Exemple #1
0
        internal GenericGFPoly[] longDivide(GenericGFPoly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GenericGFPolys do not have same GenericGF field");
            }
            if (other.isZero)
            {
                throw new ArgumentException("Divide by 0");
            }

            var quotient  = field.Zero;
            var remainder = this;

            while (remainder.Degree >= other.Degree)
            {
                var degreeDifference = remainder.Degree - other.Degree;
                var shifted          = other.multiplyByMonomial(degreeDifference, 1);

                var resultOfSingleDivide = field.divide(remainder.getCoefficient(remainder.Degree),
                                                        shifted.getCoefficient(shifted.Degree));

                var iterationQuotient = new GenericGFPoly(field, new[] { resultOfSingleDivide });
                iterationQuotient = iterationQuotient.multiplyByMonomial(degreeDifference, 1);
                quotient          = quotient.addOrSubtract(iterationQuotient);

                shifted = shifted.multiply(resultOfSingleDivide);

                remainder = remainder.addOrSubtract(shifted);
            }

            return(new [] { quotient, remainder });
        }
Exemple #2
0
        internal GenericGFPoly[] divide(GenericGFPoly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GenericGFPolys do not have same GenericGF field");
            }
            if (other.isZero)
            {
                throw new ArgumentException("Divide by 0");
            }

            GenericGFPoly quotient  = field.Zero;
            GenericGFPoly remainder = this;

            int denominatorLeadingTerm        = other.getCoefficient(other.Degree);
            int inverseDenominatorLeadingTerm = field.inverse(denominatorLeadingTerm);

            while (remainder.Degree >= other.Degree && !remainder.isZero)
            {
                int           degreeDifference  = remainder.Degree - other.Degree;
                int           scale             = field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm);
                GenericGFPoly term              = other.multiplyByMonomial(degreeDifference, scale);
                GenericGFPoly iterationQuotient = field.buildMonomial(degreeDifference, scale);
                quotient  = quotient.addOrSubtract(iterationQuotient);
                remainder = remainder.addOrSubtract(term);
            }

            return(new GenericGFPoly[] { quotient, remainder });
        }
        internal GenericGFPoly[] longDivide(GenericGFPoly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GenericGFPolys do not have same GenericGF field");
            }
            if (other.isZero)
            {
                throw new ArgumentException("Divide by 0");
            }

            var quotient = field.Zero;
            var remainder = this;

            while (remainder.Degree >= other.Degree)
            {
                var degreeDifference = remainder.Degree - other.Degree;
                var shifted = other.multiplyByMonomial(degreeDifference, 1);

                var resultOfSingleDivide = field.divide(remainder.getCoefficient(remainder.Degree),
                    shifted.getCoefficient(shifted.Degree));

                var iterationQuotient = new GenericGFPoly(field, new[] { resultOfSingleDivide });
                iterationQuotient = iterationQuotient.multiplyByMonomial(degreeDifference, 1);
                quotient = quotient.addOrSubtract(iterationQuotient);

                shifted = shifted.multiply(resultOfSingleDivide);

                remainder = remainder.addOrSubtract(shifted);
            }

            return new [] { quotient, remainder };
        }
        internal GenericGFPoly[] divide(GenericGFPoly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GenericGFPolys do not have same GenericGF field");
            }
            if (other.isZero)
            {
                throw new ArgumentException("Divide by 0");
            }

            GenericGFPoly quotient = field.Zero;
            GenericGFPoly remainder = this;

            int denominatorLeadingTerm = other.getCoefficient(other.Degree);
            int inverseDenominatorLeadingTerm = field.inverse(denominatorLeadingTerm);

            while (remainder.Degree >= other.Degree && !remainder.isZero)
            {
                int degreeDifference = remainder.Degree - other.Degree;
                int scale = field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm);
                GenericGFPoly term = other.multiplyByMonomial(degreeDifference, scale);
                GenericGFPoly iterationQuotient = field.buildMonomial(degreeDifference, scale);
                quotient = quotient.addOrSubtract(iterationQuotient);
                remainder = remainder.addOrSubtract(term);
            }

            return new GenericGFPoly[] { quotient, remainder };
        }