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