Ticket #4601: sage-4601.patch

File sage-4601.patch, 56.1 KB (added by was, 16 months ago)

this patch should be applied to sage-3.2.1.alpha0. it should fix *all* optional doctest failures related to the magma interface! Note that there is a problem with -only_optional=magma (#4600) so doctesting with that will still show a few false errors.

  • sage/calculus/calculus.py

    # 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  
    11871187    def _maple_init_(self): 
    11881188        return self._sys_init_('maple') 
    11891189 
    1190     def _magma_init_(self): 
     1190    def _magma_init_(self, magma): 
    11911191        """ 
    11921192        Return string representation in Magma of this symbolic expression. 
    11931193 
     
    11971197        EXAMPLES: 
    11981198            sage: x = var('x')                       
    11991199            sage: f = sin(cos(x^2) + log(x)) 
    1200             sage: f._magma_init_() 
     1200            sage: f._magma_init_(magma) 
    12011201            '"sin(cos(x^2) + log(x))"' 
    12021202            sage: magma(f)                         # optional - magma 
    12031203            sin(cos(x^2) + log(x)) 
     
    40954095    try: 
    40964096        return x.__getattribute__('_%s_init_'%system)() 
    40974097    except AttributeError: 
    4098         try: 
    4099             return x._system_init_(system) 
    4100         except AttributeError: 
    4101             return repr(x) 
     4098        return repr(x) 
    41024099 
    41034100class SymbolicConstant(Symbolic_object): 
    41044101    def __init__(self, x): 
  • sage/crypto/mq/mpolynomialsystem.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/crypto/mq/mpolynomialsystem.py
    a b  
    4343from sage.matrix.constructor import Matrix 
    4444 
    4545from sage.interfaces.singular import singular 
    46 from sage.interfaces.magma import magma 
    4746 
    4847 
    4948def is_MPolynomialSystem(F): 
     
    408407        """ 
    409408        return singular.ideal(self._gens) 
    410409 
    411     def _magma_(self): 
     410    def _magma_(self, magma): 
    412411        """ 
    413412        Return MAGMA ideal representation of self. 
    414413 
     
    416415            sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) 
    417416            sage: F,s = sr.polynomial_system() 
    418417            sage: R1 = F.round(1) 
    419             sage: R1._magma_()                               # optional - magma 
     418            sage: magma(R1)                               # optional - magma 
    420419            Ideal of Polynomial ring of rank 20 over GF(2) 
    421420            Graded Reverse Lexicographical Order 
    422421            Variables: k100, k101, k102, k103, x100, x101, x102, x103, w100, w101, w102, w103, s000, s001, s002, s003, k000, k001, k002, k003 
     
    826825 
    827826    def _singular_(self): 
    828827        """ 
    829         Return SINGULAR ideal representation of this system. 
     828        Return Singular ideal representation of this system. 
    830829 
    831830        EXAMPLE: 
    832831            sage: P.<a,b,c,d> = PolynomialRing(GF(127)) 
     
    841840        """ 
    842841        return singular.ideal(list(self)) 
    843842 
    844     def _magma_(self): 
     843    def _magma_(self, magma): 
    845844        """ 
    846         Return MAGMA ideal representation of this system as an ideal. 
     845        Return Magma ideal representation of this system as an ideal. 
    847846 
    848847        EXAMPLE: 
    849848            sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) 
    850849            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            ] 
    852858        """ 
    853859        return magma.ideal(list(self)) 
    854860 
  • sage/groups/perm_gps/permgroup.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/groups/perm_gps/permgroup.py
    a b  
    320320        """ 
    321321        return self._gap_string 
    322322 
    323     def _magma_init_(self): 
     323    def _magma_init_(self, magma): 
    324324        r""" 
    325325        Returns a string showing how to declare / intialize self in Magma. 
    326326 
     
    329329        Magma, one would type the string below to construct the group. 
    330330            sage: A4 = PermutationGroup([[(1,2,3)],[(2,3,4)]]); A4 
    331331            Permutation Group with generators [(2,3,4), (1,2,3)] 
    332             sage: A4._magma_init_() 
     332            sage: A4._magma_init_(magma) 
    333333            'PermutationGroup<4 | (2,3,4), (1,2,3)>' 
    334334        """ 
    335335        g = str(self.gens())[1:-1] 
  • sage/interfaces/magma.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/interfaces/magma.py
    a b  
    9595    ] 
    9696     
    9797In 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: 
     98structure S is denoted by S(x).  This also works for the Magma interface: 
    9999  
    100100    sage: G = magma.DirichletGroup(20)                                    # optional - magma 
    101101    sage: G.AssignNames(['a', 'b'])                                       # optional - magma 
     
    107107    sage: print e.Modulus()                                               # optional - magma 
    108108    40 
    109109 
    110 We coerce some polynomial rings into MAGMA: 
     110We coerce some polynomial rings into Magma: 
    111111 
    112112    sage: R.<y> = PolynomialRing(QQ) 
    113113    sage: S = magma(R)                                                    # optional - magma 
     
    185185    a new Magma object, and \code{magma.eval(...)} to run a string 
    186186    using Magma (and get the result back as a string). 
    187187 
    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 
    189189    \code{magma\_free} command instead, which uses the free demo web 
    190     interface to MAGMA. 
     190    interface to Magma. 
    191191 
    192192    EXAMPLES: 
    193193 
     
    209209            logfile -- output logged to this file 
    210210            server -- address of remote server 
    211211            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 
    214214                           supresses user configuration files. 
    215215 
    216216        EXAMPLES: 
     
    476476        Coerce x into this Magma interpreter interface. 
    477477 
    478478        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 
    481481 
    482482        OUTPUT: 
    483483            MagmaElement 
     
    502502            True 
    503503            sage: a.parent() is m       # optional - magma 
    504504            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} 
    505518        """ 
    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 
    512562    def clear(self, var): 
    513563        """ 
    514564        Clear the variable named var and make it available 
     
    593643         
    594644    def attach(self, filename): 
    595645        r""" 
    596         Attach the given file to the running instance of MAGMA. 
     646        Attach the given file to the running instance of Magma. 
    597647 
    598         Attaching a file in MAGMA makes all intrinsics defined in the 
     648        Attaching a file in Magma makes all intrinsics defined in the 
    599649        file available to the shell.  Moreover, if the file doesn't 
    600650        start with the \code{freeze;} command, then the file is 
    601651        reloaded whenever it is changed.  Note that functions and 
     
    645695    def load(self, filename): 
    646696        """ 
    647697        Load the file with given filename using the 'load' command 
    648         in the MAGMA shell. 
     698        in the Magma shell. 
    649699 
    650         Loading a file in MAGMA makes all the functions and procedures 
     700        Loading a file in Magma makes all the functions and procedures 
    651701        in the file available. The file should not contain any 
    652702        intrinsics (or you'll get errors).  It also runs code in the 
    653703        file, which can produce output. 
     
    693743            try: 
    694744                self.eval('Append(~_sage_, 0);') 
    695745            except: 
    696                 # this exception could happen if the MAGMA process 
     746                # this exception could happen if the Magma process 
    697747                # was interrupted during startup / initialization. 
    698748                self.eval('_sage_ := [* 0 : i in [1..%s] *];'%self.__seq) 
    699749        if len(self.__available_var) > 0: 
     
    861911        """ 
    862912        return MagmaElement 
    863913 
    864     # Usually "Sequences" are what you want in MAGMA, not "lists". 
     914    # Usually "Sequences" are what you want in Magma, not "lists". 
    865915    # It's very painful using the interface without this. 
    866916    def _left_list_delim(self): 
    867917        """ 
     
    10371087                except IOError: 
    10381088                    pass 
    10391089            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." 
    10411091                print "This takes a few minutes the first time, but is saved to the" 
    10421092                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." 
    10441094                print "Delete that file to force recreation of this cache." 
    1045                 print "Scanning MAGMA types ..." 
     1095                print "Scanning Magma types ..." 
    10461096                tm = sage.misc.misc.cputime() 
    10471097            T = self.eval('ListTypes()').split() 
    10481098            N = [] 
     
    10551105                    for x in s.split('\n'): 
    10561106                        i = x.find('(') 
    10571107                        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 
    10591109                    print 'Error -- %s'%msg 
    10601110                    pass 
    10611111            if verbose: 
     
    10701120 
    10711121    def ideal(self, L): 
    10721122        """ 
    1073         Return the MAGMA ideal defined by L. 
     1123        Return the Magma ideal defined by L. 
    10741124 
    10751125        INPUT: 
    10761126            L -- a list of elements of a SAGE multivariate polynomial ring. 
     
    10911141            ] 
    10921142        """ 
    10931143        P = iter(L).next().parent() 
    1094         Pn = P._magma_().name() 
     1144        Pn = self(P).name() 
    10951145        k = P.base_ring()  
    10961146        if k.degree() > 1: 
    10971147            i = str(k.gen()) 
     
    14771527            [$.1] 
    14781528        """ 
    14791529        try: 
    1480             return self.__gens 
     1530            return self._magma_gens 
    14811531        except AttributeError: 
    14821532            pass 
    14831533        G = [] 
     
    14901540            except (RuntimeError, TypeError): 
    14911541                break 
    14921542            i += 1 
    1493         self.__gens = G 
     1543        self._magma_gens = G 
    14941544        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 
    14951567 
    14961568    def evaluate(self, *args): 
    14971569        """ 
     
    18181890        Quotient of division of self by other.  This is denoted // ("div" in magma). 
    18191891 
    18201892        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 
    18231895            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 
    18271899            y + z 
    18281900        """ 
    18291901        return self.parent()('%s div %s'%(self.name(), x.name())) 
  • sage/matrix/matrix1.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix1.pyx
    a b  
    220220            [             zeta9            zeta9^4          zeta9 - 1] 
    221221            [-zeta9^5 - zeta9^2                  1                  0] 
    222222            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] 
    226226            sage: magma(M**2) == magma(M)**2           # optional - magma 
    227227            True 
    228228        """ 
     
    233233           s = 'RMatrixSpace(%s, %s, %s)'%(K.name(), self.nrows(), self.ncols()) 
    234234        v = [] 
    235235        for x in self.list(): 
    236              v.append(x._magma_init_()) 
     236             v.append(x._magma_init_(magma)) 
    237237        return magma(s + '![%s]'%(','.join(v))) 
    238238 
    239239    def _maple_init_(self): 
  • sage/matrix/matrix_mod2_dense.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix_mod2_dense.pyx
    a b  
    11281128     
    11291129 
    11301130 
    1131     def _magma_init_(self): 
     1131    def _magma_init_(self, magma): 
    11321132        r""" 
    11331133        Returns a string of self in \Magma form. Does not return \Magma 
    11341134        object but string. 
    11351135 
    11361136        EXAMPLE: 
    11371137            sage: A = random_matrix(GF(2),3,3) 
    1138             sage: A._magma_init_()                             # optional - magma 
     1138            sage: A._magma_init_(magma)                             # optional - magma 
    11391139            'MatrixAlgebra(GF(2), 3)![0,1,0,0,1,1,0,0,0]' 
    11401140            sage: A = random_matrix(GF(2),100,100) 
    11411141            sage: B = random_matrix(GF(2),100,100) 
     
    11481148            Matrix with 0 rows and 3 columns 
    11491149        """ 
    11501150        cdef int i,j 
    1151         K = self._base_ring._magma_init_() 
     1151        K = self._base_ring._magma_init_(magma) 
    11521152        if self._nrows == self._ncols:  
    11531153            s = 'MatrixAlgebra(%s, %s)'%(K, self.nrows()) 
    11541154        else: 
  • sage/matrix/matrix_modn_dense.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix_modn_dense.pyx
    a b  
    15371537            raise IndexError, "matrix window index out of range" 
    15381538        return matrix_window_modn_dense.MatrixWindow_modn_dense(self, row, col, nrows, ncols) 
    15391539 
    1540     def _magma_init_(self): 
     1540    def _magma_init_(self, magma): 
    15411541        """ 
    1542         Returns a string of self in MAGMA form. 
     1542        Returns a string representation of self in Magma form. 
    15431543 
    1544         NOTE: Does not return MAGMA object but string. 
     1544        INPUT: 
     1545            magma -- a Magma session 
     1546        OUTPUT: 
     1547            string 
    15451548        """ 
    15461549        cdef int i,j 
    1547         K = self._base_ring._magma_init_() 
     1550        K = self._base_ring._magma_init_(magma) 
    15481551        if self._nrows == self._ncols:  
    15491552            s = 'MatrixAlgebra(%s, %s)'%(K, self.nrows()) 
    15501553        else: 
  • sage/matrix/matrix_space.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/matrix/matrix_space.py
    a b  
    10861086        Z.randomize(density, *args, **kwds) 
    10871087        return Z 
    10881088 
    1089     def _magma_init_(self): 
     1089    def _magma_init_(self, magma): 
    10901090        r""" 
    10911091        EXAMPLES: 
    10921092        We first coerce a square matrix. 
     
    10961096            sage: magma(MatrixSpace(Integers(8),2,3))           # optional - magma 
    10971097            Full RMatrixSpace of 2 by 3 matrices over IntegerRing(8) 
    10981098        """ 
    1099         K = self.base_ring()._magma_init_() 
     1099        K = self.base_ring()._magma_init_(magma) 
    11001100        if self.__nrows == self.__ncols: 
    11011101            s = 'MatrixAlgebra(%s, %s)'%(K, self.__nrows) 
    11021102        else: 
  • sage/rings/finite_field_element.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/finite_field_element.py
    a b  
    414414    def _pari_init_(self): 
    415415        return str(self.__value) 
    416416 
    417     def _magma_init_(self): 
     417    def _magma_init_(self, magma): 
    418418        """ 
    419419        Return a string representation of self that Magma can understand. 
    420420 
    421421        EXAMPLES: 
    422             sage: GF(7)(3)._magma_init_()                 # optional - magma 
     422            sage: GF(7)(3)._magma_init_(magma)                 # optional - magma 
    423423            'GF(7)!3' 
    424424        """ 
    425         km = self.parent()._magma_() 
     425        km = magma(self.parent()) 
    426426        vn = km.gen(1).name() 
    427427        return ("%s"%(self.__value.lift().lift())).replace('a',vn) 
    428428 
  • sage/rings/finite_field_givaro.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/finite_field_givaro.pyx
    a b  
    18841884        """ 
    18851885        return pari(self._pari_init_(var)) 
    18861886 
    1887     def _magma_init_(self): 
     1887    def _magma_init_(self, magma): 
    18881888        """ 
    18891889        Return a string representation of self that MAGMA can 
    18901890        understand. 
    18911891 
    18921892        EXAMPLE: 
    18931893            sage: k.<a> = GF(3^5) 
    1894             sage: k._magma_init_()        # optional - magma 
     1894            sage: k._magma_init_(magma)        # optional - magma 
    18951895            'ext< GF(3) | Polynomial(GF(3), [GF(3)!1,GF(3)!2,GF(3)!0,GF(3)!0,GF(3)!0,GF(3)!1]) >' 
    18961896        """ 
    1897         km = self.parent()._magma_() 
     1897        km = magma(self.parent()) 
    18981898        vn = km.gen(1).name() 
    1899         return self.parent()._element_poly_repr(self,vn) 
     1899        return self.parent()._element_poly_repr(self, vn) 
    19001900 
    19011901    def multiplicative_order(FiniteField_givaroElement self): 
    19021902        """ 
  • sage/rings/finite_field_ntl_gf2e.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/finite_field_ntl_gf2e.pyx
    a b  
    12451245            o *= g 
    12461246        return ret 
    12471247             
    1248     def _magma_init_(self): 
     1248    def _magma_init_(self, magma): 
    12491249        r""" 
    12501250        Return a string representation of self that \MAGMA can 
    12511251        understand. 
    12521252 
    12531253        EXAMPLE: 
    12541254            sage: k.<a> = GF(2^16) 
    1255             sage: a._magma_init_()      # random; optional - magma 
     1255            sage: a._magma_init_(magma)      # random; optional - magma 
    12561256            '_sage_[2]' 
    12571257             
    12581258        NOTE: This method calls \MAGMA to setup the parent. 
    12591259        """ 
    1260         km = self.parent()._magma_() 
     1260        km = magma(self.parent()) 
    12611261        vn_m = km.gen(1).name() 
    12621262        vn_s = str(self.parent().polynomial_ring().gen()) 
    12631263        return str(self.polynomial()).replace(vn_s,vn_m) 
  • sage/rings/fraction_field.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/fraction_field.py
    a b  
    195195        return "\\mbox{\\rm Frac}(%s)"%latex.latex(self.ring()) 
    196196 
    197197    __magma = None 
    198     def _magma_init_(self): 
     198    def _magma_init_(self, magma): 
    199199        """ 
    200200        Return a string representation of self Magma can understand. 
    201201 
    202202        EXAMPLES: 
    203             sage: QQ['x'].fraction_field()._magma_init_()            # optional - magma 
     203            sage: QQ['x'].fraction_field()._magma_init_(magma)            # optional - magma 
    204204            'FieldOfFractions(PolynomialRing(RationalField()))' 
    205205        """ 
    206206        if self.__magma: 
    207207            return self.__magma 
    208         B = self.ring()._magma_init_() 
     208        B = self.ring()._magma_init_(magma) 
    209209        return "FieldOfFractions(%s)"%B 
    210210 
    211211    def _magma_(self, magma = None): 
     
    223223            import sage.interfaces.magma 
    224224            magma = sage.interfaces.magma.magma 
    225225        if self.__magma is None: 
    226             s = self._magma_init_() 
     226            s = self._magma_init_(magma) 
    227227            F = magma(s) 
    228228            F.assign_names(self.variable_names()) 
    229229            self.__magma = F 
  • sage/rings/fraction_field_element.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/fraction_field_element.py
    a b  
    349349        return "\\frac{%s}{%s}"%(latex.latex(self.__numerator), 
    350350                                 latex.latex(self.__denominator)) 
    351351 
    352     def _magma_init_(self): 
     352    def _magma_init_(self, magma): 
    353353        """ 
    354354        Return a string representation of self Magma can understand. 
    355355 
     
    362362            sage: magma((x+y)/x)                        # optional - magma 
    363363            (x + y)/x 
    364364        """ 
    365         pgens = self.parent()._magma_().gens() 
     365        pgens = magma(self.parent()).gens() 
    366366 
    367367        s = self._repr_() 
    368368        for i, j in zip(self.parent().variable_names(), pgens): 
  • sage/rings/integer_mod.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/integer_mod.pyx
    a b  
    350350        n = self.log(R(g)) 
    351351        return 'Z(%s)^%s'%(m, n) 
    352352 
    353     def _magma_init_(self): 
     353    def _magma_init_(self, magma): 
    354354        """ 
    355355        Coercion to Magma. 
    356356         
     
    362362            sage: b^2                         # optional - magma 
    363363            1 
    364364        """ 
    365         return '%s!%s'%(self.parent()._magma_init_(), self) 
     365        return '%s!%s'%(self.parent()._magma_init_(magma), self) 
    366366 
    367367    def _sage_input_(self, sib, coerced): 
    368368        r""" 
  • sage/rings/integer_mod_ring.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/integer_mod_ring.py
    a b  
    898898        """ 
    899899        return 'ZmodnZ(%s)'%self.order() 
    900900 
    901     def _magma_init_(self): 
     901    def _magma_init_(self, magma): 
    902902        """ 
    903903        EXAMPLES: 
    904904            sage: R = Integers(12345678900) 
  • sage/rings/integer_ring.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/integer_ring.pyx
    a b  
    840840        """ 
    841841        return 'Integers' 
    842842     
    843     def _magma_init_(self): 
     843    def _magma_init_(self, magma): 
    844844        """ 
    845845        EXAMPLES: 
    846846            sage: magma(ZZ)           # optional - magma 
  • sage/rings/number_field/number_field.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/number_field/number_field.py
    a b  
    54725472        """ 
    54735473        return NumberField_cyclotomic_v1, (self.__n, self.variable_name()) 
    54745474 
    5475     def _magma_init_(self): 
     5475    def _magma_init_(self, magma): 
    54765476        # TODO: I really don't like this on multiple levels. 
    54775477        # (1) it kills a global symbol self.gen() 
    54785478        # (2) it abuses how conversion works and throws in an extra define. 
     
    54895489 
    54905490        EXAMPLES: 
    54915491            sage: K=CyclotomicField(7,'z')  
    5492             sage: K._magma_init_()                                # optional - magma 
     5492            sage: K._magma_init_(magma)                                # optional - magma 
    54935493            'CyclotomicField(7); z:=CyclotomicField(7).1;' 
    54945494            sage: K=CyclotomicField(7,'zeta')                
    5495             sage: K._magma_init_()                                # optional - magma 
     5495            sage: K._magma_init_(magma)                                # optional - magma 
    54965496            'CyclotomicField(7); zeta:=CyclotomicField(7).1;'         
    54975497        """ 
    54985498        return 'CyclotomicField(%s); %s:=CyclotomicField(%s).1;'%(self.__n, self.gen(), self.__n) 
  • sage/rings/number_field/number_field_element.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/number_field/number_field_element.pyx
    a b  
    18201820        self.__pari[var] = h 
    18211821        return h 
    18221822 
    1823     def _magma_(self, magma): 
     1823    def _magma_init_(self, magma): 
    18241824        """ 
    18251825        Return Magma version of this number field element. 
    18261826 
     
    18321832 
    18331833        EXAMPLES: 
    18341834            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 
    18361838            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 
    18371848        """ 
    18381849        K = magma(self.parent()) 
    1839         return K(self.list()) 
     1850        return '(%s!%s)'%(K.name(), self.list()) 
    18401851         
    18411852    cdef void _parent_poly_c_(self, ZZX_c *num, ZZ_c *den): 
    18421853        """ 
  • sage/rings/polynomial/multi_polynomial.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial.pyx
    a b  
    662662        P = P.change_ring(R) 
    663663        return P(self) 
    664664 
    665     def _magma_init_(self): 
     665    def _magma_init_(self, magma): 
    666666        """ 
    667         Returns the MAGMA representation of self. 
     667        Returns a Magma string representation of self valid in the 
     668        given magma session. 
    668669         
    669670        EXAMPLES: 
    670671            sage: R.<x,y> = GF(2)[] 
    671672            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 
    674682        """ 
    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 
    676690         
    677691    def gradient(self): 
    678692        r""" 
  • sage/rings/polynomial/multi_polynomial_ideal.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial_ideal.py
    a b  
    359359        EXAMPLES: 
    360360            sage: R.<a,b,c,d,e,f,g,h,i,j> = PolynomialRing(GF(127),10) 
    361361            sage: I = sage.rings.ideal.Cyclic(R,4) 
    362             sage: I._magma_()                                          # optional - magma 
     362            sage: magma(I)                                          # optional - magma 
    363363            Ideal of Polynomial ring of rank 10 over GF(127) 
    364364            Graded Reverse Lexicographical Order 
    365365            Variables: a, b, c, d, e, f, g, h, i, j 
  • sage/rings/polynomial/multi_polynomial_ring_generic.pxd

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial_ring_generic.pxd
    a b  
    77    cdef object __ngens 
    88    cdef object __term_order 
    99    cdef object _has_singular 
    10     cdef object __magma 
    11     cdef object __magma_gens 
     10    cdef public object _magma_gens, _magma_cache 
    1211 
    1312    cdef _coerce_c_impl(self, x) 
    1413    cdef int _cmp_c_impl(left, Parent right) except -2 
  • sage/rings/polynomial/multi_polynomial_ring_generic.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/multi_polynomial_ring_generic.pyx
    a b  
    250250            return False 
    251251        return True 
    252252 
    253     def _magma_(self, magma=None): 
     253    def _magma_convert_(self, magma=None): 
    254254        """ 
    255255        Used in converting this ring to the corresponding ring in MAGMA. 
    256256 
     
    276276            Graded Reverse Lexicographical Order 
    277277            Variables: x0, x1, x2 
    278278        """ 
    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 
    298283 
    299     def _magma_gens(self): 
     284    def _magma_init_(self, magma): 
    300285        """ 
    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. 
    320288        """ 
    321289        try: # we need that for GF(q) arithmetic 
    322             B = self.base_ring()._magma_().name() 
     290            B = magma(self.base_ring()).name() 
    323291        except (RuntimeError,TypeError): 
    324             B = self.base_ring()._magma_init_() 
     292            B = self.base_ring()._magma_init_(magma) 
    325293        R = 'PolynomialRing(%s, %s, %s)'%(B, self.ngens(),self.term_order().magma_str()) 
    326294        return R 
    327295     
  • sage/rings/polynomial/pbori.pxd

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/pbori.pxd
    a b  
    1212    cdef Py_ssize_t* pbind 
    1313    cdef public _monom_monoid 
    1414    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 
    1518 
    1619cdef class BooleanPolynomial(MPolynomial): 
    1720    cdef PBPoly _pbpoly 
  • sage/rings/polynomial/pbori.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/pbori.pyx
    a b  
    935935 
    936936            sage: B.term_order() == R.term_order() 
    937937            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         
    940950 
    941951    def defining_ideal(self): 
    942952        r""" 
     
    976986        """ 
    977987        return self.cover_ring().quo( self.defining_ideal() )._singular_init_() 
    978988 
    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 
    9891000            Affine Algebra of rank 3 over GF(2) 
    9901001            Lexicographical Order 
    9911002            Variables: x, y, z 
     
    9961007            z^2 + z 
    9971008            ] 
    9981009        """ 
    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     
    10451021    def interpolation_polynomial(self, zeros, ones): 
    10461022        r""" 
    10471023        Return the lexicographically minimal boolean polynomial for 
     
    27862762        """  
    27872763        return unpickle_BooleanPolynomial, (self._parent, PBPoly_to_str(&self._pbpoly))  
    27882764 
    2789     def _magma_(self, magma=None): 
     2765    def _magma_(self, magma): 
    27902766        r""" 
    27912767        Returns the \MAGMA representation of self. 
    27922768         
    27932769        EXAMPLES: 
    27942770            sage: R.<x,y> = BooleanPolynomialRing() 
    27952771            sage: f = y*x + x +1 
    2796             sage: f._magma_() # optional - magma 
     2772            sage: magma(f) # optional - magma 
    27972773            x*y + x + 1 
    27982774        """ 
    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()] 
    28042776        f = self._repr_with_changed_varnames(magma_gens) 
    28052777        return magma(f) 
    28062778 
  • sage/rings/polynomial/polynomial_element.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/polynomial_element.pyx
    a b  
    28312831    def _pari_init_(self): 
    28322832        return repr(self._pari_()) 
    28332833 
    2834     def _magma_init_(self): 
     2834    def _magma_init_(self, magma): 
    28352835        """ 
    28362836        Return a string that evaluates in Magma to this polynomial. 
    28372837 
    28382838        EXAMPLES: 
    28392839            sage: R.<y> = ZZ[] 
    28402840            sage: f = y^3 - 17*y + 5 
    2841             sage: f._magma_init_()             # optional - magma 
     2841            sage: f._magma_init_(magma)             # optional - magma 
    28422842            'Polynomial(IntegerRing(), [5,-17,0,1])'         
    28432843        """ 
    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()])) 
    28452846 
    28462847    def _magma_convert_(self, G): 
    28472848        """ 
     
    28672868            y^3 - 17*y + 5         
    28682869        """ 
    28692870        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)) 
    28712872 
    28722873    def _gap_init_(self): 
    28732874        return repr(self) 
  • sage/rings/polynomial/polynomial_element_generic.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/polynomial_element_generic.py
    a b  
    715715            sage: G = f.galois_group(); G            # optional - database_gap 
    716716            Transitive group number 5 of degree 4 
    717717            sage: G.gens()                           # optional - database_gap 
    718             ((1,2,3,4), (1,2)) 
     718            [(1,2,3,4), (1,2)] 
    719719            sage: G.order()                          # optional - database_gap 
    720720            24 
    721721 
     
    739739            Transitive group number 5 of degree 4 
    740740         
    741741            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 
    743743            Transitive group number 5 of degree 4 
    744744        """ 
    745745        from sage.groups.all import PariGroup, PermutationGroup, TransitiveGroup 
  • sage/rings/polynomial/polynomial_ring.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/polynomial_ring.py
    a b  
    346346            pass 
    347347        raise TypeError 
    348348 
    349     def _magma_(self, G=None): 
     349    def _magma_convert_(self, magma): 
    350350        """ 
    351351        Used in converting this ring to the corresponding ring in MAGMA. 
    352352         
     
    367367            sage: magma(PolynomialRing(PolynomialRing(ZZ,'w'), 'x')) # optional - magma 
    368368            Univariate Polynomial Ring in x over Univariate Polynomial Ring over Integer Ring 
    369369        """ 
    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)) 
    374371        R.assign_names(self.variable_names()) 
    375372        return R 
    376373 
    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)) 
    379376 
    380377    def _gap_(self, G=None): 
    381378        """ 
  • sage/rings/polynomial/term_order.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/polynomial/term_order.py
    a b  
    902902 
    903903        EXAMPLE: 
    904904            sage: P = PolynomialRing(GF(127), 10,names='x',order='degrevlex') 
    905             sage: P._magma_() # optional - magma 
     905            sage: magma(P)                                                        # optional - magma 
    906906            Polynomial ring of rank 10 over GF(127) 
    907907            Graded Reverse Lexicographical Order 
    908908            Variables: x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 
  • sage/rings/quotient_ring.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/quotient_ring.py
    a b  
    644644        EXAMPLE: 
    645645            sage: P.<x,y> = PolynomialRing(GF(2)) 
    646646            sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) 
    647             sage: Q._magma_()                                         # optional - magma 
     647            sage: magma(Q)                                         # optional - magma 
    648648            Affine Algebra of rank 2 over GF(2) 
    649649            Graded Reverse Lexicographical Order 
    650650            Variables: x, y 
  • sage/rings/quotient_ring_element.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/quotient_ring_element.py
    a b  
    240240            sage: P.<x,y> = PolynomialRing(GF(2)) 
    241241            sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) 
    242242            sage: xbar, ybar = Q.gens() 
    243             sage: xbar._magma_() # optional requires magma 
     243            sage: magma(xbar)             # optional -- magma 
    244244            x 
    245245        """ 
    246246        if magma is None: 
    247247            import sage.interfaces.magma 
    248248            magma = sage.interfaces.magma.magma 
    249249         
    250         magma_gens = [e.name() for e in self.parent()._magma_().gens()] 
     250        magma_gens = [e.name() for e in magma(self.parent()).gens()] 
    251251        f = self.__rep._repr_with_changed_varnames(magma_gens) 
    252252        return magma(f) 
    253253 
  • sage/rings/rational_field.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/rational_field.py
    a b  
    731731        """ 
    732732        return 'Rationals' 
    733733     
    734     def _magma_init_(self): 
     734    def _magma_init_(self, magma): 
    735735        """ 
    736736        EXAMPLES: 
    737737            sage: magma(QQ)                       # optional - magma 
  • sage/rings/ring.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/rings/ring.pyx
    a b  
    15451545        """ 
    15461546        return 'GF(%s)'%self.order() 
    15471547 
    1548     def _magma_init_(self): 
     1548    def _magma_init_(self, magma): 
    15491549        """ 
    15501550        Return string representation of self that Magma can 
    15511551        understand. 
    15521552 
    15531553        EXAMPLES: 
    1554             sage: GF(97,'a')._magma_init_()              # optional - magma 
     1554            sage: GF(97,'a')._magma_init_(magma)              # optional - magma 
    15551555            'GF(97)' 
    1556             sage: GF(9,'a')._magma_init_()               # optional - magma 
     1556            sage: GF(9,'a')._magma_init_(magma)               # optional - magma 
    15571557            'ext< GF(3) | Polynomial(GF(3), [GF(3)!2,GF(3)!2,GF(3)!1]) >' 
    15581558        """ 
    15591559        if self.degree() == 1: 
    15601560            return 'GF(%s)'%self.order() 
    15611561        B = self.base_ring() 
    15621562        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)) 
    15641564 
    15651565    def _magma_convert_(self, magma): 
    15661566        """ 
     
    15721572            sage: magma(GF(9,'a')).1         # optional - magma 
    15731573            a 
    15741574        """ 
    1575         K = magma(self._magma_init_()) 
     1575        K = magma(self._magma_init_(magma)) 
    15761576        K.assign_names([self.variable_name()]) 
    15771577        return K 
    15781578     
  • sage/schemes/elliptic_curves/ell_finite_field.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_finite_field.py
    a b  
    9292        self.__pari = pari('ellinit(Mod(1,%s)*%s)'%(F.characteristic(), [b._pari_() for b in self.ainvs()])) 
    9393        return self.__pari 
    9494 
    95     def _magma_init_(self): 
     95    def _magma_init_(self, magma): 
    9696        """ 
    9797        Return a Magma command that creates this curve. 
    9898 
    9999        EXAMPLES: 
    100100            sage: E =  EllipticCurve(GF(41),[2,5]) # optional - magma 
    101             sage: E._magma_init_()                 # optional - magma 
     101            sage: E._magma_init_(magma)                 # optional - magma 
    102102            'EllipticCurve([GF(41)|GF(41)!0,GF(41)!0,GF(41)!0,GF(41)!2,GF(41)!5])' 
    103103       """ 
    104104        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()])) 
    107107 
    108108    def _gp(self): 
    109109        """ 
  • sage/schemes/elliptic_curves/ell_generic.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_generic.py
    a b  
    290290        """ 
    291291        return 'ellinit([%s])'%(','.join([x._pari_init_() for x in self.ainvs()])) 
    292292 
    293     def _magma_init_(self): 
     293    def _magma_init_(self, magma): 
    294294        """ 
    295295        Internal function.  Returns a string to initialize this 
    296296        elliptic curve in the Magma subsystem. 
    297297 
    298298        EXAMPLES: 
    299299            sage: E = EllipticCurve(QQ,[1,1]) 
    300             sage: E._magma_init_()                          # optional - magma 
     300            sage: E._magma_init_(magma)                          # optional - magma 
    301301            'EllipticCurve([0/1,0/1,0/1,1/1,1/1])' 
    302302        """ 
    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()])) 
    304304 
    305305    def _symbolic_(self, SR): 
    306306        r""" 
  • sage/schemes/elliptic_curves/ell_point.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_point.py
    a b  
    13211321 
    13221322class EllipticCurvePoint_finite_field(EllipticCurvePoint_field): 
    13231323 
    1324     def _magma_init_(self): 
     1324    def _magma_init_(self, magma): 
    13251325        """ 
    13261326        Return a string representation of self that MAGMA can 
    13271327        understand. 
     
    13291329        EXAMPLE: 
    13301330        sage: E = EllipticCurve(GF(17), [1,-1]) 
    13311331        sage: P = E([13, 4]) 
    1332         sage: P._magma_init_() 
     1332        sage: P._magma_init_(magma) 
    13331333        'EllipticCurve([GF(17)|GF(17)!0,GF(17)!0,GF(17)!0,GF(17)!1,GF(17)!16])![13,4]' 
    13341334        """ 
    1335         E = self.curve()._magma_init_() 
     1335        E = self.curve()._magma_init_(magma) 
    13361336        x,y = self.xy() 
    13371337        return "%s![%s,%s]"%(E,x,y)  
    13381338 
  • sage/schemes/elliptic_curves/ell_rational_field.py

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/schemes/elliptic_curves/ell_rational_field.py
    a b  
    10111011            from sage.lfunctions.sympow import sympow 
    10121012            return sympow.analytic_rank(self)[0] 
    10131013        elif algorithm == 'magma': 
    1014             return rings.Integer(self._magma_().AnalyticRank()) 
     1014            from sage.interfaces.all import magma 
     1015            return rings.Integer(magma(self).AnalyticRank()) 
    10151016        elif algorithm == 'all': 
    10161017            S = list(set([self.analytic_rank('cremona'),  
    10171018                     self.analytic_rank('rubinstein'), self.analytic_rank('sympow')])) 
     
    23792380                from sage.lfunctions.all import sympow 
    23802381                m = sympow.modular_degree(self) 
    23812382            elif algorithm == 'magma': 
    2382                 m = rings.Integer(self._magma_().ModularDegree()) 
     2383                from sage.interfaces.all import magma 
     2384                m = rings.Integer(magma(self).ModularDegree()) 
    23832385            else: 
    23842386                raise ValueError, "unknown algorithm %s"%algorithm 
    23852387            self.__modular_degree = m 
  • sage/structure/element.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/structure/element.pyx
    a b  
    15911591        V = magma(self._parent) 
    15921592        v = [] 
    15931593        for x in self.list(): 
    1594             v.append(x._magma_init_()) 
     1594            v.append(x._magma_init_(magma)) 
    15951595        s = '%s![%s]'%(V.name(), ','.join(v)) 
    15961596        return magma(s) 
    15971597 
  • sage/structure/sage_object.pyx

    diff -r a0b4c7f7ead9 -r 334d17e4247e sage/structure/sage_object.pyx
    a b  
    233233                    pass 
    234234            except (KeyError, ValueError): 
    235235                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)() 
    240241        else: 
    241242            try: 
    242243              s = self._interface_init_() 
     
    309310        return self._interface_init_() 
    310311 
    311312 
    312     def _magma_(self, M=None): 
     313    def _magma_(self, magma): 
    313314        """ 
    314315        Given a Magma interpreter M (or None for the default global 
    315316        interpreter), return MagmaElement corresponding to self in M. 
     
    328329        EXAMPLES: 
    329330            sage: n = -3/7 
    330331            sage: m2 = Magma()                   
    331             sage: n._magma_()                        # optional - magma 
     332            sage: n._magma_(magma)                        # optional - magma 
    332333            -3/7 
    333             sage: n._magma_().parent()               # optional - magma 
     334            sage: n._magma_(magma).parent()               # optional - magma 
    334335            Magma 
    335             sage: n._magma_().parent() is m2         # optional - magma 
     336            sage: n._magma_(magma).parent() is m2         # optional - magma 
    336337            False 
    337             sage: n._magma_().parent() is magma      # optional - magma 
     338            sage: n._magma_(magma).parent() is magma      # optional - magma 
    338339            True 
    339340            sage: n._magma_(m2).parent() is m2       # optional - magma 
    340341            True 
     
    342343        This example illustrates caching, which happens automatically 
    343344        since K is a Python object: 
    344345            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 
    346347            True 
    347348            sage: magma2 = Magma()                   
    348             sage: K._magma_() is K._magma_(magma2)  # optional - magma 
     349            sage: magma(K) is magma2(K)       # optional - magma 
    349350            False 
    350351        """ 
    351         if M is None: 
    352             import sage.interfaces.magma 
    353             M = sage.interfaces.magma.magma 
    354352        c = self._interface_is_cached_() 
    355353        if c: 
    356354            try: 
    357                 X = self.__interface[M] 
     355                X = self.__interface[magma] 
    358356                X._check_valid() 
    359357                return X 
    360358            except (AttributeError, TypeError): 
     
    367365                    pass 
    368366            except (KeyError, ValueError): 
    369367                pass 
    370         A = self._magma_convert_(M) 
     368        A = self._magma_convert_(magma) 
    371369        if c: 
    372             self.__interface[M] = A 
     370            self.__interface[magma] = A 
    373371        return A 
    374372 
    375     def _magma_init_(self): 
     373    def _magma_init_(self, magma): 
    376374        """ 
    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.   
    381377 
    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 
    386380        OUTPUT: 
    387381            string 
    388382 
    389383        EXAMPLES: 
    390384            sage: n = -3/7 
    391             sage: n._magma_init_() 
     385            sage: n._magma_init_(magma) 
    392386            '-3/7' 
    393387        """ 
    394388        return self._interface_init_()