Composition Functions Calculator
Enter the coefficients of two polynomials f(x) and g(x), each of degree two or less. The calculator expands (f circle g)(x) and (g circle f)(x) step by step and evaluates both at your chosen value of x.
Outer function
f(x)f(x) = 2x + 3
Inner function
g(x)g(x) = x squared + 1
Your compositions
Step 1, read the two functions
Step 2, expand (f circle g)(x)
Step 3, expand (g circle f)(x)
Function composition is the idea of feeding the output of one function into the input of another. If g(x) doubles a number and f(x) adds three, then the composition (f ∘ g)(x) doubles first and adds three second. It is one of the most used operations in algebra, and it appears everywhere from chain rule calculus to computer graphics.
The Composition Functions Calculator on this page composes two polynomial functions of degree two or less. You enter the coefficients of f(x) and g(x), or pick one of four preset pairs, and the tool expands (f ∘ g)(x) and (g ∘ f)(x) step by step, shows the expanded coefficients, and evaluates both compositions at your chosen value of x.
This guide explains the notation, shows exactly how the expansion works, and walks through four fully worked examples with every step shown. Every result here matches what the calculator produces for the same inputs.
What Function Composition Means
Composition chains two functions into one. The notation (f ∘ g)(x) is read "f composed with g of x" and it means f(g(x)): apply g first, then apply f to the result. The inner function runs first and the outer function runs second, always in that order.
A concrete picture helps. If g(x) = x + 1 and f(x) = 2x, then (f ∘ g)(3) means first compute g(3) = 4, then compute f(4) = 8. The composition as a formula is (f ∘ g)(x) = 2(x + 1) = 2x + 2, a brand new function built from the two originals.
Reading the Notation (f ∘ g)(x)
The small circle ∘ is the composition operator, and order matters enormously. (f ∘ g)(x) means f of g of x, with g on the inside. (g ∘ f)(x) means g of f of x, with f on the inside. Swapping the order usually gives a completely different function.
Beginners often confuse (f ∘ g)(x) with multiplication, reading it as f times g times x. It is not multiplication. Nothing is being multiplied; one function's output is becoming the other function's input. Keep that picture in mind and the notation stops being intimidating.
How to Enter f(x) and g(x)
The calculator accepts each function as three coefficients: the coefficient of x squared, the coefficient of x, and the constant term. For f(x) = 2x + 3 you enter 0 for x squared, 2 for x, and 3 for the constant. For g(x) = x squared + 1 you enter 1, 0, and 1.
Any coefficient can be zero, negative, or a decimal. Leaving a function as all zeros is not allowed, because composing with the zero function is trivial and usually means a typo. As you type, the preview under each function group shows the function in readable form so you can confirm it matches your intention.
The Preset Function Pairs
Four preset pairs cover the instructive cases and fill the coefficients automatically. Linear into linear uses f(x) = 2x + 3 with g(x) = 4x minus 1. Linear into quadratic uses f(x) = 2x + 3 with g(x) = x squared + 1.
Quadratic into linear uses f(x) = x squared + 1 with g(x) = 3x minus 2. Quadratic into quadratic uses f(x) = x squared + 1 with g(x) = x squared minus 1, the pair that produces degree four results. Choosing a preset fills all six coefficient boxes, and you can still edit any of them afterward.
How the Calculator Expands (f ∘ g)(x)
The expansion follows the definition directly. The calculator takes the formula for f(x), replaces every x in it with the complete formula for g(x), and then multiplies everything out and collects like terms. The step display shows the substitution before the simplification.
For example, with f(x) = 2x + 3 and g(x) = x squared + 1, the substitution gives 2(x squared + 1) + 3. Multiplying out gives 2x squared + 2 + 3, and collecting the constants gives 2x squared + 5. The coefficients line then reports constant term first: [5, 0, 2].
How the Calculator Expands (g ∘ f)(x)
The reverse composition starts from g(x) and substitutes the whole of f(x) into it. With the same pair, g(f(x)) means (2x + 3) squared + 1. Expanding the square gives 4x squared + 12x + 9, and adding 1 gives 4x squared + 12x + 10.
Notice this is nothing like the 2x squared + 5 from the other order. The calculator performs this expansion independently rather than reusing the first result, which is why the step display for step three repeats the substitution with the roles reversed.
Order Matters: Why (f ∘ g) Is Not (g ∘ f)
Composition is like putting on socks and shoes. Socks then shoes works; shoes then socks does not give the same result. Algebraically, f(g(x)) applies g's transformation first, so g's shape dominates the inside of the expression, while g(f(x)) lets f's transformation go first.
The calculator demonstrates this on every run by showing both expansions side by side. In the vast majority of cases the two expanded polynomials differ in several coefficients. The rare cases where they agree are special, and the results note calls that out when it happens.
Worked Example: Two Linear Functions
Take f(x) = 2x + 3 and g(x) = 4x minus 1, the first preset pair. Enter 0, 2, 3 for f and 0, 4, negative 1 for g, and evaluate at x = 2.
First, expand (f ∘ g)(x). Substitute: f(g(x)) = 2(4x minus 1) + 3. Multiply out: 8x minus 2 + 3. Collect: 8x + 1.
Next, expand (g ∘ f)(x). Substitute: g(f(x)) = 4(2x + 3) minus 1. Multiply out: 8x + 12 minus 1. Collect: 8x + 11.
Finally, evaluate at x = 2. For the first order, g(2) = 7, then f(7) = 17, so (f ∘ g)(2) = 17. For the second order, f(2) = 7, then g(7) = 27, so (g ∘ f)(2) = 27. Both compositions are linear here, but their constants differ.
Worked Example: Linear Inside Quadratic
Take f(x) = 2x + 3 and g(x) = x squared + 1, the second preset pair. Enter 0, 2, 3 for f and 1, 0, 1 for g, and evaluate at x = 1.
First, (f ∘ g)(x) = 2(x squared + 1) + 3. Expanding gives 2x squared + 2 + 3, which simplifies to 2x squared + 5. The coefficients are [5, 0, 2].
Next, (g ∘ f)(x) = (2x + 3) squared + 1. The square expands to 4x squared + 12x + 9, and adding 1 gives 4x squared + 12x + 10. The coefficients are [10, 12, 4].
Evaluate at x = 1. First order: g(1) = 2, then f(2) = 7, so the value is 7. Check the formula: 2(1) + 5 = 7. Second order: f(1) = 5, then g(5) = 26, so the value is 26. Check: 4 + 12 + 10 = 26. Both checks agree.
Worked Example: Quadratic Inside Quadratic
Take f(x) = x squared + 1 and g(x) = x squared minus 1, the fourth preset pair. Enter 1, 0, 1 for f and 1, 0, negative 1 for g, and evaluate at x = 2.
First, (f ∘ g)(x) = (x squared minus 1) squared + 1. The square expands to x to the fourth minus 2x squared + 1. Adding 1 gives x to the fourth minus 2x squared + 2. The degree is 4, and the coefficients are [2, 0, negative 2, 0, 1].
Next, (g ∘ f)(x) = (x squared + 1) squared minus 1. The square expands to x to the fourth + 2x squared + 1. Subtracting 1 gives x to the fourth + 2x squared. The coefficients are [0, 0, 2, 0, 1].
Evaluate at x = 2. First order: g(2) = 3, then f(3) = 10. Check the expanded form: 16 minus 8 + 2 = 10. Second order: f(2) = 5, then g(5) = 24. Check: 16 + 8 = 24. Both agree, and the two compositions differ in the middle coefficients.
Worked Example: Evaluating at a Point
Take f(x) = 3x minus 2 and g(x) = x squared, and evaluate at x = 3. Enter 0, 3, negative 2 for f and 1, 0, 0 for g.
First expand both orders. (f ∘ g)(x) = 3(x squared) minus 2 = 3x squared minus 2. (g ∘ f)(x) = (3x minus 2) squared = 9x squared minus 12x + 4.
Now evaluate at x = 3 the long way. For the first order, g(3) = 9, then f(9) = 3 times 9 minus 2 = 25. For the second order, f(3) = 7, then g(7) = 49.
Confirm with the expanded forms. First: 3(9) minus 2 = 25. Second: 9(9) minus 12(3) + 4 = 81 minus 36 + 4 = 49. The two routes to each answer always agree, which makes evaluation the perfect way to check an expansion.
Degrees: What Happens to the Powers
The degree of a composition is the product of the degrees. A linear function composed with a quadratic gives degree 1 times 2 = 2, as the second example showed. A quadratic composed with a quadratic gives degree 2 times 2 = 4, as the third example showed.
This is why the calculator can return up to five coefficients even though you only entered quadratics. The results panel always states the degree of each expansion, so a degree four answer never comes as a surprise. If both functions are linear, the composition stays linear.
Common Composition Mistakes
The classic mistake is distributing incorrectly when the inner function has more than one term. In (2x + 3) squared, the middle term 12x is easy to forget, and dropping it gives 4x squared + 9 instead of the correct 4x squared + 12x + 9. Always expand squares with the full (a + b) squared pattern.
Another mistake is composing in the wrong order, computing g(f(x)) when the question asked for f(g(x)). A third is forgetting to square the entire inner expression rather than just its first term. The calculator's step display guards against all three by showing the substitution explicitly before simplifying.
Where Composition Shows Up
Composition is the engine behind the chain rule in calculus: the derivative of f(g(x)) is f prime of g(x) times g prime of x. It also describes multi stage processes, like a temperature conversion followed by a unit conversion, or a discount applied after a tax.
In computing, function pipelines and nested transformations are compositions in disguise. Any time the output of one stage becomes the input of the next, you are composing functions, whether the stages are formulas, filters, or machine learning layers.
Checking Your Answer by Hand
Evaluation at a point is the fastest check. Pick a simple x value like 1 or 2, compute the composition the long way through the inner and outer functions, and compare with the expanded formula's value at the same x. If they disagree, the expansion has an error.
Also check the degree first. If you composed two quadratics and your hand expansion came out quadratic, you lost a square somewhere. The degree product rule catches that mistake in seconds, before you hunt through the algebra.
When the Compositions Come Out Equal
Occasionally (f ∘ g)(x) and (g ∘ f)(x) are the same function. The most famous case is inverse functions: if g undoes f, both compositions collapse to x. Powers can also commute in special cases, such as f(x) = x squared and g(x) = x cubed, where both orders give x to the sixth.
The calculator detects this and says so in the results note. Equality is the exception that proves the rule, and when it happens it is usually a clue that the two functions have a deeper relationship worth investigating.
Frequently Asked Questions
1. What does (f ∘ g)(x) mean?
It means f of g of x. Apply the inner function g to x first, then apply the outer function f to that result. The calculator expands this into a single polynomial so you can see the combined function directly.
2. Is (f ∘ g)(x) the same as (g ∘ f)(x)?
Usually not. The order decides which function acts first, and different orders give different results, as every worked example on this page shows. Equality happens only for special pairs such as inverse functions.
3. How do I enter a function like 5x squared minus 2?
Type 5 in the x squared box, 0 in the x box, and negative 2 in the constant box. Each function is defined by its three coefficients, so any polynomial of degree two or less can be entered this way.
4. What do the preset pairs do?
Each preset fills all six coefficient boxes with a classic example: linear into linear, linear into quadratic, quadratic into linear, or quadratic into quadratic. They are starting points. You can edit any coefficient after choosing a preset.
5. Why does the result sometimes have degree 4?
Because the degree of a composition is the product of the degrees. Composing two quadratics gives degree 2 times 2 = 4. The calculator handles this automatically and lists all five coefficients, constant term first.
6. What does the coefficients line mean?
It lists the expanded polynomial's coefficients starting with the constant term. For 4x squared + 12x + 10 the line reads [10, 12, 4]. This format matches how many textbooks and computer algebra systems store polynomials.
7. How is the evaluation at x computed?
Two ways that must agree. The calculator plugs your x value into the inner function, feeds that result into the outer function, and also plugs x directly into the expanded polynomial. The step display shows the long way so you can verify the expansion.
8. Can I use decimals or fractions as coefficients?
Yes. Any finite number works, including decimals like 0.5 and negative numbers. The expansion rounds displayed coefficients to four decimal places to keep tiny floating point artifacts out of your view.
9. What happens if I enter all zeros for a function?
The calculator asks you to enter a non-zero function. Composing with the zero function always gives zero, which is mathematically correct but almost never what anyone wants, so the tool treats it as a likely typo.
10. Is composition the same as multiplication of functions?
No. Multiplication forms f(x) times g(x) by multiplying outputs. Composition forms f(g(x)) by chaining. For f(x) = 2x and g(x) = x + 1, the product is 2x squared + 2x while the composition is 2x + 2. They are different operations.
11. Why do the two orders give different evaluations at the same x?
Because they are different functions. In the first worked example, (f ∘ g)(2) = 17 while (g ∘ f)(2) = 27. The inner function runs first in each case, so different innards produce different chains of arithmetic.
12. How do I check my expansion by hand?
Evaluate at x = 1 or x = 2 both ways. Compute inner then outer step by step, and separately plug x into your expanded polynomial. Equal answers mean the expansion is right. Also confirm the degree equals the product of the two input degrees.
13. What is the domain of a composition?
For polynomials, the domain is all real numbers, because polynomials accept any input and produce an output that the next polynomial also accepts. Restrictions only appear with functions like square roots or fractions, which this calculator does not handle.
14. Does the calculator show the intermediate substitution?
Yes. Each composition step begins with the substitution line, such as f(g(x)) = 2(x squared + 1) + 3, before the simplified result. This mirrors how you would work the problem on paper and makes errors easy to spot.
15. Where is composition used outside algebra class?
In calculus through the chain rule, in physics for chained unit conversions, in computer graphics for nested transformations, and in programming for function pipelines. Any multi stage process where one stage's output feeds the next is a composition.