({{, (RefLink[TraceScan, paclet:ref/TraceScan])[f,expr]
applies f to all expressions used in the evaluation of expr. }, {, (RefLink[TraceScan, paclet:ref/TraceScan])[f,expr,form]
includes only those expressions which match form. }, {, (RefLink[TraceScan, paclet:ref/TraceScan])[f,expr,s]
includes all evaluations which use transformation rules associated with the symbol s. }, {, (RefLink[TraceScan, paclet:ref/TraceScan])[f,expr,form,fp]
applies f before evaluation and fp after evaluation to expressions used in the evaluation of expr. }})

OpenersNotesSection(Spacer1)Details and Options

All expressions are wrapped in (RefLink[HoldForm, paclet:ref/HoldForm]) to prevent evaluation before f or fp are applied to them.

The function fp is given as an argument for both the form before evaluation and the form after evaluation.

(RefLink[TraceScan, paclet:ref/TraceScan])[f,expr] returns the result of evaluating expr.

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)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];

Count calls to fib required:

{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]);

Count calls to fib required:

{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}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Trace, paclet:ref/Trace])  ▪  (RefLink[TracePrint, paclet:ref/TracePrint])  ▪  (RefLink[TraceDialog, paclet:ref/TraceDialog])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Tracing Evaluation, paclet:tutorial/TracingEvaluation])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Symbolic Execution History, paclet:guide/SymbolicExecutionHistory])}})}})