While finding eigenvalues for a matrix of mine, I ran into a
polynomial decompose error. It seems that when a polynomial has both a
cubic and quartic term and coefficients that consist of symbols,
factortools.py runs into trouble. To simplify the error, here is some
test code that throws the same error:
--------------------------
import sympy as sp
x = sp.Symbol('x')
z = sp.Symbol('z')
g = cos(z)*x**4 + x**3 + 1
res = sp.solve(g, x)
print res
--------------------------
which throws:
--------------------------
sympy.polys.polynomial.PolynomialError: Can't decompose cos(z)
File "C:\Documents and Settings\wflynn\My Documents\workspace\spinwaves
\spinwaves\cross_section\util\play.py", line 25, in <module>
res=sp.solve(g,x)
File "C:\Python25\Lib\site-packages\sympy\solvers\solvers.py", line
178, in solve
result = roots(poly, cubics=True, quartics=True).keys()
File "C:\Python25\Lib\site-packages\sympy\polys\rootfinding.py", line
290, in roots
_, factors = poly_factors(f)
File "C:\Python25\Lib\site-packages\sympy\polys\factortools.py", line
36, in poly_factors
F = Poly(f, *symbols)
File "C:\Python25\Lib\site-packages\sympy\polys\polynomial.py", line
389, in __new__
terms = Poly._decompose(poly.as_basic(), *symbols)
File "C:\Python25\Lib\site-packages\sympy\polys\polynomial.py", line
545, in _decompose
raise PolynomialError("Can't decompose %s" % factor)
--------------------------
It seems to only fail when there is a quartic term, cubic term and
constant term. For example:
g=cos(z)*x**4+x**3
res=sp.solve(g,x)
print res
yields
[-1/cos(z), 0]
and
g=cos(z)*x**4+1
res=sp.solve(g,x)
print res
yields
[-(-1)**(3/4)*(1/cos(z))**(1/4), -(-1)**(1/4)*(1/cos(z))**(1/4), (-1)**
(3/4)*(1/cos(z))**(1/4), (-1)**(1/4)*(1/cos(z))**(1/4)]
Anyway, seems like the offending line is in factortools.py >
poly_factors(f, *symbols, **flags).
def poly_factors(f, *symbols, **flags):
...
try:
denom, F = f.as_integer()
except CoefficientError:
other = set([])
for coeff in f.iter_coeffs():
other |= coeff.atoms(Symbol)
>>> symbols += sorted(other)
>>> F = Poly(f, *symbols)
denom, F = F.as_integer()
Here, symbol z is being added to the 'symbols' variable so then F
tries to decompose the coefficients with z in them as well.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---