def __rsub__(self, poly): """Subtract a polynomial from a polynomial""" if type(poly) == int: poly = ZPoly([poly]) L = poly_add(self.coef, [-c for c in poly.coef]) return ZPoly(L)
def __add__(self, poly): """Add a polynomial to a polynomial""" if type(poly) != ZPoly: poly = ZPoly([poly]) L = poly_add(self.coef, poly.coef) return ZPoly(L)
def __sub__(self,poly): """Subtract a polynomial from a polynomial""" if type(poly) != RPoly: poly = RPoly([poly]) L = poly_add(self.coef,[-c for c in poly.coef]) return RPoly(L,self)
def __sub__(self, poly): """Subtract a polynomial from a polynomial""" if type(poly) == int or type(poly) == Rational: poly = QPoly([poly]) L = poly_add(self.coef, [-c for c in poly.coef]) return QPoly(L, self)
def __add__(self, poly): """Add a polynomial to a polynomial""" if type(poly) == int or type(poly) == Rational: poly = QPoly([poly]) L = poly_add(self.coef, poly.coef) return QPoly(L)
def __rsub__(self,poly): """Subtract a polynomial from a polynomial""" if type(poly) != Polynomial: poly = Polynomial([poly]) if self.modulus != poly.modulus: raise Exception("Modulus does not match.") L = poly_add(self.coef,[-c for c in poly.coef],self.modulus) return Polynomial(L,self.modulus)
def __radd__(self,poly): """Add a polynomial to a polynomial""" if type(poly) != Polynomial: poly = Polynomial([poly]) if self.modulus != poly.modulus: raise Exception("Modulus does not match.") L = poly_add(self.coef,poly.coef,self.modulus) return Polynomial(L,self.modulus)