## `@@` -- iterate a function

#### Introduction

`f@@n` represents the `n`-fold iterate `x -> f(f(...(f(x))...))` of the function `f`.

#### Call(s)

f `@@` n `_fnest(f, n)`

#### Parameters

`f` | - | a function
`n` | - | an integer

#### Returns

a function

#### Related Functions

`@`, `fp::fixargs`, `fp::nest`, `fp::nestvals`, `fp::fold`

#### Details

- The statement `f@@n` is equivalent to the call `_fnest(f, n)`.
- For positive `n`, `f@@n` is also equivalent to `_fconcat(f $ n)`.
- `f@@0` returns the identity map `id`.
- If `f` is a function environment with the slot `"inverse"` set, `n` can also be negative. Cf. example 2.
- Iteration is only reasonable for functions that accept their own return values as input. Note that `fp::fixargs` is a handy tool for converting functions with parameters to univariate functions which may be suitable for iteration. Cf. example 3.

#### Example 1

For a nonnegative integer `n`, `f@@n` is equivalent to an `_fconcat` call:

    >> f@@4, (f@@4)(x)

                              f@f@f@f, f(f(f(f(x))))

`@@` simplifies the composition of symbolic iterates:

    >> (f@@n)@@m

                                     f@@(m n)

The iterate may be called like any other MuPAD function. If `f` evaluates to a procedure and `n` to an integer, a corresponding value is computed:

    >> f := x -> x^2:  (f@@n)(x) $ n = 0..10

                   2   4   8   16   32   64   128   256   512   1024
               x, x , x , x , x  , x  , x  , x   , x   , x   , x

    >> delete f:

#### Example 2

For functions with a known inverse function, `n` may be negative. The function `f` must have been declared as a function environment with the `"inverse"` slot. Examples of such functions include the trigonometric functions which are implemented as function environments in MuPAD:

    >> sin::"inverse", sin@@-3, (sin@@(-3))(x)

             "arcsin", arcsin@arcsin@arcsin, arcsin(arcsin(arcsin(x)))

#### Example 3

`@@` can only be used for functions that accept their own output domain as an input, i.e., f:M M for some set M. If you want to use `@@` with a function which needs additional parameters, `fp::fixargs` is a handy tool to generate a corresponding univariate function. In the following call, the function `f: x -> g(x, p)` is iterated:

    >> g := (x, y) -> x^2 + y: f := fp::fixargs(g, 1, p): (f@@4)(x)

                                                2 2 2 2
                            p + (p + (p + (p + x ) ) )

    >> delete g, f:

#### Changes

- used to be called `repcom`
- The slot `"inverse"` is now used.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000