From: Szabolcs Horvát on
On 2009.10.04. 12:44, Nasser Abbasi wrote:
> ?===
> lhs===rhs yields True if the expression lhs is identical to rhs, and yields
> False otherwise.
>
> ?==
> lhs==rhs returns True if lhs and rhs are identical.
>
> But looking at this example:
>
> a = ComplexInfinity;
> If[a == ComplexInfinity, Print["YES"]]
>
> Expecting it would print "YES", but it does not. it just returns the whole
> thing unevaluated? But
>
> If[a === ComplexInfinity, Print["YES"]]
>
> does return YES.
>
> I guess I am a little confused about the "expression" bit in the definition.
>
> So, when using the 3"=", it is looking at the _value_ of the expression, but
> when using the 2"=", it is looking at the expression _as it is_, i.e.
> without evaluating it? Is this the difference? I've always used the 2"="
> for equality, now I have to be more careful which to use.
>

=== tests for structural equivalence, without taking into account any
mathematical meaning. It yields True if and only if the FullForm of the
lhs and rhs look identical.

== tests for mathematical equivalence, AND is also used when writing
equations. ComplexInfinity == ComplexInfinity won't give true because
the phase of ComplexInfinity is undetermined. Comparing ComplexInfinity
to a finite number will always give False.

None of the two operators have any Hold* attributes, i.e. the lhs and
rhs are evaluated before the comparison is performed.

From: Leonid Shifrin on
Apparently, at the bottom of that page I made an incorrect statement: Nasser
just found an example where SameQ gives True while Equal evaluates to
itself. I should post it in the <errata> section and then eventually correct
it.

Regards,
Leonid

On Mon, Oct 5, 2009 at 3:35 PM, Chris Degnen <degnen(a)cwgsy.net> wrote:

> I refer you to Leonid's Mathematica introduction:
>
> http://www.mathprogramming-intro.org/book/node109.html
>
>
> "Nasser Abbasi" <nma(a)12000.org> asked:
> >
> > ?===
> > lhs===rhs yields True if the expression lhs is identical to rhs, and
> > yields
> > False otherwise.
> >
> > ?==
> > lhs==rhs returns True if lhs and rhs are identical.
> >
> > But looking at this example:
> >
> > a = ComplexInfinity;
> > If[a == ComplexInfinity, Print["YES"]]
> >
> > Expecting it would print "YES", but it does not. it just returns the
> whole
> > thing unevaluated? But
> >
> > If[a === ComplexInfinity, Print["YES"]]
> >
> > does return YES.
> >
> > I guess I am a little confused about the "expression" bit in the
> > definition.
> >
> > So, when using the 3"=", it is looking at the _value_ of the expression,
> > but
> > when using the 2"=", it is looking at the expression _as it is_, i.e.
> > without evaluating it? Is this the difference? I've always used the
> 2"="
> > for equality, now I have to be more careful which to use.
> >
> > --Nasser
> >
>
>
>


From: Andrzej Kozlowski on

On 5 Oct 2009, at 20:36, danl(a)wolfram.com wrote:

> he decision, which I believe only goes back a few versions, was to
> also
> treat infinities in that way. From a mathematical point of view this
> makes
> sense, and it may well be useful in the innards of some Limit code in
> avoiding what would be incorrect cancellations. (Though I have
> worked on
> that code, I do not recall all specifics, but I think we always
> carefully
> guarded against this.)

This does not seem to be quite true, at least not for all infinities.

Infinity == Infinity

True

I think this is reasonable as in a certain sense there is "only one"
positive real infinity. Similarly:
DirectedInfinity[I] == DirectedInfinity[I]

True

and so on. So, I think, as I wrote in my other message in this thread,
it is probably the case that DirectiedInfinity[] and Indeterminate are
the only symbols with this property.

I completely agree with the behaviour of Indeterminate but still have
some doubts about DirectedInfinity[] and would like to see an example
where having equality return true would cause some sort of problem or
weirdness.

Andrzej Kozlowski


