For questions about the composition of functions and relations: If $f\colon A\to B$ and $g\colon B\to C$ are functions, their composition $g\circ f\colon A\to C$ is given by $x\mapsto g(f(x))$. Similarly for $R\subseteq A\times B$ and $S\subseteq B\times C$ the composite relation is defined $S\circ R=\{(a,c); (\exists b\in B) (a,b)\in R \land (b,c)\in S\}$.