protected static PolynomialInt ShiftLeft(PolynomialInt polynomial, int shift) { if (shift == 0) { return(polynomial); } shift = Math.Abs(shift); if (shift > polynomial.Length) { throw new DimensionMismatchException("Polynomial shift is greater than the length of a polynomial"); } var rawResult = new int[polynomial.Length]; for (int i = 0; i < polynomial.Length + shift; i++) { rawResult[i] = polynomial.Coefficients[i + shift]; } var result = new PolynomialInt(rawResult); return(result); }
protected static PolynomialInt Addition(PolynomialInt polynomial, int scalar) { return(new PolynomialInt( ElementWiseOperation( polynomial, scalar, (a, b) => a + b ))); }
protected static PolynomialInt Subtraction(PolynomialInt polynomialLeft, PolynomialInt polynomialRight) { var resultLength = Math.Max(polynomialLeft.Length, polynomialRight.Length); var rawResult = new int[resultLength]; for (int i = 0; i < resultLength; i++) { rawResult[i] = i < polynomialLeft.Length ? polynomialLeft.Coefficients[i] : 0 - i < polynomialRight.Length ? polynomialRight.Coefficients[i] : 0; } var result = new PolynomialInt(rawResult); return(result); }
public bool Equals(PolynomialInt other) { if (Length != other.Length) { throw new DimensionMismatchException("The length of this polynomial does not equal the length of other polynomial"); } for (var i = 0; i < Length; i++) { if (Coefficients[i] != other.Coefficients[i]) { return(false); } } return(true); }
protected static PolynomialInt Multiplication(PolynomialInt polynomialLeft, PolynomialInt polynomialRight) { if (polynomialLeft.IsZero() || polynomialRight.IsZero()) { return(Helper.ZeroPolynomialInt()); } var resultLength = polynomialLeft.Length + polynomialRight.Length; var rawResult = new int[resultLength]; for (int i = 0; i < polynomialLeft.Length; i++) { for (int j = 0; j < polynomialRight.Length; j++) { rawResult[i + j] = polynomialLeft.Coefficients[i] * polynomialRight.Coefficients[j]; } } var result = new PolynomialInt(rawResult); return(result); }