WOLFRAM

Nest[f,expr,n]

gives an expression with f applied n times to expr.

Nest[f,n]

represents an operator form of Nest that can be applied to expressions.

Details

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

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Apply f to x from 0 to 4 times:

Out[1]=1

The function to nest can be a pure function:

Out[1]=1

Scope  (4)Survey of the scope of standard use cases

Nesting a function can build a formula:

Out[1]=1

Nesting can return a single number:

Out[1]=1

The nested function can operate on a list:

Out[1]=1

Apply the operator form to different starting expressions:

Out[2]=2

Generalizations & Extensions  (2)Generalized and extended use cases

Use Throw to exit a Nest:

Out[1]=1
Out[2]=2

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

Out[1]=1

Applications  (8)Sample problems that can be solved with this function

Continued fraction:

Out[1]=1

Power tower:

Out[1]=1

Growth of annually compounded capital in 10 years:

Out[1]=1

Newton iterations for :

Out[1]=1

Iterated string replacements:

Out[1]=1

Consecutive pairs of Fibonacci numbers:

Out[1]=1

Functional composition for higher-order Newton iteration (for ):

Out[1]=1
Out[2]=2

Generate a bifurcation diagram for an iterated logistic map:

Out[1]=1

Properties & Relations  (6)Properties of the function, and connections to other functions

Nest gives the last element of NestList:

Out[1]=1
Out[2]=2

Nest is effectively Composition using the same function multiple times:

Out[1]=1
Out[2]=2

Use RSolve to symbolically compute Nest operations:

Out[2]=2
Out[3]=3

Different length compositions or nests give the same result:

Out[4]=4
Out[5]=5

FixedPoint automatically goes on until the result no longer changes:

Out[1]=1
Out[2]=2

NestWhile goes on while a condition is true:

Out[1]=1

Fold automatically inserts second arguments from a list:

Out[1]=1
Out[2]=2

Neat Examples  (4)Surprising or curious use cases

Out[1]=1

Binary tree:

Out[1]=1
Out[2]=2
Out[3]=3
Out[1]=1

Gray codes of length 4:

Out[1]=1
Wolfram Research (1988), Nest, Wolfram Language function, https://reference.wolfram.com/language/ref/Nest.html (updated 2024).
Wolfram Research (1988), Nest, Wolfram Language function, https://reference.wolfram.com/language/ref/Nest.html (updated 2024).

Text

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

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

CMS

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

Wolfram Language. 1988. "Nest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. 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

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="2024", howpublished="\url{https://reference.wolfram.com/language/ref/Nest.html}", note=[Accessed: 11-January-2025 ]}

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

BibLaTeX

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

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