From: pfalloon on
On Oct 6, 5:06 am, Daniel Lichtblau <d...(a)wolfram.com> wrote:
> d...(a)wolfram.com wrote:
> >> ?===
> >> lhs===rhs yields True if the expression lhs is identical to rhs,=
and
> >> yields
> >> False otherwise.
>
> >> ?==
> >> lhs==rhs returns True if lhs and rhs are identical.
>
> >> But looking at this example:
>
> >> a = ComplexInfinity;
> >> If[a == ComplexInfinity, Print["YES"]]
>
> >> Expecting it would print "YES", but it does not. it just returns the w=
hole
> >> thing unevaluated? But
>
> >> If[a === ComplexInfinity, Print["YES"]]
>
> >> does return YES.
>
> >> I guess I am a little confused about the "expression" bit in the
> >> definition.
>
> >> So, when using the 3"=", it is looking at the _value_ of the express=
ion,
> >> but
> >> when using the 2"=", it is looking at the expression _as it is_, i.e=
..
> >> without evaluating it? Is this the difference? I've always used =
the 2"="
> >> for equality, now I have to be more careful which to use.
>
> >> --Nasser
>
> > First some background. Usually SameQ (===) is more stringent than=
Equal
> > (==). That is to say, things might pass the Equal test but fail the=
SameQ
> > test. Here are some examples.
>
> > In[62]:= 2 == 2.0
> > Out[62]= True
>
> > In[63]:= 2 === 2.0
> > Out[63]= False
>
> > In[64]:= Sin[2]^2 + Cos[2]^2 == 1
> > Out[64]= True
>
> > In[66]:= Sin[2]^2 + Cos[2]^2 === 1
> > Out[66]= False
>
> > In[68]:= GoldenRatio == 1/2 + Sqrt[5]/2
> > Out[68]= True
>
> > In[69]:= GoldenRatio === 1/2 + Sqrt[5]/2
> > Out[69]= False
>
> > There are exceptions, and DirectedInfinity[] (the InputForm of
> > ComplexInfinity) is one such. In this case it is SameQ, but not Equal, =
to
> > itself. To try to make sense of this, consider instead Indeterminate. I
> > think it is uncontroversial that Indeterminate should not be deemed Equ=
al
> > to itself. But it is the same expression as itself, therefore SameQ to
> > itself.
>
> > The decision, which I believe only goes back a few versions, was to als=
o
> > treat infinities in that way. From a mathematical point of view this ma=
kes
> > sense, and it may well be useful in the innards of some Limit code in
> > avoiding what would be incorrect cancellations. (Though I have worked o=
n
> > that code, I do not recall all specifics, but I think we always careful=
ly
> > guarded against this.)
>
> > This has its shortcomings. For example, it is not uncommon to check
> > whether precision is finite, and handle infinite precision input
> > differently from finite. At one time I had to change code that had
> > constructs like
> > If [prec==Infinity,...]
> > to use SameQ instead of Equal.
>
> It had been pointed out to me that only ComplexInfinity seems to behave
> in this way. I suspect there was a time when we changed
> Infinity==Infinity behavior (and a code change message I have seen se=
ems
> to bear out this suspicion), but I cannot verify that such a change ever
> went into a released version of Mathematica. So I was probably just
> muddying the waters there.
>
> That said, playing with infinities is a tricky business, and considering
> them as equal when their directions agree is itself something of a
> design decision.
>
> > My point being, as a design decision this is something of a question ca=
ll.
> > I think the choice we made is the better one, but I realize there are
> > arguments against it, and there are examples where it can cause trouble=
if
> > one is not aware of the issue (or has inconveniently forgotten the lurk=
ing
> > "gotcha").
>
> > Let me address, finally, your reading of the documentation. I can only
> > conclude that the problem is at your end: clearly you cannot tell the
> > difference between "identical" and "identical". I'll report this as a
> > documentation bug of some sort.
>
> I guess I should mention that this "problem is at your end" was intended
> as irony. Documentation that uses non-identical meanings of "identical",
> with otherwise virtually identical wording, is in need of some serious
> spanking. I have filed a bug report about this.
>
> Daniel Lichtblau
> Wolfram Research

Not sure if some of this was noted previously in the thread, but the
following seems to be a reasonable interpretation of how things work:

1. When the "direction" of the infinite quantity is known, then Equal
operates on them:

In[14]:= {Infinity == Infinity, -Infinity == DirectedInfinity[-1]=
,
DirectedInfinity[1+I] == DirectedInfinity[10+10I]}

Out[14]= {True, True, True}

2. But DirectedInfinity[] represents an infinite quantity, defined as
ComplexInfinity, whose direction is unknown. This can be thought of as
the north pole of the stereographic projection of the complex plane
(if I'm remembering my complex analysis class correctly...). It is
thus sensible to avoid treating two instances of this quantity as
being equal. It's a similar story for Indeterminate (the Mathematica
equivalent of NaN):

