1 // Copyright (c) 2007,2017 John Abbott and Anna M. Bigatti
2
3 // This file is part of the source of CoCoALib, the CoCoA Library.
4
5 // CoCoALib is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9
10 // CoCoALib is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with CoCoALib. If not, see <http://www.gnu.org/licenses/>.
17
18
19 #include "CoCoA/BigIntOps.H"
20 #include "CoCoA/BuildInfo.H"
21 #include "CoCoA/DenseMatrix.H"
22 #include "CoCoA/GlobalManager.H"
23 #include "CoCoA/PPMonoid.H"
24 #include "CoCoA/PPMonoidEv.H"
25 #include "CoCoA/PPMonoidEvOv.H"
26 #include "CoCoA/PPMonoidOv.H"
27 #include "CoCoA/RingZZ.H"
28 #include "CoCoA/degree.H"
29 #include "CoCoA/error.H"
30 #include "CoCoA/matrix.H"
31 #include "CoCoA/symbol.H"
32
33 #include<iostream>
34 using std::cout;
35 using std::cerr;
36 using std::endl;
37 #include<vector>
38 using std::vector;
39
40 //----------------------------------------------------------------------
41 // Test for PPMonoidOv functions on PPMonoidElem
42 // functions: *, wdeg, CmpWDeg, >, IsOne, ==, IsDivisible, /, IsCoprime, colon,
43 // gcd, lcm, power, cmp, log, IndetPower, wdeg
44 // environments: PPMonoidEv, PPMonoidOv, PPMonoidEvOv, PPMonoidBigEv;
45 // lex, DegLex, DegRevLex, MatOrd
46 //----------------------------------------------------------------------
47
48 namespace CoCoA
49 {
50
51 // convention: a function containing a "new" should be named "New.."
NewMatrixFromC(ring Z,int cmat[6][6])52 matrix NewMatrixFromC(ring Z, int cmat[6][6])
53 {
54 matrix M(NewDenseMat(Z,6,6));
55
56 for (int i=0; i < 6; ++i)
57 for (int j=0; j < 6; ++j)
58 SetEntry(M, i, j, cmat[i][j]);
59 return M;
60 }
61
62
63 //-- TestPPMonoid ------------------------------------------------------
64 // behaviour of different orderings and gradings on PPMonoid and PolyRing
65
TestPPMonoid(PPMonoid PPM)66 void TestPPMonoid(PPMonoid PPM)
67 {
68 cout << "TESTING: " << PPM << endl << endl;
69 cout << std::boolalpha; // prints true/false for bool
70
71 vector<long> expv(6);
72 for (expv[0]=0; expv[0] <= 2; ++expv[0])
73 for (expv[1]=0; expv[1] <= 2; ++expv[1])
74 for (expv[2]=0; expv[2] <= 2; ++expv[2])
75 for (expv[3]=0; expv[3] <= 2; ++expv[3])
76 for (expv[4]=0; expv[4] <= 2; ++expv[4])
77 for (expv[5]=0; expv[5] <= 2; ++expv[5])
78 {
79 PPMonoidElem t = PPMonoidElem(PPM, expv);
80 PPMonoidElem radt = radical(t);
81 CoCoA_ASSERT_ALWAYS(IsSqFree(radt));
82 CoCoA_ASSERT_ALWAYS(radical(radt*power(t,3)) == radt);
83 if (t == radt)
84 {
85 CoCoA_ASSERT_ALWAYS(IsSqFree(t));
86 continue;
87 }
88 // t is not radical, but since max exp is 2, t/radt must be radical
89 CoCoA_ASSERT_ALWAYS(!IsSqFree(t));
90 CoCoA_ASSERT_ALWAYS(IsSqFree(t/radt));
91 }
92
93
94 cout << "------------------------------------------------" << endl << endl;
95 }
96
97
98 //-- program --------------------------------------------------------------
99 // we run TestPolyRing on predefined and user-defined orderings
100
program()101 void program()
102 {
103 GlobalManager CoCoAFoundations;
104
105 // each ordering is degree-compatible with grading over Z^GradingDim
106 // i.e. the grading is given by the first GradingDim rows
107 // of the ordering matrix
108
109 const int NumIndets = 6;
110 const vector<symbol> X = SymbolRange("x", 0, NumIndets-1);
111
112 // user-defined ordering and grading
113 const int GradingDim = 2;
114 // the first 2 rows represent the degree matrix
115 int M[6][6] = {{ 1, 0, 0, 4, 0, 2},
116 { 0, 3, 5, 0, 2, 1},
117 { 1, 0, 0, 0, 0, 0},
118 { 0, 1, 0, 0, 0, -2},
119 {-1, -1, -1, -1, 0, -1},
120 {-1, 0, -2, -4, 1, 0}};
121 PPOrdering MatOrd = NewMatrixOrdering(NewMatrixFromC(RingZZ(),M),
122 GradingDim);
123
124
125 TestPPMonoid(NewPPMonoidEvOv(X, lex));
126 TestPPMonoid(NewPPMonoidEvOv(X, StdDegLex));
127 TestPPMonoid(NewPPMonoidEvOv(X, StdDegRevLex));
128 TestPPMonoid(NewPPMonoidEvOv(X, MatOrd));
129
130 TestPPMonoid(NewPPMonoidEv(X, lex));
131 TestPPMonoid(NewPPMonoidEv(X, StdDegLex));
132 TestPPMonoid(NewPPMonoidEv(X, StdDegRevLex));
133 TestPPMonoid(NewPPMonoidEv(X, MatOrd));
134
135 TestPPMonoid(NewPPMonoidOv(X, lex));
136 TestPPMonoid(NewPPMonoidOv(X, StdDegLex));
137 TestPPMonoid(NewPPMonoidOv(X, StdDegRevLex));
138 TestPPMonoid(NewPPMonoidOv(X, MatOrd));
139
140 TestPPMonoid(NewPPMonoidEv(X, lex, BigExps));
141 TestPPMonoid(NewPPMonoidEv(X, StdDegLex, BigExps));
142 TestPPMonoid(NewPPMonoidEv(X, StdDegRevLex, BigExps));
143 TestPPMonoid(NewPPMonoidEv(X, MatOrd, BigExps));
144 }
145
146 } // end of namespace CoCoA
147
148
149 // Use main() to handle any uncaught exceptions and warn the user about them.
main()150 int main()
151 {
152 try
153 {
154 CoCoA::program();
155 return 0;
156 }
157 catch (const CoCoA::ErrorInfo& err)
158 {
159 cerr << "***ERROR*** UNCAUGHT CoCoA Error";
160 ANNOUNCE(cerr, err);
161 }
162 catch (const std::exception& exc)
163 {
164 cerr << "***ERROR*** UNCAUGHT std::exception: " << exc.what() << endl;
165 }
166 catch(...)
167 {
168 cerr << "***ERROR*** UNCAUGHT UNKNOWN EXCEPTION" << endl;
169 }
170
171 CoCoA::BuildInfo::PrintAll(cerr);
172 return 1;
173 }
174