Nest

Nest[f,expr,n]

gives an expression with f applied n times to expr.

Details

  • You can use Throw to exit from Nest before it is finished. »

Examples

open allclose all

Basic Examples  (2)

The function to nest can be a pure function:

Scope  (3)

Nesting a function can build a formula:

Nesting can return a single number:

The nested function can operate on a list:

Generalizations & Extensions  (2)

Use Throw to exit a Nest:

To nest a function of more than one argument, the arguments can be put into a list:

Applications  (8)

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:

Properties & Relations  (6)

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:

Neat Examples  (4)

Binary tree:

Gray codes of length 4:

Wolfram Research (1988), Nest, Wolfram Language function, https://reference.wolfram.com/language/ref/Nest.html (updated 1996).

Text

Wolfram Research (1988), Nest, Wolfram Language function, https://reference.wolfram.com/language/ref/Nest.html (updated 1996).

CMS

Wolfram Language. 1988. "Nest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Nest.html.

APA

Wolfram Language. (1988). Nest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Nest.html

BibTeX

@misc{reference.wolfram_2024_nest, author="Wolfram Research", title="{Nest}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Nest.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_nest, organization={Wolfram Research}, title={Nest}, year={1996}, url={https://reference.wolfram.com/language/ref/Nest.html}, note=[Accessed: 19-March-2024 ]}