MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: More /.{I->-1} craziness

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106067] Re: More /.{I->-1} craziness
  • From: Vince Virgilio <blueschi at gmail.com>
  • Date: Thu, 31 Dec 2009 03:19:48 -0500 (EST)
  • References: <hhf5s3$h4o$1@smc.vnet.net>

On Dec 30, 4:17 am, AES <sieg... at stanford.edu> wrote:
> The more I play with these I->-I substitution rules, the more seemingly
> wildly inconsistent results emerge.  For example:  
>
>    In[1]:= -I/.I->-I
>
>    Out[1]= -I
>

I think 'I' compares better with simple real numbers than
transcendentals or infinities. I don't think you'd expect the
following to give 2 instead of -2.

In[52]:= -2 /. 2 -> -2

Out[52]= -2


But because of the constructive/structural nature of Mathematica, you
can make In[1] work as intended. Delay evaluation. Replace I before it
'goes atomic' (ref/AtomQ) as a Complex.

In[46]:= Hold[-I] /. HoldPattern@I -> -I

Out[46]= Hold[-(-1) I]

In[47]:= ReleaseHold@%

Out[47]= I


Or to change sign another way, again delay evaluation, where
necessary.

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

Out[41]= Hold[1 I]

In[42]:= ReleaseHold@%

Out[42]= I



Nonetheless, this is hindsight. For the unititiated, I'd say I's
behavior doesn't follow the Principle of Least Surprise (doesn't
'please') [**]. Yet I don't think there's a silver bullet for this
problem. The only way I see to mitigate it is with continual
improvements to the documentation, prompted by users such as yourself.

Vince Virgilio


[*] Reminds me of C's Usual Arithmetic Conversions: http://tinyurl.com/y85j=
c2r


  • Prev by Date: Re: Re: bug in RandomChoice if weight is zero?
  • Next by Date: Re: Re: Replace and ReplaceAll -- simple application
  • Previous by thread: Re: More /.{I->-1} craziness
  • Next by thread: Re: More /.{I->-1} craziness