simple question

41 views
Skip to first unread message

Marco Inacio

unread,
Oct 21, 2016, 3:02:19 PM10/21/16
to sympy
Hi, out of curiosity I wanted to know why does this:

from sympy.solvers import solve
from sympy import Symbol,exp
x=Symbol("x")
solve(x*10e-4+exp(x),x)

runs much faster than this:

from sympy.solvers import solve
from sympy import Symbol,exp
x=Symbol("x")
solve(x+exp(x/10e-4),x)

(?) Thanks!

Aaron Meurer

unread,
Oct 21, 2016, 3:06:55 PM10/21/16
to sy...@googlegroups.com
The difference is only a few hundred milliseconds for me on SymPy
master (it's a 4x difference, but time that small could end up
corresponding to something trivial). You'd need to profile the
functions to see the difference. LIkely one is taking a slightly
different code path than the other.

Aaron Meurer
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/e9c9c294-066b-4149-8ae9-82c7b48ed3ac%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Marco Inacio

unread,
Oct 21, 2016, 7:09:11 PM10/21/16
to sympy
Thanks, could you also run

from sympy.solvers import solve
from sympy import Symbol,exp,Eq

IS=7.443e-14; BF=1343.59; BR=62.79; VT=26.03e-3

IB=Symbol("IB")
VBE=Symbol("VTB")
E=100
RT=5
solve([Eq(IB, IS*(exp(VBE)/BF - 1/BF - 1/BR)), Eq(IB, (E - VBE*VT)/RT)], [IB, VBE])

and 

from sympy.solvers import solve
from sympy import Symbol,exp,Eq

IS=7.443e-14; BF=1343.59; BR=62.79; VT=26.03e-3

IB=Symbol("IB")
VBE=Symbol("VTB")
E=100
RT=5
solve([Eq(IB, IS*(exp(VBE/VT)/BF - 1/BF - 1/BR)), Eq(IB, (E - VBE)/RT)], [IB, VBE])

? The last one no only takes a lot of time, but is also eating lots of RAM, maybe it's something related to my computer or something that was already patched in master branch (I'm using the latest version on pip3).

As for profiling, I don't know much about it, I tried cProfile.run and the first finished with 966802 function calls (907997 primitive calls) in 2.835 seconds

The second one, I stop before finish (increasly eating RAM) with 318160249 function calls (318145924 primitive calls) in 112.793 seconds, what got my attention was
        8   82.562   10.320  112.439   14.055 densebasic.py:920(dup_from_dict)
     10/6    0.000    0.000  112.439   18.740 densebasic.py:978(dmp_from_dict)

Richard Fateman

unread,
Oct 30, 2016, 12:51:12 PM10/30/16
to sympy
Hi Marco.

I suggest you learn to use the "subject" line for something relevant.



Reply all
Reply to author
Forward
0 new messages