Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 37 · Function Analysis

Composition and Inverse Functions

Combine functions by composition, learn one-to-one functions and the horizontal line test, and find inverses algebraically and graphically in Python.

Functions can be combined, and sometimes they can be undone. Both ideas are everywhere in later math: a chain of operations is a composition, and "undoing" an operation is an inverse. This lesson covers how to build and take apart composite functions, and how to find an inverse when one exists.

Combining functions

You can add, subtract, multiply and divide functions pointwise:

(f + g)(x) = f(x) + g(x), (fg)(x) = f(x)·g(x), (f/g)(x) = f(x)/g(x) (with g(x) ≠ 0).

The domain of the result is the set of inputs allowed by both functions (and, for a quotient, with g(x) ≠ 0).

Composition

The composition (f ∘ g)(x) = f(g(x)) means: apply g first, then feed the result to f. Work from the inside out.

If f(x) = x² + 1 and g(x) = 2x - 3:

  • f(g(x)) = (2x - 3)² + 1 = 4x² - 12x + 10
  • g(f(x)) = 2(x² + 1) - 3 = 2x² - 1

The two results differ, so composition is not commutative: order matters.

flowchart LR
X["x"] --> G["g: double,<br/>subtract 3"]
G --> F["f: square,<br/>add 1"]
F --> Y["f(g(x))"]

Composition as a pipeline: g runs first.

The domain of f ∘ g is the set of x in the domain of g such that g(x) is in the domain of f. For f(x) = √x and g(x) = x - 4, f(g(x)) = √(x - 4) needs x ≥ 4.

Composition is also how you decompose a complicated function: h(x) = (3x + 1)⁵ is f(g(x)) with inner g(x) = 3x + 1 and outer f(u) = u⁵. Calculus uses this to differentiate (the chain rule).

Python Compose functions in code

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

One-to-one functions and the horizontal line test

A function is one-to-one if different inputs always give different outputs. Graphically, use the horizontal line test: if no horizontal line crosses the graph more than once, the function is one-to-one.

f(x) = x³ passes. f(x) = x² fails (f(2) = f(-2) = 4). But if you restrict the domain to x ≥ 0, then x² is one-to-one. Restricting the domain is the standard way to rescue an inverse.

Inverse functions

If f is one-to-one, its inverse f⁻¹ reverses it: if f(a) = b, then f⁻¹(b) = a. The two satisfy:

f⁻¹(f(x)) = x and f(f⁻¹(x)) = x

(Note: f⁻¹(x) is not 1/f(x). The -1 is a label for the inverse.)

To find an inverse algebraically:

  1. Write y = f(x).
  2. Swap x and y.
  3. Solve for y.
  4. Check with composition.

Example: f(x) = (2x + 3)/5. Swap: x = (2y + 3)/5, so 5x = 2y + 3, so y = (5x - 3)/2. Hence f⁻¹(x) = (5x - 3)/2.

Graphically, f and f⁻¹ are mirror images in the line y = x, because swapping x and y reflects the plane. The domain of f becomes the range of f⁻¹, and vice versa.

Python Find an inverse with SymPy

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python A function and its inverse mirror in y = x

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

An inverse exists only for a one-to-one function. f(x) = x² on all real numbers has no inverse until you restrict the domain.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. If f(x) = x + 2 and g(x) = 3x, what is f(g(x))?

    Apply g first: g(x) = 3x. Then f adds 2: 3x + 2.
  2. 2. Which function passes the horizontal line test?

    x³ never repeats an output. x² and |x| both give the same output for x and -x.
  3. 3. What is the inverse of f(x) = 2x - 6?

    Swap and solve: x = 2y - 6, so y = (x + 6)/2.
  4. 4. The graph of f and its inverse are reflections in which line?

    Swapping x and y is a reflection in the line y = x.

Summary

  • (f ∘ g)(x) = f(g(x)): apply g first. Order matters.
  • One-to-one functions pass the horizontal line test and can be inverted.
  • To invert: write y = f(x), swap x and y, solve for y, check.
  • A function and its inverse mirror in y = x; domain and range swap.

Next: Piecewise and Absolute Value Functions