Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Functional Programming > Functional Iteration > Fold >
Mathematica > Core Language > Procedural Programming > Looping Constructs > Functional Iteration > Fold >

Fold

Fold
gives the last element of FoldList.
  • You can use Throw to exit from Fold before it is finished.
In[1]:=
Click for copyable input
Out[1]=
 
In[1]:=
Click for copyable input
Out[1]=
 
In[1]:=
Click for copyable input
Out[1]=
 
In[1]:=
Click for copyable input
Out[1]=
The head need not be List:
Use Throw to exit a Fold:
Fold to the right:
Create a nested polynomial (Horner form):
HornerForm directly produces this output:
Form a continued fraction:
Form a number from digits:
Form an alternating sum:
Form a binary tree:
Form a left-branching binary tree:
Form a function composition:
Apply an indexed sequence of functions:
Successively partition a list:
Folding with an empty list does not apply the function at all:
Fold returns the last element of FoldList:
Functions that ignore their second argument give the same result as in Nest:
An explicit form of the primitive recursive function []:
Generate all subsets of a set:
Find all possible sums of any of the elements of a list of numbers:
The fourth Swinnerton-Dyer polynomial []:
New in 2 | Last modified in 3
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team
Format:   HTML  |  CDF