Mathematica 9 is now available

Trace

Usage

Trace[expr]产生用在expr的计算中的所有表达式的一个列表。
Trace[expr, form]仅包括匹配form的表达式。
Trace[expr, s]包括所有使用和符号s关联的变换规则的计算。


Notes

• 通常,在Trace[expr, form]中的form既和被计算的每个完全表达式比较,也和在计算时使用的任何变换规则相关联的标记比较。
Trace[expr, lhs -> rhs]选出匹配 lhs 的表达式,然后用返回列表中的rhs替换它们。
• 由Trace返回的列表中的所有表达式被包裹在HoldForm中。
Trace返回一个嵌套列表集合。每个个体列表相应于一个单一计算链,包含对一个特殊表达式找到的形式序列。这个列表有子列表,给出辅助计算的历史记录。
• 例如: Trace[2 3 + 4]LongRightArrow .
• 可以给出下面的选项:
"\!\(\*StyleBox[\"\\\"MatchLocalNames\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"True\\\"\", \"MR\"]\) "是否允许 x 代表x$nnn
"\!\(\*StyleBox[\"\\\"TraceAbove\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"False\\\"\", \"MR\"]\) "是否显示包含 form的链的计算链
"\!\(\*StyleBox[\"\\\"TraceBackward\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"False\\\"\", \"MR\"]\) "是否在计算链中显示在 form前的表达式
"\!\(\*StyleBox[\"\\\"TraceDepth\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"Infinity\\\"\", \"MR\"]\) "包括的嵌套计算的层数
"\!\(\*StyleBox[\"\\\"TraceForward\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"False\\\"\", \"MR\"]\) "是否在计算链中显示接着的表达式
"\!\(\*StyleBox[\"\\\"TraceOff\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"None\\\"\", \"MR\"]\) "以这种形式关掉跟踪
"\!\(\*StyleBox[\"\\\"TraceOn\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"_\\\"\", \"MR\"]\) "以这种形式打开跟踪
"\!\(\*StyleBox[\"\\\"TraceOriginal\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"False\\\"\", \"MR\"]\) "是否在它们的头和参数计算前浏览表达式
• 在Trace的执行期间,form的参数和对选项TraceOnTraceOff设置,可以通过分别重新设置全局变量$TracePattern, $TraceOn$TraceOff的值来修改。
• 参见Mathematica 全书: 2.5.4 and 节 2.5.10.
• 同时参见: TraceDialog, TracePrint, TraceScan.
Further Examples

This show the order of operations in a simple arithmetic expression.

In[1]:=  

Out[1]=

Here is the recursive definition of the Fibonacci numbers.

In[2]:=  

Here are the end conditions for the recursion.

In[3]:=  

Out[3]=

This tells Trace to return only the arguments of fib used in the evaluation of fib[5].

In[4]:=  

Out[4]=

This shows all occurrences of fib in the evaluation of fib[3].

In[5]:=  

Out[5]=



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.