source: git/kernel/combinatorics/test.cc @ a4771e1

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