Steven D'Aprano wrote:
> On Tue, May 05, 2020 at 09:34:28AM -0000, jdve...@gmail.com wrote:
> > (frozenset() == set()) is True shocked
> > me.
> > According to wikipedia https://en.wikipedia.org/wiki/Equality_(mathematics):
> > "equality is a relationship between two quantities or, more generally two 
> > mathematical
> > expressions, asserting that the quantities have the same value, or that the 
> > expressions
> > represent the same mathematical object."
> > If lists and tuples are considered different "mathematical objects" 
> > (different types), they cannot be considered equal --tough they can be 
> > equivalent, for instance ([1, 2, 3] == list((1, 2, 3)) and tuple([1, 
> > 2, 3]) == (1, 2, 3)) is True.
> > There is no good correspondence between "mathematical objects" and 
> types. Even in mathematics, it is not clear whether the integer 1 as the 
> same mathematical object as the real number 1, or the complex number 1, 
> or the quaternion 1.
> In Python, we usually say that if a type is part of the numeric tower 
> ABC, then instances with the same numeric value should be considered 
> equal even if they have different types. But that's not a hard rule, 
> just a guideline.
> And it certainly shouldn't be used as a precedent implying that 
> non-numeric values should behave the same way.
> If you are looking for a single overriding consistant principle for 
> equality in Python, I think you are going to be disappointed. Python 
> does not pretend to be a formal mathematically consistent language 
> and the only principle for equality in Python is that equality means 
> whatever the object's __eq__ method wants it to mean.
> > I can only explain (frozenset() == set()) is
> > True vs (list() == tuple()) is False if:
> > a) frozensets and sets are considered the same "mathematical
> > 
> > objects". So immutability vs mutability is not a relevant feature in 
> > Python equality context. Then, list() == tuple() should be True
> > if 
> > no other feature distinguishes lists from tuples, I suppose...
> > List and tuple are distinguished by the most important feature of all: 
> the designer's intent. Tuples are records or structs, not frozen lists, 
> which is why they are called tuple not frozen list :-) even if people 
> use them as a defacto frozen list.
> On the other hand, frozensets are frozen sets, which is why they compare 
> equal.
> Does this make 100% perfectly logical sense? Probably not. But it 
> doesn't have to. Lists and tuples are considered to be independent kinds 
> of thing, while sets and frozensets are considered to be fundamentally 
> the same kind of thing differentiated by mutability.
> (In hindsight, it might have been more logically clear if mutable sets 
> inherited from immutable frozensets, but we missed the chance to do 
> that.)

Thanks for your reply.

I do not expect any kind of full correspondence between mathematical objects 
and programming objects. Just reasoning by analogy and trying to understand how 
lists and tuples cannot be equal and frozensets and sets can be on similar 
grounds. Mostly asking than answering.

Designers' intent is an admissible answer, of course. A cat and a dog can be 
equal if equality is defined as "having the same name".

However, designers' intent is one thing, and users' understating is another one.

>From your words, I have learnt that --from designers' point of view-- tuples 
>are different from lists in their nature while sets and frozensets are mostly 
>the same kind of thing --roughly speaking of course...

I wonder if users share that view. I feel that it is not unreasonable to expect 
that frozenset and set cannot be equal on the grounds that they are different 
types (as tuples and lists are different types too). From that perspective, 
equality on tuples / lists and frozensets / sets should follow similar rules. 
Not being that way is surprising. That is all.

However, if sets and frozensets are "are considered to be fundamentally the 
same kind of thing differentiated by mutability", as you said, why not tuples 
and lists? And that is, I guess, the reasoning behind proponent's claim. What 
if the difference between tuples and lists is not so deep or relevant and they 
just differ on mutability?

Asking again...
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4AKVBC3GLGJLAQXB55NQA55KKELC6Y23/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to