I was using sympy's default_sort_order to sort objects.  However, I 
realized that it does not sort numerical quantities in order:

In [15]: sorted([-1, -1-sqrt(2),1+sqrt(2), pi, 4], key=default_sort_key)
Out[15]: [-1, 4, pi, 1 + sqrt(2), -sqrt(2) - 1]

The default sort key, lex, works in this case

In [16]: sorted([-1, -1-sqrt(2),1+sqrt(2), pi, 4])
Out[16]: [-sqrt(2) - 1, -1, 1 + sqrt(2), pi, 4]

but that doesn't work on symbolic objects.

Is there a way to sort that works on all sympy objects, symbolic or not, 
but still produces the normal order for numerical quantities?

The only thing I can think of is trying the lex sort key first, then 
reverting to default_sort_key on TypeError.  But, that has the undesirable 
effect of changing the relative order of numerical quantities once a 
symbolic quantity is added to the mix.

Any suggestions or pointers to a place where this is discussed already?

Thanks,
Duane

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" 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 http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/7c2f4357-6038-4dd0-8716-c80c9a38277e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to