source: git/kernel/test.cc @ cd5fefc

fieker-DuValspielwiese
Last change on this file since cd5fefc was 59f97c, checked in by Oleksandr Motsak <motsak@…>, 10 years ago
Defined libkernelCommon.la to be the actual shared part of libkernel.la
  • Property mode set to 100644
File size: 13.5 KB
Line 
1#include <kernel/mod2.h>
2
3#include <omalloc/omalloc.h>
4#include <misc/auxiliary.h>
5#include <factory/factory.h> // :(
6
7#include <misc/intvec.h>
8#include <misc/int64vec.h>
9#include <misc/mylimits.h>
10#include <misc/options.h>
11
12#include <reporter/reporter.h>
13
14#include <resources/feFopen.h>
15#include <resources/feResource.h>
16
17#include <coeffs/coeffs.h>
18
19#include <coeffs/si_gmp.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
29#include <polys/monomials/maps.h>
30#include <polys/monomials/monomials.h>
31#include <polys/monomials/p_polys.h>
32#include <polys/monomials/ring.h>
33
34#include <polys/nc/nc.h>
35#include <polys/nc/ncSACache.h>
36#include <polys/nc/ncSAFormula.h>
37#include <polys/nc/ncSAMult.h>
38#include <polys/nc/sca.h>
39#include <polys/nc/summator.h>
40
41
42#include <polys/templates/p_MemAdd.h>
43#include <polys/templates/p_Procs.h>
44
45#include <polys/operations/pShallowCopyDelete.h>
46
47#include <polys/clapsing.h>
48
49
50// // TODO: DUE to the use of HALT in npolygon.cc :(((
51extern "C" {void m2_end(int i){exit(i);}}
52
53// // TODO: DUE to its use in kutil.cc :(((
54char * showOption(){return NULL;}
55
56// // TODO: DUE to its use in feread.cc :(((
57char *iiArithGetCmd(int nPos){return NULL; }
58
59
60#include <coeffs/numbers.h>
61
62#include "structs.h"
63
64
65// HEADERS:
66#include <kernel/combinatorics/hutil.h>
67#include <kernel/GBEngine/stairc.h>
68#include <kernel/ideals.h>
69#include <kernel/GBEngine/syz.h>
70#include <kernel/maps/fast_maps.h>
71#include <kernel/groebner_walk/walkProc.h>
72#include <kernel/groebner_walk/walkMain.h>
73#include <kernel/groebner_walk/walkSupport.h>
74#include <kernel/GBEngine/khstd.h>
75/// #include <kernel/sparsmat.h> // TODO: install polys/this!
76//+
77
78#include <kernel/fglm/fglm.h>
79#include <kernel/GBEngine/kstd1.h>
80#include <kernel/fglm/fglmgauss.h>
81#include <kernel/fglm/fglmvec.h>
82#include <kernel/GBEngine/kstdfac.h>
83#include <kernel/spectrum/kmatrix.h>
84#include <kernel/spectrum/GMPrat.h>
85#include <kernel/spectrum/multicnt.h>
86#include <kernel/spectrum/npolygon.h>
87#include <kernel/spectrum/semic.h>
88#include <kernel/spectrum/spectrum.h>
89#include <kernel/spectrum/splist.h>
90#include <kernel/spectrum/multicnt.h>
91#include <kernel/linear_algebra/eigenval.h>
92#include <kernel/GBEngine/units.h>
93#include <kernel/GBEngine/ratgring.h>
94#include <kernel/GBEngine/shiftgb.h>
95
96
97#include <kernel/GBEngine/kutil.h>
98
99// #include "CCRing.h" // Too old!
100#include <kernel/digitech.h>
101#include <kernel/linear_algebra/eigenval.h>
102#include <kernel/maps/fast_maps.h>
103#include <kernel/fast_mult.h>
104
105#include <kernel/fglm/fglmgauss.h>
106#include <kernel/fglm/fglm.h>
107#include <kernel/fglm/fglmvec.h>
108
109////////#include <kernel/F5cData.h>
110#include <kernel/GBEngine/f5c.h>
111#include <kernel/GBEngine/f5data.h>
112#include <kernel/GBEngine/f5gb.h>
113#include <kernel/GBEngine/f5lists.h>
114////////#include <kernel/F5cLists.h>
115
116
117// #include "Ideal.h" // Too old?
118
119
120#include <kernel/ideals.h>
121
122#include <kernel/spectrum/kmatrix.h>
123#include <kernel/GBEngine/kstd1.h>
124#include <kernel/GBEngine/kstdfac.h>
125#include <kernel/GBEngine/khstd.h>
126
127#include <kernel/linear_algebra/linearAlgebra.h>
128
129
130
131// #include <kernel/lplist.h> // Too old!
132#include <kernel/spectrum/multicnt.h>
133#include <kernel/spectrum/npolygon.h>
134// #include "Number.h" // Too old?
135// #include "Poly.h" // Too old?
136// #include "PowerSeries.h" // Too old?
137
138#include <kernel/preimage.h>
139
140#include <kernel/GBEngine/nc.h>
141
142#include <kernel/GBEngine/ratgring.h>
143#include <kernel/GBEngine/ringgb.h>
144#include <kernel/spectrum/semic.h>
145#include <kernel/GBEngine/shiftgb.h>
146#include <kernel/spectrum/spectrum.h>
147#include <kernel/spectrum/splist.h>
148#include <kernel/GBEngine/stairc.h>
149#include <kernel/structs.h>
150#include <kernel/GBEngine/syz.h>
151// #include <kernel/testpoly.h> // Too old?
152
153#include <kernel/GBEngine/tgbgauss.h>
154#include <kernel/GBEngine/tgb.h>
155
156
157#include <kernel/GBEngine/units.h>
158#include <kernel/groebner_walk/walkMain.h>
159#include <kernel/groebner_walk/walkProc.h>
160#include <kernel/groebner_walk/walkSupport.h>
161
162#include <kernel/GBEngine/janet.h>
163#include <kernel/linear_algebra/interpolation.h>
164#include <kernel/linear_algebra/minpoly.h>
165
166#include <kernel/linear_algebra/Minor.h>
167#include <kernel/linear_algebra/MinorInterface.h>
168#include <kernel/linear_algebra/MinorProcessor.h>
169#include <kernel/linear_algebra/Cache.h>
170#include <kernel/linear_algebra/CacheImplementation.h>
171
172// #include <polys/clapconv.h> // due to factory? :(
173// #include <kernel/tgb_internal.h> // :(
174// #include <kernel/F4.h> // uses tgb_internal // :(
175
176
177
178
179// #include <kernel/fglm/fglmzero.cc> // looks like <factory/templates/ftmpl_list.h> must be installed!
180// TODO: looks like <coeffs/mpr_complex.h> must be installed!
181
182
183
184#include <kernel/polys.h>
185
186void TestGBEngine()
187{
188
189  //  R = MPolynomialRing_polydict(QQ,5,'w,x,y,z,C', order='degrevlex')
190  //  J = (w*w - x*z, w*x - y*z, x*x - w*y, x*y - z*z, y*y - w*z)
191
192  const short w = 1;
193  const short x = 2;
194  const short y = 3;
195  const short z = 4;
196
197  const short N = (z - w + 1);
198
199  char **n=(char**)omalloc(N*sizeof(char*));
200
201
202  n[w-1]=omStrDup("w");
203  n[x-1]=omStrDup("x");
204  n[y-1]=omStrDup("y");
205  n[z-1]=omStrDup("z");
206
207
208  const int D = 3;
209  int *order = (int *) omAlloc0(D* sizeof(int));
210  int *block0 = (int *)omAlloc0(D * sizeof(int));
211  int *block1 = (int *)omAlloc0(D * sizeof(int));
212
213  order[0]  = ringorder_dp;
214  block0[0] = 1;
215  block1[0] = N;
216
217  order[1]  = ringorder_C;
218  block0[1] = 1;
219  block1[1] = N;
220
221  ring R = rDefault(0, N, n, D, order, block0, block1);
222
223//   ring R = rDefault(0, N, n);
224
225  rWrite(R); PrintLn();
226
227#ifdef RDEBUG
228  rDebugPrint(R);
229#endif
230
231  ideal I = idInit(5, 1);
232
233  int gen = 0;
234
235  {
236    // -xz
237    poly p = p_ISet(-1,R);
238
239    p_SetExp(p, x, 1, R);
240    p_SetExp(p, z, 1, R);
241    p_Setm(p, R);
242
243    assume( p_GetExp(p, x, R) == 1 );
244    assume( p_GetExp(p, z, R) == 1 );
245    assume( p_GetExp(p, w, R) == 0 );
246    assume( p_GetExp(p, y, R) == 0 );
247
248    // +w2
249    poly lp = p_ISet(1,R);
250    p_SetExp(lp, w, 2, R);
251    p_Setm(lp, R);
252
253    assume( p_GetExp(lp, w, R) == 2 );
254    assume( p_GetExp(lp, x, R) == 0 );
255    assume( p_GetExp(lp, y, R) == 0 );
256    assume( p_GetExp(lp, z, R) == 0 );
257
258    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // w2 - xz
259  }
260
261  {
262    // -yz
263    poly p = p_ISet(-1,R);
264
265    p_SetExp(p, y, 1, R);
266    p_SetExp(p, z, 1, R);
267    p_Setm(p, R);
268
269    assume( p_GetExp(p, y, R) == 1 );
270    assume( p_GetExp(p, z, R) == 1 );
271    assume( p_GetExp(p, w, R) == 0 );
272    assume( p_GetExp(p, x, R) == 0 );
273
274    // +wx
275    poly lp = p_ISet(1,R);
276    p_SetExp(lp, w, 1, R);
277    p_SetExp(lp, x, 1, R);
278    p_Setm(lp, R);
279
280    assume( p_GetExp(lp, w, R) == 1 );
281    assume( p_GetExp(lp, x, R) == 1 );
282    assume( p_GetExp(lp, y, R) == 0 );
283    assume( p_GetExp(lp, z, R) == 0 );
284
285    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // wx - yz
286  }
287
288
289  {
290    // -wy
291    poly p = p_ISet(-1,R);
292
293    p_SetExp(p, y, 1, R);
294    p_SetExp(p, w, 1, R);
295    p_Setm(p, R);
296
297    assume( p_GetExp(p, y, R) == 1 );
298    assume( p_GetExp(p, w, R) == 1 );
299    assume( p_GetExp(p, z, R) == 0 );
300    assume( p_GetExp(p, x, R) == 0 );
301
302    // +x2
303    poly lp = p_ISet(1,R);
304    p_SetExp(lp, x, 2, R);
305    p_Setm(lp, R);
306
307    assume( p_GetExp(lp, w, R) == 0 );
308    assume( p_GetExp(lp, x, R) == 2 );
309    assume( p_GetExp(lp, y, R) == 0 );
310    assume( p_GetExp(lp, z, R) == 0 );
311
312    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // x2 - wy
313  }
314
315
316  {
317    // -z2
318    poly p = p_ISet(-1,R);
319
320    p_SetExp(p, z, 2, R);
321    p_Setm(p, R);
322
323    assume( p_GetExp(p, y, R) == 0 );
324    assume( p_GetExp(p, w, R) == 0 );
325    assume( p_GetExp(p, z, R) == 2 );
326    assume( p_GetExp(p, x, R) == 0 );
327
328    // +xy
329    poly lp = p_ISet(1,R);
330    p_SetExp(lp, x, 1, R);
331    p_SetExp(lp, y, 1, R);
332    p_Setm(lp, R);
333
334    assume( p_GetExp(lp, w, R) == 0 );
335    assume( p_GetExp(lp, x, R) == 1 );
336    assume( p_GetExp(lp, y, R) == 1 );
337    assume( p_GetExp(lp, z, R) == 0 );
338
339    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // xy - z2
340  }
341
342
343  {
344    // -wz
345    poly p = p_ISet(-1,R);
346
347    p_SetExp(p, w, 1, R);
348    p_SetExp(p, z, 1, R);
349    p_Setm(p, R);
350
351    assume( p_GetExp(p, y, R) == 0 );
352    assume( p_GetExp(p, w, R) == 1 );
353    assume( p_GetExp(p, z, R) == 1 );
354    assume( p_GetExp(p, x, R) == 0 );
355
356    // +y2
357    poly lp = p_ISet(1,R);
358    p_SetExp(lp, y, 2, R);
359    p_Setm(lp, R);
360
361    assume( p_GetExp(lp, w, R) == 0 );
362    assume( p_GetExp(lp, x, R) == 0 );
363    assume( p_GetExp(lp, y, R) == 2 );
364    assume( p_GetExp(lp, z, R) == 0 );
365
366    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // y2 - wz
367  }
368#ifdef PDEBUG
369  PrintS("I: ");
370  idShow(I, R, R, 0);
371#endif
372
373
374//  ideal kStd(ideal F, ideal Q, tHomog h, intvec ** mw,intvec *hilb=NULL,
375//             int syzComp=0,int newIdeal=0, intvec *vw=NULL);
376  // make R the default ring:
377  rChangeCurrRing(R);
378
379  {
380    ideal G = kStd(I, currQuotient, testHomog, NULL);
381
382#ifdef PDEBUG
383    PrintS("GB: ");
384    idShow(G, R, R, 0);
385#endif
386
387    idDelete( &G, R);
388  }
389
390  {
391    intvec *weights = NULL;
392    ideal SYZ = idSyzygies(I, testHomog, &weights);
393
394#ifdef PDEBUG
395    PrintS("SYZ: ");
396    idShow(SYZ, R, R, 0);
397#endif
398
399    idDelete(&SYZ, R);
400    if (weights!=NULL) { PrintS("weights: "); weights->show(); delete weights; }
401  }
402
403
404  {
405    PrintS("\n**********************************\n");
406    PrintS("lres: \n");
407    int dummy;
408    syStrategy r = syLaScala3(I,&dummy);
409
410    intvec *b = syBettiOfComputation(r, FALSE);
411    PrintS("non-min. betti: \n");    b->show();    PrintLn();
412    delete b;
413
414    Print("length: %d\n", sySize(r));
415
416    syPrint(r, "R");
417
418    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
419
420    b = syBettiOfComputation(r, TRUE);
421    PrintS("min. betti: \n");    b->show();    PrintLn();
422    delete b;
423
424    Print("length: %d\n", sySize(r));
425
426    syPrint(r, "R");
427
428    syKillComputation(r, R);
429  }
430
431  {
432    PrintS("\n**********************************\n");
433    PrintS("sres: \n");
434    const int maxl = rVar(R)-1; // +2*(1);
435
436    syStrategy r = sySchreyer(I, rVar(R));
437
438    intvec *b = syBettiOfComputation(r, FALSE);
439    PrintS("non-min. betti: \n");    b->show();    PrintLn();
440    delete b;
441
442    Print("length: %d\n", sySize(r));
443
444    syPrint(r, "R");
445
446    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
447
448    b = syBettiOfComputation(r, TRUE);
449    PrintS("min. betti: \n");    b->show();    PrintLn();
450    delete b;
451
452    Print("length: %d\n", sySize(r));
453
454    syPrint(r, "R");
455
456    syKillComputation(r, R);
457  }
458
459
460
461  {
462    PrintS("\n**********************************\n");
463    PrintS("nres: \n");
464    intvec *weights=NULL;
465//    const int maxl = rVar(R)-1 + 2*(1);
466    syStrategy r = syResolution(I, rVar(R)-1, weights, FALSE/*iiOp==MRES_CMD*/);
467
468    intvec *b = syBettiOfComputation(r, FALSE);
469    PrintS("non-min. betti: \n");    b->show();    PrintLn();
470    delete b;
471
472    Print("length: %d\n", sySize(r));
473
474    syPrint(r, "R");
475
476    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
477
478    b = syBettiOfComputation(r, TRUE);
479    PrintS("min. betti: \n");    b->show();    PrintLn();
480    delete b;
481
482    Print("length: %d\n", sySize(r));
483
484    syPrint(r, "R");
485
486    syKillComputation(r, R);
487  }
488
489
490  {
491    PrintS("\n**********************************\n");
492    PrintS("mres: \n");
493    intvec *weights=NULL;
494//    const int maxl = rVar(R)-1 + 2*(1);
495    syStrategy r = syResolution(I, rVar(R)+1, weights, TRUE/*iiOp==MRES_CMD*/);
496
497    intvec *b = syBettiOfComputation(r, FALSE);
498    PrintS("non-min. betti: \n");    b->show();    PrintLn();
499    delete b;
500
501    Print("length: %d\n", sySize(r));
502
503    syPrint(r, "R");
504
505    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
506
507    b = syBettiOfComputation(r, TRUE);
508    PrintS("min. betti: \n");    b->show();    PrintLn();
509    delete b;
510
511    Print("length: %d\n", sySize(r));
512
513    syPrint(r, "R");
514
515    syKillComputation(r, R);
516  }
517
518
519
520
521  idDelete( &I, R);
522  rDelete(R); // should cleanup every belonging polynomial, right!?
523
524}
525
526
527
528void TestSimpleRingArithmetcs()
529{
530  // Libpolys tests:
531
532  // construct the ring Z/32003[x,y,z]
533  // the variable names
534  char **n=(char**)omalloc(3*sizeof(char*));
535  n[0]=omStrDup("x");
536  n[1]=omStrDup("y");
537  n[2]=omStrDup("z2");
538
539  ring R = rDefault(32003,3,n); //  ring R = rDefault(0,3,n);
540
541  rWrite(R); PrintLn();
542
543#ifdef RDEBUG
544  rDebugPrint(R);
545#endif
546
547
548  poly p = p_ISet(1,R); p_SetExp(p,1,1, R); p_Setm(p, R);
549
550  assume( p_GetExp(p,1, R) == 1 );
551
552  poly pp = pp_Mult_qq( p, p, R);
553
554  Print("p: "); p_Write0(p, R); Print(", deg(p): %d", p_Totaldegree(p, R)); assume( 1 == p_Totaldegree(p, R) );
555
556  Print("; p*p : "); p_Write0(pp, R); Print("deg(pp): %d\n", p_Totaldegree(pp, R)); assume( 2 == p_Totaldegree(pp, R) );
557
558
559  p_Delete(&p, R);
560
561  assume( p_GetExp(pp,1, R) == 2 );
562
563  p_Delete(&pp, R);
564
565
566//  rDelete(R);
567
568  // make R the default ring:
569  rChangeCurrRing(R);
570
571  // create the polynomial 1
572  poly p1=pISet(1);
573
574  // create tthe polynomial 2*x^3*z^2
575  poly p2=p_ISet(2,R);
576  pSetExp(p2,1,3);
577  pSetExp(p2,3,2);
578  pSetm(p2);
579
580  // print p1 + p2
581  Print("p1: "); pWrite0(p1);
582  Print(" + p2: "); pWrite0(p2);
583  Print("  ---- >>>> ");
584
585  // compute p1+p2
586  p1=p_Add_q(p1,p2,R); p2=NULL;
587  pWrite(p1);
588
589  // clean up:
590//  pDelete(&p1);
591
592  rDelete(R); // should cleanup every belonging polynomial, right!?
593}
594
595
596int main( int, char *argv[] )
597{
598  assume( sizeof(long) == SIZEOF_LONG );
599
600  if( sizeof(long) != SIZEOF_LONG )
601  {
602    WerrorS("Bad config.h: wrong size of long!");
603
604    return(1);
605  }
606
607
608  feInitResources(argv[0]);
609
610  StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
611  feStringAppendResources(0);
612
613  PrintLn();
614  { char* s = StringEndS(); PrintS(s); omFree(s); }
615
616  TestGBEngine();
617  TestSimpleRingArithmetcs();
618
619  return 0;
620}
Note: See TracBrowser for help on using the repository browser.