source: git/kernel/numeric/test.cc @ fea494

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