Introduction

A set in Magma is a (usually unordered) collection of objects belonging to some common structure (called the universe of the set). There are four basic types of sets: enumerated sets, whose elements are all stored explicitly (with one exception, see below); formal sets, whose elements are stored implicitly by means of a predicate that allows for testing membership; indexed sets, which are restricted enumerated sets having a numbering on elements; and multisets, which are enumerated sets with possible repetition of elements. In particular, enumerated sets, indexed sets and multisets are always finite, and formal sets are allowed to be infinite.

Contents

Enumerated Sets

Enumerated sets are finite, and can be specified in three basic ways (see also section 2 below): by listing all elements; by an expression involving elements of some finite structure; and by an arithmetic progression. If an arithmetic progression is specified, the elements are not calculated explicitly until a modification of the set necessitates it; in all other cases all elements of the enumerated set are stored explicitly.

Formal Sets

A formal set consists of the subset of elements of some carrier set (structure) on which a certain predicate assumes the value `true'.

The only set-theoretic operations that can be performed on formal sets are union, intersection, difference and symmetric difference, and element membership testing.

Indexed Sets

For some purposes it is useful to be able to access elements of a set through an index map, which numbers the elements of the set. For that purpose Magma has indexed sets, on which a very few basic set operations are allowed (element membership testing) as well as some sequence-like operations (such as accessing the i-th term, getting the index of an element, appending and pruning).

Multisets

For some purposes it is useful to construct a set with some of its members repeated. For that purpose Magma has multisets, which take into account the repetition of members. The number of times an object x occurs in a multiset S is called the multiplicity of x in S. Magma has the ^^ operator to specify a multiplicity: the expression x^^ n means the object x with multiplicity n. In the following, whenever any multiset constructor or function expects an element y, the expression x^^ n may usually be used.

Compatibility

The binary operators for sets do not allow mixing of the four types of sets (so one cannot take the intersection of an enumerated set and a formal set, for example), but it is easy to convert an enumerated set into a formal set --- see the section on binary operators below --- and there are functions provided for making an enumerated set out of an indexed set or a multiset (and vice versa).

By the limitation on their construction formal sets can only contain elements from one structure in Magma. The elements of enumerated sets are also restricted, in the sense that either some universe must be specified upon creation, or Magma must be able to find such universe automatically. The rules for compatibility of elements and the way Magma deals with these universes are the same for sequences and sets, and are described in the previous chapter. The restrictions on indexed sets are the same as those for enumerated sets.

Notation

Certain expressions appearing in the sections below (possibly with subscripts) have a standard interpretation:

U
the universe: any Magma structure;
E
the carrier set for enumerated sets: any enumerated structure (it must be possible to loop over its elements --- see the Introduction to this Part (Chapter INTRODUCTION TO AGGREGATES));
F
the carrier set for formal sets: any structure for which membership testing using in is defined --- see the Introduction to this Part (Chapter INTRODUCTION TO AGGREGATES));
x
a free variable which successively takes the elements of E (or F in the formal case) as its values;
P
a Boolean expression that usually involves the variable(s) x, x1, ..., xk;
e
an expression that also usually involves the variable(s) x, x1, ..., xk.
V2.28, 13 July 2023