Combining and Composing Functions Advanced. This lesson goes beyond core Algebra I. You can skip it.

Learning goals

  • Add, subtract, multiply and divide two functions, excluding any input where the divisor is zero
  • Compose with (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)), inner first
  • Substitute the whole inner rule to get a composed formula
  • Show that f∘gf \circ g usually differs from g∘fg \circ f
  • Require an input allowed into both functions in turn

Building new functions by arithmetic

Suppose f(x)=3xf(x)=3x and g(x)=x+2g(x)=x+2 give two runners’ positions in meters from the same starting mark, xx seconds after they start. The second runner has a two-meter head start. At time xx, the sum of their positions is f(x)+g(x)f(x)+g(x). The difference f(x)−g(x)f(x)-g(x) tells how far the first runner is ahead; it is negative while the first runner is behind.

You evaluate both functions at the same input, then combine their outputs. In general:

(f+g)(x)=f(x)+g(x),(f−g)(x)=f(x)−g(x),(f + g)(x) = f(x) + g(x), \qquad (f - g)(x) = f(x) - g(x), (fg)(x)=f(x)⋅g(x),(fg)(x)=f(x)g(x).(fg)(x) = f(x) \cdot g(x), \qquad \left(\frac{f}{g}\right)(x) = \frac{f(x)}{g(x)}.

Each combination is a new function. For example, f+gf+g means “evaluate both functions at the input and add their outputs.”

The sum, difference and product use only inputs accepted by both functions. The quotient needs that same shared domain and one further condition: g(x)≠0g(x)\ne0. Even if both outputs exist, their quotient does not exist when its denominator is zero.

Worked example 1 Adding, subtracting, multiplying, and dividing two functions

Let f(x)=3xf(x) = 3x and g(x)=x+2g(x) = x + 2, now treated simply as algebra rules that accept any real number xx, not only the runner story’s elapsed time. Build all four combinations, and find where the quotient is defined.

For the sum, subtraction, and product, substitute the two rules and simplify:

(f+g)(x)=3x+(x+2)=4x+2,(f + g)(x) = 3x + (x + 2) = 4x + 2,(f−g)(x)=3x−(x+2)=2x−2,(f - g)(x) = 3x - (x + 2) = 2x - 2,(fg)(x)=3x⋅(x+2)=3x2+6x.(fg)(x) = 3x \cdot (x + 2) = 3x^2 + 6x.

For the quotient, write the fraction and then find the input that would make the denominator zero:

(fg)(x)=3xx+2,x+2=0  ⟹  x=−2.\left(\frac{f}{g}\right)(x) = \frac{3x}{x + 2}, \qquad x + 2 = 0 \;\Longrightarrow\; x = -2.

So fg\dfrac{f}{g} is defined for every input except x=−2x = -2. You can also evaluate any combination at a number. At x=4x = 4, for instance, f(4)=12f(4) = 12 and g(4)=6g(4) = 6, so (f+g)(4)=18(f + g)(4) = 18 and (fg)(4)=72(fg)(4) = 72.

Check your understanding

If f(x)=x+6f(x) = x + 6 and g(x)=2xg(x) = 2x, what is (f+g)(x)(f + g)(x)?

Answer choices

Composing: feeding one function into another

Picture two machines in an assembly line. The first receives the input, and its output goes directly into the second. This differs from evaluating both functions at the original input.

Make it concrete with g(x)=x+4g(x) = x + 4 and f(x)=x2f(x) = x^2. Start with an input, say 33. Run gg first: g(3)=3+4=7g(3) = 3 + 4 = 7. Now take that result, 77, and run it through ff: f(7)=72=49f(7) = 7^2 = 49. The end product of the two-step process is 4949. Written on one line, this is f(g(3))f(g(3)): the inner function gg acts on 33, and ff acts on whatever gg hands it.

This two-step operation is composition, and it has its own symbol. The composition of ff and gg is written f∘gf \circ g (read ”ff composed with gg,” or ”ff after gg”), and it is defined by

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

The little ring ∘\circ is not multiplication and not the letter o; it is the composition sign. The right-hand side, f(g(x))f(g(x)), is the form you actually calculate with.

Notice how different this is from the product fgfg from the last section. The product runs ff and gg side by side on the same input and multiplies the two outputs. Composition runs them in a chain: gg‘s output becomes ff‘s input. For f(x)=x+1f(x) = x + 1 and g(x)=2xg(x) = 2x at x=3x = 3, the product is (fg)(3)=f(3)⋅g(3)=4⋅6=24(fg)(3) = f(3) \cdot g(3) = 4 \cdot 6 = 24, but the composition is (f∘g)(3)=f(g(3))=f(6)=7(f \circ g)(3) = f(g(3)) = f(6) = 7.

