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