In[19]:= {ComplexInfinity == ComplexInfinity, Indeterminate ==
Indeterminate}

Out[19]= {ComplexInfinity == ComplexInfinity,
Indeterminate == Indeterminate}

Also, note that algebraic properties of ComplexInfinity differ
slightly from directional infinite quantities:

In[25]:= {-Infinity, -ComplexInfinity}

Out[25]= {-\[Infinity], ComplexInfinity}

Cheers,
Peter.

From: Drago Ganic on
Hi Andrzej,
there is one function (Missing) and one symbol (Null) which >>should<<
behave the same as Indetereminate and ComplexInfinity but unfortunatly does
not.

In[1]:= Null == Null
Out[1]= True

In[2]:= Missing[] == Missing[]
Out[2]= True

Null is Mathematica legacy which has basically the same meaning as Missing[]
(or maybe Missing["Nonexistent"]). Missing incorporates Indetereminate via
Missing["Indeterminate"].
All of those (Indetereminate & ComplexInfinity for numeric data and
Null/Missing for any kind of data), are so called "null values" in database
systems and for them the Equal and other logical connectivities (And, Or,
Not, etc.) are overloaded. Unfortunatly this is not the case in Mathematica.

Greetings from Croatia,
Drago Ganic

"Andrzej Kozlowski" <akoz(a)mimuw.edu.pl> wrote in message
news:hacmoa$sko$1(a)smc.vnet.net...
>I amy be taking a bit of a risk here, but I would guess that
> ComplexInfinity and Indeterminate are the only symbols in Mathematica
> with this property, that is we get:
>
> a=ComplexInfinity
>
> TrueQ[Unevaluated[x == x] /. x -> a]
>
> False
>
> a = Indeterminate;
>
> TrueQ[Unevaluated[x == x] /. x -> a]
>
> False
>
> I believe that there are no other symbols for which this happens (?)
> (If I am right and it is the only one that there is no need to be
> seriously concerned or, as you say, "careful" about this issue.)
>
> Why does and Indeterminate and ComplexInfinity behave in this way? Of
> course this is a matter of design and not (for example) mathematics so
> the question really is, is this a reasonable and useful thing rather
> than if it is right. I guess it is pretty clear that since
> Indeterminate refers to a magnitude that cannot be determined, you
> would not really want to assert that two expressions, both of which
> evaluate to Indeterminate, are in any sense equal. For example it
> would seem very strange if
>
> Infinity - Infinity == Infinity/Infinity
>
> returned True (as would have to be the case if
> Indeterminate==Indeterminate returned True). Similar considerations
> perhaps apply to ComplexInfinity, which refers to a complex quantity
> with infinite magnitude but with an indeterminate argument. (However,
> I am less convinced of that in the case of ComplexInfinty than in the
> case of Indeterminate, because ComplexInfinity has a natural
> interpretation as a unique point on the Riemann sphere).
>
> (Of course === asks quite a different question and there is no doubt
> that when you have identical expressions on both sides of === the
> answer should always be True.)
>
> Andrzej Kozlowski
>
>
>
>
>
>
> On 4 Oct 2009, at 18:35, Nasser Abbasi wrote:
>
>> ?===
>> lhs===rhs yields True if the expression lhs is identical to rhs, and
>> yields
>> False otherwise.
>>
>> ?==
>> lhs==rhs returns True if lhs and rhs are identical.
>>
>> But looking at this example:
>>
>> a = ComplexInfinity;
>> If[a == ComplexInfinity, Print["YES"]]
>>
>> Expecting it would print "YES", but it does not. it just returns the
>> whole
>> thing unevaluated? But
>>
>> If[a === ComplexInfinity, Print["YES"]]
>>
>> does return YES.
>>
>> I guess I am a little confused about the "expression" bit in the
>> definition.
>>
>> So, when using the 3"=", it is looking at the _value_ of the
>> expression, but
>> when using the 2"=", it is looking at the expression _as it is_, i.e.
>> without evaluating it? Is this the difference? I've always used
>> the 2"="
>> for equality, now I have to be more careful which to use.
>>
>> --Nasser
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 4478 (20091003) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>
>


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: ListShadowPlot3D
Next: Image processing with ImageCompose