def __add__(self,other): if isinstance(other,abstractPolynomial.abstractPolynomial): return composite.composite.__add__(self,other) elif (type(other) in [str,float,int]) or isinstance(other,coefficient.coefficient): return self + monomial.monomial(other) else: return NotImplemented
def __init__(self, monomials=(), coeff=coefficient.coefficient(1)): if type(monomials) not in [list,tuple]: monomials = (monomials,) monomials= tuple(monomials) self.coefficient = coeff index = 0 while index < len(monomials): if type(monomials[index]) in [coefficient.coefficient,int,float]: monomials = monomials[:index] + (monomial.monomial(monomials[index]),) + monomials[index+1:] index +=1 for i in monomials: self.coefficient = self.coefficient * i.coefficient self.monomials = tuple( [x.withCoefficientOf1() for x in monomials])
def zero(self): return monomial.monomial(0)