Ejemplo n.º 1
0
        public static PolynomialOverFiniteField Rem(PolynomialOverFiniteField firstArg, PolynomialOverFiniteField secondArg)
        {
            var        field     = secondArg._field;
            var        firstDeg  = firstArg.Deg;
            var        secondDeg = secondArg.Deg;
            var        newDeg    = firstDeg - secondDeg;
            var        result    = new Polynomial[newDeg + 1];
            var        reminder  = (Polynomial[])firstArg._coefficients.Clone();
            var        mod       = secondArg._mod;
            Polynomial firstLc;
            Polynomial secondLc = secondArg[secondDeg];

            for (int i = 0; i <= newDeg; i++)
            {
                firstLc            = reminder[firstDeg - i];
                result[newDeg - i] = field.Div(firstLc, secondLc);
                for (int j = 0; j <= secondDeg; j++)
                {
                    if (reminder[firstDeg - secondDeg + j - i] != null)
                    {
                        reminder[firstDeg - secondDeg + j - i] = field.Add
                                                                     (reminder[firstDeg - secondDeg + j - i], (field.Mul(result[newDeg - i], secondArg[j])));
                    }
                    else
                    {
                        reminder[firstDeg - secondDeg + j - i] = (field.Mul(result[newDeg - i], secondArg[j]));
                    }
                }
            }
            return(new PolynomialOverFiniteField(reminder, field));
        }
Ejemplo n.º 2
0
        public static PolynomialOverFiniteField Mul(PolynomialOverFiniteField firstArg, PolynomialOverFiniteField secondArg)
        {
            int firstDeg  = firstArg._deg;
            int secondDeg = secondArg._deg;
            var field     = secondArg._field;

            if (firstDeg == -1 || secondDeg == -1)
            {
                return(new PolynomialOverFiniteField(new Polynomial[] { Polynomial.Zero }, secondArg._field));
            }
            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] = field.Add(result[i + j], (field.Mul(firstArg[i], secondArg[j])));
                    }
                    else
                    {
                        result[i + j] = (field.Mul(firstArg[i], secondArg[j]));
                    }
                }
            }
            return(new PolynomialOverFiniteField(result, field));
        }
Ejemplo n.º 3
0
        public static PolynomialOverFiniteField Sub(PolynomialOverFiniteField firstArg, PolynomialOverFiniteField secondArg)
        {
            int firstDeg  = firstArg._deg;
            int secondDeg = secondArg._deg;
            var field     = secondArg._field;


            var maxDeg = Math.Max(firstDeg, secondDeg);

            if (maxDeg == -1)
            {
                return(new PolynomialOverFiniteField(new Polynomial[] { Polynomial.Zero }, field));
            }

            var result = new Polynomial[maxDeg + 1];

            if (firstDeg > secondDeg)
            {
                int i;
                for (i = 0; i <= secondDeg; i++)
                {
                    result[i] = field.Sub(firstArg[i], secondArg[i]);
                }
                for (; i <= firstDeg; i++)
                {
                    result[i] = firstArg[i];
                }
            }
            else
            {
                int i;
                for (i = 0; i <= firstDeg; i++)
                {
                    result[i] = field.Sub(firstArg[i], secondArg[i]);
                }
                for (; i <= secondDeg; i++)
                {
                    result[i] = field.Sub(Polynomial.Zero, secondArg[i]);
                }
            }

            return(new PolynomialOverFiniteField(result, field));
        }