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

(optional — leave blank to skip)

Syntax: Use ^ for powers, * for multiply, sqrt(x), abs(x), log(x), ln(x), sin(x), cos(x), tan(x), exp(x)

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+32x²+3(2x+3)² = 4x²+12x+9
√xx+1√(x+1)√x+1
1/xx−31/(x−3)1/x−3
2x−1(2x−1)²=4x²−4x+12x²−1
ln(x)exp(x)ln(eˣ) = xe^(ln x) = x

Frequently Asked Questions

What is function composition?
Function composition is the process of applying one function to the result of another. Written as (f∘g)(x) = f(g(x)), it means you first evaluate g at x, then feed that result into f. The order matters: f∘g and g∘f are generally different functions.
What does f∘g mean and how is it different from g∘f?
f∘g (read "f composed with g") means (f∘g)(x) = f(g(x)) — apply g first, then f. g∘f means (g∘f)(x) = g(f(x)) — apply f first, then g. These are generally not equal, so function composition is not commutative. For example, if f(x)=2x+1 and g(x)=x², then (f∘g)(x)=2x²+1 but (g∘f)(x)=(2x+1)²=4x²+4x+1.
How do you find the domain of a composite function f∘g?
The domain of (f∘g)(x) = f(g(x)) consists of all x values that are (1) in the domain of g, AND (2) whose image g(x) is in the domain of f. In set notation: Dom(f∘g) = { x ∈ Dom(g) : g(x) ∈ Dom(f) }. For example, if g(x)=x-3 and f(x)=√x, then g(x) must be ≥ 0, so x-3 ≥ 0, meaning x ≥ 3.
Is function composition associative?
Yes, function composition is associative: (f∘g)∘h = f∘(g∘h). This means when composing three or more functions, the grouping of parentheses does not change the result. However, as noted, it is NOT commutative — changing the order of composition generally changes the result.
What is the relationship between composition and inverse functions?
If f⁻¹ is the inverse of f, then composing them in either order gives the identity function: (f∘f⁻¹)(x) = x and (f⁻¹∘f)(x) = x. This is actually the defining property of an inverse function. It means that applying a function and then its inverse (or vice versa) undoes the transformation.
How is function composition related to the chain rule in calculus?
The chain rule in calculus is the differentiation rule for composite functions. If h(x) = f(g(x)), then h'(x) = f'(g(x)) · g'(x). In other words, the derivative of a 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 important differentiation rules in calculus.
What function notation is supported in this calculator?
This calculator supports polynomials (e.g., 2x^2+3x-1), sqrt(x) for square roots, abs(x) for absolute value, 1/x for reciprocals, log(x) for base-10 logarithm, ln(x) for natural logarithm, sin(x), cos(x), tan(x) for trigonometric functions, and exp(x) for the exponential function e^x. Use ^ for exponentiation and standard arithmetic operators + − * /.