Composition Of Two Functions Calculator
Pick an outer function f(x) and an inner function g(x), enter a value for x, and see f(g(x)) computed step by step, inner function first.
Choose your functions
The inner function is always evaluated first. Watch out: some combinations are undefined for certain x values.
Your input
f(g(x))
Educational tool. Results are rounded to 4 decimal places.
Function composition is the idea of feeding the output of one function directly into the input of another. When you see f(g(x)), it means compute g(x) first, then apply f to whatever came out. The order is fixed: inner first, then outer.
The Composition Of Two Functions Calculator lets you pick an outer function f(x) and an inner function g(x) from preset lists, enter a value for x, and watch the two-step evaluation unfold. It also flags the cases where the composition is undefined.
Below you will find a plain explanation of how composition works, why order matters, where students most often go wrong, and four worked examples that match exactly what the calculator produces.
What Function Composition Means
A function is a rule that turns each allowed input into exactly one output. Composition chains two such rules together. The notation f(g(x)) is read as f of g of x, and it describes a two-stage machine: g processes x, and f processes the result.
You can also write the same idea as (f ∘ g)(x), which is read as f composed with g. Both notations describe the same computation, and both hide a trap: the expression is evaluated from the inside out, not left to right.
A helpful image is a relay race. The runner g carries the baton x partway, then hands it to runner f, who carries it to the finish. Swapping the runners changes the race completely.
What This Calculator Does
The calculator offers five outer functions and five inner functions: x squared + 1, 2x − 3, square root of x, 1 / x, and x cubed for f, and 2x + 1, x − 4, x squared, 3 − x, and square root of x for g. You choose one of each, then enter x.
It evaluates the inner function at your x, checks that the result is valid input for the outer function, and then evaluates the outer function on that inner value. The answer appears with three step cards showing the inner step, the outer step, and the final combined result.
When a combination is undefined, for example when the inner value is negative for a square root or zero for 1 / x, the calculator explains the problem in an error message instead of printing a nonsense number.
The Inputs Explained
The outer function f(x) is applied last, so it gets the final say on the answer. Choosing a square root here means the inner function's output must be non-negative. Choosing 1 / x means the inner function's output cannot be zero.
The inner function g(x) is applied first to your raw x value. It must accept x itself, so the square root choice here requires x to be zero or positive.
The value of x can be any number between negative one million and positive one million. Decimal values are fine, and the calculator rounds displayed results to four decimal places.
The Formula Behind the Math
Composition has no complicated formula because the operation is procedural rather than algebraic. You evaluate twice, nesting one evaluation inside the other.
The formula is:
(f ∘ g)(x) = f(g(x))
The right side is the working definition: compute the inner value g(x), then apply f to that value. Every worked example in this article follows those two steps in that exact order.
How the Calculation Works
Step one substitutes your x into the inner function and simplifies. With g(x) = 2x + 1 and x = 3, the inner value is 2(3) + 1 = 7. This number becomes the input to the outer function.
Step two substitutes the inner value into the outer function and simplifies again. With f(x) = x squared + 1 and an inner value of 7, the result is 7 squared + 1 = 50. The calculator displays each substitution so you can follow the chain.
Before the second step, a domain check runs. If the inner value is outside the outer function's domain, the calculation stops with an explanation. That check mirrors what a careful student should do by hand: verify that each stage's output is legal input for the next stage.
Why Order Matters
Composition is not commutative, which is the formal way of saying that f(g(x)) and g(f(x)) are usually different numbers. Swapping the outer and inner functions changes the machine.
Take f(x) = x squared + 1 and g(x) = 2x + 1 with x = 3. Then f(g(3)) = f(7) = 50, but g(f(3)) = g(10) = 21. Same functions, same x, wildly different answers.
The only time swapping makes no difference is for special pairs of functions, such as inverse functions. In general, always read composition from the inside out and resist the urge to rearrange it.
Domain Pitfalls in Composition
A composition can break at either stage. The inner function may reject x directly, as with g(x) = square root of x at x = −4. Or the inner function may produce a value the outer function rejects, as with f(x) = 1 / x when g(x) outputs zero.
This second failure mode surprises students because the original x looked perfectly fine. The input was legal for g, the output of g was a normal number, and yet f could not accept it. That is why domain checking must happen after the inner evaluation, not just at the start.
The calculator's error messages name the offending stage. Knowing whether the breakdown happened inside or outside tells you exactly where to adjust your x value.
Worked Example: f(x) = x Squared + 1, g(x) = 2x + 1, x = 3
First: evaluate the inner function. g(3) = 2(3) + 1 = 6 + 1 = 7.
Then: evaluate the outer function at the inner value. f(7) = 7 squared + 1 = 49 + 1 = 50.
The answer: f(g(3)) = 50. The calculator shows the same three lines: the inner step equals 7, the outer step equals 50, and the combined statement confirms the result.
Common Mistakes to Avoid
The classic mistake is applying f first. With f(g(x)), students sometimes compute f(x) and then plug that into g, which answers a different question entirely. The parentheses tell you the order: g is innermost, so g goes first.
A second mistake is forgetting to substitute into the inner function fully. Writing f(2x + 1) and stopping, without replacing x with the number, leaves the job half done. Always reduce the inner function to a single number before touching f.
A third mistake is ignoring domain restrictions on the outer function. A negative inner value fed into a square root, or a zero inner value fed into 1 / x, silently breaks the math. Check the domain of the outer function against the inner result every time.
Worked Example: f(x) = 2x − 3, g(x) = x Squared, x = −4
First: evaluate the inner function. g(−4) = (−4) squared = 16. Notice the negative input becomes a positive inner value.
Then: evaluate the outer function at the inner value. f(16) = 2(16) − 3 = 32 − 3 = 29.
The answer: f(g(−4)) = 29. This example also shows why you should not pre-simplify signs: the squaring must happen before the doubling.
Composition Versus Multiplication of Functions
Students sometimes confuse f(g(x)) with f(x) times g(x). They are entirely different operations. Composition nests one evaluation inside the other; multiplication evaluates both at the same x and multiplies the results.
With f(x) = x squared + 1, g(x) = 2x + 1, and x = 3, composition gives 50, while multiplication gives f(3) × g(3) = 10 × 7 = 70. The notation f(g(x)) always means composition, never multiplication.
If you need the product, write it explicitly as f(x) × g(x). The calculator never multiplies; it always composes, inner first.
Worked Example: f(x) = Square Root of x, g(x) = 3 − x, x = 2
First: evaluate the inner function. g(2) = 3 − 2 = 1.
Then: evaluate the outer function at the inner value. f(1) = square root of 1 = 1.
The answer: f(g(2)) = 1. The domain check passes because the inner value 1 is non-negative, which the square root requires.
Recognizing Composition in Word Problems
Composition appears whenever one quantity depends on another which depends on a third. A store applies a coupon to a price, then applies sales tax to the discounted price. That is tax(discount(price)), a composition of two functions.
Another common setting is unit conversion chains. Converting miles to kilometers and then kilometers to meters is a composition of two linear functions. Each stage's output becomes the next stage's input.
Spotting the inner function is the key skill. Ask yourself: which calculation must finish before the other can start? That one is g, and the one waiting for its output is f.
Worked Example: An Undefined Case, f(x) = 1 / x, g(x) = x − 4, x = 4
First: evaluate the inner function. g(4) = 4 − 4 = 0. So far nothing looks wrong; zero is a perfectly ordinary number.
Then: attempt the outer function. f(0) = 1 / 0, which is undefined. The calculator stops here and reports that the outer function cannot accept the inner value zero.
The answer: f(g(4)) is undefined. This is a correct mathematical result, not a calculator bug. Choosing x = 5 instead gives g(5) = 1 and f(1) = 1, a perfectly valid answer.
Tips for Checking Your Work
Plug the final answer back through the chain in reverse to sanity-check it. If f(g(3)) = 50 with f(x) = x squared + 1, then the inner value must have been 7, because 7 squared + 1 = 50. Then confirm g(3) = 7. If both links hold, the answer is right.
Try a second x value, especially a negative or zero one, to expose domain mistakes. Compositions that work for positive x sometimes break for negative x, and a quick second check catches that.
Finally, compare f(g(x)) with g(f(x)) for your chosen functions. If the two differ, you have confirmed that order matters for this pair, which is a strong sign your inner-first evaluation was correct.
Limitations of This Tool
The calculator works from fixed preset lists, so it cannot evaluate arbitrary functions you invent. For custom functions, the same two-step procedure applies by hand or in a computer algebra system.
Results round to four decimal places, which can hide tiny differences between very close values. The underlying arithmetic is exact for the presets given, since all of them use elementary operations.
The domain checks cover the two ways compositions break in these presets: negative square roots and division by zero. Exotic functions with trickier domains would need their own analysis.
Frequently Asked Questions
1. What does f(g(x)) mean?
It means evaluate g(x) first, then apply f to the result. The notation is read as f of g of x, and the evaluation always proceeds from the inside out.
2. Which function do I evaluate first in a composition?
The inner function, g(x). Compute it to a single number, then substitute that number into the outer function f. Evaluating f first answers a different question.
3. Is f(g(x)) the same as g(f(x))?
Usually not. Composition is generally not commutative. With f(x) = x squared + 1 and g(x) = 2x + 1 at x = 3, f(g(3)) = 50 while g(f(3)) = 21.
4. What does (f ∘ g)(x) mean?
It is another notation for the same composition: (f ∘ g)(x) = f(g(x)). Read it as f composed with g, and evaluate it inner-first exactly like f(g(x)).
5. Can a composition be undefined?
Yes, in two ways. The inner function may reject x, or the inner function's output may fall outside the outer function's domain. The calculator checks both stages and reports which one failed.
6. Why does 1 / x fail when the inner value is zero?
Division by zero is undefined. If g(x) = 0, then f(g(x)) = 1 / 0 has no value. Picking an x that makes g(x) nonzero fixes it.
7. Why does the square root option fail for negative inputs?
Over the real numbers, the square root of a negative number is undefined. Both the inner and outer square root options require their inputs to be zero or positive.
8. What is the domain of a composite function?
It is the set of x values such that x is in the domain of g and g(x) is in the domain of f. Both conditions must hold at once.
9. How is composition different from multiplying functions?
Composition nests evaluations: f(g(x)). Multiplication evaluates both at the same x and multiplies: f(x) × g(x). They give different answers for the same inputs.
10. Does the calculator show the intermediate steps?
Yes. Each result shows three step cards: the inner evaluation, the outer evaluation, and the combined statement, so you can follow the chain from x to the final answer.
11. Can I use decimal values for x?
Yes. Any number between -1000000 and 1000000 works, including decimals. Displayed results are rounded to four decimal places.
12. What are the preset functions in the calculator?
The outer list is x squared + 1, 2x - 3, square root of x, 1 / x, and x cubed. The inner list is 2x + 1, x - 4, x squared, 3 - x, and square root of x.
13. How do I check a composition answer by hand?
Evaluate the inner function at x to a single number, substitute that number into the outer function, and simplify. Then reverse-check: confirm the outer function maps your inner value to the final answer.
14. Where does composition appear outside math class?
Anywhere one process feeds another: discounts then tax on a price, chained unit conversions, or multi-stage manufacturing where each stage transforms the previous stage's output.
15. Is this calculator exact or approximate?
The arithmetic is exact for the preset elementary functions, but displayed answers are rounded to 4 decimal places. The domain checks reflect the two failure modes in these presets: negative square roots and division by zero.