TITLE: Composition relation of R1 ∘ R2
QUESTION [6 upvotes]: Let $R_1$ and $R_2$ be the relations on $\{1, 2, 3, 4, 5\}$ defined by
$$R_1 = \{(1,1),(2,3),(2,4),(3,5),(5,2),(5,5)\}$$
$$R_2 = \{(1,1),(2,2),(2,3),(2,5),(4,3),(5,5)\}$$

The answer for this is below but I'm not sure how they arrived at this answer.

Answer:
$$R_2 \circ R_1 = \{(1,1),(2,3),(2,4),(2,5),(4,5),(5,5)\}$$

What I got:
$$R_2 \circ R_1 = \{(1,1),(2,3),(2,4),(2,5),(2,2),(4,5),(5,5)\}$$

REPLY [3 votes]: An alternative is through matrix representations of relations ($a_{ij}=1$ if $(i,j)$ is present in the relation, $0$ otherwise) with composition of relations replaced by matrix product (in the same order as in the composition, with boolean addition convention: $1+1=1$). This can be very useful on a computer. Here, we have :
$$\begin{pmatrix}1&0&0&0&0\\0&1&1&0&1\\0&0&0&0&0\\0&0&1&0&0\\0&0&0&0&1\end{pmatrix}
\times \begin{pmatrix}1&0&0&0&0\\0&0&1&1&0\\0&0&0&0&1\\0&0&0&0&0\\0&1&0&0&1\end{pmatrix}=\begin{pmatrix}1&0&0&0&0\\0&1&1&1&1\\0&0&0&0&0\\0&0&0&0&1\\0&1&0&0&1\end{pmatrix}$$