FoldPair

FoldPair[f,y0,list]

gives the last element of FoldPairList[f,y0,list].

FoldPair[f,y0,list,g]

gives the last element of FoldPairList[f,y0,list,g].

FoldPair[f,{a0,a1,a2,}]

is equivalent to FoldPair[f,a0,{a1,a2,}].

Details

  • The function f in FoldPair[f,y0,list] always takes two arguments and is expected to return a pair {x,y} of expressions.
  • The expression expr in FoldPair[f,y0,expr] can be any nonatomic expression, with any head.
  • You can use Throw to exit from FoldPair before it is finished.

Examples

open allclose all

Basic Examples  (3)

Scope  (1)

Use a list in the third argument:

Use an arbitrary head in the third argument:

Generalizations & Extensions  (1)

Use Throw to exit a FoldPair:

Applications  (2)

Find the last sublist of an arbitrary partition of a list:

A discrete-time state-space system is represented using a state equation and output equation . Simulate such a system to get the final output:

Properties & Relations  (2)

FoldPair returns the last element of the list returned by FoldPairList:

FoldPair does not return by default the remainder of the process:

Use Last in the fourth argument to get the remainder:

Use Identity in the fourth argument to get both:

Possible Issues  (2)

The function in the first argument of FoldPair must return a pair of expressions:

FoldPairList[f,y0,{}] returns an empty list, with no last element:

Therefore FoldPair[f,y0,{}] stays unevaluated:

Wolfram Research (2015), FoldPair, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldPair.html.

Text

Wolfram Research (2015), FoldPair, Wolfram Language function, https://reference.wolfram.com/language/ref/FoldPair.html.

BibTeX

@misc{reference.wolfram_2020_foldpair, author="Wolfram Research", title="{FoldPair}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/FoldPair.html}", note=[Accessed: 16-January-2021 ]}

BibLaTeX

@online{reference.wolfram_2020_foldpair, organization={Wolfram Research}, title={FoldPair}, year={2015}, url={https://reference.wolfram.com/language/ref/FoldPair.html}, note=[Accessed: 16-January-2021 ]}

CMS

Wolfram Language. 2015. "FoldPair." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FoldPair.html.

APA

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