source: git/kernel/test.cc @ 0f43c5

fieker-DuValspielwiese
Last change on this file since 0f43c5 was 1a1f34b, checked in by Hans Schoenemann <hannes@…>, 9 years ago
removed unsed files, fixed make_tar.sh and make dist
  • Property mode set to 100644
File size: 13.4 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/combinatorics/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/structs.h>
149#include <kernel/GBEngine/syz.h>
150// #include <kernel/testpoly.h> // Too old?
151
152#include <kernel/GBEngine/tgbgauss.h>
153#include <kernel/GBEngine/tgb.h>
154
155
156#include <kernel/GBEngine/units.h>
157#include <kernel/groebner_walk/walkMain.h>
158#include <kernel/groebner_walk/walkProc.h>
159#include <kernel/groebner_walk/walkSupport.h>
160
161#include <kernel/GBEngine/janet.h>
162#include <kernel/linear_algebra/interpolation.h>
163#include <kernel/linear_algebra/minpoly.h>
164
165#include <kernel/linear_algebra/Minor.h>
166#include <kernel/linear_algebra/MinorInterface.h>
167#include <kernel/linear_algebra/MinorProcessor.h>
168#include <kernel/linear_algebra/Cache.h>
169#include <kernel/linear_algebra/CacheImplementation.h>
170
171// #include <polys/clapconv.h> // due to factory? :(
172// #include <kernel/tgb_internal.h> // :(
173
174
175
176
177// #include <kernel/fglm/fglmzero.cc> // looks like <factory/templates/ftmpl_list.h> must be installed!
178// TODO: looks like <coeffs/mpr_complex.h> must be installed!
179
180
181
182#include <kernel/polys.h>
183
184void TestGBEngine()
185{
186
187  //  R = MPolynomialRing_polydict(QQ,5,'w,x,y,z,C', order='degrevlex')
188  //  J = (w*w - x*z, w*x - y*z, x*x - w*y, x*y - z*z, y*y - w*z)
189
190  const short w = 1;
191  const short x = 2;
192  const short y = 3;
193  const short z = 4;
194
195  const short N = (z - w + 1);
196
197  char **n=(char**)omalloc(N*sizeof(char*));
198
199
200  n[w-1]=omStrDup("w");
201  n[x-1]=omStrDup("x");
202  n[y-1]=omStrDup("y");
203  n[z-1]=omStrDup("z");
204
205
206  const int D = 3;
207  int *order = (int *) omAlloc0(D* sizeof(int));
208  int *block0 = (int *)omAlloc0(D * sizeof(int));
209  int *block1 = (int *)omAlloc0(D * sizeof(int));
210
211  order[0]  = ringorder_dp;
212  block0[0] = 1;
213  block1[0] = N;
214
215  order[1]  = ringorder_C;
216  block0[1] = 1;
217  block1[1] = N;
218
219  ring R = rDefault(0, N, n, D, order, block0, block1);
220
221//   ring R = rDefault(0, N, n);
222
223  rWrite(R); PrintLn();
224
225#ifdef RDEBUG
226  rDebugPrint(R);
227#endif
228
229  ideal I = idInit(5, 1);
230
231  int gen = 0;
232
233  {
234    // -xz
235    poly p = p_ISet(-1,R);
236
237    p_SetExp(p, x, 1, R);
238    p_SetExp(p, z, 1, R);
239    p_Setm(p, R);
240
241    assume( p_GetExp(p, x, R) == 1 );
242    assume( p_GetExp(p, z, R) == 1 );
243    assume( p_GetExp(p, w, R) == 0 );
244    assume( p_GetExp(p, y, R) == 0 );
245
246    // +w2
247    poly lp = p_ISet(1,R);
248    p_SetExp(lp, w, 2, R);
249    p_Setm(lp, R);
250
251    assume( p_GetExp(lp, w, R) == 2 );
252    assume( p_GetExp(lp, x, R) == 0 );
253    assume( p_GetExp(lp, y, R) == 0 );
254    assume( p_GetExp(lp, z, R) == 0 );
255
256    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // w2 - xz
257  }
258
259  {
260    // -yz
261    poly p = p_ISet(-1,R);
262
263    p_SetExp(p, y, 1, R);
264    p_SetExp(p, z, 1, R);
265    p_Setm(p, R);
266
267    assume( p_GetExp(p, y, R) == 1 );
268    assume( p_GetExp(p, z, R) == 1 );
269    assume( p_GetExp(p, w, R) == 0 );
270    assume( p_GetExp(p, x, R) == 0 );
271
272    // +wx
273    poly lp = p_ISet(1,R);
274    p_SetExp(lp, w, 1, R);
275    p_SetExp(lp, x, 1, R);
276    p_Setm(lp, R);
277
278    assume( p_GetExp(lp, w, R) == 1 );
279    assume( p_GetExp(lp, x, R) == 1 );
280    assume( p_GetExp(lp, y, R) == 0 );
281    assume( p_GetExp(lp, z, R) == 0 );
282
283    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // wx - yz
284  }
285
286
287  {
288    // -wy
289    poly p = p_ISet(-1,R);
290
291    p_SetExp(p, y, 1, R);
292    p_SetExp(p, w, 1, R);
293    p_Setm(p, R);
294
295    assume( p_GetExp(p, y, R) == 1 );
296    assume( p_GetExp(p, w, R) == 1 );
297    assume( p_GetExp(p, z, R) == 0 );
298    assume( p_GetExp(p, x, R) == 0 );
299
300    // +x2
301    poly lp = p_ISet(1,R);
302    p_SetExp(lp, x, 2, R);
303    p_Setm(lp, R);
304
305    assume( p_GetExp(lp, w, R) == 0 );
306    assume( p_GetExp(lp, x, R) == 2 );
307    assume( p_GetExp(lp, y, R) == 0 );
308    assume( p_GetExp(lp, z, R) == 0 );
309
310    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // x2 - wy
311  }
312
313
314  {
315    // -z2
316    poly p = p_ISet(-1,R);
317
318    p_SetExp(p, z, 2, R);
319    p_Setm(p, R);
320
321    assume( p_GetExp(p, y, R) == 0 );
322    assume( p_GetExp(p, w, R) == 0 );
323    assume( p_GetExp(p, z, R) == 2 );
324    assume( p_GetExp(p, x, R) == 0 );
325
326    // +xy
327    poly lp = p_ISet(1,R);
328    p_SetExp(lp, x, 1, R);
329    p_SetExp(lp, y, 1, R);
330    p_Setm(lp, R);
331
332    assume( p_GetExp(lp, w, R) == 0 );
333    assume( p_GetExp(lp, x, R) == 1 );
334    assume( p_GetExp(lp, y, R) == 1 );
335    assume( p_GetExp(lp, z, R) == 0 );
336
337    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // xy - z2
338  }
339
340
341  {
342    // -wz
343    poly p = p_ISet(-1,R);
344
345    p_SetExp(p, w, 1, R);
346    p_SetExp(p, z, 1, R);
347    p_Setm(p, R);
348
349    assume( p_GetExp(p, y, R) == 0 );
350    assume( p_GetExp(p, w, R) == 1 );
351    assume( p_GetExp(p, z, R) == 1 );
352    assume( p_GetExp(p, x, R) == 0 );
353
354    // +y2
355    poly lp = p_ISet(1,R);
356    p_SetExp(lp, y, 2, R);
357    p_Setm(lp, R);
358
359    assume( p_GetExp(lp, w, R) == 0 );
360    assume( p_GetExp(lp, x, R) == 0 );
361    assume( p_GetExp(lp, y, R) == 2 );
362    assume( p_GetExp(lp, z, R) == 0 );
363
364    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // y2 - wz
365  }
366#ifdef PDEBUG
367  PrintS("I: ");
368  idShow(I, R, R, 0);
369#endif
370
371
372//  ideal kStd(ideal F, ideal Q, tHomog h, intvec ** mw,intvec *hilb=NULL,
373//             int syzComp=0,int newIdeal=0, intvec *vw=NULL);
374  // make R the default ring:
375  rChangeCurrRing(R);
376
377  {
378    ideal G = kStd(I, currRing->qideal, testHomog, NULL);
379
380#ifdef PDEBUG
381    PrintS("GB: ");
382    idShow(G, R, R, 0);
383#endif
384
385    id_Delete( &G, R);
386  }
387
388  {
389    intvec *weights = NULL;
390    ideal SYZ = idSyzygies(I, testHomog, &weights);
391
392#ifdef PDEBUG
393    PrintS("SYZ: ");
394    idShow(SYZ, R, R, 0);
395#endif
396
397    id_Delete(&SYZ, R);
398    if (weights!=NULL) { PrintS("weights: "); weights->show(); delete weights; }
399  }
400
401
402  {
403    PrintS("\n**********************************\n");
404    PrintS("lres: \n");
405    int dummy;
406    syStrategy r = syLaScala3(I,&dummy);
407
408    intvec *b = syBettiOfComputation(r, FALSE);
409    PrintS("non-min. betti: \n");    b->show();    PrintLn();
410    delete b;
411
412    Print("length: %d\n", sySize(r));
413
414    syPrint(r, "R");
415
416    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
417
418    b = syBettiOfComputation(r, TRUE);
419    PrintS("min. betti: \n");    b->show();    PrintLn();
420    delete b;
421
422    Print("length: %d\n", sySize(r));
423
424    syPrint(r, "R");
425
426    syKillComputation(r, R);
427  }
428
429  {
430    PrintS("\n**********************************\n");
431    PrintS("sres: \n");
432    const int maxl = rVar(R)-1; // +2*(1);
433
434    syStrategy r = sySchreyer(I, rVar(R));
435
436    intvec *b = syBettiOfComputation(r, FALSE);
437    PrintS("non-min. betti: \n");    b->show();    PrintLn();
438    delete b;
439
440    Print("length: %d\n", sySize(r));
441
442    syPrint(r, "R");
443
444    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
445
446    b = syBettiOfComputation(r, TRUE);
447    PrintS("min. betti: \n");    b->show();    PrintLn();
448    delete b;
449
450    Print("length: %d\n", sySize(r));
451
452    syPrint(r, "R");
453
454    syKillComputation(r, R);
455  }
456
457
458
459  {
460    PrintS("\n**********************************\n");
461    PrintS("nres: \n");
462    intvec *weights=NULL;
463//    const int maxl = rVar(R)-1 + 2*(1);
464    syStrategy r = syResolution(I, rVar(R)-1, weights, FALSE/*iiOp==MRES_CMD*/);
465
466    intvec *b = syBettiOfComputation(r, FALSE);
467    PrintS("non-min. betti: \n");    b->show();    PrintLn();
468    delete b;
469
470    Print("length: %d\n", sySize(r));
471
472    syPrint(r, "R");
473
474    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
475
476    b = syBettiOfComputation(r, TRUE);
477    PrintS("min. betti: \n");    b->show();    PrintLn();
478    delete b;
479
480    Print("length: %d\n", sySize(r));
481
482    syPrint(r, "R");
483
484    syKillComputation(r, R);
485  }
486
487
488  {
489    PrintS("\n**********************************\n");
490    PrintS("mres: \n");
491    intvec *weights=NULL;
492//    const int maxl = rVar(R)-1 + 2*(1);
493    syStrategy r = syResolution(I, rVar(R)+1, weights, TRUE/*iiOp==MRES_CMD*/);
494
495    intvec *b = syBettiOfComputation(r, FALSE);
496    PrintS("non-min. betti: \n");    b->show();    PrintLn();
497    delete b;
498
499    Print("length: %d\n", sySize(r));
500
501    syPrint(r, "R");
502
503    r =  syMinimize(r); // syzstr->references ++ ==> memory leak :(((
504
505    b = syBettiOfComputation(r, TRUE);
506    PrintS("min. betti: \n");    b->show();    PrintLn();
507    delete b;
508
509    Print("length: %d\n", sySize(r));
510
511    syPrint(r, "R");
512
513    syKillComputation(r, R);
514  }
515
516
517
518
519  id_Delete( &I, R);
520  rDelete(R); // should cleanup every belonging polynomial, right!?
521
522}
523
524
525
526void TestSimpleRingArithmetcs()
527{
528  // Libpolys tests:
529
530  // construct the ring Z/32003[x,y,z]
531  // the variable names
532  char **n=(char**)omalloc(3*sizeof(char*));
533  n[0]=omStrDup("x");
534  n[1]=omStrDup("y");
535  n[2]=omStrDup("z2");
536
537  ring R = rDefault(32003,3,n); //  ring R = rDefault(0,3,n);
538
539  rWrite(R); PrintLn();
540
541#ifdef RDEBUG
542  rDebugPrint(R);
543#endif
544
545
546  poly p = p_ISet(1,R); p_SetExp(p,1,1, R); p_Setm(p, R);
547
548  assume( p_GetExp(p,1, R) == 1 );
549
550  poly pp = pp_Mult_qq( p, p, R);
551
552  Print("p: "); p_Write0(p, R); Print(", deg(p): %ld", p_Totaldegree(p, R)); assume( 1 == p_Totaldegree(p, R) );
553
554  Print("; p*p : "); p_Write0(pp, R); Print("deg(pp): %ld\n", p_Totaldegree(pp, R)); assume( 2 == p_Totaldegree(pp, R) );
555
556
557  p_Delete(&p, R);
558
559  assume( p_GetExp(pp,1, R) == 2 );
560
561  p_Delete(&pp, R);
562
563
564//  rDelete(R);
565
566  // make R the default ring:
567  rChangeCurrRing(R);
568
569  // create the polynomial 1
570  poly p1=pISet(1);
571
572  // create tthe polynomial 2*x^3*z^2
573  poly p2=p_ISet(2,R);
574  pSetExp(p2,1,3);
575  pSetExp(p2,3,2);
576  pSetm(p2);
577
578  // print p1 + p2
579  Print("p1: "); pWrite0(p1);
580  Print(" + p2: "); pWrite0(p2);
581  Print("  ---- >>>> ");
582
583  // compute p1+p2
584  p1=p_Add_q(p1,p2,R); p2=NULL;
585  pWrite(p1);
586
587  // clean up:
588//  pDelete(&p1);
589
590  rDelete(R); // should cleanup every belonging polynomial, right!?
591}
592
593
594int main( int, char *argv[] )
595{
596  assume( sizeof(long) == SIZEOF_LONG );
597
598  if( sizeof(long) != SIZEOF_LONG )
599  {
600    WerrorS("Bad config.h: wrong size of long!");
601
602    return(1);
603  }
604
605
606  feInitResources(argv[0]);
607
608  StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
609  feStringAppendResources(0);
610
611  PrintLn();
612  { char* s = StringEndS(); PrintS(s); omFree(s); }
613
614  TestGBEngine();
615  TestSimpleRingArithmetcs();
616
617  return 0;
618}
Note: See TracBrowser for help on using the repository browser.