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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)