import sympy as sym
import numpy as np
import math
from IPython.display import display, Math
from sympy.abc import w,x,y,z,a,b,c,d
sym.init_printing()
p1 = 2*x**3+x**2-x
p2 = x**3-x**4-4*x**2
p1
p2
p1+p2
display(Math('(%s)+(%s)=%s' %(sym.latex(p1),sym.latex(p2),sym.latex(p1+p2))))
display(Math('(%s)-(%s)=%s' %(sym.latex(p1),sym.latex(p2),sym.latex(p1-p2))))
p1 = sym.Poly(2*x**3+x**2-x)
type(p1)
p1
p1.eval(0)
p1.coeffs()
polys = [sym.Poly(2*x+x**2), sym.Poly(-x**3+4*x), sym.Poly(x**5-x**4+x/4+4)]
polys
p1.degree()
for poli in polys:
if np.mod(poli.degree(),2)==0: #poli.degree()%2==0
print('The degree of %s is even, and the coefficients sum to %g. ' %(poli.as_expr(), sum(poli.coeffs())))
else:
print('The degree of %s is odd, and there are %gcoefficients. ' %(poli.as_expr(), sum(poli.coeffs())))