No, this is not intentional.  Python sets the recursion limit to 1000,
to prevent infinit recursion from causing a stack overflow (in C).
Since many of our functions are highly recursive, we often run into
this limit.

You can raise it with sys.setrecursionlimit.  I set it to 10000 in
your script, and it worked.  The highest possible limit is platform
dependent, and raising it too high could cause some performance issues
(I'm not sure about this, though, you'll have to play with it).

What we need to do is rewrite as many recursive operations as we can
to be non-recursive.  Unfortunately, due to the recursive nature of
SymPy objects (nested objects in .args), some operatios lend
themselves to this very nicely.

In this particular case, it's determining if an Add is positive by
peeling off one term at a time (see line 440 of add.py), which I think
should be changed (not only is this needlessly recursive, but it's
also inefficient, because it recomputes Add.flatten each time, making
it a O(n**2) operation).

If you have an expression that isn't highly nested and you run into
this problem, it's likely that whatever algorithm causes it can be
rewritten to be non-recursive.   The real problem comes when your
expression really is highly nested.  For example, you'll have
difficulty dealing with the following expression with the default
recursion depth:

x = Symbol('x')
a
for i in xrange(1000):
    x = x*(1 - a)

Aaron Meurer

On Sun, Feb 12, 2012 at 10:48 PM, Kevin Hunter <[email protected]> wrote:
> Hullo List,
>
> I have a fairly small expression (~500 variables).  When I create a Relation
> with it, Python informs me that Sympy has exceeded the max recursion depth.
>  Is there an intentional limit to expression sizes in Sympy?
>
> Please find attached a mini-script that highlights the issue I'm
> encountering.  You should be able to just run it:
>
> $ python recreate_sympy_recursion_issue.py
>
> Thanks,
>
> Kevin
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/YPHoqiYIUuYJ.
> 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.

-- 
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