1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | version="version modstd.lib 4.1.1.0 Dec_2017 "; // $Id$ |
---|
3 | category="Commutative Algebra"; |
---|
4 | info=" |
---|
5 | LIBRARY: modstd.lib Groebner bases of ideals using modular methods |
---|
6 | |
---|
7 | AUTHORS: A. Hashemi Amir.Hashemi@lip6.fr |
---|
8 | G. Pfister pfister@mathematik.uni-kl.de |
---|
9 | H. Schoenemann hannes@mathematik.uni-kl.de |
---|
10 | A. Steenpass steenpass@mathematik.uni-kl.de |
---|
11 | S. Steidel steidel@mathematik.uni-kl.de |
---|
12 | |
---|
13 | OVERVIEW: |
---|
14 | A library for computing Groebner bases of ideals in the polynomial ring over |
---|
15 | the rational numbers using modular methods. |
---|
16 | |
---|
17 | REFERENCES: |
---|
18 | E. A. Arnold: Modular algorithms for computing Groebner bases. |
---|
19 | J. Symb. Comp. 35, 403-419 (2003). |
---|
20 | |
---|
21 | N. Idrees, G. Pfister, S. Steidel: Parallelization of Modular Algorithms. |
---|
22 | J. Symb. Comp. 46, 672-684 (2011). |
---|
23 | |
---|
24 | PROCEDURES: |
---|
25 | modStd(I); standard basis of I using modular methods |
---|
26 | modSyz(I); syzygy module of I using modular methods |
---|
27 | modIntersect(I,J); intersection of I and J using modular methods |
---|
28 | "; |
---|
29 | |
---|
30 | LIB "poly.lib"; |
---|
31 | LIB "modular.lib"; |
---|
32 | |
---|
33 | proc modStd(def I, list #) |
---|
34 | "USAGE: modStd(I[, exactness]); I ideal/module, exactness int |
---|
35 | RETURN: a standard basis of I |
---|
36 | NOTE: The procedure computes a standard basis of I (over the rational |
---|
37 | numbers) by using modular methods. |
---|
38 | @* An optional parameter 'exactness' can be provided. |
---|
39 | If exactness = 1(default), the procedure computes a standard basis |
---|
40 | of I for sure; if exactness = 0, it computes a standard basis of I |
---|
41 | with high probability. |
---|
42 | SEE ALSO: modular |
---|
43 | EXAMPLE: example modStd; shows an example" |
---|
44 | { |
---|
45 | /* read optional parameter */ |
---|
46 | int exactness = 1; |
---|
47 | if (size(#) > 0) |
---|
48 | { |
---|
49 | /* For compatibility, we only test size(#) > 4. This can be changed to |
---|
50 | * size(#) > 1 in the future. */ |
---|
51 | if (size(#) > 4 || typeof(#[1]) != "int") |
---|
52 | { |
---|
53 | ERROR("wrong optional parameter"); |
---|
54 | } |
---|
55 | exactness = #[1]; |
---|
56 | } |
---|
57 | |
---|
58 | /* save options */ |
---|
59 | intvec opt = option(get); |
---|
60 | option(redSB); |
---|
61 | |
---|
62 | /* choose the right command */ |
---|
63 | string command = "groebner"; |
---|
64 | if (npars(basering) > 0) { command = "Modstd::groebner_norm"; } |
---|
65 | |
---|
66 | /* call modular() */ |
---|
67 | if (exactness) |
---|
68 | { |
---|
69 | I = modular(command, list(I), primeTest_std, |
---|
70 | deleteUnluckyPrimes_std, pTest_std, finalTest_std); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | I = modular(command, list(I), primeTest_std, |
---|
75 | deleteUnluckyPrimes_std, pTest_std); |
---|
76 | } |
---|
77 | |
---|
78 | /* return the result */ |
---|
79 | attrib(I, "isSB", 1); |
---|
80 | option(set, opt); |
---|
81 | return(I); |
---|
82 | } |
---|
83 | example |
---|
84 | { |
---|
85 | "EXAMPLE:"; |
---|
86 | echo = 2; |
---|
87 | ring R1 = 0, (x,y,z,t), dp; |
---|
88 | ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4; |
---|
89 | ideal J = modStd(I); |
---|
90 | J; |
---|
91 | I = homog(I, t); |
---|
92 | J = modStd(I); |
---|
93 | J; |
---|
94 | |
---|
95 | ring R2 = 0, (x,y,z), ds; |
---|
96 | ideal I = jacob(x5+y6+z7+xyz); |
---|
97 | ideal J = modStd(I, 0); |
---|
98 | J; |
---|
99 | |
---|
100 | ring R3 = 0, x(1..4), lp; |
---|
101 | ideal I = cyclic(4); |
---|
102 | ideal J1 = modStd(I, 1); // default |
---|
103 | ideal J2 = modStd(I, 0); |
---|
104 | size(reduce(J1, J2)); |
---|
105 | size(reduce(J2, J1)); |
---|
106 | } |
---|
107 | |
---|
108 | proc modSyz(def I) |
---|
109 | "USAGE: modSyz(I); I ideal/module |
---|
110 | RETURN: a generating set of syzygies of I |
---|
111 | NOTE: The procedure computes a the syzygy module of I (over the rational |
---|
112 | numbers) by using modular methods with high probability. |
---|
113 | The property of being a syzygy is tested. |
---|
114 | SEE ALSO: modular |
---|
115 | EXAMPLE: example modSyz; shows an example" |
---|
116 | { |
---|
117 | /* save options */ |
---|
118 | intvec opt = option(get); |
---|
119 | option(redSB); |
---|
120 | |
---|
121 | /* choose the right command */ |
---|
122 | string command = "syz"; |
---|
123 | |
---|
124 | /* call modular() */ |
---|
125 | module M = modular(command, list(I), primeTest_std, |
---|
126 | deleteUnluckyPrimes_std, pTest_syz); |
---|
127 | |
---|
128 | /* return the result */ |
---|
129 | option(set, opt); |
---|
130 | return(M); |
---|
131 | } |
---|
132 | example |
---|
133 | { |
---|
134 | "EXAMPLE:"; echo = 2; |
---|
135 | ring R1 = 0, (x,y,z,t), dp; |
---|
136 | ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4; |
---|
137 | modSyz(I); |
---|
138 | simplify(syz(I),1); |
---|
139 | } |
---|
140 | |
---|
141 | proc modIntersect(def I, def J) |
---|
142 | "USAGE: modIntersect(I,J); I,J ideal/module |
---|
143 | RETURN: a generating set of the intersection of I and J |
---|
144 | NOTE: The procedure computes a the intersection of I and J |
---|
145 | (over the rational numbers) by using modular methods |
---|
146 | with high probability. |
---|
147 | No additional tests are performed. |
---|
148 | SEE ALSO: modular |
---|
149 | EXAMPLE: example modIntersect; shows an example" |
---|
150 | { |
---|
151 | /* save options */ |
---|
152 | intvec opt = option(get); |
---|
153 | option(redSB); |
---|
154 | |
---|
155 | /* choose the right command */ |
---|
156 | string command = "intersect"; |
---|
157 | |
---|
158 | /* call modular() */ |
---|
159 | def M = modular(command, list(I,J), primeTest_std, |
---|
160 | deleteUnluckyPrimes_std); |
---|
161 | |
---|
162 | /* return the result */ |
---|
163 | option(set, opt); |
---|
164 | return(M); |
---|
165 | } |
---|
166 | example |
---|
167 | { |
---|
168 | "EXAMPLE:"; echo = 2; |
---|
169 | ring R1 = 0, (x,y,z,t), dp; |
---|
170 | ideal I = 3x3+x2+1, 11y5+y3+2, 5z4+z2+4; |
---|
171 | ideal J = maxideal(2); |
---|
172 | modIntersect(I,J); |
---|
173 | simplify(intersect(I,J),1); |
---|
174 | } |
---|
175 | |
---|
176 | /* compute a normalized GB via groebner() */ |
---|
177 | static proc groebner_norm(ideal I) |
---|
178 | { |
---|
179 | I = simplify(groebner(I), 1); |
---|
180 | attrib(I, "isSB", 1); |
---|
181 | return(I); |
---|
182 | } |
---|
183 | |
---|
184 | /* test if the prime p is suitable for the input, i.e. it does not divide |
---|
185 | * the numerator or denominator of any of the coefficients */ |
---|
186 | static proc primeTest_std(int p, alias list args) |
---|
187 | { |
---|
188 | /* erase zero generators */ |
---|
189 | def I = simplify(args[1], 2); |
---|
190 | |
---|
191 | /* clear denominators and count the terms */ |
---|
192 | def J=I; // dummy assign, to get the type of I |
---|
193 | ideal K; |
---|
194 | int n = ncols(I); |
---|
195 | intvec sizes; |
---|
196 | number cnt; |
---|
197 | int i; |
---|
198 | for(i = n; i > 0; i--) |
---|
199 | { |
---|
200 | J[i] = cleardenom(I[i]); |
---|
201 | cnt = leadcoef(J[i])/leadcoef(I[i]); |
---|
202 | K[i] = numerator(cnt)*var(1)+denominator(cnt); |
---|
203 | } |
---|
204 | sizes = size(J[1..n]); |
---|
205 | |
---|
206 | /* change to characteristic p */ |
---|
207 | def br = basering; |
---|
208 | list lbr = ringlist(br); |
---|
209 | if (typeof(lbr[1]) == "int") { lbr[1] = p; } |
---|
210 | else { lbr[1][1] = p; } |
---|
211 | def rp = ring(lbr); |
---|
212 | setring(rp); |
---|
213 | def Jp = fetch(br, J); |
---|
214 | ideal Kp = fetch(br, K); |
---|
215 | |
---|
216 | /* test if any coefficient is missing */ |
---|
217 | if (intvec(size(Kp[1..n])) != 2:n) { setring(br); return(0); } |
---|
218 | if (intvec(size(Jp[1..n])) != sizes) { setring(br); return(0); } |
---|
219 | setring(br); |
---|
220 | return(1); |
---|
221 | } |
---|
222 | |
---|
223 | /* find entries in modresults which come from unlucky primes. |
---|
224 | * For this, sort the entries into categories depending on their leading |
---|
225 | * ideal and return the indices in all but the biggest category. */ |
---|
226 | static proc deleteUnluckyPrimes_std(alias list modresults) |
---|
227 | { |
---|
228 | int size_modresults = size(modresults); |
---|
229 | |
---|
230 | /* sort results into categories. |
---|
231 | * each category is represented by three entries: |
---|
232 | * - the corresponding leading ideal |
---|
233 | * - the number of elements |
---|
234 | * - the indices of the elements |
---|
235 | */ |
---|
236 | list cat; |
---|
237 | int size_cat; |
---|
238 | def L=modresults[1]; // dummy assign to get the type of L |
---|
239 | int i; |
---|
240 | int j; |
---|
241 | for (i = 1; i <= size_modresults; i++) |
---|
242 | { |
---|
243 | L = lead(modresults[i]); |
---|
244 | attrib(L, "isSB", 1); |
---|
245 | for (j = 1; j <= size_cat; j++) |
---|
246 | { |
---|
247 | if (size(L) == size(cat[j][1]) |
---|
248 | && size(reduce(L, cat[j][1], 5)) == 0 |
---|
249 | && size(reduce(cat[j][1], L, 5)) == 0) |
---|
250 | { |
---|
251 | cat[j][2] = cat[j][2]+1; |
---|
252 | cat[j][3][cat[j][2]] = i; |
---|
253 | break; |
---|
254 | } |
---|
255 | } |
---|
256 | if (j > size_cat) |
---|
257 | { |
---|
258 | size_cat++; |
---|
259 | cat[size_cat] = list(); |
---|
260 | cat[size_cat][1] = L; |
---|
261 | cat[size_cat][2] = 1; |
---|
262 | cat[size_cat][3] = list(i); |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | /* find the biggest categories */ |
---|
267 | int cat_max = 1; |
---|
268 | int max = cat[1][2]; |
---|
269 | for (i = 2; i <= size_cat; i++) |
---|
270 | { |
---|
271 | if (cat[i][2] > max) |
---|
272 | { |
---|
273 | cat_max = i; |
---|
274 | max = cat[i][2]; |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | /* return all other indices */ |
---|
279 | list unluckyIndices; |
---|
280 | for (i = 1; i <= size_cat; i++) |
---|
281 | { |
---|
282 | if (i != cat_max) { unluckyIndices = unluckyIndices + cat[i][3]; } |
---|
283 | } |
---|
284 | return(unluckyIndices); |
---|
285 | } |
---|
286 | //////////////////////////////////////////////////////////////////////////////// |
---|
287 | |
---|
288 | static proc cleardenomModule(def I) |
---|
289 | { |
---|
290 | int t=ncols(I); |
---|
291 | if(size(I)==0) |
---|
292 | { |
---|
293 | return(I); |
---|
294 | } |
---|
295 | else |
---|
296 | { |
---|
297 | for(int i=1;i<=t;i++) |
---|
298 | { |
---|
299 | I[i]=cleardenom(I[i]); |
---|
300 | } |
---|
301 | } |
---|
302 | return(I); |
---|
303 | } |
---|
304 | |
---|
305 | static proc pTest_syz(string command, alias list args, alias def result, int p) |
---|
306 | { |
---|
307 | module result_without_denom=cleardenomModule(result); |
---|
308 | return(size(module(matrix(args[1])*matrix(result_without_denom)))==0); |
---|
309 | } |
---|
310 | |
---|
311 | /* test if 'command' applied to 'args' in characteristic p is the same as |
---|
312 | 'result' mapped to characteristic p */ |
---|
313 | static proc pTest_std(string command, alias list args, alias def result, |
---|
314 | int p) |
---|
315 | { |
---|
316 | /* change to characteristic p */ |
---|
317 | def br = basering; |
---|
318 | list lbr = ringlist(br); |
---|
319 | if (typeof(lbr[1]) == "int") { lbr[1] = p; } |
---|
320 | else { lbr[1][1] = p; } |
---|
321 | def rp = ring(lbr); |
---|
322 | setring(rp); |
---|
323 | def Ip = fetch(br, args)[1]; |
---|
324 | def Gp = fetch(br, result); |
---|
325 | attrib(Gp, "isSB", 1); |
---|
326 | |
---|
327 | /* test if Ip is in Gp */ |
---|
328 | int i; |
---|
329 | for (i = ncols(Ip); i > 0; i--) |
---|
330 | { |
---|
331 | if (reduce(Ip[i], Gp, 1) != 0) |
---|
332 | { |
---|
333 | setring(br); |
---|
334 | return(0); |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | /* compute command(args) */ |
---|
339 | execute("Ip = "+command+"(Ip);"); |
---|
340 | |
---|
341 | /* test if Gp is in Ip */ |
---|
342 | for (i = ncols(Gp); i > 0; i--) |
---|
343 | { |
---|
344 | if (reduce(Gp[i], Ip, 1) != 0) { setring(br); return(0); } |
---|
345 | } |
---|
346 | setring(br); |
---|
347 | return(1); |
---|
348 | } |
---|
349 | |
---|
350 | /* test if 'result' is a GB of the input ideal */ |
---|
351 | static proc finalTest_std(string command, alias list args, def result) |
---|
352 | { |
---|
353 | /* test if args[1] is in result */ |
---|
354 | attrib(result, "isSB", 1); |
---|
355 | int i; |
---|
356 | for (i = ncols(args[1]); i > 0; i--) |
---|
357 | { |
---|
358 | if (reduce(args[1][i], result, 1) != 0) { return(0); } |
---|
359 | } |
---|
360 | |
---|
361 | /* test if result is a GB */ |
---|
362 | def G = std(result); |
---|
363 | if (reduce_parallel(G, result)) { return(0); } |
---|
364 | return(1); |
---|
365 | } |
---|
366 | |
---|
367 | /* return 1, if I_reduce is _not_ in G_reduce, |
---|
368 | * 0, otherwise |
---|
369 | * (same as size(reduce(I_reduce, G_reduce))). |
---|
370 | * Uses parallelization. */ |
---|
371 | static proc reduce_parallel(def I_reduce, def G_reduce) |
---|
372 | { |
---|
373 | exportto(Modstd, I_reduce); |
---|
374 | exportto(Modstd, G_reduce); |
---|
375 | int size_I = ncols(I_reduce); |
---|
376 | int chunks = Modular::par_range(size_I); |
---|
377 | intvec range; |
---|
378 | int i; |
---|
379 | for (i = chunks; i > 0; i--) |
---|
380 | { |
---|
381 | range = Modular::par_range(size_I, i); |
---|
382 | task t(i) = "Modstd::reduce_task", list(range); |
---|
383 | } |
---|
384 | startTasks(t(1..chunks)); |
---|
385 | waitAllTasks(t(1..chunks)); |
---|
386 | int result = 0; |
---|
387 | for (i = chunks; i > 0; i--) |
---|
388 | { |
---|
389 | if (getResult(t(i))) { result = 1; break; } |
---|
390 | } |
---|
391 | kill I_reduce; |
---|
392 | kill G_reduce; |
---|
393 | return(result); |
---|
394 | } |
---|
395 | |
---|
396 | /* compute a chunk of reductions for reduce_parallel */ |
---|
397 | static proc reduce_task(intvec range) |
---|
398 | { |
---|
399 | int result = 0; |
---|
400 | int i; |
---|
401 | for (i = range[1]; i <= range[2]; i++) |
---|
402 | { |
---|
403 | if (reduce(I_reduce[i], G_reduce, 1) != 0) { result = 1; break; } |
---|
404 | } |
---|
405 | return(result); |
---|
406 | } |
---|
407 | |
---|
408 | //////////////////////////////////////////////////////////////////////////////// |
---|
409 | /* |
---|
410 | * The following procedures are kept for backward compatibility with the old |
---|
411 | * version of modstd.lib. As of now (May 2014), they are still needed in |
---|
412 | * modnormal.lib, modwalk.lib, and symodstd.lib. They can be removed here as |
---|
413 | * soon as they are not longer needed in these libraries. |
---|
414 | */ |
---|
415 | |
---|
416 | LIB "parallel.lib"; |
---|
417 | |
---|
418 | static proc mod_init() |
---|
419 | { |
---|
420 | newstruct("idealPrimeTest", "ideal Ideal"); |
---|
421 | } |
---|
422 | |
---|
423 | static proc redFork(ideal I, ideal J, int n) |
---|
424 | { |
---|
425 | attrib(J,"isSB",1); |
---|
426 | return(reduce(I,J,1)); |
---|
427 | } |
---|
428 | |
---|
429 | proc isIncluded(ideal I, ideal J, list #) |
---|
430 | "USAGE: isIncluded(I,J); I,J ideals |
---|
431 | RETURN: 1 if J includes I, |
---|
432 | @* 0 if there is an element f in I which does not reduce to 0 w.r.t. J. |
---|
433 | EXAMPLE: example isIncluded; shows an example |
---|
434 | " |
---|
435 | { |
---|
436 | def R = basering; |
---|
437 | setring R; |
---|
438 | |
---|
439 | attrib(J,"isSB",1); |
---|
440 | int i,j,k; |
---|
441 | |
---|
442 | if(size(#) > 0) |
---|
443 | { |
---|
444 | int n = #[1]; |
---|
445 | if(n >= ncols(I)) { n = ncols(I); } |
---|
446 | if(n > 1) |
---|
447 | { |
---|
448 | for(i = 1; i <= n - 1; i++) |
---|
449 | { |
---|
450 | //link l(i) = "MPtcp:fork"; |
---|
451 | link l(i) = "ssi:fork"; |
---|
452 | open(l(i)); |
---|
453 | |
---|
454 | write(l(i), quote(redFork(eval(I[ncols(I)-i]), eval(J), 1))); |
---|
455 | } |
---|
456 | |
---|
457 | int t = timer; |
---|
458 | if(reduce(I[ncols(I)], J, 1) != 0) |
---|
459 | { |
---|
460 | for(i = 1; i <= n - 1; i++) |
---|
461 | { |
---|
462 | close(l(i)); |
---|
463 | } |
---|
464 | return(0); |
---|
465 | } |
---|
466 | t = timer - t; |
---|
467 | if(t > 60) { t = 60; } |
---|
468 | int i_sleep = system("sh", "sleep "+string(t)); |
---|
469 | |
---|
470 | j = ncols(I) - n; |
---|
471 | |
---|
472 | while(j >= 0) |
---|
473 | { |
---|
474 | for(i = 1; i <= n - 1; i++) |
---|
475 | { |
---|
476 | if(status(l(i), "read", "ready")) |
---|
477 | { |
---|
478 | if(read(l(i)) != 0) |
---|
479 | { |
---|
480 | for(i = 1; i <= n - 1; i++) |
---|
481 | { |
---|
482 | close(l(i)); |
---|
483 | } |
---|
484 | return(0); |
---|
485 | } |
---|
486 | else |
---|
487 | { |
---|
488 | if(j >= 1) |
---|
489 | { |
---|
490 | write(l(i), quote(redFork(eval(I[j]), eval(J), 1))); |
---|
491 | j--; |
---|
492 | } |
---|
493 | else |
---|
494 | { |
---|
495 | k++; |
---|
496 | close(l(i)); |
---|
497 | } |
---|
498 | } |
---|
499 | } |
---|
500 | } |
---|
501 | if(k == n - 1) |
---|
502 | { |
---|
503 | j--; |
---|
504 | } |
---|
505 | i_sleep = system("sh", "sleep "+string(t)); |
---|
506 | } |
---|
507 | return(1); |
---|
508 | } |
---|
509 | } |
---|
510 | |
---|
511 | for(i = ncols(I); i >= 1; i--) |
---|
512 | { |
---|
513 | if(reduce(I[i],J,1) != 0){ return(0); } |
---|
514 | } |
---|
515 | return(1); |
---|
516 | } |
---|
517 | example |
---|
518 | { "EXAMPLE:"; echo = 2; |
---|
519 | ring r=0,(x,y,z),dp; |
---|
520 | ideal I = x+1,x+y+1; |
---|
521 | ideal J = x+1,y; |
---|
522 | isIncluded(I,J); |
---|
523 | isIncluded(J,I); |
---|
524 | isIncluded(I,J,4); |
---|
525 | |
---|
526 | ring R = 0, x(1..5), dp; |
---|
527 | ideal I1 = cyclic(4); |
---|
528 | ideal I2 = I1,x(5)^2; |
---|
529 | isIncluded(I1,I2,4); |
---|
530 | } |
---|
531 | |
---|
532 | proc deleteUnluckyPrimes(list T, list L, int ho, list #) |
---|
533 | "USAGE: deleteUnluckyPrimes(T,L,ho,#); T/L list of polys/primes, ho integer |
---|
534 | RETURN: lists T,L(,M),lT with T/L(/M) list of polys/primes(/type of #), |
---|
535 | lT ideal |
---|
536 | NOTE: - if ho = 1, the polynomials in T are homogeneous, else ho = 0, |
---|
537 | @* - lT is prevalent, i.e. the most appearing leading ideal in T |
---|
538 | EXAMPLE: example deleteUnluckyPrimes; shows an example |
---|
539 | " |
---|
540 | { |
---|
541 | ho = ((ho)||(ord_test(basering) == -1)); |
---|
542 | int j,k,c; |
---|
543 | intvec hl,hc; |
---|
544 | ideal cT,lT,cK; |
---|
545 | lT = lead(T[size(T)]); |
---|
546 | attrib(lT,"isSB",1); |
---|
547 | if(!ho) |
---|
548 | { |
---|
549 | for(j = 1; j < size(T); j++) |
---|
550 | { |
---|
551 | cT = lead(T[j]); |
---|
552 | attrib(cT,"isSB",1); |
---|
553 | if((size(reduce(cT,lT,5))!=0)||(size(reduce(lT,cT,5))!=0)) |
---|
554 | { |
---|
555 | cK = cT; |
---|
556 | c++; |
---|
557 | } |
---|
558 | } |
---|
559 | if(c > size(T) div 2){ lT = cK; } |
---|
560 | } |
---|
561 | else |
---|
562 | { |
---|
563 | hl = hilb(lT,1); |
---|
564 | for(j = 1; j < size(T); j++) |
---|
565 | { |
---|
566 | cT = lead(T[j]); |
---|
567 | attrib(cT,"isSB",1); |
---|
568 | hc = hilb(cT,1); |
---|
569 | if(hl == hc) |
---|
570 | { |
---|
571 | for(k = 1; k <= size(lT); k++) |
---|
572 | { |
---|
573 | if(lT[k] < cT[k]) { lT = cT; c++; break; } |
---|
574 | if(lT[k] > cT[k]) { c++; break; } |
---|
575 | } |
---|
576 | } |
---|
577 | else |
---|
578 | { |
---|
579 | if(hc < hl){ lT = cT; hl = hilb(lT,1); c++; } |
---|
580 | } |
---|
581 | } |
---|
582 | } |
---|
583 | |
---|
584 | int addList; |
---|
585 | if(size(#) > 0) { list M = #; addList = 1; } |
---|
586 | j = 1; |
---|
587 | attrib(lT,"isSB",1); |
---|
588 | while((j <= size(T))&&(c > 0)) |
---|
589 | { |
---|
590 | cT = lead(T[j]); |
---|
591 | attrib(cT,"isSB",1); |
---|
592 | if((size(reduce(cT,lT,5)) != 0)||(size(reduce(lT,cT,5)) != 0)) |
---|
593 | { |
---|
594 | T = delete(T,j); |
---|
595 | if(j == 1) |
---|
596 | { |
---|
597 | L = L[2..size(L)]; |
---|
598 | if(addList == 1) { M = M[2..size(M)]; } |
---|
599 | } |
---|
600 | else |
---|
601 | { |
---|
602 | if(j == size(L)) |
---|
603 | { |
---|
604 | L = L[1..size(L)-1]; |
---|
605 | if(addList == 1) { M = M[1..size(M)-1]; } |
---|
606 | } |
---|
607 | else |
---|
608 | { |
---|
609 | L = L[1..j-1],L[j+1..size(L)]; |
---|
610 | if(addList == 1) { M = M[1..j-1],M[j+1..size(M)]; } |
---|
611 | } |
---|
612 | } |
---|
613 | j--; |
---|
614 | } |
---|
615 | j++; |
---|
616 | } |
---|
617 | |
---|
618 | for(j = 1; j <= size(L); j++) |
---|
619 | { |
---|
620 | L[j] = bigint(L[j]); |
---|
621 | } |
---|
622 | |
---|
623 | if(addList == 0) { return(list(T,L,lT)); } |
---|
624 | if(addList == 1) { return(list(T,L,M,lT)); } |
---|
625 | } |
---|
626 | example |
---|
627 | { "EXAMPLE:"; echo = 2; |
---|
628 | list L = 2,3,5,7,11; |
---|
629 | ring r = 0,(y,x),Dp; |
---|
630 | ideal I1 = 2y2x,y6; |
---|
631 | ideal I2 = yx2,y3x,x5,y6; |
---|
632 | ideal I3 = y2x,x3y,x5,y6; |
---|
633 | ideal I4 = y2x,11x3y,x5; |
---|
634 | ideal I5 = y2x,yx3,x5,7y6; |
---|
635 | list T = I1,I2,I3,I4,I5; |
---|
636 | deleteUnluckyPrimes(T,L,1); |
---|
637 | list P = poly(x),poly(x2),poly(x3),poly(x4),poly(x5); |
---|
638 | deleteUnluckyPrimes(T,L,1,P); |
---|
639 | } |
---|
640 | |
---|
641 | proc primeTest(def II, bigint p) |
---|
642 | { |
---|
643 | if(typeof(II) == "string") |
---|
644 | { |
---|
645 | ideal I = `II`.Ideal; |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | ideal I = II; |
---|
650 | } |
---|
651 | |
---|
652 | I = simplify(I, 2); // erase zero generators |
---|
653 | |
---|
654 | int i,j; |
---|
655 | poly f; |
---|
656 | number cnt; |
---|
657 | for(i = 1; i <= size(I); i++) |
---|
658 | { |
---|
659 | f = cleardenom(I[i]); |
---|
660 | if(f == 0) { return(0); } |
---|
661 | cnt = leadcoef(I[i])/leadcoef(f); |
---|
662 | if((bigint(numerator(cnt)) mod p) == 0) { return(0); } |
---|
663 | if((bigint(denominator(cnt)) mod p) == 0) { return(0); } |
---|
664 | for(j = size(f); j > 0; j--) |
---|
665 | { |
---|
666 | if((bigint(leadcoef(f[j])) mod p) == 0) { return(0); } |
---|
667 | } |
---|
668 | } |
---|
669 | return(1); |
---|
670 | } |
---|
671 | |
---|
672 | proc primeList(ideal I, int n, list #) |
---|
673 | "USAGE: primeList(I,n[,ncores]); ( resp. primeList(I,n[,L,ncores]); ) I ideal, |
---|
674 | n integer |
---|
675 | RETURN: the intvec of n greatest primes <= 2147483647 (resp. n greatest primes |
---|
676 | < L[size(L)] union with L) such that none of these primes divides any |
---|
677 | coefficient occuring in I |
---|
678 | NOTE: The number of cores to use can be defined by ncores, default is 1. |
---|
679 | EXAMPLE: example primeList; shows an example |
---|
680 | " |
---|
681 | { |
---|
682 | intvec L; |
---|
683 | int i,p; |
---|
684 | int ncores = 1; |
---|
685 | |
---|
686 | //----------------- Initialize optional parameter ncores --------------------- |
---|
687 | if(size(#) > 0) |
---|
688 | { |
---|
689 | if(size(#) == 1) |
---|
690 | { |
---|
691 | if(typeof(#[1]) == "int") |
---|
692 | { |
---|
693 | ncores = #[1]; |
---|
694 | # = list(); |
---|
695 | } |
---|
696 | } |
---|
697 | else |
---|
698 | { |
---|
699 | ncores = #[2]; |
---|
700 | } |
---|
701 | } |
---|
702 | |
---|
703 | if(size(#) == 0) |
---|
704 | { |
---|
705 | p = 2147483647; |
---|
706 | while(!primeTest(I,p)) |
---|
707 | { |
---|
708 | p = prime(p-1); |
---|
709 | if(p == 2) { ERROR("no more primes"); } |
---|
710 | } |
---|
711 | L[1] = p; |
---|
712 | } |
---|
713 | else |
---|
714 | { |
---|
715 | L = #[1]; |
---|
716 | p = prime(L[size(L)]-1); |
---|
717 | while(!primeTest(I,p)) |
---|
718 | { |
---|
719 | p = prime(p-1); |
---|
720 | if(p == 2) { ERROR("no more primes"); } |
---|
721 | } |
---|
722 | L[size(L)+1] = p; |
---|
723 | } |
---|
724 | if(p == 2) { ERROR("no more primes"); } |
---|
725 | if(ncores == 1) |
---|
726 | { |
---|
727 | for(i = 2; i <= n; i++) |
---|
728 | { |
---|
729 | p = prime(p-1); |
---|
730 | while(!primeTest(I,p)) |
---|
731 | { |
---|
732 | p = prime(p-1); |
---|
733 | if(p == 2) { ERROR("no more primes"); } |
---|
734 | } |
---|
735 | L[size(L)+1] = p; |
---|
736 | } |
---|
737 | } |
---|
738 | else |
---|
739 | { |
---|
740 | int neededSize = size(L)+n-1;; |
---|
741 | list parallelResults; |
---|
742 | list arguments; |
---|
743 | int neededPrimes = neededSize-size(L); |
---|
744 | idealPrimeTest Id; |
---|
745 | Id.Ideal = I; |
---|
746 | export(Id); |
---|
747 | while(neededPrimes > 0) |
---|
748 | { |
---|
749 | arguments = list(); |
---|
750 | for(i = ((neededPrimes div ncores)+1-(neededPrimes%ncores == 0)) |
---|
751 | *ncores; i > 0; i--) |
---|
752 | { |
---|
753 | p = prime(p-1); |
---|
754 | if(p == 2) { ERROR("no more primes"); } |
---|
755 | arguments[i] = list("Id", p); |
---|
756 | } |
---|
757 | parallelResults = parallelWaitAll("primeTest", arguments, 0, ncores); |
---|
758 | for(i = size(arguments); i > 0; i--) |
---|
759 | { |
---|
760 | if(parallelResults[i]) |
---|
761 | { |
---|
762 | L[size(L)+1] = arguments[i][2]; |
---|
763 | } |
---|
764 | } |
---|
765 | neededPrimes = neededSize-size(L); |
---|
766 | } |
---|
767 | kill Id; |
---|
768 | if(size(L) > neededSize) |
---|
769 | { |
---|
770 | L = L[1..neededSize]; |
---|
771 | } |
---|
772 | } |
---|
773 | return(L); |
---|
774 | } |
---|
775 | example |
---|
776 | { "EXAMPLE:"; echo = 2; |
---|
777 | ring r = 0,(x,y,z),dp; |
---|
778 | ideal I = 2147483647x+y, z-181; |
---|
779 | intvec L = primeList(I,10); |
---|
780 | size(L); |
---|
781 | L[1]; |
---|
782 | L[size(L)]; |
---|
783 | L = primeList(I,5,L); |
---|
784 | size(L); |
---|
785 | L[size(L)]; |
---|
786 | } |
---|
787 | |
---|
788 | ////////////////////////////// further examples //////////////////////////////// |
---|
789 | |
---|
790 | /* |
---|
791 | ring r = 0, (x,y,z), lp; |
---|
792 | poly s1 = 5x3y2z+3y3x2z+7xy2z2; |
---|
793 | poly s2 = 3xy2z2+x5+11y2z2; |
---|
794 | poly s3 = 4xyz+7x3+12y3+1; |
---|
795 | poly s4 = 3x3-4y3+yz2; |
---|
796 | ideal i = s1, s2, s3, s4; |
---|
797 | |
---|
798 | ring r = 0, (x,y,z), lp; |
---|
799 | poly s1 = 2xy4z2+x3y2z-x2y3z+2xyz2+7y3+7; |
---|
800 | poly s2 = 2x2y4z+x2yz2-xy2z2+2x2yz-12x+12y; |
---|
801 | poly s3 = 2y5z+x2y2z-xy3z-xy3+y4+2y2z; |
---|
802 | poly s4 = 3xy4z3+x2y2z-xy3z+4y3z2+3xyz3+4z2-x+y; |
---|
803 | ideal i = s1, s2, s3, s4; |
---|
804 | |
---|
805 | ring r = 0, (x,y,z), lp; |
---|
806 | poly s1 = 8x2y2 + 5xy3 + 3x3z + x2yz; |
---|
807 | poly s2 = x5 + 2y3z2 + 13y2z3 + 5yz4; |
---|
808 | poly s3 = 8x3 + 12y3 + xz2 + 3; |
---|
809 | poly s4 = 7x2y4 + 18xy3z2 + y3z3; |
---|
810 | ideal i = s1, s2, s3, s4; |
---|
811 | |
---|
812 | int n = 6; |
---|
813 | ring r = 0,(x(1..n)),lp; |
---|
814 | ideal i = cyclic(n); |
---|
815 | ring s = 0, (x(1..n),t), lp; |
---|
816 | ideal i = imap(r,i); |
---|
817 | i = homog(i,t); |
---|
818 | |
---|
819 | ring r = 0, (x(1..4),s), (dp(4),dp); |
---|
820 | poly s1 = 1 + s^2*x(1)*x(3) + s^8*x(2)*x(3) + s^19*x(1)*x(2)*x(4); |
---|
821 | poly s2 = x(1) + s^8 *x(1)* x(2)* x(3) + s^19* x(2)* x(4); |
---|
822 | poly s3 = x(2) + s^10*x(3)*x(4) + s^11*x(1)*x(4); |
---|
823 | poly s4 = x(3) + s^4*x(1)*x(2) + s^19*x(1)*x(3)*x(4) +s^24*x(2)*x(3)*x(4); |
---|
824 | poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4); |
---|
825 | ideal i = s1, s2, s3, s4, s5; |
---|
826 | |
---|
827 | ring r = 0, (x,y,z), ds; |
---|
828 | int a = 16; |
---|
829 | int b = 15; |
---|
830 | int c = 4; |
---|
831 | int t = 1; |
---|
832 | poly f = x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3 |
---|
833 | +x^(c-2)*y^c*(y2+t*x)^2; |
---|
834 | ideal i = jacob(f); |
---|
835 | |
---|
836 | ring r = 0, (x,y,z), ds; |
---|
837 | int a = 25; |
---|
838 | int b = 25; |
---|
839 | int c = 5; |
---|
840 | int t = 1; |
---|
841 | poly f = x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3 |
---|
842 | +x^(c-2)*y^c*(y2+t*x)^2; |
---|
843 | ideal i = jacob(f),f; |
---|
844 | |
---|
845 | ring r = 0, (x,y,z), ds; |
---|
846 | int a = 10; |
---|
847 | poly f = xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a; |
---|
848 | ideal i = jacob(f); |
---|
849 | |
---|
850 | ring r = 0, (x,y,z), ds; |
---|
851 | int a = 6; |
---|
852 | int b = 8; |
---|
853 | int c = 10; |
---|
854 | int alpha = 5; |
---|
855 | int beta = 5; |
---|
856 | int t = 1; |
---|
857 | poly f = x^a+y^b+z^c+x^alpha*y^(beta-5)+x^(alpha-2)*y^(beta-3) |
---|
858 | +x^(alpha-3)*y^(beta-4)*z^2+x^(alpha-4)*y^(beta-4)*(y^2+t*x)^2; |
---|
859 | ideal i = jacob(f); |
---|
860 | */ |
---|
861 | |
---|