FoldPairList[f,y0,{a1,a2,…}]
gives the list of successive xi obtained by applying f to pairs of the form {yi-1,ai}, where at each step f returns {xi,yi}.
FoldPairList[f,y0,list,g]
gives the list of successive values of g[{xi,yi}].
FoldPairList[f,{a0,a1,a2,…}]
is equivalent to FoldPairList[f,a0,{a1,a2,…}].
FoldPairList
FoldPairList[f,y0,{a1,a2,…}]
gives the list of successive xi obtained by applying f to pairs of the form {yi-1,ai}, where at each step f returns {xi,yi}.
FoldPairList[f,y0,list,g]
gives the list of successive values of g[{xi,yi}].
FoldPairList[f,{a0,a1,a2,…}]
is equivalent to FoldPairList[f,a0,{a1,a2,…}].
Details
- The function f in FoldPairList[f,y0,list] always takes two arguments and is expected to return a pair {x,y} of expressions.
- The expression expr in FoldPairList[f,y0,expr] can be any nonatomic expression, with any head.
- FoldPairList[f,y0,list] is equivalent to FoldPairList[f,y0,list,First].
- FoldPairList[f,y0,{a1,…,an}] returns a list of length n. FoldPairList[f,y0,{}] returns {}.
- You can use Throw to exit from FoldPairList before it is finished.
Examples
open all close allBasic Examples (6)
Successively apply a function that returns a pair to a seed u and the elements of a list, returning the first element of the pair:
FoldPairList[{p[#1, #2], q[#1, #2]}&, u, {1, 2, 3, 4}]Successively apply a function that returns a pair to a seed u and the elements of a list, then applying function g to the pair:
FoldPairList[{p[#1, #2], q[#1, #2]}&, u, {1, 2, 3}, g]Provide the seed and the list of elements as a single list, having the seed as first element:
FoldPairList[{p[#1, #2], q[#1, #2]}&, {a, b, c}]List can be used as the function that returns a pair:
FoldPairList[List, 0, {1, 2, 3, 4}, g]Partition a list into sublists of different lengths:
FoldPairList[TakeDrop, {a, b, c, d, e, f}, {1, 3, 2}]Break an amount of money into bills of given values:
FoldPairList[QuotientRemainder, 498, {100, 50, 20, 5, 1}]Return both the quotients and the remainders at each step:
FoldPairList[QuotientRemainder, 498, {100, 50, 20, 5, 1}, Identity]Scope (2)
Use a list in the third argument:
FoldPairList[TakeDrop, {a, b, c, d, e, f}, {1, 3, 2}]Use an arbitrary head in the third argument:
FoldPairList[TakeDrop, {a, b, c, d, e, f}, h[1, 3, 2]]By default, FoldPairList returns only the first elements of the pairs:
FoldPairList[QuotientRemainder, 498, {100, 50, 20, 5}]Use FoldPairList with fourth argument Last to get the second element of the successive pairs:
FoldPairList[QuotientRemainder, 498, {100, 50, 20, 5}, Last]Generalizations & Extensions (1)
Use Throw to exit a FoldPairList:
FoldPairList[{#1 > 1000, #1 #2}&, 1, Range[10]]Catch[FoldPairList[{If[#1 > 1000, Throw[#1]], #1 #2}&, 1, Range[10]]]Applications (2)
For each element of a list, return True if it is larger than all previous ones, and False otherwise:
FoldPairList[{#2 > #1, Max[#1, #2]}&, {1, 1, 2, 5, 2, 2, 9, 1, 2, 11}]A discrete-time state-space system is represented using a state equation
and output equation
. Simulate such a system to get the outputs
:
FoldPairList[{g[#1, #2], f[#1, #2]}&, x0, {u0, u1, u2}]Properties & Relations (4)
Return the seed and all but the last elements of the third argument:
FoldPairList[List, u, {1, 2, 3, 4}]Return the list in the third argument:
FoldPairList[List, u, {1, 2, 3, 4}, Last]Find dimensions of an array up to level 3:
array = Array[a, {2, 1, 4, 3}];FoldPairList[{Length[#], First[#]}&, array, Range[3]]% === Dimensions[array, 3]FoldPair returns the last element of the list returned by FoldPairList:
FoldPairList[QuotientRemainder, 498, {100, 50, 20, 5, 1}]FoldPair[QuotientRemainder, 498, {100, 50, 20, 5, 1}]FoldPairList returns one element less than FoldList:
FoldList[f[#1, #2]&, u, {a, b, c}]FoldPairList[{#, f[#1, #2]}&, u, {a, b, c}]FoldPairList[{#, f[#1, #2]}&, u, {a, b, c}, Last]Possible Issues (2)
The function in the first argument of FoldPairList must return a pair of expressions:
FoldPairList[MinMax[{#1, #2}]&, 10, {1, 20, 3, 25, 4, 30}]FoldPairList[Min, 10, {1, 20, 3, 25, 4, 30}]FoldPairList[f,y0,{}] returns an empty list, with no last element:
FoldPairList[f, y0, {}]Therefore FoldPair[f,y0,{}] stays unevaluated:
FoldPair[f, y0, {}]Related Guides
History
Text
Wolfram Research (2015), FoldPairList, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldPairList.html.
CMS
Wolfram Language. 2015. "FoldPairList." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FoldPairList.html.
APA
Wolfram Language. (2015). FoldPairList. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FoldPairList.html
BibTeX
@misc{reference.wolfram_2026_foldpairlist, author="Wolfram Research", title="{FoldPairList}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/FoldPairList.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_foldpairlist, organization={Wolfram Research}, title={FoldPairList}, year={2015}, url={https://reference.wolfram.com/language/ref/FoldPairList.html}, note=[Accessed: 13-June-2026]}