source: git/kernel/test.cc @ 9b49b20

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