The Polys module in SymPy allows users to perform polynomial manipulations. It has methods ranging from simple operations on polynomials, such as division, GCD, and LCM, to advanced concepts, such as Gröbner bases and multivariate factorization.
The following program shows polynomial division using the div
method. This method performs polynomial division with the remainder. An argument domain may be used to specify the types of values of the argument. If the operation is to be performed only on integers, then pass domain='ZZ'
, domain='QQ'
for rational and domain='RR'
for real numbers. The expand
method expands the expression into its normal representation:
from sympy import * x, y, z = symbols('x,y,z') init_printing(use_unicode=False, wrap_line=False, no_global=True) f = 4*x**2 + 8*x + 5 g = 3*x + 1 q, r = div(f, g, domain='QQ') ## QQ for rationals q r (q*g + r).expand() q, r = div(f, g, domain='ZZ') ## ZZ for integers q r g = 4*x + 2 q, r = div(f, g, domain='ZZ...