On Jul 5, 5:48 pm, Robert Bradshaw <[EMAIL PROTECTED]>
wrote:
> 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.
>

I think I understand this, but I have one more problem. I think you're
saying that I'm supposed to get rid of __eq__ and define __cmp__
instead, with no error checking -- assume that the two arguments have
the same parent.  I have done this, and __cmp__ just checks whether
the difference x-y is the zero element of the algebra.

Now I get the following, which is good:

sage: A5.P(2) == A7.P(2)
False
sage: A5.P(2) - A5.P(2) == 0
True
sage: 2 * A5.P(2)
2 P(2)
sage: 10 * A7.P(2)  # working mod 7
3 P(2)

On the other hand,

sage: cmp(A5.P(2), A7.P(2))

gives an error message: "unsupported operand parent(s) for '-': 'mod 5
Steenrod algebra' and 'mod 7 Steenrod algebra' "

(Same thing happens with 'A5.P(2).__cmp__(A7.P(2))', but cmp(A5(3),
3)  returns 0, as it should.)

Why doesn't cmp() work, or is this what's supposed to happen?  (I can
add type-checking to the definition of __cmp__, in which case the
above command returns -1, but it sounded like you were saying that I
shouldn't have to.)

Thanks for taking the time to answer all of my silly questions, by the
way.  I think this might be the last one for now.

  John

> - 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