Пример #1
0
    def __init__(self, monomial1=None, monomial2=None):
        """Initialize the binomial with 2 monomials.

        The arguments can also be 2-tuples in the form:
            (coefficient, degree)
        """
        if not monomial1:
            monomial1 = Monomial(1, 1)
        if not monomial2:
            monomial2 = Monomial(1, 2)
        Polynomial.__init__(self, [monomial1, monomial2], from_monomials=True)
Пример #2
0
    def __init__(self, monomial1=None, monomial2=None, monomial3=None):
        """Initialize the trinomial with 3 monomials.

        The arguments can also be 2-tuples in the form:
            (coefficient, degree)
        """
        if not monomial1:
            monomial1 = Monomial(1, 1)
        if not monomial2:
            monomial2 = Monomial(1, 2)
        if not monomial3:
            monomial3 = Monomial(1, 3)
        args = [monomial1, monomial2, monomial3]
        Polynomial.__init__(self, args, from_monomials=True)
Пример #3
0
 def complex_factors(self):
     """Return (a, (x-x_0), (x-x_1)), where x_0 and x_1 are the roots."""
     roots = self.complex_roots
     return (Constant(self.a), Polynomial([1, -roots[0]]),
             Polynomial([1, -roots[1]]))
Пример #4
0
 def __init__(self, a=1, b=1, c=1):
     """Initialize the trinomial as ax^2 + bx + c."""
     if a == 0:
         raise ValueError("Object not a quadratic trinomial since a==0!")
     Polynomial.__init__(self, a, b, c)
Пример #5
0
 def __init__(self, *args, **kwargs):
     """Create a polynomial from the args, and then freeze it."""
     Polynomial.__init__(self, *args, **kwargs)
     self._vector = tuple(self._vector)
     self._trim = self._no_op
     self._freeze()
Пример #6
0
 def __init__(self, a=1, b=1):
     """Initialize the binomial as ax + b."""
     if a == 0:
         raise ValueError("object not a linear binomial since a = 0!")
     Polynomial.__init__(self, [a, b])