On Sat, Aug 23, 2008 at 1:00 PM, Fredrik Johansson
<[EMAIL PROTECTED]> wrote:
>
> On Sat, Aug 23, 2008 at 9:57 PM, Nils Bruin <[EMAIL PROTECTED]> wrote:
>>
>> Would it break Python too much if comparison would simply throw an
>> exception in these cases?
>
> Hardly, considering that this is what Python itself does:
>
>>>> 1+1j > 1-1j
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: no ordering relation is defined for complex numbers
>
> Fredrik

Note by the way that this has consequences:

>>> v = [1+1j , 1-1j]
sage: v.sort()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/was/<ipython console> in <module>()

TypeError: no ordering relation is defined for complex numbers

However, these aren't too hard to deal with:

>>> v.sort( lambda x,y: cmp(str(x),str(y)) )
>>> v
[(1+1j), (1-1j)]

So, for places in our code -- e.g., roots of polynomials -- where
we want the result "sorted" for consistency of output, we could
just have a bunch of "pseudo comparison" functions.

William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@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-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to