Inactivate all occurrences of a symbol
Clash 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.)
evaluation
add a comment |Â
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.)
evaluation
add a comment |Â
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.)
evaluation
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
evaluation
asked 1 hour ago
Stalpotaten
434
434
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited 12 mins ago
answered 1 hour ago


Mr.Wizard♦
228k294671023
228k294671023
add a comment |Â
add a comment |Â
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
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
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
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
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