Message Boards Message Boards

2 Replies
6 Total Likes
View groups...
Share this post:

What uses are there for Inactive?

Posted 10 years ago

I'm curious about how people use Inactive, especially in cases when HoldForm can't replace it. Some were quite enthusiastic about its introduction.

How do you use this new feature?

POSTED BY: Szabolcs Horvát
2 Replies

Are the main uses you see educational, mostly related to step-by-step evaluation or display of unevaluated forms?

Are there other uses, e.g. code generation that was more difficult with Hold? One difficulty I see with trying to use it for code generation is that when the head of an expression is compound, its body can't be held:

Inactive[head][ (* this can't be held *) ]

Perhaps the idea is to inactivate every single head in the expression.

I am aware that NDSolve has direct support for Inactive, described here. Does Inactive tie into other functionality anywhere else?

POSTED BY: Szabolcs Horvát

The Inactive/Activate mechanism is much more versatile than HoldForm. It allows controlled evaluation of parts or all of an expression. This is certainly useful in didactic expositions (The automatic evaluation of so many expressions has always been a problem and this plugs the hole.) and it might also be useful in investigating which parts of an expression are causing a problem.

There are many examples in the Inactive help page.

Here is an example of nested Inactive expressions being evaluated. (Unfortunately I don't know how to suppress the Inactive display in the output.) We can evaluate with one command, or evaluate the inner Inactive first. Ah, but what if the inner Inactive was also a Cos? Then you have to use Map or MapAt, which you could also have done with HoldForm.

In[495]:= expr = Inactive[Cos][Inactive[ArcSin][1/2]]
Activate[expr, ArcSin]
Activate[%, Cos]
Activate[expr, ArcSin | Cos]

Out[495]= Inactive[Cos][Inactive[ArcSin][1/2]]

Out[496]= Sqrt[3]/2

Out[497]= Inactive[Cos][\[Pi]/6]

Out[498]= Sqrt[3]/2

Out[499]= Sqrt[3]/2 

With HoldForm all you can do is use ReleaseHold twice.

expr2 = HoldForm[Cos[HoldForm[ArcSin[1/2]]]];
% // ReleaseHold // ReleaseHold
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract