TraceScan[f,expr]
applies f to all expressions used in the evaluation of expr.
TraceScan[f,expr,form]
includes only those expressions which match form.
TraceScan[f,expr,s]
includes all evaluations which use transformation rules associated with the symbol s.
TraceScan[f,expr,form,fp]
applies f before evaluation and fp after evaluation to expressions used in the evaluation of expr.
TraceScan
TraceScan[f,expr]
applies f to all expressions used in the evaluation of expr.
TraceScan[f,expr,form]
includes only those expressions which match form.
TraceScan[f,expr,s]
includes all evaluations which use transformation rules associated with the symbol s.
TraceScan[f,expr,form,fp]
applies f before evaluation and fp after evaluation to expressions used in the evaluation of expr.
Examples
Basic Examples (3)
Print all expressions used for evaluation:
TraceScan[Print, f[1, 2 + 3]]Count additions and multiplications of machine numbers needed for a numerical computation:
Block[{c = 0}, {TraceScan[c++&, FixedPoint[(# / 2 + 1 / #)&, 1.], (Plus | Times)[__ ? MachineNumberQ]], c}]A recursive definition for finding Fibonacci numbers:
fib[0] = fib[1] = 1;fib[n_] := fib[n - 1] + fib[n - 2];{c = 0;TraceScan[(c++)&, fib[10], fib[_Integer]], c}Redefine fib so that it saves results:
fib[n_] := (fib[n] = fib[n - 1] + fib[n - 2]);{c = 0;TraceScan[(c++)&, fib[10], fib[_Integer]], c}The second time through it takes only one call since the value was saved:
{c = 0;TraceScan[(c++)&, fib[10], fib[_Integer]], c}See Also
Tech Notes
Related Guides
History
Introduced in 1991 (2.0)
Text
Wolfram Research (1991), TraceScan, Wolfram Language function, https://reference.wolfram.com/language/ref/TraceScan.html.
CMS
Wolfram Language. 1991. "TraceScan." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TraceScan.html.
APA
Wolfram Language. (1991). TraceScan. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TraceScan.html
BibTeX
@misc{reference.wolfram_2026_tracescan, author="Wolfram Research", title="{TraceScan}", year="1991", howpublished="\url{https://reference.wolfram.com/language/ref/TraceScan.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_tracescan, organization={Wolfram Research}, title={TraceScan}, year={1991}, url={https://reference.wolfram.com/language/ref/TraceScan.html}, note=[Accessed: 12-June-2026]}