source: git/kernel/GBEngine/test.cc @ 891f0e

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