Sub topic 9
Composing Functions: f(g(x))
What you need before this chapter
This chapter assumes you can do the following:
- Evaluate a defined function or made-up operation by substitution, including negative and fractional inputs.
- Apply the order of operations.
- Solve one-variable linear equations and simple quadratics such as x² = 16.
- Expand a squared binomial like (3x + 2)².
Composition is substitution used twice. If a single substitution is solid, this chapter adds one new idea: the output of one rule becomes the input of another.
What composition means
To compose two functions is to feed the output of one into the other. The notation f(g(x)) reads "f of g of x". It tells you to compute g(x) first and then use that result as the input to f.
The function nearest the x goes first, and the evaluation order is the reverse of the left-to-right reading order. That reversal is the most common source of errors on this topic.
Suppose f(x) = x² − 1 and g(x) = 3x + 2. To find f(g(2)):
- Evaluate the inner function: g(2) = 3(2) + 2 = 8.
- Use 8 as the input of the outer function: f(8) = 8² − 1 = 63.
So f(g(2)) = 63.
Other ways the same idea is written
| Notation | Meaning | Evaluate first |
|---|---|---|
| f(g(x)) | f applied to the output of g | g |
| g(f(x)) | g applied to the output of f | f |
| f(f(x)) | f applied twice | the inner f |
| (f∘g)(x) | same as f(g(x)) | g |
The GRE usually writes f(g(x)) directly. If you see the ∘ symbol, read it as "of": (f∘g)(x) is "f of g of x".
Composition in code
A numeric check is the fastest way to confirm that you understand the order. The following program composes two simple functions and shows that the order matters.
def g(x):
return x + 3
def h(x):
return 2 * x
print(g(h(4))) # h(4) = 8, then g(8) = 11, which equals 2x + 3 at x = 4
print(h(g(4))) # g(4) = 7, then h(7) = 14, which equals 2x + 6 at x = 4The two results differ (11 and 14). In general, f(g(x)) and g(f(x)) are different functions. They are equal only for special pairs, so never assume you can swap them.
Building a formula for f(g(x))
Sometimes the question asks for an expression rather than a number. You then substitute the entire inner expression wherever the outer function has its variable.
With f(x) = x² − 1 and g(x) = 3x + 2:
- f(g(x)) = (3x + 2)² − 1 = 9x² + 12x + 4 − 1 = 9x² + 12x + 3
- g(f(x)) = 3(x² − 1) + 2 = 3x² − 3 + 2 = 3x² − 1
Check both formulas at x = 2. The step-by-step route gave f(g(2)) = 63, and the formula gives 9(4) + 12(2) + 3 = 36 + 24 + 3 = 63. For the other order, f(2) = 3 and g(3) = 11, while the formula gives 3(4) − 1 = 11. Both match.
Put parentheses around the inner expression whenever you substitute it. The parentheses are what make (3x + 2)² a squared binomial instead of 3x + 2². Dropping them is the classic composition error.
Composing made-up operations
GRE problems often define a symbol operation and then ask you to compose it with itself or with another rule. Treat a symbol operation as a function with two inputs. Fixing one input turns it into a one-input function you can compose.
Use the operation a★b = 2a + b² and define two one-input functions:
- g(x) = x★3 = 2x + 9
- h(x) = 3★x = 6 + x²
Now compose them:
- g(h(1)): h(1) = 6 + 1 = 7, so g(7) = 14 + 9 = 23.
- h(g(1)): g(1) = 2 + 9 = 11, so h(11) = 6 + 121 = 127.
The results differ, as expected. Argument position also matters inside each function. In g the variable is the first input of ★, and in h it is the second. Swapping those roles changes the rule completely, which is the same issue you met with a★b versus b★a.
Here is a program that builds these functions from the operation and checks the hand results.
def star(a, b):
return 2 * a + b ** 2
def g(x):
return star(x, 3) # x is the first input
def h(x):
return star(3, x) # x is the second input
print(g(h(1))) # h(1) = 7, g(7) = 23
print(h(g(1))) # g(1) = 11, h(11) = 127Composition also shows up in the nested form (1★2)★3 from the previous chapter. The inner pair is evaluated first and becomes an input of the outer operation. The mechanism is the same: a result becomes an input.
Composing a function with itself
The notation f(f(x)) means apply the rule twice. Take f(x) = 2x − 3.
- By formula: f(f(x)) = 2(2x − 3) − 3 = 4x − 6 − 3 = 4x − 9.
- By numbers at x = 5: f(5) = 7, then f(7) = 11. The formula gives 4(5) − 9 = 11.
Be careful not to write f(f(x)) as [f(x)]². Squaring multiplies the output by itself. Composing feeds the output back in. For f(x) = 2x − 3 and x = 5, [f(5)]² = 49, while f(f(5)) = 11.
On the GRE, the numeric route is usually faster than building the formula. If the question gives a specific x, evaluate twice and stop. Build a formula only when the variable stays in the answer or when you must evaluate at many points.
Working backward: solving for an unknown input
Composition can also be an equation. You are given the final output and must find the input.
Let f(x) = 2x − 5 and g(x) = x².
Problem 1. If f(g(x)) = 27, find x.
- Write the composition: f(g(x)) = 2x² − 5.
- Set it equal to 27: 2x² − 5 = 27.
- Solve: 2x² = 32, so x² = 16, so x = 4 or x = −4.
Both values work. Check: g(4) = 16 and f(16) = 27. Also g(−4) = 16 and f(16) = 27. A squaring step erases the sign of the input, so expect two solutions unless the problem restricts x.
Problem 2. If g(f(x)) = 49, find x.
- Write the composition: g(f(x)) = (2x − 5)².
- Set it equal to 49: (2x − 5)² = 49, so 2x − 5 = 7 or 2x − 5 = −7.
- Solve each: x = 6 or x = −1.
Check: f(6) = 7 and g(7) = 49. Also f(−1) = −7 and g(−7) = 49.
Note that the order of composition changed the equation and the answers. When the question asks for "the sum of all possible values of x", the roots are 4 and −4 (sum 0) for the first problem, and 6 and −1 (sum 5) for the second.
A second route is to peel the layers off in reverse. For f(g(x)) = 27, undo f first: f(u) = 27 gives u = 16. Then solve g(x) = 16, which gives x = ±4. This inverse-order method is useful when the inner function is awkward to expand.
def f(x):
return 2 * x - 5
def g(x):
return x ** 2
print([x for x in range(-10, 11) if f(g(x)) == 27]) # [-4, 4]
print([x for x in range(-10, 11) if g(f(x)) == 49]) # [-1, 6]Domain and restrictions
A composition is defined only where every step is defined. The inner output must be a legal input for the outer function.
Let f(x) = √x and g(x) = x − 4.
- f(g(x)) = √(x − 4), which requires x ≥ 4.
- g(f(x)) = √x − 4, which requires x ≥ 0.
At x = 13, f(g(13)) = √9 = 3, and g(f(13)) = √13 − 4, which is about −0.39. At x = 2, f(g(2)) would need √(−2), which is not a real number, so it is undefined on the GRE, even though g(2) = −2 is fine by itself.
The same check applies to division. If f(x) = 1/x and g(x) = x − 3, then f(g(3)) = 1/0 is undefined. Check the inner output before applying the outer rule, and watch for zero denominators and negatives under square roots.
Common errors and how to avoid them
| Error | Example | Fix |
|---|---|---|
| Evaluating the outer function first | Computing f first in f(g(2)) | Start at the innermost parentheses |
| Treating composition as multiplication | Reading f(g(x)) as f(x)·g(x) | Parentheses after f mean "input", not "multiply" |
| Swapping the order | Assuming f(g(x)) = g(f(x)) | Compute both with one number if unsure |
| Dropping parentheses when substituting | 3x + 2² instead of (3x + 2)² | Wrap the inner expression before applying the outer rule |
| Squaring instead of composing | Writing f(f(x)) as [f(x)]² | Feed the output back into f |
| Losing a root | Giving only x = 4 for x² = 16 | Check for sign pairs after any squaring |
| Ignoring domain | Evaluating √(−2) | Verify the inner output is a legal outer input |
A checking routine for composition
Use these steps on any composed expression:
- Mark the innermost function and write its output on its own line.
- Substitute that output, wrapped in parentheses, into the next rule.
- Simplify using the order of operations.
- If you built a formula, test it at one easy value by evaluating step by step, and compare.
- If you solved for x, substitute each answer back through both layers.
- Before finishing, ask whether any intermediate value is illegal for the next function.
Composition questions often appear as quantity comparisons, such as comparing f(g(2)) with g(f(2)). Do not guess from symmetry. Compute both. With f(x) = x² − 1 and g(x) = 3x + 2, the values are 63 and 11, so the first quantity is larger. Different inputs can reverse the comparison, so compute at the value you are given.
Exercises
Exercise
Let f(x) = 3x − 1 and g(x) = x² + 2. Find f(g(2)) and g(f(2)).
Show answer
For f(g(2)): g(2) = 4 + 2 = 6, then f(6) = 18 − 1 = 17. For g(f(2)): f(2) = 6 − 1 = 5, then g(5) = 25 + 2 = 27. So f(g(2)) = 17 and g(f(2)) = 27.
Exercise
Define a★b = 2a + b². Let p(x) = x★1 and q(x) = 2★x. Find p(q(3)).
Show answer
p(x) = 2x + 1 and q(x) = 4 + x². First q(3) = 4 + 9 = 13. Then p(13) = 26 + 1 = 27.
Exercise
Let f(x) = 2x − 5 and g(x) = x². For which values of x does g(f(x)) = 9?
Show answer
g(f(x)) = (2x − 5)² = 9, so 2x − 5 = 3 or 2x − 5 = −3. Then x = 4 or x = 1. Check: f(4) = 3 and g(3) = 9; f(1) = −3 and g(−3) = 9.
Exercise
Let f(x) = √x and g(x) = x − 4. Is f(g(1)) defined as a real number? Is g(f(1)) defined? Give the values if they exist.
Show answer
g(1) = −3, and f(−3) = √(−3) is not a real number, so f(g(1)) is undefined. f(1) = 1 and g(1) = 1 − 4 = −3, so g(f(1)) = −3 is defined.