Beispiel #1
0
        /// <summary>
        /// Computes Groebner basis for the polynomial basis. Based on Theorem 2 of sectin 2.7, CLO. Not very efficient.
        /// </summary>
        /// <returns>A polynomial basis that is the reduced Groebner basis.</returns>
        public PolynomialBasis SimplifiedBuchberger()
        {
            PolynomialBasis groebner     = this;
            PolynomialBasis groebnerTemp = this;

            do
            {
                groebnerTemp = new PolynomialBasis(groebner); // G' := G

                List <Polynomial> groebnerTempList = groebnerTemp.polynomialData.ToList();
                for (int i = 0; i < groebnerTemp.polynomialData.Count; i++)
                {
                    for (int j = (i + 1); j < groebnerTemp.polynomialData.Count; j++)
                    {
                        Polynomial s = groebnerTempList[i].GetSPolynomial(groebnerTempList[j]).GetRemainder(groebnerTemp);
                        if (!s.IsZero)
                        {
                            groebner.polynomialData.Add(s); // G := G ∪ {S}
                        }
                    }
                }
            }while (!groebner.Equals(groebnerTemp));

            groebner.MakeMinimal(); // First minimal and then reduced.
            groebner.MakeReduced();
            return(groebner);
        }
Beispiel #2
0
        /// <summary>
        /// Computes the Groebner basis for a polynomial ideal using Buchbergers algorithm.
        /// </summary>
        /// <param name="basis">The basis that defines the ideal.</param>
        /// <returns>The Groebner basis.</returns>
        public static PolynomialBasis GetGroebnerBasis(params Polynomial[] basis)
        {
            PolynomialBasis groebner = new PolynomialBasis(basis);

            return(groebner.SimplifiedBuchberger());
            //return groebner.OptimizedBuchberger(basis); //TODO: Change to optimized Buchberger.
        }
Beispiel #3
0
        /// <summary>
        /// Implementation incomplete.
        /// </summary>
        /// <param name="basis"></param>
        /// <returns></returns>
        public static PolynomialBasis GrobnerBasisOptimized(params Polynomial[] basis)
        {
            int t = basis.Length;
            List <Tuple <int, int> > b = new List <Tuple <int, int> >();

            for (int i = 0; i < t; i++)
            {
                for (int j = i; j < t; j++)
                {
                    b.Add(Tuple.Create(i, j));
                }
            }

            PolynomialBasis groebner = new PolynomialBasis(basis);

            while (b.Count > 0)
            {
                int i = b[0].Item1;
                int j = b[0].Item2;

                /*
                 * if (basis[i].GetLeadingTerm().LCM(basis[j].GetLeadingTerm()).Equals(basis[i].GetLeadingTerm()) && !criterion()) // TODO: Implement multiply monomials.
                 * {
                 *
                 * }*/
            }

            return(groebner);
        }
Beispiel #4
0
        /// <summary>
        /// Gets remainder on division by a polynomial basis.
        /// </summary>
        /// <param name="basis">The basis (or collection) of quitient polynomials.</param>
        /// <returns>The remainder polynomial on division.</returns>
        public Polynomial GetRemainder(PolynomialBasis basis)
        {
            Polynomial[]      divisorList = basis.polynomialData.ToArray();
            List <Polynomial> quotients   = this.DivideBy(divisorList);

            return(quotients[quotients.Count - 1]); // The last element in the list is the remainder
        }
