Algosim documentation: orbit

orbit

Computes iterated images of a value under a given function.

Syntax

Description

If f is a function, x any object, and n a non-negative integer, then orbit(f, x, n) returns the set

{x, f(x), f(f(x)), ..., f^n(x)}.

If omitted, iterated images are computed until a value is found a second time.

Since the result is a set, its cardinality may be less than n + 1 and its members have no order. (When printed to screen, the order is undefined.)

The IteratedImages function is similar, except that it returns the values as a list instead of a set. In particular, this means that the elements are ordered and that the result is of length n + 1 and thus may contain duplicates.

Examples

a ≔ n ↦ if(even(n), n/2, 3⋅n+1);
#orbit(a, 27)
112

See also