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