Algebra & Functions · Composite function

Composite function

The composite function g ∘ f applies f first and then g: (g ∘ f)(x) = g(f(x)), defined where x is in the domain of f and f(x) is in the domain of g. Follow an input through both steps, and swap the order to see that g ∘ f and f ∘ g are usually different functions.

Composite functions in this visualization

A composite function chains two functions: the output of the first becomes the input of the second. Applying ff and then gg gives the function g∘fg \circ f, read “gg after ff”. Here ff and gg are each one of five functions; three number lines carry an input xx to f(x)f(x) and on to g(f(x))g(f(x)), and a graph shows g∘fg \circ f, so you can see where the chain breaks and compare the two orders.

g after f
(g∘f)(x)=g(f(x))(g \circ f)(x) = g(f(x))

Evaluate from the inside out: in g(f(x))g(f(x)), f(x)f(x) is worked out first, so g∘fg \circ f means ff first even though gg is written first. The small circle is not multiplication. On the picture the middle line holds the value f(x)f(x) that goes into gg.

Where g ∘ f is defined

Working out g(f(x))g(f(x)) needs two things: xx must be in the domain of ff, and f(x)f(x) must be in the domain of gg. So the domain of g∘fg \circ f can be smaller than the domain of ff. With f(x)=x+1f(x) = x + 1 and g(x)=xg(x) = \sqrt{x}, the middle value x+1x + 1 must not be negative, so x+1\sqrt{x + 1} is defined only for x≥−1x \ge -1, though ff accepts every xx. The shaded part of the middle line is the domain of gg, and the chain stops at the step that fails.

Domain of g ∘ f
{ x∈Df:f(x)∈Dg }\{\, x \in D_f : f(x) \in D_g \,\}

Why the order matters

Swapping ff and gg usually gives a different function. x2+1x^2 + 1 and (x+1)2(x + 1)^2 agree only at x=0x = 0, because they differ by 2x2x. Two functions are equal only when they have the same domain and the same value at every point of it, and the graph of f∘gf \circ g laid over the graph of g∘fg \circ f shows both conditions at once. Of the pairs of different functions on this page, only doubling and negating give the same composite in either order: −2x-2x.

Squaring and the square root show why the domain counts. Squaring first loses the sign, and the square root gives the non-negative number, so x2=∣x∣\sqrt{x^2} = |x| for every real xx. Taking the root first needs x≥0x \ge 0, and then (x)2=x(\sqrt{x})^2 = x. The two composites agree wherever both are defined, but x2\sqrt{x^2} is also defined for negative xx, so they are different functions.

Undoing a step

Negating twice returns every input to where it started: g(f(x))=xg(f(x)) = x for all xx, so g∘fg \circ f is the identity function, and negation is its own inverse. One order returning every input is not yet enough for two functions to undo each other. Taking the square root and then squaring returns every x≥0x \ge 0, but in the other order a negative input comes back as its absolute value. Two functions ff and gg are inverses of each other when g(f(x))=xg(f(x)) = x for every xx in the domain of ff and f(g(y))=yf(g(y)) = y for every yy in the domain of gg.

Controls

  • Both handles for x, on the first number line and on the graph’s x-axis, move with the arrow keys, 0.1 at a time (0.01 with Shift).

Related