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)
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)
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]]))
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)
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()
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])