1 | #include <kernel/mod2.h> |
---|
2 | |
---|
3 | #include <omalloc/omalloc.h> |
---|
4 | #include <misc/auxiliary.h> |
---|
5 | #include <factory/factory.h> // :( |
---|
6 | |
---|
7 | #include <misc/intvec.h> |
---|
8 | #include <misc/int64vec.h> |
---|
9 | #include <misc/mylimits.h> |
---|
10 | #include <misc/options.h> |
---|
11 | |
---|
12 | #include <reporter/reporter.h> |
---|
13 | |
---|
14 | #include <resources/feFopen.h> |
---|
15 | #include <resources/feResource.h> |
---|
16 | |
---|
17 | #include <coeffs/coeffs.h> |
---|
18 | |
---|
19 | #include <coeffs/si_gmp.h> |
---|
20 | |
---|
21 | #include <polys/kbuckets.h> |
---|
22 | #include <polys/matpol.h> |
---|
23 | #include <polys/mod_raw.h> |
---|
24 | #include <polys/prCopy.h> |
---|
25 | #include <polys/sbuckets.h> |
---|
26 | #include <polys/simpleideals.h> |
---|
27 | #include <polys/weight.h> |
---|
28 | |
---|
29 | #include <polys/monomials/maps.h> |
---|
30 | #include <polys/monomials/monomials.h> |
---|
31 | #include <polys/monomials/p_polys.h> |
---|
32 | #include <polys/monomials/ring.h> |
---|
33 | |
---|
34 | #include <polys/nc/nc.h> |
---|
35 | #include <polys/nc/ncSACache.h> |
---|
36 | #include <polys/nc/ncSAFormula.h> |
---|
37 | #include <polys/nc/ncSAMult.h> |
---|
38 | #include <polys/nc/sca.h> |
---|
39 | #include <polys/nc/summator.h> |
---|
40 | |
---|
41 | |
---|
42 | #include <polys/templates/p_MemAdd.h> |
---|
43 | #include <polys/templates/p_Procs.h> |
---|
44 | |
---|
45 | #include <polys/operations/pShallowCopyDelete.h> |
---|
46 | |
---|
47 | #include <polys/clapsing.h> |
---|
48 | |
---|
49 | |
---|
50 | // // TODO: DUE to the use of HALT in npolygon.cc :((( |
---|
51 | extern "C" {void m2_end(int i){exit(i);}} |
---|
52 | |
---|
53 | // // TODO: DUE to its use in kutil.cc :((( |
---|
54 | char * showOption(){return NULL;} |
---|
55 | |
---|
56 | // // TODO: DUE to its use in feread.cc :((( |
---|
57 | char *iiArithGetCmd(int nPos){return NULL; } |
---|
58 | |
---|
59 | |
---|
60 | #include <coeffs/numbers.h> |
---|
61 | |
---|
62 | #include "structs.h" |
---|
63 | |
---|
64 | |
---|
65 | // HEADERS: |
---|
66 | #include <kernel/combinatorics/hutil.h> |
---|
67 | #include <kernel/combinatorics/stairc.h> |
---|
68 | #include <kernel/ideals.h> |
---|
69 | #include <kernel/GBEngine/syz.h> |
---|
70 | #include <kernel/maps/fast_maps.h> |
---|
71 | #include <kernel/groebner_walk/walkProc.h> |
---|
72 | #include <kernel/groebner_walk/walkMain.h> |
---|
73 | #include <kernel/groebner_walk/walkSupport.h> |
---|
74 | #include <kernel/GBEngine/khstd.h> |
---|
75 | /// #include <kernel/sparsmat.h> // TODO: install polys/this! |
---|
76 | //+ |
---|
77 | |
---|
78 | #include <kernel/fglm/fglm.h> |
---|
79 | #include <kernel/GBEngine/kstd1.h> |
---|
80 | #include <kernel/fglm/fglmgauss.h> |
---|
81 | #include <kernel/fglm/fglmvec.h> |
---|
82 | #include <kernel/GBEngine/kstdfac.h> |
---|
83 | #include <kernel/spectrum/kmatrix.h> |
---|
84 | #include <kernel/spectrum/GMPrat.h> |
---|
85 | #include <kernel/spectrum/multicnt.h> |
---|
86 | #include <kernel/spectrum/npolygon.h> |
---|
87 | #include <kernel/spectrum/semic.h> |
---|
88 | #include <kernel/spectrum/spectrum.h> |
---|
89 | #include <kernel/spectrum/splist.h> |
---|
90 | #include <kernel/spectrum/multicnt.h> |
---|
91 | #include <kernel/linear_algebra/eigenval.h> |
---|
92 | #include <kernel/GBEngine/units.h> |
---|
93 | #include <kernel/GBEngine/ratgring.h> |
---|
94 | #include <kernel/GBEngine/shiftgb.h> |
---|
95 | |
---|
96 | |
---|
97 | #include <kernel/GBEngine/kutil.h> |
---|
98 | |
---|
99 | // #include "CCRing.h" // Too old! |
---|
100 | #include <kernel/digitech.h> |
---|
101 | #include <kernel/linear_algebra/eigenval.h> |
---|
102 | #include <kernel/maps/fast_maps.h> |
---|
103 | #include <kernel/fast_mult.h> |
---|
104 | |
---|
105 | #include <kernel/fglm/fglmgauss.h> |
---|
106 | #include <kernel/fglm/fglm.h> |
---|
107 | #include <kernel/fglm/fglmvec.h> |
---|
108 | |
---|
109 | ////////#include <kernel/F5cData.h> |
---|
110 | #include <kernel/GBEngine/f5c.h> |
---|
111 | #include <kernel/GBEngine/f5data.h> |
---|
112 | #include <kernel/GBEngine/f5gb.h> |
---|
113 | #include <kernel/GBEngine/f5lists.h> |
---|
114 | ////////#include <kernel/F5cLists.h> |
---|
115 | |
---|
116 | |
---|
117 | // #include "Ideal.h" // Too old? |
---|
118 | |
---|
119 | |
---|
120 | #include <kernel/ideals.h> |
---|
121 | |
---|
122 | #include <kernel/spectrum/kmatrix.h> |
---|
123 | #include <kernel/GBEngine/kstd1.h> |
---|
124 | #include <kernel/GBEngine/kstdfac.h> |
---|
125 | #include <kernel/GBEngine/khstd.h> |
---|
126 | |
---|
127 | #include <kernel/linear_algebra/linearAlgebra.h> |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | // #include <kernel/lplist.h> // Too old! |
---|
132 | #include <kernel/spectrum/multicnt.h> |
---|
133 | #include <kernel/spectrum/npolygon.h> |
---|
134 | // #include "Number.h" // Too old? |
---|
135 | // #include "Poly.h" // Too old? |
---|
136 | // #include "PowerSeries.h" // Too old? |
---|
137 | |
---|
138 | #include <kernel/preimage.h> |
---|
139 | |
---|
140 | #include <kernel/GBEngine/nc.h> |
---|
141 | |
---|
142 | #include <kernel/GBEngine/ratgring.h> |
---|
143 | #include <kernel/GBEngine/ringgb.h> |
---|
144 | #include <kernel/spectrum/semic.h> |
---|
145 | #include <kernel/GBEngine/shiftgb.h> |
---|
146 | #include <kernel/spectrum/spectrum.h> |
---|
147 | #include <kernel/spectrum/splist.h> |
---|
148 | #include <kernel/structs.h> |
---|
149 | #include <kernel/GBEngine/syz.h> |
---|
150 | // #include <kernel/testpoly.h> // Too old? |
---|
151 | |
---|
152 | #include <kernel/GBEngine/tgbgauss.h> |
---|
153 | #include <kernel/GBEngine/tgb.h> |
---|
154 | |
---|
155 | |
---|
156 | #include <kernel/GBEngine/units.h> |
---|
157 | #include <kernel/groebner_walk/walkMain.h> |
---|
158 | #include <kernel/groebner_walk/walkProc.h> |
---|
159 | #include <kernel/groebner_walk/walkSupport.h> |
---|
160 | |
---|
161 | #include <kernel/GBEngine/janet.h> |
---|
162 | #include <kernel/linear_algebra/interpolation.h> |
---|
163 | #include <kernel/linear_algebra/minpoly.h> |
---|
164 | |
---|
165 | #include <kernel/linear_algebra/Minor.h> |
---|
166 | #include <kernel/linear_algebra/MinorInterface.h> |
---|
167 | #include <kernel/linear_algebra/MinorProcessor.h> |
---|
168 | #include <kernel/linear_algebra/Cache.h> |
---|
169 | #include <kernel/linear_algebra/CacheImplementation.h> |
---|
170 | |
---|
171 | // #include <polys/clapconv.h> // due to factory? :( |
---|
172 | // #include <kernel/tgb_internal.h> // :( |
---|
173 | // #include <kernel/F4.h> // uses tgb_internal // :( |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | // #include <kernel/fglm/fglmzero.cc> // looks like <factory/templates/ftmpl_list.h> must be installed! |
---|
179 | // TODO: looks like <coeffs/mpr_complex.h> must be installed! |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | #include <kernel/polys.h> |
---|
184 | |
---|
185 | void TestGBEngine() |
---|
186 | { |
---|
187 | |
---|
188 | // R = MPolynomialRing_polydict(QQ,5,'w,x,y,z,C', order='degrevlex') |
---|
189 | // J = (w*w - x*z, w*x - y*z, x*x - w*y, x*y - z*z, y*y - w*z) |
---|
190 | |
---|
191 | const short w = 1; |
---|
192 | const short x = 2; |
---|
193 | const short y = 3; |
---|
194 | const short z = 4; |
---|
195 | |
---|
196 | const short N = (z - w + 1); |
---|
197 | |
---|
198 | char **n=(char**)omalloc(N*sizeof(char*)); |
---|
199 | |
---|
200 | |
---|
201 | n[w-1]=omStrDup("w"); |
---|
202 | n[x-1]=omStrDup("x"); |
---|
203 | n[y-1]=omStrDup("y"); |
---|
204 | n[z-1]=omStrDup("z"); |
---|
205 | |
---|
206 | |
---|
207 | const int D = 3; |
---|
208 | int *order = (int *) omAlloc0(D* sizeof(int)); |
---|
209 | int *block0 = (int *)omAlloc0(D * sizeof(int)); |
---|
210 | int *block1 = (int *)omAlloc0(D * sizeof(int)); |
---|
211 | |
---|
212 | order[0] = ringorder_dp; |
---|
213 | block0[0] = 1; |
---|
214 | block1[0] = N; |
---|
215 | |
---|
216 | order[1] = ringorder_C; |
---|
217 | block0[1] = 1; |
---|
218 | block1[1] = N; |
---|
219 | |
---|
220 | ring R = rDefault(0, N, n, D, order, block0, block1); |
---|
221 | |
---|
222 | // ring R = rDefault(0, N, n); |
---|
223 | |
---|
224 | rWrite(R); PrintLn(); |
---|
225 | |
---|
226 | #ifdef RDEBUG |
---|
227 | rDebugPrint(R); |
---|
228 | #endif |
---|
229 | |
---|
230 | ideal I = idInit(5, 1); |
---|
231 | |
---|
232 | int gen = 0; |
---|
233 | |
---|
234 | { |
---|
235 | // -xz |
---|
236 | poly p = p_ISet(-1,R); |
---|
237 | |
---|
238 | p_SetExp(p, x, 1, R); |
---|
239 | p_SetExp(p, z, 1, R); |
---|
240 | p_Setm(p, R); |
---|
241 | |
---|
242 | assume( p_GetExp(p, x, R) == 1 ); |
---|
243 | assume( p_GetExp(p, z, R) == 1 ); |
---|
244 | assume( p_GetExp(p, w, R) == 0 ); |
---|
245 | assume( p_GetExp(p, y, R) == 0 ); |
---|
246 | |
---|
247 | // +w2 |
---|
248 | poly lp = p_ISet(1,R); |
---|
249 | p_SetExp(lp, w, 2, R); |
---|
250 | p_Setm(lp, R); |
---|
251 | |
---|
252 | assume( p_GetExp(lp, w, R) == 2 ); |
---|
253 | assume( p_GetExp(lp, x, R) == 0 ); |
---|
254 | assume( p_GetExp(lp, y, R) == 0 ); |
---|
255 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
256 | |
---|
257 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // w2 - xz |
---|
258 | } |
---|
259 | |
---|
260 | { |
---|
261 | // -yz |
---|
262 | poly p = p_ISet(-1,R); |
---|
263 | |
---|
264 | p_SetExp(p, y, 1, R); |
---|
265 | p_SetExp(p, z, 1, R); |
---|
266 | p_Setm(p, R); |
---|
267 | |
---|
268 | assume( p_GetExp(p, y, R) == 1 ); |
---|
269 | assume( p_GetExp(p, z, R) == 1 ); |
---|
270 | assume( p_GetExp(p, w, R) == 0 ); |
---|
271 | assume( p_GetExp(p, x, R) == 0 ); |
---|
272 | |
---|
273 | // +wx |
---|
274 | poly lp = p_ISet(1,R); |
---|
275 | p_SetExp(lp, w, 1, R); |
---|
276 | p_SetExp(lp, x, 1, R); |
---|
277 | p_Setm(lp, R); |
---|
278 | |
---|
279 | assume( p_GetExp(lp, w, R) == 1 ); |
---|
280 | assume( p_GetExp(lp, x, R) == 1 ); |
---|
281 | assume( p_GetExp(lp, y, R) == 0 ); |
---|
282 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
283 | |
---|
284 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // wx - yz |
---|
285 | } |
---|
286 | |
---|
287 | |
---|
288 | { |
---|
289 | // -wy |
---|
290 | poly p = p_ISet(-1,R); |
---|
291 | |
---|
292 | p_SetExp(p, y, 1, R); |
---|
293 | p_SetExp(p, w, 1, R); |
---|
294 | p_Setm(p, R); |
---|
295 | |
---|
296 | assume( p_GetExp(p, y, R) == 1 ); |
---|
297 | assume( p_GetExp(p, w, R) == 1 ); |
---|
298 | assume( p_GetExp(p, z, R) == 0 ); |
---|
299 | assume( p_GetExp(p, x, R) == 0 ); |
---|
300 | |
---|
301 | // +x2 |
---|
302 | poly lp = p_ISet(1,R); |
---|
303 | p_SetExp(lp, x, 2, R); |
---|
304 | p_Setm(lp, R); |
---|
305 | |
---|
306 | assume( p_GetExp(lp, w, R) == 0 ); |
---|
307 | assume( p_GetExp(lp, x, R) == 2 ); |
---|
308 | assume( p_GetExp(lp, y, R) == 0 ); |
---|
309 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
310 | |
---|
311 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // x2 - wy |
---|
312 | } |
---|
313 | |
---|
314 | |
---|
315 | { |
---|
316 | // -z2 |
---|
317 | poly p = p_ISet(-1,R); |
---|
318 | |
---|
319 | p_SetExp(p, z, 2, R); |
---|
320 | p_Setm(p, R); |
---|
321 | |
---|
322 | assume( p_GetExp(p, y, R) == 0 ); |
---|
323 | assume( p_GetExp(p, w, R) == 0 ); |
---|
324 | assume( p_GetExp(p, z, R) == 2 ); |
---|
325 | assume( p_GetExp(p, x, R) == 0 ); |
---|
326 | |
---|
327 | // +xy |
---|
328 | poly lp = p_ISet(1,R); |
---|
329 | p_SetExp(lp, x, 1, R); |
---|
330 | p_SetExp(lp, y, 1, R); |
---|
331 | p_Setm(lp, R); |
---|
332 | |
---|
333 | assume( p_GetExp(lp, w, R) == 0 ); |
---|
334 | assume( p_GetExp(lp, x, R) == 1 ); |
---|
335 | assume( p_GetExp(lp, y, R) == 1 ); |
---|
336 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
337 | |
---|
338 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // xy - z2 |
---|
339 | } |
---|
340 | |
---|
341 | |
---|
342 | { |
---|
343 | // -wz |
---|
344 | poly p = p_ISet(-1,R); |
---|
345 | |
---|
346 | p_SetExp(p, w, 1, R); |
---|
347 | p_SetExp(p, z, 1, R); |
---|
348 | p_Setm(p, R); |
---|
349 | |
---|
350 | assume( p_GetExp(p, y, R) == 0 ); |
---|
351 | assume( p_GetExp(p, w, R) == 1 ); |
---|
352 | assume( p_GetExp(p, z, R) == 1 ); |
---|
353 | assume( p_GetExp(p, x, R) == 0 ); |
---|
354 | |
---|
355 | // +y2 |
---|
356 | poly lp = p_ISet(1,R); |
---|
357 | p_SetExp(lp, y, 2, R); |
---|
358 | p_Setm(lp, R); |
---|
359 | |
---|
360 | assume( p_GetExp(lp, w, R) == 0 ); |
---|
361 | assume( p_GetExp(lp, x, R) == 0 ); |
---|
362 | assume( p_GetExp(lp, y, R) == 2 ); |
---|
363 | assume( p_GetExp(lp, z, R) == 0 ); |
---|
364 | |
---|
365 | MATELEM(I, 1, ++gen) = p_Add_q(lp, p, R); // y2 - wz |
---|
366 | } |
---|
367 | #ifdef PDEBUG |
---|
368 | PrintS("I: "); |
---|
369 | idShow(I, R, R, 0); |
---|
370 | #endif |
---|
371 | |
---|
372 | |
---|
373 | // ideal kStd(ideal F, ideal Q, tHomog h, intvec ** mw,intvec *hilb=NULL, |
---|
374 | // int syzComp=0,int newIdeal=0, intvec *vw=NULL); |
---|
375 | // make R the default ring: |
---|
376 | rChangeCurrRing(R); |
---|
377 | |
---|
378 | { |
---|
379 | ideal G = kStd(I, currRing->qideal, testHomog, NULL); |
---|
380 | |
---|
381 | #ifdef PDEBUG |
---|
382 | PrintS("GB: "); |
---|
383 | idShow(G, R, R, 0); |
---|
384 | #endif |
---|
385 | |
---|
386 | id_Delete( &G, R); |
---|
387 | } |
---|
388 | |
---|
389 | { |
---|
390 | intvec *weights = NULL; |
---|
391 | ideal SYZ = idSyzygies(I, testHomog, &weights); |
---|
392 | |
---|
393 | #ifdef PDEBUG |
---|
394 | PrintS("SYZ: "); |
---|
395 | idShow(SYZ, R, R, 0); |
---|
396 | #endif |
---|
397 | |
---|
398 | id_Delete(&SYZ, R); |
---|
399 | if (weights!=NULL) { PrintS("weights: "); weights->show(); delete weights; } |
---|
400 | } |
---|
401 | |
---|
402 | |
---|
403 | { |
---|
404 | PrintS("\n**********************************\n"); |
---|
405 | PrintS("lres: \n"); |
---|
406 | int dummy; |
---|
407 | syStrategy r = syLaScala3(I,&dummy); |
---|
408 | |
---|
409 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
410 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
411 | delete b; |
---|
412 | |
---|
413 | Print("length: %d\n", sySize(r)); |
---|
414 | |
---|
415 | syPrint(r, "R"); |
---|
416 | |
---|
417 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
418 | |
---|
419 | b = syBettiOfComputation(r, TRUE); |
---|
420 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
421 | delete b; |
---|
422 | |
---|
423 | Print("length: %d\n", sySize(r)); |
---|
424 | |
---|
425 | syPrint(r, "R"); |
---|
426 | |
---|
427 | syKillComputation(r, R); |
---|
428 | } |
---|
429 | |
---|
430 | { |
---|
431 | PrintS("\n**********************************\n"); |
---|
432 | PrintS("sres: \n"); |
---|
433 | const int maxl = rVar(R)-1; // +2*(1); |
---|
434 | |
---|
435 | syStrategy r = sySchreyer(I, rVar(R)); |
---|
436 | |
---|
437 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
438 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
439 | delete b; |
---|
440 | |
---|
441 | Print("length: %d\n", sySize(r)); |
---|
442 | |
---|
443 | syPrint(r, "R"); |
---|
444 | |
---|
445 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
446 | |
---|
447 | b = syBettiOfComputation(r, TRUE); |
---|
448 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
449 | delete b; |
---|
450 | |
---|
451 | Print("length: %d\n", sySize(r)); |
---|
452 | |
---|
453 | syPrint(r, "R"); |
---|
454 | |
---|
455 | syKillComputation(r, R); |
---|
456 | } |
---|
457 | |
---|
458 | |
---|
459 | |
---|
460 | { |
---|
461 | PrintS("\n**********************************\n"); |
---|
462 | PrintS("nres: \n"); |
---|
463 | intvec *weights=NULL; |
---|
464 | // const int maxl = rVar(R)-1 + 2*(1); |
---|
465 | syStrategy r = syResolution(I, rVar(R)-1, weights, FALSE/*iiOp==MRES_CMD*/); |
---|
466 | |
---|
467 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
468 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
469 | delete b; |
---|
470 | |
---|
471 | Print("length: %d\n", sySize(r)); |
---|
472 | |
---|
473 | syPrint(r, "R"); |
---|
474 | |
---|
475 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
476 | |
---|
477 | b = syBettiOfComputation(r, TRUE); |
---|
478 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
479 | delete b; |
---|
480 | |
---|
481 | Print("length: %d\n", sySize(r)); |
---|
482 | |
---|
483 | syPrint(r, "R"); |
---|
484 | |
---|
485 | syKillComputation(r, R); |
---|
486 | } |
---|
487 | |
---|
488 | |
---|
489 | { |
---|
490 | PrintS("\n**********************************\n"); |
---|
491 | PrintS("mres: \n"); |
---|
492 | intvec *weights=NULL; |
---|
493 | // const int maxl = rVar(R)-1 + 2*(1); |
---|
494 | syStrategy r = syResolution(I, rVar(R)+1, weights, TRUE/*iiOp==MRES_CMD*/); |
---|
495 | |
---|
496 | intvec *b = syBettiOfComputation(r, FALSE); |
---|
497 | PrintS("non-min. betti: \n"); b->show(); PrintLn(); |
---|
498 | delete b; |
---|
499 | |
---|
500 | Print("length: %d\n", sySize(r)); |
---|
501 | |
---|
502 | syPrint(r, "R"); |
---|
503 | |
---|
504 | r = syMinimize(r); // syzstr->references ++ ==> memory leak :((( |
---|
505 | |
---|
506 | b = syBettiOfComputation(r, TRUE); |
---|
507 | PrintS("min. betti: \n"); b->show(); PrintLn(); |
---|
508 | delete b; |
---|
509 | |
---|
510 | Print("length: %d\n", sySize(r)); |
---|
511 | |
---|
512 | syPrint(r, "R"); |
---|
513 | |
---|
514 | syKillComputation(r, R); |
---|
515 | } |
---|
516 | |
---|
517 | |
---|
518 | |
---|
519 | |
---|
520 | id_Delete( &I, R); |
---|
521 | rDelete(R); // should cleanup every belonging polynomial, right!? |
---|
522 | |
---|
523 | } |
---|
524 | |
---|
525 | |
---|
526 | |
---|
527 | void TestSimpleRingArithmetcs() |
---|
528 | { |
---|
529 | // Libpolys tests: |
---|
530 | |
---|
531 | // construct the ring Z/32003[x,y,z] |
---|
532 | // the variable names |
---|
533 | char **n=(char**)omalloc(3*sizeof(char*)); |
---|
534 | n[0]=omStrDup("x"); |
---|
535 | n[1]=omStrDup("y"); |
---|
536 | n[2]=omStrDup("z2"); |
---|
537 | |
---|
538 | ring R = rDefault(32003,3,n); // ring R = rDefault(0,3,n); |
---|
539 | |
---|
540 | rWrite(R); PrintLn(); |
---|
541 | |
---|
542 | #ifdef RDEBUG |
---|
543 | rDebugPrint(R); |
---|
544 | #endif |
---|
545 | |
---|
546 | |
---|
547 | poly p = p_ISet(1,R); p_SetExp(p,1,1, R); p_Setm(p, R); |
---|
548 | |
---|
549 | assume( p_GetExp(p,1, R) == 1 ); |
---|
550 | |
---|
551 | poly pp = pp_Mult_qq( p, p, R); |
---|
552 | |
---|
553 | Print("p: "); p_Write0(p, R); Print(", deg(p): %ld", p_Totaldegree(p, R)); assume( 1 == p_Totaldegree(p, R) ); |
---|
554 | |
---|
555 | Print("; p*p : "); p_Write0(pp, R); Print("deg(pp): %ld\n", p_Totaldegree(pp, R)); assume( 2 == p_Totaldegree(pp, R) ); |
---|
556 | |
---|
557 | |
---|
558 | p_Delete(&p, R); |
---|
559 | |
---|
560 | assume( p_GetExp(pp,1, R) == 2 ); |
---|
561 | |
---|
562 | p_Delete(&pp, R); |
---|
563 | |
---|
564 | |
---|
565 | // rDelete(R); |
---|
566 | |
---|
567 | // make R the default ring: |
---|
568 | rChangeCurrRing(R); |
---|
569 | |
---|
570 | // create the polynomial 1 |
---|
571 | poly p1=pISet(1); |
---|
572 | |
---|
573 | // create tthe polynomial 2*x^3*z^2 |
---|
574 | poly p2=p_ISet(2,R); |
---|
575 | pSetExp(p2,1,3); |
---|
576 | pSetExp(p2,3,2); |
---|
577 | pSetm(p2); |
---|
578 | |
---|
579 | // print p1 + p2 |
---|
580 | Print("p1: "); pWrite0(p1); |
---|
581 | Print(" + p2: "); pWrite0(p2); |
---|
582 | Print(" ---- >>>> "); |
---|
583 | |
---|
584 | // compute p1+p2 |
---|
585 | p1=p_Add_q(p1,p2,R); p2=NULL; |
---|
586 | pWrite(p1); |
---|
587 | |
---|
588 | // clean up: |
---|
589 | // pDelete(&p1); |
---|
590 | |
---|
591 | rDelete(R); // should cleanup every belonging polynomial, right!? |
---|
592 | } |
---|
593 | |
---|
594 | |
---|
595 | int main( int, char *argv[] ) |
---|
596 | { |
---|
597 | assume( sizeof(long) == SIZEOF_LONG ); |
---|
598 | |
---|
599 | if( sizeof(long) != SIZEOF_LONG ) |
---|
600 | { |
---|
601 | WerrorS("Bad config.h: wrong size of long!"); |
---|
602 | |
---|
603 | return(1); |
---|
604 | } |
---|
605 | |
---|
606 | |
---|
607 | feInitResources(argv[0]); |
---|
608 | |
---|
609 | StringSetS("ressources in use (as reported by feStringAppendResources(0):\n"); |
---|
610 | feStringAppendResources(0); |
---|
611 | |
---|
612 | PrintLn(); |
---|
613 | { char* s = StringEndS(); PrintS(s); omFree(s); } |
---|
614 | |
---|
615 | TestGBEngine(); |
---|
616 | TestSimpleRingArithmetcs(); |
---|
617 | |
---|
618 | return 0; |
---|
619 | } |
---|