Sub topic 9
Composing Functions: f(g(x))
Prerequisites and the Main Idea
Assume you can substitute values into algebraic expressions, follow the order of operations, and evaluate a function such as \(f(x)=2x+1\). You should also be comfortable with parentheses and simple equations.
Function composition means using one function's output as another function's input. In the expression \(f(g(x))\), evaluate \(g(x)\) first. Then use that result as the input to \(f\).
The innermost function acts first:
x \longrightarrow g(x) \longrightarrow f(g(x))The notation \(f(g(x))\) does not mean \(f(x) \cdot g(x)\). It means “\(f\) of \(g(x)\).”
A Step-by-Step Example
Let
f(x)=2x+1and
g(x)=x^2-3.To find \(f(g(4))\), work from the inside out.
- Evaluate the inner function:
g(4)=4^2-3=16-3=13.- Use 13 as the input to \(f\):
f(g(4))=f(13)=2(13)+1=27.Therefore,
f(g(4))=27.You can also substitute the entire expression \(g(x)\) into the rule for \(f\):
f(g(x))=2(x^2-3)+1=2x^2-5.This gives a new function that describes the composition for any allowed value of \(x\).
def f(x):
return 2 * x + 1
def g(x):
return x ** 2 - 3
inner = g(4)
result = f(inner)
print(inner) # 13
print(result) # 27The Order Matters
In general,
f(g(x)) \ne g(f(x)).Using the same functions, compare the two expressions at \(x=4\):
f(g(4))=f(13)=27.But
g(f(4))=g(9)=9^2-3=78.The results differ because the functions are applied in a different order.
This is similar to a made-up two-input operation. If an operation is defined by
a \star b=2a+b^2,then switching the inputs can change the result. Likewise, switching the order of composed functions can change the result.
def g(x):
return x + 3
def h(x):
return 2 * x
print(g(h(4))) # g(8) = 11
print(h(g(4))) # h(7) = 14Reading Composition from a Diagram
The diagram helps prevent a common mistake: reading \(f(g(x))\) from left to right. The function closest to \(x\), which is \(g\), must be evaluated first.
Common Errors and a Checking Routine
Watch for these errors:
- Applying \(f\) before \(g\).
- Treating \(f(g(x))\) as multiplication.
- Dropping parentheses when substituting a negative value.
- Assuming \(f(g(x))\) and \(g(f(x))\) are equal.
- Substituting only part of the inner expression.
For a GRE question, use this routine:
- Identify the inner function.
- Evaluate it completely.
- Substitute its result into the outer function.
- Check parentheses, signs, and exponents.
- If possible, evaluate the reversed composition to see whether order matters.
For example, if \(g(-2)=-5\) and \(f(t)=t^2+4\), then
f(g(-2))=f(-5)=(-5)^2+4=29.The parentheses matter. Writing \(-5^2+4\) would incorrectly treat the value as \(-(5^2)+4\).
Exercise
Let f(x)=3x-2 and g(x)=x/2+5. Find f(g(8)).
Show answer
First, g(8)=8/2+5=9. Then f(9)=3(9)-2=25, so f(g(8))=25.
Exercise
Using f(x)=3x-2 and g(x)=x/2+5, compare f(g(8)) and g(f(8)). Are they equal?
Show answer
f(g(8))=25. Since f(8)=22, g(f(8))=22/2+5=16. They are not equal.