# Forward and backward composition in relational algebra

1. Forward composition: $p\,;q$

$$\forall p,q\cdot p\in S\leftrightarrow T\land q\in T\leftrightarrow U\implies\\p\,;q=\{x\mapsto y\mid(\exists z\cdot x\mapsto z\in p\land z\mapsto y\in q)\}$$

2. Backward composition: $p\circ q$

$$p\circ q=q\,;p$$

I am having trouble understanding what forward composition and backward composition mean. The content above is from my unit notes and I just fail to see any intuition reading it.

Consider two relations $A \leftrightarrow^R B \leftrightarrow^S C$, then forward composition says that for two-elements $a,c$ we have $a (R;S) c$ precisely when there's an intermediary connecting them ---ie $\exists b \in B :: a R b \land b S c$.
For diagram $A \leftrightarrow^R B \leftrightarrow^S C$, it is clear that the composition $R;S$ has type $A \leftrightarrow C$. Whereas the diagram does not immediatly make it clear the type of $S \circ R$ ---this has a more right-to-left flavour of diagram-reading, but English is left-to-right.
It is common to write $xRy$ or $(x,y) \in R$ to mean that $x,y$ are related via relation $R$.