Canonical: https://knowlpedia.com/shared-foundations/composition/

# Composition of functions

Forming a new function by applying one function after another

A **composition of functions** is the function obtained by applying one function after another: if \(f:A\to B\) and \(g:B\to C\) are [functions](https://knowlpedia.com/shared-foundations/function/) (so the codomain of \(f\) matches the domain of \(g\)), then the composition \(g\circ f:A\to C\) is defined by
\[
(g\circ f)(a)=g(f(a))\quad\text{for all }a\in A.
\]

## Remarks

Composition is associative when defined, and [identity functions](https://knowlpedia.com/shared-foundations/identity-function/) act as identities for composition. If \(f\) is [bijective](https://knowlpedia.com/shared-foundations/bijective-function/), then composing with its [inverse function](https://knowlpedia.com/shared-foundations/inverse-function/) recovers the appropriate identity functions.

## Examples

- Let \(f:\mathbb{Z}\to\mathbb{Z}\) be \(f(n)=n+1\) and let \(g:\mathbb{Z}\to\mathbb{Z}\) be \(g(n)=2n\); then \((g\circ f)(n)=2(n+1)=2n+2\).
- If \(i:S\to A\) is the inclusion of a [subset](https://knowlpedia.com/shared-foundations/subset/) and \(f:A\to B\) is any function, then \(f\circ i:S\to B\) is the restriction of \(f\) to \(S\).
