Precalculus

Function Composition Calculator

Enter two functions f(x) and g(x) to get the composed function (f ∘ g)(x) = f(g(x)) in simplified form. You can also fill in a numeric value of a to get the composed value (f ∘ g)(a) alongside.

Function Composition Calculator

Compute (f ∘ g)(x) symbolically, plus an optional value at x = a.

Try:
Answer(f ∘ g)(x) = (2·x + 3)² + 1
  1. f(x)x² + 1
  2. g(x)2·x + 3
  3. Composition(f ∘ g)(x) = f(g(x)) = (2·x + 3)² + 1

The composed expression, not just a value

Composing two functions means feeding the output of one into the other. Written (f ∘ g)(x), it stands for f(g(x)): apply g first, then f to whatever g produced. The notation reads right to left, which is the first thing about composition that catches people out.

This calculator builds the composed function symbolically, returning (f ∘ g)(x) as a simplified expression. Supply a numeric value as well and it evaluates the composition there, showing the inner value along the way.

Composition is easy to describe and tedious to carry out. Substituting a whole expression for x inside another means every occurrence has to be replaced, brackets respected, and the result usually expanded before it is recognisable.

The tool substitutes structurally and simplifies afterwards, so the answer is a function you can differentiate, solve or compose again — not a number that closes off the next step.

How to use this calculator

  1. Enter f(x), the outer function Applied second, despite being written first. Any expression in x with the usual operators and named functions; implicit multiplication such as 2x is understood.
  2. Enter g(x), the inner function Applied first. Its entire expression is substituted for every x in f, so its own structure carries through into the result.
  3. Optionally enter a value for a Leave it blank for the symbolic composition alone. Fill it in and the tool also reports g(a) and then (f ∘ g)(a), so the two-stage evaluation is visible.
  4. Read the composition, then the values The composed expression comes first, already simplified. Numeric lines, when present, follow and can be checked against it.

How the composition is built

Both functions are parsed into expression trees and simplified before being combined, which is why the echoed f(x) and g(x) lines may look tidier than what you typed. Composition is then substitution: the tree for g replaces every occurrence of the variable inside the tree for f.

Because the substitution is structural rather than textual, brackets never have to be inserted or guessed at. Replacing x with 2x + 3 inside x² produces (2x + 3)² correctly, where a naive text replacement would give 2x + 3² — the error that makes composition worth automating.

The composed tree is then run through the same simplifier the symbolic derivative tool uses, so constants collapse and like terms combine. The result is simplified rather than fully expanded, which is why a squared bracket may be left as a bracket.

When a numeric value is supplied, two lines are reported: g at that point, giving the inner value, and the already-composed expression at the same point, giving the final answer. Seeing both makes the order of application concrete.

What each input means

f Outer function — form field “f(x)”
The function applied second. Its variable is the one that gets replaced, so its structure determines the shape of the result.
g Inner function — form field “g(x)”
The function applied first. Its whole expression is substituted, so it appears inside the composition wherever f had an x.
a Evaluation point — form field “Optional x value (for (f ∘ g)(a))”
Optional. A finite number at which to evaluate the composition. Left blank, only the symbolic result is produced.

Worked examples

Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.

Substituting an expression into a square

Take f(x) = x² and g(x) = x + 1, with no evaluation point. This is the smallest example where the bracket matters.

Inputs f(x) = x^2, g(x) = x + 1, Optional x value (for (f ∘ g)(a)) =

  1. f(x) x²
  2. g(x) x + 1
  3. Composition (f ∘ g)(x) = f(g(x)) = (x + 1)²

Result (f ∘ g)(x) = (x + 1)²

The result is the whole of g squared, not g with a squared term inside it. That distinction is the entire content of the exercise: the substitution replaces x with the complete inner expression, brackets included.

Reversing the two would give x² + 1, a different function entirely. Composition is not commutative, and this pair is the standard demonstration of it.

Composition evaluated at a point

Take f(x) = 2x + 1 and g(x) = x², evaluated at 3. Both the symbolic result and the two-stage numeric evaluation are reported.

Inputs f(x) = 2x + 1, g(x) = x^2, Optional x value (for (f ∘ g)(a)) = 3

  1. f(x) 2·x + 1
  2. g(x) x²
  3. Composition (f ∘ g)(x) = f(g(x)) = 2·x² + 1
  4. g(a) g(3) = 9
  5. (f ∘ g)(a) f(g(3)) = f(9) = 19

Result (f ∘ g)(x) = 2·x² + 1; (f ∘ g)(3) = 19

