Click here to Skip to main content
15,889,992 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to deploy your software (set up) Pin
ago248618-Apr-18 0:16
ago248618-Apr-18 0:16 
AnswerRe: how to deploy your software (set up) Pin
Gerry Schmitz18-Apr-18 6:24
mveGerry Schmitz18-Apr-18 6:24 
GeneralRe: how to deploy your software (set up) Pin
ago248618-Apr-18 6:52
ago248618-Apr-18 6:52 
GeneralRe: how to deploy your software (set up) Pin
Gerry Schmitz18-Apr-18 9:07
mveGerry Schmitz18-Apr-18 9:07 
GeneralRe: how to deploy your software (set up) Pin
ago248619-Apr-18 21:48
ago248619-Apr-18 21:48 
GeneralRe: how to deploy your software (set up) Pin
Gerry Schmitz20-Apr-18 6:22
mveGerry Schmitz20-Apr-18 6:22 
GeneralRe: how to deploy your software (set up) Pin
ago248620-Apr-18 6:30
ago248620-Apr-18 6:30 
Questionconsolidating four similar classes Pin
Alexander Kindel16-Apr-18 15:23
Alexander Kindel16-Apr-18 15:23 
I've sought guidance on this issue before, but I figure some concrete code would make it easier to get to the heart of the matter. The IntegerPolynomial, ModdedPolynomial, RationalPolynomial, and FieldElement classes are mostly the same, but with different types for the Coefficient field. I was able to factor out some of the shared algorithms, but notably not the one used by IntegerPolynomial.GetGCD() and FieldElement.GetGCD(), which makes for a pretty awful amount of code repetition. It seems like there should be a way to improve the situation with a generic polynomial class whose type parameter determines the type of the coefficients, but if I were to try to get by with just that one class, it seems like it would be messy to handle the few but significant differences between the classes as I have them now. Several methods would have to check the run-time type of the generic parameter to determine which algorithm to use, which wouldn't be so bad, but the fact that the class would need to have a Characteristic and a MinimalPolynomial field when they are each only applicable for certain types seems worse. I've tried using inheritance to specialize the generic class in different ways for different types, but I run into seemingly insurmountable difficulties where, say, the inherited arithmetic operations for IntegerPolynomial all end up returning objects of type Polynomial<integer> when I need them to return objects of type IntegerPolynomial lest I have to do a conversion every time I do invoke an operation. I also tried using extension methods, and that got very messy too. As highly redundant as it is, the way I have it now is by far the cleanest solution I've found. Any advice?

