Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Composition






Functions Within Functions

Some processes happen in stages. Convert a temperature from Celsius to Fahrenheit, then from Fahrenheit to Rankine. Apply a discount to a price, then add tax to the result. Each stage is a function, and the stages chain together — the output of one becomes the input of the next.

This chaining is composition. Given functions ff and gg, the composition fgf \circ g applies gg first, then feeds the result into ff. The output of gg becomes the input of ff, creating a single combined process from two separate ones.



What is Function Composition

Function composition connects two functions in sequence: the output of the first becomes the input of the second. The result is a new function that combines both operations.

If gg takes an input xx and produces g(x)g(x), and ff then takes g(x)g(x) and produces f(g(x))f(g(x)), the composition fgf \circ g captures this two-step process as a single function:

(fg)(x)=f(g(x))(f \circ g)(x) = f(g(x))


The function gg acts first, transforming the original input. The function ff acts second, transforming the intermediate result. The final output depends on both functions working in sequence.

Composition differs fundamentally from arithmetic. Adding functions combines their outputs at the same input: (f+g)(x)=f(x)+g(x)(f + g)(x) = f(x) + g(x). Composing functions chains their operations: (fg)(x)=f(g(x))(f \circ g)(x) = f(g(x)). The input to ff in composition is not xx but g(x)g(x).

Composition creates new functions with potentially different domains, ranges, and properties than either component.

Notation for Composition

Several notations express the same composition:

(fg)(x)=f(g(x))(f \circ g)(x) = f(g(x))


The symbol \circ denotes composition. Read fgf \circ g as "ff composed with gg" or "ff of gg."

The notation f(g(x))f(g(x)) shows the structure explicitly: g(x)g(x) is computed first, then ff is applied to that result. The inner function gg acts first; the outer function ff acts second.

Some texts write fg(x)fg(x) without the composition symbol, relying on context to distinguish from multiplication. This notation risks confusion and is best avoided unless the meaning is clear.

The order in the notation matters critically. In fgf \circ g, the function gg appears on the right but acts first. The function ff appears on the left but acts second. This right-to-left reading matches the nested parentheses in f(g(x))f(g(x)): evaluate from the inside out.

When speaking aloud, "ff of gg of xx" follows the written order while preserving the evaluation sequence: start with xx, apply gg, then apply ff.

Evaluating Compositions at a Point

To find (fg)(a)(f \circ g)(a) for a specific input aa, work from the inside out:

Step 1: Evaluate the inner function: compute g(a)g(a).

Step 2: Evaluate the outer function at that result: compute f(g(a))f(g(a)).

Let f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x2g(x) = 3x - 2. Find (fg)(4)(f \circ g)(4).

Step 1: g(4)=3(4)2=10g(4) = 3(4) - 2 = 10

Step 2: f(10)=102+1=101f(10) = 10^2 + 1 = 101

Therefore (fg)(4)=101(f \circ g)(4) = 101.

Now find (gf)(4)(g \circ f)(4) — the composition in the opposite order.

Step 1: f(4)=42+1=17f(4) = 4^2 + 1 = 17

Step 2: g(17)=3(17)2=49g(17) = 3(17) - 2 = 49

Therefore (gf)(4)=49(g \circ f)(4) = 49.

The two results differ: 10149101 \neq 49. The order of composition matters — fgf \circ g and gfg \circ f are generally different functions.

Finding Composite Functions Algebraically

To find the formula for (fg)(x)(f \circ g)(x), substitute the entire expression for g(x)g(x) into ff wherever ff has its input variable.

Let f(x)=x24f(x) = x^2 - 4 and g(x)=2x+1g(x) = 2x + 1. Find (fg)(x)(f \circ g)(x).

Start with f(x)=x24f(x) = x^2 - 4. Replace every xx with g(x)=2x+1g(x) = 2x + 1:

f(g(x))=(2x+1)24f(g(x)) = (2x + 1)^2 - 4


Expand and simplify:

(2x+1)24=4x2+4x+14=4x2+4x3(2x + 1)^2 - 4 = 4x^2 + 4x + 1 - 4 = 4x^2 + 4x - 3


So (fg)(x)=4x2+4x3(f \circ g)(x) = 4x^2 + 4x - 3.

Now find (gf)(x)(g \circ f)(x). Start with g(x)=2x+1g(x) = 2x + 1. Replace xx with f(x)=x24f(x) = x^2 - 4:

g(f(x))=2(x24)+1=2x28+1=2x27g(f(x)) = 2(x^2 - 4) + 1 = 2x^2 - 8 + 1 = 2x^2 - 7


So (gf)(x)=2x27(g \circ f)(x) = 2x^2 - 7.

The two composite functions are different, confirming that composition is not commutative.

Domain of Composite Functions

