Message Boards Message Boards

0
|
3043 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Why Is the End Result of Trace Wrapped in HoldForm?

This is probably of no practical importance but my curiosity is aroused. For example, the end result of Trace[2*3+4] is HoldForm[10]

tr = Trace[2*3 + 4]
TreeForm[tr]

enter image description here

POSTED BY: Frank Kampas
4 Replies

Sure, why bother to test if HoldForm is needed or not?

It's like going to the grocery store to buy a bag of chips and the salesclerk puts the bag of chips in a plastic bag.

No thinking required.

POSTED BY: Eric Johnstone

It would display the same if there were no HoldForm on the 10. The same is true of the 6. Note that the HoldForm around the 6 disappears in the next step. Are you saying that every part of Trace is automatically wrapped in HoldForm, whether it is needed or not?

POSTED BY: Frank Kampas

The description of HoldForm is:

HoldForm[expr] prints as the expression expr, with expr maintained in an unevaluated form.

The trace is displayed as:

{{2 3,6},6+4,10}

But in order that it not be evaluated, the actual code is:

{{HoldForm[2*3], HoldForm[6]}, 
  HoldForm[6 + 4], HoldForm[10]}

which is what the tree displays.

POSTED BY: Eric Johnstone

See below.

POSTED BY: Eric Johnstone
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract