next up previous contents
Next: Using for loops Up: Common data structures Previous: Common data structures   Contents

Lists, sequences, via for loops

Let's start with lists, sequences, ... in MAGMA. These structures seem to pop up a lot in using programs like MAPLE or GAP, so it may help to see what the syntax is for them first.

The syntax for MAGMA is more complicated than in MAPLE. In MAPLE of GAP, a list is of the form L:=[1,2,3,4];. Lists are entered differently in MAGMA.

According to the MAGMA documentation, ``A list in Magma is an ordered finite collection of objects. Unlike sequences, lists are not required to consist of objects that have some common parent. '' On the other hand, ``A sequence in Magma is a linearly ordered collection of objects belonging to some common structure (called the universe of the sequence). '' So, lists and sequences are different animals to MAGMA. (Lists in MAGMA are of the form <...> and sequences of the form [...]. In MAPLE, a sequence is a list [...] but without the brackets.) However, as this is supposed to be an elementary and basic introduction, we shall not distinguish them at this point. As long as your elements have the same universe, it doesn't matter which one you use.

A sequence (or list) of consecutive integers is easy. For example, the integers from -3 to 101 is constructed by typing

> [-3..101];
Here are some other basic lists (more precisely, in MAGMA, these are sequences):

> List1:=[2^i:i in [1..3]];
> List1;
[ 2, 4, 8 ]
> List2:=[NextPrime(i):i in [1..10]];   
> List2;
[ 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 ]

Pretty simple, right?



Subsections
next up previous contents
Next: Using for loops Up: Common data structures Previous: Common data structures   Contents
David Joyner 2001-08-22