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

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.

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?

  • $\begingroup$ How very odd. Inactivate[Hold[f[a, b]]] works as expected, but the indirect approach you demonstrate does not. $\endgroup$ – J. M.'s ennui Dec 28 '16 at 20:44

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

  • 1
    $\begingroup$ Further evidence in favor of this answer: expr = HoldForm[f[a, b]]; Inactivate[Evaluate@expr] // InputForm $\endgroup$ – march Dec 28 '16 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$ – Fred Simons Dec 29 '16 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 '17 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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