source: git/kernel/maps/test.cc @ 52e6ef

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