How to explain the behaviour of TreeForm?With/Function(/etc) replacement behaviourdirect assignment to the element in a TableSome _atomic elements' TreeForm looks confusing with Level in appearanceConverting expressions to “edges” for use in TreePlot, GraphTreeForm expression that will automatically spread nodes vertically so labels do not overlapInserting symbols' definitions during read time of the codeUnderstanding the output formatting of held formsHow to stop TreeForm from shaking when changing resolution?Strange behaviour of ValueQ inside loopsStrange behaviour (or issue?) in using evaluation of held argument inside a table in Mathematica
Company stopped paying my salary. What are my options?
Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks?
Getting a error after using setState with a promise
We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?
Two researchers want to work on the same extension to my paper. Who to help?
Is it nonsense to say B > [A > B]?
Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?
Exception propagation
How to get the IP of a user who executed a command?
Was Mohammed the most popular first name for boys born in Berlin in 2018?
What is the criteria of choosing a given pin pattern in ICs?
Renting a house to a graduate student in my department
Succinct and gender-neutral Russian word for "writer"
Names of the Six Tastes
Extending Kan fibrations, without using minimal fibrations
Why use steam instead of just hot air?
date -d 'previous Monday" to display the preceding Monday
Why do Thanos' punches not kill Captain America or at least cause vital wounds?
Is there a need for better software for writers?
Different problems with tabularx
Why should password hash verification be time consistent?
Can a surprised creature fall prone voluntarily on their turn?
Remove color cast in darktable?
Passport stamps art, can it be done?
How to explain the behaviour of TreeForm?
With/Function(/etc) replacement behaviourdirect assignment to the element in a TableSome _atomic elements' TreeForm looks confusing with Level in appearanceConverting expressions to “edges” for use in TreePlot, GraphTreeForm expression that will automatically spread nodes vertically so labels do not overlapInserting symbols' definitions during read time of the codeUnderstanding the output formatting of held formsHow to stop TreeForm from shaking when changing resolution?Strange behaviour of ValueQ inside loopsStrange behaviour (or issue?) in using evaluation of held argument inside a table in Mathematica
$begingroup$
Just try this:
g=1;a=1;TreeForm[Hold[g[a]]]
The weird thing in the outcome is that the node of g displays 1 ,and a is still a.
I do not know how to explain the behaviour of TreeForm.
evaluation hold trees
$endgroup$
add a comment |
$begingroup$
Just try this:
g=1;a=1;TreeForm[Hold[g[a]]]
The weird thing in the outcome is that the node of g displays 1 ,and a is still a.
I do not know how to explain the behaviour of TreeForm.
evaluation hold trees
$endgroup$
add a comment |
$begingroup$
Just try this:
g=1;a=1;TreeForm[Hold[g[a]]]
The weird thing in the outcome is that the node of g displays 1 ,and a is still a.
I do not know how to explain the behaviour of TreeForm.
evaluation hold trees
$endgroup$
Just try this:
g=1;a=1;TreeForm[Hold[g[a]]]
The weird thing in the outcome is that the node of g displays 1 ,and a is still a.
I do not know how to explain the behaviour of TreeForm.
evaluation hold trees
evaluation hold trees
edited Apr 30 at 16:23
user64494
3,67911222
3,67911222
asked Apr 30 at 13:46
任天一任天一
1397
1397
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
I would call this a bug. Please report it to Wolfram.
IGraph/M's IGExpressionTree can handle this:
IGExpressionTree[Hold[g[a]]]

The documentation has examples that show how to get a more TreeForm-like output. Do keep in mind that the purpose of IGExpressionTree is not a perfect visualization of expressions, but simply converting fairly benign expressions to Graph (or rather to generate tree graphs which are easier to assemble as expressions). It is definitely possible to construct examples where it leaks evaluation, and I am not going to fix these if the fix would affect performance.
$endgroup$
add a comment |
$begingroup$
If the symbols with OwnValues are all on the context path, then one idea is to write the expression to a string or file, where contexts are not included, and then to block the context and context path so that all symbols are loaded in a temporary context. The symbols in the temporary context will not have OwnValues, so you can use TreeForm without worrying about leaky symbols.
There is one issue to deal with. The new symbols should only be temporary, which means the output should not contain any references to these symbols. The way to fix this is to convert the TreeForm output to boxes, and then remove the symbols before returning the TreeForm box output. I will use Export[..., "Text"] to convert the expression to a string, there may be better options:
sealedTreeForm[expr_] := With[es = ExportString[expr, "Text"],
Block[$Context="FOO`", $ContextPath="System`", "FOO`",
Internal`WithLocalSettings[
Null,
Quiet[
RawBoxes @ ToBoxes @ TreeForm @ ImportString[es],
General::shdw
],
Remove["FOO`*"]
]
]
]
Example:
g=1; a=1; sealedTreeForm[Hold[g[a]]]

$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f197382%2fhow-to-explain-the-behaviour-of-treeform%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
I would call this a bug. Please report it to Wolfram.
IGraph/M's IGExpressionTree can handle this:
IGExpressionTree[Hold[g[a]]]

The documentation has examples that show how to get a more TreeForm-like output. Do keep in mind that the purpose of IGExpressionTree is not a perfect visualization of expressions, but simply converting fairly benign expressions to Graph (or rather to generate tree graphs which are easier to assemble as expressions). It is definitely possible to construct examples where it leaks evaluation, and I am not going to fix these if the fix would affect performance.
$endgroup$
add a comment |
$begingroup$
I would call this a bug. Please report it to Wolfram.
IGraph/M's IGExpressionTree can handle this:
IGExpressionTree[Hold[g[a]]]

