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

FoldList[f]

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

Details

Examples

open allclose all

Basic Examples  (6)

Cumulative sums of the elements of the list:

Cumulative powers:

Start from the first element of the list:

Use the operator form of FoldList on one argument:

Use the operator form of FoldList on two arguments:

Scope  (2)

Perform two subsequent permutations:

Perform a chain of cross products:

Generalizations & Extensions  (2)

The head need not be List:

Fold to the right:

Applications  (15)

Compute successive factorials:

Compute products of successive primes:

Cumulative sums:

Build up a continued fraction:

Build up a nested polynomial (Horner form):

Build up a number from digits:

Form alternating sums:

Generate a random walk:

Find the running maximum of a list:

Find successively deeper parts in an expression:

Successively append to a list:

Build up a binary tree:

Build up a left-branching binary tree:

Make function compositions:

Compute a power using a power tree with successive squaring:

Properties & Relations  (5)

FoldList makes a list of length :

Rest gives a result of length :

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

Fold gives the last element of FoldList:

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

Accumulate is equivalent to FoldList with Plus:

Possible Issues  (1)

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

Therefore Fold[f,{}] stays unevaluated:

Neat Examples  (1)

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

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).

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_foldlist, organization={Wolfram Research}, title={FoldList}, year={2016}, url={https://reference.wolfram.com/language/ref/FoldList.html}, note=[Accessed: 30-December-2024 ]}