4

I recently reinstalled my python environment and a code that used to work very quickly now creeps at best (usually just hangs taking up more and more memory).

The point at which the code hangs is:

solve(exp(-alpha * x**2) - 0.01, alpha)

I've been able to reproduce this problem with a fresh IPython 0.13.1 session:

In [1]: from sympy import solve, Symbol, exp
In [2]: x = 14.7296138519
In [3]: alpha = Symbol('alpha', real=True)
In [4]: solve(exp(-alpha * x**2) - 0.01, alpha)

this works for integers but also quite slow. In the original code I looped over this looking for hundreds of different alpha's for different values of x (other than 14.7296138519) and it didn't take more than a second.

any thoughts?

Shahar
  • 886
  • 1
  • 10
  • 22

3 Answers3

5

The rational=False flag was introduced for such cases as this.

>>> q=14.7296138519
>>> solve(exp(-alpha * q**2) - 0.01, alpha, rational=False)
[0.0212257459123917]

(The explanation is given in the issue cited above.)

smichr
  • 16,948
  • 2
  • 27
  • 34
  • 2
    Someone should mark this as correct. Based on rep, I'd guess @Shahar won't notice this so maybe a moderator can? – bossylobster Sep 09 '14 at 04:48
  • This parameter allows solving equations like e^(-at)=k which otherwise hang the kernel in version 3.9. Looks like this answer should be selected. – mins Oct 21 '22 at 08:04
2

Rolling back from version 0.7.2 to 0.7.1 solved this problem.

easy_install sympy==0.7.1

I've reported this as a bug to sympy's google code.

Shahar
  • 886
  • 1
  • 10
  • 22
0

I am currently running sympy ver: 1.11.1 This is for all I know the latest version. However, hanging as was described, when solving a set of 3 differential for 3 angular double differentials persist.

Eg.:

sols = solve([LE1, LE2, LE3], (the_dd, phi_dd, psi_dd),
             simplify=False, rational=False)
lepsch
  • 8,927
  • 5
  • 24
  • 44