source: git/kernel/GBEngine/test.cc @ d73d74

spielwiese
Last change on this file since d73d74 was d73d74, checked in by Hans Schoenemann <hannes@…>, 3 years ago
compiler warnings: signed etc
  • Property mode set to 100644
File size: 10.5 KB
Line 
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
64void 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
313    syStrategy r = sySchreyer(I, rVar(R));
314
315    intvec *b = syBettiOfComputation(r, FALSE);
316    PrintS("non-min. betti: \n");    b->show();    PrintLn();
317    delete b;
318
319    Print("length: %d\n", sySize(r));
320
321    syPrint(r, "R");
322
323    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
324
325    b = syBettiOfComputation(r, TRUE);
326    PrintS("min. betti: \n");    b->show();    PrintLn();
327    delete b;
328
329    Print("length: %d\n", sySize(r));
330
331    syPrint(r, "R");
332
333    syKillComputation(r, R);
334  }
335
336
337
338  {
339    PrintS("\n**********************************\n");
340    PrintS("nres: \n");
341    intvec *weights=NULL;
342//    const int maxl = rVar(R)-1 + 2*(1);
343    syStrategy r = syResolution(I, rVar(R)-1, weights, FALSE/*iiOp==MRES_CMD*/);
344
345    intvec *b = syBettiOfComputation(r, FALSE);
346    PrintS("non-min. betti: \n");    b->show();    PrintLn();
347    delete b;
348
349    Print("length: %d\n", sySize(r));
350
351    syPrint(r, "R");
352
353    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
354
355    b = syBettiOfComputation(r, TRUE);
356    PrintS("min. betti: \n");    b->show();    PrintLn();
357    delete b;
358
359    Print("length: %d\n", sySize(r));
360
361    syPrint(r, "R");
362
363    syKillComputation(r, R);
364  }
365
366
367  {
368    PrintS("\n**********************************\n");
369    PrintS("mres: \n");
370    intvec *weights=NULL;
371//    const int maxl = rVar(R)-1 + 2*(1);
372    syStrategy r = syResolution(I, rVar(R)+1, weights, TRUE/*iiOp==MRES_CMD*/);
373
374    intvec *b = syBettiOfComputation(r, FALSE);
375    PrintS("non-min. betti: \n");    b->show();    PrintLn();
376    delete b;
377
378    Print("length: %d\n", sySize(r));
379
380    syPrint(r, "R");
381
382    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
383
384    b = syBettiOfComputation(r, TRUE);
385    PrintS("min. betti: \n");    b->show();    PrintLn();
386    delete b;
387
388    Print("length: %d\n", sySize(r));
389
390    syPrint(r, "R");
391
392    syKillComputation(r, R);
393  }
394
395
396
397
398  id_Delete( &I, R);
399  rDelete(R); // should cleanup every belonging polynomial, right!?
400
401}
402
403
404
405void TestSimpleRingArithmetcs()
406{
407  // Libpolys tests:
408
409  // construct the ring Z/32003[x,y,z]
410  // the variable names
411  char **n=(char**)omalloc(3*sizeof(char*));
412  n[0]=omStrDup("x");
413  n[1]=omStrDup("y");
414  n[2]=omStrDup("z2");
415
416  ring R = rDefault(32003,3,n); //  ring R = rDefault(0,3,n);
417
418  rWrite(R); PrintLn();
419
420#ifdef RDEBUG
421  rDebugPrint(R);
422#endif
423
424
425  poly p = p_ISet(1,R); p_SetExp(p,1,1, R); p_Setm(p, R);
426
427  assume( p_GetExp(p,1, R) == 1 );
428
429  poly pp = pp_Mult_qq( p, p, R);
430
431  PrintS("p: "); p_Write0(p, R); Print(", deg(p): %ld", p_Totaldegree(p, R)); assume( 1 == p_Totaldegree(p, R) );
432
433  PrintS("; p*p : "); p_Write0(pp, R); Print("deg(pp): %ld\n", p_Totaldegree(pp, R)); assume( 2 == p_Totaldegree(pp, R) );
434
435
436  p_Delete(&p, R);
437
438  assume( p_GetExp(pp,1, R) == 2 );
439
440  p_Delete(&pp, R);
441
442
443//  rDelete(R);
444
445  // make R the default ring:
446  rChangeCurrRing(R);
447
448  // create the polynomial 1
449  poly p1=pISet(1);
450
451  // create tthe polynomial 2*x^3*z^2
452  poly p2=p_ISet(2,R);
453  pSetExp(p2,1,3);
454  pSetExp(p2,3,2);
455  pSetm(p2);
456
457  // print p1 + p2
458  PrintS("p1: "); pWrite0(p1);
459  PrintS(" + p2: "); pWrite0(p2);
460  PrintS("  ---- >>>> ");
461
462  // compute p1+p2
463  p1=p_Add_q(p1,p2,R); p2=NULL;
464  pWrite(p1);
465
466  // clean up:
467//  pDelete(&p1);
468
469  rDelete(R); // should cleanup every belonging polynomial, right!?
470}
471
472
473int main( int, char *argv[] )
474{
475  assume( sizeof(long) == SIZEOF_LONG );
476
477  if( sizeof(long) != SIZEOF_LONG )
478  {
479    WerrorS("Bad config.h: wrong size of long!");
480
481    return(1);
482  }
483
484
485  feInitResources(argv[0]);
486
487  StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
488  feStringAppendResources(0);
489
490  PrintLn();
491  { char* s = StringEndS(); PrintS(s); omFree(s); }
492
493  TestGBEngine();
494  TestSimpleRingArithmetcs();
495
496  return 0;
497}
Note: See TracBrowser for help on using the repository browser.