Sow
Examples
open all close allBasic Examples (4)
Evaluate a sequence of expressions, "sowing" some to be collected by Reap:
Reap[Sow[a];b;Sow[c];Sow[d];e]Compute a sum, "sowing" i^2 at each step:
Reap[Sum[Sow[i ^ 2] + 1, {i, 10}]]Make separate lists for expressions "sown" with different tags:
Reap[Sow[1, x];Sow[2, y];Sow[3, x];Sow[4, y]]Reap only expressions "sown" with tag x:
Reap[Sow[1, x];Sow[2, y];Sow[3, x];Sow[4, y], x]Scope (5)
Sow can be used anywhere in a computation:
Reap[MapAll[If[PrimeQ[#], Sow[#]]&, Integrate[1 / (x ^ 5 - 1), x]];]It still works inside a function:
f[e_] := If[PrimeQ[e], Sow[e]]Reap[MapAll[f, Integrate[1 / (x ^ 5 - 1), x]];]A single expression can be "sown" with multiple tags:
Reap[Sow[1, x];Sow[2, {x, y}];Sow[3, y]]If a single tag is repeated, the expression is sown repeatedly:
Reap[Sow[1, {x, x, x}];Sow[2, {x, y}];Sow[3, y]]A pattern in Reap can be used to specify which tags to collect:
Reap[Sow[1, x];Sow[2, {x, y}];Sow[3, {y, z}];Sow[4, {x, y, z}], x | y]The default is the pattern _, so that everything is collected:
Reap[Sow[1, x];Sow[2, {x, y}];Sow[3, {y, z}];Sow[4, {x, y, z}]]Tags can have any form; here they are True and False:
Reap[Sow[#, # > 0]& /@ {1, -1, 2, -3, 1, 4, 5};]Reap[Sow[#, # > 0]& /@ {1, -1, 2, -3, 1, 4, 5};, True]Applications (3)
Make a list of all the steps taken in evaluating FindRoot:
Reap[FindRoot[Cos[x] == x, {x, 1}, StepMonitor :> Sow[x]]]Evaluate an iterated map, keeping iterates that are below 1/100:
Reap[Nest[(If[# < 1 / 100, Sow[#]];4 #(1 - #))&, 0.2, 100]]Find equivalence classes with respect to the value of
mod 10:
Reap[Do[Sow[i, Mod[i ^ 2, 10]], {i, 20}]]Tech Notes
Related Guides
History
Introduced in 2003 (5.0)
Text
Wolfram Research (2003), Sow, Wolfram Language function, https://reference.wolfram.com/language/ref/Sow.html.
CMS
Wolfram Language. 2003. "Sow." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Sow.html.
APA
Wolfram Language. (2003). Sow. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Sow.html
BibTeX
@misc{reference.wolfram_2026_sow, author="Wolfram Research", title="{Sow}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/Sow.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sow, organization={Wolfram Research}, title={Sow}, year={2003}, url={https://reference.wolfram.com/language/ref/Sow.html}, note=[Accessed: 12-June-2026]}