Skip to content

Commit

Permalink
convert magma power series rings
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Oct 9, 2024
1 parent b0f09d9 commit c7381d7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 26 deletions.
38 changes: 31 additions & 7 deletions src/sage/ext_data/magma/sage/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function PreparseElts(R)
end function;

intrinsic Sage(X::.) -> MonStgElt, BoolElt
{Default way to convert a Magma object to Sage if we haven't
{Default way to convert a Magma object to Sage if we have not
written anything better.}
return Sprintf("%o", X), true;
end intrinsic;
Expand Down Expand Up @@ -153,16 +153,19 @@ intrinsic SageNamesHelper(X::.) -> MonStgElt
{}
/* XXX */
i := NumberOfNames(X);
if i ge 2 then
return (&* [ Sprintf("%o, ", X.j) : j in [ 1..i-1 ] ]) * Sprintf("%o", X.i);
if "$" in Sprint(X.i) then
/* unnamed variables */
return "(" * (&* [ Sprintf("'x%o', ", j) : j in [ 1..i ] ]) * ")"
else
return Sprintf("%o", X.i);
end if;
/* named variables */
return "(" * (&* [ Sprintf("'%o', ", X.j) : j in [ 1..i ] ]) * ")"
end if:
end intrinsic;

intrinsic Sage(X::RngUPol) -> MonStgElt, BoolElt
{}
return Sprintf("%o['%o'.replace('$.', 'x').replace('.', '')]", Sage(BaseRing(X)), SageNamesHelper(X)), false;
txt := "PolynomialRing(%o, %o)";
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
end intrinsic;

intrinsic Sage(X::RngUPolElt) -> MonStgElt, BoolElt
Expand All @@ -173,7 +176,8 @@ intrinsic Sage(X::RngUPolElt) -> MonStgElt, BoolElt

intrinsic Sage(X::RngMPol) -> MonStgElt, BoolElt
{}
return Sprintf("%o['%o'.replace('$.', 'x').replace('.', '')]", Sage(BaseRing(X)), SageNamesHelper(X)), false;
txt := "PolynomialRing(%o, %o)";
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
end intrinsic;

intrinsic Sage(X::RngMPolElt) -> MonStgElt, BoolElt
Expand Down Expand Up @@ -264,3 +268,23 @@ intrinsic Sage(X::ModTupRngElt) -> MonStgElt, BoolElt
{}
return Sprintf("%o(%o)", Sage(Parent(X)), Sage(ElementToSequence(X))), true;
end intrinsic;

/* Power series rings */

intrinsic Sage(X::RngSerPow) -> MonStgElt, BoolElt
{}
txt := "PowerSeriesRing(%o, %o)";
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
end intrinsic;

intrinsic Sage(X::RngSerLaur) -> MonStgElt, BoolElt
{}
txt := "LaurentSeriesRing(%o, %o)";
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
end intrinsic;

intrinsic Sage(X::RngSerPuis) -> MonStgElt, BoolElt
{}
txt := "PuiseuxSeriesRing(%o, %o)";
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
end intrinsic;
40 changes: 21 additions & 19 deletions src/sage/interfaces/magma.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,28 @@

from sage.structure.parent import Parent
from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement
PROMPT = ">>>"

SAGE_REF = "_sage_ref"
SAGE_REF_RE = re.compile(r'%s\d+' % SAGE_REF)

from sage.env import SAGE_EXTCODE, DOT_SAGE
import sage.misc.misc
import sage.misc.sage_eval
import sage.interfaces.abc
from sage.interfaces.tab_completion import ExtraTabCompletion
from sage.misc.instancedoc import instancedoc

PROMPT = ">>>"

SAGE_REF = "_sage_ref"
SAGE_REF_RE = re.compile(r'%s\d+' % SAGE_REF)

INTRINSIC_CACHE = '%s/magma_intrinsic_cache.sobj' % DOT_SAGE
EXTCODE_DIR = None


def extcode_dir(iface=None):
def extcode_dir(iface=None) -> str:
"""
Return directory that contains all the Magma extcode. This is put
in a writable directory owned by the user, since when attached,
Magma has to write sig and lck files.
Return directory that contains all the Magma extcode.
This is put in a writable directory owned by the user, since when
attached, Magma has to write sig and lck files.
EXAMPLES::
Expand Down Expand Up @@ -413,7 +414,7 @@ def __reduce__(self):
"""
return reduce_load_Magma, tuple([])

def _read_in_file_command(self, filename):
def _read_in_file_command(self, filename) -> str:
"""
Return the command in Magma that reads in the contents of the given
file.
Expand All @@ -433,7 +434,7 @@ def _read_in_file_command(self, filename):
"""
return 'load "%s";' % filename

def _post_process_from_file(self, s):
def _post_process_from_file(self, s) -> str:
r"""
Used internally in the Magma interface to post-process the result
of evaluating a string using a file. For Magma what this does is
Expand Down Expand Up @@ -462,7 +463,7 @@ def _post_process_from_file(self, s):
return ''
return s[i + 1:]

def __getattr__(self, attrname):
def __getattr__(self, attrname) -> MagmaFunction:
"""
Return a formal wrapper around a Magma function, or raise an
:exc:`AttributeError` if attrname starts with an underscore.
Expand Down Expand Up @@ -494,7 +495,7 @@ def __getattr__(self, attrname):
raise AttributeError
return MagmaFunction(self, attrname)

def eval(self, x, strip=True, **kwds):
def eval(self, x, strip=True, **kwds) -> str:
"""
Evaluate the given block x of code in Magma and return the output
as a string.
Expand Down Expand Up @@ -553,7 +554,7 @@ def eval(self, x, strip=True, **kwds):
raise RuntimeError("Error evaluating Magma code.\nIN:%s\nOUT:%s" % (x, ans))
return ans

def _preparse(self, s):
def _preparse(self, s) -> str:
"""
All input gets preparsed by calling this function before it gets evaluated.
Expand All @@ -578,7 +579,7 @@ def _preparse(self, s):
pass
return s

def _start(self):
def _start(self) -> None:
"""
Initialize a Magma interface instance. This involves (1) setting up
an obfuscated prompt, and (2) attaching the MAGMA_SPEC file (see
Expand Down Expand Up @@ -619,7 +620,7 @@ def set(self, var, value):
if out.lower().find("error") != -1:
raise TypeError("Error executing Magma code:\n%s" % out)

def get(self, var):
def get(self, var) -> str:
"""
Get the value of the variable var.
Expand Down Expand Up @@ -1880,10 +1881,11 @@ def __getattr__(self, attrname):

def _sage_(self):
"""
Return Sage version of this object. Use self.sage() to get the Sage
version.
Return Sage version of this object.
Use self.sage() to get the Sage version.
Edit src/ext/magma/sage/basic.m to add functionality.
Edit ``src/sage/ext_data/magma/sage/basic.m`` to add functionality.
EXAMPLES: Enumerated Sets::
Expand Down

0 comments on commit c7381d7

Please sign in to comment.