Composite Functions

One machine fed into the next, right to left.

One function after another

Take two functions: f(x) = x + 3, which adds 3, and g(x) = 2x, which doubles. The output of one can be used as the input of the other. A function made this way, by applying one function and then another to its output, is called a composite function.

gf(x) means g(f(x)): first apply f to x, then apply g to the result. The function written nearest to the x acts first, just as the inside bracket of g(f(x)) is worked out first. So a composite is read from right to left.

gf means f first

Work out gf(4). The f is nearer to the 4, so f acts first: f(4) = 4 + 3 = 7. Then g acts on that output: g(7) = 2 × 7 = 14. So gf(4) = g(f(4)) = g(7) = 14.

4f: + 37g: × 214gf(4) = g(f(4)) = 14

For gf(4), the 4 goes through f first, which adds 3 to make 7, and then through g, which doubles 7 to make 14.

The other order

fg(4) means f(g(4)), so g acts first this time: g(4) = 2 × 4 = 8, and then f(8) = 8 + 3 = 11. The same two functions, applied in the other order, give 11 instead of 14.

The two orders do different things to the 3 that f adds. In gf, the 3 is added first and then doubled along with everything else, so it becomes 6. In fg, the doubling is already over when the 3 is added, so it stays 3.

4g: × 28f: + 311fg(4) = f(g(4)) = 11

For fg(4), the 4 goes through g first, which doubles it to 8, and then through f, which adds 3 to make 11.

The composite as a formula

To write gf(x) as a formula, put the whole of f(x) in as the input of g. Since g doubles its input, gf(x) = g(x + 3) = 2(x + 3) = 2x + 6. Check: gf(4) = 2 × 4 + 6 = 14.

For fg(x), put g(x) in as the input of f. Since f adds 3 to its input, fg(x) = f(2x) = 2x + 3. Check: fg(4) = 2 × 4 + 3 = 11.

So gf(x) = 2x + 6 and fg(x) = 2x + 3. For every x, gf(x) is 3 more than fg(x), so the two composites never agree: fg and gf are different functions, not just different at x = 4.

The order can change more than a number. Take f(x) = x + 3 and h(x) = x². Then hf(x) = h(x + 3) = (x + 3)², which adds 3 and then squares, while fh(x) = f(x²) = x² + 3, which squares and then adds 3. At x = 1, hf(1) = 4² = 16 but fh(1) = 1 + 3 = 4.

Each output must be an input the next function accepts

In a composite, the outputs of the first function become the inputs of the second, so they must lie in the second function's domain. Take f(x) = √x, whose domain is x ≥ 0, and g(x) = x − 5. Then fg(x) = f(x − 5) = √(x − 5).

Try fg(3). First g(3) = 3 − 5 = −2. That is a perfectly good output of g, but it is not an input f accepts, because −2 has no real square root. So fg(3) has no value. fg(x) has a value only when g(x) = x − 5 is 0 or more, which means x ≥ 5: the domain of fg is x ≥ 5, even though g on its own accepts every number.

In the other order, gf(x) = g(√x) = √x − 5. Here f acts first, so the input must be 0 or more, and then any output of f can go into g. The domain of gf is x ≥ 0.

3g: − 5−2f: √no real valuefg(3) has no value

For f(x) = √x and g(x) = x − 5, the input 3 goes through g to give −2, and −2 is not in the domain of f, so fg(3) has no value.

A function applied twice

A function can be composed with itself. For f(x) = x + 3, ff(x) = f(x + 3) = (x + 3) + 3 = x + 6: adding 3 twice adds 6. For g(x) = 2x, gg(x) = g(2x) = 2 × 2x = 4x: doubling twice multiplies by 4.

Some books write ff(x) as f²(x). There the 2 means "apply f twice", not "square the output": for g(x) = 2x, g²(3) = gg(3) = 12, while (g(3))² = 6² = 36.

Solving an equation in a composite

Which input x gives gf(x) = 20, for f(x) = x + 3 and g(x) = 2x? Write the composite as a formula first, gf(x) = 2x + 6, then solve 2x + 6 = 20: subtract 6 from both sides to get 2x = 14, so x = 7. Check through the machines: f(7) = 10, and g(10) = 20.

The usual mistakes

Reading the composite from left to right. gf(4) is not "g first": the f is next to the 4, so f acts first, and gf(4) = g(7) = 14, not f(8) = 11.

Using only one of the functions. 2 × 4 = 8 is only g; for gf(4) the adding of 3 has to happen as well, and before the doubling.

