Re: Equals, Less, Greater, etc; Confused by this simple
- To: mathgroup at smc.vnet.net
- Subject: [mg109858] Re: Equals, Less, Greater, etc; Confused by this simple
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Wed, 19 May 2010 20:16:41 -0400 (EDT)
I think we should not forget about the evaluation aspects of Mathematica: In[1]:= n = 0; a >= a /. a :> n++ Out[2]= False However, by the same logic <a> may not be equal to itself in some cases. If we use Unevaluated to simulate the situation where a==a would not evaluate, we get also: In[3]:= Unevaluated[a == a] /. a :> n++ Out[3]= False So, the question I'd ask (given the programming/evaluation aspects) is not why the rest of your expressions did not evaluate (which from that viewpoint is correct - it reflects the appreciation that by the time that <a> on the r.h.s is evaluated its value may have changed as a result of the evaluation of the l.h.s), but why the first did (a==a). I would guess this is because, in most cases (including this one), the logic is that if SameQ gives true then Equal should also. Overall, all this behavior looks to me like a deliberate design decision. Regards, Leonid On Wed, May 19, 2010 at 3:03 PM, telefunkenvf14 <rgorka at gmail.com> wrote: > Can someone offer an explanation for the following output?---I'm > trying to understand why it makes sense for Mathematica to be set up > to respond like this. (Of course, feel free to point out any glaringly > obvious math examples.) > > In[1]:= {a == a, a <= a, a >= a, a < a, a > a} > > Out[1]= {True, a <= a, a >= a, a < a, a > a} > > I would have thought that a <= a and a >= a would both evaluate to > True, given that a == a does. Also, can something really be greater > than itself? Hmmm... maybe there's hope for me after all. :) > > -RG >