NestList
Details
- NestList[f,expr,n] gives a list of length n+1.
Examples
open all close allBasic Examples (3)
Create a list by applying f to x from 0 to 4 times:
NestList[f, x, 4]Repeatedly apply Cos to to a number:
NestList[Cos, 1.0, 10]The function to nest can be a pure function:
NestList[(1 + #) ^ 2&, x, 3]Scope (4)
Nesting a function can build a formula:
NestList[(1 + #) ^ 2&, x, 3]Nesting can return a single number:
NestList[Sqrt, 100.0, 4]The nested function can operate on a list:
With[{ϵ = 0.1}, NestList[Function[xy, {2ϵ, 0} + {{1 - 2ϵ, 0}, {0, 1 - 2ϵ}}.xy], {1.0, 1.0}, 4]]Use the operator form to create a list from different starting expressions:
op = NestList[Sin, 4];op[0.]op[(π/4.)]op[(π/2.)]Generalizations & Extensions (1)
Applications (15)
NestList[2#1&, 1, 10]NestList[# + 1&, 0, 10]NestList[# ^ 2&, 2, 6]Growth of annually compounded capital:
NestList[#(1 + 0.05)&, 1000, 10]NestList[D[#, x]&, x ^ n, 3]NestList[(# + 2 / #) / 2&, 1.0, 5]NestList[1 / (1 + #)&, x, 5]NestList[4#(1 - #)&, 1 / 3, 5]NestList[4#(1 - #)&, N[1 / 3], 10]NestList[If[EvenQ[#], # / 2, (3# + 1) / 2]&, 100, 20]Linear congruential pseudorandom generator:
NestList[Mod[59#, 101]&, 1, 15]NestList[# + RandomChoice[{-1, 1}]&, 0, 20]ListLinePlot[%]NestList[StringReplace[#, {"A" -> "BA", "B" -> "AB"}]&, "A", 5]Successively append to a list:
NestList[Append[#, x]&, {a}, 5]NestList[RotateLeft, {a, b, c, d}, 4]Operations on a pair of values:
NestList[{f[Last[#]], g[First[#]]}&, {x, y}, 5]Properties & Relations (5)
Nest gives the last element of NestList:
NestList[f, x, 4]Nest[f, x, 4]Nesting zero times simply returns to the original argument:
NestList[f, x, 0]FixedPointList goes on until the result no longer changes:
NestList[1 + Floor[# / 2]&, 1000, 15]FixedPointList[1 + Floor[# / 2]&, 1000, 15]NestWhileList goes on while a condition is true:
NestWhileList[If[EvenQ[#], # / 2, (3# + 1) / 2]&, 29, # > 1&]FoldList automatically inserts second arguments from a list:
NestList[f[#, a]&, x, 3]FoldList[f, x, {a, a, a}]Neat Examples (4)
NestList[Framed, x, 6]NestList[Style[#, Larger]&, x, 6]NestList[x ^ #&, x, 6]NestList[# ^ #&, x, 4]NestList[Framed[Row[{#, #}]]&, x, 4]NestList[p[#][#]&, x, 3]NestList[Subsuperscript[#, #, #]&, x, 4]Tech Notes
Related Links
-

An Elementary Introduction to the Wolfram Language
: Applying Functions Repeatedly
-

An Elementary Introduction to the Wolfram Language
: More about Pure Functions
-

An Elementary Introduction to the Wolfram Language
: Rearranging Lists
-

An Elementary Introduction to the Wolfram Language
: More about Patterns
-

An Elementary Introduction to the Wolfram Language
: String Patterns and Templates
-

NKS|Online
(A New Kind of Science)
History
Introduced in 1988 (1.0) | Updated in 2024 (14.1)
Text
Wolfram Research (1988), NestList, Wolfram Language function, https://reference.wolfram.com/language/ref/NestList.html (updated 2024).
CMS
Wolfram Language. 1988. "NestList." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/NestList.html.
APA
Wolfram Language. (1988). NestList. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NestList.html
BibTeX
@misc{reference.wolfram_2026_nestlist, author="Wolfram Research", title="{NestList}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NestList.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_nestlist, organization={Wolfram Research}, title={NestList}, year={2024}, url={https://reference.wolfram.com/language/ref/NestList.html}, note=[Accessed: 13-June-2026]}