In f(g(x))f(g(x)), work from the inside out, as with nested arithmetic parentheses. The inner function is gg, the one applied directly to xx. The outer function is ff, which receives g(x)g(x). Thus gg runs first even though it is written second in f∘gf\circ g.

Composition runs g first and f secondThe stages run downward: 3, g with rule x+4, 7, f with rule x squared, 49.input 3gg(x) = x + 4g(3) = 7ff(x) = x²f(g(3)) = 49
Composition as a two-machine assembly line. The input enters the inner machine g first, its output becomes the input of the outer machine f, and f produces the final result. Reading f(g(3)) from the inside out matches the order the machines run: g, then f.

Worked example 2 Composing at a number in both orders

Let f(x)=x2f(x) = x^2 and g(x)=x+4g(x) = x + 4. You already found f(g(3))=49f(g(3)) = 49 above by running gg first and then ff. Now reverse the order and compute g(f(3))g(f(3)): run ff on 33 first, then run gg on the result.

f(3)=32=9,g(9)=9+4=13.f(3) = 3^2 = 9, \qquad g(9) = 9 + 4 = 13.

So g(f(3))=13g(f(3))=13, whereas f(g(3))=49f(g(3))=49. Reversing the order changed the answer.

Finding a formula for a composition

A formula for f∘gf\circ g describes the whole two-step process. Build it by substituting the entire expression g(x)g(x) wherever the rule for ff expects an input. Keep parentheses around that expression.

Worked example 3 Finding a formula for f∘gf \circ g and g∘fg \circ f

Let f(x)=x2f(x) = x^2 and g(x)=x+4g(x) = x + 4. Find formulas for (f∘g)(x)(f \circ g)(x) and (g∘f)(x)(g \circ f)(x).

For f∘gf \circ g, substitute the whole rule g(x)=x+4g(x) = x + 4 into ff in place of its input, then expand the square. Recall (a+b)2=a2+2ab+b2(a + b)^2 = a^2 + 2ab + b^2, so with a=xa = x and b=4b = 4:

(f∘g)(x)=f(g(x))=f(x+4)=(x+4)2=x2+2(4x)+42=x2+8x+16.\begin{aligned} (f \circ g)(x) &= f(g(x)) = f(x + 4) = (x + 4)^2 \\ &= x^2 + 2(4x) + 4^2 = x^2 + 8x + 16. \end{aligned}

For g∘fg \circ f, substitute the whole rule f(x)=x2f(x) = x^2 into gg in place of its input:

(g∘f)(x)=g(f(x))=g(x2)=x2+4.(g \circ f)(x) = g(f(x)) = g(x^2) = x^2 + 4.

These two formulas describe different functions. Putting x=3x = 3 into x2+8x+16x^2 + 8x + 16 and into x2+4x^2 + 4 gives 4949 and 1313, the same numbers the previous worked example found by running the machines step by step.

Check your understanding

If f(x)=2xf(x) = 2x and g(x)=x+1g(x) = x + 1, what is (f∘g)(x)(f \circ g)(x)?

Answer choices

Check your understanding

If f(x)=x2f(x) = x^2 and g(x)=x−1g(x) = x - 1, what is f(g(4))f(g(4))?

Answer choices

Order matters: a composition is not commutative

The examples show that composition is not commutative: you cannot generally swap its order. Squaring and then adding four gives x2+4x^2+4. Adding four first and then squaring gives (x+4)2=x2+8x+16(x+4)^2=x^2+8x+16. In the second order, the added four is part of what gets squared.

Some pairs do give the same function in both orders, but that must be checked. Equality of functions requires the same domain and the same output at every allowed input. A disagreement such as 49≠1349\ne13 at input 33 proves these two compositions differ; agreement at one input alone would not prove equality.

The two orders give 49 and 13Left: f after g gives 49. Right: g after f gives 13. Both start at 3.f(g(3))3add 47square49g, then fg(f(3))3square9add 413f, then g
Read each chain downward from input 3. Adding 4 then squaring gives 49; squaring then adding 4 gives 13. The outer function runs last, so it acts on the result of the earlier step.

The domain of a composition

A composition accepts an input only if both steps can be carried out.

Worked example 4 The domain of a composition

Let f(x)=1xf(x) = \dfrac{1}{x} and g(x)=x−4g(x) = x - 4. Find (f∘g)(x)(f \circ g)(x) and its domain.

Substitute gg into ff to get the formula:

(f∘g)(x)=f(g(x))=f(x−4)=1x−4.(f \circ g)(x) = f(g(x)) = f(x - 4) = \frac{1}{x - 4}.

