FoldList
FoldList[f,x,{a,b,…}]
gives {x,f[x,a],f[f[x,a],b],…}.
FoldList[f,{a,b,c,…}]
gives {a,f[a,b],f[f[a,b],c],…}.
Details
- FoldList[Plus,0,list] generates cumulative sums of the elements in list.
- With a length n list, FoldList generates a list of length . »
- The head of list in FoldList[f,x,list] need not be List.
- FoldList[f][list] is equivalent to FoldList[f,list].
- FoldList[f][x,list] is equivalent to FoldList[f,x,list].
Examples
open allclose allBasic Examples (6)
Generalizations & Extensions (2)
Applications (15)
Compute successive factorials:
Compute products of successive primes:
Build up a continued fraction:
Build up a nested polynomial (Horner form):
Build up a number from digits:
Find the running maximum of a list:
Find successively deeper parts in an expression:
Successively append to a list:
Build up a left-branching binary tree:
Compute a power using a power tree with successive squaring:
Properties & Relations (5)
Possible Issues (1)
Text
Wolfram Research (1991), FoldList, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldList.html (updated 2016).
CMS
Wolfram Language. 1991. "FoldList." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/FoldList.html.
APA
Wolfram Language. (1991). FoldList. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FoldList.html