What we've referred to up until now as ``sets'' and ``relations'' are
implemented as a single class, ` Relation`
. Each relation is
marked as being either a set or a relation. Most functions on
relations don't care whether they operate on sets or relations, but
some require either a set or a relation, and they will check.

We provide the following constructors for ` Relation`
s:

`Relation()`

This is a default constructor for the class. Relations created this way are known as null relations and must be assigned a value before they can be used. This constructor is provided to allow the creation of arrays of relations.`Relation(int n_input, int n_output);`

This constructor creates a relation with`n_input`input variables and`n_output`output variables. It can't be used in any functions yet, because it doesn't have a Presburger formula to describe which tuples it contains.`Relation(Non_Coercible<int> nci);`

This constructor creates a set. In normal use, you should pass an`int`to this function to get a set with that many variables in its tuple. (The class`Non_Coercible<int>`is used as a C++ trick so that you couldn't, for example, pass an`int`to a function expecting a`Relation`, and have the compiler construct a`Relation`from it on the fly.)`Relation(const Relation &r, Conjunct *c)`

This is used to create a relation by copying a conjunction of constraints**c**, from some other relation**r**. Conjuncts are created when a relation is simplified into disjunctive normal form and will be described in Chapter 5.

The input, output, or set variables can be given names:

`void Relation::name_input_var(int nth, String s)`

Set the name of the`nth`input variable to`s`.`void Relation::name_output_var(int nth, String s)`

Set the name of the`nth`output variable to`s`.`void Relation::name_set_var(int nth, String s)`

Set the name of the`nth`set variable to`s`.

If you don't name the variables yourself, each variable will get a name that depends on its position in the input or output tuple. If two variables in the same relation are given the same name, the print functions will add ``primes'' to one of them to distinguish them.

The following are some simple functions that extract information about a set or relation:

`bool Relation::is_set()`

Return true if the relation is a set, false if it is a relation.`int Relation::n_inp()`

Find out how many variables are in a relation's input tuple.`int Relation::n_out()`

Find out how many variables are in a relation's output tuple.`int Relation::n_set()`

Find out how many variables are in a set's tuple.

**Figure 4.1:** Example, Part 1: Declaring Relations and Variables

The first six lines of Figure 4.1 show how the
` Relation`
constructors and some of the functions above are used
to create the relations in our examples.

omega@cs.umd.edu