Understood.  I thought that a total order was implemented for number
field elements, but looking in the code I could not even find the
relevant _cmp_ function!

John

On 5 February 2016 at 11:49, Nathann Cohen <[email protected]> wrote:
> If the default comparison on your objects is not a total order there
> is no guarantee that the output of a sorting algorithm (name any that
> you know) will give you a unique output.
>
>     sage: sorted([{1,2},{3,4}])
>     [{1, 2}, {3, 4}]
>     sage: sorted([{3,4},{1,2}])
>     [{3, 4}, {1, 2}]
>
> Which comes from:
>
>     sage: {3,4} < {1,2}
>     False
>     sage: {3,4} > {1,2}
>     False
>
> Nathann
>
>
> On 5 February 2016 at 11:39, John Cremona <[email protected]> wrote:
>> I have two lists of 6 (relative) number field elements:  they are the
>> same up to a permutation, as revealed by turning each into a set, but
>> the do not sort to the same list!
>>
>> sage: type(L1)
>> <type 'list'>
>> sage: type(L2)
>> <type 'list'>
>> sage: type(L1[0])
>> <type 
>> 'sage.rings.number_field.number_field_element.NumberFieldElement_relative'>
>> sage: type(L2[0])
>> <type 
>> 'sage.rings.number_field.number_field_element.NumberFieldElement_relative'>
>> sage: len(L1)==len(L2)==6
>> True
>>
>> sage: L1==L2
>> False
>> sage: set(L1)==set(L2)
>> True
>> sage: sorted(L1)==sorted(L2)
>> False
>>
>> This is causing a doctest to fail randomly, since in the code I apply
>> a sort function to such lists and the output is not always the same.
>> (See #19229, where one patchbot is happy but another is not;  none of
>> the changes in that ticket affect the relevant code at all.)
>>
>> John
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "sage-devel" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/sage-devel.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to