source: git/kernel/test.cc @ 4da485

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