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

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