linguistic:voice_change, structural:reformatting, structural:expansion
Generalizations

Composition can be generalized to arbitrary binary relations.If R ⊆ X × Y and S ⊆ Y × Z are two binary relations, then their composition amounts to

R ∘ S = { (x, z) ∈ X × Z: (∃ y ∈ Y) ((x, y) ∈ R ∧ (y, z) ∈ S) } {\displaystyle R\circ S=\{(x,z)\in X\times Z:(\exists y\in Y)((x,y)\in R\,\land \,(y,z)\in S)\}}.

Considering a function as a special case of a binary relation (namely functional relations), function composition satisfies the definition for relation composition. A small circle R ∘ S has been used for the infix notation of composition of relations, as well as functions. When used to represent composition of functions (g ∘ f) (x) = g (f (x)) {\displaystyle (g\circ f)(x)\ =\ g(f(x))} however, the text sequence is reversed to illustrate the different operation sequences accordingly.

The composition is defined in the same way for partial functions and Cayley's theorem has its analogue called the Wagner–Preston theorem.

The category of sets with functions as morphisms is the prototypical category. The axioms of a category are in fact inspired from the properties (and also the definition) of function composition. The structures given by composition are axiomatized and generalized in category theory with the concept of morphism as the category-theoretical replacement of functions. The reversed order of composition in the formula (f ∘ g) = (g ∘ f) applies for composition of relations using converse relations, and thus in group theory. These structures form dagger categories.

The standard "foundation" for mathematics starts with sets and their elements. It is possible to start differently, by axiomatising not elements of sets but functions between sets. This can be done by using the language of categories and universal constructions.

... the membership relation for sets can often be replaced by the composition operation for functions. This leads to an alternative foundation for Mathematics upon categories -- specifically, on the category of all functions. Now much of Mathematics is dynamic, in that it deals with morphisms of an object into another object of the same kind. Such morphisms (like functions) form categories, and so the approach via categories fits well with the objective of organizing and understanding Mathematics. That, in truth, should be the goal of a proper philosophy of Mathematics.

- Saunders Mac Lane, Mathematics: Form and Function