[Next] [Prev] [Right] [Left] [Up] [Index] [Root]
Expression

Expression

An expression is anything which Magma can evaluate to get a value. It is used to define or specify objects.

The simplest kind of expression is a constant or identifier. Its value is the constant's value, or the current value of the identifier.

Expressions can also be built from smaller expressions, using operators or functions, according to rules which are very similar to those used in algebra. Conventional rules of operator precedence apply. Apart from this, evaluation is from left to right, except when parentheses ( ) indicate a different order of evaluation.

Magma employs call-by-value evaluation, that is, it evaluates every one of the smaller expressions in order to find the final value, whether this is necessary or not. For instance, to evaluate 0 * (45 ^ 2687) Magma has to find the values of both 0 and (45 ^ 2687) before doing the multiplication, although the presence of 0 in the product means that the result must be 0. The same applies to the evaluation of function arguments as to the evaluation of operands, because Magma considers operators to be infix functions.

The only exceptions to call-by-value evaluation are the operators `and', `or', and `select'. These short-circuit operators use call-by-name evaluation, only evaluating their operands as required. The operator `select' evaluates the Boolean condition, then whichever of the two expressions is required. The operators `and' and `or' evaluate from left to right, stopping as soon as the result is determined.

Example

42

t // where t has been assigned

13 + 9 * (27 - 8)

IsEven(n) and not finished // where identifiers n and finished have suitable values

Centralizer(G, g) // where g is an element of the group G

> print true or 14; // NOT an error true

Subscreens
[Next] [Prev] [Right] [Left] [Up] [Index] [Root]