Functions

Composition of Functions

The composition of functions feeds the output of one function into another: (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)). The inner function gg runs first, then ff works on whatever gg returned.

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

Try it with your numbers

Show every step

Most errors come from three places: reading the notation in the wrong order, dropping brackets during substitution, and forgetting that the domain of the composite can be smaller than the final formula suggests. Each one has a quick fix below.

What does f of g of x mean in a composition?

Read f(g(x))f(g(x)) from the inside out. Start with xx, apply gg, and hand the result to ff. The small circle in f∘gf \circ g is read “f after g”, which is why the function on the right acts first. The notation feels backward until you remember that it mirrors f(g(x))f(g(x)), where gg sits closest to xx. If the bracket style is unfamiliar, a quick look at function notation clears it up.

The one idea behind everything is that composition is substitution. A rule like f(x)=x2f(x)=x^2 really says “square whatever is in the bracket.” So f(g(x))f(g(x)) squares the entire expression g(x)g(x), brackets and all. Nothing new is invented here; you are replacing the variable in ff with a whole expression.

This works because a function gives exactly one output for each input, so gg always hands ff a single, definite value. That is the defining property covered in relations and functions, and it is why you cannot compose a relation that gives two outputs for one input.

Quick check

Let f(x)=x+4f(x)=x+4 and g(x)=3xg(x)=3x. Find f(g(2))f(g(2)).

How do you find a composite function step by step?

Use the same three moves every time:

  1. Write the outer function with an empty bracket: f(  )f(\ \ ).
  2. Put the whole inner function in that bracket, wrapped in parentheses.
  3. Expand and simplify.

Example 1. Let f(x)=2x+3f(x)=2x+3 and g(x)=x2−1g(x)=x^2-1. Find f(g(x))f(g(x)) and g(f(x))g(f(x)).

f(g(x))=2(x2−1)+3=2x2−2+3=2x2+1f(g(x)) = 2(x^2-1)+3 = 2x^2-2+3 = 2x^2+1

g(f(x))=(2x+3)2−1=4x2+12x+9−1=4x2+12x+8g(f(x)) = (2x+3)^2-1 = 4x^2+12x+9-1 = 4x^2+12x+8

The costly slip is in the second line: (2x+3)2(2x+3)^2 is not 4x2+94x^2+9. The middle term 12x12x appears only if you keep the parentheses and expand properly.

A two-second check catches most mistakes. Pick x=2x=2. Directly, g(2)=3g(2)=3 and f(3)=9f(3)=9, and the formula gives 2(4)+1=92(4)+1=9. For the other order, f(2)=7f(2)=7 and g(7)=48g(7)=48, and the formula gives 4(4)+24+8=484(4)+24+8=48. Both agree.

How do you evaluate a composition with negatives or a table?

If you need a value at one point, skip the algebra and go inside out with numbers. With the functions from Example 1 and x=−12x=-\tfrac12:

g(−12)=14−1=−34,f(−34)=2(−34)+3=32g\left(-\tfrac12\right)=\tfrac14-1=-\tfrac34,\qquad f\left(-\tfrac34\right)=2\left(-\tfrac34\right)+3=\tfrac32

The formula 2x2+12x^2+1 confirms it: 2⋅14+1=322\cdot\tfrac14+1=\tfrac32. Square negatives with brackets, so (−12)2=14\left(-\tfrac12\right)^2=\tfrac14, never −14-\tfrac14. When you need many values, build the composite formula once and reuse it.

Tables and graphs follow the same chain. Find xx in gg‘s table, read its output, then look up that output as the input in ff‘s table.

xx g(x)g(x) f(g(x))f(g(x))
−2-2 33 99
00 −1-1 11
11 00 33
33 88 1919

On a graph, the output of gg (a height) becomes the input of ff (a position on the horizontal axis), so you cross over from the yy-axis to the xx-axis between steps. If gg produces a value that ff‘s table or graph does not contain, the composite is undefined there. That is the doorway to domains.

