public static IComplexPolynomial Add(IComplexPolynomial left, IComplexPolynomial right)
        {
            if (left == null)
            {
                throw new ArgumentNullException(nameof(left));
            }
            if (right == null)
            {
                throw new ArgumentNullException(nameof(right));
            }

            Complex[] terms = new Complex[Math.Max(left.Degree, right.Degree) + 1];
            for (int i = 0; i < terms.Length; i++)
            {
                Complex l   = left[i];
                Complex r   = right[i];
                Complex ttl = (l + r);

                terms[i] = ttl;
            }

            IComplexPolynomial result = new ComplexPolynomial(ComplexTerm.GetTerms(terms.ToArray()));

            return(result);
        }
        public static IComplexPolynomial ReduceDegree(IComplexPolynomial polynomial, Complex polynomialBase)
        {
            List <Complex> coefficients       = polynomial.Terms.Select(t => t.CoEfficient).ToList();
            Complex        leadingCoefficient = coefficients.Last();

            coefficients.Remove(leadingCoefficient);

            Complex toAdd = (leadingCoefficient * polynomialBase);

            leadingCoefficient = coefficients.Last();

            Complex newLeadingCoefficient = leadingCoefficient + toAdd;

            coefficients.Remove(leadingCoefficient);
            coefficients.Add(newLeadingCoefficient);

            return(new ComplexPolynomial(ComplexTerm.GetTerms(coefficients.ToArray())));
        }
        public static IComplexPolynomial Multiply(IComplexPolynomial left, IComplexPolynomial right)
        {
            if (left == null)
            {
                throw new ArgumentNullException(nameof(left));
            }
            if (right == null)
            {
                throw new ArgumentNullException(nameof(right));
            }

            Complex[] terms = new Complex[left.Degree + right.Degree + 1];

            for (int i = 0; i <= left.Degree; i++)
            {
                for (int j = 0; j <= right.Degree; j++)
                {
                    terms[(i + j)] += Complex.Multiply(left[i], right[j]);
                }
            }

            IComplexTerm[] newTerms = ComplexTerm.GetTerms(terms);
            return(new ComplexPolynomial(newTerms));
        }
 public static IComplexPolynomial ModularInverse(IComplexPolynomial poly, Complex mod)
 {
     return(new ComplexPolynomial(ComplexTerm.GetTerms(poly.Terms.Select(trm => (mod - trm.CoEfficient).Mod(mod)).ToArray())));
 }