Trace

Trace[expr]

generates a list of all expressions used in the evaluation of expr.

Trace[expr,form]

includes only those expressions that match form.

Trace[expr,s]

includes all evaluations that use transformation rules associated with the symbol s.

Details and Options

  • In general, form in Trace[expr,form] is compared both with each complete expression that is evaluated and with the tag associated with any transformation rule used in the evaluation.
  • Trace[expr,lhs->rhs] picks out expressions that match lhs, then replaces them with rhs in the list returned.
  • All expressions in the list returned by Trace are wrapped in HoldForm.
  • Trace returns a set of nested lists. Each individual list corresponds to a single evaluation chain, which contains the sequence of forms found for a particular expression. The list has sublists that give the histories of subsidiary evaluations.
  • The following options can be given:
  • MatchLocalNamesTruewhether to allow x to stand for x$nnn
    TraceAboveFalsewhether to show evaluation chains that contain the chain containing form
    TraceBackwardFalsewhether to show expressions preceding form in the evaluation chain
    TraceDepthInfinityhow many levels of nested evaluations to include
    TraceForwardFalsewhether to show expressions following form in the evaluation chain
    TraceOffNoneforms within which to switch off tracing
    TraceOn_forms within which to switch on tracing
    TraceOriginalFalsewhether to look at expressions before their heads and arguments are evaluated
  • During the execution of Trace, the settings for the form argument, and for the options TraceOn and TraceOff, can be modified by resetting the values of the global variables $TracePattern, $TraceOn, and $TraceOff, respectively.

Examples

Basic Examples  (2)

Trace each step in an evaluation:

Trace only the computations with head Times:

Use Trace to trace the operation of FoldList:

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

Text

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2024_trace, author="Wolfram Research", title="{Trace}", year="1991", howpublished="\url{https://reference.wolfram.com/language/ref/Trace.html}", note=[Accessed: 17-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_trace, organization={Wolfram Research}, title={Trace}, year={1991}, url={https://reference.wolfram.com/language/ref/Trace.html}, note=[Accessed: 17-November-2024 ]}