Beispiel #5
0
        public static void CLOSecn2Pt7Exerc2a()
        {
            Monomial.orderingScheme = "lex";
            Polynomial      p1 = new Polynomial(new double[] { 1, -1 }, new Monomial(2, 1), new Monomial(0, 0));
            Polynomial      p2 = new Polynomial(new double[] { 1, -1 }, new Monomial(1, 2), new Monomial(1, 0));
            PolynomialBasis gb = PolynomialBasis.GetGroebnerBasis(p1, p2);

            PrintPolynomialBasis(gb);
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of class <see cref="PolynomialBasis"/>. Creates a deep copy of the input basis in a new instance.
        /// </summary>
        /// <param name="inputBasis">The input basis which is to be deep copied.</param>
        public PolynomialBasis(PolynomialBasis inputBasis)
        {
            this.polynomialData = new HashSet <Polynomial>();

            foreach (Polynomial p in inputBasis.polynomialData)
            {
                Polynomial toAdd = new Polynomial(p);
                this.polynomialData.Add(toAdd);
            }
        }
Beispiel #7
0
        public static void CLOSectn2Pt8Exerc11()
        {
            Monomial.orderingScheme = "lex";
            Polynomial      p1 = new Polynomial(new double[] { 1, 1, 1, -3 }, new Monomial(1, 0, 0), new Monomial(0, 1, 0), new Monomial(0, 0, 1), new Monomial(0, 0, 0));
            Polynomial      p2 = new Polynomial(new double[] { 1, 1, 1, -5 }, new Monomial(2, 0, 0), new Monomial(0, 2, 0), new Monomial(0, 0, 2), new Monomial(0, 0, 0));
            Polynomial      p3 = new Polynomial(new double[] { 1, 1, 1, -7 }, new Monomial(3, 0, 0), new Monomial(0, 3, 0), new Monomial(0, 0, 3), new Monomial(0, 0, 0));
            Polynomial      p4 = new Polynomial(new double[] { 1, 1, 1, -9 }, new Monomial(4, 0, 0), new Monomial(0, 4, 0), new Monomial(0, 0, 4), new Monomial(0, 0, 0));
            PolynomialBasis gb = PolynomialBasis.GetGroebnerBasis(p1, p2, p3, p4);

            PrintPolynomialBasis(gb);
        }
Beispiel #8
0
        public static void CLOSec2Pt7Exerc9()
        {
            Monomial.orderingScheme = "lex";
            Polynomial p1 = new Polynomial(new double[] { 3, -6, -2 }, new Monomial(1, 0, 0, 0), new Monomial(0, 1, 0, 0), new Monomial(0, 0, 1, 0));
            Polynomial p2 = new Polynomial(new double[] { 2, -4, 4 }, new Monomial(1, 0, 0, 0), new Monomial(0, 1, 0, 0), new Monomial(0, 0, 0, 1));
            Polynomial p3 = new Polynomial(new double[] { 1, -2, -1, -1 }, new Monomial(1, 0, 0, 0), new Monomial(0, 1, 0, 0), new Monomial(0, 0, 1, 0), new Monomial(0, 0, 0, 1));

            PolynomialBasis gb = PolynomialBasis.GetGroebnerBasis(p1, p2, p3);

            PrintPolynomialBasis(gb);
        }
Beispiel #9
0
        /// <summary>
        /// Optimized Buchberger implementation based on Theorem 11 of section 2.9.
        /// </summary>
        /// <param name="basis">An array of polynomials that are going to form the basis.</param>
        /// <returns>A polynomial basis that wraps the polynomials that make up the Groebner basis.</returns>
        public PolynomialBasis OptimizedBuchberger(params Polynomial[] basis)
        {
            int t = basis.Length - 1;
            HashSet <Tuple <int, int> > b = new HashSet <Tuple <int, int> >();

            for (int i = 0; i <= t; i++)
            {
                for (int j = i + 1; j <= t; j++)
                {
                    b.Add(Tuple.Create(i, j)); // i will always be less than j.
                }
            }

            PolynomialBasis   groebner  = new PolynomialBasis(basis);
            List <Polynomial> listBasis = basis.ToList();

            while (b.Count > 0)
            {
                List <Tuple <int, int> > bList = b.ToList();
                foreach (Tuple <int, int> ij in bList)
                {
                    int i = ij.Item1;
                    int j = ij.Item2;

                    if ( // First, is the combination relatively prime (see propositions 4 of section 2.9, CLO)? If so, we know the remainder by G will be zero.
                         // So, just skip the if condition and remove it.
                        listBasis[i].GetLeadingTerm().LCM(listBasis[j].GetLeadingTerm()) != listBasis[i].GetLeadingTerm() * (listBasis[j].GetLeadingTerm())
                        // Next, is it possible to remove this combination? If so, skip the if and remove ij.
                        && !this.Criterion(i, j, b, listBasis)
                        )
                    {
                        Polynomial s = listBasis[i].GetSPolynomial(listBasis[j]).GetRemainder(new PolynomialBasis(listBasis)); // TODO: Implement remainder method that takes list. It will be more efficient.
                        if (!s.IsZero)
                        {
                            t++;
                            listBasis.Add(s);

                            for (int l = 0; l < t; l++)
                            {                              // We need to consider all combinations with this new polynomial that was introduced.
                                b.Add(Tuple.Create(l, t)); // l will always be smaller than t.
                            }
                        }
                    }

                    b.Remove(ij); // ij has already been considered and its S-polynomial (if non-zero) added. So, we don't need to consider it again.
                }
            }

            PolynomialBasis grb = new PolynomialBasis(listBasis);

            grb.MakeMinimal(); // First minimal and then reduced.
            grb.MakeReduced();
            return(grb);
        }
Beispiel #10
0
        public static void CLOSecn2Pt8Exerc5()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "4x^3+4xy^2-8x-3",
                "4y^3+4yx^2-8y-3"
                                 );

            PolynomialBasis gb = pb.SimplifiedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #11
