14.7.4 Other Examples

We compute a space of modular forms with character.

sage: N = 20
sage: D = 20
sage: eps_top = fundamental_discriminant(D)
sage: eps = magma.KroneckerCharacter(eps_top, RationalField())
sage: M2 = magma.ModularForms(eps)
sage: print M2
Space of modular forms on Gamma_1(5) with character $.1, weight 2, and
dimension 2 over Integer Ring.
sage: print M2.Basis()   # note -- this has been changed to be *wrong* as below in Magma 2.14!!
[
1 + 10*q^2 + 20*q^3 + 20*q^5 + 60*q^7 + 50*q^8 + 30*q^10 + O(q^12),
q + q^2 + 2*q^3 + 3*q^4 + 5*q^5 + 2*q^6 + 6*q^7 + 5*q^8 + 7*q^9 + 5*q^10 +
12*q^11 + O(q^12)
]

In SAGE/Python (and sort of C++) coercion of an element x into a structure S is denoted by S(x). This also works for the MAGMA interface:

sage: G = magma.DirichletGroup(20)
sage: G.AssignNames(['a', 'b'])
sage: (G.1).Modulus()
20
sage: e = magma.DirichletGroup(40)(G.1)
sage: print e
$.1
sage: print e.Modulus()
40

We coerce some polynomial rings into MAGMA:

sage: R.<y> = PolynomialRing(QQ)
sage: S = magma(R)
sage: print S
Univariate Polynomial Ring in y over Rational Field
sage: S.1
y

This example illustrates that SAGE doesn't magically extend how MAGMA implicit coercion (what there is, at least) works:

sage: R.<x> = ZZ[]
sage: x * 5
5*x
sage: x * 1.0
1.00000000000000*x
sage: x * (2/3)
2/3*x
sage: y = magma(x)
sage: y * 5
5*x
sage: y * 1.0
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for '*': 'Magma' and 'Real Field
with 53 bits of precision'
sage: y * (2/3)
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for '*': 'Magma' and 'Rational
Field'

Author Log:

Module-level Functions

is_MagmaElement( x)

magma_console( )

magma_version( )

reduce_load_Magma( )

Class: Magma

class Magma
Interface to the Magma interpreter.

Type magma.[tab] for a list of all the functions available from your Magma install. Type magma.[tab]? for Magma's help about a given function. Type magma(...) to create a new Magma object, and magma.eval(...) to run a string using Magma (and get the result back as a string).

NOTE: If you do not own a local copy of MAGMA, try using the magma_free command instead, which uses the free demo web interface to MAGMA.

You must use nvals = 0 to call a function that doesn't return anything, otherwise you'll get an error. (nvals is the number of return values.)

sage: magma.SetDefaultRealFieldPrecision(200, nvals=0)  # optional and requires MAGMA >= v2.12
sage: magma.eval('1.1')   # optional
'1.100000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000'
sage: magma.SetDefaultRealFieldPrecision(30, nvals=0)  # optional
Magma( self, [maxread=10000], [script_subdirectory=None], [logfile=None], [server=None], [server_tmpdir=None], [user_config=False])

Input:

maxread
- affects buffering
script_subdirectory
- directory where scripts are read from
logfile
- output logged to this file
server
- address of remote server
user_config
- if True, then local user configuration files will be read by MAGMA. If False (the default), then MAGMA is started with the -n option which supresses user configuration files.

Functions: Attach,$ \,$ attach,$ \,$ attach_spec,$ \,$ AttachSpec,$ \,$ chdir,$ \,$ console,$ \,$ cputime,$ \,$ eval,$ \,$ function_call,$ \,$ get,$ \,$ get_verbose,$ \,$ GetVerbose,$ \,$ help,$ \,$ ideal,$ \,$ load,$ \,$ objgens,$ \,$ set,$ \,$ set_verbose,$ \,$ SetVerbose,$ \,$ trait_names,$ \,$ version

Attach( self, filename)

Attach the given file to the running instance of MAGMA.