The domain of a composite function fgf \circ g is not simply the intersection of the two domains. Two conditions must be satisfied:

1. xx must be in the domain of gg — the inner function must be able to process the input.

2. g(x)g(x) must be in the domain of ff — the output of gg must be a valid input for ff.

Let f(x)=xf(x) = \sqrt{x} with domain [0,)[0, \infty) and g(x)=x3g(x) = x - 3 with domain (,)(-\infty, \infty).

For (fg)(x)=x3(f \circ g)(x) = \sqrt{x - 3}:

Condition 1: gg accepts all real xx — no restriction here.

Condition 2: ff requires g(x)0g(x) \geq 0, so x30x - 3 \geq 0, meaning x3x \geq 3.

The domain of fgf \circ g is [3,)[3, \infty).

Let f(x)=1/xf(x) = 1/x with domain x0x \neq 0 and g(x)=x21g(x) = x^2 - 1.

For (fg)(x)=1x21(f \circ g)(x) = \dfrac{1}{x^2 - 1}:

Condition 1: gg accepts all real xx.

Condition 2: ff requires g(x)0g(x) \neq 0, so x210x^2 - 1 \neq 0, meaning x±1x \neq \pm 1.

The domain of fgf \circ g is {x:x1 and x1}\{x : x \neq -1 \text{ and } x \neq 1\}.

Non-Commutativity

Composition is not commutative: fgf \circ g does not generally equal gfg \circ f. The order of the functions determines the result.

Let f(x)=x+5f(x) = x + 5 and g(x)=x2g(x) = x^2.

(fg)(x)=f(g(x))=f(x2)=x2+5(f \circ g)(x) = f(g(x)) = f(x^2) = x^2 + 5

(gf)(x)=g(f(x))=g(x+5)=(x+5)2=x2+10x+25(g \circ f)(x) = g(f(x)) = g(x + 5) = (x + 5)^2 = x^2 + 10x + 25

These are different functions with different graphs and different values at most inputs. Only at specific points might they coincide by accident.

Non-commutativity reflects the asymmetry of chained processes. Converting Celsius to Fahrenheit, then to Rankine produces a different result than converting Celsius to Rankine, then to Fahrenheit — if such a path even made sense.

In rare cases, fg=gff \circ g = g \circ f. When both functions are linear with the same slope but different intercepts, for example, or when one function is the identity. But these are special cases, not the general rule.

Composing More Than Two Functions

Composition extends to three or more functions. The principle remains the same: evaluate from the innermost function outward.

For three functions ff, gg, and hh:

(fgh)(x)=f(g(h(x)))(f \circ g \circ h)(x) = f(g(h(x)))


The function hh acts first on xx, producing h(x)h(x). Then gg acts on that result, producing g(h(x))g(h(x)). Finally ff acts, producing f(g(h(x)))f(g(h(x))).

Let f(x)=x2f(x) = x^2, g(x)=x+1g(x) = x + 1, and h(x)=2xh(x) = 2x. Find (fgh)(3)(f \circ g \circ h)(3).

Step 1: h(3)=6h(3) = 6

Step 2: g(6)=7g(6) = 7

Step 3: f(7)=49f(7) = 49

So (fgh)(3)=49(f \circ g \circ h)(3) = 49.

The algebraic formula:

h(x)=2xh(x) = 2x

g(h(x))=2x+1g(h(x)) = 2x + 1

f(g(h(x)))=(2x+1)2=4x2+4x+1f(g(h(x))) = (2x + 1)^2 = 4x^2 + 4x + 1


Composition is associative: (fg)h=f(gh)(f \circ g) \circ h = f \circ (g \circ h). Grouping does not affect the result, though order still matters.

Composition with Itself

A function can be composed with itself. The notation fff \circ f means applying ff twice in succession, and (ff)(x)=f(f(x))(f \circ f)(x) = f(f(x)).

Let f(x)=2xf(x) = 2x. Then:

f(f(x))=f(2x)=2(2x)=4xf(f(x)) = f(2x) = 2(2x) = 4x


Applying ff twice multiplies by 44. Applying three times gives f(f(f(x)))=8xf(f(f(x))) = 8x. Each application doubles the input.

Let f(x)=x2f(x) = x^2. Then:

f(f(x))=f(x2)=(x2)2=x4f(f(x)) = f(x^2) = (x^2)^2 = x^4


Squaring twice yields the fourth power.

The notation f2f^2 sometimes denotes fff \circ f, meaning ff composed with itself — not ff squared as a multiplication. Context determines the meaning. When clarity is needed, write fff \circ f or f(f(x))f(f(x)) explicitly.

Iterated composition leads to sequences and dynamical systems. Starting with x0x_0, define x1=f(x0)x_1 = f(x_0), x2=f(x1)=f(f(x0))x_2 = f(x_1) = f(f(x_0)), and so on. The behavior of these iterates reveals long-term dynamics of the function.

