Function Composition Calculator
f(g(x)) · g(f(x)) · f(f(x)) · Step-by-Step · Domain · Graph
Compose two functions symbolically and numerically. See the substitution steps, domain restrictions, and a live graph of all three composed functions.
Quick Examples
Syntax: Use ^ for powers, * for multiply, sqrt(x), abs(x), log(x), ln(x), sin(x), cos(x), tan(x), exp(x)
Step-by-Step Substitution — (f∘g)(x)
Domain of Composite Functions
Graph
Graph range: x ∈ [−6, 6]. Values outside [−20, 20] are clipped for readability.
Notation & Properties Reference
f∘g notation
(f∘g)(x) = f(g(x))
Apply g first, then f. Read: "f composed with g" or "f of g of x".
g∘f notation
(g∘f)(x) = g(f(x))
Apply f first, then g. Order is reversed from f∘g.
Commutativity
f∘g ≠ g∘f (generally)
Composition is NOT commutative. Order matters.
Associativity
(f∘g)∘h = f∘(g∘h)
Composition IS associative. Grouping doesn't change the result.
Inverse & Identity
(f∘f⁻¹)(x) = x
Composing a function with its inverse gives the identity function.
Domain Rule
Dom(f∘g) = {x ∈ Dom(g) : g(x) ∈ Dom(f)}
x must be valid in g AND g(x) must be valid in f.
What Is Function Composition?
Function composition is a fundamental operation in mathematics where you apply one function to the output of another. Given two functions f and g, the composition (f∘g)(x) — read "f composed with g of x" — is defined as f(g(x)). You first evaluate g at x, then feed that result into f as the new input.
For example, if f(x) = 2x + 1 and g(x) = x², then (f∘g)(x) = f(g(x)) = f(x²) = 2x² + 1. The inner function g transforms x first, and the outer function f transforms the result.
Order Matters: f∘g vs. g∘f
One of the most important properties of function composition is that it is not commutative. Swapping the order generally produces a different function:
- (f∘g)(x) = f(g(x)): apply g first, then f
- (g∘f)(x) = g(f(x)): apply f first, then g
Using the same example: (g∘f)(x) = g(f(x)) = g(2x+1) = (2x+1)² = 4x²+4x+1, which is clearly different from 2x²+1. Always be careful about which function goes inside (is applied first) and which is outside.
Domain of a Composite Function
When composing functions, domain restrictions can emerge that don't appear in either individual function. The domain of (f∘g) is the set of all x values satisfying two conditions simultaneously:
- x must be in the domain of g (g(x) must be defined)
- g(x) must be in the domain of f (f(g(x)) must be defined)
Example: f(x) = √x requires x ≥ 0, and g(x) = x − 3 has all reals as its domain. For (f∘g)(x) = √(x−3), we need x − 3 ≥ 0, so x ≥ 3. The composition introduces a restriction not present in g alone.
Associativity and Self-Composition
While composition is not commutative, it is associative: (f∘g)∘h = f∘(g∘h). This means when composing three or more functions, the grouping does not matter — only the order.
Self-composition f∘f (also written f²) applies f twice: f(f(x)). This is useful for iterative processes, fractals (such as the Mandelbrot set), and dynamical systems where repeated application of the same rule models evolution over time.
Inverse Functions and Composition
The inverse of a function f, denoted f⁻¹, is defined precisely by composition: (f∘f⁻¹)(x) = x and (f⁻¹∘f)(x) = x. Applying a function and then its inverse "undoes" the transformation and returns the original value. This is why inverse functions are so central in algebra — they allow you to "reverse" any one-to-one function.
Composition and the Chain Rule in Calculus
In calculus, the chain rule is the differentiation rule for composite functions. If h(x) = f(g(x)), then:
h'(x) = f'(g(x)) · g'(x)
The derivative of the composition is the derivative of the outer function (evaluated at the inner function) multiplied by the derivative of the inner function. This is one of the most frequently used rules in differential calculus.
Function Composition in Programming
Function composition has a direct counterpart in computer science called function piping or function chaining. In functional programming languages like Haskell, Elm, or F#, the composition operator (often written as . or >>) allows combining functions into pipelines: h = f . g means applying g first, then f — identical to mathematical composition.
Real-world uses include data transformation pipelines (apply normalizer, then encoder, then classifier), graphics rendering (apply rotation, then scaling, then projection), and middleware chains in web servers.
Reference: Common Composed Functions
| f(x) | g(x) | (f∘g)(x) | (g∘f)(x) |
|---|---|---|---|
| 2x+3 | x² | 2x²+3 | (2x+3)² = 4x²+12x+9 |
| √x | x+1 | √(x+1) | √x+1 |
| 1/x | x−3 | 1/(x−3) | 1/x−3 |
| x² | 2x−1 | (2x−1)²=4x²−4x+1 | 2x²−1 |
| ln(x) | exp(x) | ln(eˣ) = x | e^(ln x) = x |