Magma supports the following categories of sets:
For most purposes, enumerated sets are used. A simple example is {3, 7, 2}.
When creating a set, it is preferable to specify its universe, of which all the elements are members, as follows:
{ Integers() | 3, 7, 2} { Sym(5) | (4, 3, 1), (2, 4)(5, 1) }
An empty set is a set with no elements:
{ UNIVERSE | }A null set is an empty set with no universe:
{ }
The set 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 set 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 set 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 set { s, s+u, s+2u, ... , t }. The shorter form
{ s .. t }returns the set { s, s+1, ... , t }.
Indexed sets are constructed like enumerated sets except that {@ and @} are used instead of { and } . The i-th element of the indexed set S is S[i], and the position of element x in S is Index(S, x). In this they resemble sequences.
Formal sets are constructed in this way:
{! x in DOMAIN | P(x) !}Here DOMAIN may be infinite. They are used for membership and subset testing, by means of the operators in and subset .
Operations on enumerated and indexed sets include:
> proots := {@ z : z in GF(10007) | IsPrimitive(z) @}; > print #proots; 5002 > print proots[17]; 41> S1 := { 84 .. 27 by -5 }; > print Min(S1); 29 > Include(~S1, 72); > print S1; { 29, 34, 39, 44, 49, 54, 59, 64, 69, 72, 74, 79, 84 } > print &+S1; 750
> primes_3_mod_4 := {! n in Integers() | > IsPrime(n) and n mod 4 eq 3 !}; > for i in { 150 .. 180 } do for> if i in primes_3_mod_4 then for|if> print i; for|if> end if; for> end for; 151 163 167 179
[Next] [Prev] [_____] [Left] [Up] [Index] [Root]