How do you find the domain of a composite function?

Number lines showing domain of f(g(x)) excludes 0 and 1 before simplifying, but only 1 after
Test the original expressions: g forbids x = 0 and f forbids g(x) = 1, so both 0 and 1 are excluded.

A number xx is allowed in f∘gf \circ g only if it survives two filters: xx must be allowed in gg, and then g(x)g(x) must be allowed in ff. The domain of the composite is always a subset of the domain of gg. For the vocabulary of allowed inputs and outputs, see domain and range.

Test the unsimplified form

Run both filters on the original expressions. Simplifying first can cancel a factor and hide a value that was never allowed, such as x=0x=0 in f(g(x))f(g(x)) below.

Example 2. Let f(x)=1x−1f(x)=\dfrac{1}{x-1} and g(x)=1xg(x)=\dfrac1x. Find f(g(x))f(g(x)) and its domain.

First the formula. Replace xx in ff with 1x\tfrac1x and clear the small fraction by multiplying top and bottom by xx:

f(g(x))=11x−1=x1−xf(g(x))=\frac{1}{\frac1x-1}=\frac{x}{1-x}

Filter 1: gg needs x≠0x\neq 0. Filter 2: ff cannot accept 11, so g(x)≠1g(x)\neq 1, which means 1x≠1\tfrac1x\neq 1 and x≠1x\neq 1. The domain is all real numbers except 00 and 11.

The trap is plain to see: the simplified fraction x1−x\frac{x}{1-x} only warns you about x=1x=1. At x=0x=0 it happily returns 00, yet g(0)g(0) does not exist, so f(g(0))f(g(0)) does not either. A square root works the same way: with f(x)=xf(x)=\sqrt{x} and g(x)=x2−4g(x)=x^2-4, the second filter demands x2−4≥0x^2-4\ge 0, giving x≤−2x\le -2 or x≥2x\ge 2.

Quick check

Let f(x)=3x+2f(x)=\dfrac{3}{x+2} and g(x)=xg(x)=\sqrt{x}. What is the domain of f(g(x))f(g(x))?

Why does f composed with g differ from g composed with f?

Two chains showing input 2 through g then f gives 9, through f then g gives 48
With f(x) = 2x + 3 and g(x) = x² − 1, f(g(2)) = 9 but g(f(2)) = 48.

Take two lines, f(x)=ax+bf(x)=ax+b and g(x)=cx+dg(x)=cx+d. Substituting both ways gives

f(g(x))=acx+(ad+b),g(f(x))=acx+(bc+d)f(g(x))=acx+(ad+b),\qquad g(f(x))=acx+(bc+d)

The slopes match because multiplication commutes, but the intercepts ad+bad+b and bc+dbc+d are generally different. They agree only in special cases, such as when ff and gg are inverses of each other (both compositions then give xx). If you want the line basics behind this, see slope-intercept form.

The same split shows up in graphs. With f(x)=x2f(x)=x^2, the inner change (x+3)2(x+3)^2 slides the parabola left by 3, while the outer change x2+3x^2+3 lifts it up by 3. This is the whole logic of transformations of functions: changes inside the bracket act on xx, changes outside act on the output.

Three fast checks save time on tests:

  • Degrees multiply. If ff has degree mm and gg has degree nn, then f∘gf\circ g has degree mnmn, so a quadratic inside a quadratic gives a quartic. This predicts the end behavior of the polynomial.
  • If gg is even, f∘gf\circ g is even, and if ff and gg are both odd, f∘gf\circ g is odd (see even and odd functions).
  • Grouping is free: (f∘g)∘h=f∘(g∘h)(f\circ g)\circ h=f\circ(g\circ h). Only the order of the functions matters.

Try this: Let f(x)=x2f(x)=x^2 and g(x)=x+3g(x)=x+3. Compute f(g(1))f(g(1)) and g(f(1))g(f(1)) with numbers, then build both formulas and check that each one reproduces your number.

