First off, class f(Function) is a strange way of doing things.  Why aren't you 
just using f = Function('f')?

Second, calling a bare sorted() on SymPy objects is a bad idea.  SymPy objects 
are not intended to be sorted.  In Python 3, for example, this kind of sorting 
among "uncomparable types" will not be allowed.  The problem is that sorted() 
calls < or > on the objects (i.e., __le__ or __ge__).  But SymPy overrides 
these to create Le() objects.  These should work nicely with bool(), but if you 
create a strange object like class f(Function), I guess it might not.  (by the 
way, how would others feel about making bool(Le) raise an error so that this 
kind of thing doesn't even pretend to work?)

If you want to have a canonical order of sympy objects, you should pass some 
kind of sorting key to sorted().  A good choice is hash, because it is quick 
(i.e., sorted([Symbol('x'), Real(10)], key=hash)).  hash has the disadvantage 
of being platform dependent.  In the future (i.e., the next release), we will 
have a Basic.sorted_key() function that should sort things platform 
independently (Mateusz, am I right about this?).  

Aaron Meurer

On Feb 13, 2011, at 10:46 AM, Jeff wrote:

> Hi,
> 
> I had a strange sympy error -- the last line in the code below leads
> to an infinite recursion and never ends.
> 
> import sympy
> from sympy import Function, Symbol
> 
> class f(Function):
>    pass
> 
> sorted([sympy.Real(10), Symbol('x')]) # ok
> f(10)                                 # ok
> sorted([f(10), Symbol('x')]) # error never ends
> 
> It is tested on sympy 0.6.7
> 
> I appreciate any suggestions.
> 
> Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to