WOLFRAM

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],}.

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

Details

Examples

open allclose all

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

Out[1]=1

Cumulative sums of the elements of the list:

Out[1]=1

Cumulative powers:

Out[1]=1

Start from the first element of the list:

Out[1]=1

Use the operator form of FoldList on one argument:

Out[1]=1

Use the operator form of FoldList on two arguments:

Out[1]=1

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

Perform two subsequent permutations:

Out[1]=1

Perform a chain of cross products:

Out[1]=1

Generalizations & Extensions  (2)Generalized and extended use cases

The head need not be List:

Out[1]=1

Fold to the right:

Out[1]=1

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

Compute successive factorials:

Out[1]=1

Compute products of successive primes:

Out[1]=1

Cumulative sums:

Out[1]=1

Build up a continued fraction:

Out[1]=1

Build up a nested polynomial (Horner form):

Out[1]=1

Build up a number from digits:

Out[1]=1

Form alternating sums:

Out[1]=1

Generate a random walk:

Out[1]=1

Find the running maximum of a list:

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

Find successively deeper parts in an expression:

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

Successively append to a list:

Out[1]=1

Build up a binary tree:

Out[1]=1

Build up a left-branching binary tree:

Out[1]=1

Make function compositions:

Out[1]=1

Compute a power using a power tree with successive squaring:

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

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

FoldList makes a list of length :

Out[1]=1

Rest gives a result of length :

Out[2]=2

Folding with an empty list does not apply the function at all:

Out[1]=1

Fold gives the last element of FoldList:

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

Functions that ignore their second argument give the same result as in NestList:

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

Accumulate is equivalent to FoldList with Plus:

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

Possible Issues  (1)Common pitfalls and unexpected behavior

FoldList[f,{}] evaluates to an empty list, without a last element:

Out[1]=1

Therefore Fold[f,{}] stays unevaluated:

Out[2]=2

Neat Examples  (1)Surprising or curious use cases

Compute the minimum number of coins of different value needed to make up an amount :

Out[2]=2
Wolfram Research (1991), FoldList, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldList.html (updated 2016).
Wolfram Research (1991), FoldList, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldList.html (updated 2016).

Text

Wolfram Research (1991), FoldList, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldList.html (updated 2016).

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.

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

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

BibTeX

@misc{reference.wolfram_2025_foldlist, author="Wolfram Research", title="{FoldList}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/FoldList.html}", note=[Accessed: 26-April-2025 ]}

@misc{reference.wolfram_2025_foldlist, author="Wolfram Research", title="{FoldList}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/FoldList.html}", note=[Accessed: 26-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_foldlist, organization={Wolfram Research}, title={FoldList}, year={2016}, url={https://reference.wolfram.com/language/ref/FoldList.html}, note=[Accessed: 26-April-2025 ]}

@online{reference.wolfram_2025_foldlist, organization={Wolfram Research}, title={FoldList}, year={2016}, url={https://reference.wolfram.com/language/ref/FoldList.html}, note=[Accessed: 26-April-2025 ]}