BUILT-IN MATHEMATICA SYMBOL

# 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.

## Details and OptionsDetails and Options

• All expressions are wrapped in 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.
• TraceScan[f, expr] returns the result of evaluating expr.

## ExamplesExamplesopen allclose all

### Basic Examples (3)Basic Examples (3)

Print all expressions used for evaluation:

 Out[1]=

Count additions and multiplications of machine numbers needed for a numerical computation:

 Out[1]=

A recursive definition for finding Fibonacci numbers:

Count calls to required:

 Out[2]=

Redefine so that it saves results:

Count calls to required:

 Out[4]=

The second time through it takes only one call since the value was saved:

 Out[5]=