Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Functional Programming > Functional Iteration >
Mathematica > Core Language > Procedural Programming > Looping Constructs > Functional Iteration >

Nest

Nest[f, expr, n]
gives an expression with f applied n times to expr.
The function to nest can be a pure function:
In[1]:=
Click for copyable input
Out[1]=
 
The function to nest can be a pure function:
In[1]:=
Click for copyable input
Out[1]=
Nesting a function can build a formula:
Nesting can return a single number:
The nested function can operate on a list:
Use Throw to exit a Nest:
To nest a function of more than one argument, the arguments can be put into a list:
Continued fraction:
Power tower:
Growth of annually compounded capital in 10 years:
Newton iterations for :
Iterated string replacements:
Consecutive pairs of Fibonacci numbers:
Functional composition for higher-order Newton iteration (for ):
Generate a bifurcation diagram for an iterated logistic map:
Nest gives the last element of NestList:
Nest is effectively Composition using the same function multiple times:
Use RSolve to symbolically compute Nest operations:
Different length compositions or nests give the same result:
FixedPoint automatically goes on until the result no longer changes:
NestWhile goes on while a condition is true:
Fold automatically inserts second arguments from a list:
Binary tree:
Gray codes of length 4:
New in 1 | Last modified in 3
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team