# Why is the composition of relations $R$ and $S$ written $S \circ R$ instead of $R \circ S$?

This is really basic (I'm new to this stuff), and doesn't even matter at all - But I'm just curious:

From my book:

If $R = (G,A,B)$ and $S = (H,B,C)$ the composition of $R$ and $S$ is known as $S \circ R = (H \circ G,A,C)$

First of all, if it says "of $R$ and $S$" I'd expect the $R$ to come first, and then the $S$. Which is not the case in $S \circ R$.

Even the graphs are inverted. I would expect $G$ to come first. But we got $(H \circ G,A,C)$.

I can live with that. But I'd like to know why is this the case. Why are they inverted?

-
You are right, it certainly could be done the other way. Some people do. The problem is that the usual left to right convention of European languages does not play well with the function notation. – André Nicolas Dec 5 '12 at 5:59

Composition of relations is a generalization of composition of functions. When we have a function $f:A\to B$ and a function $g:B\to C$, the composite function is a function from $A$ to $C$ that takes $a$ to $g\big(f(a)\big)$, so it makes sense to write the composition in that same order: $g\circ f$ to match $g\big(f(a)\big)$ rather than $f\circ g$ to mean ‘apply $f$ first, then $g$’.

That said, however, it should be mentioned that some people do use the opposite convention for composition: when they write $f\circ g$, they do mean that $f$ is applied first, so that the result of applying $f\circ g$ to $a$ is $g\big(f(a)\big)$. When this convention is used, functions are often written to the right of their arguments: $(a)(f\circ g)=\big((a)f\big)g$. (The parentheses around the argument are often omitted.)

-

Because the argument of a function is usually written to its right. Then it looks like $$(S \circ R)(x) = S(R(x))$$ and function application is right to left.

-

It quite probably originates from function notation: If you have $f:A\to B$ and $g:B\to C$ and want to compose them, you get $g(f(x))$, so $g\circ f:A\to C$. This then got extended to relations and other things. I would personally prefer $f\circ g$ in this case and $xf$ or similar for function application.

-