Compose functions right to left like nested machines
Function composition feeds one map's outputs into another's inputs. Write g∘f for 'do f, then g'; associativity lets you drop parentheses, while domains must match, or at least nest, before the combination makes sense. Order matters, though: most pairs of functions give different answers when you swap which one goes first.
Composing functions means feeding the output of one into another: g ∘ f means apply f first, then g. It is a special case of composing relations and inherits their associativity, so f ∘ (g ∘ h) equals (f ∘ g) ∘ h and the brackets are usually dropped. Strictly, g ∘ f makes sense only when the codomain of f equals the domain of g, but in a looser sense it is enough for the first to sit inside the second, and the domain of f is often quietly trimmed so its outputs land where g can accept them.
Examples range from concrete to abstract. On the finite set {1, 2, 3, 4}, listing each function's pairs shows where every value ends up after both steps. On the real numbers, f(x) = 2x + 4 and g(x) = x³ combine by substitution. If a(t) gives an airplane's altitude at time t and p(x) the air pressure at altitude x, then (p ∘ a)(t) tells you the outside pressure the plane experiences at moment t. Permutations, which reorder a finite set, compose in just the same way.
Swapping the order usually changes the result. Two functions commute only when g ∘ f equals f ∘ g, a special property: |x| + 3 and |x + 3| agree only when x is at least 0. Composing one-to-one functions yields a one-to-one function and composing onto functions yields an onto function, so two bijections compose to a bijection whose inverse reverses the order, (f ∘ g)⁻¹ = g⁻¹ ∘ f⁻¹. Derivatives of compositions come from the chain rule, and higher derivatives from Faà di Bruno's formula.
Composing a function with itself over and over is called iteration, and the notation f^n for the nth functional power goes back to Hans Heinrich Bürmann and John Herschel, with f^0 taken as the identity. That clashes with trigonometry, where sin² normally means a product, yet tan⁻¹ still means arctan rather than 1/tan. All bijections of a set onto itself form the symmetric group under composition, and Cayley's theorem says every group is essentially a subgroup of one. Iterated functions and their continuous cousins, flows, arise naturally in fractals and dynamical systems.
Source: Function composition