Hi Steven,

I think you are taking this a bit too far out of what we normal use Python for in real life :-)

The mathematical complication of not having
∀x(x∈S ↔ x∈T) → S = T
be a consequence of
S = T → (∀x)(x∈S ↔ x∈T)
which may sound weird to many people, originates in the fact that the above must also hold for infinite number of elements in a set, including uncountably infinite sets and sets which have such sets as elements (including possibly uncountably infinite recursion of such inclusions). You enter a world full of wonders when you start considering such things.

In Python, however, we typically always operate on finite sets. In such a world, the above is not a complication anymore. In fact, the C implementation uses:
|S| = |T| ∧ S ⊆ T → S = T 
or written using the above form:
|S| = |T| ∧ ∀x(x∈S → x∈T) → S = T 


On 3/24/2020 11:19 AM, Steven D'Aprano wrote:
Apologies in advance... the following is going to contain mathematical 
jargon and pedantry. Run now while you still can *wink*

On Tue, Mar 24, 2020 at 12:56:55AM -0700, Andrew Barnert wrote:
On Mar 23, 2020, at 19:52, Steven D'Aprano <steve@pearwood.info> wrote:
On Mon, Mar 23, 2020 at 06:03:06PM -0700, Andrew Barnert wrote:
The existing methods are named issubset and issuperset (and
isdisjoint, which doesn’t have an operator near-equivalent). Given
that, would you still want equals instead of isequal or something?
Oops! I mean, aha, you passed my test to see if you were paying 
attention, well done!


I would be satisfied by "isequal", if the method were needed.

So, I’d rather have an uglier, more explicit, and more obviously
specific-to-set name like iscoextensive. Sure, not everyone will know
what “coextensive” means
That's an unnecessary use of jargon
As far as I’m aware (and your MathWorld search bears this out), 
“coextensive” isn’t mathematical jargon.
No, it's definitely mathematical jargon, but *really* specialised. As 
far as I can tell, it's only used by people working on the foundations 
of logic and set theory. I haven't come across it elsewhere.

For example:


"Introduction To Discrete Mathematics Via Logic And Proof" by Calvin 
Jongsma, on pages 283-4, it says:

    First-Order Logic already has a fixed, standard notation of 
    identity governed by rules of inference. S = T logically implies
    (∀x)(x∈S ↔ x∈T) [...] Thus identical sets must contain exactly
    the same elements. However we can't turn this claim around and 
    say that sets having the same elements are identical -- 
    *set equality for coextensive sets doesn't follow from logic alone.*
    We'll therefore postulate this as an axiom, using the formal 
    notation of FOL.

    Axiom 5.3.1: Axiom of Extensionality
    ∀x(x∈S ↔ x∈T) → S = T

    The crierion for equal sets (see Definition 4.1.1 follows 

    Proposition 5.3.1: Equal Sets
    S = T ↔ ∀x(x∈S ↔ x∈T)

Apologies to everyone who got lost reading that :-)

In the above quote, "identity" should be read as "equality". The 
emphasised clause "set equality for coextensive sets..." is in the 
original. The upside down A ∀ means "for all", the rounded E ∈ means 
"element of".

So translated into English, what the author is saying is that he has a 
concept of two sets being equal, S = T. He has another concept of two 
sets being coextensive, namely, that for each element in S, it is also 
in T, and vice versa. He then says that if two sets are identical 
(equal), then logically they must also be coextensive, but to go the 
other way (coextensive implies equality) we have to make it part of the 

That's a long-winded, pedantic and precise way of saying that two sets 
are equal if, and only if, they have precisely the same elements as each 
other, by definition.

I chose it because of its ordinary (if not super-common) English 

Well, you outsmarted me, or perhaps outdumbed me *smiles* because it 
definitely is a term from mathematics, whether you knew it or not.

I thought that you were referring to the mathematical usage.

As far as the non-mathematical meaning:

    being of equal extent or scope or duration;
    having the same spatial limits or boundaries;

I think we would be justified as reading `A.iscoextensive(B)` in one of 
two ways:

    len(A) == len(B)
    (min(A), max(A)) == (min(B), max(B))

but not necessarily as equal.

Why not equal? Consider somebody who started a project on the day of the 
Olypics Opening Ceremony, and finished the project on the day of the 
Closing Ceremony. We can say that the project and the Olympics were 
coextensive, but we can't necessarily say that they were equal or the 
same thing, or that the project was the Olympics.

Sure, but in math, just as in Python, a set is never equal to a list 
(with a tiny foundations asterisk that isn’t relevant, but I’ll 
mention it below).
Well, yes and no.

In Python, just as in mathematics, a set is never a superset or subset 
of a list either, and yet in Python we have a set method which quite 
happily says that a set can be a superset or subset (or equal to) a 

    {1, 2}.issubset([2, 1])  # Returns True

We understand that, unlike the operators `<` and `<=`, the issubset 
method is happy to (conceptually) coerce the list into a set.

So when mathematicians want to say a set is equal to a list… well, 
they just don’t say that, because it isn’t true, and usually isn’t 
even a meaningful question in the first place.
Don't you think that there is a sense in which the Natural numbers ℕ {0, 
1, 2, 3, ...} and the sequence (0, 1, 2, 3, ...) are "the same thing"?

We even talk about ℕ having successor and predecessor functions, which 
implies a natural order to the set.

The foundations of mathematics is one of those things which are 
extremely over-represented on the Internet
Well, you’re the only one who brought up foundations here, and in the 
same email where you’re railing against people talking about 
foundations on the internet, so I’m not sure what the point is.
Because I genuinely thought you intended to refer to the mathematical 
jargon, I didn't imagine you just got lucky.

My guess is that you saw Greg, Marc-Andre, etc. talking about sets in 
mathematics and naturally thought “oh no, here comes irrelevant 
mathematical logic”,

Um, are you confusing me with someone else? Is there something I've said 
that leads you to the conclusion that I think that being mathematical 
and logical is irrelevant?

but there isn’t any; the reason sets came up is 
that we’re talking about set operations on Python set objects, and 
it’s pretty hard to talk about what issubset means/should mean without 
talking about sets.
Oh well I'm glad you set me straight.

Marc-Andre Lemburg

Professional Python Services directly from the Experts (#1, Mar 22 2020)
>>> Python Projects, Coaching and Support ...    https://www.egenix.com/
>>> Python Product Development ...        https://consulting.egenix.com/

::: We implement business ideas - efficiently in both time and costs :::
   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611