0
        public static void TestOptimizedBuchberger()
        {
            Monomial.orderingScheme = "grlex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "x^3 - 2xy",
                "x^2y - 2y^2 + x"
                                 );

            PolynomialBasis gb = pb.OptimizedBuchberger(); // since gb doesn't have pb's indiceToVariable, we will get old fashioned printing.

            gb.PrettyPrint();
        }
Beispiel #12
0
        public static void PrintPolynomialBasis(PolynomialBasis gb)
        {
            int i = 0;

            foreach (Polynomial p in gb.polynomialData)
            {
                System.Console.WriteLine("Polynomial - " + i++.ToString());
                foreach (Monomial m in p.monomialData.Keys)
                {
                    System.Console.WriteLine(string.Join(",", m.powers) + " * " + p.monomialData[m].ToString() + " + ");
                }
            }
        }
Beispiel #13
0
        /**************************
         * Now for expercies from section 8 of CLO
         *************************/

        public static void CLOSecn2Pt8Exerc1()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "xy^3 - z^2 + y^5 - z^3",
                "-x^3 + y",
                "x^2y - z"
                                 );

            PolynomialBasis gb = pb.OptimizedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #14
0
        public static void CLOSecn2Pt8Exerc3()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "x^2 + y^2 + z^2 - 1", // Ensure that y appears before z in the equations.
                "x^2 + y^2 + z^2 - 2x",
                "2x - 3y - z"
                                 );

            PolynomialBasis gb = pb.SimplifiedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #15
0
        public static void CLOSecn2Pt8Exerc6()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "t + u -x",
                "t^2 + 2tu - y",
                "t^3+3t^2u-z"
                                 );

            PolynomialBasis gb = pb.OptimizedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #16
0
        public static void TestString2GroebnerBasis()
        {
            Monomial.orderingScheme = "grlex";

            PolynomialBasis pb = new PolynomialBasis
                                 (
                "x^2 + y^2 + z^2 - 8",
                "x^2 + z^2 - y",
                "x - z + y - 2"
                                 );

            pb.SimplifiedBuchberger();
            pb.PrettyPrint();
        }
Beispiel #17
0
        public static void CLOSecn2Pt8Exerc7()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "ut - x",
                "1-u-y",
                "u+t-ut-z"
                                 );

            PolynomialBasis gb = pb.SimplifiedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #18
0
        public static void TestGroebnerBasisCLOSec2Pt7Exerc3()
        {
            Monomial.orderingScheme = "lex";
            Polynomial f = new Polynomial(new Monomial(new int[] { 2, 1 }));

            f.AddMonomial(new Monomial(new int[] { 0, 0 }), -1);

            Polynomial g = new Polynomial(new Monomial(new int[] { 1, 2 }));

            g.AddMonomial(new Monomial(new int[] { 1, 0 }), -1);

            PolynomialBasis gb = PolynomialBasis.GetGroebnerBasis(f, g);

            PrintPolynomialBasis(gb);
        }
Beispiel #19
0
        public static void CLOSecn2Pt8Exerc2()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "xy + 2z^2", // Ensure that y appears before z in the equations.
                "y - z",
                "xz - y",
                "x^3z - 2y^2"
                                 );

            PolynomialBasis gb = pb.SimplifiedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #20
0
        public static void CLOSecn2Pt8Exerc9()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "a^2 + b^2 -1",
                "8a^5 -2a^3 -3a - x",
                "8b^5 - 18b^3 + 9b -y",
                "2ab - z"
                                 );

            PolynomialBasis gb = pb.OptimizedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #21
0
        public static void CLOSecn2Pt8Exerc4()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "x^2y - z^3",
                "2xy - 4z - 1",
                "z - y^2",
                "x^3 - 4zy"
                                 );

            PolynomialBasis gb = pb.OptimizedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #22
0
        public static void CLOSecn2Pt8Exerc10()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "4lx + 2x - 2",
                "2ly + 2y - 2",
                "2lz + 2z - 2",
                "x^4 + y^2 + z^2 -1"
                                 );

            PolynomialBasis gb = pb.OptimizedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #23
