source: git/kernel/spectrum/test.cc @ 438818

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