# Notation for the composition of functions and relations.

Given any functions $f$ and $g$ the function $h(x)=f(g(x))$ is well defined with:

$$\text{dom}(h)=g^{-1}[\text{dom}(f)\cap \text{img}(g)]$$ $$\text{img}(h)=f[\text{dom}(f)\cap \text{img}(g)]$$

However based on the answer to my question here:

When is composition of functions defined?

It seems it would not be proper to normally write $h=f\circ g$.

My new question is why this is still used for the composition of binary relations as seen here:

What is the composition of relations like this? With no transitive relations between them?

Where the range of the first relation is not equal to the domain of the second relation. Yet the composition appears to still be well defined? Transferring over that notation it would seem that it would actually make sense to write $h=f\circ g$? Why is the definition of composition defined differently for relations then if we consider a function a relation?

Even though functions are normally defined as a special case of relation the relevant difference here lies in how they are used.

A function is used by applying it to an argument and expecting that it would evaluate to a (one) value. If the argument is outside of the domain of the function the expression becomes meaningless and can't evaluate to a value.

A relation on the other hand is used by stating that two elements are related. If the RH-element is not within the range (for RH-elements) the elements are just not related, but stil the statement is formally valid albeit being false.

This means that a relation may be used outside its range and domain while a function can't be used outside it's domain. This means that there's no problem with composition of relations even if the range of the inner falls outside the domain of the outer.

Definition. A binary relation is a set of ordered pairs "$(a,b)$."

Remark. A function is a binary relation. (Observe the graph of a function is a set of ordered pairs)

Definition. Let $R$ and $S$ be binary relations. The composition $R\circ S$ is defined as follows: $$R\circ S:=\{ (a,b): (\exists c\in \mathrm{ran}(S)\cap\mathrm{dom}(R))[(a,c)\in S\,\wedge\,(c,b)\in R] \}$$

To answer the very last question, it is because we insist that
y = f(x) for xfy instead of xf = y.
The uncommon prefix notation xf, is used by some mathematicians.