# HG changeset patch
# User Martin Albrecht <malb@informatik.uni-bremen.de>
# Date 1200663296 0
# Node ID 45654ca1a75debf2d589089238f407c237dec89a
# Parent 2453d0497684ed6d32d044d1e383ffbea936b03b
some improvements for the Term Ordering documentation
diff -r 2453d0497684 -r 45654ca1a75d sage/rings/polynomial/term_order.py
a
|
b
|
r""" |
1 | 1 | r""" |
2 | | Term Orderings. |
| 2 | Term Orderings |
3 | 3 | |
4 | 4 | \SAGE supports the following term orderings: |
5 | 5 | |
6 | 6 | \begin{description} |
7 | | \item[Lexicographic (\emph{lex})], defined as |
| 7 | \item[Lexicographic (\emph{lex})] |
8 | 8 | |
9 | 9 | $x^a < x^b \Leftrightarrow \exists\; 1 \le i \le n : a_1 = b_1, \ldots, a_{i-1} = b_{i-1}, a_i < b_i$ |
10 | 10 | |
… |
… |
EXAMPLES: |
23 | 23 | |
24 | 24 | This term ordering is called 'lp' in Singular. |
25 | 25 | |
26 | | \item[Degree reverse lexicographic (\emph{degrevlex})], defined as: |
| 26 | \item[Degree reverse lexicographic (\emph{degrevlex})] |
27 | 27 | |
28 | 28 | Let $deg(x^a) = a_1 + \cdots + a_n,$ then |
29 | 29 | $x^a < x^b \Leftrightarrow deg(x^a) < deg(x^b)$ or |
… |
… |
EXAMPLES: |
44 | 44 | |
45 | 45 | This term ordering is called 'dp' in Singular. |
46 | 46 | |
47 | | \item[Degree lexicographic (\emph{deglex})], defined as: |
| 47 | \item[Degree lexicographic (\emph{deglex})] |
48 | 48 | |
49 | 49 | Let $deg(x^a) = a_1 + \cdots + a_n,$ then |
50 | 50 | $x^a < x^b \Leftrightarrow deg(x^a) < deg(x^b)$ or |
… |
… |
EXAMPLES: |
66 | 66 | |
67 | 67 | This term order is called 'Dp' in Singular. |
68 | 68 | |
69 | | \item[Inverse lexicographic (\emph{invlex})], defined as |
| 69 | \item[Inverse lexicographic (\emph{invlex})] |
70 | 70 | |
71 | 71 | $x^a < x^b \Leftrightarrow \exists\; 1 \le i \le n : a_n = b_n, \ldots, a_{i+1} = b_{i+1}, a_i < b_i.$ |
72 | 72 | |
… |
… |
because if P is the ring $k[x_1, \dots, |
86 | 86 | 'invlex' then it is equivalent to the ring $k[x_n, \dots, x_1]$ with |
87 | 87 | term ordering 'lex'. This ordering is called 'rp' in Singular. |
88 | 88 | |
89 | | \item[Negative lexicographic (\emph{neglex})], defined as |
| 89 | \item[Negative lexicographic (\emph{neglex})] |
90 | 90 | |
91 | 91 | $x^a < x^b \Leftrightarrow \exists\; 1 \le i \le n : a_1 = b_1, \ldots, a_{i-1} = b_{i-1}, a_i > b_i$ |
92 | 92 | |
… |
… |
EXAMPLES: |
105 | 105 | |
106 | 106 | This term ordering is called 'ls' in Singular. |
107 | 107 | |
108 | | \item[Negative degree reverse lexicographic (\emph{negdegrevlex})], defined as: |
| 108 | \item[Negative degree reverse lexicographic (\emph{negdegrevlex})] |
109 | 109 | |
110 | 110 | Let $deg(x^a) = a_1 + \cdots + a_n,$ then |
111 | 111 | $x^a < x^b \Leftrightarrow deg(x^a) > deg(x^b)$ or |
… |
… |
EXAMPLES: |
126 | 126 | |
127 | 127 | This term ordering is called 'ds' in Singular. |
128 | 128 | |
129 | | \item[Negative degree lexicographic (\emph{negdeglex})], defined as: |
| 129 | \item[Negative degree lexicographic (\emph{negdeglex})] |
130 | 130 | |
131 | 131 | Let $deg(x^a) = a_1 + \cdots + a_n,$ then |
132 | 132 | $x^a < x^b \Leftrightarrow deg(x^a) > deg(x^b)$ or |
… |
… |
This term ordering is called 'Ds' in Sin |
149 | 149 | |
150 | 150 | \end{description} |
151 | 151 | |
152 | | Of these, only $degrevlex$, $deglex$, $invlex$ and $lex$ are global orderings. |
| 152 | Of these, only 'degrevlex', 'deglex', 'invlex' and 'lex' are global orderings. |
153 | 153 | |
154 | 154 | Additionally all these monomial orderings may be combined to product |
155 | 155 | or block orderings, defined as: |
156 | 156 | |
157 | | Let $x = (x_0, \ldots, x_{n-1})$ and $y = (y_0, \ldots, y_{m-1})$ be two ordered sets of variables, $<_1$ a |
158 | | monomial ordering on $k[x]$ and $<_2$ a monomial ordering on $k[y]$. |
| 157 | Let $x = (x_0, \ldots, x_{n-1})$ and $y = (y_0, \ldots, y_{m-1})$ be |
| 158 | two ordered sets of variables, $<_1$ a monomial ordering on $k[x]$ and |
| 159 | $<_2$ a monomial ordering on $k[y]$. |
159 | 160 | |
160 | | The product ordering (or block ordering) $<\ := (<_1,<_2)$ on |
161 | | $k[x,y]$ is defined as: |
162 | | $x^a y^b < x^A y^B \Leftrightarrow x^a <_1 x^A \textrm{ or }(x^a =x^A \textrm{ and } y^b <_2 y^B)$. |
| 161 | The product ordering (or block ordering) $<\ := (<_1,<_2)$ on $k[x,y]$ |
| 162 | is defined as: $x^a y^b < x^A y^B \Leftrightarrow x^a <_1 x^A$ or |
| 163 | $(x^a =x^A \textrm{ and } y^b <_2 y^B)$. |
163 | 164 | |
164 | | These block orderings are constructed in SAGE by giving a comma |
| 165 | These block orderings are constructed in \SAGE by giving a comma |
165 | 166 | separated list of monomial orderings with the length of each block |
166 | 167 | attached to them. |
167 | 168 | |
… |
… |
EXAMPLE: |
192 | 193 | True |
193 | 194 | |
194 | 195 | If any other unsupported term ordering is given the provided string is |
195 | | passed through as is to SINGULAR, Macaulay2, and MAGMA. This ensures |
196 | | that it is for example possible to calculated a Groebner basis with |
197 | | respect to some term ordering SINGULAR supports but SAGE doesn't. |
| 196 | passed through as is to \textsc{Singular}, \textsc{Macaulay2}, and |
| 197 | \textsc{Magma}. This ensures that it is for example possible to |
| 198 | calculated a Groebner basis with respect to some term ordering |
| 199 | \textsc{Singular} supports but \SAGE doesn't. |
198 | 200 | |
199 | 201 | AUTHORS: |
200 | 202 | -- David Joyner and William Stein: initial version multi_polynomial_ring |
… |
… |
inv_singular_name_mapping ={'lp':'lex' |
242 | 244 | |
243 | 245 | |
244 | 246 | class TermOrder(SageObject): |
245 | | """ |
246 | | Implements term orderings for polydict bases polynomials and |
247 | | conversions to MAGMA, SINGULAR, and Macaulay2. |
248 | | |
249 | | EXAMPLES: |
250 | | |
251 | | sage: t = TermOrder('lex') |
252 | | sage: t |
253 | | Lexicographic term order |
254 | | sage: loads(dumps(t)) == t |
255 | | True |
256 | | |
257 | | We can construct block orderings directly as |
258 | | |
259 | | sage: TermOrder('degrevlex(3),neglex(2)') |
260 | | degrevlex(3),neglex(2) term order |
261 | | |
262 | | or by adding together the blocks: |
263 | | |
264 | | sage: t1 = TermOrder('degrevlex',3) |
265 | | sage: t2 = TermOrder('neglex',2) |
266 | | sage: t1 + t2 |
267 | | degrevlex(3),neglex(2) term order |
268 | | sage: t2 + t1 |
269 | | neglex(2),degrevlex(3) term order |
270 | | |
271 | | """ |
272 | 247 | def __init__(self, name='lex', n = 0): |
273 | 248 | """ |
274 | 249 | Construct a new term ordering object. |
275 | | |
276 | | See \code{term_order.py} for details which term orderings are |
277 | | supported in SAGE. |
278 | 250 | |
279 | 251 | INPUT: |
280 | 252 | name -- name of the term ordering (default: lex) |
… |
… |
class TermOrder(SageObject): |
282 | 254 | |
283 | 255 | See the \code{sage.rings.polynomial.term_order} module for |
284 | 256 | help which names and orderings are available. |
| 257 | |
| 258 | EXAMPLES: |
| 259 | |
| 260 | sage: t = TermOrder('lex') |
| 261 | sage: t |
| 262 | Lexicographic term order |
| 263 | sage: loads(dumps(t)) == t |
| 264 | True |
| 265 | |
| 266 | We can construct block orderings directly as |
| 267 | |
| 268 | sage: TermOrder('degrevlex(3),neglex(2)') |
| 269 | degrevlex(3),neglex(2) term order |
| 270 | |
| 271 | or by adding together the blocks: |
| 272 | |
| 273 | sage: t1 = TermOrder('degrevlex',3) |
| 274 | sage: t2 = TermOrder('neglex',2) |
| 275 | sage: t1 + t2 |
| 276 | degrevlex(3),neglex(2) term order |
| 277 | sage: t2 + t1 |
| 278 | neglex(2),degrevlex(3) term order |
285 | 279 | |
286 | 280 | NOTE: The optional $n$ parameter is not necessary if only |
287 | 281 | simple orderings like $deglex$ are constructed. However, it is |
… |
… |
class TermOrder(SageObject): |
341 | 335 | def __getattr__(self,name): |
342 | 336 | """ |
343 | 337 | Return the correct compare_tuples/greater_tuple function. |
| 338 | |
| 339 | EXAMPLE: |
| 340 | sage: TermOrder('lex').compare_tuples |
| 341 | <bound method TermOrder.compare_tuples_lp of Lexicographic term order> |
| 342 | |
| 343 | sage: TermOrder('deglex').compare_tuples |
| 344 | <bound method TermOrder.compare_tuples_Dp of Degree lexicographic term order> |
344 | 345 | """ |
345 | 346 | if name=='compare_tuples': |
346 | 347 | if len(self.blocks) == 1: |
… |
… |
class TermOrder(SageObject): |
360 | 361 | Compares two exponent tuples with respect to the |
361 | 362 | lexicographical term order. |
362 | 363 | |
| 364 | INPUT: |
| 365 | f -- exponent tuple |
| 366 | g -- exponent tuple |
| 367 | |
363 | 368 | EXAMPLE: |
364 | 369 | sage: P.<x,y> = PolynomialRing(QQ,2,order='lex') |
365 | | sage: x > y^2 |
| 370 | sage: x > y^2 # indirect doctest |
366 | 371 | True |
367 | 372 | sage: x > 1 |
368 | 373 | True |
… |
… |
class TermOrder(SageObject): |
380 | 385 | Compares two exponent tuples with respect to the inversed |
381 | 386 | lexicographical term order. |
382 | 387 | |
| 388 | INPUT: |
| 389 | f -- exponent tuple |
| 390 | g -- exponent tuple |
| 391 | |
383 | 392 | EXAMPLE: |
384 | 393 | sage: P.<x,y> = PolynomialRing(ZZ,2,order='invlex') |
385 | 394 | sage: x > y^2 |
… |
… |
class TermOrder(SageObject): |
393 | 402 | """ |
394 | 403 | Compares two exponent tuples with respect to the |
395 | 404 | degree lexicographical term order. |
| 405 | |
| 406 | INPUT: |
| 407 | f -- exponent tuple |
| 408 | g -- exponent tuple |
396 | 409 | |
397 | 410 | EXAMPLE: |
398 | 411 | sage: P.<x,y> = PolynomialRing(GF(127),2,order='deglex') |
… |
… |
class TermOrder(SageObject): |
415 | 428 | Compares two exponent tuples with respect to the degree |
416 | 429 | reversed lexicographical term order. |
417 | 430 | |
| 431 | INPUT: |
| 432 | f -- exponent tuple |
| 433 | g -- exponent tuple |
| 434 | |
418 | 435 | EXAMPLE: |
419 | 436 | sage: P.<x,y> = PolynomialRing(GF(127),2,order='degrevlex') |
420 | 437 | sage: x > y^2 |
… |
… |
class TermOrder(SageObject): |
437 | 454 | Compares two exponent tuples with respect to the |
438 | 455 | negative lexicographical term order. |
439 | 456 | |
| 457 | INPUT: |
| 458 | f -- exponent tuple |
| 459 | g -- exponent tuple |
| 460 | |
440 | 461 | EXAMPLE: |
441 | 462 | sage: P.<x,y> = PolynomialRing(GF(2^8,'a'),2,order='neglex') |
442 | 463 | sage: x > y^2 |
… |
… |
class TermOrder(SageObject): |
451 | 472 | Compares two exponent tuples with respect to the |
452 | 473 | negative degree reverse lexicographical term order. |
453 | 474 | |
| 475 | INPUT: |
| 476 | f -- exponent tuple |
| 477 | g -- exponent tuple |
| 478 | |
454 | 479 | EXAMPLE: |
455 | 480 | sage: P.<x,y> = PolynomialRing(IntegerModRing(10), 2,order='negdegrevlex') |
456 | 481 | sage: x > y^2 |
… |
… |
class TermOrder(SageObject): |
464 | 489 | """ |
465 | 490 | Compares two exponent tuples with respect to the |
466 | 491 | negative degree lexicographical term order. |
| 492 | |
| 493 | INPUT: |
| 494 | f -- exponent tuple |
| 495 | g -- exponent tuple |
| 496 | |
467 | 497 | EXAMPLE: |
468 | 498 | sage: P.<x,y> = PolynomialRing(GF(2), 2,order='negdevlex') |
469 | 499 | sage: x > y^2 |
… |
… |
class TermOrder(SageObject): |
479 | 509 | """ |
480 | 510 | Compares two exponent tuple with respec to the block ordering |
481 | 511 | as specified when constructing this element. |
| 512 | |
| 513 | INPUT: |
| 514 | f -- exponent tuple |
| 515 | g -- exponent tuple |
482 | 516 | """ |
483 | 517 | n = 0 |
484 | 518 | for order,length in self.blocks: |
… |
… |
class TermOrder(SageObject): |
495 | 529 | |
496 | 530 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
497 | 531 | |
| 532 | INPUT: |
| 533 | f -- exponent tuple |
| 534 | g -- exponent tuple |
498 | 535 | """ |
499 | 536 | return f > g and f or g |
500 | 537 | |
… |
… |
class TermOrder(SageObject): |
503 | 540 | Returns the greater exponent tuple with respect to the |
504 | 541 | inversed lexicographical term order. |
505 | 542 | |
| 543 | INPUT: |
| 544 | f -- exponent tuple |
| 545 | g -- exponent tuple |
| 546 | |
506 | 547 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
507 | | |
508 | 548 | """ |
509 | 549 | return f.reversed() > g.reversed() and f or g |
510 | 550 | |
… |
… |
class TermOrder(SageObject): |
513 | 553 | Returns the greater exponent tuple with respect to the total |
514 | 554 | degree lexicographical term order. |
515 | 555 | |
| 556 | INPUT: |
| 557 | f -- exponent tuple |
| 558 | g -- exponent tuple |
| 559 | |
516 | 560 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
517 | | |
518 | 561 | """ |
519 | 562 | return (sum(f.nonzero_values(sort=False))>sum(g.nonzero_values(sort=False)) |
520 | 563 | or (sum(f.nonzero_values(sort=False))==sum(g.nonzero_values(sort=False)) and f > g )) and f or g |
… |
… |
class TermOrder(SageObject): |
523 | 566 | """ |
524 | 567 | Returns the greater exponent tuple with respect to the total |
525 | 568 | degree reversed lexicographical term order. |
| 569 | |
| 570 | INPUT: |
| 571 | f -- exponent tuple |
| 572 | g -- exponent tuple |
526 | 573 | |
527 | 574 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
528 | 575 | |
… |
… |
class TermOrder(SageObject): |
534 | 581 | """ |
535 | 582 | Returns the greater exponent tuple with respect to the |
536 | 583 | negative degree reverse lexicographical term order. |
| 584 | |
| 585 | INPUT: |
| 586 | f -- exponent tuple |
| 587 | g -- exponent tuple |
537 | 588 | |
538 | 589 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
539 | 590 | |
… |
… |
class TermOrder(SageObject): |
548 | 599 | Returns the greater exponent tuple with respect to the |
549 | 600 | negative degree lexicographical term order. |
550 | 601 | |
| 602 | INPUT: |
| 603 | f -- exponent tuple |
| 604 | g -- exponent tuple |
| 605 | |
551 | 606 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
552 | 607 | |
553 | 608 | """ |
… |
… |
class TermOrder(SageObject): |
560 | 615 | """ |
561 | 616 | Returns the greater exponent tuple with respect to the |
562 | 617 | negative lexicographical term order. |
| 618 | |
| 619 | INPUT: |
| 620 | f -- exponent tuple |
| 621 | g -- exponent tuple |
563 | 622 | |
564 | 623 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
565 | 624 | |
… |
… |
class TermOrder(SageObject): |
575 | 634 | as specified when constructing this element. |
576 | 635 | |
577 | 636 | This method is called by the lm/lc/lt methods of \code{MPolynomial_polydict}. |
| 637 | |
| 638 | INPUT: |
| 639 | f -- exponent tuple |
| 640 | g -- exponent tuple |
578 | 641 | |
579 | 642 | EXAMPLE: |
580 | 643 | sage: P.<a,b,c,d,e,f>=PolynomialRing(ZZ,6, order='degrevlex(3),degrevlex(3)') |