8
$\begingroup$

I am a little bit puzzled by the following, for me inconsistent, behaviour of Inactivate.

expr=HoldForm[f[a,b]];
Inactivate[expr] // InputForm
(* HoldForm[f[a, b]] *)

Nothing has happened. The documentation states, a little bit vague: Hold maintains expressions in unevaluated form, and all parts are inactive. With respect to the second statement, observe that the parts inside Hold are not wrapped in Inactive.

expr={HoldForm[f[a,b]]};
Inactivate[expr] // InputForm
(* {HoldForm[f[a, b]]} *)

This is as above. However:

Inactivate /@ expr // InputForm
(* {HoldForm[Inactive[f][a, b]]} *)

Mathematica has to evaluate {Inactivate[HoldForm[f[a,b]]]}, for which, according to the first example, I would have expected {HoldForm[f[a,b]]}. However, in this situation the heads have been inactivated.

Is there any documentation on this phemomenon? More precisely: under what conditions are the heads in an held expression explicitely inactivated and when not?

$\endgroup$
1
  • $\begingroup$ How very odd. Inactivate[Hold[f[a, b]]] works as expected, but the indirect approach you demonstrate does not. $\endgroup$ Dec 28, 2016 at 20:44

1 Answer 1

7
$\begingroup$

Inactivate is HoldFirst. So, it applies Inactive where it can to the unevaluated argument, and then returns the argument. In your example, expr (unevaluated) has no Head to inactivate, so Inactivate[expr] returns expr, which then evaluates to HoldForm[f[a,b]].

$\endgroup$
3
  • 1
    $\begingroup$ Further evidence in favor of this answer: expr = HoldForm[f[a, b]]; Inactivate[Evaluate@expr] // InputForm $\endgroup$
    – march
    Dec 28, 2016 at 22:11
  • $\begingroup$ That is a simple explanation! I thought it had something to do with Hold or HoldForm; that it was the HoldFirst property of Inactivate did not turn up with me. Thanks! $\endgroup$ Dec 29, 2016 at 7:24
  • $\begingroup$ Is Inactivate precisely the same as HoldFirst in all circumstances? I'm asking because I have many notebooks with delicate (and torturous) control of evaluation for metaprogramming, and I am considering diving into Inactivate to simplify them. $\endgroup$
    – Reb.Cabin
    Apr 24, 2017 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.