2
$\begingroup$

Mathematica 10.1 does not replace I (i.e. \[ImaginaryI], the square root of -1) inside functions with the Hold attribute. Example:

In[1]:= Hold[I] /. I -> a Out[1]= Hold[I] 

I don't understand why this happens. I have not found any other symbols with the same behavior. If I create a new symbol with the same Attributes as I, it replaces without problem.

Why is it doing this, and is it the intended behavior?

$\endgroup$

1 Answer 1

7
$\begingroup$

Because sometimes I is not I...

Hold[I] // FullForm I -> a // FullForm 

Results in:

Hold[\[ImaginaryI]] Rule[Complex[0, 1], a] 

You can see that in the first expression I is held and remains the same. However, in the second expression I is evaluated (since Rule does not have any Attributes to hold its arguments). I gets evaluated into a Complex number; and since there is no instance of Complex inside the Hold, nothing is replaced. You can get around this with HoldPattern:

Hold[I] /. HoldPattern[I] -> a (* Hold[a] *) 
$\endgroup$
1
  • 1
    $\begingroup$ Oops. I checked that I in Hold[I] was not changed but I forgot that I in rule might have been changed. $\endgroup$ Commented Apr 30, 2015 at 16:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.