Comment #5 on issue 3887 by smi...@gmail.com: sympy 0.7.2 hangs when trying to solve a simple algebraic equation
http://code.google.com/p/sympy/issues/detail?id=3887

after Floats are replaced with Rationals, a failure occurs when trying to convert the expression to a Poly:

e
-exp(54240381056521*alpha/250000000000) + 100
Poly(e)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\polys\polytools.py", line 95, in __new__
    return cls._from_expr(rep, opt)
  File "sympy\polys\polytools.py", line 206, in _from_expr
    return cls._from_dict(rep, opt)
  File "sympy\polys\polytools.py", line 155, in _from_dict
    return cls.new(DMP.from_dict(rep, level, domain), *gens)
  File "sympy\polys\polyclasses.py", line 255, in from_dict
    return cls(dmp_from_dict(rep, lev, dom), dom, lev)
  File "sympy\polys\densebasic.py", line 1021, in dmp_from_dict
    return dup_from_dict(f, K)
  File "sympy\polys\densebasic.py", line 971, in dup_from_dict
    for k in xrange(n, -1, -1):
OverflowError: Python int too large to convert to C long


Aaron points out that it tries to make a 54240381056521 degree polynomial, which won't work with the dense representation (it needs a list of 54240381056521 terms).

This can be seen in the solutions to the following:

Poly(exp(2*x)+3)
Poly(exp(x)**2 + 3, exp(x), domain='ZZ')

The generator is exp(x) and the expression is quadratic in that. So two solutions are obtained:

solve(exp(2*x)-3)
[log(3)/2 + I*pi, log(3)/2]

and 3 solutions are obtained if the numerator is 3:

solve(exp(3*x)-3)
[log(3**(1/3)), log(-3**(1/3)/2 - 3**(5/6)*I/2), log(-3**(1/3)/2 + 3**(5/6)*I/2)
]


And unless rational=False, something with a Float will be recast in Rational, so this, for example, also gives 3 roots:

solve(exp(.3*x)-3)
[3.66204096222703, 3.66204096222703 - 20.943951023932*I, 3.66204096222703 + 20.9
43951023932*I]


If you don't want that, you can use the rational=False flag

solve(exp(.3*x)-3,rational=False)
[3.33333333333333*log(3)]
q=14.7296138519
solve(exp(-alpha * q**2) - 0.01, alpha, rational=False)
[0.0212257459123917]

This, then, is the expected behavior at present, because Floats are recast. There is a flag to avoid this, so I would suggest marking this as WontFix.

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy-issues+unsubscr...@googlegroups.com.
To post to this group, send email to sympy-issues@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy-issues.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to