[sage-devel] Re: Vector space morphism equality

2011-07-26 Thread Rob Beezer
OK, maybe I figured this out.  The parent of my vector space
morphisms, a vector space homset, was not coercing a vector space
morphism properly, so when trying to compare two vector space
morphisms they had unequal parents.

For the record, this was made obvious by calling
canonical_coercion(f, g)  on the two morphisms I wanted to compare,
which raised an informative error.

Thanks for the replies, William and Jason - the key bit was buried
down in the vicinity of some comparison functions in
sage.structure.element, which I might not have found without the
hints.

Rob

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Vector space morphism equality

2011-07-26 Thread Jason Grout

On 7/26/11 12:03 PM, William Stein wrote:



On Tue, Jul 26, 2011 at 11:55 AM, Rob Beezer mailto:goo...@beezer.cotse.net>> wrote:

I've built a class for vector space morphisms, aka linear
transformations.  Mostly this just extends free module morphisms,
while making a few distinctions between behavior for vector spaces
versus modules over rings.  Everything seems to be working fine, but I
cannot get equality testing to work.

Equality testing of free module morphisms ends up in a __cmp__()
method for "matrix morphisms."  My vector space morphisms extend free
module morphisms, which in turn extend matrix morphisms.  If  f  and
g  are two free module morphisms, then

f == g,  f.__eq__(g),  f.__cmp__(g)

all employ the matrix morphism method  __cmp__()  and do the right
thing.  However, if  f  and  g  are two of my vector spaces morphisms,
then  f.__cmp__(g)  does the right thing, but  f == g   and
f.__eq__(g)  give the wrong answer (False for equal morphisms) and
never "reach down" to employ the  __cmp__  method in the base matrix
morphism class.

Any hints, or places to look for guidance?  No amount of searching the
developers guide, reference manual, or forums has landed me in the
right place.  A 95%-complete patch is up at
http://trac.sagemath.org/sage_trac/ticket/11556
which has all the details, but there is little point in wading through
all that, unless you were interested in reviewing it once
complete.  ;-)


Did you overload *both* __cmp__ *and* __hash__?



To fill in some references, please see:

http://docs.python.org/reference/datamodel.html?highlight=__hash__#object.__hash__

and

http://docs.python.org/c-api/typeobj.html?highlight=__hash__#tp_compare

in particular:

"This field is inherited by subtypes together with tp_richcompare and 
tp_hash: a subtypes inherits all three of tp_compare, tp_richcompare, 
and tp_hash when the subtype’s tp_compare, tp_richcompare, and tp_hash 
are all NULL."


I thought there was a note in the Cython documentation about the 
relationship between inheriting __cmp__ and __hash__, but I can't seem 
to find anything in either the docs or the FAQ.


Jason


--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Vector space morphism equality

2011-07-26 Thread Rob Beezer
On Jul 26, 12:03 pm, William Stein  wrote:
> Did you overload *both* __cmp__ *and* __hash__?

The matrix morphism class implements just __cmp__, with no __hash__.

Existing free module morphism class implements neither, my new vector
space morphism class implements neither.

Free module morphisms behave properly with respect to equality (eg
==), making calls to the matrix morphism __cmp__ in the process.

Vector space morphisms can "see" and use the matrix morphism __cmp__,
but the  ==  syntax won't behave properly.

Rob

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org