Hi all,
While I was working on a failing test in set.py in sage-on-gentoo
(and actually sage-on-mandriva) I noticed two strange things
while tracing "Primes()<Set(QQ)" in sage (compiled from the official
tarball).
First I noticed that the comparison ended with that piece of code:
ipdb>
> /home/francois/Work/sandbox/install/sage-4.4.1/local/lib/python2.6/site-
packages/sage/sets/set.py(319)__cmp__()
318 if not isinstance(right, Set_object):
--> 319 return cmp(type(right), type(Set_object))
320 return cmp(self.__object, right.__object)
ipdb>
--Return--
1
> /home/francois/Work/sandbox/install/sage-4.4.1/local/lib/python2.6/site-
packages/sage/sets/set.py(319)__cmp__()
318 if not isinstance(right, Set_object):
--> 319 return cmp(type(right), type(Set_object))
320 return cmp(self.__object, right.__object)
which means that in this branch "right" is not a Set_object.
After examination it turns out that Primes() is not a Set_object:
sage: type(Primes())
<class 'sage.sets.primes.Primes_with_category'>
So while I am expecting the sets to be compared this is not the case.
That's the first thing I find odd.
The second thing is that according to the comments of the code:
If right is not a Set compare types. If right is also a Set,
returns comparison on the underlying objects.
So I am looking at "Primes()<Set(QQ)", since we are in the fall back
option I am expecting the types of Primes() and Set(QQ) to be compared.
That is I am expecting this to happen:
cmp(type(Primes()), type(Set(QQ)))
And therefore
<class 'sage.sets.primes.Primes_with_category'> to be compared to
<class 'sage.sets.set.Set_object'>
But what happens with the current code is cmp(type(Primes()),
type(Set_object)) and what is compared is
<class 'sage.sets.primes.Primes_with_category'> and
<type 'type'>
I think the first issue is that Primes() should really be treated as a set.
The second issue I am fairly sure is bug and the code should actually
be something like
return cmp(type(right), type(self))
I think the test return the answer we expect but for the wrong reasons.
Now I returned to work out why in sage from the tarball:
sage: cmp(type(Primes()),type(sage.sets.set.Set_object))
1
and sage-on-gentoo:
sage: cmp(type(Primes()),type(sage.sets.set.Set_object))
-1
what should be the right answer (clue welcome) and which patch where causes
this.
Francois
--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org