Function Composition Calculator — f(g(x)) and g(f(x))
Compose two polynomial functions: get f(g(x)) and g(f(x)) expanded and simplified, their degree, and the value of each composition at any x with the inner value shown.
How it works
(f ∘ g)(x) = f(g(x)): replace every x in f with the whole expression g(x), then expand and collect like terms · (g ∘ f)(x) = g(f(x)) · deg f(g(x)) = deg f × deg g
Composition feeds the output of one function into another: in f(g(x)) the inner function g acts first and f acts on its result. The calculator substitutes g(x) into f symbolically using exact fractions, expands the powers and collects like terms, and does the same the other way round. Composition is usually not commutative, so f(g(x)) and g(f(x)) are generally different polynomials. The value at a chosen x is found by evaluating the inner function first, which is how textbooks (OpenStax Precalculus §1.4) teach it.
Worked example
f(x) = x² + 1 and g(x) = 2x − 3. f(g(x)) = (2x − 3)² + 1 = 4x² − 12x + 9 + 1 = 4x² − 12x + 10. g(f(x)) = 2(x² + 1) − 3 = 2x² − 1. At x = 2: g(2) = 1, so f(g(2)) = f(1) = 2; f(2) = 5, so g(f(2)) = g(5) = 7. The two compositions differ, so the order matters.
Sources: OpenStax Precalculus 2e — 1.4 Composition of Functions · Khan Academy — Composite functions
Frequently asked questions
How do you find f(g(x))?
Write f(x), and wherever x appears put (g(x)) in parentheses. Then expand and simplify. For f(x) = x² + 1 and g(x) = 2x − 3, f(g(x)) = (2x − 3)² + 1 = 4x² − 12x + 10.
Is f(g(x)) the same as g(f(x))?
Usually not. Composition is not commutative; the example above gives 4x² − 12x + 10 one way and 2x² − 1 the other. They agree only for special pairs, such as a function and its inverse.
Is f(g(x)) the same as f(x) · g(x)?
No. f(x)·g(x) multiplies the two outputs, while f(g(x)) plugs one function into the other. The notation (f ∘ g)(x) with a small circle means composition.
What is the degree of a composition?
For polynomials, deg f(g(x)) = deg f × deg g. A quadratic composed with a cubic gives a degree-6 polynomial.
How do I evaluate f(g(2)) without the formula?
Work from the inside out: compute g(2) first, then put that number into f. The calculator shows both steps.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.