Can you compose a function with itself?

Yes. Writing f∘ff\circ f means f(f(x))f(f(x)), the same rule applied twice. For f(x)=2x+1f(x)=2x+1:

f(f(x))=2(2x+1)+1=4x+3f(f(x))=2(2x+1)+1=4x+3

Apply it a third time and you get f(4x+3)=8x+7f(4x+3)=8x+7. The pattern is fn(x)=2nx+2n−1f^{n}(x)=2^{n}x+2^{n}-1, which you can verify with n=2n=2 and n=3n=3 above.

Watch the notation. In iteration, f2(x)f^2(x) means f(f(x))f(f(x)), but in algebra and trigonometry sin⁡2x\sin^2 x means (sin⁡x)2(\sin x)^2. And f−1f^{-1} never means the reciprocal 1f\tfrac1f; it names the inverse function. The context (a composition chapter versus a trig chapter) tells you which one is meant, and when in doubt, write out f(f(x))f(f(x)).

Some functions return to the start after two passes. The function f(x)=1xf(x)=\tfrac1x gives f(f(x))=xf(f(x))=x for x≠0x\neq 0, so it is its own inverse. Practice problem 5 below uses another one of these.

How do you use composition to check an inverse function?

Two functions ff and gg are inverses exactly when each undoes the other: f(g(x))=xf(g(x))=x and g(f(x))=xg(f(x))=x on the right domains. This is the cleanest way to verify an answer you got from solving for xx.

Example 3. Check that f(x)=3x−4f(x)=3x-4 and g(x)=x+43g(x)=\dfrac{x+4}{3} are inverses.

f(g(x))=3⋅x+43−4=x+4−4=xf(g(x))=3\cdot\frac{x+4}{3}-4=x+4-4=x

g(f(x))=(3x−4)+43=3x3=xg(f(x))=\frac{(3x-4)+4}{3}=\frac{3x}{3}=x

Both come out as xx, so they are inverses. You can find such a partner yourself with the method on inverse of a linear function.

Undo in reverse order

ff multiplies by 3, then subtracts 4. Its inverse must add 4 first, then divide by 3, just as you take off shoes before socks.

Now the failure case. Let f(x)=x2f(x)=x^2 and g(x)=xg(x)=\sqrt{x}. Then f(g(x))=(x)2=xf(g(x))=(\sqrt{x})^2=x for x≥0x\ge 0, but g(f(x))=x2=∣x∣g(f(x))=\sqrt{x^2}=|x|. So g(f(−5))=5g(f(-5))=5, not −5-5. Squaring loses the sign, so no function can undo it on all real numbers. The cure is to restrict the domain, which is the reason a function must be one-to-one to have an inverse, and why the inverse of a quadratic function needs a restricted domain.

Quick check

Let f(x)=x2f(x)=x^2 and g(x)=xg(x)=\sqrt{x}. Find g(f(−5))g(f(-5)).

How do you break a function into a composition?

Decomposing is the reverse of composing. Ask what you would do first if you evaluated h(x)h(x) with a calculator. That first operation is the inner function, and what happens to its result is the outer function.

For h(x)=(2x−5)4h(x)=(2x-5)^4, you first compute 2x−52x-5, then raise to the fourth power. So g(x)=2x−5g(x)=2x-5 and f(x)=x4f(x)=x^4, and the check is f(g(x))=(2x−5)4f(g(x))=(2x-5)^4. Some functions have more than two layers. For h(x)=1x+3h(x)=\dfrac{1}{\sqrt{x}+3} the chain is: take x\sqrt{x}, add 33, then take the reciprocal. That is h=r∘q∘ph=r\circ q\circ p with p(x)=xp(x)=\sqrt{x}, q(x)=x+3q(x)=x+3 and r(x)=1xr(x)=\tfrac1x.

