/// <summary> /// Остаток от деления. С возвратом целой части /// </summary> /// <param name="a">Делимое</param> /// <param name="b">Делитель</param> /// <param name="_div">Целая цасть</param> /// <returns>Остаток</returns> public static Polynom Remainder(Polynom a, Polynom b, out Polynom _div) { if (a.Degree < b.Degree) { _div = null; return(a); } List <Monom> div = new List <Monom>(); // целая часть while (a.Degree >= b.Degree) { BigInteger current_deg = a.Degree - b.Degree; Monom c = new Monom(current_deg, 1); // целая часть от деления BigInteger currentInt = a.coefficients[0].Coefficient * Extension.Inverse(b.coefficients[0].Coefficient, b.Fp); c.MultiplyInt(currentInt); div.Add(c); Polynom temp = new Polynom(new List <Monom> { c }, a.Fp); a -= temp * b; a.NormPolynom(); } _div = new Polynom(div, a.Fp); return(a); }
/// <summary> /// Умножение монома на моном /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Monom operator *(Monom a, Monom b) { Monom c = new Monom(); c.Coefficient = a.Coefficient * b.Coefficient; c.Degree = a.Degree + b.Degree; return(c); }
/// <summary> /// Разность полиномов /// </summary> /// <param name="a">Уменьшаемое</param> /// <param name="b">Вычитаемое</param> /// <returns></returns> public static Polynom operator -(Polynom a, Polynom b) { a.NormPolynom(); b.NormPolynom(); List <Monom> c = new List <Monom>(); int curnta = 0; // Текущий элемент в полиноме а int curntb = 0; // Текущий элемент в полиноме b while (curnta < a.coefficients.Count && curntb < b.coefficients.Count) { if (a.coefficients[curnta].Degree < b.coefficients[curntb].Degree) { c.Add(Monom.Negate(b.coefficients[curntb])); curntb++; } else if (a.coefficients[curnta].Degree > b.coefficients[curntb].Degree) { c.Add(a.coefficients[curnta]); curnta++; } else { c.Add(a.coefficients[curnta].SubNumber(b.coefficients[curntb].Coefficient)); curnta++; curntb++; } } if (curnta == a.coefficients.Count) { while (curntb < b.coefficients.Count) { c.Add(Monom.Negate(b.coefficients[curntb])); curntb++; } } else if (curntb == b.coefficients.Count) { while (curnta < a.coefficients.Count) { c.Add(a.coefficients[curnta]); curnta++; } } return(new Polynom(c, a.Fp)); }
/// <summary> /// Изменяет знак коэффициента /// </summary> /// <returns></returns> static public Monom Negate(Monom a) { return(new Monom(a.Degree, BigInteger.Negate(a.Coefficient))); }