operator +(
            double n,
            Polynomial polynomial
            )
        {
            Polynomial ret = new Polynomial(polynomial);

            ret.AddInplace(n);
            return(ret);
        }
        operator +(
            Polynomial polynomial1,
            Polynomial polynomial2
            )
        {
            Polynomial ret = new Polynomial(polynomial1);

            ret.AddInplace(polynomial2);
            return(ret);
        }
        MultiplyKaratsuba(
            double[] leftCoefficients,
            double[] rightCoefficients,
            int leftOrder,
            int rightOrder,
            int n,
            int offset
            )
        {
            if (n == 1)
            {
                return(new Polynomial(new double[] { leftCoefficients[offset] * rightCoefficients[offset] }));
            }

            if (n == 2)
            {
                return(new Polynomial(
                           new double[] {
                    leftCoefficients[offset] * rightCoefficients[offset],
                    leftCoefficients[offset] * rightCoefficients[offset + 1] + leftCoefficients[offset + 1] * rightCoefficients[offset],
                    leftCoefficients[offset + 1] * rightCoefficients[offset + 1]
                }));
            }

            n >>= 1;
            double[] FF = new double[n], GG = new double[n];
            for (int i = offset; i < n + offset; i++)
            {
                FF[i - offset] = leftCoefficients[i] + leftCoefficients[n + i];
                GG[i - offset] = rightCoefficients[i] + rightCoefficients[n + i];
            }

            Polynomial FG0 = MultiplyKaratsuba(
                leftCoefficients,
                rightCoefficients,
                n - 1,
                n - 1,
                n,
                offset
                );

            Polynomial FG1 = MultiplyKaratsuba(
                leftCoefficients,
                rightCoefficients,
                Math.Max(leftOrder - n, 0),
                Math.Max(rightOrder - n, 0),
                n,
                offset + n
                );

            Polynomial FFGG = MultiplyKaratsuba(
                FF,
                GG,
                n - 1,
                n - 1,
                n,
                0
                );

            FFGG.SubtractInplace(FG0);
            FFGG.SubtractInplace(FG1);
            FFGG.MultiplyShiftInplace(n);

            FG1.MultiplyShiftInplace(n + n);
            FG1.AddInplace(FFGG);
            FG1.AddInplace(FG0);

            return(FG1);
        }
 /// <summary>
 /// Subtract a polynomial from a real number.
 /// </summary>
 public static Polynomial operator -(
     double n,
     Polynomial polynomial
     )
 {
     Polynomial ret = new Polynomial(polynomial);
     ret.NegateInplace();
     ret.AddInplace(n);
     return ret;
 }
 /// <summary>
 /// Add a real number to a polynomial.
 /// </summary>
 public static Polynomial operator +(
     Polynomial polynomial,
     double n
     )
 {
     Polynomial ret = new Polynomial(polynomial);
     ret.AddInplace(n);
     return ret;
 }
 /// <summary>
 /// Add a polynomials to a polynomial.
 /// </summary>
 public static Polynomial operator +(
     Polynomial polynomial1,
     Polynomial polynomial2
     )
 {
     Polynomial ret = new Polynomial(polynomial1);
     ret.AddInplace(polynomial2);
     return ret;
 }
Beispiel #7
0
 AddInplace(
     Polynomial polynomial
     )
 {
     numerator.AddInplace(denominator * polynomial);
 }