Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate a graph of all expressions in an evaluation chain
ResourceFunction["TraceGraph"][expr] generates a graph of all expressions used in the evaluation of expr. | |
ResourceFunction["TraceGraph"][expr,form] includes only those expressions that match form. | |
ResourceFunction["TraceGraph"][expr,s] includes all evaluations that use transformation rules associated with the symbol s. |
MatchLocalNames | True | whether to allow x to stand for x$nnn |
TraceAbove | False | whether to show evaluation chains that contain the chain containing form |
TraceBackward | False | whether to show expressions preceding form in the evaluation chain |
TraceDepth | Infinity | how many levels of nested evaluations to include |
TraceForward | False | whether to show expressions following form in the evaluation chain |
TraceOff | None | forms within which to switch off tracing |
TraceOn | _ | forms within which to switch on tracing |
TraceOriginal | False | whether to look at expressions before their heads and arguments are evaluated |
Trace each step in an evaluation:
In[1]:= | ![]() |
Out[1]= | ![]() |
Trace only the computations with head Times:
In[2]:= | ![]() |
Out[2]= | ![]() |
Trace an empty evaluation chain:
In[3]:= | ![]() |
Out[3]= | ![]() |
Trace a single step evaluation:
In[4]:= | ![]() |
Out[4]= | ![]() |
Trace each branch in an evaluation:
In[5]:= | ![]() |
Out[5]= | ![]() |
Trace evaluations given by definitions:
In[6]:= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
Trace each step in an evaluation:
In[8]:= | ![]() |
Out[8]= | ![]() |
Trace the operation of FoldList:
In[9]:= | ![]() |
Out[9]= | ![]() |
Trace the steps in a non-standard evaluation:
In[10]:= | ![]() |
Out[10]= | ![]() |
Trace each step in an evaluation:
In[11]:= | ![]() |
Out[11]= | ![]() |
Include only those expressions that match _Plus:
In[12]:= | ![]() |
Out[12]= | ![]() |
Trace the computations with head Plus:
In[13]:= | ![]() |
Out[13]= | ![]() |
Apply a transformation rule to expressions that match a pattern:
In[14]:= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
Modify the setting for the form argument during the execution of TraceGraph[expr,form] by resetting the value of the global variable $TracePattern:
In[16]:= | ![]() |
Out[16]= | ![]() |
By default, symbols such as x match symbols with local names of the form x$nnn:
In[17]:= | ![]() |
In[18]:= | ![]() |
Out[18]= | ![]() |
With MatchLocalNames->False, only an explicit match of x will show up:
In[19]:= | ![]() |
Out[19]= | ![]() |
A recursive definition for finding Fibonacci numbers:
In[20]:= | ![]() |
Show only what sums of fib are encountered:
In[21]:= | ![]() |
Out[21]= | ![]() |
Show the beginning of the evaluation chain that leads to each sum of fib:
In[22]:= | ![]() |
Out[22]= | ![]() |
Show the entire evaluation chain that leads to each sum of fib:
In[23]:= | ![]() |
Out[23]= | ![]() |
A recursive definition for finding Fibonacci numbers:
In[24]:= | ![]() |
Show only what additions of positive integers are required:
In[25]:= | ![]() |
Out[25]= | ![]() |
Show the beginning of the evaluation chain that leads to each addition:
In[26]:= | ![]() |
Out[26]= | ![]() |
Show all intermediate evaluations that led to each addition:
In[27]:= | ![]() |
Out[27]= | ![]() |
A recursive definition for finding Fibonacci numbers:
In[28]:= | ![]() |
Trace only evaluations through depth 3:
In[29]:= | ![]() |
Out[29]= | ![]() |
Trace all evaluations:
In[30]:= | ![]() |
Out[30]= | ![]() |
A recursive definition for finding Fibonacci numbers:
In[31]:= | ![]() |
Show only what evaluations of fib are encountered:
In[32]:= | ![]() |
Out[32]= | ![]() |
Show only the evaluations of fib and the results:
In[33]:= | ![]() |
Out[33]= | ![]() |
Show all intermediate evaluations between calls of fib and the result:
In[34]:= | ![]() |
Out[34]= | ![]() |
Trace evaluation of an expression that evaluates a function g:
In[35]:= | ![]() |
In[36]:= | ![]() |
Out[36]= | ![]() |
Omit evaluations required to get the values of g:
In[37]:= | ![]() |
Out[37]= | ![]() |
Trace evaluation of an expression that evaluates a function g:
In[38]:= | ![]() |
In[39]:= | ![]() |
Out[39]= | ![]() |
Trace only evaluation inside of g:
In[40]:= | ![]() |
Out[40]= | ![]() |
Trace evaluation of an expression showing evaluation chains for expressions that change:
In[41]:= | ![]() |
Out[41]= | ![]() |
Show evaluation chains even for expressions that do not change:
In[42]:= | ![]() |
Out[42]= | ![]() |
TraceGraph[expr] traces each step in the evaluation of expr:
In[43]:= | ![]() |
In[44]:= | ![]() |
Out[44]= | ![]() |
TraceGraph[expr,form] includes only those expressions that match form:
In[45]:= | ![]() |
Out[45]= | ![]() |
This corresponds to deleting all expressions that do not match form, then deleting empty evaluation chains:
In[46]:= | ![]() |
Out[46]= | ![]() |
In[47]:= | ![]() |
Out[47]= | ![]() |
In[48]:= | ![]() |
Out[48]= | ![]() |
In[49]:= | ![]() |
Out[49]= | ![]() |
All expressions in the graph returned by TraceGraph are wrapped in HoldForm to prevent evaluation:
In[50]:= | ![]() |
Out[50]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License