Skip to content

Commit 83449ba

Browse files
committed
convert magma power series rings
1 parent 5188024 commit 83449ba

File tree

2 files changed

+52
-26
lines changed

2 files changed

+52
-26
lines changed

src/sage/ext_data/magma/sage/basic.m

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function PreparseElts(R)
88
end function;
99

1010
intrinsic Sage(X::.) -> MonStgElt, BoolElt
11-
{Default way to convert a Magma object to Sage if we haven't
11+
{Default way to convert a Magma object to Sage if we have not
1212
written anything better.}
1313
return Sprintf("%o", X), true;
1414
end intrinsic;
@@ -153,16 +153,19 @@ intrinsic SageNamesHelper(X::.) -> MonStgElt
153153
{}
154154
/* XXX */
155155
i := NumberOfNames(X);
156-
if i ge 2 then
157-
return (&* [ Sprintf("%o, ", X.j) : j in [ 1..i-1 ] ]) * Sprintf("%o", X.i);
156+
if "$" in Sprint(X.i) then
157+
/* unnamed variables */
158+
return "(" * (&* [ Sprintf("'x%o', ", j) : j in [ 1..i ] ]) * ")"
158159
else
159-
return Sprintf("%o", X.i);
160-
end if;
160+
/* named variables */
161+
return "(" * (&* [ Sprintf("'%o', ", X.j) : j in [ 1..i ] ]) * ")"
162+
end if:
161163
end intrinsic;
162164

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

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

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

179183
intrinsic Sage(X::RngMPolElt) -> MonStgElt, BoolElt
@@ -264,3 +268,23 @@ intrinsic Sage(X::ModTupRngElt) -> MonStgElt, BoolElt
264268
{}
265269
return Sprintf("%o(%o)", Sage(Parent(X)), Sage(ElementToSequence(X))), true;
266270
end intrinsic;
271+
272+
/* Power series rings */
273+
274+
intrinsic Sage(X::RngSerPow) -> MonStgElt, BoolElt
275+
{}
276+
txt := "PowerSeriesRing(%o, %o)";
277+
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
278+
end intrinsic;
279+
280+
intrinsic Sage(X::RngSerLaur) -> MonStgElt, BoolElt
281+
{}
282+
txt := "LaurentSeriesRing(%o, %o)";
283+
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
284+
end intrinsic;
285+
286+
intrinsic Sage(X::RngSerPuis) -> MonStgElt, BoolElt
287+
{}
288+
txt := "PuiseuxSeriesRing(%o, %o)";
289+
return Sprintf(txt, Sage(BaseRing(X)), SageNamesHelper(X)), false;
290+
end intrinsic;

src/sage/interfaces/magma.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,28 @@
221221

222222
from sage.structure.parent import Parent
223223
from .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-
229224
from sage.env import SAGE_EXTCODE, DOT_SAGE
230225
import sage.misc.misc
231226
import sage.misc.sage_eval
232227
import sage.interfaces.abc
233228
from sage.interfaces.tab_completion import ExtraTabCompletion
234229
from 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+
236236
INTRINSIC_CACHE = '%s/magma_intrinsic_cache.sobj' % DOT_SAGE
237237
EXTCODE_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
@@ -462,7 +463,7 @@ def _post_process_from_file(self, s):
462463
return ''
463464
return s[i + 1:]
464465

465-
def __getattr__(self, attrname):
466+
def __getattr__(self, attrname) -> MagmaFunction:
466467
"""
467468
Return a formal wrapper around a Magma function, or raise an
468469
:exc:`AttributeError` if attrname starts with an underscore.
@@ -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.\nIN:%s\nOUT:%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
@@ -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

0 commit comments

Comments
 (0)