Function Composition Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

What is function composition?

Functions act like machines: you put in an input, the function processes it, and you get an output. Function composition is what happens when the output of one function is used as the input of another function. In symbols, this is written as (f \circ g)(x) or f(g(x)), which you read as โ€œf of g of xโ€.

This calculator helps you evaluate function compositions numerically. You enter two functions, f(x) and g(x), plus a specific value of x. The tool then computes both f(g(x)) and g(f(x)) at that value so you can compare the results and see how the order of composition changes the outcome.

Function composition shows up throughout algebra, precalculus, and calculus. It is also a useful way to describe real processes that happen in steps, such as converting units and then applying a correction factor, or applying multiple percentage changes in sequence.

Notation and formulas for function composition

Suppose you have two functions:

The composition of f with g, written f \circ g, is the function defined by

( f โˆ˜ g ) ( x ) = f ( g ( x ) )

Similarly, the composition of g with f, written g \circ f, is

( g โˆ˜ f ) ( x ) = g ( f ( x ) )

Even though the same two functions are involved, f(g(x)) and g(f(x)) usually give different results because the operations happen in a different order.

Example formulas using the default functions

The default functions in the calculator are chosen to match a standard textbook example:

Using these, the two possible compositions are:

If you leave the defaults in the form and choose a value of x, the calculator will evaluate these formulas numerically. This lets you see how the symbolic expressions and numeric values line up.

Interpreting the calculator results

When you submit the form, the calculator processes three main pieces of information:

  1. Your definition of f(x).
  2. Your definition of g(x).
  3. The numerical value you choose for x.

From these, it computes:

This lets you compare what happens when you apply g first and then f, versus applying f first and then g. In many situations, one of these compositions has a more useful interpretation than the other, depending on the underlying problem.

Worked example: step-by-step composition

To see the process in action, use the default functions:

Suppose you choose x = 2. Then the compositions are evaluated as follows.

Compute f(g(2))

  1. Start with x = 2.
  2. Apply g first: g(2) = 2^2 = 4.
  3. Use that result as the input to f: f(g(2)) = f(4) = 2ยท4 + 1 = 9.

So f(g(2)) = 9.

Compute g(f(2))

  1. Start with x = 2.
  2. Apply f first: f(2) = 2ยท2 + 1 = 5.
  3. Use that result as the input to g: g(f(2)) = g(5) = 5^2 = 25.

So g(f(2)) = 25. The different final answers (9 vs 25) highlight that the order of composition matters.

Comparing f(g(x)) and g(f(x))

The following table summarizes the behavior of the same example functions, using a few integer values of x. The patterns you see here will match what the calculator produces if you use the default functions and plug in these same x-values.

Comparison of f(g(x)) and g(f(x)) for f(x) = 2x + 1 and g(x) = x^2
x g(x) f(g(x)) f(x) g(f(x))
0 0 1 1 1
1 1 3 3 9
2 4 9 5 25

Notice again that although both compositions use the same basic operations (square, then double and add 1), the order changes the expression and the numerical results. This is a core idea in working with composite functions.

Domain considerations for composite functions

In function composition, the domain (the set of allowed input values) needs special attention. For f(g(x)) to be well-defined at a specific x-value:

Similarly, for g(f(x)) to be defined, x must be in the domain of f, and f(x) must be in the domain of g. If any of these conditions fail, the composition is undefined at that input.

For example, let

Then the composition f(g(x)) = 1/(x + 2) is undefined at x = -2, because it would require dividing by zero. On the other hand, g(f(x)) = 1/x + 2 is undefined at x = 0, for the same reason. Note that each composition can have a different domain, even when built from the same two functions.

Real-world interpretations and uses

Function composition is not just a symbolic trick; it captures real processes made of several steps.

Unit conversions and adjustments

Suppose you convert a temperature from Celsius to Fahrenheit and then apply a wind-chill adjustment. If

then f(g(x)) represents โ€œtake a Celsius temperature, convert it, then apply wind chillโ€. The composition captures the whole process in a single function of the original Celsius value.

Sequential percentage changes

In finance, sequential percentage changes are naturally described using composition. For instance, you might first apply a 10% discount (one function), and then apply sales tax (another function). The combined effect on the original price is a composition of those two functions, and the order of operations (discount then tax, or tax then discount) will affect the final price.

Nested functions in programming

In programming languages, you often see nested function calls such as f(g(x)). This is a direct parallel to mathematical composition: the expression g(x) is evaluated first, then its result is passed as the argument to f. Understanding composite functions in algebra can make it easier to reason about nested function calls in code, and vice versa.

Using this calculator effectively

This calculator is designed primarily for students and educators studying algebra, precalculus, or early calculus. Some practical suggestions:

Calculator notes, assumptions, and limitations

To keep the tool focused and easy to use, a few assumptions and limitations apply:

If you are teaching or studying composite functions, you can use this calculator alongside hand calculations, graphing tools, or a computer algebra system to verify your work and deepen your understanding.

Related concepts and further study

Once you are comfortable with function composition, you may want to explore related ideas such as inverse functions, transformations of graphs, and piecewise-defined functions. These topics build on the same core idea of viewing functions as processes that can be combined and rearranged in different ways.

Enter functions and a value.

Embed this calculator

Copy and paste the HTML below to add the Function Composition Calculator to your website.