Beispiel #1
0
 public static Poly GetGcd(Poly polyA, Poly polyB)
 {
     if (polyB.Degree == 0 && polyB.coefficients[0] == Fraction.ZeroFraction || polyB is null)
     {
         return(polyA);
     }
     return(GetGcd(polyB, polyA % polyB));
 }
Beispiel #2
0
        ///<summary>Возращает сначала результат деления, потом остаток от деления</summary>
        static private Tuple <Poly, Poly> LongDivision(Poly dividend, Poly divider)
        {
            if (divider.Degree == 0)
            {
                return(new Tuple <Poly, Poly>(new Poly(dividend.coefficients.Select(x => x / divider.coefficients[0]).ToArray()), new Poly(new Fraction[] { Fraction.ZeroFraction })));
            }
            var resultPolyArray = Enumerable.Repeat(Fraction.ZeroFraction, Math.Max(0, dividend.Degree - divider.Degree) + 1).ToArray();

            while (dividend.Degree >= divider.Degree)
            {
                resultPolyArray[dividend.Degree - divider.Degree] = dividend[dividend.Degree] / divider[divider.Degree];
                var tempPoly = new Poly(resultPolyArray[dividend.Degree - divider.Degree], dividend.Degree - divider.Degree);
                dividend = dividend - (tempPoly * divider);
            }
            var resultPoly = new Poly(resultPolyArray);

            return(new Tuple <Poly, Poly>(resultPoly, dividend));
        }