C#
static class Solver
{
    struct Division<T>
    {
        public T Quotient;
        public T Remainder;
        public Division(T quotient, T remainder)
        {
            Quotient = quotient;
            Remainder = remainder;
        }
    }
    interface IArithmetic<T>
    {
        T GetAdditiveIdentity();
        T Plus(T n);            
        T Minus(T n);
        T GetMultiplicativeIdentity();
        T Times(T n);
        Division<T> EuclideanDivideBy(T divisor);
    }
    static T GetGCD<T>(T a, T b) where T : IArithmetic<T>
    {
        T c;
        while (!b.Equals(a.GetAdditiveIdentity()))
        {
            c = b;
            b = a.EuclideanDivideBy(b).Remainder;
            a = c;
        }
        return a;
    }
    static T GetGCD<T>(List<T> list) where T : IArithmetic<T>
    {
        T GCD = list[0];
        for (int i = 1; i < list.Count; ++i)
            GCD = GetGCD(GCD, list[i]);
        return GCD;
    }
    abstract class Number : IArithmetic<Number>
    {
        ...
    }
    abstract class Rational : Number, IArithmetic<Rational>
    {
        ...
    }
    class Integer : Rational, IArithmetic<Integer>
    {
        ...
    }
    static List<T> CoefficientAdd<T>(List<T> coefficientsA, List<T> coefficientsB)
        where T : IArithmetic<T>
    {
        if (coefficientsA.Count < coefficientsB.Count)
            return CoefficientAdd(coefficientsB, coefficientsA);
        List<T> output = new List<T>(coefficientsA);
        for (int i = 0; i < coefficientsB.Count; ++i)
            output[i] = output[i].Plus(coefficientsB[i]);
        return output;
    }
    static List<T> CoefficientMultiply<T>(List<T> coefficientsA,
        List<T> coefficientsB) where T : IArithmetic<T>
    {
        List<T> output = new List<T>();
        T instance;
        if (coefficientsA.Count > 0)
            instance = coefficientsA[0];
        else if (coefficientsB.Count > 0)
            instance = coefficientsB[0];
        else
            return output;
        for (int i = 0; i < coefficientsA.Count + coefficientsB.Count - 1; ++i)
            output.Add(instance.GetAdditiveIdentity());
        for (int i = 0; i < coefficientsA.Count; ++i)
            for (int j = 0; j < coefficientsB.Count; ++j)
                output[i + j] =
                    output[i + j].Plus(coefficientsA[i].Times(coefficientsB[j]));
        return output;
    }
    static List<Integer> CoefficientGetDerivative(List<Integer> coefficients)
    {
        List<Integer> output = new List<Integer>();
        for (int i = 1; i < coefficients.Count; ++i)
            output.Add(coefficients[i] * new Integer(i));
        return output;
    }
    class IntegerPolynomial : IArithmetic<IntegerPolynomial> 
    {
        public List<Integer> Coefficients { get; }
        public IntegerPolynomial(List<Integer> coefficients)
        {
            Coefficients = new List<Integer>();
            while (coefficients.Count != 0 &&
                coefficients[coefficients.Count - 1] == Number.Zero) 
                coefficients.RemoveAt(coefficients.Count - 1);
        }
        public static IntegerPolynomial Zero = new IntegerPolynomial(new List<Integer>());
        public IntegerPolynomial GetAdditiveIdentity()
        {
            return Zero;
        }
        public IntegerPolynomial Plus(IntegerPolynomial a)
        {
            return this + a;
        }
        public static IntegerPolynomial operator +(IntegerPolynomial a, IntegerPolynomial b)
        {
            return new IntegerPolynomial(CoefficientAdd(a.Coefficients, b.Coefficients));
        }
        public IntegerPolynomial Minus(IntegerPolynomial a)
        {
            return this - a;
        }
        public IntegerPolynomial Negative()
        {
            List<Integer> output = new List<Integer>();
            foreach (Integer coefficient in Coefficients)
                output.Add(-coefficient);
            return new IntegerPolynomial(output);
        }
        public static IntegerPolynomial operator -(IntegerPolynomial a, IntegerPolynomial b)
        {
            return a + b.Negative();
        }
        public static IntegerPolynomial One =
            new IntegerPolynomial(new List<Integer> { Number.One });
        public IntegerPolynomial GetMultiplicativeIdentity()
        {
            return One;
        }
        public IntegerPolynomial Times(IntegerPolynomial a)
        {
            return this * a;
        }
        public static IntegerPolynomial operator *(IntegerPolynomial a, IntegerPolynomial b)
        {
            return new IntegerPolynomial(CoefficientMultiply(a.Coefficients, b.Coefficients));
        }            
        public static IntegerPolynomial operator *(IntegerPolynomial a, Integer b)
        {
            return a * new IntegerPolynomial(new List<Integer> { b });
        }
        public static IntegerPolynomial operator *(Integer a, IntegerPolynomial b)
        {
            return new IntegerPolynomial(new List<Integer> { a }) * b;
        }
        IntegerPolynomial DivideBy(Integer a)
        {
            List<Integer> coefficients = new List<Integer>();
            foreach (Integer coefficient in Coefficients)
                coefficients.Add(coefficient.EuclideanDivideBy(a).Quotient);
            return new IntegerPolynomial(coefficients);
        }
        public Division<IntegerPolynomial> EuclideanDivideBy(IntegerPolynomial divisor)
        {
            Division<IntegerPolynomial> division;
            List<Integer> quotient = new List<Integer>();
            List<Integer> remainder = new List<Integer>(Coefficients);
            if (divisor.Coefficients.Count <= Coefficients.Count)
                for (int i = 0; i <= Coefficients.Count - divisor.Coefficients.Count; ++i)
                {
                    Number quotientCoefficient = remainder[remainder.Count - 1] /
                        divisor.Coefficients[divisor.Coefficients.Count - 1];
                    if (quotientCoefficient is Integer integer)
                    {
                        quotient.Insert(0, integer);
                        remainder.RemoveAt(remainder.Count - 1);
                        for (int j = 1; j < divisor.Coefficients.Count; ++j)
                            remainder[remainder.Count - j] =
                                remainder[remainder.Count - j] - quotient[0] *
                                divisor.Coefficients[divisor.Coefficients.Count - j - 1];
                    }
                    else
                    {
                        division.Quotient = null;
                        division.Remainder = null;
                        return division;
                    }
                }
            division.Quotient = new IntegerPolynomial(quotient);
            division.Remainder = new IntegerPolynomial(remainder);
            return division;
        }
        public static IntegerPolynomial operator /(IntegerPolynomial a, IntegerPolynomial b)
        {
            return a.EuclideanDivideBy(b).Quotient;
        }
        public static IntegerPolynomial operator %(IntegerPolynomial a, IntegerPolynomial b)
        {
            return a.EuclideanDivideBy(b).Remainder;
        }
        public IntegerPolynomial GetDerivative()
        {
            return new IntegerPolynomial(CoefficientGetDerivative(Coefficients));
        }            
        public IntegerPolynomial GetPrimitivePart()
        {
            return DivideBy(Solver.GetGCD(Coefficients));
        }           
        public static IntegerPolynomial GetGCD(IntegerPolynomial a, IntegerPolynomial b)
        {
            if (b.Coefficients.Count > a.Coefficients.Count)
            {
                if (a.Coefficients.Count == 0)
                    return b;
                IntegerPolynomial t = a;
                a = new IntegerPolynomial(new List<Integer>(b.Coefficients));
                b = new IntegerPolynomial(new List<Integer>(t.Coefficients));
            }
            else
            {
                if (b.Coefficients.Count == 0)
                    return a;
                a = new IntegerPolynomial(new List<Integer>(a.Coefficients));
                b = new IntegerPolynomial(new List<Integer>(b.Coefficients));
            }
            Integer aContent = Solver.GetGCD(a.Coefficients);
            Integer bContent = Solver.GetGCD(b.Coefficients);
            a = a.DivideBy(aContent);
            b = b.DivideBy(bContent);
            Integer d = Solver.GetGCD(aContent, bContent);
            Integer g = Number.One;
            Number h = Number.One;
            Integer degree = new Integer(a.Coefficients.Count - b.Coefficients.Count);
            IntegerPolynomial remainder = ((Integer)b.Coefficients[b.Coefficients.Count - 1].
                Exponentiate(degree + Number.One) * a).EuclideanDivideBy(b).Remainder;
            while (remainder.Coefficients.Count > 1)
            {
                a = b;
                Number divisor = (g * h).Exponentiate(degree);
                b = remainder;
                for (int i = 0; i < b.Coefficients.Count; ++i)                    
                    b.Coefficients[i] = (Integer)(b.Coefficients[i] / divisor);                    
                g = a.Coefficients[a.Coefficients.Count - 1];
                h = h.Exponentiate(Number.One - degree) * g.Exponentiate(degree);
                degree = new Integer(a.Coefficients.Count - b.Coefficients.Count);
                remainder = ((Integer)b.Coefficients[b.Coefficients.Count - 1].Exponentiate(
                    degree + Number.One) * a).EuclideanDivideBy(b).Remainder;
            }
            if (remainder.Coefficients.Count == 1)
                return new IntegerPolynomial(new List<Integer> { d });
            return d * b.GetPrimitivePart();
        }
        public List<IntegerPolynomial> GetFactors()
        {                                
            //unique code
        }
    }
    class ModdedPolynomial : IArithmetic<ModdedPolynomial>
    {
        public List<Integer> Coefficients { get; }
        public Integer Characteristic { get; }
        public ModdedPolynomial(List<Integer> coefficients, Integer characteristic)
        {
            Coefficients = new List<Integer>();
            foreach (Integer coefficient in coefficients)
            {
                Integer remainder = coefficient.EuclideanDivideBy(characteristic).Remainder;
                if (remainder.Sign < 0)
                    Coefficients.Add(remainder + characteristic);
                else
                    Coefficients.Add(remainder);
            }
            while (Coefficients.Count != 0 &&
                Coefficients[Coefficients.Count - 1] == Number.Zero)
                Coefficients.RemoveAt(Coefficients.Count - 1);
            Characteristic = characteristic;
        }
        public ModdedPolynomial GetAdditiveIdentity()
        {
            return new ModdedPolynomial(new List<Integer>(), Characteristic);
        }
        public ModdedPolynomial Plus(ModdedPolynomial a)
        {
            return this + a;
        }
        public static ModdedPolynomial operator +(ModdedPolynomial a, ModdedPolynomial b)
        {
            return new ModdedPolynomial(CoefficientAdd(a.Coefficients, b.Coefficients),
                a.Characteristic);
        }
        public ModdedPolynomial Minus(ModdedPolynomial a)
        {
            return this - a;
        }
        public ModdedPolynomial Negative()
        {
            List<Integer> output = new List<Integer>();
            foreach (Integer coefficient in Coefficients)
                output.Add(-coefficient);
            return new ModdedPolynomial(output, Characteristic);
        }
        public static ModdedPolynomial operator -(ModdedPolynomial a, ModdedPolynomial b)
        {
            return a + b.Negative();
        }
        public ModdedPolynomial GetMultiplicativeIdentity()
        {
            return new ModdedPolynomial(new List<Integer> { Number.One }, Characteristic);
        }
        public ModdedPolynomial Times(ModdedPolynomial a)
        {
            return this * a;
        }
        public static ModdedPolynomial operator *(ModdedPolynomial a, ModdedPolynomial b)
        {
            return new ModdedPolynomial(CoefficientMultiply(a.Coefficients, b.Coefficients),
                a.Characteristic);
        }
        public static ModdedPolynomial operator *(Integer a, ModdedPolynomial b)
        {
            return new ModdedPolynomial(new List<Integer> { a }, b.Characteristic) * b;
        }
        public static ModdedPolynomial operator *(ModdedPolynomial a, Integer b)
        {
            return a * new ModdedPolynomial(new List<Integer> { b }, a.Characteristic);
        }
        public Division<ModdedPolynomial> EuclideanDivideBy(ModdedPolynomial divisor)
        {
            Division<ModdedPolynomial> division;
            List<Integer> quotient = new List<Integer>();
            List<Integer> remainder = new List<Integer>(Coefficients);
            if (divisor.Coefficients.Count <= Coefficients.Count)
                for (int i = 0; i <= Coefficients.Count - divisor.Coefficients.Count; ++i)
                {
                    quotient.Insert(0, remainder[remainder.Count - 1] *
                        divisor.Coefficients[divisor.Coefficients.Count - 1].Reciprocal(
                        Characteristic));
                    remainder.RemoveAt(remainder.Count - 1);
                    for (int j = 1; j < divisor.Coefficients.Count; ++j)
                        remainder[remainder.Count - j] =
                            remainder[remainder.Count - j] - quotient[0] *
                            divisor.Coefficients[divisor.Coefficients.Count - j - 1];
                }
            division.Quotient = new ModdedPolynomial(quotient, Characteristic);
            division.Remainder = new ModdedPolynomial(remainder, Characteristic);
            return division;
        }
        public static ModdedPolynomial operator /(ModdedPolynomial a, ModdedPolynomial b)
        {
            return a.EuclideanDivideBy(b).Quotient;
        }
        public static ModdedPolynomial operator %(ModdedPolynomial a, ModdedPolynomial b)
        {
            return a.EuclideanDivideBy(b).Remainder;
        }
        public ModdedPolynomial GetDerivative()
        {
            return new ModdedPolynomial(CoefficientGetDerivative(Coefficients), Characteristic);
        }
        public List<ModdedPolynomial> GetFactorsOfSquarefree()
        {                
            //unique code
        }            
    }
    class RationalPolynomial : IArithmetic<RationalPolynomial>
    {
        public List<Rational> Coefficients { get; }
        RationalPolynomial MinimalPolynomial;
        public RationalPolynomial(List<Rational> coefficients,
            RationalPolynomial minimalPolynomial = null)
        {                
            while (coefficients.Count != 0 &&
                coefficients[coefficients.Count - 1] == Number.Zero)
                coefficients.RemoveAt(coefficients.Count - 1);
            Coefficients = coefficients;
            MinimalPolynomial = minimalPolynomial;
        }
        public RationalPolynomial GetAdditiveIdentity()
        {
            return new RationalPolynomial(new List<Rational>(), MinimalPolynomial);
        }
        public RationalPolynomial Plus(RationalPolynomial a)
        {
            return this + a;
        }
        public static RationalPolynomial operator +(RationalPolynomial a, RationalPolynomial b)
        {
            return new RationalPolynomial(CoefficientAdd(a.Coefficients, b.Coefficients),
                a.MinimalPolynomial);
        }
        public RationalPolynomial Minus(RationalPolynomial a)
        {
            return this - a;
        }
        public RationalPolynomial Negative()
        {
            List<Rational> output = new List<Rational>();
            foreach (Rational coefficient in Coefficients)
                output.Add(-coefficient);
            return new RationalPolynomial(output, MinimalPolynomial);
        }
        public static RationalPolynomial operator -(RationalPolynomial a, RationalPolynomial b)
        {
            return a + b.Negative();
        }
        public RationalPolynomial GetMultiplicativeIdentity()
        {
            return new RationalPolynomial(new List<Rational> { Number.One }, MinimalPolynomial);
        }
        public RationalPolynomial Times(RationalPolynomial a)
        {
            return this * a;
        }
        public static RationalPolynomial operator *(RationalPolynomial a, RationalPolynomial b)
        {
            List<Rational> coefficients = CoefficientMultiply(a.Coefficients, b.Coefficients);
            for (int i = coefficients.Count; i >= a.MinimalPolynomial.Coefficients.Count; --i)
            {
                for (int j = 0; j < a.MinimalPolynomial.Coefficients.Count - 1; ++j)
                    coefficients[i - a.MinimalPolynomial.Coefficients.Count + j] -=
                        a.MinimalPolynomial.Coefficients[j];
                coefficients.RemoveAt(coefficients.Count - 1);
            }
            return new RationalPolynomial(coefficients, a.MinimalPolynomial);
        }
        public static RationalPolynomial operator *(Rational a, RationalPolynomial b)
        {
            List<Rational> coefficients = new List<Rational>();
            for (int i = 0; i < b.Coefficients.Count; ++i)
                coefficients.Add(a * b.Coefficients[i]);
            return new RationalPolynomial(new List<Rational> { a }, b.MinimalPolynomial);
        }
        public static RationalPolynomial operator *(RationalPolynomial a, Rational b)
        {
            return b * a;
        }
        public Division<RationalPolynomial> EuclideanDivideBy(RationalPolynomial divisor)
        {
            Division<RationalPolynomial> division;
            List<Rational> quotient = new List<Rational>();
            List<Rational> remainder = new List<Rational>(Coefficients);
            if (divisor.Coefficients.Count <= Coefficients.Count)
                for (int i = 0; i <= Coefficients.Count - divisor.Coefficients.Count; ++i)
                {
                    quotient.Insert(0, remainder[remainder.Count - 1] /
                        divisor.Coefficients[divisor.Coefficients.Count - 1]);
                    remainder.RemoveAt(remainder.Count - 1);
                    for (int j = 1; j < divisor.Coefficients.Count; ++j)
                        remainder[remainder.Count - j] =
                            remainder[remainder.Count - j] - quotient[0] *
                            divisor.Coefficients[divisor.Coefficients.Count - j - 1];
                }
            division.Quotient = new RationalPolynomial(quotient, MinimalPolynomial);
            division.Remainder = new RationalPolynomial(remainder, MinimalPolynomial);
            return division;
        }
        public static RationalPolynomial operator /(RationalPolynomial a, RationalPolynomial b)
        {
            return a.EuclideanDivideBy(b).Quotient;
        }
        public static RationalPolynomial operator %(RationalPolynomial a, RationalPolynomial b)
        {
            return a.EuclideanDivideBy(b).Remainder;
        }
        IntegerPolynomial GetPrimitivePart()
        {
            Integer LCM = Number.One;
            foreach (Rational coefficient in Coefficients)
                LCM *= coefficient.GetDenominatorLCM();
            List<Integer> coefficients = new List<Integer>();
            foreach (Rational coefficient in Coefficients)
                coefficients.Add((Integer)(LCM * coefficient));
            return new IntegerPolynomial(coefficients).GetPrimitivePart();
        }
        public static RationalPolynomial GetGCD(RationalPolynomial a, RationalPolynomial b)
        {
            return IntegerPolynomial.GetGCD(a.GetPrimitivePart(), b.GetPrimitivePart());
        }
        public IntegerPolynomial GetMinimalPolynomial()
        {
            //unique code
        }
        public static implicit operator RationalPolynomial(IntegerPolynomial a)
        {
            List<Rational> coefficients = new List<Rational>();
            foreach (Rational coefficient in a.Coefficients)
                coefficients.Add(coefficient);
            return new RationalPolynomial(coefficients);
        }
    }
    class FieldElement : IArithmetic<FieldElement>
    {
        public List<RationalPolynomial> Coefficients { get; }
        IntegerPolynomial MinimalPolynomial;
        public FieldElement(List<RationalPolynomial> coefficients,
            IntegerPolynomial minimalPolynomial)
        {
            Coefficients = new List<RationalPolynomial>();
            while (Coefficients.Count != 0 &&
                Coefficients[Coefficients.Count - 1].Coefficients.Count != 0) 
                Coefficients.RemoveAt(Coefficients.Count - 1);
            MinimalPolynomial = minimalPolynomial;
        }
        public FieldElement GetAdditiveIdentity()
        {
            return new FieldElement(new List<RationalPolynomial>(), MinimalPolynomial);
        }
        public FieldElement Plus(FieldElement a)
        {
            return this + a;
        }
        public static FieldElement operator +(FieldElement a, FieldElement b)
        {
            return new FieldElement(CoefficientAdd(a.Coefficients, b.Coefficients),
                a.MinimalPolynomial);
        }
        public FieldElement Minus(FieldElement a)
        {
            return this - a;
        }
        public FieldElement Negative()
        {
            List<RationalPolynomial> output = new List<RationalPolynomial>();
            foreach (RationalPolynomial coefficient in Coefficients)
                output.Add(coefficient.Negative());
            return new FieldElement(output, MinimalPolynomial);
        }
        public static FieldElement operator -(FieldElement a, FieldElement b)
        {
            return a + b.Negative();
        }
        public FieldElement GetMultiplicativeIdentity()
        {
            return new FieldElement(new List<RationalPolynomial> { new RationalPolynomial(
                new List<Rational> { Number.One }, MinimalPolynomial) }, MinimalPolynomial);
        }
        public FieldElement Times(FieldElement a)
        {
            return this * a;
        }
        public static FieldElement operator *(FieldElement a, FieldElement b)
        {
            return new FieldElement(CoefficientMultiply(a.Coefficients, b.Coefficients),
                a.MinimalPolynomial);
        }
        public static FieldElement operator *(RationalPolynomial a, FieldElement b)
        {
            List<RationalPolynomial> coefficients = new List<RationalPolynomial>();
            for (int i = 0; i < b.Coefficients.Count; ++i)
                coefficients.Add(a * b.Coefficients[i]);
            return new FieldElement(coefficients, b.MinimalPolynomial);
        }
        public static FieldElement operator *(FieldElement a, RationalPolynomial b)
        {
            return b * a;
        }
        FieldElement DivideBy(RationalPolynomial a)
        {
            List<RationalPolynomial> coefficients = new List<RationalPolynomial>();
                foreach (RationalPolynomial coefficient in Coefficients)
                    coefficients.Add(coefficient.EuclideanDivideBy(a).Quotient);
            return new FieldElement(coefficients, MinimalPolynomial);
        }
        public Division<FieldElement> EuclideanDivideBy(FieldElement divisor)
        {
            Division<FieldElement> division;
            List<RationalPolynomial> quotient = new List<RationalPolynomial>();
            List<RationalPolynomial> remainder = new List<RationalPolynomial>(Coefficients);
            if (divisor.Coefficients.Count <= Coefficients.Count)
                for (int i = 0; i <= Coefficients.Count - divisor.Coefficients.Count; ++i)
                {
                    quotient.Insert(0, remainder[remainder.Count - 1] /
                        divisor.Coefficients[divisor.Coefficients.Count - 1]);
                    remainder.RemoveAt(remainder.Count - 1);
                    for (int j = 1; j < divisor.Coefficients.Count; ++j)
                        remainder[remainder.Count - j] =
                            remainder[remainder.Count - j] - quotient[0] *
                            divisor.Coefficients[divisor.Coefficients.Count - j - 1];
                }
            division.Quotient = new FieldElement(quotient, MinimalPolynomial);
            division.Remainder = new FieldElement(remainder, MinimalPolynomial);
            return division;
        }
        FieldElement GetDerivative()
        {
            List<RationalPolynomial> coefficients = new List<RationalPolynomial>();
            for (int i = 1; i < Coefficients.Count; ++i)
                coefficients.Add(Coefficients[i] * new Integer(i));
            return new FieldElement(coefficients, MinimalPolynomial);
        }
        FieldElement GetPrimitivePart()
        {
            return DivideBy(Solver.GetGCD(Coefficients));
        }
        static FieldElement GetGCD(FieldElement a, FieldElement b)
        {
            if (b.Coefficients.Count > a.Coefficients.Count)
            {
                if (a.Coefficients.Count == 0)
                    return b;
                FieldElement t = a;
                a = new FieldElement(new List<RationalPolynomial>(b.Coefficients),
                    b.MinimalPolynomial);
                b = new FieldElement(new List<RationalPolynomial>(t.Coefficients),
                    t.MinimalPolynomial);
            }
            else
            {
                if (b.Coefficients.Count == 0)
                    return a;
                a = new FieldElement(new List<RationalPolynomial>(a.Coefficients),
                    a.MinimalPolynomial);
                b = new FieldElement(new List<RationalPolynomial>(b.Coefficients),
                    b.MinimalPolynomial);
            }
            RationalPolynomial aContent = Solver.GetGCD(a.Coefficients);
            RationalPolynomial bContent = Solver.GetGCD(b.Coefficients);
            a = a.DivideBy(aContent);
            b = b.DivideBy(bContent);
            RationalPolynomial d = Solver.GetGCD(aContent, bContent);
            RationalPolynomial g = a.Coefficients[0].GetMultiplicativeIdentity();
            RationalPolynomial h = a.Coefficients[0].GetMultiplicativeIdentity();
            Integer degree = new Integer(a.Coefficients.Count - b.Coefficients.Count);
            FieldElement remainder = (Exponentiate(b.Coefficients[b.Coefficients.Count - 1],
                degree + Number.One) * a).EuclideanDivideBy(b).Remainder;
            while (remainder.Coefficients.Count > 1)
            {
                a = b;
                b = remainder;
                for (int i = 0; i < b.Coefficients.Count; ++i)
                    b.Coefficients[i] = b.Coefficients[i] / Exponentiate(g * h, degree);
                g = a.Coefficients[a.Coefficients.Count - 1];
                h = Exponentiate(h, Number.One - degree) * Exponentiate(g, degree);
                degree = new Integer(a.Coefficients.Count - b.Coefficients.Count);
                remainder = (Exponentiate(b.Coefficients[b.Coefficients.Count - 1],
                    degree + Number.One) * a).EuclideanDivideBy(b).Remainder;
            }
            return d * b.GetPrimitivePart();
        }
    }
}

