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
Python 3 - simple temperature program
Prove that a definite integral is an infinite sum
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
As a GM, is it bad form to ask for a moment to think when improvising?
Dangerous workplace travelling
Why would a military not separate its forces into different branches?
Trigonometry substitution issue with sign
Nested loops to process groups of pictures
How to pass hash as password to ssh server
How can I get people to remember my character's gender?
History of the kernel of a homomorphism?
Are there terms in German for different skull shapes?
Out of scope work duties and resignation
Why didn't this character get a funeral at the end of Avengers: Endgame?
Is Benjen dead?
Is 'contemporary' ambiguous and if so is there a better word?
Is there a word that describes the unjustified use of a more complex word?
Would a small hole in a Faraday cage drastically reduce its effectiveness at blocking interference?
Checking if two expressions are related
What do I do if my advisor made a mistake?
Formatting Datetime.now()
Can you use "едать" and "игрывать" in the present and future tenses?
When an imagined world resembles or has similarities with a famous world
Find magical solution to magical equation
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,65211222
3,65211222
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
166k15453958
166k15453958
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.1k3101202
77.1k3101202
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