This function composition calculator computes both (f ∘ g)(x) = f(g(x)) and (g ∘ f)(x) = g(f(x)) for two polynomials up to degree 2 — expanded, simplified, and evaluated at a point of your choice. The two orders are computed side by side because composition’s first lesson is that they almost never agree: order is not a detail, it’s the operation.
f(x) = a₂x² + a₁x + a₀
g(x) = b₂x² + b₁x + b₀
| (f ∘ g)(x) = f(g(x)) | – |
| (g ∘ f)(x) = g(f(x)) | – |
| Evaluations | – |
Read (f ∘ g)(x) right to left: g acts first, f second. The evaluation line verifies composition numerically the safe way — inside out: g(x₀), then f of the result.
Inside Out: What Composition Actually Does
Composition chains functions the way machines chain on a line: (f ∘ g)(x) means g processes x first, and f processes g’s output. Substituting g’s entire expression into every x of f — then expanding honestly — is the whole algorithm, and it’s what this calculator’s polynomial engine does (powers of g built by multiplication, scaled, summed). The default pair shows the textbook-beautiful case: f(x) = x² + 2x + 1 is secretly (x + 1)², and g(x) = 3x − 2, so f(g(x)) = (3x − 2 + 1)² = (3x − 1)² = 9x² − 6x + 1, while g(f(x)) = 3(x + 1)² − 2 = 3x² + 6x + 1 — different functions, different values (at x = 2: 25 vs 25 — equal there by coincidence of this pair’s numbers, which is why the evaluation readout compares several things rather than declaring a winner). Composition is associative ((f∘g)∘h = f∘(g∘h)) but not commutative — the algebra of real processes: socks-then-shoes ≠ shoes-then-socks, and undoing a chain (inverse functions) must reverse the order, the fact our Inverse Function sibling page is built around.
Domains carry a two-step gate: x must be in g’s domain AND g(x) must be in f’s domain — for polynomials both gates are always open (all reals), but the moment square roots or denominators enter (see Domain and Range Calculator), (f ∘ g)’s domain can shrink dramatically from either side. Composition also underlies the chain rule in calculus — d/dx f(g(x)) = f′(g(x))·g′(x) — arguably the most-used derivative rule in existence, and the reason fluency here pays interest for years.
Worked Examples (Verified)
- Defaults: f = (x + 1)², g = 3x − 2 → f(g(x)) = 9x² − 6x + 1; g(f(x)) = 3x² + 6x + 1. At x = 0: f(g(0)) = f(−2) = 1 ✔ (constant term of the expansion); g(f(0)) = g(1) = 1 ✔ — both expansions agree with inside-out evaluation, the calculator prints the check at your chosen x.
- Quadratic into quadratic: f = x², g = x² + 1 → f(g(x)) = (x² + 1)² = x⁴ + 2x² + 1 and g(f(x)) = x⁴ + 1 — same degree-4 family, different middles; the widget’s compose engine handles degree 4 results natively.
- The undoing pair: f = 2x + 3 and g = (x − 3)/2 give f(g(x)) = x and g(f(x)) = x — compositions that collapse to the identity are inverse functions announcing themselves; try it with b₁ = 1/2, b₀ = −3/2.
Composition Discipline
- Notation reads right-to-left: (f ∘ g) applies g first. The commonest composition error is executing in reading order; the evaluation readout (g(x₀) first) is the antidote made visible.
- Substitute into EVERY x of the outer function — including the constant-adjacent ones students miss when f has multiple terms — then expand fully; “f(g(x)) = f’s formula with g pasted once” is the classic half-substitution.
- Simplify (x + 1)²-style factorizations when you spot them: recognizing f as a perfect square turned our example’s expansion into a one-liner; the calculator expands blind, you may expand clever.
- Domain check precedes algebra whenever functions carry roots or denominators: composition’s domain is {x ∈ dom g : g(x) ∈ dom f}, not a union or an afterthought.
- Decomposition is the reverse skill (recognizing that √(x² + 1) is f∘g with g = x² + 1, f = √) — the chain rule’s setup step; practice reading this page’s outputs backwards.
Related Tools
- Domain and Range Calculator — composition’s domain gate
- Vertex Calculator — the quadratics being composed
- Math Calculators — the full collection
Frequently Asked Questions
How do you compute f(g(x))?
Substitute the entire expression g(x) for every x in f, then expand and simplify. With f(x) = x² + 2x + 1 and g(x) = 3x − 2: f(g) = (3x − 2)² + 2(3x − 2) + 1 = 9x² − 12x + 4 + 6x − 4 + 1 = 9x² − 6x + 1 (equivalently (3x − 1)², since f is (x + 1)²). This calculator performs the substitution with a polynomial engine and shows the reverse composition plus a numeric inside-out evaluation check.
Is f(g(x)) the same as g(f(x))?
Almost never. Composition is not commutative: defaults here give 9x² − 6x + 1 one way and 3x² + 6x + 1 the other. The exceptions are special pairs — inverse functions (both compositions = x), a function composed with itself in trivial cases, or linear pairs engineered to commute (affine maps ax + b commute only under a coefficient condition). Treat “the two orders differ” as the default truth and any agreement as a discovery.
What does (f ∘ g)(x) mean?
“f composed with g” — f of g of x. The circle is read right to left: the function nearest x acts first. (f ∘ g)(2) for our defaults: g(2) = 4, then f(4) = 25. Function machines in series, output of one feeding the next — the same structure as unit conversions chained (inches → cm → m) and as nested function calls in programming.
What is the domain of a composition?
{x : x is in the domain of g, and g(x) is in the domain of f}. Both conditions, in order: a value g never reaches can’t be f-composed, and a value g produces that f can’t accept breaks the chain. For polynomial f and g (this calculator) the domain is all reals; with roots or fractions in either function, compute the restriction explicitly — our Domain and Range page treats the underlying families.
How does composition relate to inverse functions?
Inverses are compositions that collapse: f and g are inverses iff f(g(x)) = x AND g(f(x)) = x (on the appropriate domains). The order-reversal rule for undoing chains ((f∘g)⁻¹ = g⁻¹∘f⁻¹ — shoes and socks) follows immediately. Testing a candidate inverse is a composition exercise — exactly the third worked example here (2x + 3 with (x − 3)/2) — and our Inverse Function Calculator handles the solving side.
Why does the chain rule need composition?
Because most real functions are compositions in disguise: sin(x²), e^(3x), √(x + 1). The chain rule differentiates them by multiplying the outer derivative (evaluated at the inner) by the inner derivative — a formula that’s just the linear approximation of “rates multiply through a chain.” Recognizing the decomposition (the reverse of this page’s skill) is the setup every chain-rule problem begins with; fluency in composing is what makes decomposing fast.
Can you compose a function with itself?
Yes — iteration: f(f(x)), written f²(x) in dynamical-systems contexts (not to be confused with (f(x))²). Iterating quadratics is famously deep: f(x) = x² − 2’s iterates connect to Chebyshev polynomials and chaos theory; even x² + c iteration draws the Mandelbrot set’s boundary. The calculator composes any pair including f with f — set both coefficient rows equal and meet iteration.
Is this function composition calculator free?
Yes — free, instant, no sign-up. Enter two quadratics (or linears/constants) for both compositions, expanded, plus an inside-out numerical evaluation at your x.