operator -( Polynomial polynomial, double n ) { Polynomial ret = new Polynomial(polynomial); ret.SubtractInplace(n); return(ret); }
operator -( Polynomial polynomial1, Polynomial polynomial2 ) { Polynomial ret = new Polynomial(polynomial1); ret.SubtractInplace(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 real number from a polynomial. /// </summary> public static Polynomial operator -( Polynomial polynomial, double n ) { Polynomial ret = new Polynomial(polynomial); ret.SubtractInplace(n); return ret; }
/// <summary> /// Subtract a polynomial from another polynomial. /// </summary> public static Polynomial operator -( Polynomial polynomial1, Polynomial polynomial2 ) { Polynomial ret = new Polynomial(polynomial1); ret.SubtractInplace(polynomial2); return ret; }
SubtractInplace( Polynomial polynomial ) { numerator.SubtractInplace(denominator * polynomial); }