1 #include "kernel/mod2.h"
2
3 #include "resources/feFopen.h"
4 #include "resources/feResource.h"
5
6
7 #include "factory/factory.h" // :(
8
9 #include "misc/intvec.h"
10 #include "misc/int64vec.h"
11 #include "misc/mylimits.h"
12 #include "misc/options.h"
13
14 #include "reporter/reporter.h"
15
16 #include "coeffs/si_gmp.h"
17 #include "coeffs/coeffs.h"
18 #include "coeffs/numbers.h"
19
20 #ifndef PLURAL_INTERNAL_DECLARATIONS
21 #define PLURAL_INTERNAL_DECLARATIONS
22 #endif
23
24 #include "polys/nc/gb_hack.h"
25 #include "polys/nc/nc.h"
26 #include "polys/nc/ncSACache.h"
27 #include "polys/nc/ncSAFormula.h"
28 #include "polys/nc/ncSAMult.h"
29 #include "polys/nc/sca.h"
30 #include "polys/nc/summator.h"
31
32 #include "polys/kbuckets.h"
33 #include "polys/matpol.h"
34 #include "polys/mod_raw.h"
35 #include "polys/prCopy.h"
36 #include "polys/sbuckets.h"
37 #include "polys/simpleideals.h"
38 #include "polys/weight.h"
39
40 #include "polys/monomials/maps.h"
41 #include "polys/monomials/monomials.h"
42 #include "polys/monomials/p_polys.h"
43 #include "polys/monomials/ring.h"
44
45 #include "polys/templates/p_MemAdd.h"
46 #include "polys/templates/p_Procs.h"
47
48 #include "polys/operations/pShallowCopyDelete.h"
49
50 #include "polys/clapsing.h"
51
52
53 // #include "structs.h"
54
55
56 // HEADERS:
57 #include "kernel/ideals.h"
58 #include "kernel/digitech.h"
59 #include "kernel/fast_mult.h"
60
61 // #include "kernel/spectrum/kmatrix.h"
62 #include "kernel/preimage.h"
63
64 #include "kernel/structs.h"
65
66 #include "kernel/polys.h"
67
TestGBEngine()68 void TestGBEngine()
69 {
70
71 // R = MPolynomialRing_polydict(QQ,5,'w,x,y,z,C', order='degrevlex')
72 // J = (w*w - x*z, w*x - y*z, x*x - w*y, x*y - z*z, y*y - w*z)
73
74 const short w = 1;
75 const short x = 2;
76 const short y = 3;
77 const short z = 4;
78
79 const short N = (z - w + 1);
80
81 char **n=(char**)omalloc(N*sizeof(char*));
82
83
84 n[w-1]=omStrDup("w");
85 n[x-1]=omStrDup("x");
86 n[y-1]=omStrDup("y");
87 n[z-1]=omStrDup("z");
88
89
90 const int D = 3;
91 rRingOrder_t *order = (rRingOrder_t *) omAlloc0(D* sizeof(rRingOrder_t));
92 int *block0 = (int *)omAlloc0(D * sizeof(int));
93 int *block1 = (int *)omAlloc0(D * sizeof(int));
94
95 order[0] = ringorder_dp;
96 block0[0] = 1;
97 block1[0] = N;
98
99 order[1] = ringorder_C;
100 block0[1] = 1;
101 block1[1] = N;
102
103 ring R = rDefault(0, N, n, D, order, block0, block1);
104
105 // ring R = rDefault(0, N, n);
106
107 rWrite(R); PrintLn();
108
109 #ifdef RDEBUG
110 rDebugPrint(R);
111 #endif
112
113 ideal I = idInit(5, 1);
114
115 int gen = 0;
116
117 {
118 // -xz
119 poly p = p_ISet(-1,R);
120
121 p_SetExp(p, x, 1, R);
122 p_SetExp(p, z, 1, R);
123 p_Setm(p, R);
124
125 assume( p_GetExp(p, x, R) == 1 );
126 assume( p_GetExp(p, z, R) == 1 );
127 assume( p_GetExp(p, w, R) == 0 );
128 assume( p_GetExp(p, y, R) == 0 );
129
130 // +w2
131 poly lp = p_ISet(1,R);
132 p_SetExp(lp, w, 2, R);
133 p_Setm(lp, R);
134
135 assume( p_GetExp(lp, w, R) == 2 );
136 assume( p_GetExp(lp, x, R) == 0 );
137 assume( p_GetExp(lp, y, R) == 0 );
138 assume( p_GetExp(lp, z, R) == 0 );
139
140 MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // w2 - xz
141 }
142
143 {
144 // -yz
145 poly p = p_ISet(-1,R);
146
147 p_SetExp(p, y, 1, R);
148 p_SetExp(p, z, 1, R);
149 p_Setm(p, R);
150
151 assume( p_GetExp(p, y, R) == 1 );
152 assume( p_GetExp(p, z, R) == 1 );
153 assume( p_GetExp(p, w, R) == 0 );
154 assume( p_GetExp(p, x, R) == 0 );
155
156 // +wx
157 poly lp = p_ISet(1,R);
158 p_SetExp(lp, w, 1, R);
159 p_SetExp(lp, x, 1, R);
160 p_Setm(lp, R);
161
162 assume( p_GetExp(lp, w, R) == 1 );
163 assume( p_GetExp(lp, x, R) == 1 );
164 assume( p_GetExp(lp, y, R) == 0 );
165 assume( p_GetExp(lp, z, R) == 0 );
166
167 MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // wx - yz
168 }
169
170
171 {
172 // -wy
173 poly p = p_ISet(-1,R);
174
175 p_SetExp(p, y, 1, R);
176 p_SetExp(p, w, 1, R);
177 p_Setm(p, R);
178
179 assume( p_GetExp(p, y, R) == 1 );
180 assume( p_GetExp(p, w, R) == 1 );
181 assume( p_GetExp(p, z, R) == 0 );
182 assume( p_GetExp(p, x, R) == 0 );
183
184 // +x2
185 poly lp = p_ISet(1,R);
186 p_SetExp(lp, x, 2, R);
187 p_Setm(lp, R);
188
189 assume( p_GetExp(lp, w, R) == 0 );
190 assume( p_GetExp(lp, x, R) == 2 );
191 assume( p_GetExp(lp, y, R) == 0 );
192 assume( p_GetExp(lp, z, R) == 0 );
193
194 MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // x2 - wy
195 }
196
197
198 {
199 // -z2
200 poly p = p_ISet(-1,R);
201
202 p_SetExp(p, z, 2, R);
203 p_Setm(p, R);
204
205 assume( p_GetExp(p, y, R) == 0 );
206 assume( p_GetExp(p, w, R) == 0 );
207 assume( p_GetExp(p, z, R) == 2 );
208 assume( p_GetExp(p, x, R) == 0 );
209
210 // +xy
211 poly lp = p_ISet(1,R);
212 p_SetExp(lp, x, 1, R);
213 p_SetExp(lp, y, 1, R);
214 p_Setm(lp, R);
215
216 assume( p_GetExp(lp, w, R) == 0 );
217 assume( p_GetExp(lp, x, R) == 1 );
218 assume( p_GetExp(lp, y, R) == 1 );
219 assume( p_GetExp(lp, z, R) == 0 );
220
221 MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // xy - z2
222 }
223
224
225 {
226 // -wz
227 poly p = p_ISet(-1,R);
228
229 p_SetExp(p, w, 1, R);
230 p_SetExp(p, z, 1, R);
231 p_Setm(p, R);
232
233 assume( p_GetExp(p, y, R) == 0 );
234 assume( p_GetExp(p, w, R) == 1 );
235 assume( p_GetExp(p, z, R) == 1 );
236 assume( p_GetExp(p, x, R) == 0 );
237
238 // +y2
239 poly lp = p_ISet(1,R);
240 p_SetExp(lp, y, 2, R);
241 p_Setm(lp, R);
242
243 assume( p_GetExp(lp, w, R) == 0 );
244 assume( p_GetExp(lp, x, R) == 0 );
245 assume( p_GetExp(lp, y, R) == 2 );
246 assume( p_GetExp(lp, z, R) == 0 );
247
248 MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // y2 - wz
249 }
250 #ifdef PDEBUG
251 PrintS("I: ");
252 idShow(I, R, R, 0);
253 #endif
254
255
256 // ideal kStd(ideal F, ideal Q, tHomog h, intvec ** mw,intvec *hilb=NULL,
257 // int syzComp=0,int newIdeal=0, intvec *vw=NULL);
258 // make R the default ring:
259 rChangeCurrRing(R);
260
261 ////
262
263 id_Delete( &I, R);
264 rDelete(R); // should cleanup every belonging polynomial, right!?
265
266 }
267
268
269
TestSimpleRingArithmetcs()270 void TestSimpleRingArithmetcs()
271 {
272 // Libpolys tests:
273
274 // construct the ring Z/32003[x,y,z]
275 // the variable names
276 char **n=(char**)omalloc(3*sizeof(char*));
277 n[0]=omStrDup("x");
278 n[1]=omStrDup("y");
279 n[2]=omStrDup("z2");
280
281 ring R = rDefault(32003,3,n); // ring R = rDefault(0,3,n);
282
283 rWrite(R); PrintLn();
284
285 #ifdef RDEBUG
286 rDebugPrint(R);
287 #endif
288
289
290 poly p = p_ISet(1,R); p_SetExp(p,1,1, R); p_Setm(p, R);
291
292 assume( p_GetExp(p,1, R) == 1 );
293
294 poly pp = pp_Mult_qq( p, p, R);
295
296 PrintS("p: "); p_Write0(p, R); Print(", deg(p): %ld", p_Totaldegree(p, R)); assume( 1 == p_Totaldegree(p, R) );
297
298 PrintS("; p*p : "); p_Write0(pp, R); Print("deg(pp): %ld\n", p_Totaldegree(pp, R)); assume( 2 == p_Totaldegree(pp, R) );
299
300
301 p_Delete(&p, R);
302
303 assume( p_GetExp(pp,1, R) == 2 );
304
305 p_Delete(&pp, R);
306
307
308 // rDelete(R);
309
310 // make R the default ring:
311 rChangeCurrRing(R);
312
313 // create the polynomial 1
314 poly p1=pISet(1);
315
316 // create tthe polynomial 2*x^3*z^2
317 poly p2=p_ISet(2,R);
318 pSetExp(p2,1,3);
319 pSetExp(p2,3,2);
320 pSetm(p2);
321
322 // print p1 + p2
323 PrintS("p1: "); pWrite0(p1);
324 PrintS(" + p2: "); pWrite0(p2);
325 PrintS(" ---- >>>> ");
326
327 // compute p1+p2
328 p1=p_Add_q(p1,p2,R); p2=NULL;
329 pWrite(p1);
330
331 // clean up:
332 // pDelete(&p1);
333
334 rDelete(R); // should cleanup every belonging polynomial, right!?
335 }
336
337
main(int,char * argv[])338 int main( int, char *argv[] )
339 {
340 assume( sizeof(long) == SIZEOF_LONG );
341
342 if( sizeof(long) != SIZEOF_LONG )
343 {
344 WerrorS("Bad config.h: wrong size of long!");
345
346 return(1);
347 }
348
349
350 feInitResources(argv[0]);
351
352 StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
353 feStringAppendResources(0);
354
355 PrintLn();
356 { char* s = StringEndS(); PrintS(s); omFree(s); }
357
358 TestGBEngine();
359 TestSimpleRingArithmetcs();
360
361 return 0;
362 }
363