🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Composition of Functions

Relations and FunctionsComposition of FunctionsđŸŸĸ Free Lesson

Composition of Functions

Reading a composition as two legs of one journey

If f sends a to b and g sends b to c, then the composition g ∘ f sends a straight to c, and the intermediate value b never appears in the final answer. Read the double arrow from right to left: the right-hand function f runs first, the left-hand function g runs second and sees only the output that f produced. This right-to-left convention is the single most common source of lost marks in board answers. A student who writes (f ∘ g)(x) when the question asked for (g ∘ f)(x) reaches a completely different algebraic expression, and every line after that is internally consistent yet worth nothing. Build the habit of boxing the inner function first, then substituting into the outer one.

CompositionFirst legSecond legValue at 3
(g ∘ f)(3) with f(x) = 2x + 1, g(x) = x squaredf(3) = 7g(7) = 4949
(f ∘ g)(3) with the same pairg(3) = 9f(9) = 1919

Two compositions built from the same pair of functions give different numbers at the same input, and the gap grows as the input moves away from the origin. Neither result is an accident: they describe two different machines wired in two different directions.

Domain and range: when the composition exists at all

For (g ∘ f)(x) to make sense you need two things simultaneously: x must belong to the domain of f, and the value f(x) must belong to the domain of g. In set language, the range of f has to sit inside the domain of g. When that containment fails, the composition survives only on the part of the domain of f whose outputs still land inside g. Take f(x) = square root of x with domain x â‰Ĩ 0 and g(x) = ln x with domain x greater than 0. Then (g ∘ f)(x) is the logarithm of a square root, and it is defined for every x greater than 0, while at x = 0 the output 0 is rejected by the logarithm. The reverse composition f ∘ g is much narrower: it is the square root of ln x, which needs ln x â‰Ĩ 0 and therefore needs x â‰Ĩ 1. Notice that a composition can be perfectly well defined in one order and nearly empty in the other. Always state the surviving domain in the final answer, because it carries marks on its own.

Why order matters while brackets do not

Composition is associative but never commutative. Associativity means h ∘ (g ∘ f) and (h ∘ g) ∘ f are the same function, so brackets may be rearranged freely once every intermediate composition is defined; that is why a three-layer composition can be evaluated left to right without ambiguity. Commutativity, however, fails for every pair of non-trivial functions. With f(x) = x + 2 and g(x) = 3x the two orders give (g ∘ f)(x) = 3x + 6 and (f ∘ g)(x) = 3x + 2, which differ by the constant 4 and therefore never agree. More generally, for an affine shift f(x) = x + a and a scaling g(x) = bx you obtain (g ∘ f)(x) = bx + ba and (f ∘ g)(x) = bx + a, which coincide only when a is zero or b is one. In every other case the two orders separate, so never assume they match without checking.

Composing a function with itself

The composition of f with itself is written (f ∘ f)(x), and it is not the same object as the pointwise square of f. Board questions usually spell the composition out in full precisely to avoid that clash of notation. For f(x) = 2x + 3, one pass gives 2(2x + 3) + 3 = 4x + 9, a second pass gives 2(4x + 9) + 3 = 8x + 21, and the pattern generalises to fâŋ(x) = 2âŋ times x plus 3 times (2âŋ − 1). That closed form is a geometric sum, and it is the reason iteration problems in this chapter collapse into a single line instead of a long chain. Check the formula at n = 0: it returns x plus zero, which is the identity, exactly as it should.

Recovering the hidden function from a composition

Example 3 reverses the machine: you are handed (f ∘ g)(x) together with one of the two functions and asked for the other. Treat g(x) as a single unknown, say u, and solve the resulting equation for u in terms of x. With f(u) = 2u + 3 and f(u) known to equal 4x² + 12x + 12, you get 2u = 4x² + 12x + 9, so u = 2x² + 6x + 4.5, which is exactly g(x). The one extra step worth performing every time is a domain statement. When both functions are polynomials nothing restricts the answer, but when f involves a square root or a logarithm the recovered expression may have a domain smaller than the one the question intended, and writing that restriction down separates a complete answer from a partial one.

When a composition can be undone

A function g is called a left inverse of f when g ∘ f equals the identity on the domain of f, and a right inverse of f when f ∘ g equals the identity on the domain of g. Every injective function has at least one left inverse, because you may assign a value to g at each output that f never reaches. Every surjective function has at least one right inverse, because you may choose one preimage for each output. A two-sided inverse exists exactly when f is bijective, and then it is unique. The practical consequence for exam questions is simple: if you are told that g undoes f, verify both compositions. Checking a single direction proves only injectivity or only surjectivity, and the question almost always asks for the stronger statement.

Modelling compositions in Python

A composition is nothing more than function application nested inside function application, so a few lambdas reproduce every algebraic step above and let you spot a wrong order in seconds.

python
from sympy import symbols, expand

x = symbols('x')
f = lambda t: 2 * t + 1
g = lambda t: t**2

print(expand(g(f(x))))            # 4*x**2 + 4*x + 1
print(expand(f(g(x))))            # 2*x**2 + 1
print(expand(g(f(x)) - f(g(x))))  # 2*x**2 + 4*x: equal only at x = 0 and x = -2
python
from sympy import symbols, expand, simplify

x = symbols('x')
f = lambda t: 2 * t + 1
g = lambda t: t**2
h = lambda t: t + 1

def compose(*funcs):
    """Rightmost function runs first, matching a composed with b composed with c."""
    def inner(t):
        for fn in reversed(funcs):
            t = fn(t)
        return t
    return inner

print(expand(compose(h, g, f)(x)))   # 4*x**2 + 4*x + 2
print(expand(compose(f, g, h)(x)))   # 2*x**2 + 4*x + 3

p = lambda t: (2 * t + 3) / (t - 1)
q = lambda t: (t + 3) / (t - 2)
print(simplify(p(q(x))))             # x
print(simplify(q(p(x))))             # x

The second script settles two questions at once: it confirms that rebracketing a three-layer composition changes nothing, and it confirms that p and q really are two-sided inverses of each other by checking both directions.

Common Mistakes

Evaluating the left-hand function first because it is written first.

Fix: Work right to left: the function nearest the input is applied first, so treat (f ∘ g)(x) as f applied to the whole of g(x).

Stopping after verifying a single composition when proving two functions are inverses.

Fix: Check both g(f(x)) = x and f(g(x)) = x, because each direction establishes a different property and only both together give a two-sided inverse.

Quoting the domain of the outer function as the domain of the composition.

Fix: Intersect the domain of the inner function with the set of inputs whose outputs the outer function accepts, and state that final set in the answer.

Key Takeaways

  • Composition runs right to left: in (g ∘ f)(x) the function f is applied first and g only ever sees f's output.
  • The composition exists only where the range of the inner function sits inside the domain of the outer function, and that surviving set must be stated.
  • Composition is associative, so brackets can be rearranged, but it is never commutative: swapping the order changes the function.
  • Two functions are inverses of each other only when both compositions equal the identity, which happens exactly for bijections.
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-15

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert CBSE Class 12 Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement