Hello,

I am having trouble conceptualising how to implement Dynamic Time Warping (DTW) as a query. (See http://en.wikipedia.org/wiki/Dynamic_time_warping for addtional information.) For example, using AQL, execute

```
create array cos <cos_x:float> [i=1:10,10,0];
select * into cos from build(cos,cos(i));
create array sin <sin_x:float> [j=1:10,10,0];
select * into sin from build(sin,sin(j));
```

Starting with the traditional example, the goal is to create the following matrix:

`create array dtw <dtw_x:float> [i=0:10,11,0, j=0:10,11,0];`

such that, in psuedo-code,

```
// Boundary conditions
dtw(0,0) = 0
dtw(i,0) = inf
dtw(0,j) = inf
// Algorithm
dtw(i,j) = abs(cos(i) - sin(j)) + min(dtw(i,j-1), dtw(i-1,j), dtw(i-1,j-1)
// Result
dtw(10,10)
```

Despite the tail recursive definition above, the process is iterative by starting with dtw(1,1) and working forward to dtw(10,10) given the above boundary conditions. For example, one could simulate this example in a spreadsheet.

What I am having difficulting seeing is how create this iterative process as a query, AQL or AFL:

```
diff = abs(cos(i) - sin(j))
+-----------+-----------------------------+
| (i-1,j-1) | (i,j-1) |
+-----------+-----------------------------+
| (i-1,j) | diff + min of prevous cells |
+-----------+-----------------------------+
```

I have read the user guide a few times and worked with every operator and function at least once so please feel free to give me a cryptic pointer, and I will do the rest.

Thanks in advance for the help.