Identifiers (names for user variables, functions etc.) must begin with a letter, and this letter may be followed by any combination of letters or digits, provided that the name is not a reserved word (see the Appendix for a list of reserved words). In this definition the underscore _ is treated as a letter; but note that a single underscore is a reserved word. Identifier names are case-sensitive, that is, they are distinguished from one another by lower and upper case.
Intrinsic Magma functions usually have names beginning with capital
letters (current exceptions are pCore, pQuotient and the like, where the
p indicates a prime).
Note that these identifiers are not reserved words,
that is, one may use names of intrinsic functions for variables.
Assignment and Deletion
Here, we describe the basic forms of assignment to and deletion of
variables.
x := expression;
This is the basic form of assignment of a single value to a single variable. Here x may be any identifier, and expression must be a legal Magma expression returning a value.
> x := 13; > y := x^2-2; > print x, y; 13 167Intrinsic function names are identifiers just like the x and y above. Therefore it is possible to reassign them to your own variable.
> f := PreviousPrime; > print f(y); 163In fact, the same can also be done with the infix operators, except that it is necessary to enclose their names in quotes. Thus it is possible to define your own function Plus to be the function taking the arguments of the intrinsic + operator.
> Plus := '+'; > print Plus(1/2, 2); 5/2Note that redefining the infix operator will not change the corresponding mutation assignment operator (in this case +:=).
Assignment of n >= 1 values, returned by the expression on the right hand side. Here the x_i are identifiers, and the right hand side expression must return m >= n values; the first n of these will be assigned to x_1, x_2, ..., x_n respectively.
Ignore the value(s) returned by the expression on the right hand side.
> d := Xgcd(12, 15);To obtain the multipliers as well, type
> d, x, y := Xgcd(12, 15);while the following offers ways to retrieve two of the three return values.
> d, x := Xgcd(12, 15); > d, _, y := Xgcd(12, 15); > _, x, y := Xgcd(12, 15);
If the argument on the left hand side allows indexing at least n levels deep, and if this indexing can be used to modify the argument, this offers two equivalent ways of accessing and modifying the entry indicated by the expressions expr_i. The most important case is that of (nested) sequences.
> s := [ [1], [1, 2], [1, 2, 3] ];
> print s;
[
[ 1 ],
[ 1, 2 ],
[ 1, 2, 3 ]
]
> s[2, 2] := -1;
> print s;
[
[ 1 ],
[ 1, -1 ],
[ 1, 2, 3 ]
]
If the right hand side expression returns a structure that allows naming of `generators', such as finitely generated groups or algebras, polynomial rings, this assigns the first n names to the variables x_1, x_2, ..., x_n. Naming of generators usually has two aspects; firstly, the strings x_1, x_2, ...x_n are used for printing of the generators, and secondly, to the identifiers x_1, x_2, ...x_n are assigned the values of the generators. Thus, except for this side effect regarding printing, the above assignment is equivalent to the n + 1 assignments:
E := expression; x_1 := E.1; x_2 := E.2; ... x_n := E.n;
Procedure. If S is a structure that allows naming of `generators' (see the Appendix for a complete list), this assigns the names specified by the strings to these generators. The number of generators has to match the length of the sequence. This will result in the creation of a new structure.
> R<x, y> := PolynomialAlgebra( Integers(), 2 ); > f := x^2 + y^2; > print f; y^2 + x^2 > AssignNames(~R, ["a", "b"]); > print R; Polynomial ring : Integer Ring[a][b] > print f; y^2 + x^2 > print Parent(f); Polynomial ring : Integer Ring[x][y] > print Parent(f) eq R; false
This is the mutation assignment: the expression is evaluated and the operator o is applied on the result and the current value of x, and assigned to x again. So the result is equivalent to (but an optimized version of): x := x o expression;. The operator may be any of the operations join, meet, diff, sdiff, cat, *, +, -, /, ^, div, mod, and, or, xor provided that the operation is legal on its arguments of course.
> x := 1;
> S := { };
> for i := 1 to 10 do
> S join:= { x };
> x *:= 2;
> end for;
> print S;
{ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }
(Statement.) Delete the current value of the identifier x. The memory occupied is freed, unless other variables still refer to it. If x is the name of an intrinsic Magma function that has been reassigned to, the identifier will after deletion again refer to that intrinsic function. Intrinsic functions cannot be deleted.
Returns true if the `local' x has a current value, that is, if x has been assigned to and its value has not been deleted after that; otherwise it returns false. (This will return false for intrinsic function names, since they are not `local'.)[Next] [Prev] [Right] [Left] [Up] [Index] [Root]