Given functions f:A→B and g:B→C, the composite functiong∘f:A→C is defined by
(g∘f)(x)=g(f(x)),for every x∈A
Reading right to left: first apply f to x, landing in B; then apply g to that result, landing in C. The composite is only defined when the codomain of the "inner" function matches (or lies inside) the domain of the "outer" function.
Computing a Composite
Illustration. Let f(x)=2x+1 and g(x)=x2−2, both R→R.
(g∘f)(x)=g(f(x))=g(2x+1)=(2x+1)2−2=4x2+4x−1
(f∘g)(x)=f(g(x))=f(x2−2)=2(x2−2)+1=2x2−3
Comparing the two results, 4x2+4x−1=2x2−3 in general.
Watch out
Composition of functions is not commutative — in general f∘g=g∘f, as the illustration above shows. Always compute the two composites separately and never assume they agree; when they do coincide, it is a special situation worth noting.
Domain of a Composite
The domain of g∘f is the set of x in the domain of f for which f(x) also lies in the domain of g; composing can shrink the domain below that of either function alone.
Illustration. Let f(x)=x (domain x≥0) and g(x)=x+4 (domain all of R).
(g∘f)(x)=x+4,domain x≥0 (inherited from f)
(f∘g)(x)=x+4,domain x≥−4 (need the input to f to be ≥0)