51. Relations
The mathematical concept of relation is an abstraction of the properties of relations such as “=” and “$<$” in much the same way as the modern concept of function was abstracted from the concrete functions considered in freshman calculus, as described in Section 39.8.
51.1 Definition: binary relation
A binary relation $\alpha$ from a set $A$ to a set $B$ is a subset of $A\times B$. If $\langle a,b\rangle \in \alpha$, then one writes $a \alpha b$.
51.1.1 Remark Any subset of $A\times B$ for any sets $A$ and $B$ is a binary relation from $A$ to $B$.
51.1.2 Fact Definition 51.1 gives the following equivalence, which describes two different ways of writing the same thing:
$$a \alpha b \Leftrightarrow \langle a,b\rangle \in \alpha \tag{51.1}$$
51.1.3 Usage A relation corresponds to a predicate with two variables, one of type $A$ and the other of type $B$: the predicate is true if $a \alpha b$ (that is, if $\langle a,b\rangle \in \alpha$) and false otherwise. Logic texts often define a relation to be a predicate of this type, but the point of view taken here (that a relation is a set of ordered pairs) is most common in mathematics and computer science.
51.1.4 Example Let $A = \{ 1, 2, 3, 6\}$ and $B = \{ 1, 2, 3, 4, 5\}$. Then
$$\alpha = \left\{ \langle 2, 2\rangle, \langle 1, 5\rangle, \langle 1, 3\rangle, \langle 2, 5\rangle, \langle 2, 1\rangle \right\}$$
is a binary relation from $A$ to $B$. For this definition, we know $1\,\alpha\, 5$ and $2\,\alpha\, 1$ but it is not true that $1\,\alpha\, 2$.
51.1.5 Exercise Write all ordered pairs in the relation from $A$ to $B$:
a) $A = \{ 1, 2, 3\}$, $B = \{ 1, 3, 5\}$. $\alpha$ is “$\neq$”.
b) $A = \{ 2, 3, 5, 7\}$, $B = \{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\}$, $\alpha$ is “divides”.
c) $A = \{ 0, 1, 2, 3\}$, $B = \{ 1, 2, 3\}$, $\alpha$ is “divides”. (Answer on page 245.)
51.2 Picturing relations
A relation on a small finite set can be exhibited by drawing dots representing the elements of $A$ and $B$ and an arrow from $x$ to $y$ if and only if $x \alpha y$. Here is the relation in Example 51.1.4 exhibited in this way:

Such a picture is called the digraph representing the relation. Digraphs are studied in depth in Chapters 144 and 151.
51.2.1 Example Two not very interesting binary relations from $A$ to $B$ are the empty relation $\emptyset \subseteq A\times B$ and the total relation $A\times B$. If E denotes the empty relation, then $a\,\mathrm{E}\,b$ is false for any $a\in A$ and $b \in B$, and if $T$ denotes the total relation, $a\,\mathrm{T}\,b$ is true for any $a\in A$ and $b \in B$.
51.2.2 Example In a university, the pairs of the form $\langle \text{student, class}\rangle$ where the student is registered for the class form a relation from the set of students to the set of classes.
51.3 Definition: $\operatorname{Rel}(A,B)$
The set of all relations from $A$ to $B$ is denoted by $\operatorname{Rel}(A,B)$.
51.3.1 Remark By Definition 51.1, $\operatorname{Rel}(A,B)$ is the same thing as the powerset $\mathcal{P}(A\times B)$; the only difference is in point of view.
51.4 The projections from a relation
A relation $\alpha$ from $A$ to $B$ is a subset of $A\times B$ by definition, so there are functions $p^{\alpha}_{1}\colon \alpha \to A$, $p^{\alpha}_{2}\colon \alpha \to B$, which are the restrictions of the coordinate functioncoordinate (projection) functions (see 41.1.6, page 63) from $A\times B$ to $A$ and to $B$.
51.4.1 Example If $\alpha$ is defined as in Example 51.1.4, then $p^{\alpha}_{1}\colon \alpha \to \{ 1, 2, 3, 6\}$ and $p^{\alpha}_{2}\colon \alpha \to \{ 1, 2, 3, 4, 5\}$. In particular, $p^{\alpha}_{1}(\langle 1, 5\rangle) = 1$.
Pages 73–74 of the book (PDF).