Function Composition Calculator

Use this Function Composition Calculator to enter values, adjust options, and review results in a compact responsive workspace.

Results are calculated automatically as you enter data.

Evaluate at an input value

Use x, numbers, + - * / ^, parentheses, sqrt(), log(), exp(), abs(), sin(), cos(), and tan(). Each function is limited to 240 characters.

Substitution steps
Composition Define functions.

▼ See explanations and tips below ▼

What Is Function Composition?

Function composition is the process of using the output of one function as the input of another function. Instead of applying two functions separately, composition connects them into one ordered chain.

If \(g\) is applied first and \(f\) is applied second, the composite function is written as:

$$ (f \circ g)(x) = f(g(x)) $$

This is read as “\(f\) composed with \(g\)” or “\(f\) of \(g\) of \(x\).” The expression inside the parentheses, \(g(x)\), is evaluated first. Its output then becomes the input for \(f\).

That inside-to-outside order is the central idea. In \(f(g(x))\), the function \(g\) does not come second just because it appears later in the notation. It is the inner function, so it acts first.

Function composition is useful whenever one quantity depends on another intermediate quantity. For example, the cost of heating a home may depend on temperature, and temperature may depend on the day of the year. A composite function lets you connect those relationships in one expression.


Why Function Composition Matters

Function composition helps turn multi-step relationships into clear mathematical models. It appears throughout algebra, precalculus, calculus, science, economics, computer science, and many applied fields.

Students often meet composition when learning function notation, inverse functions, transformations, and derivatives. Later, it becomes important for the chain rule in calculus, where a function inside another function must be handled carefully.

Composition also helps avoid a common algebra mistake: assuming that changing the order of operations gives the same result. In many cases, \(f(g(x))\) and \(g(f(x))\) are different functions and produce different values.


Key Terms to Know

  • Function: A rule that assigns each allowed input exactly one output.
  • Input: The value placed into a function, often represented by \(x\).
  • Output: The value returned by a function after the input is processed.
  • Composite function: A function made by applying one function to the output of another.
  • Inner function: The function evaluated first in a composition, such as \(g\) in \(f(g(x))\).
  • Outer function: The function evaluated after the inner function, such as \(f\) in \(f(g(x))\).
  • Domain: The set of input values for which a function is defined.
  • Range: The set of output values a function can produce.
  • Repeated composition: A composition that uses the same function more than once, such as \(f(f(x))\).
  • Noncommutative operation: An operation where changing the order can change the result. Function composition is generally noncommutative.

How Function Composition Works

To compose two functions, substitute the entire inner function wherever the input variable appears in the outer function.

For two functions \(f\) and \(g\):

$$ (f \circ g)(x) = f(g(x)) $$

The reverse order is:

$$ (g \circ f)(x) = g(f(x)) $$

These two expressions usually are not the same:

$$ f(g(x)) \ne g(f(x)) \quad \text{in general} $$

The basic process is:

  1. Identify the inner function.
  2. Substitute the inner function into the outer function wherever the outer function uses \(x\).
  3. Simplify the expression when it is helpful and valid.
  4. For a numeric input, evaluate from the inside out.
  5. Check whether every intermediate value is allowed by the next function’s domain.

Domain is especially important. For \(f(g(x))\), the input \(x\) must be allowed by \(g\), and the resulting value \(g(x)\) must be allowed by \(f\). In set notation:

$$ \operatorname{Dom}(f \circ g) = \{x \in \operatorname{Dom}(g) : g(x) \in \operatorname{Dom}(f)\} $$

This means the domain of a composite function is not always just the domain of the inner function or the outer function by itself. The output of the inner function has to fit the outer function.


Examples of Function Composition in Practice

Example 1: A Simple Composition

Let:

$$ f(x) = 2x + 3 $$
$$ g(x) = x^2 $$

To find \(f(g(x))\), substitute \(g(x)\) into \(f\):

$$ f(g(x)) = f(x^2) $$

Since \(f\) doubles its input and adds \(3\):

$$ f(x^2) = 2x^2 + 3 $$

So:

$$ (f \circ g)(x) = 2x^2 + 3 $$

At \(x = 4\):

$$ g(4) = 4^2 = 16 $$
$$ f(g(4)) = f(16) = 2(16) + 3 = 35 $$

Example 2: Why Order Matters

Using the same functions:

$$ f(x) = 2x + 3 $$
$$ g(x) = x^2 $$

Now reverse the order and find \(g(f(x))\):

$$ g(f(x)) = g(2x + 3) $$

