source: git/kernel/test.cc @ 266ae3

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