comparison of PartitionTuples

asked 2019-09-18 21:00:28 +0100

heluani gravatar image

updated 2023-05-11 14:12:12 +0100

FrédéricC gravatar image

I find this issue with the coercion model for PartitionTuples confusing:

sage: P = PartitionTuples(level=2)
sage: P((p,p)) in P
True
sage: (p,p) in P
True
sage: P((p,p)) == (p,p)
False

However as FrédericC notes below we have

sage: P((p,p)) == [p,p]
True

Implementing _richcmp_ and __richcmp__ both in the element and in the category does not solve this issue as they are never called. Also in the list case if one tries to compare directly using _cmp_ or their rich versions we'd get an exception. So I guess the comparison is happening at the Python level as follows:

sage: S = (p,p,p)
sage: T = P(S)
sage: L = [p,p,p]
sage: T.__eq__(S)
False
sage: T.__eq__(L)
True
edit retag flag offensive close merge delete

Comments

But

sage: P((p,p)) == [p,p]
True
FrédéricC gravatar imageFrédéricC ( 2019-09-18 21:29:12 +0100 )edit

Probably caused by the absence of a specific _richcmp_ for partition tuples.

FrédéricC gravatar imageFrédéricC ( 2019-09-19 09:16:43 +0100 )edit

It's a little more complicated than that. I've implemented _richcmp_ directly in the element class and in the category elementmethods and it never gets called. I figured it is because first Element tries to coerce. So I implemented __richcmp__ and still its never called. Same for _cmp_ and __cmp__. Calling directly coercion_model.richcmp((p,p), P(p,p), op_EQ) as expected gives FALSE. I'll update the question with your remark as well

heluani gravatar imageheluani ( 2019-09-19 12:03:57 +0100 )edit

perhaps reimplementing __eq__ in the class, but that could lead to lots of problems elsewhere so I decided against it

heluani gravatar imageheluani ( 2019-09-19 12:22:39 +0100 )edit