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













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,67911222




      3,67911222










      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

                  166k15455961




                  166k15455961





















                      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.9k3102206




                          77.9k3102206



























                              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

                              How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

                              What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

                              Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos