GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing reference.wolfram.com — Nest—Wolfram Documentation Details
Examples
Basic Examples
Scope
Generalizations & Extensions
Applications
Properties & Relations
Neat Examples
See Also
Tech Notes
Related Guides
Related Links
History
Cite this Page
NestExamplesopen all close allBasic Examples (2)Apply f to x from 0 to 4 times: Nest[f, x, 4]The function to nest can be a pure function: Nest[(1 + #) ^ 2&, 1, 3]Scope (4)Nesting a function can build a formula: Nest[(1 + #) ^ 2&, x, 5]Nesting can return a single number: Nest[Sqrt, 100.0, 4]The nested function can operate on a list: With[{ϵ = 0.1}, Nest[Function[xy, {2ϵ, 0} + {{1 - 2ϵ, 0}, {0, 1 - 2ϵ}}.xy], {1.0, 1.0}, 5]]Apply the operator form to different starting expressions: op = Nest[Sin, 3];{op[0], op[π / 4], op[π / 2]}Generalizations & Extensions (2)NestList[# ^ 2&, 2, 6]Catch[Nest[If[# > 10 ^ 6, Throw[#], # ^ 2]&, 2, 6]]To nest a function of more than one argument, the arguments can be put into a list: Nest[{(#[[1]] + #[[2]]/2), Sqrt[#[[1]] #[[2]]]}&, {0.5, 1.0}, 10]Applications (8)Continued fraction: Nest[1 / (1 + #)&, x, 5]Power tower: Nest[x ^ #&, x, 6]Growth of annually compounded capital in 10 years: Nest[#(1 + 0.05)&, 1000, 10]Newton iterations for Nest[(# + 2 / # ) / 2&, 1.0, 5]Iterated string replacements: Nest[StringReplace[#, {"A" -> "BA", "B" -> "AB"}]&, "A", 5]Consecutive pairs of Fibonacci numbers: Nest[{{1, 1}, {1, 0}}.#&, {0, 1}, 10]Functional composition for higher-order Newton iteration (for Function[x, Evaluate[Together[Nest[Function[z, (z + 3 / z) / 2], x, 4]]]]FixedPointList[%, 1`50]Generate a bifurcation diagram for an iterated logistic map: ListPlot[Table[Thread[{r, Nest[r # (1 - #)&, Range[0, 1, 0.01], 1000]}], {r, 0, 4, 0.01}]]Properties & Relations (6)Nest gives the last element of NestList: NestList[f, x, 4]Nest[f, x, 4]Nest is effectively Composition using the same function multiple times: Nest[f, x, 3]Composition[f, f, f][x]Use RSolve to symbolically compute Nest operations: f[x_] := (2x + 3/x + 4)RSolve[y[k + 1] == f[y[k]] && y[0] == 0, y, k]g = y /. First[%]Different length compositions or nests give the same result: Table[g[k], {k, 1, 5}]Table[Nest[f, 0, k], {k, 1, 5}]FixedPoint automatically goes on until the result no longer changes: Nest[Floor[# / 2]&, 20, 6]FixedPoint[Floor[# / 2]&, 20]NestWhile goes on while a condition is true: NestWhile[If[EvenQ[#], # / 2, (3 # + 1) / 2]&, 29, # > 1&]Fold automatically inserts second arguments from a list: Nest[f[#, a]&, x, 3]Fold[f, x, {a, a, a}]Neat Examples (4)Nest[Framed, x, 6]Binary tree: Nest[{#, #}&, x, 3]Nest[Framed[Row[{#, #}]]&, "", 5]Nest[p[#][#]&, x, 4]Nest[Subsuperscript[#, #, #]&, x, 5]Gray codes of length 4: Nest[Join[#, Length[#] + Reverse[#]]&, {0}, 4]BaseForm[%, 2]See AlsoNestList NestGraph NestWhile Fold Function FixedPoint Do Composition Tech NotesRelated GuidesHistoryIntroduced in 1988 (1.0) | Updated in 1996 (3.0) ▪ 2024 (14.1)
Wolfram Research (1988), Nest, Wolfram Language function, https://reference.wolfram.com/language/ref/Nest.html (updated 2024).
TextWolfram Research (1988), Nest, Wolfram Language function, https://reference.wolfram.com/language/ref/Nest.html (updated 2024). CMSWolfram Language. 1988. "Nest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/Nest.html. APAWolfram Language. (1988). Nest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Nest.html BibTeX@misc{reference.wolfram_2026_nest, author="Wolfram Research", title="{Nest}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/Nest.html}", note=[Accessed: 12-November-2026]} BibLaTeX@online{reference.wolfram_2026_nest, organization={Wolfram Research}, title={Nest}, year={2024}, url={https://reference.wolfram.com/language/ref/Nest.html}, note=[Accessed: 12-November-2026]} |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |