public static IComplexPolynomial Pow(IComplexPolynomial poly, int exponent) { if (exponent < 0) { throw new NotImplementedException("Raising a polynomial to a negative exponent not supported. Build this functionality if it is needed."); } else if (exponent == 0) { return(new ComplexPolynomial(new ComplexTerm[] { new ComplexTerm(1, 0) })); } else if (exponent == 1) { return(poly.Clone()); } else if (exponent == 2) { return(Square(poly)); } IComplexPolynomial total = ComplexPolynomial.Square(poly); int counter = exponent - 2; while (counter != 0) { total = ComplexPolynomial.Multiply(total, poly); counter -= 1; } return(total); }
public static IComplexPolynomial Product(IEnumerable <IComplexPolynomial> polys) { IComplexPolynomial result = null; foreach (IComplexPolynomial p in polys) { if (result == null) { result = p; } else { result = ComplexPolynomial.Multiply(result, p); } } return(result); }
public static IComplexPolynomial Square(IComplexPolynomial poly) { return(ComplexPolynomial.Multiply(poly, poly)); }