source: git/kernel/GBEngine/test.cc @ 89f4843

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