Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 protected static PolynomialInt Addition(PolynomialInt polynomial, int scalar)
 {
     return(new PolynomialInt(
                ElementWiseOperation(
                    polynomial,
                    scalar,
                    (a, b) => a + b
                    )));
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }