Math Core

Lesson 1.3 · Functions

Combining and composing functions

Complicated functions are usually built from simple ones. A company's profit is revenue minus cost; the area of a spreading oil spill depends on its radius, which depends on time. This lesson covers the two ways to build new functions from old ones, arithmetic combinations and composition, and the part students most often skip: working out the domain of the result.

Sums, differences, products and quotients

Given two functions ff and gg, you can combine their outputs input by input:

(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)\,g(x), \qquad \left(\frac{f}{g}\right)(x) = \frac{f(x)}{g(x)}

To compute (f+g)(x)(f + g)(x) at some input, you need both f(x)f(x) and g(x)g(x) to exist. So the domain of f+gf + g, f−gf - g and fgfg is the set of inputs in both domains, the intersection. A quotient has one extra condition: the denominator can't be zero.

Domains of combined functions

  • f+gf + g, f−gf - g, fgfg: all xx in the domain of ff and in the domain of gg.
  • fg\dfrac{f}{g}: the same, and g(x)≠0g(x) \ne 0.

Find the domain from the original functions, before simplifying. Simplifying can hide a restriction.

Worked example: A quotient and its domain

Let f(x)=x+3f(x) = \sqrt{x + 3} and g(x)=x−1g(x) = x - 1. Find (fg)(6)(fg)(6) and the domain of fg\dfrac{f}{g}.

(fg)(6)=f(6) g(6)=9⋅5=15(fg)(6) = f(6)\,g(6) = \sqrt{9} \cdot 5 = 15.

The domain of ff is x≥−3x \ge -3. The domain of gg is all real numbers. For the quotient, also exclude g(x)=0g(x) = 0, which happens at x=1x = 1. The domain of fg\dfrac{f}{g} is

[−3,1)∪(1,∞)[-3, 1) \cup (1, \infty)

Composition

Composition feeds the output of one function into another.

Definition

Composition

The composition of ff with gg is

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

Read it as "ff of gg of xx." The function written on the right, gg, acts first; its output becomes the input of ff.

Think of an assembly line: xx enters machine gg, the product g(x)g(x) comes out and goes straight into machine ff. To find a formula for f(g(x))f\big(g(x)\big), substitute the entire expression g(x)g(x) for every xx in the rule for ff.

Worked example: Composing in both orders

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

f(g(x))=(2x−3)2+1=4x2−12x+10f\big(g(x)\big) = (2x - 3)^2 + 1 = 4x^2 - 12x + 10g(f(x))=2(x2+1)−3=2x2−1g\big(f(x)\big) = 2(x^2 + 1) - 3 = 2x^2 - 1

The two results are different: composition is not commutative.

For a single value, work from the inside out: g(2)=1g(2) = 1, then f(1)=2f(1) = 2. So f(g(2))=2f\big(g(2)\big) = 2. (Check with the formula: 4(4)−24+10=24(4) - 24 + 10 = 2.)

Common mistake

f(g(x))f\big(g(x)\big) is not the product f(x) g(x)f(x)\,g(x). The small circle in f∘gf \circ g means composition, not multiplication. For the functions above, f(x) g(x)=(x2+1)(2x−3)f(x)\,g(x) = (x^2 + 1)(2x - 3), which is a cubic, while f(g(x))f\big(g(x)\big) is a quadratic.

The domain of a composition

For f(g(x))f\big(g(x)\big) to exist, two things must happen in order:

  1. xx must be in the domain of gg, so that g(x)g(x) exists.
  2. g(x)g(x) must be in the domain of ff, so that ff can accept it.

The simplified formula alone can mislead you. For example, if g(x)=xg(x) = \sqrt{x} and f(x)=x2f(x) = x^2, then f(g(x))=(x)2=xf\big(g(x)\big) = (\sqrt{x})^2 = x, which looks defined everywhere. But gg can't accept negative inputs, so the domain of f∘gf \circ g is only x≥0x \ge 0.

Worked example: Domains of compositions

Let f(x)=1x−2f(x) = \dfrac{1}{x - 2} and g(x)=xg(x) = \sqrt{x}. Find the domains of f∘gf \circ g and g∘fg \circ f.

