Composition Calculator
Pick two functions and an x value, then see (f∘g)(x) and (g∘f)(x) worked out step by step.
Compositions
Functions are the machines of mathematics. You feed a number in, the function follows its rule, and a new number comes out. But what happens when you connect two of these machines together, so the output of the first becomes the input of the second? That linked process is called function composition, and it is one of the most useful ideas in algebra and calculus.
This page gives you a free composition calculator that evaluates composite functions step by step. You pick two functions from the preset lists, enter a value for x, and the calculator shows you both (f∘g)(x) and (g∘f)(x), with every substitution written out. Below the tool you will find a complete plain-English guide to composing functions, with worked examples and the mistakes to watch out for.
What This Calculator Does
This calculator composes two functions and evaluates the result at a number you choose. It offers five preset functions for f(x) and five for g(x): x², 2x + 1, 3x − 2, x + 5, and x³. You select one function for each slot, type in a value of x, and press the Calculate button. The tool then calculates both possible compositions and shows its work.
The results panel shows (f∘g)(x) and (g∘f)(x) as bold numbers, followed by a step-by-step trace. For example, with f(x) = x², g(x) = 2x + 1, and x = 3, the steps read: g(3) = 2(3) + 1 = 7, then f(7) = (7)² = 49, so (f∘g)(3) = 49. Then f(3) = (3)² = 9, then g(9) = 2(9) + 1 = 19, so (g∘f)(3) = 19. Seeing the substitutions written out is what makes the idea click.
How to Use This Calculator
Start by choosing your first function from the f(x) dropdown and your second function from the g(x) dropdown. Then type the value of x you want to evaluate into the input box. Any real number works, including decimals and negatives. Click the Calculate button, and both compositions appear below with their full working shown.
The only input that needs care is x: it must be a valid number. The dropdowns always contain a selection, so there is nothing else to go wrong. If you leave x empty or type something that is not a number, the calculator shows a friendly error message instead of a wrong answer. The Reset button clears your choices so you can try a new pair.
What Function Composition Means
The notation (f∘g)(x) is read as f composed with g of x, and it means f(g(x)). The small circle is just shorthand. The key rule is that you always work from the inside out: first apply the function closest to x, which is g, and then apply f to whatever comes out. Think of it as an assembly line where g does its job first and f finishes the work.
The reverse order, (g∘f)(x), means g(f(x)): now f goes first and g goes second. These two are usually different numbers, which surprises many students. Composition is not like multiplication, where order does not matter. Swapping f and g almost always changes the answer, and the calculator shows both side by side so you can see the difference clearly.
You can also think of composition as substitution. To find (f∘g)(x), take the formula for f and replace every x in it with the whole formula for g(x). If f(x) = x² and g(x) = 2x + 1, then (f∘g)(x) = (2x + 1)². The calculator does the numeric version of this: it computes g(x) as a number first, then plugs that number into f.
Worked Examples With Full Steps
Example one: f(x) = x², g(x) = 2x + 1, x = 3. For (f∘g)(3), start inside with g: g(3) = 2(3) + 1 = 6 + 1 = 7. Now feed 7 into f: f(7) = (7)² = 49. So (f∘g)(3) = 49. For (g∘f)(3), start inside with f: f(3) = (3)² = 9. Now feed 9 into g: g(9) = 2(9) + 1 = 18 + 1 = 19. So (g∘f)(3) = 19. Same functions, same x, but 49 versus 19 because the order changed.
Example two: f(x) = 3x − 2, g(x) = x + 5, x = 2. For (f∘g)(2): g(2) = (2) + 5 = 7, then f(7) = 3(7) − 2 = 21 − 2 = 19. So (f∘g)(2) = 19. For (g∘f)(2): f(2) = 3(2) − 2 = 6 − 2 = 4, then g(4) = (4) + 5 = 9. So (g∘f)(2) = 9. Here the two answers are 19 and 9.
Example three uses a cube: f(x) = x³, g(x) = x + 5, x = 1. For (f∘g)(1): g(1) = (1) + 5 = 6, then f(6) = (6)³ = 216. So (f∘g)(1) = 216. For (g∘f)(1): f(1) = (1)³ = 1, then g(1) = (1) + 5 = 6. So (g∘f)(1) = 6. Notice how cubing after adding gives a huge number, while cubing first barely changes anything.
Understanding Your Results
The two headline numbers are the values of the two compositions at your x. The (f∘g)(x) row applies g first and f second. The (g∘f)(x) row applies f first and g second. In most cases these numbers differ, and that difference is exactly the lesson composition teaches.
Below the numbers, the steps paragraph narrates the whole calculation in sentences. Read it from left to right: it names which function goes first, shows the substitution with your x value, gives the intermediate result, and then shows the second substitution leading to the final answer. If your own hand calculation disagrees with the tool, compare your steps against this trace to find where you went wrong.
Why the Order Matters So Much
Order matters because the first function changes the number the second function sees. In the first example, g turned 3 into 7 before f squared it, giving 49. In the reverse order, f turned 3 into 9 before g doubled it and added 1, giving 19. The second function always works on a different starting number, so the results diverge.
A real-life picture helps. Imagine g means put on socks and f means put on shoes. Doing g then f gives the normal result: socks, then shoes. Doing f then g gives shoes, then socks, which is a very different outcome. Function composition behaves the same way: the sequence of operations defines the result, and swapping the sequence changes everything.
Common Mistakes to Avoid
The number one mistake is reading (f∘g)(x) from left to right and applying f first. The correct order is inside out: g first, then f. A good memory trick is that the function sitting closest to the x touches the x first. Another common error is forgetting parentheses when substituting, for example writing 2x + 1² instead of (2x + 1)². Those are different numbers, and the parentheses are not optional.
Students also mix up composition with multiplication. The expression (f∘g)(x) does not mean f(x) times g(x). It means f of g of x, a chain of two operations. Finally, watch your arithmetic on the intermediate step. If g(3) is wrong, everything after it is wrong too, so double-check the inner function before moving outward.
Frequently Asked Questions
1. What does (f∘g)(x) mean?
The notation (f∘g)(x) means f(g(x)): apply g to x first, then apply f to the result. The small circle stands for composition. You always evaluate from the inside out, starting with the function closest to x.
2. Is (f∘g)(x) the same as (g∘f)(x)?
Usually not. Composition is not commutative, which means the order changes the answer. With f(x) = x², g(x) = 2x + 1, and x = 3, (f∘g)(3) = 49 while (g∘f)(3) = 19. The two are equal only for special pairs of functions, so never assume they match.
3. Which function do I apply first?
Apply the inner function first, the one written closest to x. In (f∘g)(x), that is g. In (g∘f)(x), that is f. A simple way to remember: the function touching the x goes first, and its output becomes the input of the other function.
4. What is the difference between composition and multiplication of functions?
Composition chains functions: (f∘g)(x) = f(g(x)), one output feeding the next input. Multiplication combines outputs: (f·g)(x) = f(x) × g(x), both functions evaluated at the same x and then multiplied. They are completely different operations with different answers.
5. Can I compose a function with itself?
Yes. Composing a function with itself means (f∘f)(x) = f(f(x)). If f(x) = 2x + 1, then f(f(3)) = f(7) = 15. To try this in the calculator, select the same preset in both dropdowns and enter your x value.
6. What are the domain restrictions in composition?
The output of the inner function must be a valid input for the outer function. If the inner function produces a number the outer function cannot accept, the composition is undefined there. With the polynomial presets in this calculator, every real number works, so there are no restrictions to worry about.
7. How do I write (f∘g)(x) as a single formula?
Substitute the whole formula of g into every x in the formula of f. If f(x) = x² and g(x) = 2x + 1, replace x with (2x + 1) to get (f∘g)(x) = (2x + 1)², which expands to 4x² + 4x + 1. The calculator evaluates numerically, but this formula version is what you would use in algebra class.
8. Why do the steps show parentheses around the numbers?
The parentheses show exactly what got substituted where. Writing f(7) = (7)² makes it clear that the entire 7 was squared, not just part of an expression. When the substituted value is itself a formula, like (2x + 1), the parentheses become essential to getting the right answer.
9. Does composition work with three functions?
Yes. The expression (f∘g∘h)(x) means f(g(h(x))): apply h first, then g, then f, always working inside out. You can chain as many functions as you like. To do three with this calculator, compose two of them first, then compose the result with the third.
10. Where is function composition used in real life?
Composition appears whenever one process feeds another. Converting currencies through an intermediate currency is composition. In computing, piping the output of one program into another is composition. In calculus, the chain rule for derivatives exists precisely to differentiate composite functions.
11. What is an inverse function in terms of composition?
Two functions are inverses when composing them returns the original input: (f∘g)(x) = x and (g∘f)(x) = x. For example, f(x) = 2x and g(x) = x/2 undo each other. Checking both compositions is the standard test for whether two functions are inverses.
12. Can x be a decimal or a negative number?
Yes. The calculator accepts any real number for x, including decimals like 2.5 and negatives like −4. The same inside-out rule applies. Just type the number into the x box and the tool handles the arithmetic, including the signs, for you.
13. Why is my hand calculation different from the calculator?
The most likely cause is applying the functions in the wrong order, or an arithmetic slip in the inner function. Read the steps paragraph under the results and compare it line by line with your work. The first place your numbers differ from the trace is where the mistake happened.
14. What does the ∘ symbol stand for?
The ∘ symbol is the composition operator. It is read as composed with, so f∘g is f composed with g. It is not a multiplication dot and not the letter o. Some textbooks write it as a small open circle between the function names, exactly as shown in this calculator.
15. Is composition associative?
Yes. Composition is associative, which means (f∘g)∘h gives the same result as f∘(g∘h). Grouping does not matter, only the left-to-right order of the functions matters. This is different from commutativity: you can regroup the parentheses freely, but you cannot swap the functions.
Final Thoughts
Function composition is simply functions working as a team, with the output of one becoming the input of the next. The golden rule is inside out: start with the function closest to x and work outward. Use the calculator above to test any pair of presets, study the step-by-step trace, and the notation (f∘g)(x) will soon feel as natural as ordinary arithmetic.