-
# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1227497767 28800
# Node ID 334d17e4247e08c16e57b02c2b0245f4171338ee
# Parent a0b4c7f7ead9aa49975d5c361d9b9fae1a05054b
trac #4601 -- optional magma interface -- fix all broken optional doctests by introducing _magma_init_(self, magma) signature
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/calculus/calculus.py
|
a
|
b
|
|
| 1187 | 1187 | def _maple_init_(self): |
| 1188 | 1188 | return self._sys_init_('maple') |
| 1189 | 1189 | |
| 1190 | | def _magma_init_(self): |
| | 1190 | def _magma_init_(self, magma): |
| 1191 | 1191 | """ |
| 1192 | 1192 | Return string representation in Magma of this symbolic expression. |
| 1193 | 1193 | |
| … |
… |
|
| 1197 | 1197 | EXAMPLES: |
| 1198 | 1198 | sage: x = var('x') |
| 1199 | 1199 | sage: f = sin(cos(x^2) + log(x)) |
| 1200 | | sage: f._magma_init_() |
| | 1200 | sage: f._magma_init_(magma) |
| 1201 | 1201 | '"sin(cos(x^2) + log(x))"' |
| 1202 | 1202 | sage: magma(f) # optional - magma |
| 1203 | 1203 | sin(cos(x^2) + log(x)) |
| … |
… |
|
| 4095 | 4095 | try: |
| 4096 | 4096 | return x.__getattribute__('_%s_init_'%system)() |
| 4097 | 4097 | except AttributeError: |
| 4098 | | try: |
| 4099 | | return x._system_init_(system) |
| 4100 | | except AttributeError: |
| 4101 | | return repr(x) |
| | 4098 | return repr(x) |
| 4102 | 4099 | |
| 4103 | 4100 | class SymbolicConstant(Symbolic_object): |
| 4104 | 4101 | def __init__(self, x): |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/crypto/mq/mpolynomialsystem.py
|
a
|
b
|
|
| 43 | 43 | from sage.matrix.constructor import Matrix |
| 44 | 44 | |
| 45 | 45 | from sage.interfaces.singular import singular |
| 46 | | from sage.interfaces.magma import magma |
| 47 | 46 | |
| 48 | 47 | |
| 49 | 48 | def is_MPolynomialSystem(F): |
| … |
… |
|
| 408 | 407 | """ |
| 409 | 408 | return singular.ideal(self._gens) |
| 410 | 409 | |
| 411 | | def _magma_(self): |
| | 410 | def _magma_(self, magma): |
| 412 | 411 | """ |
| 413 | 412 | Return MAGMA ideal representation of self. |
| 414 | 413 | |
| … |
… |
|
| 416 | 415 | sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) |
| 417 | 416 | sage: F,s = sr.polynomial_system() |
| 418 | 417 | sage: R1 = F.round(1) |
| 419 | | sage: R1._magma_() # optional - magma |
| | 418 | sage: magma(R1) # optional - magma |
| 420 | 419 | Ideal of Polynomial ring of rank 20 over GF(2) |
| 421 | 420 | Graded Reverse Lexicographical Order |
| 422 | 421 | Variables: k100, k101, k102, k103, x100, x101, x102, x103, w100, w101, w102, w103, s000, s001, s002, s003, k000, k001, k002, k003 |
| … |
… |
|
| 826 | 825 | |
| 827 | 826 | def _singular_(self): |
| 828 | 827 | """ |
| 829 | | Return SINGULAR ideal representation of this system. |
| | 828 | Return Singular ideal representation of this system. |
| 830 | 829 | |
| 831 | 830 | EXAMPLE: |
| 832 | 831 | sage: P.<a,b,c,d> = PolynomialRing(GF(127)) |
| … |
… |
|
| 841 | 840 | """ |
| 842 | 841 | return singular.ideal(list(self)) |
| 843 | 842 | |
| 844 | | def _magma_(self): |
| | 843 | def _magma_(self, magma): |
| 845 | 844 | """ |
| 846 | | Return MAGMA ideal representation of this system as an ideal. |
| | 845 | Return Magma ideal representation of this system as an ideal. |
| 847 | 846 | |
| 848 | 847 | EXAMPLE: |
| 849 | 848 | sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) |
| 850 | 849 | sage: F,s = sr.polynomial_system() |
| 851 | | sage: F._magma_() # optional - magma |
| | 850 | sage: magma(F) # optional - magma |
| | 851 | Ideal of Polynomial ring of rank 20 over GF(2) |
| | 852 | Graded Reverse Lexicographical Order |
| | 853 | Variables: k100, k101, k102, k103, x100, x101, x102, x103, w100, w101, w102, w103, s000, s001, s002, s003, k000, k001, k002, k003 |
| | 854 | Basis: |
| | 855 | [ |
| | 856 | ... |
| | 857 | ] |
| 852 | 858 | """ |
| 853 | 859 | return magma.ideal(list(self)) |
| 854 | 860 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/groups/perm_gps/permgroup.py
|
a
|
b
|
|
| 320 | 320 | """ |
| 321 | 321 | return self._gap_string |
| 322 | 322 | |
| 323 | | def _magma_init_(self): |
| | 323 | def _magma_init_(self, magma): |
| 324 | 324 | r""" |
| 325 | 325 | Returns a string showing how to declare / intialize self in Magma. |
| 326 | 326 | |
| … |
… |
|
| 329 | 329 | Magma, one would type the string below to construct the group. |
| 330 | 330 | sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4 |
| 331 | 331 | Permutation Group with generators [(2,3,4), (1,2,3)] |
| 332 | | sage: A4._magma_init_() |
| | 332 | sage: A4._magma_init_(magma) |
| 333 | 333 | 'PermutationGroup<4 | (2,3,4), (1,2,3)>' |
| 334 | 334 | """ |
| 335 | 335 | g = str(self.gens())[1:-1] |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/interfaces/magma.py
|
a
|
b
|
|
| 95 | 95 | ] |
| 96 | 96 | |
| 97 | 97 | In SAGE/Python (and sort of C++) coercion of an element x into a |
| 98 | | structure S is denoted by S(x). This also works for the MAGMA interface: |
| | 98 | structure S is denoted by S(x). This also works for the Magma interface: |
| 99 | 99 | |
| 100 | 100 | sage: G = magma.DirichletGroup(20) # optional - magma |
| 101 | 101 | sage: G.AssignNames(['a', 'b']) # optional - magma |
| … |
… |
|
| 107 | 107 | sage: print e.Modulus() # optional - magma |
| 108 | 108 | 40 |
| 109 | 109 | |
| 110 | | We coerce some polynomial rings into MAGMA: |
| | 110 | We coerce some polynomial rings into Magma: |
| 111 | 111 | |
| 112 | 112 | sage: R.<y> = PolynomialRing(QQ) |
| 113 | 113 | sage: S = magma(R) # optional - magma |
| … |
… |
|
| 185 | 185 | a new Magma object, and \code{magma.eval(...)} to run a string |
| 186 | 186 | using Magma (and get the result back as a string). |
| 187 | 187 | |
| 188 | | NOTE: If you do not own a local copy of MAGMA, try using the |
| | 188 | NOTE: If you do not own a local copy of Magma, try using the |
| 189 | 189 | \code{magma\_free} command instead, which uses the free demo web |
| 190 | | interface to MAGMA. |
| | 190 | interface to Magma. |
| 191 | 191 | |
| 192 | 192 | EXAMPLES: |
| 193 | 193 | |
| … |
… |
|
| 209 | 209 | logfile -- output logged to this file |
| 210 | 210 | server -- address of remote server |
| 211 | 211 | user_config -- if True, then local user configuration files |
| 212 | | will be read by MAGMA. If False (the default), |
| 213 | | then MAGMA is started with the -n option which |
| | 212 | will be read by Magma. If False (the default), |
| | 213 | then Magma is started with the -n option which |
| 214 | 214 | supresses user configuration files. |
| 215 | 215 | |
| 216 | 216 | EXAMPLES: |
| … |
… |
|
| 476 | 476 | Coerce x into this Magma interpreter interface. |
| 477 | 477 | |
| 478 | 478 | INPUT: |
| 479 | | x -- object |
| 480 | | gens -- string; names of generators of self, separated by commas |
| | 479 | x -- object |
| | 480 | gens -- string; names of generators of self, separated by commas |
| 481 | 481 | |
| 482 | 482 | OUTPUT: |
| 483 | 483 | MagmaElement |
| … |
… |
|
| 502 | 502 | True |
| 503 | 503 | sage: a.parent() is m # optional - magma |
| 504 | 504 | False |
| | 505 | |
| | 506 | We test caching: |
| | 507 | sage: R.<x> = ZZ[] # optional - magma |
| | 508 | sage: magma(R) is magma(R) # optional - magma |
| | 509 | True |
| | 510 | sage: m = Magma() # optional - magma |
| | 511 | sage: m(R) # optional - magma |
| | 512 | Univariate Polynomial Ring in x over Integer Ring |
| | 513 | sage: m(R) is magma(R) # optional - magma |
| | 514 | False |
| | 515 | sage: R._magma_cache # optional - magma |
| | 516 | {Magma: Univariate Polynomial Ring in x over Integer Ring, |
| | 517 | Magma: Univariate Polynomial Ring in x over Integer Ring} |
| 505 | 518 | """ |
| 506 | | if gens is None: |
| 507 | | if isinstance(x, bool): |
| 508 | | return Expect.__call__(self, str(x).lower()) |
| 509 | | return Expect.__call__(self, x) |
| 510 | | return self.objgens(x, gens) |
| 511 | | |
| | 519 | if isinstance(x, bool): |
| | 520 | return Expect.__call__(self, 'true' if x else 'false') |
| | 521 | |
| | 522 | if gens is not None: # get rid of this at some point -- it's weird |
| | 523 | return self.objgens(x, gens) |
| | 524 | |
| | 525 | # This is mostly about caching the Magma element in the object |
| | 526 | # itself below. Note that it is *very* important that caching |
| | 527 | # happen on the object itself, and not in a dictionary that is |
| | 528 | # held by the Magma interface, since we want garbage collection |
| | 529 | # of the objects in the Magma interface to work correctly. |
| | 530 | has_cache = hasattr(x, '_magma_cache') |
| | 531 | try: |
| | 532 | if has_cache and x._magma_cache.has_key(self): |
| | 533 | A = x._magma_cache[self] |
| | 534 | if A._session_number == self._session_number: |
| | 535 | return A |
| | 536 | except AttributeError: |
| | 537 | # This happens when x has _magma_cache as a cdef public object attribute. |
| | 538 | x._magma_cache = {} |
| | 539 | A = Expect.__call__(self, x) |
| | 540 | if has_cache: |
| | 541 | x._magma_cache[self] = A |
| | 542 | else: |
| | 543 | try: # use try/except here, because if x is cdef'd we won't be able to set this. |
| | 544 | x._magma_cache = {self:A} |
| | 545 | except AttributeError, msg: |
| | 546 | pass |
| | 547 | return A |
| | 548 | |
| | 549 | |
| | 550 | def _coerce_from_special_method(self, x): |
| | 551 | """ |
| | 552 | Tries to coerce to self by calling a special underscore method. |
| | 553 | |
| | 554 | If no such method is defined, raises an AttributeError |
| | 555 | instead of a TypeError. |
| | 556 | """ |
| | 557 | try: |
| | 558 | return x._magma_(self) |
| | 559 | except AttributeError: |
| | 560 | return self(x._magma_init_(self)) |
| | 561 | |
| 512 | 562 | def clear(self, var): |
| 513 | 563 | """ |
| 514 | 564 | Clear the variable named var and make it available |
| … |
… |
|
| 593 | 643 | |
| 594 | 644 | def attach(self, filename): |
| 595 | 645 | r""" |
| 596 | | Attach the given file to the running instance of MAGMA. |
| | 646 | Attach the given file to the running instance of Magma. |
| 597 | 647 | |
| 598 | | Attaching a file in MAGMA makes all intrinsics defined in the |
| | 648 | Attaching a file in Magma makes all intrinsics defined in the |
| 599 | 649 | file available to the shell. Moreover, if the file doesn't |
| 600 | 650 | start with the \code{freeze;} command, then the file is |
| 601 | 651 | reloaded whenever it is changed. Note that functions and |
| … |
… |
|
| 645 | 695 | def load(self, filename): |
| 646 | 696 | """ |
| 647 | 697 | Load the file with given filename using the 'load' command |
| 648 | | in the MAGMA shell. |
| | 698 | in the Magma shell. |
| 649 | 699 | |
| 650 | | Loading a file in MAGMA makes all the functions and procedures |
| | 700 | Loading a file in Magma makes all the functions and procedures |
| 651 | 701 | in the file available. The file should not contain any |
| 652 | 702 | intrinsics (or you'll get errors). It also runs code in the |
| 653 | 703 | file, which can produce output. |
| … |
… |
|
| 693 | 743 | try: |
| 694 | 744 | self.eval('Append(~_sage_, 0);') |
| 695 | 745 | except: |
| 696 | | # this exception could happen if the MAGMA process |
| | 746 | # this exception could happen if the Magma process |
| 697 | 747 | # was interrupted during startup / initialization. |
| 698 | 748 | self.eval('_sage_ := [* 0 : i in [1..%s] *];'%self.__seq) |
| 699 | 749 | if len(self.__available_var) > 0: |
| … |
… |
|
| 861 | 911 | """ |
| 862 | 912 | return MagmaElement |
| 863 | 913 | |
| 864 | | # Usually "Sequences" are what you want in MAGMA, not "lists". |
| | 914 | # Usually "Sequences" are what you want in Magma, not "lists". |
| 865 | 915 | # It's very painful using the interface without this. |
| 866 | 916 | def _left_list_delim(self): |
| 867 | 917 | """ |
| … |
… |
|
| 1037 | 1087 | except IOError: |
| 1038 | 1088 | pass |
| 1039 | 1089 | if verbose: |
| 1040 | | print "\nCreating list of all MAGMA intrinsics for use in tab completion." |
| | 1090 | print "\nCreating list of all Magma intrinsics for use in tab completion." |
| 1041 | 1091 | print "This takes a few minutes the first time, but is saved to the" |
| 1042 | 1092 | print "file '%s' for future instant use."%INTRINSIC_CACHE |
| 1043 | | print "MAGMA may produce errors during this process, which are safe to ignore." |
| | 1093 | print "Magma may produce errors during this process, which are safe to ignore." |
| 1044 | 1094 | print "Delete that file to force recreation of this cache." |
| 1045 | | print "Scanning MAGMA types ..." |
| | 1095 | print "Scanning Magma types ..." |
| 1046 | 1096 | tm = sage.misc.misc.cputime() |
| 1047 | 1097 | T = self.eval('ListTypes()').split() |
| 1048 | 1098 | N = [] |
| … |
… |
|
| 1055 | 1105 | for x in s.split('\n'): |
| 1056 | 1106 | i = x.find('(') |
| 1057 | 1107 | N.append(x[:i]) |
| 1058 | | except RuntimeError, msg: # weird internal problems in MAGMA type system |
| | 1108 | except RuntimeError, msg: # weird internal problems in Magma type system |
| 1059 | 1109 | print 'Error -- %s'%msg |
| 1060 | 1110 | pass |
| 1061 | 1111 | if verbose: |
| … |
… |
|
| 1070 | 1120 | |
| 1071 | 1121 | def ideal(self, L): |
| 1072 | 1122 | """ |
| 1073 | | Return the MAGMA ideal defined by L. |
| | 1123 | Return the Magma ideal defined by L. |
| 1074 | 1124 | |
| 1075 | 1125 | INPUT: |
| 1076 | 1126 | L -- a list of elements of a SAGE multivariate polynomial ring. |
| … |
… |
|
| 1091 | 1141 | ] |
| 1092 | 1142 | """ |
| 1093 | 1143 | P = iter(L).next().parent() |
| 1094 | | Pn = P._magma_().name() |
| | 1144 | Pn = self(P).name() |
| 1095 | 1145 | k = P.base_ring() |
| 1096 | 1146 | if k.degree() > 1: |
| 1097 | 1147 | i = str(k.gen()) |
| … |
… |
|
| 1477 | 1527 | [$.1] |
| 1478 | 1528 | """ |
| 1479 | 1529 | try: |
| 1480 | | return self.__gens |
| | 1530 | return self._magma_gens |
| 1481 | 1531 | except AttributeError: |
| 1482 | 1532 | pass |
| 1483 | 1533 | G = [] |
| … |
… |
|
| 1490 | 1540 | except (RuntimeError, TypeError): |
| 1491 | 1541 | break |
| 1492 | 1542 | i += 1 |
| 1493 | | self.__gens = G |
| | 1543 | self._magma_gens = G |
| 1494 | 1544 | return G |
| | 1545 | |
| | 1546 | def gen_names(self): |
| | 1547 | """ |
| | 1548 | Return list of Magma variable names of the generators of self. |
| | 1549 | |
| | 1550 | NOTE: As illustrated below, these are not the print names of |
| | 1551 | the the generators of the Magma object, but special variable |
| | 1552 | names in the Magma session that reference the generators. |
| | 1553 | |
| | 1554 | EXAMPLES: |
| | 1555 | sage: R.<x,zw> = QQ[] |
| | 1556 | sage: S = magma(R) # optional - magma |
| | 1557 | sage: S.gen_names() # optional - magma |
| | 1558 | ('_sage_[...]', '_sage_[...]') |
| | 1559 | sage: magma(S.gen_names()[1]) |
| | 1560 | zw |
| | 1561 | """ |
| | 1562 | try: |
| | 1563 | return self.__gen_names |
| | 1564 | except AttributeError: |
| | 1565 | self.__gen_names = tuple([x.name() for x in self.gens()]) |
| | 1566 | return self.__gen_names |
| 1495 | 1567 | |
| 1496 | 1568 | def evaluate(self, *args): |
| 1497 | 1569 | """ |
| … |
… |
|
| 1818 | 1890 | Quotient of division of self by other. This is denoted // ("div" in magma). |
| 1819 | 1891 | |
| 1820 | 1892 | EXAMPLE: |
| 1821 | | sage: R.<x,y,z>=QQ[] |
| 1822 | | sage: magma(5)//magma(2) # optional - magma |
| | 1893 | sage: R.<x,y,z> = QQ[] |
| | 1894 | sage: magma(5)//magma(2) # optional - magma |
| 1823 | 1895 | 2 |
| 1824 | | sage: m=magma(x*z+x*y) # optional - magma |
| 1825 | | sage: n=magma(x) # optional - magma |
| 1826 | | sage: m//n # optional - magma |
| | 1896 | sage: m = magma(x*z + x*y) # optional - magma |
| | 1897 | sage: n = magma(x) # optional - magma |
| | 1898 | sage: m//n # optional - magma |
| 1827 | 1899 | y + z |
| 1828 | 1900 | """ |
| 1829 | 1901 | return self.parent()('%s div %s'%(self.name(), x.name())) |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix1.pyx
|
a
|
b
|
|
| 220 | 220 | [ zeta9 zeta9^4 zeta9 - 1] |
| 221 | 221 | [-zeta9^5 - zeta9^2 1 0] |
| 222 | 222 | sage: magma(M) # optional - magma |
| 223 | | [ 0 1 3] |
| 224 | | [ zeta_9 zeta_9^4 zeta_9 - 1] |
| 225 | | [-zeta_9^5 - zeta_9^2 1 0] |
| | 223 | [ 0 1 3] |
| | 224 | [ zeta9 zeta9^4 zeta9 - 1] |
| | 225 | [-zeta9^5 - zeta9^2 1 0] |
| 226 | 226 | sage: magma(M**2) == magma(M)**2 # optional - magma |
| 227 | 227 | True |
| 228 | 228 | """ |
| … |
… |
|
| 233 | 233 | s = 'RMatrixSpace(%s, %s, %s)'%(K.name(), self.nrows(), self.ncols()) |
| 234 | 234 | v = [] |
| 235 | 235 | for x in self.list(): |
| 236 | | v.append(x._magma_init_()) |
| | 236 | v.append(x._magma_init_(magma)) |
| 237 | 237 | return magma(s + '![%s]'%(','.join(v))) |
| 238 | 238 | |
| 239 | 239 | def _maple_init_(self): |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix_mod2_dense.pyx
|
a
|
b
|
|
| 1128 | 1128 | |
| 1129 | 1129 | |
| 1130 | 1130 | |
| 1131 | | def _magma_init_(self): |
| | 1131 | def _magma_init_(self, magma): |
| 1132 | 1132 | r""" |
| 1133 | 1133 | Returns a string of self in \Magma form. Does not return \Magma |
| 1134 | 1134 | object but string. |
| 1135 | 1135 | |
| 1136 | 1136 | EXAMPLE: |
| 1137 | 1137 | sage: A = random_matrix(GF(2),3,3) |
| 1138 | | sage: A._magma_init_() # optional - magma |
| | 1138 | sage: A._magma_init_(magma) # optional - magma |
| 1139 | 1139 | 'MatrixAlgebra(GF(2), 3)![0,1,0,0,1,1,0,0,0]' |
| 1140 | 1140 | sage: A = random_matrix(GF(2),100,100) |
| 1141 | 1141 | sage: B = random_matrix(GF(2),100,100) |
| … |
… |
|
| 1148 | 1148 | Matrix with 0 rows and 3 columns |
| 1149 | 1149 | """ |
| 1150 | 1150 | cdef int i,j |
| 1151 | | K = self._base_ring._magma_init_() |
| | 1151 | K = self._base_ring._magma_init_(magma) |
| 1152 | 1152 | if self._nrows == self._ncols: |
| 1153 | 1153 | s = 'MatrixAlgebra(%s, %s)'%(K, self.nrows()) |
| 1154 | 1154 | else: |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix_modn_dense.pyx
|
a
|
b
|
|
| 1537 | 1537 | raise IndexError, "matrix window index out of range" |
| 1538 | 1538 | return matrix_window_modn_dense.MatrixWindow_modn_dense(self, row, col, nrows, ncols) |
| 1539 | 1539 | |
| 1540 | | def _magma_init_(self): |
| | 1540 | def _magma_init_(self, magma): |
| 1541 | 1541 | """ |
| 1542 | | Returns a string of self in MAGMA form. |
| | 1542 | Returns a string representation of self in Magma form. |
| 1543 | 1543 | |
| 1544 | | NOTE: Does not return MAGMA object but string. |
| | 1544 | INPUT: |
| | 1545 | magma -- a Magma session |
| | 1546 | OUTPUT: |
| | 1547 | string |
| 1545 | 1548 | """ |
| 1546 | 1549 | cdef int i,j |
| 1547 | | K = self._base_ring._magma_init_() |
| | 1550 | K = self._base_ring._magma_init_(magma) |
| 1548 | 1551 | if self._nrows == self._ncols: |
| 1549 | 1552 | s = 'MatrixAlgebra(%s, %s)'%(K, self.nrows()) |
| 1550 | 1553 | else: |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix_space.py
|
a
|
b
|
|
| 1086 | 1086 | Z.randomize(density, *args, **kwds) |
| 1087 | 1087 | return Z |
| 1088 | 1088 | |
| 1089 | | def _magma_init_(self): |
| | 1089 | def _magma_init_(self, magma): |
| 1090 | 1090 | r""" |
| 1091 | 1091 | EXAMPLES: |
| 1092 | 1092 | We first coerce a square matrix. |
| … |
… |
|
| 1096 | 1096 | sage: magma(MatrixSpace(Integers(8),2,3)) # optional - magma |
| 1097 | 1097 | Full RMatrixSpace of 2 by 3 matrices over IntegerRing(8) |
| 1098 | 1098 | """ |
| 1099 | | K = self.base_ring()._magma_init_() |
| | 1099 | K = self.base_ring()._magma_init_(magma) |
| 1100 | 1100 | if self.__nrows == self.__ncols: |
| 1101 | 1101 | s = 'MatrixAlgebra(%s, %s)'%(K, self.__nrows) |
| 1102 | 1102 | else: |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/finite_field_element.py
|
a
|
b
|
|
| 414 | 414 | def _pari_init_(self): |
| 415 | 415 | return str(self.__value) |
| 416 | 416 | |
| 417 | | def _magma_init_(self): |
| | 417 | def _magma_init_(self, magma): |
| 418 | 418 | """ |
| 419 | 419 | Return a string representation of self that Magma can understand. |
| 420 | 420 | |
| 421 | 421 | EXAMPLES: |
| 422 | | sage: GF(7)(3)._magma_init_() # optional - magma |
| | 422 | sage: GF(7)(3)._magma_init_(magma) # optional - magma |
| 423 | 423 | 'GF(7)!3' |
| 424 | 424 | """ |
| 425 | | km = self.parent()._magma_() |
| | 425 | km = magma(self.parent()) |
| 426 | 426 | vn = km.gen(1).name() |
| 427 | 427 | return ("%s"%(self.__value.lift().lift())).replace('a',vn) |
| 428 | 428 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/finite_field_givaro.pyx
|
a
|
b
|
|
| 1884 | 1884 | """ |
| 1885 | 1885 | return pari(self._pari_init_(var)) |
| 1886 | 1886 | |
| 1887 | | def _magma_init_(self): |
| | 1887 | def _magma_init_(self, magma): |
| 1888 | 1888 | """ |
| 1889 | 1889 | Return a string representation of self that MAGMA can |
| 1890 | 1890 | understand. |
| 1891 | 1891 | |
| 1892 | 1892 | EXAMPLE: |
| 1893 | 1893 | sage: k.<a> = GF(3^5) |
| 1894 | | sage: k._magma_init_() # optional - magma |
| | 1894 | sage: k._magma_init_(magma) # optional - magma |
| 1895 | 1895 | 'ext< GF(3) | Polynomial(GF(3), [GF(3)!1,GF(3)!2,GF(3)!0,GF(3)!0,GF(3)!0,GF(3)!1]) >' |
| 1896 | 1896 | """ |
| 1897 | | km = self.parent()._magma_() |
| | 1897 | km = magma(self.parent()) |
| 1898 | 1898 | vn = km.gen(1).name() |
| 1899 | | return self.parent()._element_poly_repr(self,vn) |
| | 1899 | return self.parent()._element_poly_repr(self, vn) |
| 1900 | 1900 | |
| 1901 | 1901 | def multiplicative_order(FiniteField_givaroElement self): |
| 1902 | 1902 | """ |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/finite_field_ntl_gf2e.pyx
|
a
|
b
|
|
| 1245 | 1245 | o *= g |
| 1246 | 1246 | return ret |
| 1247 | 1247 | |
| 1248 | | def _magma_init_(self): |
| | 1248 | def _magma_init_(self, magma): |
| 1249 | 1249 | r""" |
| 1250 | 1250 | Return a string representation of self that \MAGMA can |
| 1251 | 1251 | understand. |
| 1252 | 1252 | |
| 1253 | 1253 | EXAMPLE: |
| 1254 | 1254 | sage: k.<a> = GF(2^16) |
| 1255 | | sage: a._magma_init_() # random; optional - magma |
| | 1255 | sage: a._magma_init_(magma) # random; optional - magma |
| 1256 | 1256 | '_sage_[2]' |
| 1257 | 1257 | |
| 1258 | 1258 | NOTE: This method calls \MAGMA to setup the parent. |
| 1259 | 1259 | """ |
| 1260 | | km = self.parent()._magma_() |
| | 1260 | km = magma(self.parent()) |
| 1261 | 1261 | vn_m = km.gen(1).name() |
| 1262 | 1262 | vn_s = str(self.parent().polynomial_ring().gen()) |
| 1263 | 1263 | return str(self.polynomial()).replace(vn_s,vn_m) |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/fraction_field.py
|
a
|
b
|
|
| 195 | 195 | return "\\mbox{\\rm Frac}(%s)"%latex.latex(self.ring()) |
| 196 | 196 | |
| 197 | 197 | __magma = None |
| 198 | | def _magma_init_(self): |
| | 198 | def _magma_init_(self, magma): |
| 199 | 199 | """ |
| 200 | 200 | Return a string representation of self Magma can understand. |
| 201 | 201 | |
| 202 | 202 | EXAMPLES: |
| 203 | | sage: QQ['x'].fraction_field()._magma_init_() # optional - magma |
| | 203 | sage: QQ['x'].fraction_field()._magma_init_(magma) # optional - magma |
| 204 | 204 | 'FieldOfFractions(PolynomialRing(RationalField()))' |
| 205 | 205 | """ |
| 206 | 206 | if self.__magma: |
| 207 | 207 | return self.__magma |
| 208 | | B = self.ring()._magma_init_() |
| | 208 | B = self.ring()._magma_init_(magma) |
| 209 | 209 | return "FieldOfFractions(%s)"%B |
| 210 | 210 | |
| 211 | 211 | def _magma_(self, magma = None): |
| … |
… |
|
| 223 | 223 | import sage.interfaces.magma |
| 224 | 224 | magma = sage.interfaces.magma.magma |
| 225 | 225 | if self.__magma is None: |
| 226 | | s = self._magma_init_() |
| | 226 | s = self._magma_init_(magma) |
| 227 | 227 | F = magma(s) |
| 228 | 228 | F.assign_names(self.variable_names()) |
| 229 | 229 | self.__magma = F |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/fraction_field_element.py
|
a
|
b
|
|
| 349 | 349 | return "\\frac{%s}{%s}"%(latex.latex(self.__numerator), |
| 350 | 350 | latex.latex(self.__denominator)) |
| 351 | 351 | |
| 352 | | def _magma_init_(self): |
| | 352 | def _magma_init_(self, magma): |
| 353 | 353 | """ |
| 354 | 354 | Return a string representation of self Magma can understand. |
| 355 | 355 | |
| … |
… |
|
| 362 | 362 | sage: magma((x+y)/x) # optional - magma |
| 363 | 363 | (x + y)/x |
| 364 | 364 | """ |
| 365 | | pgens = self.parent()._magma_().gens() |
| | 365 | pgens = magma(self.parent()).gens() |
| 366 | 366 | |
| 367 | 367 | s = self._repr_() |
| 368 | 368 | for i, j in zip(self.parent().variable_names(), pgens): |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/integer_mod.pyx
|
a
|
b
|
|
| 350 | 350 | n = self.log(R(g)) |
| 351 | 351 | return 'Z(%s)^%s'%(m, n) |
| 352 | 352 | |
| 353 | | def _magma_init_(self): |
| | 353 | def _magma_init_(self, magma): |
| 354 | 354 | """ |
| 355 | 355 | Coercion to Magma. |
| 356 | 356 | |
| … |
… |
|
| 362 | 362 | sage: b^2 # optional - magma |
| 363 | 363 | 1 |
| 364 | 364 | """ |
| 365 | | return '%s!%s'%(self.parent()._magma_init_(), self) |
| | 365 | return '%s!%s'%(self.parent()._magma_init_(magma), self) |
| 366 | 366 | |
| 367 | 367 | def _sage_input_(self, sib, coerced): |
| 368 | 368 | r""" |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/integer_mod_ring.py
|
a
|
b
|
|
| 898 | 898 | """ |
| 899 | 899 | return 'ZmodnZ(%s)'%self.order() |
| 900 | 900 | |
| 901 | | def _magma_init_(self): |
| | 901 | def _magma_init_(self, magma): |
| 902 | 902 | """ |
| 903 | 903 | EXAMPLES: |
| 904 | 904 | sage: R = Integers(12345678900) |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/integer_ring.pyx
|
a
|
b
|
|
| 840 | 840 | """ |
| 841 | 841 | return 'Integers' |
| 842 | 842 | |
| 843 | | def _magma_init_(self): |
| | 843 | def _magma_init_(self, magma): |
| 844 | 844 | """ |
| 845 | 845 | EXAMPLES: |
| 846 | 846 | sage: magma(ZZ) # optional - magma |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/number_field/number_field.py
|
a
|
b
|
|
| 5472 | 5472 | """ |
| 5473 | 5473 | return NumberField_cyclotomic_v1, (self.__n, self.variable_name()) |
| 5474 | 5474 | |
| 5475 | | def _magma_init_(self): |
| | 5475 | def _magma_init_(self, magma): |
| 5476 | 5476 | # TODO: I really don't like this on multiple levels. |
| 5477 | 5477 | # (1) it kills a global symbol self.gen() |
| 5478 | 5478 | # (2) it abuses how conversion works and throws in an extra define. |
| … |
… |
|
| 5489 | 5489 | |
| 5490 | 5490 | EXAMPLES: |
| 5491 | 5491 | sage: K=CyclotomicField(7,'z') |
| 5492 | | sage: K._magma_init_() # optional - magma |
| | 5492 | sage: K._magma_init_(magma) # optional - magma |
| 5493 | 5493 | 'CyclotomicField(7); z:=CyclotomicField(7).1;' |
| 5494 | 5494 | sage: K=CyclotomicField(7,'zeta') |
| 5495 | | sage: K._magma_init_() # optional - magma |
| | 5495 | sage: K._magma_init_(magma) # optional - magma |
| 5496 | 5496 | 'CyclotomicField(7); zeta:=CyclotomicField(7).1;' |
| 5497 | 5497 | """ |
| 5498 | 5498 | return 'CyclotomicField(%s); %s:=CyclotomicField(%s).1;'%(self.__n, self.gen(), self.__n) |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/number_field/number_field_element.pyx
|
a
|
b
|
|
| 1820 | 1820 | self.__pari[var] = h |
| 1821 | 1821 | return h |
| 1822 | 1822 | |
| 1823 | | def _magma_(self, magma): |
| | 1823 | def _magma_init_(self, magma): |
| 1824 | 1824 | """ |
| 1825 | 1825 | Return Magma version of this number field element. |
| 1826 | 1826 | |
| … |
… |
|
| 1832 | 1832 | |
| 1833 | 1833 | EXAMPLES: |
| 1834 | 1834 | sage: K.<a> = NumberField(x^3 + 2) |
| 1835 | | sage: magma((2/3)*a^2 - 17/3) # optional -- requires magma |
| | 1835 | sage: a._magma_init_(magma) # optional - magma |
| | 1836 | '(_sage_[...]![0, 1, 0])' |
| | 1837 | sage: magma((2/3)*a^2 - 17/3) # optional - magma |
| 1836 | 1838 | 1/3*(2*a^2 - 17) |
| | 1839 | |
| | 1840 | An element of a cyclotomic field. |
| | 1841 | sage: K = CyclotomicField(9) |
| | 1842 | sage: K.gen() |
| | 1843 | zeta9 |
| | 1844 | sage: K.gen()._magma_init_(magma) |
| | 1845 | '(_sage_[...]![0, 1, 0, 0, 0, 0])' |
| | 1846 | sage: magma(K.gen()) |
| | 1847 | zeta9 |
| 1837 | 1848 | """ |
| 1838 | 1849 | K = magma(self.parent()) |
| 1839 | | return K(self.list()) |
| | 1850 | return '(%s!%s)'%(K.name(), self.list()) |
| 1840 | 1851 | |
| 1841 | 1852 | cdef void _parent_poly_c_(self, ZZX_c *num, ZZ_c *den): |
| 1842 | 1853 | """ |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial.pyx
|
a
|
b
|
|
| 662 | 662 | P = P.change_ring(R) |
| 663 | 663 | return P(self) |
| 664 | 664 | |
| 665 | | def _magma_init_(self): |
| | 665 | def _magma_init_(self, magma): |
| 666 | 666 | """ |
| 667 | | Returns the MAGMA representation of self. |
| | 667 | Returns a Magma string representation of self valid in the |
| | 668 | given magma session. |
| 668 | 669 | |
| 669 | 670 | EXAMPLES: |
| 670 | 671 | sage: R.<x,y> = GF(2)[] |
| 671 | 672 | sage: f = y*x^2 + x +1 |
| 672 | | sage: f._magma_init_() # optional - magma |
| 673 | | '_sage_[3]^2*_sage_[4] + _sage_[3] + 1' |
| | 673 | sage: f._magma_init_(magma) # optional - magma |
| | 674 | '(GF(2)!1)*_sage_[...]^2*_sage_[...]+(GF(2)!1)*_sage_[...]+(GF(2)!1)*1' |
| | 675 | |
| | 676 | A more complicated nested example: |
| | 677 | sage: R.<x,y> = QQ[]; S.<z,w> = R[]; f = (2/3)*x^3*z + w^2 + 5 |
| | 678 | sage: f._magma_init_(magma) # optional - magma |
| | 679 | '((1/1)*1)*_sage_[...]^2+((2/3)*_sage_[...]^3)*_sage_[...]+((5/1)*1)*1' |
| | 680 | sage: magma(f) # optional - magma |
| | 681 | w^2 + 2/3*x^3*z + 5 |
| 674 | 682 | """ |
| 675 | | return self._repr_with_changed_varnames(self.parent()._magma_gens()) |
| | 683 | g = magma(self.parent()).gen_names() |
| | 684 | v = [] |
| | 685 | for m, c in zip(self.monomials(), self.coefficients()): |
| | 686 | v.append('(%s)*%s'%( c._magma_init_(magma), |
| | 687 | m._repr_with_changed_varnames(g))) |
| | 688 | return '+'.join(v) |
| | 689 | |
| 676 | 690 | |
| 677 | 691 | def gradient(self): |
| 678 | 692 | r""" |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial_ideal.py
|
a
|
b
|
|
| 359 | 359 | EXAMPLES: |
| 360 | 360 | sage: R.<a,b,c,d,e,f,g,h,i,j> = PolynomialRing(GF(127),10) |
| 361 | 361 | sage: I = sage.rings.ideal.Cyclic(R,4) |
| 362 | | sage: I._magma_() # optional - magma |
| | 362 | sage: magma(I) # optional - magma |
| 363 | 363 | Ideal of Polynomial ring of rank 10 over GF(127) |
| 364 | 364 | Graded Reverse Lexicographical Order |
| 365 | 365 | Variables: a, b, c, d, e, f, g, h, i, j |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial_ring_generic.pxd
|
a
|
b
|
|
| 7 | 7 | cdef object __ngens |
| 8 | 8 | cdef object __term_order |
| 9 | 9 | cdef object _has_singular |
| 10 | | cdef object __magma |
| 11 | | cdef object __magma_gens |
| | 10 | cdef public object _magma_gens, _magma_cache |
| 12 | 11 | |
| 13 | 12 | cdef _coerce_c_impl(self, x) |
| 14 | 13 | cdef int _cmp_c_impl(left, Parent right) except -2 |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial_ring_generic.pyx
|
a
|
b
|
|
| 250 | 250 | return False |
| 251 | 251 | return True |
| 252 | 252 | |
| 253 | | def _magma_(self, magma=None): |
| | 253 | def _magma_convert_(self, magma=None): |
| 254 | 254 | """ |
| 255 | 255 | Used in converting this ring to the corresponding ring in MAGMA. |
| 256 | 256 | |
| … |
… |
|
| 276 | 276 | Graded Reverse Lexicographical Order |
| 277 | 277 | Variables: x0, x1, x2 |
| 278 | 278 | """ |
| 279 | | if magma == None: |
| 280 | | import sage.interfaces.magma |
| 281 | | magma = sage.interfaces.magma.magma |
| 282 | | |
| 283 | | try: |
| 284 | | if self.__magma is None: |
| 285 | | raise AttributeError |
| 286 | | m = self.__magma |
| 287 | | m._check_valid() |
| 288 | | if not m.parent() is magma: |
| 289 | | raise ValueError |
| 290 | | return m |
| 291 | | except (AttributeError,ValueError): |
| 292 | | B = magma(self.base_ring()) |
| 293 | | R = magma('PolynomialRing(%s, %s, %s)'%(B.name(), self.ngens(),self.term_order().magma_str())) |
| 294 | | R.assign_names(self.variable_names()) |
| 295 | | self.__magma = R |
| 296 | | self.__magma_gens = [e.name() for e in R.gens()] |
| 297 | | return R |
| | 279 | B = magma(self.base_ring()) |
| | 280 | R = magma('PolynomialRing(%s, %s, %s)'%(B.name(), self.ngens(), self.term_order().magma_str())) |
| | 281 | R.assign_names(self.variable_names()) |
| | 282 | return R |
| 298 | 283 | |
| 299 | | def _magma_gens(self): |
| | 284 | def _magma_init_(self, magma): |
| 300 | 285 | """ |
| 301 | | Returns a list with names of Magma representations of the generators |
| 302 | | of this ring. |
| 303 | | |
| 304 | | If a Magma object for this ring has not already been initialized, |
| 305 | | Magma is called first, otherwise cached names are returned. |
| 306 | | |
| 307 | | EXAMPLES: |
| 308 | | sage: R = ZZ['x,y'] |
| 309 | | sage: R._magma_gens() # optional - magma |
| 310 | | ['_sage_[3]', '_sage_[4]'] |
| 311 | | |
| 312 | | """ |
| 313 | | if self.__magma_gens is None or not self.__magma._check_valid(): |
| 314 | | self._magma_() |
| 315 | | return self.__magma_gens |
| 316 | | |
| 317 | | def _magma_init_(self): |
| 318 | | """ |
| 319 | | Return a string representation of self MAGMA can understand. |
| | 286 | Return a string representation of self Magma can understand. |
| | 287 | Used in conversion of self to Magma. |
| 320 | 288 | """ |
| 321 | 289 | try: # we need that for GF(q) arithmetic |
| 322 | | B = self.base_ring()._magma_().name() |
| | 290 | B = magma(self.base_ring()).name() |
| 323 | 291 | except (RuntimeError,TypeError): |
| 324 | | B = self.base_ring()._magma_init_() |
| | 292 | B = self.base_ring()._magma_init_(magma) |
| 325 | 293 | R = 'PolynomialRing(%s, %s, %s)'%(B, self.ngens(),self.term_order().magma_str()) |
| 326 | 294 | return R |
| 327 | 295 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/pbori.pxd
|
a
|
b
|
|
| 12 | 12 | cdef Py_ssize_t* pbind |
| 13 | 13 | cdef public _monom_monoid |
| 14 | 14 | cdef public object __interface |
| | 15 | |
| | 16 | # it is very important to keep this cached, since otherwise the magma interface will break |
| | 17 | cdef public object __cover_ring |
| 15 | 18 | |
| 16 | 19 | cdef class BooleanPolynomial(MPolynomial): |
| 17 | 20 | cdef PBPoly _pbpoly |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/pbori.pyx
|
a
|
b
|
|
| 935 | 935 | |
| 936 | 936 | sage: B.term_order() == R.term_order() |
| 937 | 937 | True |
| 938 | | """ |
| 939 | | return PolynomialRing(GF(2),self.ngens(),self.variable_names(),order=self.term_order()) |
| | 938 | |
| | 939 | The cover ring is cached: |
| | 940 | sage: B.cover_ring() is B.cover_ring() |
| | 941 | True |
| | 942 | """ |
| | 943 | if self.__cover_ring is not None: |
| | 944 | return self.__cover_ring |
| | 945 | R = PolynomialRing(GF(2), self.ngens(), |
| | 946 | self.variable_names(), order=self.term_order()) |
| | 947 | self.__cover_ring = R |
| | 948 | return R |
| | 949 | |
| 940 | 950 | |
| 941 | 951 | def defining_ideal(self): |
| 942 | 952 | r""" |
| … |
… |
|
| 976 | 986 | """ |
| 977 | 987 | return self.cover_ring().quo( self.defining_ideal() )._singular_init_() |
| 978 | 988 | |
| 979 | | def _magma_(self, magma=None): |
| 980 | | r""" |
| 981 | | Return a \Magma representation of this boolean polynomial ring. |
| 982 | | |
| 983 | | INPUT: |
| 984 | | magma -- a magma instance (default: default instance) |
| 985 | | |
| 986 | | EXAMPLE: |
| 987 | | sage: B.<x,y,z> = BooleanPolynomialRing(3) |
| 988 | | sage: B._magma_() # optional - magma |
| | 989 | def _magma_init_(self, magma): |
| | 990 | r""" |
| | 991 | Return a a string which when evaluated with Magma returns a |
| | 992 | Magma representaion of this boolean polynomial ring. |
| | 993 | |
| | 994 | INPUT: |
| | 995 | magma -- a magma instance |
| | 996 | |
| | 997 | EXAMPLE: |
| | 998 | sage: B.<x,y,z> = BooleanPolynomialRing(3) |
| | 999 | sage: magma(B) # indirect doctest; optional - magma |
| 989 | 1000 | Affine Algebra of rank 3 over GF(2) |
| 990 | 1001 | Lexicographical Order |
| 991 | 1002 | Variables: x, y, z |
| … |
… |
|
| 996 | 1007 | z^2 + z |
| 997 | 1008 | ] |
| 998 | 1009 | """ |
| 999 | | |
| 1000 | | if magma is None: |
| 1001 | | import sage.interfaces.magma |
| 1002 | | magma = sage.interfaces.magma.magma |
| 1003 | | |
| 1004 | | try: |
| 1005 | | m = self.__interface['magma'] |
| 1006 | | m._check_valid() |
| 1007 | | if not m.parent() is magma: |
| 1008 | | raise ValueError |
| 1009 | | return m |
| 1010 | | except (KeyError, ValueError): |
| 1011 | | self.__interface['magma'] = magma(self._magma_init_(magma=magma)) |
| 1012 | | return self.__interface['magma'] |
| 1013 | | |
| 1014 | | def _magma_init_(self, magma=None): |
| 1015 | | r""" |
| 1016 | | Return a a string which when evaluated with \Magma returns a |
| 1017 | | \Magma representaion of this boolean polynomial ring. |
| 1018 | | |
| 1019 | | INPUT: |
| 1020 | | magma -- a magma instance (default: default instance) |
| 1021 | | |
| 1022 | | EXAMPLE: |
| 1023 | | sage: B.<x,y,z> = BooleanPolynomialRing(3) |
| 1024 | | sage: B._magma_() # indirect doctest; optional - magma |
| 1025 | | Affine Algebra of rank 3 over GF(2) |
| 1026 | | Lexicographical Order |
| 1027 | | Variables: x, y, z |
| 1028 | | Quotient relations: |
| 1029 | | [ |
| 1030 | | x^2 + x, |
| 1031 | | y^2 + y, |
| 1032 | | z^2 + z |
| 1033 | | ] |
| 1034 | | |
| 1035 | | NOTE: This method actually calls \Magma. |
| 1036 | | """ |
| 1037 | | if magma is None: |
| 1038 | | import sage.interfaces.magma |
| 1039 | | magma = sage.interfaces.magma.magma |
| 1040 | | |
| 1041 | | R = self.cover_ring()._magma_(magma=magma) |
| 1042 | | vn = [x._magma_().name() for x in self.cover_ring().gens()] |
| 1043 | | return "quo<%s | %s>"%(R.name(), ",".join([f._repr_with_changed_varnames(vn) for f in self.defining_ideal().gens()])) |
| 1044 | | |
| | 1010 | R = magma(self.cover_ring()) |
| | 1011 | v = [z.name() for z in R.gens()] # important to use this because it caches the generators |
| | 1012 | w = [f._repr_with_changed_varnames(v) for f in self.defining_ideal().gens()] |
| | 1013 | return "quo<%s | %s>"%(R.name(), ",".join(w)) |
| | 1014 | |
| | 1015 | def _magma_convert_(self, magma): |
| | 1016 | return magma(self._magma_init_(magma)) |
| | 1017 | |
| | 1018 | def _magma_(self, magma): |
| | 1019 | return magma(self._magma_init_(magma)) |
| | 1020 | |
| 1045 | 1021 | def interpolation_polynomial(self, zeros, ones): |
| 1046 | 1022 | r""" |
| 1047 | 1023 | Return the lexicographically minimal boolean polynomial for |
| … |
… |
|
| 2786 | 2762 | """ |
| 2787 | 2763 | return unpickle_BooleanPolynomial, (self._parent, PBPoly_to_str(&self._pbpoly)) |
| 2788 | 2764 | |
| 2789 | | def _magma_(self, magma=None): |
| | 2765 | def _magma_(self, magma): |
| 2790 | 2766 | r""" |
| 2791 | 2767 | Returns the \MAGMA representation of self. |
| 2792 | 2768 | |
| 2793 | 2769 | EXAMPLES: |
| 2794 | 2770 | sage: R.<x,y> = BooleanPolynomialRing() |
| 2795 | 2771 | sage: f = y*x + x +1 |
| 2796 | | sage: f._magma_() # optional - magma |
| | 2772 | sage: magma(f) # optional - magma |
| 2797 | 2773 | x*y + x + 1 |
| 2798 | 2774 | """ |
| 2799 | | if magma is None: |
| 2800 | | import sage.interfaces.magma |
| 2801 | | magma = sage.interfaces.magma.magma |
| 2802 | | |
| 2803 | | magma_gens = [e.name() for e in self.parent()._magma_().gens()] |
| | 2775 | magma_gens = [e.name() for e in magma(self.parent()).gens()] |
| 2804 | 2776 | f = self._repr_with_changed_varnames(magma_gens) |
| 2805 | 2777 | return magma(f) |
| 2806 | 2778 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/polynomial_element.pyx
|
a
|
b
|
|
| 2831 | 2831 | def _pari_init_(self): |
| 2832 | 2832 | return repr(self._pari_()) |
| 2833 | 2833 | |
| 2834 | | def _magma_init_(self): |
| | 2834 | def _magma_init_(self, magma): |
| 2835 | 2835 | """ |
| 2836 | 2836 | Return a string that evaluates in Magma to this polynomial. |
| 2837 | 2837 | |
| 2838 | 2838 | EXAMPLES: |
| 2839 | 2839 | sage: R.<y> = ZZ[] |
| 2840 | 2840 | sage: f = y^3 - 17*y + 5 |
| 2841 | | sage: f._magma_init_() # optional - magma |
| | 2841 | sage: f._magma_init_(magma) # optional - magma |
| 2842 | 2842 | 'Polynomial(IntegerRing(), [5,-17,0,1])' |
| 2843 | 2843 | """ |
| 2844 | | return 'Polynomial(%s, [%s])'%(self.base_ring()._magma_init_(), ','.join([a._magma_init_() for a in self.list()])) |
| | 2844 | return 'Polynomial(%s, [%s])'%(self.base_ring()._magma_init_(magma), |
| | 2845 | ','.join([a._magma_init_(magma) for a in self.list()])) |
| 2845 | 2846 | |
| 2846 | 2847 | def _magma_convert_(self, G): |
| 2847 | 2848 | """ |
| … |
… |
|
| 2867 | 2868 | y^3 - 17*y + 5 |
| 2868 | 2869 | """ |
| 2869 | 2870 | z = G(self.parent()) # makes sure the indeterminate var name is defined |
| 2870 | | return G(self._magma_init_()) |
| | 2871 | return G(self._magma_init_(G)) |
| 2871 | 2872 | |
| 2872 | 2873 | def _gap_init_(self): |
| 2873 | 2874 | return repr(self) |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/polynomial_element_generic.py
|
a
|
b
|
|
| 715 | 715 | sage: G = f.galois_group(); G # optional - database_gap |
| 716 | 716 | Transitive group number 5 of degree 4 |
| 717 | 717 | sage: G.gens() # optional - database_gap |
| 718 | | ((1,2,3,4), (1,2)) |
| | 718 | [(1,2,3,4), (1,2)] |
| 719 | 719 | sage: G.order() # optional - database_gap |
| 720 | 720 | 24 |
| 721 | 721 | |
| … |
… |
|
| 739 | 739 | Transitive group number 5 of degree 4 |
| 740 | 740 | |
| 741 | 741 | sage: f = x^4 - 17*x^3 - 2*x + 1 |
| 742 | | sage: f.galois_group(algorithm='magma') # optional - magma |
| | 742 | sage: f.galois_group(algorithm='magma') # optional - magma |
| 743 | 743 | Transitive group number 5 of degree 4 |
| 744 | 744 | """ |
| 745 | 745 | from sage.groups.all import PariGroup, PermutationGroup, TransitiveGroup |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/polynomial_ring.py
|
a
|
b
|
|
| 346 | 346 | pass |
| 347 | 347 | raise TypeError |
| 348 | 348 | |
| 349 | | def _magma_(self, G=None): |
| | 349 | def _magma_convert_(self, magma): |
| 350 | 350 | """ |
| 351 | 351 | Used in converting this ring to the corresponding ring in MAGMA. |
| 352 | 352 | |
| … |
… |
|
| 367 | 367 | sage: magma(PolynomialRing(PolynomialRing(ZZ,'w'), 'x')) # optional - magma |
| 368 | 368 | Univariate Polynomial Ring in x over Univariate Polynomial Ring over Integer Ring |
| 369 | 369 | """ |
| 370 | | if G is None: |
| 371 | | import sage.interfaces.magma |
| 372 | | G = sage.interfaces.magma.magma |
| 373 | | R = G(self._magma_init_()) |
| | 370 | R = magma(self._magma_init_(magma)) |
| 374 | 371 | R.assign_names(self.variable_names()) |
| 375 | 372 | return R |
| 376 | 373 | |
| 377 | | def _magma_init_(self): |
| 378 | | return 'PolynomialRing(%s)'%(self.base_ring()._magma_init_()) |
| | 374 | def _magma_init_(self, magma): |
| | 375 | return 'PolynomialRing(%s)'%(self.base_ring()._magma_init_(magma)) |
| 379 | 376 | |
| 380 | 377 | def _gap_(self, G=None): |
| 381 | 378 | """ |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/term_order.py
|
a
|
b
|
|
| 902 | 902 | |
| 903 | 903 | EXAMPLE: |
| 904 | 904 | sage: P = PolynomialRing(GF(127), 10,names='x',order='degrevlex') |
| 905 | | sage: P._magma_() # optional - magma |
| | 905 | sage: magma(P) # optional - magma |
| 906 | 906 | Polynomial ring of rank 10 over GF(127) |
| 907 | 907 | Graded Reverse Lexicographical Order |
| 908 | 908 | Variables: x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/quotient_ring.py
|
a
|
b
|
|
| 644 | 644 | EXAMPLE: |
| 645 | 645 | sage: P.<x,y> = PolynomialRing(GF(2)) |
| 646 | 646 | sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) |
| 647 | | sage: Q._magma_() # optional - magma |
| | 647 | sage: magma(Q) # optional - magma |
| 648 | 648 | Affine Algebra of rank 2 over GF(2) |
| 649 | 649 | Graded Reverse Lexicographical Order |
| 650 | 650 | Variables: x, y |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/quotient_ring_element.py
|
a
|
b
|
|
| 240 | 240 | sage: P.<x,y> = PolynomialRing(GF(2)) |
| 241 | 241 | sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) |
| 242 | 242 | sage: xbar, ybar = Q.gens() |
| 243 | | sage: xbar._magma_() # optional requires magma |
| | 243 | sage: magma(xbar) # optional -- magma |
| 244 | 244 | x |
| 245 | 245 | """ |
| 246 | 246 | if magma is None: |
| 247 | 247 | import sage.interfaces.magma |
| 248 | 248 | magma = sage.interfaces.magma.magma |
| 249 | 249 | |
| 250 | | magma_gens = [e.name() for e in self.parent()._magma_().gens()] |
| | 250 | magma_gens = [e.name() for e in magma(self.parent()).gens()] |
| 251 | 251 | f = self.__rep._repr_with_changed_varnames(magma_gens) |
| 252 | 252 | return magma(f) |
| 253 | 253 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/rational_field.py
|
a
|
b
|
|
| 731 | 731 | """ |
| 732 | 732 | return 'Rationals' |
| 733 | 733 | |
| 734 | | def _magma_init_(self): |
| | 734 | def _magma_init_(self, magma): |
| 735 | 735 | """ |
| 736 | 736 | EXAMPLES: |
| 737 | 737 | sage: magma(QQ) # optional - magma |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/ring.pyx
|
a
|
b
|
|
| 1545 | 1545 | """ |
| 1546 | 1546 | return 'GF(%s)'%self.order() |
| 1547 | 1547 | |
| 1548 | | def _magma_init_(self): |
| | 1548 | def _magma_init_(self, magma): |
| 1549 | 1549 | """ |
| 1550 | 1550 | Return string representation of self that Magma can |
| 1551 | 1551 | understand. |
| 1552 | 1552 | |
| 1553 | 1553 | EXAMPLES: |
| 1554 | | sage: GF(97,'a')._magma_init_() # optional - magma |
| | 1554 | sage: GF(97,'a')._magma_init_(magma) # optional - magma |
| 1555 | 1555 | 'GF(97)' |
| 1556 | | sage: GF(9,'a')._magma_init_() # optional - magma |
| | 1556 | sage: GF(9,'a')._magma_init_(magma) # optional - magma |
| 1557 | 1557 | 'ext< GF(3) | Polynomial(GF(3), [GF(3)!2,GF(3)!2,GF(3)!1]) >' |
| 1558 | 1558 | """ |
| 1559 | 1559 | if self.degree() == 1: |
| 1560 | 1560 | return 'GF(%s)'%self.order() |
| 1561 | 1561 | B = self.base_ring() |
| 1562 | 1562 | p = self.polynomial() |
| 1563 | | return "ext< %s | %s >"%(B._magma_init_(),p._magma_init_()) |
| | 1563 | return "ext< %s | %s >"%(B._magma_init_(magma),p._magma_init_(magma)) |
| 1564 | 1564 | |
| 1565 | 1565 | def _magma_convert_(self, magma): |
| 1566 | 1566 | """ |
| … |
… |
|
| 1572 | 1572 | sage: magma(GF(9,'a')).1 # optional - magma |
| 1573 | 1573 | a |
| 1574 | 1574 | """ |
| 1575 | | K = magma(self._magma_init_()) |
| | 1575 | K = magma(self._magma_init_(magma)) |
| 1576 | 1576 | K.assign_names([self.variable_name()]) |
| 1577 | 1577 | return K |
| 1578 | 1578 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_finite_field.py
|
a
|
b
|
|
| 92 | 92 | self.__pari = pari('ellinit(Mod(1,%s)*%s)'%(F.characteristic(), [b._pari_() for b in self.ainvs()])) |
| 93 | 93 | return self.__pari |
| 94 | 94 | |
| 95 | | def _magma_init_(self): |
| | 95 | def _magma_init_(self, magma): |
| 96 | 96 | """ |
| 97 | 97 | Return a Magma command that creates this curve. |
| 98 | 98 | |
| 99 | 99 | EXAMPLES: |
| 100 | 100 | sage: E = EllipticCurve(GF(41),[2,5]) # optional - magma |
| 101 | | sage: E._magma_init_() # optional - magma |
| | 101 | sage: E._magma_init_(magma) # optional - magma |
| 102 | 102 | 'EllipticCurve([GF(41)|GF(41)!0,GF(41)!0,GF(41)!0,GF(41)!2,GF(41)!5])' |
| 103 | 103 | """ |
| 104 | 104 | k = self.base_ring() |
| 105 | | kmn = k._magma_init_() |
| 106 | | return 'EllipticCurve([%s|%s])'%(kmn,','.join([x._magma_init_() for x in self.ainvs()])) |
| | 105 | kmn = k._magma_init_(magma) |
| | 106 | return 'EllipticCurve([%s|%s])'%(kmn,','.join([x._magma_init_(magma) for x in self.ainvs()])) |
| 107 | 107 | |
| 108 | 108 | def _gp(self): |
| 109 | 109 | """ |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_generic.py
|
a
|
b
|
|
| 290 | 290 | """ |
| 291 | 291 | return 'ellinit([%s])'%(','.join([x._pari_init_() for x in self.ainvs()])) |
| 292 | 292 | |
| 293 | | def _magma_init_(self): |
| | 293 | def _magma_init_(self, magma): |
| 294 | 294 | """ |
| 295 | 295 | Internal function. Returns a string to initialize this |
| 296 | 296 | elliptic curve in the Magma subsystem. |
| 297 | 297 | |
| 298 | 298 | EXAMPLES: |
| 299 | 299 | sage: E = EllipticCurve(QQ,[1,1]) |
| 300 | | sage: E._magma_init_() # optional - magma |
| | 300 | sage: E._magma_init_(magma) # optional - magma |
| 301 | 301 | 'EllipticCurve([0/1,0/1,0/1,1/1,1/1])' |
| 302 | 302 | """ |
| 303 | | return 'EllipticCurve([%s])'%(','.join([x._magma_init_() for x in self.ainvs()])) |
| | 303 | return 'EllipticCurve([%s])'%(','.join([x._magma_init_(magma) for x in self.ainvs()])) |
| 304 | 304 | |
| 305 | 305 | def _symbolic_(self, SR): |
| 306 | 306 | r""" |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_point.py
|
a
|
b
|
|
| 1321 | 1321 | |
| 1322 | 1322 | class EllipticCurvePoint_finite_field(EllipticCurvePoint_field): |
| 1323 | 1323 | |
| 1324 | | def _magma_init_(self): |
| | 1324 | def _magma_init_(self, magma): |
| 1325 | 1325 | """ |
| 1326 | 1326 | Return a string representation of self that MAGMA can |
| 1327 | 1327 | understand. |
| … |
… |
|
| 1329 | 1329 | EXAMPLE: |
| 1330 | 1330 | sage: E = EllipticCurve(GF(17), [1,-1]) |
| 1331 | 1331 | sage: P = E([13, 4]) |
| 1332 | | sage: P._magma_init_() |
| | 1332 | sage: P._magma_init_(magma) |
| 1333 | 1333 | 'EllipticCurve([GF(17)|GF(17)!0,GF(17)!0,GF(17)!0,GF(17)!1,GF(17)!16])![13,4]' |
| 1334 | 1334 | """ |
| 1335 | | E = self.curve()._magma_init_() |
| | 1335 | E = self.curve()._magma_init_(magma) |
| 1336 | 1336 | x,y = self.xy() |
| 1337 | 1337 | return "%s![%s,%s]"%(E,x,y) |
| 1338 | 1338 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_rational_field.py
|
a
|
b
|
|
| 1011 | 1011 | from sage.lfunctions.sympow import sympow |
| 1012 | 1012 | return sympow.analytic_rank(self)[0] |
| 1013 | 1013 | elif algorithm == 'magma': |
| 1014 | | return rings.Integer(self._magma_().AnalyticRank()) |
| | 1014 | from sage.interfaces.all import magma |
| | 1015 | return rings.Integer(magma(self).AnalyticRank()) |
| 1015 | 1016 | elif algorithm == 'all': |
| 1016 | 1017 | S = list(set([self.analytic_rank('cremona'), |
| 1017 | 1018 | self.analytic_rank('rubinstein'), self.analytic_rank('sympow')])) |
| … |
… |
|
| 2379 | 2380 | from sage.lfunctions.all import sympow |
| 2380 | 2381 | m = sympow.modular_degree(self) |
| 2381 | 2382 | elif algorithm == 'magma': |
| 2382 | | m = rings.Integer(self._magma_().ModularDegree()) |
| | 2383 | from sage.interfaces.all import magma |
| | 2384 | m = rings.Integer(magma(self).ModularDegree()) |
| 2383 | 2385 | else: |
| 2384 | 2386 | raise ValueError, "unknown algorithm %s"%algorithm |
| 2385 | 2387 | self.__modular_degree = m |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/structure/element.pyx
|
a
|
b
|
|
| 1591 | 1591 | V = magma(self._parent) |
| 1592 | 1592 | v = [] |
| 1593 | 1593 | for x in self.list(): |
| 1594 | | v.append(x._magma_init_()) |
| | 1594 | v.append(x._magma_init_(magma)) |
| 1595 | 1595 | s = '%s![%s]'%(V.name(), ','.join(v)) |
| 1596 | 1596 | return magma(s) |
| 1597 | 1597 | |
-
diff -r a0b4c7f7ead9 -r 334d17e4247e sage/structure/sage_object.pyx
|
a
|
b
|
|
| 233 | 233 | pass |
| 234 | 234 | except (KeyError, ValueError): |
| 235 | 235 | pass |
| 236 | | if hasattr(self, '_%s_init_'%I.name()): |
| 237 | | s = self.__getattribute__('_%s_init_'%I.name())() |
| 238 | | elif hasattr(self, '_system_init_'): |
| 239 | | s = self._system_init_(I.name()) |
| | 236 | nm = I.name() |
| | 237 | if nm == 'magma': |
| | 238 | s = self._magma_init_(I) |
| | 239 | elif hasattr(self, '_%s_init_'%nm): |
| | 240 | s = self.__getattribute__('_%s_init_'%nm)() |
| 240 | 241 | else: |
| 241 | 242 | try: |
| 242 | 243 | s = self._interface_init_() |
| … |
… |
|
| 309 | 310 | return self._interface_init_() |
| 310 | 311 | |
| 311 | 312 | |
| 312 | | def _magma_(self, M=None): |
| | 313 | def _magma_(self, magma): |
| 313 | 314 | """ |
| 314 | 315 | Given a Magma interpreter M (or None for the default global |
| 315 | 316 | interpreter), return MagmaElement corresponding to self in M. |
| … |
… |
|
| 328 | 329 | EXAMPLES: |
| 329 | 330 | sage: n = -3/7 |
| 330 | 331 | sage: m2 = Magma() |
| 331 | | sage: n._magma_() # optional - magma |
| | 332 | sage: n._magma_(magma) # optional - magma |
| 332 | 333 | -3/7 |
| 333 | | sage: n._magma_().parent() # optional - magma |
| | 334 | sage: n._magma_(magma).parent() # optional - magma |
| 334 | 335 | Magma |
| 335 | | sage: n._magma_().parent() is m2 # optional - magma |
| | 336 | sage: n._magma_(magma).parent() is m2 # optional - magma |
| 336 | 337 | False |
| 337 | | sage: n._magma_().parent() is magma # optional - magma |
| | 338 | sage: n._magma_(magma).parent() is magma # optional - magma |
| 338 | 339 | True |
| 339 | 340 | sage: n._magma_(m2).parent() is m2 # optional - magma |
| 340 | 341 | True |
| … |
… |
|
| 342 | 343 | This example illustrates caching, which happens automatically |
| 343 | 344 | since K is a Python object: |
| 344 | 345 | sage: K.<a> = NumberField(x^3 + 2) |
| 345 | | sage: K._magma_() is K._magma_() # optional - magma |
| | 346 | sage: magma(K) is magma(K) # optional - magma |
| 346 | 347 | True |
| 347 | 348 | sage: magma2 = Magma() |
| 348 | | sage: K._magma_() is K._magma_(magma2) # optional - magma |
| | 349 | sage: magma(K) is magma2(K) # optional - magma |
| 349 | 350 | False |
| 350 | 351 | """ |
| 351 | | if M is None: |
| 352 | | import sage.interfaces.magma |
| 353 | | M = sage.interfaces.magma.magma |
| 354 | 352 | c = self._interface_is_cached_() |
| 355 | 353 | if c: |
| 356 | 354 | try: |
| 357 | | X = self.__interface[M] |
| | 355 | X = self.__interface[magma] |
| 358 | 356 | X._check_valid() |
| 359 | 357 | return X |
| 360 | 358 | except (AttributeError, TypeError): |
| … |
… |
|
| 367 | 365 | pass |
| 368 | 366 | except (KeyError, ValueError): |
| 369 | 367 | pass |
| 370 | | A = self._magma_convert_(M) |
| | 368 | A = self._magma_convert_(magma) |
| 371 | 369 | if c: |
| 372 | | self.__interface[M] = A |
| | 370 | self.__interface[magma] = A |
| 373 | 371 | return A |
| 374 | 372 | |
| 375 | | def _magma_init_(self): |
| | 373 | def _magma_init_(self, magma): |
| 376 | 374 | """ |
| 377 | | Return an ascii string that evaluates to something equal to |
| 378 | | self in Magma. Use this for converting very simple things |
| 379 | | (e.g., integers) from Sage to Magma. For anything much more |
| 380 | | complicated, use _magma_convert_. |
| | 375 | Return an ascii string that evaluates to the Magma version of |
| | 376 | self in the given magma interface. |
| 381 | 377 | |
| 382 | | The default coercion for elements from Sage to Magma is to |
| 383 | | call _magma_init_, which just calls the repr method of the |
| 384 | | object. |
| 385 | | |
| | 378 | INPUT: |
| | 379 | magma -- a Magma interface |
| 386 | 380 | OUTPUT: |
| 387 | 381 | string |
| 388 | 382 | |
| 389 | 383 | EXAMPLES: |
| 390 | 384 | sage: n = -3/7 |
| 391 | | sage: n._magma_init_() |
| | 385 | sage: n._magma_init_(magma) |
| 392 | 386 | '-3/7' |
| 393 | 387 | """ |
| 394 | 388 | return self._interface_init_() |