# Inactive / Activate : basic question of how it works

I would like to understand how Inactive and Activate function works because I'm disturbed.

If I need to inactivate a function and then re activate it how to do it ? I tried the following which doesn't work :

hh[x_] := x^2

hh

4

hh = Inactive[hh]

Inactive[hh]

hh

Inactive[hh]

hh = Activate[hh]

Inactive[hh]

hh

Inactive[hh]


As you can see the function isn't reactivated as I would like it to be. I would like to understand why because it would help me to understand better how activate/inactivate functions work.

• if you use a different name for Inactive[hh] (e.g. hh1 =Inactive[hh], Activate[hh1]gives 4 as expected. – kglr Jun 27 at 12:20
• @kglr but why isn't it working as I wrote it ? Indeed in hh=Activate[hh] I would expexct mathematica to expand the rhs which would mean : hh=Activate[Inactive[hh]] thus "in a way:" hh[x]=Activate[Inactive[x^2]]=x^2. I am writing it roughly for you to see how I understand the code to give you an idea of where my misunderstanding would be – StarBucK Jun 27 at 12:27
• Defining a thing in terms of itself is not a good idea if you don't want to do recursion. For example, try hh = List[hh]: you'll see that Mathematica complains about recursion depth. The only reason that doesn't happen with Inactive is because of the HoldFirst attribute, but it's still not a good idea to do self-referential definitions like the one you posted. The only time you can do that is when hh actually has a value, such as with x = 1; x = x + 1. In that case, the self-reference is broken because x will evaluate to its value on the r.h.s. – Sjoerd Smit Jun 27 at 13:18
• @SjoerdSmit ok maybe I'm too much used to other programming language. In mathematica I should avoid to do it. Thanks ! – StarBucK Jun 27 at 13:20

When you say hh = Inactive[hh], it means "whenever you see hh, rewrite it as Inactive[hh]. Once you've made that definition, it becomes very hard to activate hh because when Activate yields hh, it immediately gets rewritten as Inactive[hh].
Look at Trace[hh = Activate[hh]]. The rewrite defeats your attempt to redefine it.