Ejemplo n.º 1
0
        public Tuple <Polynomial, Polynomial, Polynomial> FindBezoutCoefficients(Polynomial firstArg, Polynomial secondArg)
        {
            var        polyMath = new PolynomialMath(-1);
            Polynomial u0       = new Polynomial(new BigInteger[] { 1 });

            Polynomial u1 = new Polynomial(new BigInteger[] { 0 });

            Polynomial v0 = new Polynomial(new BigInteger[] { 0 });

            Polynomial v1 = new Polynomial(new BigInteger[] { 1 });

            Polynomial u2, v2, q0, r2;

            Polynomial r0 = firstArg;

            Polynomial r1 = secondArg;

            while (r1.Deg != -1)
            {
                q0 = polyMath.Div(r0, r1);
                u2 = polyMath.Sub(u0, polyMath.Mul(q0, u1));
                v2 = polyMath.Sub(v0, polyMath.Mul(q0, v1));
                r2 = polyMath.Add(polyMath.Mul(u2, firstArg), polyMath.Mul(v2, secondArg));
                r0 = r1;
                r1 = r2;
                u0 = u1;
                u1 = u2;
                v0 = v1;
                v1 = v2;
            }
            return(new Tuple <Polynomial, Polynomial, Polynomial>(u0, v0, r0));
        }
Ejemplo n.º 2
0
        public PolynomialOverFiniteField Mul(PolynomialOverFiniteField firstArg, PolynomialOverFiniteField secondArg)
        {
            int firstDeg  = firstArg.Deg;
            int secondDeg = secondArg.Deg;

            if (firstDeg == -1 || secondDeg == -1)
            {
                return(new PolynomialOverFiniteField(new Polynomial[] { new Polynomial(new BigInteger[] { 0 }) }));
            }
            int maxdegree = firstDeg + secondDeg;

            Polynomial[] result = new Polynomial[maxdegree + 1];
            for (int i = 0; i <= firstDeg; i++)
            {
                for (int j = 0; j <= secondDeg; j++)
                {
                    if (result[i + j] == null)
                    {
                        result[i + j] = new Polynomial(new BigInteger[] { 0 });
                    }
                    result[i + j] = _polynomialMath.Add(result[i + j], _polynomialMath.Mul(firstArg[i], secondArg[j]));
                }
            }
            return(new PolynomialOverFiniteField(result, Mod, FieldChar));
        }