f(g(x))=1x−2f\big(g(x)\big) = \dfrac{1}{\sqrt{x} - 2}. First, gg needs x≥0x \ge 0. Then ff can't accept the input 22, so we need x≠2\sqrt{x} \ne 2, which means x≠4x \ne 4. Domain: [0,4)∪(4,∞)[0, 4) \cup (4, \infty).

g(f(x))=1x−2g\big(f(x)\big) = \sqrt{\dfrac{1}{x - 2}}. First, ff needs x≠2x \ne 2. Then gg needs its input to be nonnegative: 1x−2≥0\dfrac{1}{x - 2} \ge 0. A fraction with numerator 11 is never 00, and it is positive exactly when x−2>0x - 2 > 0. Domain: (2,∞)(2, \infty).

f(g(x)) exists only for x ≥ 0 and breaks at x = 4; g(f(x)) exists only for x > 2.Open in grapher →

Compositions from tables and graphs

You don't need formulas to compose. Given a table or a graph, evaluate from the inside out, one step at a time.

Worked example: Composing with a table

Use the table to find f(g(1))f\big(g(1)\big), g(f(3))g\big(f(3)\big) and (f∘f)(2)(f \circ f)(2).

xx0011223344
f(x)f(x)2244330011
g(x)g(x)3300441122
  • g(1)=0g(1) = 0, then f(0)=2f(0) = 2. So f(g(1))=2f\big(g(1)\big) = 2.
  • f(3)=0f(3) = 0, then g(0)=3g(0) = 3. So g(f(3))=3g\big(f(3)\big) = 3.
  • f(2)=3f(2) = 3, then f(3)=0f(3) = 0. So (f∘f)(2)=0(f \circ f)(2) = 0.

Decomposing a function

Going backward is just as useful, especially in calculus: given a complicated function hh, find an inner function gg and an outer function ff with h(x)=f(g(x))h(x) = f\big(g(x)\big). Look for the "inside" expression that is being plugged into something.

  • h(x)=(3x−1)5h(x) = (3x - 1)^5: inner g(x)=3x−1g(x) = 3x - 1, outer f(x)=x5f(x) = x^5.
  • h(x)=2x+4h(x) = \dfrac{2}{\sqrt{x + 4}}: inner g(x)=x+4g(x) = x + 4, outer f(x)=2xf(x) = \dfrac{2}{\sqrt{x}}. (Or inner x+4\sqrt{x + 4} and outer 2x\dfrac{2}{x}. Decompositions aren't unique.)

Tip

Check a decomposition by composing it back: if f(x)=x5f(x) = x^5 and g(x)=3x−1g(x) = 3x - 1, then f(g(x))=(3x−1)5f\big(g(x)\big) = (3x - 1)^5. It matches.

Practice

Practice 1

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

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

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

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Let f(x)=3x−2f(x) = 3x - 2 and g(x)=x2+1g(x) = x^2 + 1. Find a formula for g(f(x))g\big(f(x)\big).

Enter an expression, e.g. 3x^2 - 2x + 1

Practice 4

Use the table to find g(f(g(1)))g\Big(f\big(g(1)\big)\Big).

xx1122334455
f(x)f(x)3355112244
g(x)g(x)2211445533

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

Let f(x)=xf(x) = \sqrt{x} and g(x)=5−xg(x) = 5 - x. What is the domain of f(g(x))f\big(g(x)\big)? Write it as an inequality in xx.

Enter an inequality, e.g. x >= 4, -2 < x <= 3, or x < 1 or x > 5

Practice 6

Let f(x)=1xf(x) = \dfrac{1}{x} and g(x)=x2−4g(x) = x^2 - 4. What is the domain of f∘gf \circ g?

Practice 7

The function h(x)=x2+7h(x) = \sqrt{x^2 + 7} can be written as h(x)=f(g(x))h(x) = f\big(g(x)\big). Which pair works?

Practice 8

Let f(x)=xx−1f(x) = \dfrac{x}{x - 1}. Find and simplify f(f(x))f\big(f(x)\big).

Enter an expression, e.g. 3x^2 - 2x + 1