1 // Copyright (c) 2007-2013 John Abbott, 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/FractionField.H"
22 #include "CoCoA/FreeModule.H"
23 #include "CoCoA/GlobalManager.H"
24 #include "CoCoA/ModuleOrdering.H"
25 #include "CoCoA/RingDistrMPolyClean.H"
26 #include "CoCoA/RingQQ.H"
27 #include "CoCoA/SparsePolyOps-RingElem.H"
28 //#include "CoCoA/SparsePolyRing.H"
29 #include "CoCoA/degree.H"
30
31 #include <iostream>
32 using std::cout;
33 using std::cerr;
34 using std::endl;
35 #include <vector>
36 using std::vector;
37
38 namespace CoCoA
39 {
40
41 //----------------------------------------------------------------------
42 // Test for FreeModules over SparsePolyRing with many different orderings
43 // functions: LPosn(v), LPP(v), wdeg(v), IsHomog(v)
44 // environments: Q[x,y,z], WDegPosnOrd/OrdPosn, shifts
45 //----------------------------------------------------------------------
46
trial(const FreeModule & F)47 void trial(const FreeModule& F)
48 {
49 const vector<ModuleElem>& e = gens(F);
50 const SparsePolyRing P = RingOf(F);
51 const vector<RingElem>& x = indets(P);
52
53 const ModuleElem u = power(x[1],5)*e[0] + x[0]*e[1];
54 const ModuleElem v = x[2]*x[2]*e[1] + x[1]*x[2]*e[2];
55 const RingElem a = 2 * one(RingOf(F)); // RingOf(F) is R
56
57 cout << "---- F = " << F << " ----" << endl;
58 cout << "-- " << ordering(F) << endl;
59 // cout << "-- " << ordering(PPM(P)) << endl;
60 cout << "u[0] = " << u[0] << " and u[1] = " << u[1] << endl;
61 cout << "u = " << u << endl;
62 cout << "LPosn(u) = " << LPosn(u) << std::endl;
63 cout << "LPP(u) = " << LPP(u) << endl;
64 cout << "wdeg(u) = " << wdeg(u) << endl;
65 if (GradingDim(P)==0)
66 cout << "IsHomog(u) undefined because GradingDim is 0" << endl;
67 else
68 cout << "IsHomog(u) = " << IsHomog(u) << std::endl;
69 cout << "v = " << v << endl;
70 cout << "LPosn(v) = " << LPosn(v) << std::endl;
71
72 cout << endl;
73 }
74
75
program()76 void program()
77 {
78 GlobalManager CoCoAFoundations;
79 std::cout << std::boolalpha;
80
81 ring QQ = RingQQ();
82 SparsePolyRing PLex = NewPolyRing(QQ, symbols("x,y,z"), lex);
83 SparsePolyRing PDegLex = NewPolyRing(QQ, symbols("x,y,z"), StdDegLex);
84 long n = 4;
85 std::vector<degree> sh(n, wdeg(one(PDegLex)));
86 sh[1] = wdeg(power(indet(PDegLex,0),4));
87 trial(NewFreeModule(PLex, n));
88 trial(NewFreeModule(PDegLex, n));
89 // trial(NewFreeModule(PDegLex, n, PosnOrd));
90 trial(NewFreeModule(PDegLex, n, OrdPosn));
91 trial(NewFreeModule(PLex, n, WDegPosnOrd));
92 trial(NewFreeModule(PDegLex, n, WDegPosnOrd));
93 trial(NewFreeModule(PDegLex, sh, WDegPosnOrd));
94 }
95
96 } // end of namespace CoCoA
97
98
99 // Use main() to handle any uncaught exceptions and warn the user about them.
main()100 int main()
101 {
102 try
103 {
104 CoCoA::program();
105 return 0;
106 }
107 catch (const CoCoA::ErrorInfo& err)
108 {
109 cerr << "***ERROR*** UNCAUGHT CoCoA error";
110 ANNOUNCE(cerr, err);
111 }
112 catch (const std::exception& exc)
113 {
114 cerr << "***ERROR*** UNCAUGHT std::exception: " << exc.what() << endl;
115 }
116 catch(...)
117 {
118 cerr << "***ERROR*** UNCAUGHT UNKNOWN EXCEPTION" << endl;
119 }
120 CoCoA::BuildInfo::PrintAll(cerr);
121 return 1;
122 }
123
124 //----------------------------------------------------------------------
125 // RCS header/log in the next few lines
126 // $Header: /Volumes/Home_1/cocoa/cvs-repository/CoCoALib-0.99/src/tests/test-FreeModule2.C,v 1.13 2018/09/28 15:54:05 abbott Exp $
127 // $Log: test-FreeModule2.C,v $
128 // Revision 1.13 2018/09/28 15:54:05 abbott
129 // Summary: Removed pseudo-ctors NewPolyRing which took just num of indets; now must specify their names
130 //
131 // Revision 1.12 2018/05/18 16:46:17 bigatti
132 // -- added include SparsePolyOps-RingElem.H
133 //
134 // Revision 1.11 2018/05/18 12:29:29 bigatti
135 // -- renamed IntOperations --> BigIntOps
136 //
137 // Revision 1.10 2016/09/16 16:36:37 abbott
138 // Summary: Changed TEST_ASSERT into CoCoA_ASSERT_ALWAYS; removed all include assert.H lines
139 //
140 // Revision 1.9 2014/10/29 10:59:12 bigatti
141 // -- improved comment
142 //
143 // Revision 1.8 2014/10/29 10:47:29 abbott
144 // Summary: moved code into namespace CoCoA; some minor tidying
145 // Author: JAA
146 //
147 // Revision 1.7 2014/07/30 14:28:52 abbott
148 // Summary: Changed BaseRing into RingOf
149 // Author: JAA
150 //
151 // Revision 1.6 2014/07/07 13:38:35 abbott
152 // Summary: Removed AsSparsePolyRing
153 // Author: JAA
154 //
155 // Revision 1.5 2013/08/02 16:05:50 bigatti
156 // -- LPos --> LPosn
157 //
158 // Revision 1.4 2013/06/03 09:12:24 bigatti
159 // renamed ModuleTermOrdering into ModuleOrdering
160 //
161 // Revision 1.3 2013/05/28 11:50:32 bigatti
162 // -- minor comments
163 //
164 // Revision 1.2 2013/05/28 06:58:47 bigatti
165 // -- improved test
166 //
167 // Revision 1.1 2013/05/27 16:52:35 bigatti
168 // -- first import
169 //
170 // Revision 1.6 2013/01/23 14:43:36 bigatti
171 // -- added "v==w"
172 //
173 // Revision 1.5 2012/02/08 17:52:17 bigatti
174 // -- changed: Z,Q -> ZZ,QQ
175 //
176 // Revision 1.4 2010/12/17 16:07:54 abbott
177 // Ensured that all i/o in examples is on standard C++ streams
178 // (rather than GlobalInput(), etc).
179 //
180 // Revision 1.3 2008/04/21 12:33:45 abbott
181 // Made a very minor change.
182 //
183 // Revision 1.2 2007/06/21 21:29:47 abbott
184 // Changed name of RingFloat into RingTwinFloat.
185 //
186 // Revision 1.1.1.1 2007/03/09 15:16:11 abbott
187 // Imported files
188 //
189 // Revision 1.6 2007/03/03 14:15:45 bigatti
190 // -- "foundations" renamed into "GlobalManager"
191 //
192 // Revision 1.5 2007/02/28 15:15:10 bigatti
193 // -- added sum and multiplication examples
194 //
195 // Revision 1.4 2007/02/26 17:40:34 bigatti
196 // -- getting ready for unique ring Z: using NewZmod(N), NewRingQ()
197 //
198 // Revision 1.3 2007/02/12 16:27:43 bigatti
199 // -- added strings ShortDescription and LongDescription for indexing
200 //
201 // Revision 1.2 2007/02/10 18:44:03 cocoa
202 // Added "const" twice to each test and example.
203 // Eliminated dependency on io.H in several files.
204 // Improved BuildInfo, and added an example about how to use it.
205 // Some other minor cleaning.
206 //
207 // Revision 1.1.1.1 2006/05/30 11:39:36 cocoa
208 // Imported files
209 //
210 // Revision 1.1 2005/12/16 17:53:01 cocoa
211 // --- first import
212 //
213