Exemple #1
0
        /// <summary>
        /// Method for multiplying current bivariate polynomial by bivariate polynomial <paramref name="b"/>
        /// </summary>
        /// <param name="b">Factor</param>
        public BiVariablePolynomial Multiply(BiVariablePolynomial b)
        {
            var coeficientsArray = _coefficients.ToArray();

            _coefficients.Clear();

            if (b.IsZero)
            {
                return(this);
            }

            foreach (var coefficient in coeficientsArray)
            {
                foreach (var otherCoefficient in b._coefficients)
                {
                    FieldElement coeficientValue;
                    var          monomial = new Tuple <int, int>(coefficient.Key.Item1 + otherCoefficient.Key.Item1,
                                                                 coefficient.Key.Item2 + otherCoefficient.Key.Item2);

                    if (_coefficients.TryGetValue(monomial, out coeficientValue) == false)
                    {
                        coeficientValue         = Field.Zero();
                        _coefficients[monomial] = coeficientValue;
                    }
                    coeficientValue.Add(coefficient.Value * otherCoefficient.Value);
                }
            }

            return(RemoveZeroCoefficients());
        }
Exemple #2
0
        /// <summary>
        /// Method for subtracting bivariate polynomial <paramref name="other"/> multiplied by <paramref name="b"/> from current bivariate polynomial
        /// </summary>
        /// <param name="b">Subtrahend multiplier</param>
        /// <param name="other">Subtrahend</param>
        public BiVariablePolynomial Subtract(FieldElement b, BiVariablePolynomial other)
        {
            if (Field.Equals(b.Field) == false)
            {
                throw new ArgumentException(nameof(b));
            }
            if (Field.Equals(other.Field) == false)
            {
                throw new ArgumentException(nameof(other));
            }

            if (b.Representation == 0)
            {
                return(this);
            }

            foreach (var otherCoefficient in other._coefficients)
            {
                FieldElement coeficientValue;
                if (_coefficients.TryGetValue(otherCoefficient.Key, out coeficientValue) == false)
                {
                    coeficientValue = Field.Zero();
                    _coefficients[otherCoefficient.Key] = coeficientValue;
                }

                coeficientValue.Subtract(b * otherCoefficient.Value);
                if (coeficientValue.Representation == 0)
                {
                    _coefficients.Remove(otherCoefficient.Key);
                }
            }

            return(this);
        }
Exemple #3
0
        /// <summary>
        /// Constructor for creating copy of the bivariate polynomial <paramref name="polynomial"/>
        /// </summary>
        /// <param name="polynomial">Copied bivariate polynomial</param>
        public BiVariablePolynomial(BiVariablePolynomial polynomial)
        {
            if (polynomial == null)
            {
                throw new ArgumentNullException(nameof(polynomial));
            }

            Field = polynomial.Field;

            _coefficients = polynomial._coefficients.ToDictionary(x => x.Key, x => new FieldElement(x.Value));
        }
Exemple #4
0
        /// <summary>
        /// Method for multiplying field elemnt <paramref name="a"/> by bivariate polynomial <paramref name="b"/>
        /// </summary>
        /// <param name="a">First factor</param>
        /// <param name="b">Second factor</param>
        public static BiVariablePolynomial Multiply(FieldElement a, BiVariablePolynomial b)
        {
            var c = new BiVariablePolynomial(b);

            return(c.Multiply(a));
        }
Exemple #5
0
        /// <summary>
        /// Method for multiplying bivariate polynomial <paramref name="a"/> by field elemnt <paramref name="b"/>
        /// </summary>
        /// <param name="a">First factor</param>
        /// <param name="b">Second factor</param>
        public static BiVariablePolynomial Multiply(BiVariablePolynomial a, FieldElement b)
        {
            var c = new BiVariablePolynomial(a);

            return(c.Multiply(b));
        }
Exemple #6
0
        /// <summary>
        /// Method for subtracting bivariate polynomial <paramref name="b"/> from <paramref name="a"/>
        /// </summary>
        /// <param name="a">Minuend</param>
        /// <param name="b">Subtrahend</param>
        public static BiVariablePolynomial Subtract(BiVariablePolynomial a, BiVariablePolynomial b)
        {
            var c = new BiVariablePolynomial(a);

            return(c.Subtract(b));
        }
Exemple #7
0
        /// <summary>
        /// Method for adding bivariate polynomial <paramref name="b"/> to <paramref name="a"/>
        /// </summary>
        /// <param name="a">First term</param>
        /// <param name="b">Second term</param>
        public static BiVariablePolynomial Add(BiVariablePolynomial a, BiVariablePolynomial b)
        {
            var c = new BiVariablePolynomial(a);

            return(c.Add(b));
        }
Exemple #8
0
 /// <summary>
 /// Method for checking the equality of the current bivariate polynomial to the <paramref name="other"/>
 /// </summary>
 /// <param name="other">Another bivariate polynomial</param>
 /// <returns>Checking result</returns>
 private bool Equals(BiVariablePolynomial other)
 {
     return(_coefficients.OrderBy(x => x.Key).SequenceEqual(other._coefficients.OrderBy(x => x.Key)) &&
            Field.Equals(other.Field));
 }
Exemple #9
0
 /// <summary>
 /// Method for subtracting bivariate polynomial <paramref name="other"/> from current bivariate polynomial
 /// </summary>
 /// <param name="other">Subtrahend</param>
 public BiVariablePolynomial Subtract(BiVariablePolynomial other)
 {
     return(Subtract(Field.One(), other));
 }
Exemple #10
0
 /// <summary>
 /// Method for adding bivariate polynomial <paramref name="other"/> to current bivariate polynomial
 /// </summary>
 /// <param name="other">Term</param>
 public BiVariablePolynomial Add(BiVariablePolynomial other)
 {
     return(Add(Field.One(), other));
 }