# HG changeset patch
# User Andrey Novoseltsev <novoselt@gmail.com>
# Date 1264998537 25200
# Node ID fda756e64a90a512d2620cafeb050edcff944b75
# Parent fca3d8df3d5a420331fa85a40b821c9726b23337
Trac 7897: Update doctests in Macaulay2 interface.
diff -r fca3d8df3d5a -r fda756e64a90 sage/interfaces/macaulay2.py
a
|
b
|
|
40 | 40 | sage: R = macaulay2('ZZ/5[x,y,z]') #optional |
41 | 41 | sage: print R #optional |
42 | 42 | ZZ |
43 | | -- [x, y, z] |
44 | | 5 |
| 43 | --[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => {MonomialSize => 32}, DegreeRank => 1] |
| 44 | 5 {GRevLex => {3:1} } |
| 45 | {Position => Up } |
45 | 46 | sage: x = macaulay2('x') #optional |
46 | 47 | sage: y = macaulay2('y') #optional |
47 | 48 | sage: print (x+y)^5 #optional |
… |
… |
|
396 | 397 | |
397 | 398 | EXAMPLES: |
398 | 399 | sage: macaulay2.version() #optional |
399 | | (1, 1) |
| 400 | (1, 3, 1) |
400 | 401 | """ |
401 | 402 | s = self.eval("version") |
402 | 403 | r = re.compile("VERSION => (.*?)\n") |
… |
… |
|
417 | 418 | |
418 | 419 | EXAMPLES: |
419 | 420 | sage: R2 = macaulay2.ring('QQ', '[x, y]'); R2 # optional |
420 | | QQ [x, y, MonomialOrder => Lex, MonomialSize => 16] |
| 421 | QQ[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => {MonomialSize => 16}, DegreeRank => 1] |
| 422 | {Lex => 2 } |
| 423 | {Position => Up } |
421 | 424 | sage: I = macaulay2.ideal( ('y^2 - x^3', 'x - y') ); I # optional |
422 | 425 | 3 2 |
423 | 426 | ideal (- x + y , x - y) |
… |
… |
|
455 | 458 | of order 7, with graded reverse lex ordering: |
456 | 459 | sage: R1 = macaulay2.ring('ZZ/7', '[a..d]', 'GRevLex'); R1 # optional |
457 | 460 | ZZ |
458 | | -- [a, b, c, d, MonomialOrder => GRevLex, MonomialSize => 16] |
459 | | 7 |
| 461 | --[a..d, Degrees => {4:1}, Heft => {1}, MonomialOrder => {MonomialSize => 16}, DegreeRank => 1] |
| 462 | 7 {GRevLex => {4:1} } |
| 463 | {Position => Up } |
460 | 464 | sage: R1.char() # optional |
461 | 465 | 7 |
462 | 466 | |
463 | 467 | This is a polynomial ring over the rational numbers: |
464 | 468 | sage: R2 = macaulay2.ring('QQ', '[x, y]'); R2 # optional |
465 | | QQ [x, y, MonomialOrder => Lex, MonomialSize => 16] |
| 469 | QQ[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => {MonomialSize => 16}, DegreeRank => 1] |
| 470 | {Lex => 2 } |
| 471 | {Position => Up } |
466 | 472 | """ |
467 | 473 | varstr = str(vars)[1:-1] |
468 | 474 | if ".." in varstr: |
… |
… |
|
504 | 510 | |
505 | 511 | cmds.append(cmd) |
506 | 512 | cmds.sort() |
507 | | return cmds |
508 | | |
| 513 | return cmds |
509 | 514 | |
510 | 515 | def help(self, s): |
511 | 516 | """ |
512 | 517 | EXAMPLES: |
513 | | sage: macaulay2.help("gb") #optional |
514 | | help(gb) |
| 518 | sage: macaulay2.help("load") # optional |
| 519 | load -- read Macaulay2 commands |
| 520 | ******************************* |
515 | 521 | ... |
516 | | gb -- compute a Groebner basis |
517 | | ****************************** |
518 | | ... |
519 | | * gb(Matrix) |
520 | | * gb(Module) |
| 522 | * "input" -- read Macaulay2 commands and echo |
| 523 | * "notify" -- whether to notify the user when a file is loaded |
521 | 524 | """ |
522 | | import re |
523 | | div = re.compile("o[0-9]+ : DIV") |
524 | | if self._expect is None: |
525 | | self._start() |
526 | | E = self._expect |
527 | | E.sendline("help(%s)"%s) |
528 | | E.expect(div) |
529 | | s = E.before |
530 | | E.expect(self._prompt) |
531 | | return AsciiArtString(s) |
532 | | |
| 525 | r = self.eval("help %s" % s) |
| 526 | end = r.rfind("\n\nDIV") |
| 527 | if end != -1: |
| 528 | r = r[:end] |
| 529 | return AsciiArtString(r) |
533 | 530 | |
534 | 531 | def trait_names(self, verbose=True, use_disk_cache=True): |
535 | 532 | """ |
… |
… |
|
576 | 573 | sage: P = macaulay2("ZZ/7[symbol x, symbol y]") #optional |
577 | 574 | sage: macaulay2("x").cls() #optional |
578 | 575 | ZZ |
579 | | -- [x, y] |
580 | | 7 |
| 576 | --[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => {MonomialSize => 32}, DegreeRank => 1] |
| 577 | 7 {GRevLex => {2:1} } |
| 578 | {Position => Up } |
581 | 579 | sage: macaulay2.use(R) #optional |
582 | 580 | sage: macaulay2("x").cls() #optional |
583 | | QQ [x, y] |
| 581 | QQ[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => {MonomialSize => 32}, DegreeRank => 1] |
| 582 | {GRevLex => {2:1} } |
| 583 | {Position => Up } |
584 | 584 | """ |
585 | 585 | R = self(R) |
586 | 586 | self.eval("use %s"%R.name()) |
… |
… |
|
637 | 637 | sage: print x+y #optional |
638 | 638 | x + y |
639 | 639 | sage: print macaulay2("QQ[x,y,z]") #optional |
640 | | QQ [x, y, z] |
| 640 | QQ[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => {MonomialSize => 32}, DegreeRank => 1] |
| 641 | {GRevLex => {3:1} } |
| 642 | {Position => Up } |
641 | 643 | sage: print macaulay2("QQ[x,y,z]/(x+y+z)") #optional |
642 | | QQ [x, y, z] |
643 | | ------------ |
| 644 | QQ[x, y, z] |
| 645 | ----------- |
644 | 646 | x + y + z |
645 | 647 | """ |
646 | 648 | P = self._check_valid() |
… |
… |
|
653 | 655 | EXAMPLES: |
654 | 656 | sage: R = macaulay2("QQ[symbol x, symbol y]") #optional |
655 | 657 | sage: R.external_string() #optional |
656 | | 'QQ [x, y]' |
| 658 | 'QQ[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {2:1}, Position => Up}, DegreeRank => 1]' |
657 | 659 | """ |
658 | 660 | P = self._check_valid() |
659 | 661 | code = 'toExternalString(%s)'%self.name() |
… |
… |
|
731 | 733 | Now make the M2 version of R, so we can coerce elements of R to M2: |
732 | 734 | sage: macaulay2(R) # optional |
733 | 735 | ZZ |
734 | | -- [x, y, MonomialOrder => GRevLex, MonomialSize => 16] |
735 | | 7 |
| 736 | --[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => {MonomialSize => 16}, DegreeRank => 1] |
| 737 | 7 {GRevLex => {2:1} } |
| 738 | {Position => Up } |
736 | 739 | sage: f = (x^3 + 2*y^2*x)^7; f |
737 | 740 | x^21 + 2*x^7*y^14 |
738 | 741 | sage: h = macaulay2(f); h # optional |
… |
… |
|
763 | 766 | Now make the M2 version of R, so we can coerce elements of R to M2: |
764 | 767 | sage: macaulay2(R) # optional |
765 | 768 | ZZ |
766 | | -- [x, y, MonomialOrder => GRevLex, MonomialSize => 16] |
767 | | 7 |
| 769 | --[x..y, Degrees => {2:1}, Heft => {1}, MonomialOrder => {MonomialSize => 16}, DegreeRank => 1] |
| 770 | 7 {GRevLex => {2:1} } |
| 771 | {Position => Up } |
768 | 772 | sage: f = (x^3 + 2*y^2*x)^7; f # optional |
769 | 773 | x^21 + 2*x^7*y^14 |
770 | 774 | sage: h = macaulay2(f); print h # optional |
… |
… |
|
1045 | 1049 | #Get a string list of generators |
1046 | 1050 | gens = str(self.gens())[1:-1] |
1047 | 1051 | |
| 1052 | # Check that we are dealing with default degrees, i.e. 1's. |
| 1053 | if self.degrees().any("x -> x != {1}").to_sage(): |
| 1054 | raise ValueError, "cannot convert Macaulay2 polynomial ring with non-default degrees to Sage" |
1048 | 1055 | #Handle the term order |
1049 | 1056 | external_string = self.external_string() |
1050 | 1057 | order = None |
1051 | | if "Degrees" in external_string: |
1052 | | raise ValueError, "cannot convert Macaulay2 polynomial ring with non-default degrees to Sage" |
1053 | 1058 | if "MonomialOrder" not in external_string: |
1054 | 1059 | order = "degrevlex" |
1055 | 1060 | else: |
… |
… |
|
1113 | 1118 | def _sage_doc_(self): |
1114 | 1119 | """ |
1115 | 1120 | EXAMPLES: |
1116 | | sage: print macaulay2.gb._sage_doc_() #optional |
1117 | | help(gb) |
| 1121 | sage: print macaulay2.load._sage_doc_() # optional |
| 1122 | load -- read Macaulay2 commands |
| 1123 | ******************************* |
1118 | 1124 | ... |
1119 | | gb -- compute a Groebner basis |
1120 | | ****************************** |
1121 | | ... |
1122 | | * gb(Matrix) |
1123 | | * gb(Module) |
| 1125 | * "input" -- read Macaulay2 commands and echo |
| 1126 | * "notify" -- whether to notify the user when a file is loaded |
1124 | 1127 | """ |
1125 | 1128 | return self._parent.help(self._name) |
1126 | 1129 | |