1 | initial version |
The mistake was quite stupid: The structure A
is defined over some base ring. For checking equality of the algebraic structures I used:
def __eq__(self, right):
try:
return self.base_ring() == right.base_ring()
except:
return False
However, since QQ.base_ring()
is QQ
, this meant that A
over QQ
and QQ
itself were considered equal. Hence, sage thought there is also a coercion from A
to QQ
(and not only from QQ
to A
). Therefore, for QQ(2)*A.an_element()
sage tried to convert A.an_element()
to a rational which failed. On the other hand, A.an_element()*QQ(2)
worked because QQ(2)
could indeed be converted to an element of A
. My fix was to simply change the equality function to something like
def __eq__(self, right):
if not isinstance(right, A) :
return False
try:
return self.base_ring() == right.base_ring()
except:
return False