More than you ever wanted to know about objects [was: Is everything a refrence or isn't it]
Xavier Morel
xavier.morel at masklinn.net
Sun Jan 15 06:42:15 EST 2006
Alex Martelli wrote:
> Steve Holden <steve at holdenweb.com> wrote:
> ...
>>> 3. If two objects are equal with "==", does that
>>> mean their values are the same?
>> Almost universally, yes, although if you know enough about how the
>> interpreter works "under the hood" you can define the response of
>> instances of your own classes to the "==" operator (by defining their
>> __eq__ method), and even define a class whose instances aren't equal to
>> anything, even to themselves!
>
> Hmmm... now this may be just be, but I'm quite vary of saying that,
> since 1 == 1.0 == 1.0+0j, those three objects's values "are the same".
>
> "Are equal", sure. But I intuitively see "being the same" as a stronger
> condition than "being equal".
>
One could check use Common Lisp's "=", "eq" and "eql" operators (which
respectively check for "being equal" as in "having the same set of
values", "being very equal" as in "having the same set of values and the
same type" and "being the same" as in being exactly the same object e.g.
identity equality)
> In mathematics, 1 is not "the same" as 1.0 -- there exists a natural
> morphism of integers into reals that _maps_ 1 to 1.0, but they're still
> NOT "the same" thing. And similarly for the real-vs-complex case.
>
I disagree here, 1 and 1.0 are the same mathematical object e.g. 1 (and
the same as "1+0i"), the difference due to notation only makes sense in
computer science where integers, real and complex ensembles are disjoin.
In mathematics, Z is included in IR which is included in C (note: this
is not mathspeak, but I have no idea how to say it in english), and this
notation -- at best -- merely determines the ensemble you're currently
considering.
There is no "natural morphism" of integers into reals because there is
no mathematical difference between integers and reals, the real ensemble
is merely a superset of the integers one.
Or so it was last time i got a math course.
More information about the Python-list
mailing list