Decomposing Functions

Decomposition reverses composition: given a function hh, express it as h=fgh = f \circ g for simpler functions ff and gg.

Consider h(x)=x2+1h(x) = \sqrt{x^2 + 1}. This function squares the input, adds one, then takes the square root. Identify the inner and outer operations:

Inner function: g(x)=x2+1g(x) = x^2 + 1

Outer function: f(x)=xf(x) = \sqrt{x}

Check: f(g(x))=f(x2+1)=x2+1=h(x)f(g(x)) = f(x^2 + 1) = \sqrt{x^2 + 1} = h(x). ✓

Consider h(x)=(3x7)5h(x) = (3x - 7)^5. The structure is: form 3x73x - 7, then raise to the fifth power.

Inner function: g(x)=3x7g(x) = 3x - 7

Outer function: f(x)=x5f(x) = x^5

Check: f(g(x))=(3x7)5=h(x)f(g(x)) = (3x - 7)^5 = h(x). ✓

Decomposition is not unique. The function h(x)=(x+1)2h(x) = (x + 1)^2 can be written as fgf \circ g with f(x)=x2f(x) = x^2 and g(x)=x+1g(x) = x + 1, or as fgf \circ g with f(x)=(x+1)2f(x) = (x + 1)^2 and g(x)=xg(x) = x (trivial decomposition). Choose the decomposition that serves the purpose — simplifying analysis, enabling substitution in calculus, or revealing structure.

Composition and Inverse Functions

Composition provides the defining property of inverse functions. If f1f^{-1} is the inverse of ff, then:

(ff1)(x)=f(f1(x))=x(f \circ f^{-1})(x) = f(f^{-1}(x)) = x


(f1f)(x)=f1(f(x))=x(f^{-1} \circ f)(x) = f^{-1}(f(x)) = x


Each composition yields the identity function — the function that returns its input unchanged.

Let f(x)=2x+3f(x) = 2x + 3 and f1(x)=x32f^{-1}(x) = \dfrac{x - 3}{2}. Verify:

f(f1(x))=f(x32)=2x32+3=(x3)+3=xf(f^{-1}(x)) = f\left(\frac{x - 3}{2}\right) = 2 \cdot \frac{x - 3}{2} + 3 = (x - 3) + 3 = x \checkmark


f1(f(x))=f1(2x+3)=(2x+3)32=2x2=xf^{-1}(f(x)) = f^{-1}(2x + 3) = \frac{(2x + 3) - 3}{2} = \frac{2x}{2} = x \checkmark


This verification method confirms that two functions are inverses. If either composition fails to produce xx, the functions are not inverses.

The identity function I(x)=xI(x) = x is the compositional equivalent of the number 11 in multiplication: fI=If=ff \circ I = I \circ f = f for any function ff. Inverses compose to produce this neutral element.

Graphical Composition

Composing functions graphically requires reading values from two graphs in sequence.

To find (fg)(a)(f \circ g)(a) from graphs of ff and gg:

Step 1: On the graph of gg, locate x=ax = a on the horizontal axis. Read the corresponding yy-value; this is g(a)g(a).

Step 2: On the graph of ff, locate x=g(a)x = g(a) on the horizontal axis. Read the corresponding yy-value; this is f(g(a))=(fg)(a)f(g(a)) = (f \circ g)(a).

The output of gg becomes the input for ff. Each composition evaluation requires two graph readings.

Building the entire graph of fgf \circ g from graphs of ff and gg is labor-intensive. For each xx-value, perform the two-step reading. The result is a new curve whose shape depends on both component functions.

Graphical composition is most useful for specific point evaluations or for understanding conceptually how the functions interact. For detailed graphing, algebraic methods are more efficient.

Applications of Composition

Composition models processes that occur in stages, where the output of one stage feeds into the next.

Unit conversions often chain. To convert Celsius to Kelvin, add 273.15273.15. To convert Kelvin to Rankine, multiply by 1.81.8. The composition converts Celsius directly to Rankine:

R(C)=1.8(C+273.15)=1.8C+491.67R(C) = 1.8(C + 273.15) = 1.8C + 491.67


Pricing calculations chain. A 20%20\% discount applies first: g(p)=0.8pg(p) = 0.8p. Then 8%8\% tax applies: f(x)=1.08xf(x) = 1.08x. The final price:

f(g(p))=1.08(0.8p)=0.864pf(g(p)) = 1.08(0.8p) = 0.864p


The order matters: tax on the discounted price differs from discount on the taxed price.

Growth models chain. If population depends on resources, and resources depend on time, then population depends on time through composition.

In each case, composition captures the sequential nature of the process. The intermediate quantity — Kelvin, discounted price, resource level — may never be explicitly calculated, but it mediates the relationship between initial input and final output.