About
Calculator
Ordering
FAQ
Download
Download Magma
Databases
User Contributions
Documentation
Handbook
Overview
Release Notes
Discovering Maths with Magma
First Steps in Magma (pdf)
Solving Problems with Magma (pdf)
Acknowledgements
Citations
Conferences
Links
Contact
CAG
Login
Magma
Computer • algebra
Documentation
Up
Contents
Index
Search
Expand all
Collapse all
Introduction
Starting, Interrupting and Terminating
<Ctrl>-C
quit;
<Ctrl>-\
Identifiers
Assignment
Simple Assignment
x := expression;
Example
State_Identifiers (H1E1)
x
1
, x
2
, ..., x
n
:= expression;
_ := expression;
assigned x : Var -> BoolElt
Example
State_MultipleReturns (H1E2)
Indexed Assignment
x[expr
1
][expr
2
]...[expr
n
] := expression;
Example
State_Indexing (H1E3)
Generator Assignment
E<x
1
, x
2
, ...x
n
> := expression;
E<[x]> := expression;
Example
State_GeneratorNamingSequence (H1E4)
AssignNames(~S, [s
1
, ... s
n
] ) : Str, [ MonStgElt ] ->
Example
State_GeneratorNaming (H1E5)
Mutation Assignment
x o:= expression;
Example
State_MutationAssignment (H1E6)
Deletion of Values
delete x : Var ->
Boolean Values
Creation of Booleans
Booleans() : -> Bool
# B : Bool -> RngIntElt
true
Random(B) : Bool -> BoolElt
Boolean Operators
x and y : BoolElt, BoolElt -> BoolElt
x or y: BoolElt, BoolElt -> BoolElt
x xor y: BoolElt, BoolElt -> BoolElt
not x : BoolElt -> BoolElt
Equality Operators
x eq y : Any, Any -> BoolElt
x ne y : Any, Any -> BoolElt
x cmpeq y : Any, Any -> BoolElt
x cmpne y : Any, Any -> BoolElt
Example
State_Equality (H1E7)
Iteration
Example
State_Booleans (H1E8)
Coercion
S ! x : Str, Elt -> Elt
IsCoercible(S, x) : Str, Elt -> Bool, Elt
The
where ... is
Construction
expression
1
where identifier is expression
2
Example
State_where (H1E9)
Conditional Statements and Expressions
The Simple Conditional Statement
if-then-else
elif
Example
State_if (H1E10)
The Simple Conditional Expression
Example
State_InLineConditional (H1E11)
The Case Statement
case expr : when expr
i
: statements end case : ->
Example
State_case (H1E12)
The Case Expression
case< expr | expr
left, 1
: expr_((right), 1), ..., expr_((left), n) : expr_((right), n), default : expr
def
> : ->
Error Handling Statements
The Error Objects
Error(x) : Any -> Err
e`Position : Err -> MonStgElt
e`Traceback : Err -> MonStgElt
e`Object : Err -> Any
e`Type : Err -> MonStgElt
Error Checking and Assertions
error expression, ..., expression;
error if boolexpr, expression, ..., expression;
assert boolexpr;
Catching Errors
try statements catch e statements end try : ->
Example
State_while (H1E13)
Iterative Statements
Definite Iteration
for i := expr
1
to expr
2
by expr
3
do
for
Indefinite Iteration
while
Example
State_while (H1E14)
repeat-until
Example
State_repeat (H1E15)
forrandom
Dual Iteration
for
forrandom
Early Exit from Iterative Statements
Example
State_break (H1E16)
Runtime Evaluation: the eval Expression
eval expression
Example
State_eval1 (H1E17)
Example
State_eval2 (H1E18)
Comments and Continuation
//
/* */
\
Example
State_Various (H1E19)
Timing
Cputime() : -> FldReElt
Cputime(t) : FldReElt -> FldReElt
Realtime() : -> FldReElt
Realtime(t) : FldReElt -> FldReElt
ClockCycles() : -> RngIntElt
Time() : -> MonStgElt
Time(T) : MonStgElt -> MonStgElt
time statement;
vtime flag: statement;
SetShowRealTime(v) : BoolElt ->
GetShowRealTime() : -> BoolElt
Example
State_Time (H1E20)
Example
State_TimeMultiThreaded (H1E21)
Types, Category Names, and Structures
Type(x) : Elt -> Cat
ExtendedType(x) : Elt -> ECat
ISA(T, U) : Cat, Cat -> BoolElt
MakeType(S) : MonStgElt -> Cat
ElementType(S) : Str -> Cat
CoveringStructure(S, T) : Str, Str -> Str
ExistsCoveringStructure(S, T) : Str, Str -> BoolElt, Str
Example
State_TypeStructures (H1E22)
Random Object Generation
SetSeed(s, c) : RngIntElt, RngIntElt ->
GetSeed() : -> RngIntElt, RngIntElt
Random(S) : Str -> Elt
Random(a, b) : RngIntElt, RngIntElt -> RngIntElt
Random(b) : RngIntElt -> RngIntElt
Example
State_IsIntrinsic (H1E23)
Miscellaneous
IsIntrinsic(S) : MonStgElt -> Bool, Intrinsic
Example
State_IsIntrinsic (H1E24)
Bibliography
Up
Contents
Index
Search
V2.28, 28 February 2025