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













7












$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.










share|improve this question











$endgroup$
















    7












    $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.










    share|improve this question











    $endgroup$














      7












      7








      7





      $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.










      share|improve this question











      $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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 30 at 16:23









      user64494

      3,65211222




      3,65211222










      asked Apr 30 at 13:46









      任天一任天一

      1397




      1397




















          2 Answers
          2






          active

          oldest

          votes


















          5












          $begingroup$

          I would call this a bug. Please report it to Wolfram.



          IGraph/M's IGExpressionTree can handle this:



          IGExpressionTree[Hold[g[a]]]


          enter image description here



          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.






          share|improve this answer











          $endgroup$




















            3












            $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]]]


            enter image description here






            share|improve this answer









            $endgroup$













              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
              );



              );













              draft saved

              draft discarded


















              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









              5












              $begingroup$

              I would call this a bug. Please report it to Wolfram.



              IGraph/M's IGExpressionTree can handle this:



              IGExpressionTree[Hold[g[a]]]


              enter image description here



              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.






              share|improve this answer











              $endgroup$

















                5












                $begingroup$

                I would call this a bug. Please report it to Wolfram.



                IGraph/M's IGExpressionTree can handle this:



                IGExpressionTree[Hold[g[a]]]


                enter image description here



                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.






                share|improve this answer











                $endgroup$















                  5












                  5








                  5





                  $begingroup$

                  I would call this a bug. Please report it to Wolfram.



                  IGraph/M's IGExpressionTree can handle this:



                  IGExpressionTree[Hold[g[a]]]


                  enter image description here



                  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.






                  share|improve this answer











                  $endgroup$



                  I would call this a bug. Please report it to Wolfram.



                  IGraph/M's IGExpressionTree can handle this:



                  IGExpressionTree[Hold[g[a]]]


                  enter image description here



                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 30 at 15:42

























                  answered Apr 30 at 15:19









                  SzabolcsSzabolcs

                  166k15453958




                  166k15453958





















                      3












                      $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]]]


                      enter image description here






                      share|improve this answer









                      $endgroup$

















                        3












                        $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]]]


                        enter image description here






                        share|improve this answer









                        $endgroup$















                          3












                          3








                          3





                          $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]]]


                          enter image description here






                          share|improve this answer









                          $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]]]


                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 30 at 16:14









                          Carl WollCarl Woll

                          77.1k3101202




                          77.1k3101202



























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                              Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                              Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form