AnswerRe: consolidating four similar classes Pin
#realJSOP17-Apr-18 2:24
mve#realJSOP17-Apr-18 2:24 
GeneralRe: consolidating four similar classes Pin
Alexander Kindel17-Apr-18 11:34
Alexander Kindel17-Apr-18 11:34 
GeneralRe: consolidating four similar classes Pin
#realJSOP17-Apr-18 12:33
mve#realJSOP17-Apr-18 12:33 
GeneralRe: consolidating four similar classes Pin
Alexander Kindel17-Apr-18 16:53
Alexander Kindel17-Apr-18 16:53 
GeneralRe: consolidating four similar classes Pin
#realJSOP19-Apr-18 2:50
mve#realJSOP19-Apr-18 2:50 
AnswerRe: consolidating four similar classes Pin
Gerry Schmitz18-Apr-18 7:05
mveGerry Schmitz18-Apr-18 7:05 
GeneralRe: consolidating four similar classes Pin
Alexander Kindel18-Apr-18 12:11
Alexander Kindel18-Apr-18 12:11 
GeneralRe: consolidating four similar classes Pin
Gerry Schmitz19-Apr-18 8:50
mveGerry Schmitz19-Apr-18 8:50 
QuestionC# Javascript in WebBrowser Pin
unfolded16-Apr-18 8:37
unfolded16-Apr-18 8:37 
AnswerRe: C# Javascript in WebBrowser Pin
Eddy Vluggen17-Apr-18 0:00
professionalEddy Vluggen17-Apr-18 0:00 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded17-Apr-18 1:06
unfolded17-Apr-18 1:06 
GeneralRe: C# Javascript in WebBrowser Pin
Eddy Vluggen17-Apr-18 6:32
professionalEddy Vluggen17-Apr-18 6:32 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded18-Apr-18 8:12
unfolded18-Apr-18 8:12 
AnswerRe: C# Javascript in WebBrowser Pin
Gerry Schmitz18-Apr-18 7:22
mveGerry Schmitz18-Apr-18 7:22 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded18-Apr-18 8:10
unfolded18-Apr-18 8:10 
GeneralRe: C# Javascript in WebBrowser Pin
Gerry Schmitz18-Apr-18 8:59
mveGerry Schmitz18-Apr-18 8:59 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded19-Apr-18 1:48
unfolded19-Apr-18 1:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.