At x=4x=4, the inner step works: g(4)=0g(4)=0. The outer step fails because f(0)=10f(0)=\dfrac10 is undefined. At x=6x=6, both steps work: g(6)=2g(6)=2, then f(2)=12f(2)=\dfrac12. Since gg accepts every real input and produces zero only at 44, the domain of f∘gf\circ g is all real numbers except 44.

You can use the same two checks to find the domain of any composition.

Which inputs a composition accepts#

Take g(x)=1x−2g(x)=\dfrac1{x-2} and f(u)=uf(u)=\sqrt{u}, using real numbers. At input 22, the first step fails because g(2)g(2) would divide by zero. At input 11, the first step gives g(1)=−1g(1)=-1, but the second step fails because −1\sqrt{-1} is not real. Input 33 passes both steps: g(3)=1g(3)=1 and f(1)=1f(1)=1.

For any composition f(g(x))f(g(x)), first xx must be in the domain of gg. Otherwise g(x)g(x) does not exist, so there is no output to pass to ff. Next, the produced value g(x)g(x) must be in the domain of ff. Otherwise the second step has no value.

These conditions are also sufficient: when g(x)g(x) exists and ff accepts it, f(g(x))f(g(x)) exists. Thus the domain consists exactly of the inputs passing both checks.

Keep those checks even if the formula simplifies. For example, if f(x)=1xf(x)=\dfrac1x and g(x)=1x−5g(x)=\dfrac1{x-5}, then

f(g(x))=11/(x−5)=x−5,x≠5.f(g(x))=\frac{1}{1/(x-5)}=x-5,\qquad x\ne5.

The simplified expression x−5x-5 accepts 55, but this composition does not: its first step g(5)g(5) is undefined. For every other input, g(x)g(x) is nonzero, so the second step is allowed. Simplifying a formula does not restore an excluded input.

Check your understanding

Let f(x)=1xf(x) = \dfrac{1}{x} and g(x)=x−7g(x) = x - 7. Which input is NOT in the domain of f∘gf \circ g?

Answer choices

Composition models a two-step process

When one quantity determines a second, which then determines a third, you can write the chain as a composition. Examples include discounts followed by fees, converted readings, and area determined by a changing length.

Worked example 5 A discount followed by shipping

An online store takes 2020 percent off every item, then adds a flat shipping fee of 55 dollars to the discounted price. Model the final price as a composition, and find it for an item that normally costs 4040 dollars.

Name the two steps. Taking 2020 percent off leaves 8080 percent of the price, so the discount function is d(p)=0.8pd(p) = 0.8p. Adding shipping to a price is s(x)=x+5s(x) = x + 5. The store discounts first and then adds shipping to the discounted price, so shipping is the outer function and the final price is s(d(p))s(d(p)):

s(d(p))=s(0.8p)=0.8p+5.s(d(p)) = s(0.8p) = 0.8p + 5.

For an item with p=40p = 40:

s(d(40))=0.8(40)+5=32+5=37.s(d(40)) = 0.8(40) + 5 = 32 + 5 = 37.

The final price is 3737 dollars. Had the store instead added shipping first and then discounted, the result would be d(s(p))=0.8(p+5)=0.8p+4d(s(p)) = 0.8(p + 5) = 0.8p + 4, which at p=40p = 40 gives 3636 dollars. That policy discounts the shipping fee too, so it costs one dollar less.

Common mistakes

Practice

Multiple Choice Questions (MCQ)

Progressively harder sets of questions. Each opens on its own page.

Core practice

Practice problems at the level of the course, to be worked out on paper. Hints one at a time, then the answer or the full worked solution, with your progress kept in this browser.

Core practice Work it out on paper 10 problems Start →
More practice (optional)

Extra sets, as hard as the Challenge set. Each one opens on its own page.

More resources (optional)

Other explanations of this lesson, if you want a second take.

A bit of history (optional)

Before designing his calculating engines, Charles Babbage asked what algebra could do with an unknown function rather than an unknown number. His paper An Essay towards the Calculus of Functions appeared in 1815, when he was in his early twenties.

Ordinary equations ask for a number that makes a statement true. Babbage studied equations in which the unknown was a whole rule. Composition made it possible to describe how such a rule behaved when applied after another rule, or after itself.

Babbage is better known for his later engines, but this earlier paper is the one that connects to this lesson. In a chain of calculations you must keep track of which operation acts first: feeding gg‘s result into ff is a different order from feeding ff‘s result into gg, even when some particular rules happen to give the same result in both orders.

Source: Babbage’s 1815 paper in the Royal Society archive and its published abstract.

Your progress

See all your progress →