Traps for Young Players

This section describes the two most common sources of confusion encountered when using Magma's evaluation strategy.

Contents

Trap 1

We boot Magma. It begins with an initial context something like [ ..., ('+',A), ('-',S), ... ] where A is the (function) value that is the addition function, and S is the (function) value that is the subtraction function.

Now say we type,

> '+' := '-';
> 1 + 2;
Magma will respond with the answer -1.

To see why this is so consider the effect of each line on the current context. After the first line the current context will be [ ..., ('+',S), ('-',S), ... ], where S is as before. The identifier + has been re-assigned. Its new value is the value of the identifier '-' in the current context, and the value of '-' is the (function) value that is the subtraction function. Hence in the second line when Magma replaces the identifier + with its value in the current context, the value that is substituted is therefore S, the subtraction function!

Trap 2

Say we type,

> f := func< n | n + 1 >;
> g := func< m | m + f(m) >;
After the first line the current context is [ (f,FUNC( n : n+1)) ]. After the second line the current context is [ (f,FUNC( n : n+1)), (g,FUNC(m : m + FUNC(n : n+1)(m))) ].

If we now type,

> g(6);
Magma will respond with the answer 13.

Now say we decide that our definition of f is wrong. So we now type in a new definition for f as follows,

> f := func< n | n + 2 >;
If we again type,
> g(6);
Magma will again reply with the answer 13!

To see why this is so consider how the current context changes. After typing in the initial definitions of f and g the current context is [ (f, FUNC(n : n+1)), (g, FUNC(m : m + FUNC(n : n+1)(m))) ]. After typing in the second definition of f the current context is [ (f, FUNC(n : n+2)), (g, FUNC(m : m + FUNC(n : n+1)(m)))]. Remember that changing the value of one identifier, in this case f, does not change the value of any other identifiers, in this case g! In order to change the value of g to reflect the new value of f, g would have to be re-assigned.

V2.28, 13 July 2023