source: git/kernel/test.cc @ 8f26a44

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