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$
6
$\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$ Apr 30 '15 at 16:14

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.