Multiplying the two rules together. fg(x) is one function put inside the other, not the product f(x) × g(x). For f(x) = x + 3 and g(x) = 2x, fg(x) = 2x + 3, while the product is 2x(x + 3).

Worked example: A Fee Taken Before a Currency Exchange: Two Functions in Order

Question A bureau de change takes a fee of $5 from the money a customer hands over, and then changes what is left into pesos at 40 pesos to the dollar. Let g(x) = x − 5 and f(x) = 40x. (a) Find fg(x), and the number of pesos a customer receives for $120. (b) Find gf(120), and say what the order gf would mean at the bureau.

  1. 1.The fee is taken first, so g acts first: g(120) = 120 − 5 = 115 dollars are left. Then f changes them: f(115) = 40 × 115 = 4600 pesos.

    fg: the fee first, then the exchangex − 5g40xf1201154600g(120) = 120 − 5 = 115 dollarsf(115) = 40 × 115 = 4600 pesos
    fg: the fee first, then the exchangex − 5g40xf1201154600g(120) = 120 − 5 = 115 dollarsf(115) = 40 × 115 = 4600 pesos
    The fee comes off first: g(120) = 115. Then the exchange: f(115) = 40 × 115 = 4600 pesos.
  2. 2.In fg(x) the function nearest to x acts first. Put g(x) into f: fg(x) = f(x − 5) = 40(x − 5) = 40x − 200.

    fg: the fee first, then the exchangex − 5g40xf1201154600fg(x) = f(x − 5) = 40(x − 5)fg(x) = 40x − 200
    fg: the fee first, then the exchangex − 5g40xf1201154600fg(x) = f(x − 5) = 40(x − 5)fg(x) = 40x − 200
    The output of g is the input of f: fg(x) = f(x − 5) = 40(x − 5) = 40x − 200.
  3. 3.(a) fg(x) = 40x − 200, and fg(120) = 4800 − 200 = 4600, so the customer receives 4600 pesos. The −200 is the fee of $5 seen in pesos, because 5 × 40 = 200.

    fg: the fee first, then the exchangex − 5g40xf1201154600fg(120) = 4800 − 200 = 4600 pesosthe fee of $5 is 5 × 40 = 200 pesos
    fg: the fee first, then the exchangex − 5g40xf1201154600fg(120) = 4800 − 200 = 4600 pesosthe fee of $5 is 5 × 40 = 200 pesos
    (a) fg(x) = 40x − 200 and fg(120) = 4600 pesos. The 200 is the fee of $5 in pesos.
  4. 4.In the other order f acts first: f(120) = 40 × 120 = 4800, and then g(4800) = 4800 − 5 = 4795. As a formula, gf(x) = 40x − 5.

    fg: the fee first, then the exchangex − 5g40xf1201154600gf: the exchange first, then the fee40xfx − 5g12048004795f(120) = 4800, then g(4800) = 4795gf(x) = 40x − 5
    fg: the fee first, then the exchangex − 5g40xf1201154600gf: the exchange first, then the fee40xfx − 5g12048004795f(120) = 4800, then g(4800) = 4795gf(x) = 40x − 5
    In the other order the exchange comes first: f(120) = 4800, and then g(4800) = 4795, so gf(x) = 40x − 5.
  5. 5.(b) gf(120) = 4795. The order gf would mean changing all of the money first and then taking a fee of 5 pesos, which leaves the customer 195 pesos better off. The two orders give different functions, so fg ≠ gf.

    fg: the fee first, then the exchangex − 5g40xf1201154600gf: the exchange first, then the fee40xfx − 5g12048004795gf(120) = 4795: a fee of only 5 pesos4795 − 4600 = 195, so fg and gf differ
    fg: the fee first, then the exchangex − 5g40xf1201154600gf: the exchange first, then the fee40xfx − 5g12048004795gf(120) = 4795: a fee of only 5 pesos4795 − 4600 = 195, so fg and gf differ
    (b) gf(120) = 4795. That order would take a fee of 5 pesos after the exchange, 195 pesos better for the customer, so fg ≠ gf.

Answer: (a) fg(x) = 40x − 200; 4600 pesos; (b) gf(120) = 4795, which would mean changing the money first and then taking a fee of 5 pesos, 195 pesos more for the customer

Common mistakes

  • Reading fg(x) from left to right, as f first and then g. The function nearest to x acts first, so fg(x) = f(g(x)): the fee comes off before the money is changed.
  • Multiplying the two rules together, fg(x) = 40x(x − 5). A composite is one function put inside the other, not a product: the output of g becomes the input of f.

More functions problems, worked step by step →

Practice Composite Functions in the app