1. Arithmetic combinations
Given two functions $f$ and $g$, you can build four new functions by performing arithmetic on their outputs at the same input:
$$ \begin{aligned} (f + g)(x) &= f(x) + g(x) \\ (f - g)(x) &= f(x) - g(x) \\ (f \cdot g)(x) &= f(x) \cdot g(x) \\ (f / g)(x) &= f(x) / g(x) \quad \text{provided } g(x) \neq 0 \end{aligned} $$The recipe is the same in every case: evaluate both functions at $x$, then combine the two numbers with the arithmetic operation. Nothing fancy is happening — these are pointwise operations, applied one input at a time.
For instance, with $f(x) = x^2$ and $g(x) = 3x$:
$$ (f + g)(x) = x^2 + 3x, \qquad (f - g)(x) = x^2 - 3x, \qquad (fg)(x) = 3x^3. $$And with $f(x) = x^2 - 1$, $g(x) = x - 1$:
$$ (f / g)(x) = \frac{x^2 - 1}{x - 1} = x + 1 \quad \text{for } x \neq 1. $$That "for $x \neq 1$" matters, and it's the entry point to the next section.
2. Domain of a combination
A combination only makes sense at an input where both ingredients make sense. So the domain of $f \pm g$ and $f \cdot g$ is the intersection of the individual domains:
$$ \text{dom}(f \pm g) = \text{dom}(f \cdot g) = \text{dom}(f) \cap \text{dom}(g). $$For the quotient $f / g$, you also have to throw out any $x$ where the denominator is zero:
$$ \text{dom}(f / g) = \big(\text{dom}(f) \cap \text{dom}(g)\big) \setminus \{x : g(x) = 0\}. $$Above, $(f/g)(x) = (x^2 - 1)/(x - 1)$ simplifies algebraically to $x + 1$ — but the domain still excludes $x = 1$. The plot of the original quotient has a tiny hole at $(1, 2)$ that the simplified form papers over. Whenever you cancel a factor, write down what was lost.
3. Composition: feeding one function into another
Arithmetic combinations are the gentle case. The deeper way to combine two functions is to chain them: take the output of one and pour it straight into the input of the other. That's composition.
The composition of $f$ and $g$, written $f \circ g$, is the function defined by
$$ (f \circ g)(x) = f(g(x)). $$Read right to left: first apply $g$ to $x$, then apply $f$ to the result.
The pipeline picture is almost the whole story. The input $x$ enters on the left, $g$ does its work, hands the number $g(x)$ to $f$, and $f$ delivers the final output.
Concretely, take $f(u) = u^2$ and $g(x) = x + 3$. Then
$$ (f \circ g)(x) = f(g(x)) = f(x + 3) = (x + 3)^2. $$Notice how $g$ "fills in" the variable slot of $f$. Wherever $f$'s formula has its input variable (here written $u$ to keep the slots straight), you substitute the entire expression $g(x)$.
Evaluating at a specific number is even more straightforward — work inside out. With $f(x) = 2x + 1$ and $g(x) = x^2$:
$$ (f \circ g)(3) = f(g(3)) = f(9) = 2(9) + 1 = 19. $$Composition is how complicated functions get built. The function $\sin(2x + 3)$ isn't really one function — it's three simple ones (multiply by 2, add 3, take sine) chained in a specific order. The chain rule in calculus is exactly the rule for differentiating these chains, and it only works once you can see the chain.
4. Order matters: $f \circ g \neq g \circ f$
Addition and multiplication don't care about order: $f + g = g + f$. Composition cares enormously. Swapping which function goes first usually produces a completely different result.
Take $f(x) = x + 1$ and $g(x) = x^2$. Compute both orderings:
$$ \begin{aligned} (f \circ g)(x) &= f(g(x)) = f(x^2) = x^2 + 1, \\ (g \circ f)(x) &= g(f(x)) = g(x + 1) = (x + 1)^2 = x^2 + 2x + 1. \end{aligned} $$These are clearly different functions — they only happen to agree at $x = 0$. The two orderings don't even share a graph.
The everyday analogy is putting on socks and shoes. "Socks then shoes" and "shoes then socks" describe the same two actions in two different orders, and the results are not interchangeable. Function composition captures that kind of sequenced structure: each function is an action, and the order in which you perform them changes what comes out.
Some special pairs satisfy $f \circ g = g \circ f$ — for instance any $f$ with the identity function, or any pair of inverses. But these are exceptions. The default expectation is they're different; treat equality as something you have to prove.
5. Domain of a composition
This is where compositions start to bite. For $(f \circ g)(x) = f(g(x))$ to even be defined at a particular $x$, two things have to be true:
- $x$ has to be in the domain of $g$ — otherwise $g(x)$ isn't a number.
- $g(x)$ has to be in the domain of $f$ — otherwise $f$ can't accept it.
So the domain of the composition is the set of $x$ satisfying both conditions:
$$ \text{dom}(f \circ g) = \{\, x : x \in \text{dom}(g) \text{ and } g(x) \in \text{dom}(f) \,\}. $$The second clause is the sneaky one. The domain of the composition can be strictly smaller than the domain of $g$ — sometimes by a lot.
Worked example: $f(x) = \sqrt{x}$, $g(x) = x - 5$
Here $g$ is defined for all real $x$, but $f$ only accepts non-negative inputs. The composition
$$ (f \circ g)(x) = \sqrt{x - 5} $$requires $g(x) = x - 5 \geq 0$, i.e. $x \geq 5$. So even though $g$'s domain is all of $\mathbb{R}$, the composition's domain shrinks to $[5, \infty)$.
The procedure, in three steps
- Write down $\text{dom}(g)$.
- Identify the constraint from $\text{dom}(f)$, translated into a condition on $g(x)$.
- Take the intersection.
If you simplify $(f \circ g)(x)$ before reading off the domain, you may miss restrictions that originally lived inside $g$ or were enforced by the boundary of $f$. Determine the domain from the two-step form $f(g(x))$, then simplify afterwards.
6. Decomposing a function into a chain
So far we've been going forward: given $f$ and $g$, build $f \circ g$. The reverse question is just as important. Given a single complicated function $h$, can you write it as $h = f \circ g$ for simpler $f$ and $g$? This is decomposition, and it's the prerequisite skill for the chain rule.
The trick is to ask: what's the last thing this function does? That last action is the outer function $f$. Whatever it acts on is the inner function $g$.
Example: $h(x) = \sqrt{x^2 + 1}$
The last thing $h$ does is take a square root. Whatever's under the square root is the inner expression. So:
$$ g(x) = x^2 + 1, \qquad f(u) = \sqrt{u}, \qquad h(x) = f(g(x)). $$Use a fresh letter $u$ for $f$'s input — it's a reminder that $f$ doesn't care where its input came from, only what to do with it.
A few more, side by side
| $h(x)$ | Inner $g(x)$ | Outer $f(u)$ |
|---|---|---|
| $\sin(2x + 3)$ | $2x + 3$ | $\sin u$ |
| $(3x - 1)^7$ | $3x - 1$ | $u^7$ |
| $e^{x^2}$ | $x^2$ | $e^u$ |
| $\dfrac{1}{x + 4}$ | $x + 4$ | $1/u$ |
Chains of three or more
Some functions are deeper than a single layer. Take $h(x) = \sqrt{\sin(x^2)}$. The last action is $\sqrt{\cdot}$, applied to $\sin(x^2)$; and that itself is a composition. Writing $h = f \circ g \circ k$ with
$$ k(x) = x^2, \qquad g(u) = \sin u, \qquad f(v) = \sqrt{v}, $$gives $h(x) = f(g(k(x)))$. Composition is associative — it doesn't matter whether you parenthesize as $(f \circ g) \circ k$ or $f \circ (g \circ k)$ — so writing $f \circ g \circ k$ is unambiguous.
You could split $h(x) = \sqrt{x^2 + 1}$ differently — say $g(x) = x^2$ and $f(u) = \sqrt{u + 1}$ — and the chain still composes correctly. Both are valid. Prefer the decomposition that makes the structure most transparent, which usually means peeling off one operation at a time.
7. Identity, and a peek at inverses
Among all functions, one is special under composition: the identity function $\text{id}(x) = x$. It does nothing, and so leaves whatever it composes with unchanged:
$$ f \circ \text{id} = \text{id} \circ f = f. $$It plays the same role for composition that $0$ plays for addition or $1$ plays for multiplication — a neutral element that leaves things alone.
Now ask the next question: given a function $f$, is there another function $f^{-1}$ that undoes it, in the sense that
$$ f \circ f^{-1} = \text{id} \quad \text{and} \quad f^{-1} \circ f = \text{id}\,? $$If so, $f^{-1}$ is the inverse of $f$ — the partner that puts every output back to the input it came from. Not every function has one (you need each output to come from a single input), and finding inverses, characterising when they exist, and reading them off a graph is the entire next topic.
Inverse functions are defined by composition: $f^{-1}$ is the unique function — when it exists — that composes with $f$ to give the identity on both sides. That definition is why everything in this topic is the right warm-up for what comes next. See Inverse Functions.
8. Common pitfalls
$(fg)(x) = f(x) \cdot g(x)$ multiplies the two outputs at $x$. $(f \circ g)(x) = f(g(x))$ feeds one into the other. With $f(x) = x + 1$ and $g(x) = x^2$, the product is $x^3 + x^2$ but the composition is $x^2 + 1$ — wildly different.
The notation $f \circ g$ means "$f$ after $g$" — $g$ runs first, despite appearing on the right. The motivation is the formula $f(g(x))$: $g$ is closer to the input $x$, so it acts first. Always evaluate inside out.
$(f / g)(x) = (x^2 - 1)/(x - 1)$ simplifies to $x + 1$, but $x = 1$ remains excluded. Similarly, $\sqrt{x}^2$ simplifies to $x$ but only for $x \geq 0$. Carry the constraints with you even after the algebra gets prettier.
It is almost always the case that $f \circ g \neq g \circ f$. Never substitute one for the other without checking — the swap can quietly invalidate every later step.
9. Worked examples
Try each one yourself before opening the solution. The point is to internalise the procedure, not to match a number.
Example 1 · Sum, product, quotient of $f(x) = x^2$ and $g(x) = x - 2$
Sum: $(f + g)(x) = x^2 + (x - 2) = x^2 + x - 2$.
Product: $(fg)(x) = x^2(x - 2) = x^3 - 2x^2$.
Quotient: $(f / g)(x) = \dfrac{x^2}{x - 2}$, valid for $x \neq 2$.
Domains. Both $f$ and $g$ have domain $\mathbb{R}$. Sum and product: $\mathbb{R}$. Quotient: $\mathbb{R} \setminus \{2\}$.
Example 2 · Both compositions of $f(x) = 2x + 1$ and $g(x) = x^2$
$f \circ g$: $f(g(x)) = f(x^2) = 2x^2 + 1$.
$g \circ f$: $g(f(x)) = g(2x + 1) = (2x + 1)^2 = 4x^2 + 4x + 1$.
Check. At $x = 3$: $(f \circ g)(3) = 19$; $(g \circ f)(3) = 49$. Different, as expected.
Example 3 · Domain of $f(x) = \sqrt{x}$ composed with $g(x) = 9 - x^2$
$(f \circ g)(x) = \sqrt{9 - x^2}$.
Step 1. $\text{dom}(g) = \mathbb{R}$.
Step 2. Need $g(x) \geq 0$, i.e. $9 - x^2 \geq 0$, i.e. $-3 \leq x \leq 3$.
Domain: $[-3, 3]$. (This is the upper half of a circle of radius 3, by the way.)
Example 4 · Decompose $h(x) = \dfrac{1}{(x + 5)^3}$
Peel from the outside. The last action is "take reciprocal of a cube." Splitting once gives outer $f(u) = 1/u^3$ and inner $g(x) = x + 5$, so $h = f \circ g$.
Or peel one operation at a time: $k(x) = x + 5$, then $g(u) = u^3$, then $f(v) = 1/v$, giving $h = f \circ g \circ k$. Both decompositions are correct; the deeper one is more useful for the chain rule.
Example 5 · Triple composition evaluated
Let $f(x) = x + 1$, $g(x) = x^2$, $h(x) = \sqrt{x}$. Compute $(f \circ g \circ h)(4)$.
Inside out: $h(4) = 2$, then $g(2) = 4$, then $f(4) = 5$.
So $(f \circ g \circ h)(4) = 5$.
Example 6 · Find $f$ from a known composition
Suppose $g(x) = x + 1$ and $(f \circ g)(x) = x^2 + 2x + 1$. Find $f$.
Notice that $x^2 + 2x + 1 = (x + 1)^2 = g(x)^2$. So $f$ takes its input and squares it: $f(u) = u^2$.
Check. $f(g(x)) = (x + 1)^2 = x^2 + 2x + 1$ ✓.