The inner value line shows g(3) = 9 before the final answer. Reading it makes clear that the square is taken first and the doubling second, which is the opposite of the order the notation is written in.

The final value can be checked against the composed expression by substituting 3 into it directly. The two routes agree because the tool evaluates the composition itself rather than chaining two separate evaluations.

A composition that inherits a domain restriction

Take f(x) = 1/x and g(x) = x + 1, evaluated at 2. The outer function has a restriction that the composition inherits at a shifted position.

Inputs f(x) = 1/x, g(x) = x + 1, Optional x value (for (f ∘ g)(a)) = 2

  1. f(x) 1/x
  2. g(x) x + 1
  3. Composition (f ∘ g)(x) = f(g(x)) = 1/(x + 1)
  4. g(a) g(2) = 3
  5. (f ∘ g)(a) f(g(2)) = f(3) = 0.333333

Result (f ∘ g)(x) = 1/(x + 1); (f ∘ g)(2) = 0.333333

The composed function is undefined where the inner function returns zero — at x = −1 rather than at x = 0. The restriction has moved with the substitution, which is the most common way a composition surprises you.

Nothing in the output flags that restriction: the tool reports the expression, not its domain. Analysing the result in the domain and range calculator is the way to recover it.

Reading the result

Order matters, always

(f ∘ g) and (g ∘ f) are different functions except in special cases. The notation puts the outer function first even though it acts last, so reading it left to right gives the wrong order of operations.

Simplified, not expanded

The simplifier collapses constants and combines like terms but does not multiply out every bracket. A result left as a squared bracket is complete; expanding it is presentational rather than a further step.

The domain of the composition

It is not simply the domain of f or of g. A point is admissible only when g accepts it and f accepts what g returns, which can exclude points neither excludes alone.

When you would use this

Setting up a chain-rule problem

Differentiating a composite function requires identifying outer and inner parts. Building the composition explicitly makes those roles unambiguous before the chain rule is applied.

Checking whether two functions are inverses

Two functions are inverses exactly when both compositions return x. Composing in each order is the definitional test, and it catches a near-inverse that works in only one direction.

Assumptions and limitations

What this calculator assumes

  • Both functions are written in x, and the variable in f is the one substituted into.
  • The composition is (f ∘ g)(x) = f(g(x)); the reverse order requires swapping the two fields.
  • The evaluation point, when supplied, must be a finite number.
  • The result is simplified by the same rules as the symbolic derivative tool, not fully expanded.

Where it stops being the right tool

  • Two functions at a time: a triple composition must be built in stages, feeding the first result back in.
  • No domain analysis: restrictions inherited from either function are not reported alongside the composition.
  • The composition is not expanded into a standard polynomial form, so the result may need multiplying out by hand.

Common mistakes

Composing in the wrong order

Why it happens. (f ∘ g) is written with f first, so it reads as though f is applied first. It is applied second, and for most pairs the two orders give completely different functions.

How to avoid it. Read the circle as “after”: f after g. If your answer matches what the tool gives with the fields swapped, the order was the only problem.

Substituting without brackets

Why it happens. Replacing x with x + 1 in x² by hand invites writing x + 1², where the power binds only to the 1. The structural substitution the tool performs cannot make that mistake.

How to avoid it. Bracket the entire inner expression before substituting. Comparing your working against the composition line shows immediately whether a bracket was lost.

Assuming the domain is unchanged

Why it happens. The composed expression may look unrestricted even when it is not, because the inner function has moved the problem point somewhere non-obvious.

How to avoid it. Analyse the composed result separately for domain restrictions, and check that every value g produces is one f accepts.

Frequently asked questions

Is (f ∘ g) the same as (g ∘ f)?

Almost never. Composition is not commutative: f(g(x)) and g(f(x)) are generally different functions. With f(x) = x² and g(x) = x + 1 the two give (x + 1)² and x² + 1 respectively.

What syntax do the function fields accept?

Any expression in x built from the arithmetic operators, ^ for powers, and the standard named functions including sqrt, sin, cos, tan, exp and ln. Implicit multiplication such as 3x or 2sin(x) is understood.

Does it simplify the composition?

Yes, using the same simplifier as the symbolic derivative tool: constants collapse and like terms combine. It does not expand every bracket, so a result may be left in a compact form rather than as a polynomial.

Can I compose three functions?

Not in one pass. Compose two of them first, then paste that result into one of the fields and compose with the third. Each stage is simplified, so the intermediate expression stays manageable.