source: git/kernel/combinatorics/test.cc @ 891f0e

spielwiese
Last change on this file since 891f0e was 891f0e, checked in by Hans Schoenemann <hannes@…>, 6 years ago
fix: make check for static builds
  • Property mode set to 100644
File size: 7.3 KB
Line 
1#include "kernel/mod2.h"
2
3#include "omalloc/omalloc.h"
4
5#include "resources/feFopen.h"
6#include "resources/feResource.h"
7
8
9#include "factory/factory.h" // :(
10
11#include "misc/intvec.h"
12#include "misc/int64vec.h"
13#include "misc/mylimits.h"
14#include "misc/options.h"
15
16#include "reporter/reporter.h"
17
18#include "coeffs/si_gmp.h"
19#include "coeffs/coeffs.h"
20#include "coeffs/numbers.h"
21
22#ifndef PLURAL_INTERNAL_DECLARATIONS
23#define PLURAL_INTERNAL_DECLARATIONS
24#endif
25
26#include "polys/nc/gb_hack.h"
27#include "polys/nc/nc.h"
28#include "polys/nc/ncSACache.h"
29#include "polys/nc/ncSAFormula.h"
30#include "polys/nc/ncSAMult.h"
31#include "polys/nc/sca.h"
32#include "polys/nc/summator.h"
33
34#include "polys/kbuckets.h"
35#include "polys/matpol.h"
36#include "polys/mod_raw.h"
37#include "polys/prCopy.h"
38#include "polys/sbuckets.h"
39#include "polys/simpleideals.h"
40#include "polys/weight.h"
41
42#include "polys/monomials/maps.h"
43#include "polys/monomials/monomials.h"
44#include "polys/monomials/p_polys.h"
45#include "polys/monomials/ring.h"
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// #include "structs.h"
56
57
58// HEADERS:
59#include "kernel/combinatorics/hutil.h"
60#include "kernel/combinatorics/hilb.h"
61#include "kernel/combinatorics/stairc.h"
62
63#include "kernel/ideals.h"
64#include "kernel/digitech.h"
65#include "kernel/fast_mult.h"
66
67// #include "kernel/spectrum/kmatrix.h"
68#include "kernel/preimage.h"
69#include "kernel/structs.h"
70#include "kernel/polys.h"
71
72void TestGBEngine()
73{
74
75  //  R = MPolynomialRing_polydict(QQ,5,'w,x,y,z,C', order='degrevlex')
76  //  J = (w*w - x*z, w*x - y*z, x*x - w*y, x*y - z*z, y*y - w*z)
77
78  const short w = 1;
79  const short x = 2;
80  const short y = 3;
81  const short z = 4;
82
83  const short N = (z - w + 1);
84
85  char **n=(char**)omalloc(N*sizeof(char*));
86
87
88  n[w-1]=omStrDup("w");
89  n[x-1]=omStrDup("x");
90  n[y-1]=omStrDup("y");
91  n[z-1]=omStrDup("z");
92
93
94  const int D = 3;
95  rRingOrder_t *order = (rRingOrder_t *) omAlloc0(D* sizeof(rRingOrder_t));
96  int *block0 = (int *)omAlloc0(D * sizeof(int));
97  int *block1 = (int *)omAlloc0(D * sizeof(int));
98
99  order[0]  = ringorder_dp;
100  block0[0] = 1;
101  block1[0] = N;
102
103  order[1]  = ringorder_C;
104  block0[1] = 1;
105  block1[1] = N;
106
107  ring R = rDefault(0, N, n, D, order, block0, block1);
108
109//   ring R = rDefault(0, N, n);
110
111  rWrite(R); PrintLn();
112
113#ifdef RDEBUG
114  rDebugPrint(R);
115#endif
116
117  ideal I = idInit(5, 1);
118
119  int gen = 0;
120
121  {
122    // -xz
123    poly p = p_ISet(-1,R);
124
125    p_SetExp(p, x, 1, R);
126    p_SetExp(p, z, 1, R);
127    p_Setm(p, R);
128
129    assume( p_GetExp(p, x, R) == 1 );
130    assume( p_GetExp(p, z, R) == 1 );
131    assume( p_GetExp(p, w, R) == 0 );
132    assume( p_GetExp(p, y, R) == 0 );
133
134    // +w2
135    poly lp = p_ISet(1,R);
136    p_SetExp(lp, w, 2, R);
137    p_Setm(lp, R);
138
139    assume( p_GetExp(lp, w, R) == 2 );
140    assume( p_GetExp(lp, x, R) == 0 );
141    assume( p_GetExp(lp, y, R) == 0 );
142    assume( p_GetExp(lp, z, R) == 0 );
143
144    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // w2 - xz
145  }
146
147  {
148    // -yz
149    poly p = p_ISet(-1,R);
150
151    p_SetExp(p, y, 1, R);
152    p_SetExp(p, z, 1, R);
153    p_Setm(p, R);
154
155    assume( p_GetExp(p, y, R) == 1 );
156    assume( p_GetExp(p, z, R) == 1 );
157    assume( p_GetExp(p, w, R) == 0 );
158    assume( p_GetExp(p, x, R) == 0 );
159
160    // +wx
161    poly lp = p_ISet(1,R);
162    p_SetExp(lp, w, 1, R);
163    p_SetExp(lp, x, 1, R);
164    p_Setm(lp, R);
165
166    assume( p_GetExp(lp, w, R) == 1 );
167    assume( p_GetExp(lp, x, R) == 1 );
168    assume( p_GetExp(lp, y, R) == 0 );
169    assume( p_GetExp(lp, z, R) == 0 );
170
171    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // wx - yz
172  }
173
174
175  {
176    // -wy
177    poly p = p_ISet(-1,R);
178
179    p_SetExp(p, y, 1, R);
180    p_SetExp(p, w, 1, R);
181    p_Setm(p, R);
182
183    assume( p_GetExp(p, y, R) == 1 );
184    assume( p_GetExp(p, w, R) == 1 );
185    assume( p_GetExp(p, z, R) == 0 );
186    assume( p_GetExp(p, x, R) == 0 );
187
188    // +x2
189    poly lp = p_ISet(1,R);
190    p_SetExp(lp, x, 2, R);
191    p_Setm(lp, R);
192
193    assume( p_GetExp(lp, w, R) == 0 );
194    assume( p_GetExp(lp, x, R) == 2 );
195    assume( p_GetExp(lp, y, R) == 0 );
196    assume( p_GetExp(lp, z, R) == 0 );
197
198    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // x2 - wy
199  }
200
201
202  {
203    // -z2
204    poly p = p_ISet(-1,R);
205
206    p_SetExp(p, z, 2, R);
207    p_Setm(p, R);
208
209    assume( p_GetExp(p, y, R) == 0 );
210    assume( p_GetExp(p, w, R) == 0 );
211    assume( p_GetExp(p, z, R) == 2 );
212    assume( p_GetExp(p, x, R) == 0 );
213
214    // +xy
215    poly lp = p_ISet(1,R);
216    p_SetExp(lp, x, 1, R);
217    p_SetExp(lp, y, 1, R);
218    p_Setm(lp, R);
219
220    assume( p_GetExp(lp, w, R) == 0 );
221    assume( p_GetExp(lp, x, R) == 1 );
222    assume( p_GetExp(lp, y, R) == 1 );
223    assume( p_GetExp(lp, z, R) == 0 );
224
225    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // xy - z2
226  }
227
228
229  {
230    // -wz
231    poly p = p_ISet(-1,R);
232
233    p_SetExp(p, w, 1, R);
234    p_SetExp(p, z, 1, R);
235    p_Setm(p, R);
236
237    assume( p_GetExp(p, y, R) == 0 );
238    assume( p_GetExp(p, w, R) == 1 );
239    assume( p_GetExp(p, z, R) == 1 );
240    assume( p_GetExp(p, x, R) == 0 );
241
242    // +y2
243    poly lp = p_ISet(1,R);
244    p_SetExp(lp, y, 2, R);
245    p_Setm(lp, R);
246
247    assume( p_GetExp(lp, w, R) == 0 );
248    assume( p_GetExp(lp, x, R) == 0 );
249    assume( p_GetExp(lp, y, R) == 2 );
250    assume( p_GetExp(lp, z, R) == 0 );
251
252    MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // y2 - wz
253  }
254#ifdef PDEBUG
255  PrintS("I: ");
256  idShow(I, R, R, 0);
257#endif
258
259
260//  ideal kStd(ideal F, ideal Q, tHomog h, intvec ** mw,intvec *hilb=NULL,
261//             int syzComp=0,int newIdeal=0, intvec *vw=NULL);
262  // make R the default ring:
263  rChangeCurrRing(R);
264
265 ////
266
267  id_Delete( &I, R);
268  rDelete(R); // should cleanup every belonging polynomial, right!?
269
270}
271
272
273
274void TestSimpleRingArithmetcs()
275{
276  // Libpolys tests:
277
278  // construct the ring Z/32003[x,y,z]
279  // the variable names
280  char **n=(char**)omalloc(3*sizeof(char*));
281  n[0]=omStrDup("x");
282  n[1]=omStrDup("y");
283  n[2]=omStrDup("z2");
284
285  ring R = rDefault(32003,3,n); //  ring R = rDefault(0,3,n);
286
287  rWrite(R); PrintLn();
288
289#ifdef RDEBUG
290  rDebugPrint(R);
291#endif
292
293
294  poly p = p_ISet(1,R); p_SetExp(p,1,1, R); p_Setm(p, R);
295
296  assume( p_GetExp(p,1, R) == 1 );
297
298  poly pp = pp_Mult_qq( p, p, R);
299
300  PrintS("p: "); p_Write0(p, R); Print(", deg(p): %ld", p_Totaldegree(p, R)); assume( 1 == p_Totaldegree(p, R) );
301
302  PrintS("; p*p : "); p_Write0(pp, R); Print("deg(pp): %ld\n", p_Totaldegree(pp, R)); assume( 2 == p_Totaldegree(pp, R) );
303
304
305  p_Delete(&p, R);
306
307  assume( p_GetExp(pp,1, R) == 2 );
308
309  p_Delete(&pp, R);
310
311
312//  rDelete(R);
313
314  // make R the default ring:
315  rChangeCurrRing(R);
316
317  // create the polynomial 1
318  poly p1=pISet(1);
319
320  // create tthe polynomial 2*x^3*z^2
321  poly p2=p_ISet(2,R);
322  pSetExp(p2,1,3);
323  pSetExp(p2,3,2);
324  pSetm(p2);
325
326  // print p1 + p2
327  PrintS("p1: "); pWrite0(p1);
328  PrintS(" + p2: "); pWrite0(p2);
329  PrintS("  ---- >>>> ");
330
331  // compute p1+p2
332  p1=p_Add_q(p1,p2,R); p2=NULL;
333  pWrite(p1);
334
335  // clean up:
336//  pDelete(&p1);
337
338  rDelete(R); // should cleanup every belonging polynomial, right!?
339}
340
341
342int main( int, char *argv[] )
343{
344  assume( sizeof(long) == SIZEOF_LONG );
345
346  if( sizeof(long) != SIZEOF_LONG )
347  {
348    WerrorS("Bad config.h: wrong size of long!");
349
350    return(1);
351  }
352
353
354  feInitResources(argv[0]);
355
356  StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
357  feStringAppendResources(0);
358
359  PrintLn();
360  { char* s = StringEndS(); PrintS(s); omFree(s); }
361
362  TestGBEngine();
363  TestSimpleRingArithmetcs();
364
365  return 0;
366}
Note: See TracBrowser for help on using the repository browser.