0
        public static void TestGroebnerBasisCLOSecn2Pt7Example1()
        {
            Monomial.orderingScheme = "grlex";
            Polynomial f = new Polynomial(new Monomial(new int[] { 3, 0 })); // x^3

            f.AddMonomial(new Monomial(new int[] { 1, 1 }), -2.0);           // -2xy

            Polynomial g = new Polynomial(new Monomial(new int[] { 2, 1 })); // x^2y

            g.AddMonomial(new Monomial(new int[] { 0, 2 }), -2.0);           // -2y^2
            g.AddMonomial(new Monomial(new int[] { 1, 0 }));                 // x

            PolynomialBasis gb = PolynomialBasis.GetGroebnerBasis(f, g);

            PrintPolynomialBasis(gb);
        }
Beispiel #24
0
        public static void CLOSecn2Pt8Exerc8()
        {
            Monomial.orderingScheme = "lex";
            PolynomialBasis pb = new PolynomialBasis
                                 (
                "a^2 + b^2 -1",
                "c^2 + d^2 -1",
                "ac + 2c - x",
                "ad + 2d - y",
                "b - z"
                                 );

            PolynomialBasis gb = pb.SimplifiedBuchberger();

            gb.PrettyPrint();
        }
Beispiel #25
0
        public static void TestGroebnerBasisLinearSystem()
        {
            Monomial.orderingScheme = "lex";
            Polynomial f = new Polynomial(new Monomial(new int[] { 1, 0 }));

            f.AddMonomial(new Monomial(new int[] { 0, 1 }), 2);
            f.AddMonomial(new Monomial(new int[] { 0, 0 }), -3);

            Polynomial g = new Polynomial(new Monomial(new int[] { 1, 0 }));

            g.AddMonomial(new Monomial(new int[] { 0, 1 }), -2);
            g.AddMonomial(new Monomial(new int[] { 0, 0 }), -7);

            PolynomialBasis gb = PolynomialBasis.GetGroebnerBasis(f, g);

            PrintPolynomialBasis(gb);
        }
Beispiel #26
0
        /// <summary>
        /// Checks to see if the two polynomial bases are equal.
        /// </summary>
        /// <param name="obj">An object that is parsed to another polynomial with which equality is to be tested.</param>
        /// <returns>A boolean value specifying if this polynomial basis is equal to the other or not.</returns>
        public override bool Equals(object obj)
        {
            PolynomialBasis other = (PolynomialBasis)obj;

            if (this.polynomialData.Count != other.polynomialData.Count)
            {
                return(false);
            }

            foreach (Polynomial p in other.polynomialData)
            {
                if (!this.polynomialData.Contains(p))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #27
0
        /// <summary>
        /// Test method for Groebner basis.
        /// </summary>
        public static void TestGroebnerBasis()
        {
            Monomial.orderingScheme = "lex";

            //1st order
            var del_x = 1.0;
            var del_y = 2.0;

            //2nd order
            var del_x_x = 3.5;
            var del_x_y = 1.5;
            var del_y_y = 2.7;

            //3rd order
            var del_y_y_y = 1.1;
            var del_x_y_y = 1.9;
            var del_x_x_y = 2.3;
            var del_x_x_x = 1.4;

            Polynomial f = new Polynomial(new Monomial(new int[] { 2, 0 }), del_x_x_x);

            f.AddMonomial(new Monomial(new int[] { 1, 1 }), 2 * del_x_x_y);
            f.AddMonomial(new Monomial(new int[] { 0, 2 }), del_x_y_y);
            f.AddMonomial(new Monomial(new int[] { 1, 0 }), del_x_y);
            f.AddMonomial(new Monomial(new int[] { 0, 1 }), del_y_y);
            f.AddMonomial(new Monomial(new int[] { 0, 0 }), -del_x);

            Polynomial g = new Polynomial(new Monomial(new int[] { 2, 0 }), del_x_x_y);

            g.AddMonomial(new Monomial(new int[] { 1, 1 }), 2 * del_x_y_y);
            g.AddMonomial(new Monomial(new int[] { 0, 2 }), del_y_y_y);
            g.AddMonomial(new Monomial(new int[] { 1, 0 }), del_x_x);
            g.AddMonomial(new Monomial(new int[] { 0, 1 }), del_x_y);
            g.AddMonomial(new Monomial(new int[] { 0, 0 }), -del_y);

            PolynomialBasis gb = PolynomialBasis.GetGroebnerBasis(f, g);

            PrintPolynomialBasis(gb);
        }
Beispiel #28
0
        /// <summary>
        /// Computes the Groebner basis for a polynomial ideal using Buchbergers algorithm.
        /// </summary>
        /// <param name="basis">The basis that defines the ideal.</param>
        /// <returns>The Groebner basis.</returns>
        public static PolynomialBasis GroebnerBasis(params Polynomial[] basis)
        {
            PolynomialBasis groebner = new PolynomialBasis(basis);

            return(groebner.SimplifiedGroebnerBasis());
        }