Decompositions are not unique. You could also write h(x)=(2x−5)4h(x)=(2x-5)^4 using g(x)=(2x−5)2g(x)=(2x-5)^2 and f(x)=x2f(x)=x^2. The useful choice is the one where each layer is something simple, ideally one of the familiar parent functions. That habit pays off in calculus, where the chain rule asks you to name the inner and outer parts before you differentiate.

Where is composition of functions used in real life?

Unit conversions chain naturally. Fahrenheit to Celsius is C(F)=59(F−32)C(F)=\tfrac59(F-32), and Celsius to Kelvin is K(C)=C+273.15K(C)=C+273.15. Composing gives K(C(F))=59(F−32)+273.15K(C(F))=\tfrac59(F-32)+273.15. As a check, F=212F=212 gives C=100C=100 and K=373.15K=373.15, the boiling point of water in Kelvin.

Pricing shows why order matters in practice. A $100 item with 20% off and then a $10 coupon costs 0.8⋅100−10=700.8\cdot 100-10=70. Take the coupon first and then 20% off, and it costs (100−10)⋅0.8=72(100-10)\cdot 0.8=72. Two percentage discounts, in contrast, commute: 20% off then 10% off multiplies to 0.8⋅0.9=0.720.8\cdot 0.9=0.72, which is 28% off, not 30%.

The same structure runs through software, where each step in a data pipeline is a function fed by the previous one, and through calculus, where ddxf(g(x))=f′(g(x))⋅g′(x)\frac{d}{dx}f(g(x))=f'(g(x))\cdot g'(x). Type your own pair of functions into the solver above and compare both orders to see how the structure behaves.

Practice problems

0 of 5 solved

  1. Let f(x)=3x−2f(x)=3x-2 and g(x)=x+5g(x)=x+5. Find f(g(4))f(g(4)).

  2. Let f(x)=x2+1f(x)=x^2+1 and g(x)=2x−3g(x)=2x-3. Find (f∘g)(x)(f \circ g)(x) in expanded form.

  3. Let f(x)=4x−1f(x)=4x-1 and g(x)=x2g(x)=x^2. Find (g∘f)(−12)(g \circ f)\left(-\tfrac12\right).

  4. Let f(x)=1x−4f(x)=\dfrac{1}{x-4} and g(x)=xg(x)=\sqrt{x}. Find the domain of f(g(x))f(g(x)).

  5. Let f(x)=x+1x−1f(x)=\dfrac{x+1}{x-1}. Simplify f(f(x))f(f(x)).

Common questions

What is the composition of functions?

It is the process of using the output of one function as the input of another. In symbols, (f∘g)(x)=f(g(x))(f \circ g)(x)=f(g(x)): gg runs first, then ff acts on the result.

Is f∘gf \circ g the same as f(x)⋅g(x)f(x)\cdot g(x)?

No. The circle means substitute g(x)g(x) into ff, while the dot means multiply the two outputs. For f(x)=x+1f(x)=x+1 and g(x)=x+2g(x)=x+2, composition gives x+3x+3 and multiplication gives x2+3x+2x^2+3x+2.

Does the order of composition matter?

Almost always. f(g(x))f(g(x)) and g(f(x))g(f(x)) are usually different functions, with equality only in special cases such as a function and its inverse. Grouping of three functions does not matter, though: (f∘g)∘h=f∘(g∘h)(f\circ g)\circ h = f\circ(g\circ h).

How do you find the domain of a composite function?

Keep only the xx values that are allowed in the inner function gg and that make g(x)g(x) allowed in the outer function ff. Test these on the unsimplified expressions, because simplifying can hide a removed value.

How do you know if two functions are inverses using composition?

Compute both f(g(x))f(g(x)) and g(f(x))g(f(x)). If each one simplifies to xx on the proper domains, the functions are inverses of each other.

Can you compose more than two functions?

Yes. Apply them from the inside out, as in f(g(h(x)))f(g(h(x))). This is exactly how the chain rule in calculus is set up.

Up next