⚙️ Function Kingdom · Functions

Composite Functions

Feed one function into another: evaluate (f ∘ g)(a) from rules and tables, write f(g(x)) as one expression, find the domain of a composition, and take a composite function apart again.

In short

  • f(g(x)) means g runs first and f runs second: the rule written next to the x is always the inner one.
  • To evaluate a composition, work inside out and write the middle value on its own line before you use it.
  • To build f(g(x)) as an expression, put the whole of g(x) in a bracket wherever f has an x, then expand.
  • f(g(x)) and g(f(x)) are different rules, and the domain of a composition keeps the restrictions of both functions.

A machine feeding a machine

Engineer Volt keeps two brass machines bolted together on the workbench at Function City. Drop a number into the first, and whatever falls out of it drops straight into the second. Nothing about either machine changes; they are simply wired in a line.

That wiring has a name. The composition of f and g is written

(f o g)(x) = f(g(x))

and it means exactly what the brackets say: g runs first, on x, and f runs second, on g's output.

Read f(g(x)) from the middle outwards, the way you would unwrap a parcel. The x is deepest, so it meets g. What g produces is then the input of f. The letter written next to the x is always the first machine.

f(x) = 2x + 1, g(x) = x - 5

f(g(9)) = f(9 - 5) = f(4) = 2(4) + 1 = 9

The one thing f(g(x)) never means is f times g. There is no multiplying anywhere in a composition, and there is no adding either. A bracket in function notation always holds an input.

The middle value is the whole point, and it is worth writing down. In f(g(9)) above, the 4 is what travelled between the machines. If you can name that number, you have understood the composition; if you cannot, you have probably tried to do both machines at once.

Evaluating: always inside out

To work out a composition at a number, do it in two clearly separated steps and write the middle value on its own line.

f(x) = x2 - 3, g(x) = 4x + 1

Step 1 (inner): g(2) = 4(2) + 1 = 9 Step 2 (outer): f(9) = 92 - 3 = 78

so f(g(2)) = 78

The same discipline works when the functions arrive as a table instead of as rules. A table of x, f(x) and g(x) is two machines in disguise: to find f(g(2)) you look up the row x = 2 in the g(x) column, then take that answer back to the x column and read the f(x) column beside it. Two lookups, in that order — never two lookups in the same row.

Reading a composition backwards is the same journey in reverse. If you are told g(f(x)) = 7 and asked for x, undo the outer machine first: find which input makes g give 7, then find which x makes f give that.

Watch the negatives. When the inner value is negative, put it in brackets before it goes into the outer rule: f(-3) with f(x) = x2 - 3 is (-3)2 - 3 = 6, not -9 - 3.

Writing f(g(x)) as one expression

Sometimes the input is not a number but the letter x itself. The method does not change: wherever f has an x, write the whole of g(x) in a bracket.

f(x) = 3x + 4, g(x) = 2x - 7

f(g(x)) = 3(2x - 7) + 4 = 6x - 21 + 4 = 6x - 17

The bracket is not optional. It is the thing that keeps g(x) together while f acts on all of it.

When the outer rule squares its input, the bracket gets squared as a whole:

f(x) = x2 + 5, g(x) = x - 3

f(g(x)) = (x - 3)2 + 5 = x2 - 6x + 9 + 5 = x2 - 6x + 14

Notice the middle term. (x - 3)2 is not x2 + 9; expanding a squared bracket always produces three terms, and the -6x is the one that gets dropped most often.

If the outer rule has more than one x, every single one of them becomes the bracket:

f(x) = x2 - 4x + 1, g(x) = x + 2

f(g(x)) = (x + 2)2 - 4(x + 2) + 1 = x2 + 4x + 4 - 4x - 8 + 1 = x2 - 3

Roots behave the same way, and they can simplify beautifully. With f(x) = sqrt(x) and g(x) = x2 + 6x, the composition g(f(x)) is (sqrt(x))^2 + 6 sqrt(x), which is x + 6 sqrt(x) for x zero or more, because squaring undoes the root.

Order matters, and so does the domain

Multiplication does not care about order: 3 x 5 and 5 x 3 agree. Composition is not like that.

f(x) = 2x, g(x) = x + 1

f(g(3)) = f(4) = 8 but g(f(3)) = g(6) = 7

Two machines wired the other way round are a different pair of machines. f(g(x)) = 2x + 2 and g(f(x)) = 2x + 1 are different rules, so the notation has to say which one you mean, and you have to read it carefully.

The second consequence is about domains. The domain of f(g(x)) is the set of inputs that survive the whole journey: g must accept x, and f must accept whatever g hands over.

f(x) = sqrt(x), g(x) = x - 5 gives f(g(x)) = sqrt(x - 5), domain x >= 5

f(x) = 1/x, g(x) = x - 5 gives f(g(x)) = 1/(x - 5), domain all real numbers except x = 5

Sometimes both machines impose a condition and both survive into the answer. With f(x) = 1/(x - 3) and g(x) = sqrt(x), the composition is 1/(sqrt(x) - 3). The root needs x >= 0, and the fraction needs sqrt(x) to miss 3, which rules out x = 9. The domain is x >= 0 except x = 9 — two restrictions, both named.

Building the composition first and then reading its restrictions off is safe. Quoting the outer rule's own restriction is not: 1/x breaks at 0, but 1/(x - 5) breaks at 5.

Taking a composition apart

Decomposing runs the whole idea backwards: you are handed h and asked for an f and a g with f(g(x)) = h(x).

The question that finds them every time is: if I were working h out on a calculator, what would I do last? That last action is the outer function f. Everything you did before it is the inner function g.