Since \(g\) squares its input:

$$ g(2x + 3) = (2x + 3)^2 $$

At \(x = 4\):

$$ f(4) = 2(4) + 3 = 11 $$
$$ g(f(4)) = g(11) = 11^2 = 121 $$

So at \(x = 4\):

$$ f(g(4)) = 35 $$
$$ g(f(4)) = 121 $$

The same two functions give different results because they were applied in a different order.


Example 3: A Three-Function Chain

Let:

$$ f(x) = x + 1 $$
$$ g(x) = 3x $$
$$ h(x) = \sqrt{x} $$

To evaluate \(f(g(h(9)))\), start with the innermost function:

$$ h(9) = \sqrt{9} = 3 $$

Then apply \(g\):

$$ g(3) = 3(3) = 9 $$

Then apply \(f\):

$$ f(9) = 9 + 1 = 10 $$

Therefore:

$$ f(g(h(9))) = 10 $$

A stage-by-stage view is often the clearest way to understand longer compositions.


Example 4: A Domain Restriction

Let:

$$ f(x) = \ln(x) $$
$$ g(x) = x - 2 $$

Then:

$$ f(g(x)) = \ln(x - 2) $$

The natural logarithm is defined only for positive inputs, so the expression inside the logarithm must be greater than \(0\):

$$ x - 2 > 0 $$
$$ x > 2 $$

So the composite function is defined only when \(x > 2\). Even though \(g(x) = x - 2\) works for every real number, the composite function has a smaller domain because the output of \(g\) must be valid for \(f\).


How to Interpret the Result

The composed expression shows the selected function chain after substitution. For example, if the selected order is \(f\) after \(g\), the expression represents \(f(g(x))\).

The value at \(x\) is the final numeric output after all functions in the selected chain have been applied. It is not always the value of \(f(g(x))\) unless the selected order is specifically \(f\) after \(g\).

The selected order should be read from inside to outside. A label such as “\(f\) after \(g\)” means \(g\) is evaluated first and \(f\) is evaluated second:

$$ f \text{ after } g = f(g(x)) $$

The comparison between \(f(g(x))\) and \(g(f(x))\) is useful for seeing whether changing the order changes the result at the chosen input. If the calculator marks the two values as the same, that means the numeric outputs match within its comparison tolerance for that specific \(x\) value. It does not prove that the two composite functions are identical for every possible input.

Stage values show the path from the original input through each function. For a chain such as \(f(g(h(x)))\), the stages help you see \(x\), then \(h(x)\), then \(g(h(x))\), and finally \(f(g(h(x)))\).

Full-domain notes are heuristic warnings about possible restrictions; they are not a complete symbolic domain solution. At the selected input, the calculator validates square roots, logarithms, zero denominators, tangent poles, non-finite stages, and the indeterminate form (0^0).

Numeric output may be rounded for display. Ordinary finite values are shown to a limited number of decimal places, and very large or very small values may appear in exponential notation. If a result is undefined or not finite, review the domain and the intermediate stage values.


Common Mistakes and Misconceptions

Mistake 1: Reversing the order.
In \(f(g(x))\), \(g\) is evaluated first because it is inside the parentheses. The phrase “\(f\) after \(g\)” means apply \(g\) first, then apply \(f\).

Mistake 2: Assuming \(f(g(x))\) and \(g(f(x))\) are always equal.
Function composition is generally order-sensitive. The two compositions may match in special cases or at a particular input, but they usually represent different function chains.

Mistake 3: Substituting only part of the expression.
When composing functions, replace every occurrence of \(x\) in the outer function with the full inner expression. If \(f(x) = x^2 + x\) and \(g(x) = x - 1\), then:

$$ f(g(x)) = (x - 1)^2 + (x - 1) $$

Both copies of \(x\) in \(f\) must be replaced.

Mistake 4: Ignoring domain restrictions.
A composite function can fail even when the original input works in the inner function. The inner output must also be allowed by the outer function.

Mistake 5: Treating a numeric match as a symbolic identity.
If two compositions give the same value at one input, that does not mean the formulas are the same for all inputs. A full identity requires algebraic reasoning over the relevant domain.

Mistake 6: Misreading logarithms and trigonometric inputs.
In this calculator, log and ln are treated as natural logarithms. Trigonometric functions such as sin, cos, and tan use radians, not degrees.

Mistake 7: Using unsupported notation.
Use decimal points instead of decimal commas, and use only the supported variable \(x\). Multi-variable functions, comma-separated function arguments, matrices, vectors, piecewise definitions, and unsupported function names are outside this calculator’s scope.


