1 | // $Id: mrrcount.lib,v 1.2 2005-05-02 12:24:16 Singular Exp $ |
---|
2 | // E. Tobis 12.Nov.2004, April 2004 |
---|
3 | // last change 1. May 2005 (G.-M. Greuel) |
---|
4 | /////////////////////////////////////////////////////////////////////////////// |
---|
5 | category="Symbolic-numerical solving" |
---|
6 | info=" |
---|
7 | LIBRARY: mrrcount.lib Counting the number of real roots of polynomial systems |
---|
8 | AUTHOR: Enrique A. Tobis, etobis@dc.uba.ar |
---|
9 | |
---|
10 | OVERVIEW: Routines for counting the number of real roots of a multivariate |
---|
11 | polynomial system. Two methods are implemented: deterministic |
---|
12 | computation of the number of roots, via the signature of a certain |
---|
13 | bilinear form; and a rational univariate projection, using a |
---|
14 | pseudorandom polynomial. Also includes a command to verify the |
---|
15 | correctness of the pseudorandom answer. |
---|
16 | References: Basu, Pollack, Roy, \"Algorithms in Real Algebraic |
---|
17 | Geometry\", Springer, 2003. |
---|
18 | |
---|
19 | PROCEDURES: |
---|
20 | symsignature(m) Signature of the symmetric matrix m |
---|
21 | sturmquery(h,B,I) Sturm query of h on V(I) |
---|
22 | matbil(h,B,I) Matrix of the bilinear form on R/I associated to h |
---|
23 | matmult(f,B,I) Matrix of multiplication by f (m_f) on R/I in the basis B |
---|
24 | tracemult(f,B,I) Trace of m_f (B is an ordered basis of R/I) |
---|
25 | coords(f,B,I) Coordinates of f in the ordered basis B |
---|
26 | randcharpoly(B,I,n) Pseudorandom charpoly of univ. projection, n optional |
---|
27 | verify(p,B,i) Verifies the result of randcharpoly |
---|
28 | randlinpoly(n) Pseudorandom linear polynomial, n optional |
---|
29 | powersums(f,B,I) Powersums of the roots of a char polynomial |
---|
30 | symmfunc(S) Symmetric functions from the powersums S |
---|
31 | univarpoly(l) Polynomial with coefficients from l |
---|
32 | qbase(i) Like kbase, but the monomials are ordered |
---|
33 | |
---|
34 | KEYWORDS: real roots, univariate projection |
---|
35 | "; |
---|
36 | /////////////////////////////////////////////////////////////////// |
---|
37 | LIB "linalg.lib"; // We use charpoly |
---|
38 | LIB "urrcount.lib"; // We use varsigns |
---|
39 | |
---|
40 | proc symsignature(matrix m) |
---|
41 | "USAGE: symsignature(m); m matrix. m must be symmetric. |
---|
42 | RETURN: number: the signature of m |
---|
43 | SEE ALSO: matbil,sturmquery |
---|
44 | EXAMPLE: example symsignature; shows an example" |
---|
45 | { |
---|
46 | int positive, negative, i, j; |
---|
47 | list l; |
---|
48 | poly variable; |
---|
49 | |
---|
50 | if (isparam(m)) { |
---|
51 | ERROR("This procedure cannot operate with parametric arguments"); |
---|
52 | } |
---|
53 | |
---|
54 | if (!isSquare(m)) { |
---|
55 | ERROR ("m must be a square matrix"); |
---|
56 | } |
---|
57 | |
---|
58 | // We check whether m is symmetric |
---|
59 | for (i = 1;i <= nrows(m);i++) { |
---|
60 | for (j = i;j <= nrows(m);j++) { |
---|
61 | if (m[i,j] != m[j,i]) { |
---|
62 | ERROR ("m must be a symmetric matrix"); |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | poly f = charpoly(m); // Uses the last variable of the ring |
---|
68 | |
---|
69 | for (i = size(f);i >= 1;i--) { |
---|
70 | l[i] = leadcoef(f[i]); |
---|
71 | } |
---|
72 | positive = varsigns(l); |
---|
73 | |
---|
74 | variable = var(nvars(basering)); // charpoly uses the last variable |
---|
75 | f = subst(f,variable,-variable); |
---|
76 | |
---|
77 | for (i = size(f);i >= 1;i--) { |
---|
78 | l[i] = leadcoef(f[i]); |
---|
79 | } |
---|
80 | |
---|
81 | negative = varsigns(l); |
---|
82 | return (positive - negative); |
---|
83 | } |
---|
84 | example |
---|
85 | { |
---|
86 | echo = 2; |
---|
87 | ring r = 0,(x,y),dp; |
---|
88 | ideal i = x4-y2x,y2-13; |
---|
89 | i = std(i); |
---|
90 | ideal b = qbase(i); |
---|
91 | |
---|
92 | matrix m = matbil(1,b,i); |
---|
93 | symsignature(m); |
---|
94 | } |
---|
95 | /////////////////////////////////////////////////////////////////////////////// |
---|
96 | |
---|
97 | proc sturmquery(poly h,ideal B,ideal I) |
---|
98 | "USAGE: sturmquery(h,b,i); h poly, b,i ideal |
---|
99 | RETURN: number: the Sturm query of h in V(i) |
---|
100 | ASSUME: i is a Groebner basis, b is an ordered monomial basis |
---|
101 | of r/i, r = basering. |
---|
102 | SEE ALSO: symsignature,matbil |
---|
103 | EXAMPLE: example sturmquery; shows an example" |
---|
104 | { |
---|
105 | if (isparam(h) || isparam(B) || isparam(I)) { |
---|
106 | ERROR("This procedure cannot operate with parametric arguments"); |
---|
107 | } |
---|
108 | |
---|
109 | return (mysymmsig(matbil(h,B,I))); |
---|
110 | } |
---|
111 | example |
---|
112 | { |
---|
113 | echo = 2; |
---|
114 | ring r = 0,(x,y),dp; |
---|
115 | ideal i = x4-y2x,y2-13; |
---|
116 | i = std(i); |
---|
117 | ideal b = qbase(i); |
---|
118 | |
---|
119 | sturmquery(1,b,i); |
---|
120 | } |
---|
121 | |
---|
122 | static proc mysymmsig(matrix m) |
---|
123 | // returns the signature of a square symmetric matrix m |
---|
124 | { |
---|
125 | int positive, negative, i; |
---|
126 | list l; |
---|
127 | poly variable; |
---|
128 | |
---|
129 | poly f = charpoly(m); // Uses the last variable of the ring |
---|
130 | |
---|
131 | for (i = size(f);i >= 1;i--) { |
---|
132 | l[i] = leadcoef(f[i]); |
---|
133 | } |
---|
134 | positive = varsigns(l); |
---|
135 | |
---|
136 | variable = var(nvars(basering)); // charpoly uses the last variable |
---|
137 | f = subst(f,variable,-variable); |
---|
138 | |
---|
139 | for (i = size(f);i >= 1;i--) { |
---|
140 | l[i] = leadcoef(f[i]); |
---|
141 | } |
---|
142 | |
---|
143 | negative = varsigns(l); |
---|
144 | return (positive - negative); |
---|
145 | } |
---|
146 | /////////////////////////////////////////////////////////////////////////////// |
---|
147 | |
---|
148 | proc matbil(poly h,ideal B,ideal I) |
---|
149 | "USAGE: matbil(h,b,i); h poly, b,i ideal |
---|
150 | RETURN: matrix: the matrix of the bilinear form (f,g) |-> trace(m_fhg), |
---|
151 | m_fhg = multiplication with fhg on r/i |
---|
152 | ASSUME: i is a Groebner basis and b is an ordered monomial basis of r/i, |
---|
153 | r = basering |
---|
154 | SEE ALSO: matmult,tracemult |
---|
155 | EXAMPLE: example matbil; shows an example" |
---|
156 | { |
---|
157 | matrix m[size(B)][size(B)]; |
---|
158 | poly f; |
---|
159 | int k,l; |
---|
160 | |
---|
161 | f = reduce(h,I); |
---|
162 | for (k = 1;k <= size(B);k++) { |
---|
163 | for (l = 1;l <= k;l++) { |
---|
164 | m[k,l] = tracemult((reduce(f*B[k]*B[l],I),B,I)); |
---|
165 | m[l,k] = m[k,l]; // The matrix we are trying to compute is symmetric |
---|
166 | } |
---|
167 | } |
---|
168 | return(m); |
---|
169 | } |
---|
170 | example |
---|
171 | { |
---|
172 | echo = 2; |
---|
173 | ring r = 0,(x,y),dp; |
---|
174 | ideal i = x4-y2x,y2-13; |
---|
175 | i = std(i); |
---|
176 | ideal b = qbase(i); |
---|
177 | poly f = x3-xy+y-13+x4-y2x; |
---|
178 | |
---|
179 | matrix m = matbil(f,b,i); |
---|
180 | print(m); |
---|
181 | |
---|
182 | } |
---|
183 | /////////////////////////////////////////////////////////////////////////////// |
---|
184 | |
---|
185 | proc tracemult(poly f,ideal B,ideal I) |
---|
186 | "USAGE: tracemult(f,b,i);f poly, b,i ideal |
---|
187 | RETURN: number: the trace of the multiplication by f (m_f) on r/i, |
---|
188 | written in the monomial basis b of r/i, r = basering |
---|
189 | (faster than matmult + trace) |
---|
190 | ASSUME: i is a Groebner basis and b is an ordered monomial basis of r/i |
---|
191 | SEE ALSO: matmult,trace |
---|
192 | EXAMPLE: example tracemult; shows an example" |
---|
193 | { |
---|
194 | poly g; |
---|
195 | int k; // Iterates over the basis monomials |
---|
196 | int l; // Iterates over the rows of the matrix |
---|
197 | list coordinates; |
---|
198 | number m; |
---|
199 | |
---|
200 | g = reduce(f,I); |
---|
201 | |
---|
202 | m = 0; |
---|
203 | for (k = 1;k <= size(B);k++) { |
---|
204 | coordinates = coords(g*(B[k]),B,I); // f*x_k written on the basis B |
---|
205 | m = m + coordinates[k]; |
---|
206 | } |
---|
207 | return (m); |
---|
208 | } |
---|
209 | example |
---|
210 | { |
---|
211 | echo = 2; |
---|
212 | ring r = 0,(x,y),dp; |
---|
213 | ideal i = x4-y2x,y2-13; |
---|
214 | i = std(i); |
---|
215 | ideal b = qbase(i); |
---|
216 | |
---|
217 | poly f = x3-xy+y-13+x4-y2x; |
---|
218 | matrix m = matmult(f,b,i); |
---|
219 | print(m); |
---|
220 | |
---|
221 | tracemult(f,b,i); |
---|
222 | } |
---|
223 | /////////////////////////////////////////////////////////////////////////////// |
---|
224 | |
---|
225 | proc matmult(poly f, ideal B, ideal I) |
---|
226 | "USAGE: matmult(f,b,i); f poly, b,i ideal |
---|
227 | RETURN: matrix: the matrix of the multiplication map by f (m_f) on r/i |
---|
228 | wrt to the monomial basis b of r/i (r = basering) |
---|
229 | ASSUME: i is a Groebner basis and b is an ordered monomial basis of r/i |
---|
230 | SEE ALSO: coords,matbil |
---|
231 | EXAMPLE: example matmult; shows an example" |
---|
232 | { |
---|
233 | poly g; |
---|
234 | int k; // Iterates over the basis monomials |
---|
235 | int l; // Iterates over the rows of the matrix |
---|
236 | list coordinates; |
---|
237 | matrix m[size(B)][size(B)]; |
---|
238 | |
---|
239 | g = reduce(f,I); |
---|
240 | |
---|
241 | for (k = 1;k <= size(B);k++) { |
---|
242 | coordinates = coords(g*(B[k]),B,I); // f*x_k written on the basis B |
---|
243 | for (l = 1;l <= size(B);l++) { |
---|
244 | m[l,k] = coordinates[l]; |
---|
245 | } |
---|
246 | } |
---|
247 | return (m); |
---|
248 | } |
---|
249 | example |
---|
250 | { |
---|
251 | echo = 2; |
---|
252 | ring r = 0,(x,y),dp; |
---|
253 | ideal i = x4-y2x,y2-13; |
---|
254 | i = std(i); |
---|
255 | ideal b = qbase(i); |
---|
256 | |
---|
257 | poly f = x3-xy+y-13+x4-y2x; |
---|
258 | |
---|
259 | matrix m = matmult(f,b,i); |
---|
260 | print(m); |
---|
261 | } |
---|
262 | /////////////////////////////////////////////////////////////////////////////// |
---|
263 | |
---|
264 | proc coords(poly f,ideal B,ideal I) |
---|
265 | "USAGE: coords(f,b,i), f poly, b,i ideal |
---|
266 | RETURN: list: the coordinates of the class of f in the monomial basis b |
---|
267 | ASSUME: i is a Groebner basis and b is an ordered monomial basis of r/i, |
---|
268 | r = basering |
---|
269 | SEE ALSO: matmult,matbil |
---|
270 | KEYWORDS: coordinates |
---|
271 | EXAMPLE: example coords; shows an example" |
---|
272 | { |
---|
273 | // We assume the basis is sorted according to the ring order |
---|
274 | poly g; |
---|
275 | int k,l=1,1; |
---|
276 | list coordinates; |
---|
277 | int N = size(B); |
---|
278 | |
---|
279 | // We first compute the normal form of f wrt I |
---|
280 | g = reduce(f,I); |
---|
281 | |
---|
282 | coordinates[N] = 0; // We resize the list of coordinates |
---|
283 | while (k <= N) { |
---|
284 | if (l <= size(g) && leadmonom(g[l]) == B[k]) { |
---|
285 | coordinates[k] = leadcoef(g[l]); |
---|
286 | l++; |
---|
287 | } else { |
---|
288 | coordinates[k] = 0; |
---|
289 | } |
---|
290 | k++; |
---|
291 | } |
---|
292 | return (coordinates); |
---|
293 | } |
---|
294 | example |
---|
295 | { |
---|
296 | echo = 2; |
---|
297 | ring r = 0,(x,y),dp; |
---|
298 | ideal i = x4-y2x,y2-13; |
---|
299 | i = std(i); |
---|
300 | ideal b = qbase(i); |
---|
301 | |
---|
302 | coords(x3-xy+y-13+x4-y2x,b,i); |
---|
303 | b; |
---|
304 | } |
---|
305 | /////////////////////////////////////////////////////////////////////////////// |
---|
306 | |
---|
307 | static proc isSquare(matrix m) |
---|
308 | // returns 1 iff m is a square matrix |
---|
309 | { |
---|
310 | return (nrows(m)==ncols(m)); |
---|
311 | } |
---|
312 | /////////////////////////////////////////////////////////////////////////////// |
---|
313 | |
---|
314 | proc randcharpoly(ideal B,ideal I,list #) |
---|
315 | "USAGE: randcharpoly(b,i); randcharpoly(b,i,n); b,i ideal; n int |
---|
316 | RETURN: poly: the characteristic polynomial of a pseudorandom |
---|
317 | rational univariate projection having one zero per zero of i. |
---|
318 | If n is given, it is the number of digits being used for the |
---|
319 | pseudorandom coefficients (default: n=2) |
---|
320 | ASSUME: i is a Groebner basis and b is an ordered monomial basis of r/i, |
---|
321 | r = basering |
---|
322 | KEYWORDS: rational univariate projection |
---|
323 | EXAMPLE: example randcharpoly; shows an example" |
---|
324 | { |
---|
325 | poly p; |
---|
326 | poly generic; |
---|
327 | list l; |
---|
328 | matrix m; |
---|
329 | poly q; |
---|
330 | |
---|
331 | if (size(#) == 1) { |
---|
332 | generic = randlinpoly(#[1]); |
---|
333 | } else { |
---|
334 | generic = randlinpoly(); |
---|
335 | } |
---|
336 | |
---|
337 | p = reduce(generic,I); |
---|
338 | m = matmult(p,B,I); |
---|
339 | q = charpoly(m); |
---|
340 | |
---|
341 | print("*********************************************************************"); |
---|
342 | print("* WARNING: This polynomial was obtained using pseudorandom numbers.*"); |
---|
343 | print("* If you want to verify the result, please use the command *"); |
---|
344 | print("* *"); |
---|
345 | print("* verify(p,b,i) *"); |
---|
346 | print("* *"); |
---|
347 | print("* where p is the polynomial I returned, b is the monomial basis *"); |
---|
348 | print("* used, and i the Groebner basis of the ideal *"); |
---|
349 | print("*********************************************************************"); |
---|
350 | |
---|
351 | return(q); |
---|
352 | } |
---|
353 | example |
---|
354 | { |
---|
355 | echo = 2; |
---|
356 | ring r = 0,(x,y,z),dp; |
---|
357 | ideal i = (x-1)*(x-2),(y-1),(z-1)*(z-2)*(z-3)^2; |
---|
358 | i = std(i); |
---|
359 | ideal b = qbase(i); |
---|
360 | poly p = randcharpoly(b,i); |
---|
361 | p; |
---|
362 | nrroots(p); // See nrroots in urrcount.lib |
---|
363 | p = randcharpoly(b,i,5); |
---|
364 | p; |
---|
365 | nrroots(p); |
---|
366 | } |
---|
367 | |
---|
368 | /////////////////////////////////////////////////////////////////////////////// |
---|
369 | |
---|
370 | proc verify(poly p,ideal b,ideal i) |
---|
371 | "USAGE: verify(p,b,i);p poly, b,i,ideal |
---|
372 | RETURN: integer: 1 iff the polynomial p splits the points of V(i). |
---|
373 | It's used to check the result of randcharpoly |
---|
374 | ASSUME: i is a Groebner basis and b is an ordered monomial basis of r/i, |
---|
375 | r = basering |
---|
376 | SEE ALSO: randcharpoly |
---|
377 | EXAMPLE: example verify; shows an example" |
---|
378 | { |
---|
379 | poly sqrfree; |
---|
380 | int correct; |
---|
381 | poly variable; |
---|
382 | |
---|
383 | if (isparam(p) || isparam(b) || isparam(i)) { |
---|
384 | ERROR("This procedure cannot operate with parametric arguments"); |
---|
385 | } |
---|
386 | |
---|
387 | variable = isuni(p); |
---|
388 | sqrfree = p/gcd(p,diff(p,variable)); |
---|
389 | correct = (mat_rk(matbil(1,b,i)) == deg(sqrfree)); |
---|
390 | |
---|
391 | if (correct) { |
---|
392 | print("Verification successful"); |
---|
393 | } else { |
---|
394 | print("The choice of random numbers was not useful"); |
---|
395 | print("You might want to try randcharpoly with a larger number of digits"); |
---|
396 | } |
---|
397 | return (correct); |
---|
398 | } |
---|
399 | example |
---|
400 | { |
---|
401 | echo = 2; |
---|
402 | ring r = 0,(x,y),dp; |
---|
403 | poly f = x3-xy+y-13+x4-y2x; |
---|
404 | ideal i = x4-y2x,y2-13; |
---|
405 | i = std(i); |
---|
406 | ideal b = qbase(i); |
---|
407 | poly p = randcharpoly(b,i); |
---|
408 | verify(p,b,i); |
---|
409 | } |
---|
410 | /////////////////////////////////////////////////////////////////////////////// |
---|
411 | |
---|
412 | proc randlinpoly(list #) |
---|
413 | "USAGE: randlinpoly(); randlinpoly(n); n int |
---|
414 | RETURN: poly: a polynomial linear in each variable of the ring, with |
---|
415 | pseudorandom coefficients. If n is given, it is the number of |
---|
416 | digits being used for the range of the coefficients (default: n=2) |
---|
417 | SEE ALSO: randcharpoly; |
---|
418 | EXAMPLE: example randlinpoly; shows an example" |
---|
419 | { |
---|
420 | int n,i; |
---|
421 | poly p = 0; |
---|
422 | int ndigits = 2; |
---|
423 | |
---|
424 | if (size(#) == 1) { |
---|
425 | ndigits = #[1]; |
---|
426 | } |
---|
427 | |
---|
428 | n = nvars(basering); |
---|
429 | for (i = 1;i <= n;i++) { |
---|
430 | p = p + var(i)*random(1,10^ndigits); |
---|
431 | } |
---|
432 | return (p); |
---|
433 | } |
---|
434 | example |
---|
435 | { |
---|
436 | echo = 2; |
---|
437 | ring r = 0,(x,y,z,w),dp; |
---|
438 | poly p = randlinpoly(); |
---|
439 | p; |
---|
440 | p = randlinpoly(5); |
---|
441 | p; |
---|
442 | } |
---|
443 | /////////////////////////////////////////////////////////////////////////////// |
---|
444 | |
---|
445 | proc powersums(poly f,ideal B,ideal I) |
---|
446 | "USAGE: powersums(f,b,i); f poly; b,i ideal, b a sorted monomial basis for |
---|
447 | the quotient between the basering and i. |
---|
448 | RETURN: list: the powersums of the results of evaluating f at the zeros of I |
---|
449 | SEE ALSO: symmfunc |
---|
450 | EXAMPLE: example symmfunc; shows an example" |
---|
451 | { |
---|
452 | int N,k; |
---|
453 | list sums; |
---|
454 | |
---|
455 | N = size(B); |
---|
456 | for (k = 1;k <= N;k++) { |
---|
457 | sums = sums + list(leadcoef(trace(matmult(f^k,B,I)))); |
---|
458 | } |
---|
459 | return (sums); |
---|
460 | } |
---|
461 | example |
---|
462 | { |
---|
463 | echo = 2; |
---|
464 | ring r = 0,(x,y,z),dp; |
---|
465 | |
---|
466 | ideal i = (x-1)*(x-2),(y-1),(z+5); // V(I) = {(1,1,-5),(2,1,-5) |
---|
467 | i = std(i); |
---|
468 | |
---|
469 | ideal b = qbase(i); |
---|
470 | poly f = x+y+z; |
---|
471 | list psums = list(-2-3,4+9); // f evaluated at V(I) gives {-3,-2} |
---|
472 | list l = powersums(f,b,i); |
---|
473 | psums; |
---|
474 | l; |
---|
475 | } |
---|
476 | /////////////////////////////////////////////////////////////////////////////// |
---|
477 | |
---|
478 | proc symmfunc(list S) |
---|
479 | // Takes the list of power sums and returns the symmetric functions |
---|
480 | "USAGE: symmfunc(s); s list |
---|
481 | RETURN: list: the symmetric functions of the roots of a polynomial, given |
---|
482 | the power sums of those roots. |
---|
483 | SEE ALSO: powersums |
---|
484 | EXAMPLE: example symmfunc; shows an example" |
---|
485 | { |
---|
486 | list a; |
---|
487 | int j,l,N; |
---|
488 | number sum; |
---|
489 | |
---|
490 | N = size(S); |
---|
491 | a[N+1] = 1; // We set the length of the list and initialize its last element. |
---|
492 | |
---|
493 | for (l = N - 1;l >= 0;l--) { |
---|
494 | sum = 0; |
---|
495 | for (j = l + 1;j <= N;j++) { |
---|
496 | sum = sum + ((a[j+1])*(S[j-l])); |
---|
497 | } |
---|
498 | sum = -sum; |
---|
499 | a[l+1] = sum/(N-l); |
---|
500 | } |
---|
501 | |
---|
502 | a = reverse(a); |
---|
503 | return (a); |
---|
504 | } |
---|
505 | example |
---|
506 | { |
---|
507 | echo = 2; |
---|
508 | ring r = 0,x,dp; |
---|
509 | poly p = (x-1)*(x-2)*(x-3); |
---|
510 | list psums = list(1+2+3,1+4+9,1+8+27); |
---|
511 | list l = symmfunc(psums); |
---|
512 | l; |
---|
513 | p; // Compare p with the elements of l |
---|
514 | } |
---|
515 | /////////////////////////////////////////////////////////////////////////////// |
---|
516 | |
---|
517 | proc univarpoly(list l) |
---|
518 | "USAGE: univarpoly(l); l list |
---|
519 | RETURN: poly: a polynomial p on the first variable of basering, say x, |
---|
520 | with p = l[1] + l[2]*x + l[3]*x^2 + ... |
---|
521 | EXAMPLE: example univarpoly; shows an example" |
---|
522 | { |
---|
523 | poly p; |
---|
524 | int i,n; |
---|
525 | |
---|
526 | n = size(l); |
---|
527 | for (i = 1;i <= n;i++) { |
---|
528 | p = p + l[i]*var(1)^(n-i); |
---|
529 | } |
---|
530 | return (p); |
---|
531 | } |
---|
532 | example |
---|
533 | { |
---|
534 | echo = 2; |
---|
535 | ring r = 0,x,dp; |
---|
536 | list l = list(1,2,3,4,5); |
---|
537 | poly p = univarpoly(l); |
---|
538 | p; |
---|
539 | } |
---|
540 | /////////////////////////////////////////////////////////////////////////////// |
---|
541 | |
---|
542 | proc qbase(ideal i) |
---|
543 | "USAGE: qbase(I); I zero-dimensional ideal |
---|
544 | RETURN: ideal: A monomial basis of the quotient between the basering and the |
---|
545 | ideal I, sorted according to the basering order. |
---|
546 | SEE ALSO: kbase |
---|
547 | KEYWORDS: zero-dimensional |
---|
548 | EXAMPLE: example qbase; shows an example" |
---|
549 | { |
---|
550 | ideal b; |
---|
551 | |
---|
552 | b = kbase(i); |
---|
553 | b = reverseideal(sort(b)[1]); // sort sorts in ascending order |
---|
554 | return (b); |
---|
555 | } |
---|
556 | example |
---|
557 | { |
---|
558 | echo = 2; |
---|
559 | ring r = 0,(x,y,z),dp; |
---|
560 | |
---|
561 | ideal i = 2x2,-y2,z3; |
---|
562 | i = std(i); |
---|
563 | ideal b = qbase(i); |
---|
564 | b; |
---|
565 | b = kbase(i); |
---|
566 | b; // Compare this with the result of qbase |
---|
567 | } |
---|
568 | /////////////////////////////////////////////////////////////////////////////// |
---|
569 | |
---|
570 | static proc reverseideal(ideal b) // Returns b reversed |
---|
571 | { |
---|
572 | int i; |
---|
573 | ideal result; |
---|
574 | |
---|
575 | result = b[1]; |
---|
576 | for (i = 2;i <= size(b);i++) { |
---|
577 | result = b[i], result; |
---|
578 | } |
---|
579 | return (result); |
---|
580 | } |
---|
581 | /////////////////////////////////////////////////////////////////////////////// |
---|
582 | |
---|