h(x) = (2x + 3)2

You would work out 2x + 3 first and square it last, so g(x) = 2x + 3 and f(x) = x2.

h(x) = sqrt(x^2 - 4) g(x) = x2 - 4, f(x) = sqrt(x) h(x) = 1/(x + 5) g(x) = x + 5, f(x) = 1/x h(x) = 3(x - 1)2 + 4 g(x) = x - 1, f(x) = 3x2 + 4

The part written inside the bracket, or under the root sign, or on the bottom of the fraction, is almost always g. Decompositions are not unique — you could always cheat with g(x) = x — which is why questions ask for a pair where neither rule is just x.

Check a candidate by substituting it back. Put g(x) into f wherever f has an x and see whether h comes out. If it does not, the two are usually the right way round in your head and the wrong way round on the page.

Compositions are also how two-stage situations get modelled. A market stall that takes 5 gold off the price and then charges 7 % tax is C(p) = p - 5 followed by T(c) = 1.07c, and what you pay is T(C(p)) = 1.07(p - 5). Charging the tax first and taking the gold off afterwards is C(T(p)) = 1.07p - 5, which is a different amount of gold. The order is not a formality.

Worked examples

Example 1

f(x) = x2 + 2x - 4 and g(x) = -3x + 16. Find f(g(6)).

  1. The inner rule is g, because it sits next to the 6. Work it out first.
  2. g(6) = -3(6) + 16 = -18 + 16 = -2
  3. That -2 is now the input of f, so f(g(6)) = f(-2).
  4. f(-2) = (-2)2 + 2(-2) - 4 = 4 - 4 - 4
  5. f(g(6)) = -4. The brackets around the -2 are what keep the square positive.

Example 2

f(x) = x2 - 2x + 5 and g(x) = x - 3. Write f(g(x)) as a single simplified expression in x.

  1. Replace every x in f by the whole bracket (x - 3), including the one inside the squared term.
  2. f(g(x)) = (x - 3)2 - 2(x - 3) + 5
  3. Expand the square: (x - 3)2 = x2 - 6x + 9. Three terms, not two.
  4. Expand the linear bracket: -2(x - 3) = -2x + 6.
  5. Collect: x2 - 6x + 9 - 2x + 6 + 5 = x2 - 8x + 20

Example 3

f(x) = 1/(x - 3) and g(x) = sqrt(x). What is the domain of f(g(x))?

  1. Build the composition first: f(g(x)) = 1/(sqrt(x) - 3).
  2. The inner rule speaks first. sqrt(x) is only a real number when x >= 0.
  3. The outer rule speaks second. A fraction has no value when its bottom is zero, so sqrt(x) must not equal 3.
  4. sqrt(x) = 3 when x = 9, so that one input has to go as well.
  5. Domain: x >= 0, except x = 9. Both machines put a condition on the answer, and both conditions are kept.

Practice problems, with solutions

Three problems of increasing difficulty, each with the full working. In the game these are generated fresh every time; these three are fixed so this page always shows the same ones.

Problem 1

Difficulty 1 of 5

f(x) = 3x + 8 and g(x) = 2x - 2 Find f(g(4)).

Answer: 26

  1. g(4) = 2(4) - 2 = 6
  2. f(g(4)) = f(6)
  3. f(6) = 3(6) + 8 = 26

Problem 2

Difficulty 3 of 5

The table gives every value of f and every value of g. Find f(g(2)).

Answer: -1

  1. Row x = 2: g(2) = 0.
  2. f(g(2)) = f(0).
  3. Row x = 0: f(0) = -1.

Problem 3

Difficulty 4 of 5

f(x) = x2 - 5x + 1 and g(x) = x + 1 Write f(g(x)) as a single simplified expression in x.

Answer: x2 - 3x - 3

  1. f(g(x)) = (x + 1)2 - 5(x + 1) + 1
  2. (x + 1)2 = x2 + 2x + 1
  3. - 5(x + 1) gives -5x - 5
  4. f(g(x)) = x2 - 3x - 3

Common mistakes

  • Multiplying the two rules together instead of composing them, as if f(g(x)) meant f(x) times g(x).
  • Composing in the wrong order and working out g(f(a)) when the question asked for f(g(a)).
  • Stopping after the inner function and giving g(a) as the answer, without pushing it through f.
  • Expanding a squared bracket term by term, so that (x - 3)2 loses its middle term and becomes x2 + 9.
  • Stating the domain of f(g(x)) from the outer rule alone, and forgetting the restriction the inner function brings with it.

What you should be able to do

  • Evaluate (f ∘ g)(a) and (g ∘ f)(a) from function rules and from tables, and explain why the order matters.
  • Write f(g(x)) as a single simplified expression when the outer function is not linear.
  • State the domain of a composition by tracking the restrictions of both functions.
  • Decompose a function into an outer and an inner function, and model a two-stage situation with a composition.

Where this fits in the curriculum

Common Core

  • HSF-BF.A.1.C

    High school — Compose functions; for example, if T(y) is the temperature in the atmosphere as a function of height and h(t) is the height of a weather balloon as a function of time, then T(h(t)) is the temperature at the location of the balloon as a function of time.

    HSF-BF.A.1.C is a (+) standard — beyond the college- and career-ready threshold, i.e. precalculus rather than Algebra II.

  • HSF-IF.A.2

    High school — Use function notation, evaluate functions for inputs in their domains, and interpret statements that use function notation in terms of a context.

  • HSF-BF.A.1

    High school — Write a function that describes a relationship between two quantities.

SAT

Learn these first

This leads on to