About the Function Composition Calculator
This function composition calculator substitutes one function into another. Enter f(x) and g(x) and it builds (f ∘ g)(x) = f(g(x)) and (g ∘ f)(x) = g(f(x)), shows the raw substitution, then expands and simplifies each result — for f(x) = x² + 1 and g(x) = 2x − 3 you get f(g(x)) = 4x² − 12x + 10 and g(f(x)) = 2x² − 1.
It also evaluates both composites at a chosen x, showing the inner value first (g(2) = 1, then f(1) = 2) so the order of operations is clear. That makes it useful for algebra and precalculus homework, for checking whether two functions are inverses (both compositions simplify to x), and for setting up chain-rule problems in calculus.
Polynomial results are fully expanded into standard form; expressions with fractions in x, roots, logs or trig functions are simplified as far as the algebra engine allows. Remember that composition is not commutative — f(g(x)) and g(f(x)) are usually different — and the domain of f ∘ g contains only the x values for which g(x) lies in the domain of f.
How to use the function composition calculator
- 1Type the outer function f(x) and the inner function g(x) using x as the variable.
- 2Enter an x value to evaluate the compositions at.
- 3Read f(g(x)) and g(f(x)), both before and after simplification.
- 4Follow the notes to see the inner value computed first, then the outer one.
Formula and method
To compose f with g, replace every x in f by the whole expression g(x) (in brackets), then simplify. The inner function is applied first: to evaluate f(g(a)), compute g(a) and feed the result into f. Swapping the order generally gives a different function, so f ∘ g ≠ g ∘ f except in special cases such as inverse functions, where both compositions equal x.
This calculator performs the substitution on the parsed expression tree, then expands polynomial results (up to degree 40) into standard form; other expressions, including rational functions, roots, logs and trig, are simplified algebraically. The domain of f ∘ g is the set of x in the domain of g for which g(x) is in the domain of f — check points where a square root, logarithm or denominator could fail.
- f ∘ g
- “f composed with g” — apply g first, then f
- x₀
- The point where the composites are evaluated
Worked examples
f(x) = x² + 1, g(x) = 2x − 3 at x = 2
f(g(x)) = (2x − 3)² + 1 = 4x² − 12x + 10 and g(f(x)) = 2(x² + 1) − 3 = 2x² − 1. At x = 2: g(2) = 1 so f(g(2)) = 2, while f(2) = 5 so g(f(2)) = 7.
Square root and a quadratic at x = 0
f(g(x)) = √(x² + 4), defined for every x; at 0 it is √4 = 2. g(f(x)) = (√x)² + 4 = x + 4 but only for x ≥ 0; at 0 it equals 4.
Checking inverse functions
f(g(x)) = 3·(x − 2)/3 + 2 = x and g(f(x)) = (3x + 2 − 2)/3 = x, so f and g undo each other: both composites return 5 at x = 5.
Trig composition at x = π/6
f(g(x)) = sin(2x), so at π/6 it is sin(π/3) ≈ 0.866025. g(f(x)) = 2 sin x, which is 2 × ½ = 1 — a clear example that order matters.
Frequently asked questions
What does f(g(x)) mean?+
It means apply g to x first, then apply f to the result. It is written (f ∘ g)(x) and read “f of g of x” or “f composed with g”. For example if g(x) = x + 1 and f(x) = x², then f(g(x)) = (x + 1)².
Is function composition commutative?+
No. In general f(g(x)) ≠ g(f(x)). With f(x) = x² and g(x) = x + 1, f(g(x)) = x² + 2x + 1 but g(f(x)) = x² + 1. They are equal only in special cases, such as when f and g are inverses.
How do you find the domain of a composite function?+
Start with the domain of the inner function g, then remove any x for which g(x) is not allowed in f. For f(x) = √x and g(x) = x − 4, f(g(x)) = √(x − 4) needs x − 4 ≥ 0, so the domain is x ≥ 4.
How can composition show two functions are inverses?+
If f(g(x)) = x and g(f(x)) = x for every x in the relevant domains, then f and g are inverse functions. Try f(x) = 3x + 2 and g(x) = (x − 2)/3 in this calculator: both compositions simplify to x.
How does composition relate to the chain rule?+
The chain rule differentiates a composite function: (f ∘ g)′(x) = f′(g(x)) · g′(x). Identifying the outer function f and inner function g, as this tool does, is the first step in applying it.