comparison of PartitionTuples

asked 2019-09-18 14:00:28 -0500

heluani gravatar image

updated 2020-06-01 04:24:14 -0500

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
sage: (p,p) in P
sage: P((p,p)) == (p,p)

However as FrédericC notes below we have

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

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)
sage: T.__eq__(L)
edit retag flag offensive close merge delete



sage: P((p,p)) == [p,p]
FrédéricC gravatar imageFrédéricC ( 2019-09-18 14:29:12 -0500 )edit

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

FrédéricC gravatar imageFrédéricC ( 2019-09-19 02:16:43 -0500 )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 05:03:57 -0500 )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 05:22:39 -0500 )edit