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

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