1010   You must have Magma installed on your 
1111   computer for this interface to work. Magma is not free, so it is 
1212   not included with Sage, but you can obtain it from 
13-    http ://magma.maths.usyd.edu.au/. 
13+    https ://magma.maths.usyd.edu.au/. 
1414
1515The Magma interface offers three pieces of functionality: 
1616
214214# 
215215#                  https://www.gnu.org/licenses/ 
216216# **************************************************************************** 
217- from  __future__  import  annotations 
217+ from  pathlib  import  Path 
218218import  re 
219219import  sys 
220220import  os 
221221
222222from  sage .structure .parent  import  Parent 
223223from  .expect  import  Expect , ExpectElement , ExpectFunction , FunctionElement 
224- PROMPT  =  ">>>" 
225- 
226- SAGE_REF  =  "_sage_ref" 
227- SAGE_REF_RE  =  re .compile (r'%s\d+'  %  SAGE_REF )
228- 
229224from  sage .env  import  SAGE_EXTCODE , DOT_SAGE 
230225import  sage .misc .misc 
231226import  sage .misc .sage_eval 
232227import  sage .interfaces .abc 
233228from  sage .interfaces .tab_completion  import  ExtraTabCompletion 
234229from  sage .misc .instancedoc  import  instancedoc 
235230
231+ PROMPT  =  ">>>" 
232+ 
233+ SAGE_REF  =  "_sage_ref" 
234+ SAGE_REF_RE  =  re .compile (r'%s\d+'  %  SAGE_REF )
235+ 
236236INTRINSIC_CACHE  =  '%s/magma_intrinsic_cache.sobj'  %  DOT_SAGE 
237237EXTCODE_DIR  =  None 
238238
239239
240- def  extcode_dir (iface = None ):
240+ def  extcode_dir (iface = None )  ->   str :
241241    """ 
242-     Return directory that contains all the Magma extcode.  This is put 
243-     in a writable directory owned by the user, since when attached, 
244-     Magma has to write sig and lck files. 
242+     Return directory that contains all the Magma extcode. 
243+ 
244+     This is put in a writable directory owned by the user, since when 
245+     attached, Magma has to write sig and lck files. 
245246
246247    EXAMPLES:: 
247248
@@ -413,7 +414,7 @@ def __reduce__(self):
413414        """ 
414415        return  reduce_load_Magma , tuple ([])
415416
416-     def  _read_in_file_command (self , filename ):
417+     def  _read_in_file_command (self , filename )  ->   str :
417418        """ 
418419        Return the command in Magma that reads in the contents of the given 
419420        file. 
@@ -433,7 +434,7 @@ def _read_in_file_command(self, filename):
433434        """ 
434435        return  'load "%s";'  %  filename 
435436
436-     def  _post_process_from_file (self , s ):
437+     def  _post_process_from_file (self , s )  ->   str :
437438        r""" 
438439        Used internally in the Magma interface to post-process the result 
439440        of evaluating a string using a file. For Magma what this does is 
@@ -494,7 +495,7 @@ def __getattr__(self, attrname):
494495            raise  AttributeError 
495496        return  MagmaFunction (self , attrname )
496497
497-     def  eval (self , x , strip = True , ** kwds ):
498+     def  eval (self , x , strip = True , ** kwds )  ->   str :
498499        """ 
499500        Evaluate the given block x of code in Magma and return the output 
500501        as a string. 
@@ -553,7 +554,7 @@ def eval(self, x, strip=True, **kwds):
553554            raise  RuntimeError ("Error evaluating Magma code.\n IN:%s\n OUT:%s"  %  (x , ans ))
554555        return  ans 
555556
556-     def  _preparse (self , s ):
557+     def  _preparse (self , s )  ->   str :
557558        """ 
558559        All input gets preparsed by calling this function before it gets evaluated. 
559560
@@ -578,7 +579,7 @@ def _preparse(self, s):
578579            pass 
579580        return  s 
580581
581-     def  _start (self ):
582+     def  _start (self )  ->   None :
582583        """ 
583584        Initialize a Magma interface instance. This involves (1) setting up 
584585        an obfuscated prompt, and (2) attaching the MAGMA_SPEC file (see 
@@ -619,7 +620,7 @@ def set(self, var, value):
619620        if  out .lower ().find ("error" ) !=  - 1 :
620621            raise  TypeError ("Error executing Magma code:\n %s"  %  out )
621622
622-     def  get (self , var ):
623+     def  get (self , var )  ->   str :
623624        """ 
624625        Get the value of the variable var. 
625626
@@ -655,7 +656,7 @@ def objgens(self, value, gens):
655656
656657            sage: R = magma.objgens('PolynomialRing(Rationals(),2)', 'alpha,beta')    # optional - magma 
657658            sage: R.gens()          # optional - magma 
658-             [ alpha, beta]  
659+             ( alpha, beta)  
659660
660661        Because of how Magma works you can use this to change the variable 
661662        names of the generators of an object:: 
@@ -911,16 +912,15 @@ def cputime(self, t=None):
911912            sage: # optional - magma 
912913            sage: type(magma.cputime()) 
913914            <... 'float'> 
914-             sage: magma.cputime() 
915+             sage: magma.cputime()  # random  
915916            1.9399999999999999 
916917            sage: t = magma.cputime() 
917-             sage: magma.cputime(t) 
918+             sage: magma.cputime(t)  # random  
918919            0.02 
919920        """ 
920921        if  t :
921922            return  float (self .eval ('Cputime(%s)'  %  t ))
922-         else :
923-             return  float (self .eval ('Cputime()' ))
923+         return  float (self .eval ('Cputime()' ))
924924
925925    def  chdir (self , dir ):
926926        """ 
@@ -1003,7 +1003,7 @@ def load(self, filename):
10031003
10041004        Loading a file in Magma makes all the functions and procedures in 
10051005        the file available. The file should not contain any intrinsics (or 
1006-         you'll  get errors). It also runs code in the file, which can 
1006+         you will  get errors). It also runs code in the file, which can 
10071007        produce output. 
10081008
10091009        INPUT: 
@@ -1018,14 +1018,15 @@ def load(self, filename):
10181018            sage: with NTF(mode='w+t', suffix='.m') as f:  # optional - magma 
10191019            ....:     _ = f.write('function f(n) return n^2; end function;\nprint "hi";') 
10201020            ....:     print(magma.load(f.name)) 
1021-             Loading ".../a .m" 
1021+             Loading "....m" 
10221022            hi 
10231023            sage: magma('f(12)')  # optional - magma 
10241024            144 
10251025        """ 
1026-         return  self .eval ('load "%s"'  %  filename )
1026+         p  =  Path (filename )
1027+         return  self .eval ('load "%s"'  %  p .absolute ())
10271028
1028-     def  _next_var_name (self ):
1029+     def  _next_var_name (self )  ->   str :
10291030        """ 
10301031        Return the next available variable name in Magma. 
10311032
@@ -1234,7 +1235,7 @@ def bar_call(self, left, name, gens, nvals=1):
12341235        magma  =  self 
12351236        # coerce each arg to be a Magma element 
12361237        if  isinstance (gens , (list , tuple )):
1237-             gens  =  ( magma (z ) for  z  in  gens ) 
1238+             gens  =  [ magma (z ) for  z  in  gens ] 
12381239            # make comma separated list of names (in Magma) of each of the gens 
12391240            v  =  ', ' .join (w .name () for  w  in  gens )
12401241        else :
@@ -1880,10 +1881,11 @@ def __getattr__(self, attrname):
18801881
18811882    def  _sage_ (self ):
18821883        """ 
1883-         Return Sage version of this object. Use self.sage() to get the Sage 
1884-         version. 
1884+         Return Sage version of this object. 
1885+ 
1886+         Use self.sage() to get the Sage version. 
18851887
1886-         Edit src/ext/ magma/sage/basic.m to add functionality. 
1888+         Edit `` src/sage/ext_data/ magma/sage/basic.m``  to add functionality. 
18871889
18881890        EXAMPLES: Enumerated Sets:: 
18891891
@@ -2070,14 +2072,14 @@ def AssignNames(self, names):
20702072
20712073    def  gen (self , n ):
20722074        """ 
2073-         Return the `n`-th generator of this Magma element. Note that 
2074-         generators are 1-based in Magma rather than 0-based! 
2075+         Return the `n`-th generator of this Magma element. 
2076+ 
2077+         Note that generators are 1-based in Magma rather than 0-based! 
20752078
20762079        INPUT: 
20772080
20782081        - ``n`` -- *positive* integer 
20792082
2080- 
20812083        OUTPUT: :class:`MagmaElement` 
20822084
20832085        EXAMPLES:: 
@@ -2100,7 +2102,7 @@ def gen(self, n):
21002102            sage: m.gen(4)                # optional -- magma 
21012103            Traceback (most recent call last): 
21022104            ... 
2103-             IndexError: list  index out of range 
2105+             IndexError: tuple  index out of range 
21042106        """ 
21052107        if  n  <=  0 :
21062108            raise  IndexError ("index must be positive since Magma indexes are 1-based" )
@@ -2112,7 +2114,7 @@ def gens(self) -> tuple:
21122114
21132115        If ``self`` is named X in Magma, this function evaluates X.1, X.2, 
21142116        etc., in Magma until an error occurs. It then returns a Sage tuple 
2115-         of the resulting X.i. Note - I don't  think there is a Magma command 
2117+         of the resulting X.i. Note - I do not  think there is a Magma command 
21162118        that returns the list of valid X.i. There are numerous ad hoc 
21172119        functions for various classes but nothing systematic. This function 
21182120        gets around that problem. Again, this is something that should 
@@ -2294,15 +2296,15 @@ def _polynomial_(self, R):
22942296            sage: R.<x> = QQ[] 
22952297            sage: f = magma(x^2 + 2/3*x + 5)                 # optional - magma 
22962298            sage: f                                          # optional - magma 
2297-             t ^2 + 2/3*t  + 5 
2299+             x ^2 + 2/3*x  + 5 
22982300            sage: f.Type()                                   # optional - magma 
22992301            RngUPolElt 
23002302            sage: f._polynomial_(R)                          # optional - magma 
23012303            x^2 + 2/3*x + 5 
23022304        """ 
23032305        return  R (list (self .Eltseq ()))
23042306
2305-     def  _latex_ (self ):
2307+     def  _latex_ (self )  ->   str :
23062308        r""" 
23072309        Return latex representation of ``self``. 
23082310
@@ -2854,6 +2856,7 @@ def write(self, s):
28542856            sage: P.<x,y,z> = GF(32003)[] 
28552857            sage: I = sage.rings.ideal.Katsura(P) 
28562858            sage: _ = I.groebner_basis('magma',prot=True) # indirect doctest, optional - magma 
2859+             ... 
28572860            ******************** 
28582861            FAUGERE F4 ALGORITHM 
28592862            ******************** 
0 commit comments