Attaching a file in MAGMA makes all intrinsics defined in the file available to the shell. Moreover, if the file doesn't start with the freeze; command, then the file is reloaded whenever it is changed. Note that functions and procedures defined in the file are not available. For only those, use magma.load(filename).

attach( self, filename)

Attach the given file to the running instance of MAGMA.

Attaching a file in MAGMA makes all intrinsics defined in the file available to the shell. Moreover, if the file doesn't start with the freeze; command, then the file is reloaded whenever it is changed. Note that functions and procedures defined in the file are not available. For only those, use magma.load(filename).

attach_spec( self, filename)

Attach the given spec file to the running instance of MAGMA.

This attaches numerous files to the running MAGMA (see the MAGMA documentation for more details).

AttachSpec( self, filename)

Attach the given spec file to the running instance of MAGMA.

This attaches numerous files to the running MAGMA (see the MAGMA documentation for more details).

chdir( self, dir)

Change to the given directory.

eval( self, x, [strip=True])

Input:

x
- string of code
strip
- ignored

get( self, var)

Get the value of the variable var.

get_verbose( self, type)

Get the verbosity level of a given algorithm class etc. in MAGMA.

Input:

type
- string (e.g. 'Groebner'), see MAGMA documentation

GetVerbose( self, type)

Get the verbosity level of a given algorithm class etc. in MAGMA.

Input:

type
- string (e.g. 'Groebner'), see MAGMA documentation

NOTE: This method is provided to be consistent with the MAGMA naming convention.

ideal( self, L)

Return the MAGMA ideal defined by L.

Input:

L
- a list of elements of a SAGE multivariate polynomial ring.

Output: The magma ideal generated by the elements of L.

sage: R.<x,y> = QQ[]
sage: magma.ideal([x^2, y^3*x])         # optional -- requires magma
Ideal of Polynomial ring of rank 2 over Rational Field
Graded Reverse Lexicographical Order
Variables: x, y
Basis:
[
x^2,
x*y^3
]

load( self, filename)

Load the file with given filename using the 'load' command in the MAGMA shell.

