Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > List Manipulation > Applying Functions to Lists >
Mathematica > Data Manipulation > Handling Arrays of Data > Applying Functions to Lists >

FoldList

FoldList[f, x, {a, b, ...}]
gives {x, f[x, a], f[f[x, a], b], ...}.
  • FoldList[Plus, 0, list] generates cumulative sums of the elements in list.
  • With a length n list, FoldList generates a list of length n+1.  »
Cumulative sums of the elements of the list:
Cumulative powers:
The head need not be List:
Fold to the right:
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:
FoldList makes a list of length n+1:
Rest gives a result of length n:
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:
Compute the minimum number of coins of different value needed to make up an amount d:
New in 2
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team