Is it possible to reference current iteration number in Expression parameter for IterationList?

guyuming shared this question 2 months ago

What follows is the well know IterationList example:

Example: Let f_0, f_1 be numbers. IterationList(a + b, a, b, {f_0, f_1}, 5) fills the first 2 values of the resulting list from the start values. Afterwards the values are computed as f2 = f0 + f1, f3 = f1 + f2, f4 = f2 + f3, f5 = f3 + f4. Hence for f_0 = f_1 = 1 the result will be {1, 1, 2, 3, 5, 8}.

My requirement is for the Expression parameter, is it possible to reference the current iteration number? say, change a+b to a+b+CurrentIterationNumber, and CurrentIterationNumber take the value 1,2,3...n.

That is to say for f_0=f_1=1, i want the result to be {1+1,1+2,(1+1)+(1+2)+3,...} or {1,1,(1+1)+1,((1+1)+1)+2,...}

And by referencing the CurrentIterationNumber, i can actually referencing elements from another sequence. So, the Expression parameter will be like a+b+Element(ListName,CurrentIterationNumber)

if it cannot be done with current geogebra release, would anyone give some guidance on how to customize the system for this?

Comments (4)


should be something like {1,1,(1+1)+1,((1+1)+1)+1+2,...}


so the N+1 element value can be a function of current iteration number and previous element values. List[n]=f(n,List(n-1))


do you mean x(IterationList((x(A) + x(B) + y(B), y(B) + 1), A, B, {(1, 0), (1, 1)}, 5))

you can do also defining A like a set of pair of numbers


Thanks! that is what i want.

i had thought about defining another variable and let it be something like k=k+1. But i did not know that the first parameter of IterationList,i.e., the Expression, can be a tuple.

So, i turned to the java source code, to find Sequence rely on algoSequence and IterationList rely on algoIterationList. Since the expression of sequence can be thought of a function of current iteration number, and expression of IterationList can be thought of a function of previous its previous list item value, I had thought that we might need a combined algorithm for Sequence and IterationList.

Your answer shows me that sequence is actually a special case for IterationList, with expression defined as a tuple of two items.

© 2020 International GeoGebra Institute