Loading a file in MAGMA makes all the functions and procedures in the file available. The file should not contain any intrinsics (or you'll get errors).

set( self, var, value)

Set the variable var to the given value.

set_verbose( self, type, level)

Set the verbosity level for a given algorithm, class, etc. in MAGMA.

Input:

type
- string (e.g. 'Groebner')
level
- integer >= 0

SetVerbose( self, type, level)

Set the verbosity level for a given algorithm class etc. in MAGMA.

Input:

type
- string (e.g. 'Groebner'), see MAGMA documentation
level
- integer >= 0

NOTE: This method is provided to be consistent with the MAGMA naming convention.

Special Functions: __call__,$ \,$ __init__,$ \,$ __reduce__,$ \,$ _assign_symbol,$ \,$ _continuation_prompt,$ \,$ _equality_symbol,$ \,$ _false_symbol,$ \,$ _greaterthan_symbol,$ \,$ _left_list_delim,$ \,$ _lessthan_symbol,$ \,$ _next_var_name,$ \,$ _object_class,$ \,$ _post_process_from_file,$ \,$ _read_in_file_command,$ \,$ _right_list_delim,$ \,$ _start,$ \,$ _true_symbol

__call__( self, x, [gens=None])

sage: magma(EllipticCurve('37a'))                   # optional
Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
sage: magma('EllipticCurve([GF(5)|1,2,3,4,1])')     # optional
Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 1 over
GF(5)
sage: magma('PowerSeriesRing(Rationals())', 't')    # optional
Power series ring in t over Rational Field
sage: magma('PolynomialRing(RationalField(), 3)', 'x,y,z')  # optional
Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: x, y, z

Class: MagmaElement

class MagmaElement

Functions: assign_names,$ \,$ AssignNames,$ \,$ eval,$ \,$ evaluate,$ \,$ gens,$ \,$ get_magma_attribute,$ \,$ list_attributes,$ \,$ methods,$ \,$ set_magma_attribute,$ \,$ trait_names,$ \,$ x__iter__

assign_names( self, names)

sage: G = magma.DirichletGroup(20)   # optional
sage: G.AssignNames(['a','b'])       # optional
sage: G.1                            # optional
a

sage: G.Elements()                   # optional
[
1,
a,
b,
a*b
]

AssignNames( self, names)

sage: G = magma.DirichletGroup(20)   # optional
sage: G.AssignNames(['a','b'])       # optional
sage: G.1                            # optional
a

sage: G.Elements()                   # optional
[
1,
a,
b,
a*b
]

gens( self)

Return generators for self.

If self is named X is MAGMA, this function evaluates X.1, X.2, etc., in MAGMA until an error occurs. It then returns a SAGE list of the resulting X.i. Note - I don't think there is a MAGMA command that returns the list of valid X.i. There are numerous ad hoc functions for various classes but nothing systematic. This function gets around that problem.

Author Log:

methods( self, [any=False])

Return all MAGMA intrinsics that can take self as the first argument.

Input:

any
- (bool: default is False) if True, also include signatures with <Any> as first argument.

Special Functions: __call__,$ \,$ __floordiv__,$ \,$ __iter__,$ \,$ __len__,$ \,$ _latex_,$ \,$ _polynomial_,$ \,$ _sage_

__call__( self)

Coerce something into the object (using the MAGMA ! notation).

For function calls, use self.eval(...).

sage: M = magma.RMatrixSpace(magma.IntegerRing(), 2, 2)  # optional
sage: A = M([1,2,3,4]); A        # optional
[1 2]
[3 4]
sage: type(A)                    # optional
<class 'sage.interfaces.magma.MagmaElement'>  
sage: A.Type()                   # optional
ModMatRngElt

__floordiv__( self, x)

Quotient of division of self by other. This is denoted // ("div" in magma).

sage: R.<x,y,z>=QQ[]
sage: magma(5)//magma(2) # optional
2
sage: m=magma(x*z+x*y)   # optional
sage: n=magma(x)         # optional 
sage: m//n               # optional
y + z

_latex_( self)

Return latex representation of self.

Author: Jennifer Balakrishnan (jenb@mit.edu)

Types that are nicely latex include:

IMPLEMENTATION: Calls latex.m, which is in SAGE_ROOT/data/extcode/magma/latex.m

sage: latex(magma('-2/3'))                            # optional
\frac{-2}{3}

sage: magma.eval('R<x> := PolynomialRing(RationalField()); f := (x-17/2)^3;')     # optional
''
sage: latex(magma('f'))                               # optional
x^{3}-\frac{51}{2}x^{2}+\frac{867}{4}x-\frac{4913}{8}

sage: latex(magma('(MatrixAlgebra(RationalField(),3)![0,2,3,4,5,6,7,8,9])^(-1)'))    # optional
\left(\begin{array}{ccc}-1\&2\&-1\\2\&-7\&4\\-1\&\frac{14}{3}\&\frac{-8}{3}
\end{array}\right)

sage: magma.eval('K<a> := CyclotomicField(11)')       # optional
''
sage: latex(magma('a^3 + a - 17/3'))                  # optional
\frac{-17}{3}+\zeta_{11}+\zeta_{11}^{3}

sage: latex(magma('EllipticCurve([1,2/3,3/4,4/5,-5/6])'))    # optional
y^2+xy+\frac{3}{4}y=x^3+\frac{2}{3}x^2+\frac{4}{5}x-\frac{5}{6}

sage: _=magma.eval('R<x> := PolynomialRing(RationalField())')    # optional
sage: _=magma.eval('K<a> := NumberField(x^3+17*x+2)')            # optional
sage: latex(magma('(1/3)*a^2 - 17/3*a + 2'))                     # optional
2-\frac{17}{3}a+\frac{1}{3}a^{2}

SAGE auto-detects the greek letters and puts backslashes in:

sage: _=magma.eval('R<x> := PolynomialRing(RationalField())')    # optional
sage: _=magma.eval('K<alpha> := NumberField(x^3+17*x+2)')        # optional
sage: latex(magma('(1/3)*alpha^2 - 17/3*alpha + 2'))             # optional
2-\frac{17}{3}\alpha+\frac{1}{3}\alpha^{2}

sage: _=magma.eval('R<alpha> := PolynomialRing(RationalField())') # optional
sage: latex(magma('alpha^3-1/7*alpha + 3'))                      # optional
\alpha^{3}-\frac{1}{7}\alpha+3

Finite field elements:

sage: _=magma.eval('K<a> := GF(27)')                             # optional
sage: latex(magma('a^2+2'))                                      # optional
2+a^{2}

Printing of unnamed (dollar sign) generators works correctly:

sage: latex(magma('FiniteField(81).1^2+1'))                      # optional
1+\$.1^{2}

Finite fields:

sage: latex(magma('FiniteField(3)'))                             # optional
\mathbf{F}_{{3}}
sage: latex(magma('FiniteField(27)'))                            # optional
\mathbf{F}_{{3}^{3}}

Power Series:

sage: _=magma.eval('R<x> := PowerSeriesRing(RationalField())')   # optional
sage: latex(magma('(1/(1+x))'))                                  # optional
1-x+x^{2}-x^{3}+x^{4}-x^{5}+x^{6}-x^{7}+x^{8}-x^{9}+x^{10}-x^{11}+x^{12}-x^
{13}+x^{14}-x^{15}+x^{16}-x^{17}+x^{18}-x^{19}+O(x^{20})
sage: _=magma.eval('R<x> := PowerSeriesRing(RationalField())')   # optional
sage: latex(magma('(-1/(2+x + O(x^3)))'))                        # optional
\frac{-1}{2}+\frac{1}{4}x-\frac{1}{8}x^{2}+O(x^{3})

p-adic Numbers:

sage: latex(magma('pAdicField(7,4)!9333294394/49'))              # optional
4\cdot{}7^{-2} + 5\cdot{}7^{-1} + 5+ 6\cdot{}7^{1} + O(7^{2})

_sage_( self)

Return Sage version of this object.

Use the sage_eval method to call this.

Enumerated Sets:

sage: a = magma('{1,2/3,-5/9}')       # optional
sage: sage_eval(a)                    # optional
{1, -5/9, 2/3}
sage: type(sage_eval(a))              # optional
<class 'sage.sets.set.Set_object_enumerated'>
sage: a = magma('{1,2/3,-5/9}'); a    # optional
{ -5/9, 2/3, 1 }
sage: a.Type()                        # optional
SetEnum
sage: b = sage_eval(a); b             # optional
{1, -5/9, 2/3}
sage: type(b)                         # optional
<class 'sage.sets.set.Set_object_enumerated'>
sage: c = magma(b); c                 # optional
{ -5/9, 2/3, 1 }
sage: c.Type()                        # optional
SetEnum

Multisets are converted to lists:

sage: m = magma('{* 1,2,2,2,4^^2,3 *}')    # optional 
sage: z = m.sage(); z                      # optional
[1, 2, 2, 2, 3, 4, 4]
sage: type(z)                              # optional
<type 'list'>

Matrices:

sage: a = matrix(ZZ,3,3,[1..9])           
sage: m = magma(a)                        # optional
sage: b = m.sage(); b                     # optional
[1 2 3]
[4 5 6]
[7 8 9]
sage: b == a                             # optional
True

A nonsquare matrix:

sage: a = matrix(ZZ,2,3,[1..6])
sage: m = magma(a)                       # optional
sage: m.sage()                           # optional
[1 2 3]
[4 5 6]

Class: MagmaFunction

class MagmaFunction

Special Functions: __call__,$ \,$ _sage_doc_

Class: MagmaFunctionElement

class MagmaFunctionElement

Special Functions: __call__,$ \,$ __repr__,$ \,$ _sage_doc_

See About this document... for information on suggesting changes.