On Jul 5, 2008, at 12:42 PM, John H Palmieri wrote:

>>
>>
>>>> Ah, it looks like your __eq__ method is assuming that self and  
>>>> other
>>>> are elements of the steenrod algebra. There are two solutions to
>>>> this:
>>
>>>> 1) Use __cmp__ which (in Sage) will ensure that self and other have
>>>> the same parent before it's called
>>>> 2) Fix your __eq__ (and any other comparison methods you might  
>>>> have)
>>>> to make sure self-other makes sense (or, as a quick fix, catch the
>>>> type error here).
>>
>>> I still don't understand two things: why the gen method is being  
>>> used,
>>> and why if I multiply an element of SteenrodAlgebra(7) by 3, somehow
>>> elements of SteenrodAlgebra(5) are getting involved.
>>
>> I'm not seeing where the gen method is being used--it's probably to
>> get a "generic" element to see if multiplication is a viable option.
>> As for elements of SteenrodAlgebra(7) and SteenrodAlgebra(5) getting
>> compared, that's because it's looking up something in a (global-ish)
>> lookup table that happens to have SteenrodAlgebra(5) in it as well.
>> Obviously equality here should return False.
>>
>
> So, for example, for the definition of the __eq__ method for
> SteenrodAlgebraElement, replacing
>
>     difference = self - other
>     return len(difference._raw['milnor']) == 0
>
> with
>
>     if self.parent() == other.parent():
>         difference = self - other
>         return len(difference._raw['milnor']) == 0
>     else:
>         return False
>
> would be good enough?  (That is, assuming I've defined a reasonable
> __eq__ method for the parents, the SteenrodAlgebra class.)

Yes, though that will mean something like A5.P(2) - A5.P(2) == 0 will  
return False. This is why you are better off using _cmp_ instead of  
__eq__, __ne__, __le__, __gt__, ... (also, the latter are deprecated  
in Python). The _cmp_ method will always be called with two things of  
the same parent, invoking coercion if necessary.

- Robert



--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to