When to Use Function Composition

Use function composition when you want to:

  • Evaluate a function inside another function.
  • Build one formula from a sequence of simpler formulas.
  • Compare \(f(g(x))\) with \(g(f(x))\).
  • Study how order affects the output.
  • Check intermediate values in a multi-step function chain.
  • Practice substitution with algebraic expressions.
  • Explore repeated compositions such as \(f(f(x))\) or \(g(g(x))\).
  • Think through domain restrictions caused by square roots, logarithms, denominators, or trigonometric functions.

Composition is especially helpful when a problem naturally has stages. The output of one step becomes the input of the next step.


Limitations and Things to Keep in Mind

A function composition calculator is a learning and checking tool, not a full symbolic algebra system. It can show substitution, evaluate a selected input, and display intermediate stages, but it may not simplify every expression the way a computer algebra system or a handwritten algebra solution might.

This calculator is designed for one-variable functions using \(x\). It supports common operations and elementary functions such as sqrt, log, ln, exp, abs, sin, cos, and tan. It does not support variables other than \(x\), multivariable functions, piecewise functions, matrices, vectors, inequalities, or arbitrary user-defined function names.

The available composition orders are limited to the supported choices, including \(f(g(x))\), \(g(f(x))\), \(f(f(x))\), \(g(g(x))\), \(f(g(h(x)))\), and \(h(g(f(x)))\).

The domain scan is heuristic. It can flag obvious possible restrictions, but it does not solve the exact domain of every composite function. For classwork, tests, proofs, or formal domain answers, work through the domain conditions directly.

Because the calculator evaluates numerically, results can be affected by finite-precision arithmetic and display rounding. Values close to a tangent pole are treated as undefined. A “same” comparison between \(f(g(x))\) and \(g(f(x))\) means the displayed numeric results are close enough under the calculator’s tolerance at that input. It does not prove symbolic equality.

For repeated compositions, enter valid expressions carefully. A blank or invalid required expression can prevent the calculation from running even if the selected order appears to emphasize another function.


How to Use This Calculator

  1. Enter a valid expression for \(f(x)\).
  2. Enter a valid expression for \(g(x)\).
  3. Enter \(h(x)\) only if you choose a three-function order that includes \(h\).
  4. Choose the composition order, such as \(f\) after \(g\) for \(f(g(x))\).
  5. Enter a numeric \(x\) value. Use a decimal point when entering decimals.
  6. Turn the domain scan on or off depending on whether you want restriction notes.
  7. Review the composed expression, value at \(x\), \(f(g(x))\) versus \(g(f(x))\) comparison, stage table, substitution steps, and any domain notes.
  8. Use preset examples for practice, or download the composition diagram after a valid result is displayed.

Frequently Asked Questions

Which function is evaluated first in \(f(g(x))\)?

The inner function is evaluated first. In \(f(g(x))\), calculate \(g(x)\) first, then use that result as the input for \(f\).


Is \(f(g(x))\) the same as \(g(f(x))\)?

Usually, no. Function composition is generally order-dependent, so reversing the order often changes both the formula and the numeric result. They can be the same for special functions or at specific input values, but that must be checked rather than assumed.


How do I find the domain of a composite function?

For \(f(g(x))\), first make sure \(x\) is allowed in \(g\). Then make sure the output \(g(x)\) is allowed in \(f\). Any value that fails either condition must be excluded from the domain of the composite function.


Why does a composition sometimes become undefined?

A composition becomes undefined when one of the stages produces an invalid input for the next stage. Common causes include division by zero, a negative value inside an even root, a nonpositive value inside a logarithm, or a tangent input where tangent is not defined.


Does log mean base 10 or natural logarithm?

In this calculator, log and ln are treated as natural logarithms. The natural logarithm uses base \(e\). Do not assume log means base \(10\) here.


Do trigonometric functions use degrees or radians?

They use radians. For example, an input of \(\pi\) represents \(180^\circ\), and an input of \(\frac{\pi}{2}\) represents \(90^\circ\).


What does it mean if \(f(g(x))\) and \(g(f(x))\) are marked the same?

It means the two numeric results are close enough at the selected \(x\) value under the calculator’s tolerance. It does not prove that \(f(g(x))\) and \(g(f(x))\) are the same function for every \(x\).


Can this calculator simplify composite functions exactly?

It can display the substituted composition and evaluate it numerically, but it is not a complete symbolic simplification tool. For exact simplification, identities, and formal domain work, verify the algebra separately.


Sources and References