As @unutbu points out, from this question you can see what factor_list
gives polynomial factors in an easier-to-use fashon.
, SymPy (. https://github.com/sympy/sympy/issues/5131). , . SymPy, , p
, .
, -
n, d = fraction(cancel(p))
factor_list(n)
factor_list(d)
.
cancel
, factor(p)
, , fraction
. p.as_numer_denom()
, ( ).
x
1/x
. ()
def aspoly1t(p, t, z=Symbol('z')):
"""
Rewrite p, a polynomial in t and 1/t, as a polynomial in t and z=1/t
"""
pa, pd = cancel(p).as_numer_denom()
pa, pd = Poly(pa, t), Poly(pd, t)
assert pd.is_monomial
d = pd.degree(t)
one_t_part = pa.slice(0, d + 1)
t_part = pa - one_t_part
t_part = t_part.to_field().quo(pd)
one_t_part = Poly.from_list(reversed(one_t_part.rep.rep), *one_t_part.gens, domain=one_t_part.domain)
one_t_part = one_t_part.replace(t, z)
ans = t_part.as_poly(t, z) + one_t_part.as_poly(t, z)
return ans
( - Poly Poly(p, x, 1/x)
). factor_list
:
>>> aspoly1t(p, x)
Poly(2*y*x**2 + 4*y*z, x, z, domain='ZZ[y]')
>>> factor_list(aspoly1t(p, x))
(2, [(Poly(y, x, y, z, domain='ZZ'), 1), (Poly(x**2 + 2*z, x, y, z, domain='ZZ'), 1)])
, , , .