Gröbner basis project
Codebase for research into Gröbner basis computation
test_monomials.cpp
1 /*****************************************************************************\
2 * This file is part of DynGB. *
3 * *
4 * DynGB is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * Foobar is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with DynGB. If not, see <http://www.gnu.org/licenses/>. *
16 \*****************************************************************************/
17 
18 #include <iostream>
19 using std::cout; using std::endl;
20 
21 #include "fields.hpp"
22 #include "monomial.hpp"
23 
24 #include "fields.hpp"
25 #include "polynomial_ring.hpp"
26 #include "indeterminate.hpp"
27 
28 int main()
29 {
30  DEG_TYPE a [] = {1, 0, 5, 2, 0};
31  Monomial t = { 1, 0, 3, 2, 0 };
32  cout << "t = " << t << endl;
33 
34  Monomial u { 3, 1, 0, 0, 2 };
35  cout << "u = " << u << endl << endl;
36 
37  cout << "Does t divide u? " << u.divisible_by(t) << endl;
38  cout << "Does u divide t? " << t.divisible_by(u) << endl;
39  cout << "lcm(t,u) = " << t.lcm(u) << endl;
40  cout << "lcm(u,t) = " << u.lcm(t) << endl;
41  cout << "gcd(t,u) = " << t.gcd(u) << endl;
42  cout << "gcd(u,t) = " << u.gcd(t) << endl;
43 
44  Monomial w(t);
45  w *= u;
46  cout << "tu = " << w << endl;
47 
48  Monomial v { 2, 2, 0, 1, 0 };
49  cout << endl << "v = " << v << endl;
50 
51  Monomial tv(t.lcm(v));
52  tv /= t;
53  cout << "lcm(t,v)/t = " << tv << endl;
54  Monomial larger { 0, 0, 2, 0, 1, 0 };
55  Monomial smaller { 0, 1, 0, 1, 1, 0 };
56  cout << smaller << " < " << larger << " ? " << (smaller < larger) << endl;
57  cout << larger << " < " << smaller << " ? " << (larger < smaller) << endl;
58 
59  Prime_Field F = Prime_Field(43);
60  string var_names [] = { "x", "y" };
61  Polynomial_Ring R = Polynomial_Ring(2, F, var_names);
62  Indeterminate * X = R.indeterminates();
63  //Indeterminate x(R, 0);
64  //Indeterminate y(R, 1);
65  Monomial x2 = X[0]^2;
66  x2.print(true, cout, var_names);
67  Monomial xy = X[0]*X[1];
68  xy.print(true, cout, var_names);
69  Monomial x3y_first = x2 * xy;
70  Monomial x3y_second = (X[0]^2) * xy;
71  x3y_first.print(false, cout, var_names); cout << ',';
72  x3y_second.print(true, cout, var_names);
73  free(X);
74 }
Information necessary for a field modulo a prime.
Definition: fields.hpp:49
void print(bool=true, ostream &=cout, const string *names=nullptr) const
prints the monomial to the give stream with the given names; adds a newline if the boolean is true ...
Definition: monomial.cpp:439
bool divisible_by(const Monomial &other) const
Divisible by other?
Definition: monomial.cpp:286
virtual Indeterminate * indeterminates()
an array of the ring’s indeterminates; use only to biuld polynomials
Implementation of indeterminates, for easier building of polynomials.
Implementation of monomials.
Definition: monomial.hpp:69
Encapsulates information about a polynomial ring for easy access: ground field, number of indetermina...
Monomial lcm(const Monomial &u) const
Least common multiple: largest exponents.
Definition: monomial.cpp:365
Monomial gcd(const Monomial &u) const
Greatest common divisor: smallest exponents.
Definition: monomial.cpp:387