Composition. Given f:X→Y and g:Y→Z, define h:X→Z by first applying f, then g: h(x)=g(f(x)). This h is the composition of f with g, written g∘f (read "f composite with g", applied right-to-left: do f first, then g).
More generally, g∘f can be defined whenever the range of f is contained in the domain of g -- f's co-domain need not literally equal g's domain, as long as it fits inside it.
Worked examples.
- f={(1,2),(3,4),(2,2)}, g={(2,1),(3,1),(4,2)}: range of f={2,4}⊆ domain of g={2,3,4}, so g∘f exists: g∘f={(1,1),(2,1),(3,2)}. Also range of g={1,2}⊆ domain of f={1,2,3}, so f∘g={(2,2),(3,2),(4,2)} exists too -- and f∘g=g∘f as sets, illustrating non-commutativity.
- f={(1,4),(2,5),(3,5)}, g={(4,1),(5,2),(6,4)}: g∘f={(1,1),(2,2),(3,2)} exists, but f∘g does not exist, since range of g={1,2,4}⊆ domain of f={1,2,3}.
- f(x)=3x−4, g(x)=x2+3 on R: (g∘f)(x)=(3x−4)2+3=9x2−24x+19, while (f∘g)(x)=3(x2+3)−4=3x2+5 -- different, confirming composition is generally not commutative.
Theorem. If f:A→B and g:B→C are both one-to-one, then g∘f is one-to-one. Proof: if x=y in A, injectivity of f gives f(x)=f(y), and injectivity of g then gives g(f(x))=g(f(y)), i.e. (g∘f)(x)=(g∘f)(y). ■ …