1 | initial version |

Defining a function would give you a nice syntax for this kind of iteration.

For example, let us define `right_iterate`

as follows.

```
def right_iterate(n, g):
x, y = g.parent().gens()
gg = y
for k in xrange(n):
gg = g(x, gg)
return gg
```

Suppose we defined

```
sage: g = x*y^3 + x^3*y^11 - 1/21*x^11*y^5 - 2/5*x^3*y^13 + O(x, y)^60
```

then, instead of writing

```
sage: g(x, g(x, g(x, y)))
x^13*y^27 + 9*x^15*y^35 - 3/7*x^23*y^29 - 18/5*x^15*y^37 - 1/7*x^25*y^33 + O(x, y)^60
```

one can write

```
sage: right_iterate(3, g)
x^13*y^27 + 9*x^15*y^35 - 3/7*x^23*y^29 - 18/5*x^15*y^37 - 1/7*x^25*y^33 + O(x, y)^60
```

and instead of

```
sage: g(x, g(x, g(x, x)))
x^40 + 9*x^50 - 141/35*x^52 - 1/7*x^58 + O(x, y)^60
```

one can write

```
sage: right_iterate(3, g)(x, x)
x^40 + 9*x^50 - 141/35*x^52 - 1/7*x^58 + O(x, y)^60
```

Of course, you could modify the function to directly use `(x, x)`

if you always want that.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.