A composition of functions is the function obtained by applying one function after another: if f:A→Bf:A\to B and g:B→Cg:B\to C are (so the codomain of ff matches the domain of gg), then the composition g∘f:A→Cg\circ f:A\to C is defined by

(g∘f)(a)=g(f(a))for all a∈A.(g\circ f)(a)=g(f(a))\quad\text{for all }a\in A.
Remarks

Composition is associative when defined, and act as identities for composition. If ff is , then composing with its recovers the appropriate identity functions.

Examples
  • Let f:Z→Zf:\mathbb{Z}\to\mathbb{Z} be f(n)=n+1f(n)=n+1 and let g:Z→Zg:\mathbb{Z}\to\mathbb{Z} be g(n)=2ng(n)=2n; then (g∘f)(n)=2(n+1)=2n+2(g\circ f)(n)=2(n+1)=2n+2.
  • If i:S→Ai:S\to A is the inclusion of a and f:A→Bf:A\to B is any function, then f∘i:S→Bf\circ i:S\to B is the restriction of ff to SS.