1 | #include "kernel/mod2.h" |
---|
2 | |
---|
3 | #include "resources/feFopen.h" |
---|
4 | #include "resources/feResource.h" |
---|
5 | |
---|
6 | #include "factory/factory.h" // :( |
---|
7 | |
---|
8 | #include "misc/intvec.h" |
---|
9 | #include "misc/int64vec.h" |
---|
10 | #include "misc/mylimits.h" |
---|
11 | #include "misc/options.h" |
---|
12 | |
---|
13 | #include "reporter/reporter.h" |
---|
14 | |
---|
15 | #include "coeffs/si_gmp.h" |
---|
16 | #include "coeffs/coeffs.h" |
---|
17 | #include "coeffs/numbers.h" |
---|
18 | |
---|
19 | #include "polys/kbuckets.h" |
---|
20 | #include "polys/matpol.h" |
---|
21 | #include "polys/mod_raw.h" |
---|
22 | #include "polys/prCopy.h" |
---|
23 | #include "polys/sbuckets.h" |
---|
24 | #include "polys/simpleideals.h" |
---|
25 | #include "polys/weight.h" |
---|
26 | #include "polys/monomials/maps.h" |
---|
27 | #include "polys/monomials/monomials.h" |
---|
28 | #include "polys/monomials/p_polys.h" |
---|
29 | #include "polys/monomials/ring.h" |
---|
30 | #include "polys/nc/nc.h" |
---|
31 | #include "polys/nc/ncSACache.h" |
---|
32 | #include "polys/nc/ncSAFormula.h" |
---|
33 | #include "polys/nc/ncSAMult.h" |
---|
34 | #include "polys/nc/sca.h" |
---|
35 | #include "polys/nc/summator.h" |
---|
36 | #include "polys/templates/p_MemAdd.h" |
---|
37 | #include "polys/templates/p_Procs.h" |
---|
38 | #include "polys/operations/pShallowCopyDelete.h" |
---|
39 | #include "polys/clapsing.h" |
---|
40 | |
---|
41 | |
---|
42 | #include "kernel/combinatorics/stairc.h" |
---|
43 | #include "kernel/GBEngine/syz.h" |
---|
44 | #include "kernel/GBEngine/khstd.h" |
---|
45 | #include "kernel/GBEngine/kstd1.h" |
---|
46 | #include "kernel/GBEngine/kstdfac.h" |
---|
47 | #include "kernel/GBEngine/units.h" |
---|
48 | #include "kernel/GBEngine/ratgring.h" |
---|
49 | #include "kernel/GBEngine/shiftgb.h" |
---|
50 | #include "kernel/GBEngine/kutil.h" |
---|
51 | #include "kernel/GBEngine/f5data.h" |
---|
52 | #include "kernel/GBEngine/f5gb.h" |
---|
53 | #include "kernel/GBEngine/f5lists.h" |
---|
54 | #include "kernel/GBEngine/nc.h" |
---|
55 | #include "kernel/GBEngine/ratgring.h" |
---|
56 | #include "kernel/GBEngine/ringgb.h" |
---|
57 | #include "kernel/GBEngine/shiftgb.h" |
---|
58 | #include "kernel/GBEngine/syz.h" |
---|
59 | #include "kernel/GBEngine/tgbgauss.h" |
---|
60 | #include "kernel/GBEngine/tgb.h" |
---|
61 | #include "kernel/GBEngine/units.h" |
---|
62 | #include "kernel/GBEngine/janet.h" |
---|
63 | |
---|
64 | void TestGBEngine() |
---|
65 | { |
---|
66 | |
---|
67 | // R = MPolynomialRing_polydict(QQ,5,'w,x,y,z,C', order='degrevlex') |
---|
68 | // J = (w*w - x*z, w*x - y*z, x*x - w*y, x*y - z*z, y*y - w*z) |
---|
69 | |
---|
70 | const short w = 1; |
---|
71 | const short x = 2; |
---|
72 | const short y = 3; |
---|
73 | const short z = 4; |
---|
74 | |
---|
75 | const short N = (z - w + 1); |
---|
76 | |
---|
77 | char **n=(char**)omalloc(N*sizeof(char*)); |
---|
78 | |
---|
79 | |
---|
80 | n[w-1]=omStrDup("w"); |
---|
81 | n[x-1]=omStrDup("x"); |
---|
82 | n[y-1]=omStrDup("y"); |
---|
83 | n[z-1]=omStrDup("z"); |
---|
84 | |
---|
85 | |
---|
86 | const int D = 3; |
---|
87 | rRingOrder_t *order = (rRingOrder_t *) omAlloc0(D* sizeof(rRingOrder_t)); |
---|
88 | int *block0 = (int *)omAlloc0(D * sizeof(int)); |
---|
89 | int *block1 = (int *)omAlloc0(D * sizeof(int)); |
---|
90 | |
---|
91 | order[0] = ringorder_dp; |
---|
92 | block0[0] = 1; |
---|
93 | block1[0] = N; |
---|
94 | |
---|
95 | order[1] = ringorder_C; |
---|
96 | block0[1] = 1; |
---|
97 | block1[1] = N; |
---|
98 | |
---|
99 | ring R = rDefault(0, N, n, D, order, block0, block1); |
---|
100 | |
---|
101 | // ring R = rDefault(0, N, n); |
---|
102 | |
---|
103 | rWrite(R); PrintLn(); |
---|
104 | |
---|
105 | #ifdef RDEBUG |
---|
106 | rDebugPrint(R); |
---|
107 | #endif |
---|
108 | |
---|
109 | ideal I = idInit(5, 1); |
---|
110 | |
---|
111 | int gen = 0; |
---|
112 | |
---|
113 | { |
---|
114 | // -xz |
---|
115 | poly p = p_ISet(-1,R); |
---|
116 | |
---|
117 | p_SetExp(p, x, 1, R); |
---|
118 | p_SetExp(p, z, 1, R); |
---|
119 | p_Setm(p, R); |
---|
120 | |
---|
121 | assume( p_GetExp(p, x, R) == 1 ); |
---|
122 | assume( p_GetExp(p, z, R) == 1 ); |
---|
123 | assume( p_GetExp(p, w, R) == 0 ); |
---|
124 | assume( p_GetExp(p, y, R) == 0 ); |
---|
125 | |
---|
126 | // +w2 |
---|
127 | poly lp = p_ISet(1,R); |
---|
128 | p_SetExp(lp, w, 2, R); |
---|
129 | p_Setm(lp, R); |
---|
130 | |
---|
131 | assume( p_GetExp(lp, w, R) == 2 ); |
---|
132 | assume( p_GetExp(lp, x, R) == 0 ); |
---|
133 | assume( p_GetExp(lp, y, R) == 0 ); |
---|
134 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
135 | |
---|
136 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // w2 - xz |
---|
137 | } |
---|
138 | |
---|
139 | { |
---|
140 | // -yz |
---|
141 | poly p = p_ISet(-1,R); |
---|
142 | |
---|
143 | p_SetExp(p, y, 1, R); |
---|
144 | p_SetExp(p, z, 1, R); |
---|
145 | p_Setm(p, R); |
---|
146 | |
---|
147 | assume( p_GetExp(p, y, R) == 1 ); |
---|
148 | assume( p_GetExp(p, z, R) == 1 ); |
---|
149 | assume( p_GetExp(p, w, R) == 0 ); |
---|
150 | assume( p_GetExp(p, x, R) == 0 ); |
---|
151 | |
---|
152 | // +wx |
---|
153 | poly lp = p_ISet(1,R); |
---|
154 | p_SetExp(lp, w, 1, R); |
---|
155 | p_SetExp(lp, x, 1, R); |
---|
156 | p_Setm(lp, R); |
---|
157 | |
---|
158 | assume( p_GetExp(lp, w, R) == 1 ); |
---|
159 | assume( p_GetExp(lp, x, R) == 1 ); |
---|
160 | assume( p_GetExp(lp, y, R) == 0 ); |
---|
161 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
162 | |
---|
163 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // wx - yz |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | { |
---|
168 | // -wy |
---|
169 | poly p = p_ISet(-1,R); |
---|
170 | |
---|
171 | p_SetExp(p, y, 1, R); |
---|
172 | p_SetExp(p, w, 1, R); |
---|
173 | p_Setm(p, R); |
---|
174 | |
---|
175 | assume( p_GetExp(p, y, R) == 1 ); |
---|
176 | assume( p_GetExp(p, w, R) == 1 ); |
---|
177 | assume( p_GetExp(p, z, R) == 0 ); |
---|
178 | assume( p_GetExp(p, x, R) == 0 ); |
---|
179 | |
---|
180 | // +x2 |
---|
181 | poly lp = p_ISet(1,R); |
---|
182 | p_SetExp(lp, x, 2, R); |
---|
183 | p_Setm(lp, R); |
---|
184 | |
---|
185 | assume( p_GetExp(lp, w, R) == 0 ); |
---|
186 | assume( p_GetExp(lp, x, R) == 2 ); |
---|
187 | assume( p_GetExp(lp, y, R) == 0 ); |
---|
188 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
189 | |
---|
190 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // x2 - wy |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | { |
---|
195 | // -z2 |
---|
196 | poly p = p_ISet(-1,R); |
---|
197 | |
---|
198 | p_SetExp(p, z, 2, R); |
---|
199 | p_Setm(p, R); |
---|
200 | |
---|
201 | assume( p_GetExp(p, y, R) == 0 ); |
---|
202 | assume( p_GetExp(p, w, R) == 0 ); |
---|
203 | assume( p_GetExp(p, z, R) == 2 ); |
---|
204 | assume( p_GetExp(p, x, R) == 0 ); |
---|
205 | |
---|
206 | // +xy |
---|
207 | poly lp = p_ISet(1,R); |
---|
208 | p_SetExp(lp, x, 1, R); |
---|
209 | p_SetExp(lp, y, 1, R); |
---|
210 | p_Setm(lp, R); |
---|
211 | |
---|
212 | assume( p_GetExp(lp, w, R) == 0 ); |
---|
213 | assume( p_GetExp(lp, x, R) == 1 ); |
---|
214 | assume( p_GetExp(lp, y, R) == 1 ); |
---|
215 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
216 | |
---|
217 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // xy - z2 |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | { |
---|
222 | // -wz |
---|
223 | poly p = p_ISet(-1,R); |
---|
224 | |
---|
225 | p_SetExp(p, w, 1, R); |
---|
226 | p_SetExp(p, z, 1, R); |
---|
227 | p_Setm(p, R); |
---|
228 | |
---|
229 | assume( p_GetExp(p, y, R) == 0 ); |
---|
230 | assume( p_GetExp(p, w, R) == 1 ); |
---|
231 | assume( p_GetExp(p, z, R) == 1 ); |
---|
232 | assume( p_GetExp(p, x, R) == 0 ); |
---|
233 | |
---|
234 | // +y2 |
---|
235 | poly lp = p_ISet(1,R); |
---|
236 | p_SetExp(lp, y, 2, R); |
---|
237 | p_Setm(lp, R); |
---|
238 | |
---|
239 | assume( p_GetExp(lp, w, R) == 0 ); |
---|
240 | assume( p_GetExp(lp, x, R) == 0 ); |
---|
241 | assume( p_GetExp(lp, y, R) == 2 ); |
---|
242 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
243 | |
---|
244 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // y2 - wz |
---|
245 | } |
---|
246 | #ifdef PDEBUG |
---|
247 | PrintS("I: "); |
---|
248 | idShow(I, R, R, 0); |
---|
249 | #endif |
---|
250 | |
---|
251 | |
---|
252 | // ideal kStd(ideal F, ideal Q, tHomog h, intvec ** mw,intvec *hilb=NULL, |
---|
253 | // int syzComp=0,int newIdeal=0, intvec *vw=NULL); |
---|
254 | // make R the default ring: |
---|
255 | rChangeCurrRing(R); |
---|
256 | |
---|
257 | { |
---|
258 | ideal G = kStd(I, currRing->qideal, testHomog, NULL); |
---|
259 | |
---|
260 | #ifdef PDEBUG |
---|
261 | PrintS("GB: "); |
---|
262 | idShow(G, R, R, 0); |
---|
263 | #endif |
---|
264 | |
---|
265 | id_Delete( &G, R); |
---|
266 | } |
---|
267 | |
---|
268 | { |
---|
269 | intvec *weights = NULL; |
---|
270 | ideal SYZ = idSyzygies(I, testHomog, &weights); |
---|
271 | |
---|
272 | #ifdef PDEBUG |
---|
273 | PrintS("SYZ: "); |
---|
274 | idShow(SYZ, R, R, 0); |
---|
275 | #endif |
---|
276 | |
---|
277 | id_Delete(&SYZ, R); |
---|
278 | if (weights!=NULL) { PrintS("weights: "); weights->show(); delete weights; } |
---|
279 | } |
---|
280 | |
---|
281 | |
---|
282 | { |
---|
283 | PrintS("\n**********************************\n"); |
---|
284 | PrintS("lres: \n"); |
---|
285 | int dummy; |
---|
286 | syStrategy r = syLaScala3(I,&dummy); |
---|
287 | |
---|
288 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
289 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
290 | delete b; |
---|
291 | |
---|
292 | Print("length: %d\n", sySize(r)); |
---|
293 | |
---|
294 | syPrint(r, "R"); |
---|
295 | |
---|
296 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
297 | |
---|
298 | b = syBettiOfComputation(r, TRUE); |
---|
299 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
300 | delete b; |
---|
301 | |
---|
302 | Print("length: %d\n", sySize(r)); |
---|
303 | |
---|
304 | syPrint(r, "R"); |
---|
305 | |
---|
306 | syKillComputation(r, R); |
---|
307 | } |
---|
308 | |
---|
309 | { |
---|
310 | PrintS("\n**********************************\n"); |
---|
311 | PrintS("sres: \n"); |
---|
312 | const int maxl = rVar(R)-1; // +2*(1); |
---|
313 | |
---|
314 | syStrategy r = sySchreyer(I, rVar(R)); |
---|
315 | |
---|
316 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
317 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
318 | delete b; |
---|
319 | |
---|
320 | Print("length: %d\n", sySize(r)); |
---|
321 | |
---|
322 | syPrint(r, "R"); |
---|
323 | |
---|
324 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
325 | |
---|
326 | b = syBettiOfComputation(r, TRUE); |
---|
327 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
328 | delete b; |
---|
329 | |
---|
330 | Print("length: %d\n", sySize(r)); |
---|
331 | |
---|
332 | syPrint(r, "R"); |
---|
333 | |
---|
334 | syKillComputation(r, R); |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | |
---|
339 | { |
---|
340 | PrintS("\n**********************************\n"); |
---|
341 | PrintS("nres: \n"); |
---|
342 | intvec *weights=NULL; |
---|
343 | // const int maxl = rVar(R)-1 + 2*(1); |
---|
344 | syStrategy r = syResolution(I, rVar(R)-1, weights, FALSE/*iiOp==MRES_CMD*/); |
---|
345 | |
---|
346 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
347 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
348 | delete b; |
---|
349 | |
---|
350 | Print("length: %d\n", sySize(r)); |
---|
351 | |
---|
352 | syPrint(r, "R"); |
---|
353 | |
---|
354 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
355 | |
---|
356 | b = syBettiOfComputation(r, TRUE); |
---|
357 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
358 | delete b; |
---|
359 | |
---|
360 | Print("length: %d\n", sySize(r)); |
---|
361 | |
---|
362 | syPrint(r, "R"); |
---|
363 | |
---|
364 | syKillComputation(r, R); |
---|
365 | } |
---|
366 | |
---|
367 | |
---|
368 | { |
---|
369 | PrintS("\n**********************************\n"); |
---|
370 | PrintS("mres: \n"); |
---|
371 | intvec *weights=NULL; |
---|
372 | // const int maxl = rVar(R)-1 + 2*(1); |
---|
373 | syStrategy r = syResolution(I, rVar(R)+1, weights, TRUE/*iiOp==MRES_CMD*/); |
---|
374 | |
---|
375 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
376 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
377 | delete b; |
---|
378 | |
---|
379 | Print("length: %d\n", sySize(r)); |
---|
380 | |
---|
381 | syPrint(r, "R"); |
---|
382 | |
---|
383 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
384 | |
---|
385 | b = syBettiOfComputation(r, TRUE); |
---|
386 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
387 | delete b; |
---|
388 | |
---|
389 | Print("length: %d\n", sySize(r)); |
---|
390 | |
---|
391 | syPrint(r, "R"); |
---|
392 | |
---|
393 | syKillComputation(r, R); |
---|
394 | } |
---|
395 | |
---|
396 | |
---|
397 | |
---|
398 | |
---|
399 | id_Delete( &I, R); |
---|
400 | rDelete(R); // should cleanup every belonging polynomial, right!? |
---|
401 | |
---|
402 | } |
---|
403 | |
---|
404 | |
---|
405 | |
---|
406 | void TestSimpleRingArithmetcs() |
---|
407 | { |
---|
408 | // Libpolys tests: |
---|
409 | |
---|
410 | // construct the ring Z/32003[x,y,z] |
---|
411 | // the variable names |
---|
412 | char **n=(char**)omalloc(3*sizeof(char*)); |
---|
413 | n[0]=omStrDup("x"); |
---|
414 | n[1]=omStrDup("y"); |
---|
415 | n[2]=omStrDup("z2"); |
---|
416 | |
---|
417 | ring R = rDefault(32003,3,n); // ring R = rDefault(0,3,n); |
---|
418 | |
---|
419 | rWrite(R); PrintLn(); |
---|
420 | |
---|
421 | #ifdef RDEBUG |
---|
422 | rDebugPrint(R); |
---|
423 | #endif |
---|
424 | |
---|
425 | |
---|
426 | poly p = p_ISet(1,R); p_SetExp(p,1,1, R); p_Setm(p, R); |
---|
427 | |
---|
428 | assume( p_GetExp(p,1, R) == 1 ); |
---|
429 | |
---|
430 | poly pp = pp_Mult_qq( p, p, R); |
---|
431 | |
---|
432 | PrintS("p: "); p_Write0(p, R); Print(", deg(p): %ld", p_Totaldegree(p, R)); assume( 1 == p_Totaldegree(p, R) ); |
---|
433 | |
---|
434 | PrintS("; p*p : "); p_Write0(pp, R); Print("deg(pp): %ld\n", p_Totaldegree(pp, R)); assume( 2 == p_Totaldegree(pp, R) ); |
---|
435 | |
---|
436 | |
---|
437 | p_Delete(&p, R); |
---|
438 | |
---|
439 | assume( p_GetExp(pp,1, R) == 2 ); |
---|
440 | |
---|
441 | p_Delete(&pp, R); |
---|
442 | |
---|
443 | |
---|
444 | // rDelete(R); |
---|
445 | |
---|
446 | // make R the default ring: |
---|
447 | rChangeCurrRing(R); |
---|
448 | |
---|
449 | // create the polynomial 1 |
---|
450 | poly p1=pISet(1); |
---|
451 | |
---|
452 | // create tthe polynomial 2*x^3*z^2 |
---|
453 | poly p2=p_ISet(2,R); |
---|
454 | pSetExp(p2,1,3); |
---|
455 | pSetExp(p2,3,2); |
---|
456 | pSetm(p2); |
---|
457 | |
---|
458 | // print p1 + p2 |
---|
459 | PrintS("p1: "); pWrite0(p1); |
---|
460 | PrintS(" + p2: "); pWrite0(p2); |
---|
461 | PrintS(" ---- >>>> "); |
---|
462 | |
---|
463 | // compute p1+p2 |
---|
464 | p1=p_Add_q(p1,p2,R); p2=NULL; |
---|
465 | pWrite(p1); |
---|
466 | |
---|
467 | // clean up: |
---|
468 | // pDelete(&p1); |
---|
469 | |
---|
470 | rDelete(R); // should cleanup every belonging polynomial, right!? |
---|
471 | } |
---|
472 | |
---|
473 | |
---|
474 | int main( int, char *argv[] ) |
---|
475 | { |
---|
476 | assume( sizeof(long) == SIZEOF_LONG ); |
---|
477 | |
---|
478 | if( sizeof(long) != SIZEOF_LONG ) |
---|
479 | { |
---|
480 | WerrorS("Bad config.h: wrong size of long!"); |
---|
481 | |
---|
482 | return(1); |
---|
483 | } |
---|
484 | |
---|
485 | |
---|
486 | feInitResources(argv[0]); |
---|
487 | |
---|
488 | StringSetS("ressources in use (as reported by feStringAppendResources(0):\n"); |
---|
489 | feStringAppendResources(0); |
---|
490 | |
---|
491 | PrintLn(); |
---|
492 | { char* s = StringEndS(); PrintS(s); omFree(s); } |
---|
493 | |
---|
494 | TestGBEngine(); |
---|
495 | TestSimpleRingArithmetcs(); |
---|
496 | |
---|
497 | return 0; |
---|
498 | } |
---|