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.
Suppose you have two functions:
f(x) takes an input x and produces an output f(x).g(x) takes an input x and produces an output g(x).The composition of f with g, written f \circ g, is the function defined by
Similarly, the composition of g with f, written g \circ f, is
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.
The default functions in the calculator are chosen to match a standard textbook example:
f(x) = 2x + 1g(x) = x^2Using these, the two possible compositions are:
f(g(x)) = f(x^2) = 2x^2 + 1g(f(x)) = g(2x + 1) = (2x + 1)^2 = 4x^2 + 4x + 1If 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.
When you submit the form, the calculator processes three main pieces of information:
f(x).g(x).x.From these, it computes:
g(x) at the chosen x-value.f(g(x)) at that x-value.f(x) at the chosen x-value.g(f(x)) at that x-value.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.
To see the process in action, use the default functions:
f(x) = 2x + 1g(x) = x^2Suppose you choose x = 2. Then the compositions are evaluated as follows.
x = 2.g first: g(2) = 2^2 = 4.f: f(g(2)) = f(4) = 2ยท4 + 1 = 9.So f(g(2)) = 9.
x = 2.f first: f(2) = 2ยท2 + 1 = 5.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.
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.
| 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.
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:
x must be in the domain of g, andg(x) must be in the domain of f.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
f(x) = 1/x (undefined at x = 0)g(x) = x + 2 (defined for all real numbers)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.
Function composition is not just a symbolic trick; it captures real processes made of several steps.
Suppose you convert a temperature from Celsius to Fahrenheit and then apply a wind-chill adjustment. If
g(x) converts Celsius to Fahrenheit, andf(x) adjusts a Fahrenheit temperature for wind chill,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.
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.
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.
This calculator is designed primarily for students and educators studying algebra, precalculus, or early calculus. Some practical suggestions:
f(x) = 2x + 1 and g(x) = x^2 together with the table above to check your understanding of how the tool works.To keep the tool focused and easy to use, a few assumptions and limitations apply:
x as the variable name for both f(x) and g(x). The calculator treats other letters as constants or may reject them, depending on its parser.+), subtraction (-), multiplication (*), division (/), powers (for example x^2), and standard functions (such as square roots or trigonometric functions) may be supported, depending on the implementation on this site. If an expression is not recognized, you may see an error message or no result.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.
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.