The documentation has examples that show how to get a more TreeForm-like output. Do keep in mind that the purpose of IGExpressionTree is not a perfect visualization of expressions, but simply converting fairly benign expressions to Graph (or rather to generate tree graphs which are easier to assemble as expressions). It is definitely possible to construct examples where it leaks evaluation, and I am not going to fix these if the fix would affect performance.
$endgroup$
add a comment |
$begingroup$
I would call this a bug. Please report it to Wolfram.
IGraph/M's IGExpressionTree can handle this:
IGExpressionTree[Hold[g[a]]]

The documentation has examples that show how to get a more TreeForm-like output. Do keep in mind that the purpose of IGExpressionTree is not a perfect visualization of expressions, but simply converting fairly benign expressions to Graph (or rather to generate tree graphs which are easier to assemble as expressions). It is definitely possible to construct examples where it leaks evaluation, and I am not going to fix these if the fix would affect performance.
$endgroup$
I would call this a bug. Please report it to Wolfram.
IGraph/M's IGExpressionTree can handle this:
IGExpressionTree[Hold[g[a]]]

The documentation has examples that show how to get a more TreeForm-like output. Do keep in mind that the purpose of IGExpressionTree is not a perfect visualization of expressions, but simply converting fairly benign expressions to Graph (or rather to generate tree graphs which are easier to assemble as expressions). It is definitely possible to construct examples where it leaks evaluation, and I am not going to fix these if the fix would affect performance.
edited Apr 30 at 15:42
answered Apr 30 at 15:19
SzabolcsSzabolcs
166k15455961
166k15455961
add a comment |
add a comment |
$begingroup$
If the symbols with OwnValues are all on the context path, then one idea is to write the expression to a string or file, where contexts are not included, and then to block the context and context path so that all symbols are loaded in a temporary context. The symbols in the temporary context will not have OwnValues, so you can use TreeForm without worrying about leaky symbols.
There is one issue to deal with. The new symbols should only be temporary, which means the output should not contain any references to these symbols. The way to fix this is to convert the TreeForm output to boxes, and then remove the symbols before returning the TreeForm box output. I will use Export[..., "Text"] to convert the expression to a string, there may be better options:
sealedTreeForm[expr_] := With[es = ExportString[expr, "Text"],
Block[$Context="FOO`", $ContextPath="System`", "FOO`",
Internal`WithLocalSettings[
Null,
Quiet[
RawBoxes @ ToBoxes @ TreeForm @ ImportString[es],
General::shdw
],
Remove["FOO`*"]
]
]
]
Example:
g=1; a=1; sealedTreeForm[Hold[g[a]]]

$endgroup$
add a comment |
$begingroup$
If the symbols with OwnValues are all on the context path, then one idea is to write the expression to a string or file, where contexts are not included, and then to block the context and context path so that all symbols are loaded in a temporary context. The symbols in the temporary context will not have OwnValues, so you can use TreeForm without worrying about leaky symbols.
There is one issue to deal with. The new symbols should only be temporary, which means the output should not contain any references to these symbols. The way to fix this is to convert the TreeForm output to boxes, and then remove the symbols before returning the TreeForm box output. I will use Export[..., "Text"] to convert the expression to a string, there may be better options:
sealedTreeForm[expr_] := With[es = ExportString[expr, "Text"],
Block[$Context="FOO`", $ContextPath="System`", "FOO`",
Internal`WithLocalSettings[
Null,
Quiet[
RawBoxes @ ToBoxes @ TreeForm @ ImportString[es],
General::shdw
],
Remove["FOO`*"]
]
]
]
Example:
g=1; a=1; sealedTreeForm[Hold[g[a]]]

$endgroup$
add a comment |
$begingroup$
If the symbols with OwnValues are all on the context path, then one idea is to write the expression to a string or file, where contexts are not included, and then to block the context and context path so that all symbols are loaded in a temporary context. The symbols in the temporary context will not have OwnValues, so you can use TreeForm without worrying about leaky symbols.
There is one issue to deal with. The new symbols should only be temporary, which means the output should not contain any references to these symbols. The way to fix this is to convert the TreeForm output to boxes, and then remove the symbols before returning the TreeForm box output. I will use Export[..., "Text"] to convert the expression to a string, there may be better options:
sealedTreeForm[expr_] := With[es = ExportString[expr, "Text"],
Block[$Context="FOO`", $ContextPath="System`", "FOO`",
Internal`WithLocalSettings[
Null,
Quiet[
RawBoxes @ ToBoxes @ TreeForm @ ImportString[es],
General::shdw
],
Remove["FOO`*"]
]
]
]
Example:
g=1; a=1; sealedTreeForm[Hold[g[a]]]

$endgroup$
If the symbols with OwnValues are all on the context path, then one idea is to write the expression to a string or file, where contexts are not included, and then to block the context and context path so that all symbols are loaded in a temporary context. The symbols in the temporary context will not have OwnValues, so you can use TreeForm without worrying about leaky symbols.
There is one issue to deal with. The new symbols should only be temporary, which means the output should not contain any references to these symbols. The way to fix this is to convert the TreeForm output to boxes, and then remove the symbols before returning the TreeForm box output. I will use Export[..., "Text"] to convert the expression to a string, there may be better options:
sealedTreeForm[expr_] := With[es = ExportString[expr, "Text"],
Block[$Context="FOO`", $ContextPath="System`", "FOO`",
Internal`WithLocalSettings[
Null,
Quiet[
RawBoxes @ ToBoxes @ TreeForm @ ImportString[es],
General::shdw
],
Remove["FOO`*"]
]
]
]
Example:
g=1; a=1; sealedTreeForm[Hold[g[a]]]

answered Apr 30 at 16:14
Carl WollCarl Woll
77.9k3102206
77.9k3102206
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f197382%2fhow-to-explain-the-behaviour-of-treeform%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown