[Next] [Prev] [Right] [____] [Up] [Index] [Root]
Sequences

Sequences

The Magma category SeqEnum consists of enumerated sequences. A simple example of a sequence is [3, 7, 2].

When creating a sequence, it is preferable to specify its universe, of which all the terms are members, as follows:

  [ Integers() | 3, 7, 2]
  [ Sym(5) | (4, 3, 1), (2, 4)(5, 1) ]

An empty sequence is a sequence with no elements:

  [ UNIVERSE | ] 
A null sequence is an empty sequence with no universe:
  [ ]

The sequence constructor

  [ U | e(x) : x in DOMAIN | P(x) ]
where U is the universe, e(x) and P(x) are expressions in the bound identifier x, and P(x) evaluates to a Boolean, constructs the enumerated sequence containing all e(x) where x is in DOMAIN and P(x) is true. The shorter form
  [ U | e(x) : x in DOMAIN ]
is used when all of DOMAIN is required.

There is also a multivariate version of the sequence constructor:

  [ U | e(x_1, ..., x_n) : 
    x_1 in DOMAIN_1, ..., x_n in DOMAIN_n | 
    P(x_1, ..., x_n) ]
which works similarly.

The arithmetic progression constructor

  [ s .. t by u ]
where s, t, u evaluate to integers returns the sequence [ s, s+u, s+2u, ... , t ]. The shorter form
  [ s .. t ]
returns the sequence [ s, s+1, ... , t ].

The terms of a sequence are ordered, in the order in which they were listed or constructed from a domain. The i-th element of the sequence S is S[i], and the position of element x in S is Index(S, x). S[i] may be assigned the value of EXPRESSION with the statement

  S[i] := EXPRESSION;

A sequence may be recursively defined by means of Self(), which refers to the sequence under construction, and Self(i), which refers to its already-defined i-th term.

The length of a sequence S is #S. This is the index of the last term of S whose value is defined.

Operations on sequences include: Universe, IsNull, IsEmpty, Min, Max, in, notin, IsSubsequence, eq, ne, lt, cat, Include, Exclude, Append, Prune, Insert, Remove, Reverse, Rotate, Sort, &.

Example

> proots := [ z : z in GF(10007) | IsPrimitive(z) ];
> print #proots;
5002
> print proots[17];
41

> S1 := [ 84 .. 27 by -5 ]; > Include(~S1, 72); > print S1; [ 29, 34, 39, 44, 49, 54, 59, 64, 69, 72, 74, 79, 84 ] > print &+S1; 750

> fibo := [ i gt 2 select Self(i-2)+Self(i-1) else 1 : i in [1..100] ]; > print fibo[1..10]; [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ]

[Next] [Prev] [Right] [____] [Up] [Index] [Root]