Пример #1
0
    def __add__(self, other):
        """Addition"""
        # If we can turn the other into a rational do that
        if type(other) in [int, str, float, Rational]:
            other = QPoly([cast_to_rational(other)])
            L = poly_add(self.coef, other.coef)
            return QPoly(L)

        elif type(other) == QPoly:
            L = poly_add(self.coef, other.coef)
            return QPoly(L)

        else:
            return NotImplemented
Пример #2
0
    def __add__(self, other):
        """Addition"""
        # If we can turn the other into a rational do that
        if type(other) == int:
            other = ZPoly([other], self.M)
            L = poly_add(self.coef, other.coef)
            return ZPoly(L, self.M)

        elif type(other) == ZPoly:
            L = poly_add(self.coef, other.coef)
            return ZPoly(L, self.M)

        else:
            return NotImplemented
Пример #3
0
    def __rsub__(self, other):
        """Subtraction is NOT commutative"""
        if type(other) in [int, str, float, Rational]:
            other = QPoly([cast_to_rational(other)])

        L = poly_add(self.coef, [-c for c in other.coef])
        return QPoly(L)
Пример #4
0
    def __rsub__(self, other):
        """Subtraction is NOT commutative"""
        if type(other) == int:
            other = ZPoly([other], self.M)

        L = poly_add(self.coef, [-c for c in other.coef])
        return ZPoly(L, self.M)
Пример #5
0
    def __sub__(self, other):
        """Subtraction"""

        if type(other) not in [int, ZPoly]:
            return NotImplemented

        if type(other) == int:
            other = ZPoly([other], self.M)

        L = poly_add(self.coef, [-c for c in other.coef])
        return ZPoly(L, self.M)