Guide

Syntax

The following tables gives the mapping between Magma and Julia syntax.

MagmaJulia
r := Intrinsic(x, y: opt:=z)r = magf.Intrinsic(x, y, opt=z)
r, s := Intrinsic(x)r, s = magf2.Intrinsic(x)
R<x,y> := Intrinsic(p, q)R, x, y = magg.Intrinsic((:x, :y), p, q)
IntrinsicProcedure(x)magp.IntrinsicProcedure(x)
IntrinsicProcedure(~x, y)magp1.IntrinsicProcedure(x, y) or magp.IntrinsicProcedure(MagmaRef(x), y)
SomeTypemagt.SomeType
x + ymagadd(x, y) or x + y
x - ymagsub(x, y) or x - y
x * ymagmul(x, y) or x * y
x / ymagtruediv(x, y) or x / y
x ^ ymagpow(x, y) or x ^ y
x diff ymagdiff(x, y) or setdiff(x, y)
x div ymagdiv(x, y) or div(x, y)
x join ymagjoin(x, y) or union(x, y)
x meet ymagmeet(x, y) or intersect(x, y)
x mod ymagmod(x, y) or mod(x, y)
x sdiff ymagsdiff(x, y) or symdiff(x, y)
x cat ymagcat(x, y) or cat(x, y)
x eq ymageq(x, y) or x == y
x ne ymagne(x, y) or x != y
x cmpeq ymagcmpeq(x, y)
x cmpne ymagcmpne(x, y)
x le ymagle(x, y) or x <= y
x lt ymaglt(x, y) or x < y
x ge ymagge(x, y) or x >= y
x gt ymaggt(x, y) or x > y
x in ymagin(x, y) or x in y
x notin ymagnotin(x, y)
x adj ymagadj(x, y)
x notadj ymagnotadj(x, y)
x subset ymagsubset(x, y) or issubset(x, y)
x notsubset ymagnotsubset(x, y)
&+ xmagsum(x) or sum(x)
&* xmagprod(x) or prod(x)
&and xmagreduceand(x)
&or xmagreduceor(x)
&join xmagreducejoin(x)
&meet xmagreducemeet(x)
&cat xmagreducecat(x)
[* a, b, c *]maglist((a, b, c))
< a, b, c >magtuple((a, b, c))
[ a, b, c ]magseq((a, b, c))
[ U | a, b, c ]magseq((a, b, c), universe=U)
[ a..b by c]magseq(a:c:b)
{ a, b, c }magset((a, b, c))
{* a, b, c *}magmset((a, b, c))
{@ a, b, c @}magiset((a, b, c))
print xmagprint(io, x)
print x: Magmamagprint(io, x, :magma)
Sprint(x, "Magma")magsprint(x, :magma)
x[i, j]maggetindex(x, i, j) or x[i, j]
x[i, j] := ymagsetindex!(x, y, i, j) or x[i, j] = y
# xmaglength(x) (or length(x) provided the result is an integer)
x @ fmagimage(x, f)
x @@ fmagpreimage(x, f)
S ! xmagcoerce(S, x)
S.nmaggen(S, n)
x`attrmaggetattr(x, :attr) or x.attr
x`attr := ymagsetattr!(x, :attr, y) or x.attr = y
recformat<r, s:RngInt>magrecformat(:r, :s=>:RngInt)
rec<fmt | r:=x>magrec(fmt, r=x)
? querymaghelp("query")
...any expression...mag"..." (supporting $ interpolation)

Conversion to Magma

When passed as arguments to Magma functions the following conversions are made from Julia types to Magma types:

JuliaMagma
BoolBoolElt
IntegerRngIntElt
RationalFldRatElt
RealFldReElt
ComplexFldComElt
AbstractStringMonStgElt
AbstractCharMonStgElt of length 1
AbstractVectorSeqEnum
AbstractSetSetEnum
AbstractDictAssoc
TupleTup
NamedTupleRec

Conversion to Julia

Call magconvert(T, x) to convert the Magma value x to a Julia T.

The following table gives the supported conversions. These are in preference order: the first type in each row that is a subtype of T is the return type from magconvert.

MagmaJulia
RngIntElt (integer)BigInt, Int, UInt, Integer, Rational, Real, MagmaOTPInteger
FltRatElt (rational)Rational, Real, MagmaOTPRational
MonStgElt (string)String, AbstractString, Char, AbstractChar, Vector{UInt8}, AbstractVector{UInt8}, MagmaOTPString
List (list)Vector, AbstractVector, MagmaOTPList
SeqEnum (sequence)Vector, AbstractVector, MagmaOTPSequence
SetEnum (set)Set, AbstractSet, Vector, AbstractVector, MagmaOTPSet

For sequences and sets, the result depends on whether it is a null sequence/set (in which case MagmaOTPNullSequence might be returned) or is a range (in which case a StepRangeLen is the preferred return type, and MagmaOTPRangeSequence is the least preferred).

The MagmaOTP* types are exact representations of objects from the Magma Object Transfer Protocol. They are all subtypes of MagmaOTPValue. They have no extra semantics, so are always the least-preferred option. Not included in the table are structures themselves (e.g. RngInt (ring of integers), MonStg (strings)) which are always converted to a corresponding MagmaOTPStr.

Calling functions and procedures

In Magma, there is no syntactic difference between function calls and procedure calls, so in MagmaCall, we must make the distinction explicit.

The simplest way to call an intrinsic function is to use the syntax magf.Intrinsic(...). Similarly magp.Intrinsic(...) is a procedure call (returning nothing) and magf2.Intrinsic(...) is a function call returning a pair of values.

For each "calling convention" C in the following table, there is a corresponding magC object which can be accessed in this way.

ConventionInterpretation
pProcedure call. Return nothing.
fFunction call. Return a MagmaObject.
fNFunction call with N return values. Return a tuple of MagmaObject.
iFunction call returning an integer. Return an Int.
bFunction call returning a boolean. Return a Bool.
gFunction call with generators, so that R, x, y = magg.Intrinsic((:x, :y), ...) is equivalent to R<x,y> := Intrinsic(...) in Magma.
mFunction call returning a bool and a value. Return nothing if the bool is false, else the value.
pNProcedure call, passing the Nth argument by reference. Return nothing.

The way this works is that magC.Intrinsic is a MagmaCallable{:C}, which is a MagmaValue with function call syntax overloaded, so that magC.Intrinsic(...) is equivalent to magcall(Val(:C), magC.Intrinsic, ...). magcall is the worker function where calling conventions are implemented.

If you have a Magma value f and need to call it, then f(...) will not work because the desired calling convention is unknown. Instead, use magcall(Val(:C), f, ...) or magcallC(f, ...). Alternatively, you can explicitly wrap it as MagmaCallable{:C}(f) and call that.

Note also that mag"..."C is equivalent to MagmaCallable{:C}(mag"...").

The following are equivalent:

magf.PolynomialRing(Z)
magcallf(:PolynomialRing, Z)
magcall(Val(:f), :PolynomialRing, Z)
MagmaCallable{:f}(MagmaIntrinsic(:PolynomialRing))(Z)
mag"PolynomialRing"f(Z)
mag"PolynomialRing($Z)"