source: git/kernel/combinatorics/test.cc @ 1c4822a

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