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