On Fri, Apr 9, 2010 at 9:58 AM, Benjamin Goodrich
<[email protected]> wrote:
>
> Hi everyone,
>
> I am starting to use both the new polynomials and the new assumptions, and
> both are coming along great. They are (almost) allowing me to do a paper
> that isn't possible with 0.6.7. The "almost" is because while the
> calculations seem to work, I am running into hardware limitations.
>
> Let me try to outline my situation. I have a recursive calculation that
> manipulates polynomials in a loop. I would like to get 10 or more
> recursions, but at the moment I can only get to 6 or 7. The second to last
> thing that each loop does before it starts over is
>
> quo(first * second - third**2, fourth)
>
> where first, second, third, and fourth are multivariate polynomials, each of
> which is the sum of a bunch of symbolic terms (but the degrees are small).
>
> This is taking about 5 gigs of RAM for the last successful recursion, and I
> was hoping something can be done about that so that I can get a bit farther.
> I think the polynomial division may not be the problem per se, but expanding
>
> first * second - third**2
>
> in order to divide it by fourth is memory intensive on its own if I first do
> something like
>
> numer = expand(first * second - third**2)
>
> I am attaching a small file that has the actual polynomials involved for the
> next recursion after the last successful one. The polynomials are big so
> this is going to take a while to manipulate them (particularly third**2) but
> they can be written on disk to a 27K attachment, so I was hoping that it
> does not really require more than 5 GB of RAM to manipulate them in sympy.
>
> The other thing that might be related is that I have stack overflowed twice
> and then had to do something like
>
> sys.setrecursionlimit(10000)
>
> to continue. When it overflows the stack, the error message suggests that it
> goes deep into the assumptions stuff, i.e. there are a lot of messages like
> this
>
> INFO:stderr:  File "./sympy/core/add.py", line 274, in _eval_is_negative
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 279, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 279, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 279, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 279, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 256, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/mul.py", line 800, in _eval_is_even
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 279, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 279, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 366, in getit
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 282, in
> _what_known_about
>
> INFO:stderr:  File "./sympy/core/assumptions.py", line 340, in
> _learn_new_facts
>
> INFO:stderr:  File "./sympy/core/facts.py", line 870, in deduce_all_facts
>
> INFO:stderr:RuntimeError
> INFO:stderr::
> INFO:stderr:maximum recursion depth exceeded in cmp
> INFO:stderr:
>
> with similar things repeated over and over (the stderr log is 75K). The only
> places where I know that I utilize assumptions is that I create some of the
> symbolic variables with positive=True and I also utilize this little
> function several times at the top of the loop
>
> def pos_sqrt(x):
>     return refine(sqrt(x), Assume(x, Q.positive))
>
> Maybe the assumptions processing is what is eating up the hardware resources
> and it doesn't have much left for expanding and dividing the polynomial at
> the bottom of the loop? Or it isn't garbage collecting properly? I don't
> know that much about memory allocation in python and haven't looked at how
> sympy does things. Hopefully someone else can shed some light on this off
> the top of their head!

Do you need those assumptions to be there? I would suggest calculating
without them (don't use the positive=True thing), it could help. At
the end, you can always substitute it back, using:

.subs({"x": Symbol("x", positive=True), "y": ...})

Let me know if it helps. Another idea is that this line:

 first * second - third**2

probably isn't using polynomial arithmetics, but regular sympy
arithmetics, which will be slow and eat lots of memory. Is there a way
to do the above operations on polynomials only? I think it is and
maybe some things (like multiplication) might be already implemented,
so try to find the correct function, let's call it poly_mul, so try do
do:

poly_mul(first, second) - poly_mul(third, third)

and maybe there is some efficient way to do "-", e.g. poly_sub() or something.


All of this doesn't matter as long as the polynomials are small, but
in your case it does matter, and so you need to take advantage of what
you know about the expressions, in your case you know that they are
polynomials, and thus stay working just with them (e.g. the polys
module), and avoid converting back to Add/Mul/Pow instances.


Maybe Mateusz can bring some insight too, but he is offline till
Monday or Tuesday, and then he's coming here to Reno, so it might take
him up to a week to reply.

Ondrej

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