Inactivate all occurrences of a symbol

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












Hi crowd of knowledge,



I would like to inactivate all occurrences of a symbol to prevent it from evaluating, regardless where in the evaluation process it appears. A minimal example:



g[x_] := foo;
f[x_] := x + g[x];
Inactivate[f[2] + g[3], g]
(*== output ==*)
2 + f00 + Inactive[g][3]


My desired output would be 2 + Inactive[g][2] + Inactive[g][3].



I understand that there would be thorny issues in general how to handle scoping constructs such as Block and Module but my naïve wish is "inactivate everywhere there is a head g and don't care about anything else".



(Additional comments: I don't want to write a temporary overwriting definition of g as the function of my actual interest has several down values which take quite some time to compute. Something like [the fictitious] SetAttributes[g,NeverEvaluates] could be something though.)










share|improve this question

























    up vote
    2
    down vote

    favorite












    Hi crowd of knowledge,



    I would like to inactivate all occurrences of a symbol to prevent it from evaluating, regardless where in the evaluation process it appears. A minimal example:



    g[x_] := foo;
    f[x_] := x + g[x];
    Inactivate[f[2] + g[3], g]
    (*== output ==*)
    2 + f00 + Inactive[g][3]


    My desired output would be 2 + Inactive[g][2] + Inactive[g][3].



    I understand that there would be thorny issues in general how to handle scoping constructs such as Block and Module but my naïve wish is "inactivate everywhere there is a head g and don't care about anything else".



    (Additional comments: I don't want to write a temporary overwriting definition of g as the function of my actual interest has several down values which take quite some time to compute. Something like [the fictitious] SetAttributes[g,NeverEvaluates] could be something though.)










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Hi crowd of knowledge,



      I would like to inactivate all occurrences of a symbol to prevent it from evaluating, regardless where in the evaluation process it appears. A minimal example:



      g[x_] := foo;
      f[x_] := x + g[x];
      Inactivate[f[2] + g[3], g]
      (*== output ==*)
      2 + f00 + Inactive[g][3]


      My desired output would be 2 + Inactive[g][2] + Inactive[g][3].



      I understand that there would be thorny issues in general how to handle scoping constructs such as Block and Module but my naïve wish is "inactivate everywhere there is a head g and don't care about anything else".



      (Additional comments: I don't want to write a temporary overwriting definition of g as the function of my actual interest has several down values which take quite some time to compute. Something like [the fictitious] SetAttributes[g,NeverEvaluates] could be something though.)










      share|improve this question













      Hi crowd of knowledge,



      I would like to inactivate all occurrences of a symbol to prevent it from evaluating, regardless where in the evaluation process it appears. A minimal example:



      g[x_] := foo;
      f[x_] := x + g[x];
      Inactivate[f[2] + g[3], g]
      (*== output ==*)
      2 + f00 + Inactive[g][3]


      My desired output would be 2 + Inactive[g][2] + Inactive[g][3].



      I understand that there would be thorny issues in general how to handle scoping constructs such as Block and Module but my naïve wish is "inactivate everywhere there is a head g and don't care about anything else".



      (Additional comments: I don't want to write a temporary overwriting definition of g as the function of my actual interest has several down values which take quite some time to compute. Something like [the fictitious] SetAttributes[g,NeverEvaluates] could be something though.)







      evaluation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Stalpotaten

      434




      434




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          I believe that this works, your final paragraph notwithstanding as the downvalues of g are not lost by using Block.



          Block[g = Inactive[g], f[2] + g[3]]



          2 + Inactive[g][2] + Inactive[g][3]



          Since Inactive has HoldFirst infinite recursion does not occur.






          share|improve this answer






















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f184869%2finactivate-all-occurrences-of-a-symbol%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote













            I believe that this works, your final paragraph notwithstanding as the downvalues of g are not lost by using Block.



            Block[g = Inactive[g], f[2] + g[3]]



            2 + Inactive[g][2] + Inactive[g][3]



            Since Inactive has HoldFirst infinite recursion does not occur.






            share|improve this answer


























              up vote
              4
              down vote













              I believe that this works, your final paragraph notwithstanding as the downvalues of g are not lost by using Block.



              Block[g = Inactive[g], f[2] + g[3]]



              2 + Inactive[g][2] + Inactive[g][3]



              Since Inactive has HoldFirst infinite recursion does not occur.






              share|improve this answer
























                up vote
                4
                down vote










                up vote
                4
                down vote









                I believe that this works, your final paragraph notwithstanding as the downvalues of g are not lost by using Block.



                Block[g = Inactive[g], f[2] + g[3]]



                2 + Inactive[g][2] + Inactive[g][3]



                Since Inactive has HoldFirst infinite recursion does not occur.






                share|improve this answer














                I believe that this works, your final paragraph notwithstanding as the downvalues of g are not lost by using Block.



                Block[g = Inactive[g], f[2] + g[3]]



                2 + Inactive[g][2] + Inactive[g][3]



                Since Inactive has HoldFirst infinite recursion does not occur.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 12 mins ago

























                answered 1 hour ago









                Mr.Wizard♦

                228k294671023




                228k294671023



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184869%2finactivate-all-occurrences-of-a-symbol%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery