Test for Set equality

asked 2023-03-30 10:44:45 +0200

Emmanuel Charpentier gravatar image

Inspired by this question, I stumbled in an unexpected difficulty when trying to compare two Sets :

sage: L[:2]
[[
[ 2 -2]  [0 1]  [   0    1]
[-2  1], [0 1], [   0 -1/2]
],
 [
[ 2 -2]  [   0    1]  [0 1]
[-2  1], [   0 -1/2], [0 1]
]]
sage: Set(L[0][1:])==Set(L[1][1:])
False

Quite unexpected... However :

sage: all([u in Set(L[1][1:]) for u in Set(L[0][1:])])
True
sage: all([u in Set(L[0][1:]) for u in Set(L[1][1:])])
True

as expected.

The Sets reference doesn't mention testing forv Sets equality.

Is that a bug, an oversight or an expected behaviour ?

edit retag flag offensive close merge delete

Comments

Not sure, but making the matrices immutable as in L = [[matrix([[2,-2],[-2,1]], immutable=True), matrix([[0,1],[0,1]], immutable=True), matrix([[0,1],[0,-1/2]], immutable=True)], [matrix([[2,-2],[-2,1]], immutable=True), matrix([[0,1],[0,-1/2]], immutable=True), matrix([[0,1],[0,1]], immutable=True)]] makes the equality True.

rburing gravatar imagerburing ( 2023-03-30 16:06:24 +0200 )edit

It is known that Set is buggy for unhashable elements.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-03-30 22:43:07 +0200 )edit

Thanks, @Max Alekseyev !

Is there a ticket for that ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-03-30 22:44:51 +0200 )edit