2.2.8Functions
Composition of functions — f(g(x)), g(f(x))
2,816 words13 min readdifficulty · medium1 backlinks
What IS Function Composition?
Why this definition? We want to capture "do first, then " as a single operation. The notation means "the function you get by chaining then , evaluated at ."

The Mechanics: How to Compute
Step-by-step for :
- Evaluate the inner function: Calculate first
- Substitute into outer function: Use that result as input to :
- Simplify: Combine like terms, expand, factor—whatever makes sense
Why this order? Think of parentheses: in , you must resolve the innermost parentheses before you can apply .
Deriving Properties from First Principles
Property 1: Non-Comutativity
Claim: In general,
Derivation:
- By definition,
- And
- These are only equal if for all :
Why would they differ? Functions transform inputs differently. If doubles and adds3:
Clearly . The order of operations matters, just like if we couldn't distribute.
Property 2: Associativity
Claim:
Derivation:
\text{Left side: } ((h \circ g) \circ f)(x) &= (h \circ g)(f(x)) && \text{by definition of composition} \\ &= h(g(f(x))) && \text{apply } h \circ g \text{ to } f(x) \\ \\ \text{Right side: } (h \circ (g \circ f))(x) &= h((g \circ f)(x)) && \text{by definition} \\ &= h(g(f(x))) && \text{expand } (g \circ f)(x) \end{align}$$ Both give $h(g(f(x)))$, so **composition is associative**. This means you can chain functions without worying about parentheses placement—the final result is "do $f$, then $g$, then $h$." **Why does this work?** Composition is fundamentally about evaluation order, which is fixed by the nesting of function calls. Parentheses in $(h \circ g) \circ f$ don't change which function runs first. ### Property 3: Identity Function **Claim:** $f \circ I = I \circ f = f$, where $I(x) = x$ **Derivation:** $$\begin{align} (f \circ I)(x) &= f(I(x)) = f(x) && \text{since } I(x) = x \\ (I \circ f)(x) &= I(f(x)) = f(x) && \text{since } I \text{ returns its input unchanged} \end{align}$$ The ==identity function== acts like multiplying by 1 or adding 0—it does nothing, so composing with it leaves the other function unchanged. --- ## Worked Examples > [!example] Example 1: Basic Composition > **Given:** $f(x) = x^2 + 1$, $g(x) = 3x - 2$ > **Find:** $(f \circ g)(x)$ and $(g \circ f)(x)$ > **Solution:** > **For $(f \circ g)(x) = f(g(x))$:** > 1. **Inner function first:** $g(x) = 3x - 2$ > *Why this step?* The notation $f(g(x))$ tells us $g$ is the input to $f$. > > 2. **Substitute into $f$:** $f(g(x)) = f(3x-2) = (3x-2)^2 + 1$ > *Why?* Replace every $x$ in $f$'s formula with the expression $3x-2$. > > 3. **Expand:** $(3x-2)^2 + 1 = 9x^2 - 12x + 4 + 1 = 9x^2 - 12x + 5$ > *Why expand?* Simplifies the composite function to standard form. > > $$\boxed{(f \circ g)(x) = 9x^2 - 12x + 5}$$ > > **For $(g \circ f)(x) = g(f(x))$:** > 1. $f(x) = x^2 + 1$ > 2. $g(f(x)) = g(x^2 + 1) = 3(x^2+1) - 2 = 3x^2 + 3 - 2$ > 3. $= 3x^2 + 1$ > $$\boxed{(g \circ f)(x) = 3x^2 + 1}$$ > > **Notice:** $9x^2 - 12x + 5 \neq 3x^2 + 1$, confirming $f \circ g \neq g \circ f$. > [!example] Example 2: Domain Restrictions > **Given:** $f(x) = \sqrt{x}$, $g(x) = x - 4$ > **Find:** Domain of $(f \circ g)(x)$ > > **Solution:**1. **Compute composite:** $(f \circ g)(x) = f(g(x)) = f(x-4) = \sqrt{x-4}$ > *Why this step?* We need the explicit formula to find domain constraints. > > 2. **Domain of $g$:** All real numbers (subtracting 4 works for any $x$) > *Why check this?* We can only compose if $x$ is in $g$'s domain first. > > 3. **Range of $g$ must fit domain of $f$:** > - $f$ requires input $\geq 0$ (can't square root negatives in reals) > - So we need $g(x) \geq 0$, i.e., $x - 4 \geq 0$ > *Why?* The output of $g$ becomes the input of $f$. If $g$ produces $-1$, $f$ is undefined there. > > 4. **Solve:** $x - 4 \geq 0 \implies x \geq 4$ > > $$\boxed{\text{Domain of } (f \circ g) = [4, \infty)}$$ > > **Key insight:** The domain of a composite isn't just the domain of the outer function—you must trace through the entire chain. > [!example] Example 3: Finding Component Functions > **Given:** $h(x) = (2x+1)^3$ > **Find:** Functions $f$ and $g$ such that $h = f \circ g$ > > **Solution:** >Strategy:** Identify the "inner" operation and "outer" operation. > 1. **Inner operation:** The expression $2x+1$ is computed first (like preparing ingredients) > Let $g(x) = 2x + 1$ > *Why?* In $(2x+1)^3$, we must compute the linear part before cubing. > > 2. **Outer operation:** Cubing the result > Let $f(x) = x^3$ > *Why?* Once we have $2x+1$, the next step is raising to the third power. > > 3. **Verify:** $(f \circ g)(x) = f(g(x)) = f(2x+1) = (2x+1)^3= h(x)$ ✓ > >$$\boxed{g(x) = 2x+1, \quad f(x) = x^3}$$ > > **Note:** This decomposition isn't unique! You could also choose $g(x) = x$ and $f(x) = (2x+1)^3$, but the first is more useful because it separates linear and polynomial operations. > [!example] Example 4: Composing Three Functions > **Given:** $f(x) = x+2$, $g(x) = x^2$, $h(x) = 3x$ > **Find:** $(h \circ g \circ f)(5)$ > > **Solution:** > > **Method:** Work from the innermost function outward. > 1. **Apply $f$ first:** $f(5) = 5 + 2 = 7$ > *Why?* In the notation $h \circ g \circ f$, $f$ is rightmost, so it acts on the input first. > > 2. **Apply $g$ to that result:** $g(7) = 7^2 = 49$ > *Why?* $g$ processes the output of $f$. > > 3. **Apply $h$ last:** $h(49) = 3 \cdot 49 = 147$ > *Why?* $h$ is the outermost function, so it acts on the final intermediate result. > > $$\boxed{(h \circ g \circ f)(5) = 147}$$ > > **General formula:** $(h \circ g \circ f)(x) = h(g(f(x))) = h(g(x+2)) = h((x+2)^2) = 3(x+2)^2$ --- ## Common Mistakes (and Why They Feel Right) > [!mistake] Mistake 1: Confusing $f \circ g$ with $g \circ f$ > **Wrong thinking:** "$f \circ g$ means apply $f$ first because$ is written first." > **Why it feels right:** In English we read left-to-right, and $f$ appears before $g$ visually. > > **The truth:** The circle notation $\circ$ reads **right-to-left**. $(f \circ g)(x) = f(g(x))$ means "$g$ first, then $f$"—the rightmost function acts on the input. > > **Steel-man the mistake:** If we wrote composition as an operator like $f * g$ meaning "first do $f$ then $g$," confusion would vanish. But mathematical convention follows function application order: in $f(g(x))$, you evaluate $g(x)$ first (innermost parentheses). > > **How to fix:** Always expand the notation: $f \circ g$ → $f(g(x))$ → "inner function $g$ first." > [!mistake] Mistake 2: Ignoring Domain Restrictions > **Wrong thinking:** "If $f(x) = \sqrt{x}$ and $g(x) = x-5$, then $(f \circ g)(x) = \sqrt{x-5}$ works for all $x \geq 0$." > > **Why it feels right:** We see $\sqrt{\cdots}$ and think "domain is non-negative," forgetting the $-5$ shifts things. > > **The truth:** $(f \circ g)(x)$ requires $g(x) \geq 0$, i.e., $x - 5 \geq 0$, so $x \geq 5$. The domain is $[5, \infty)$, not $[0, \infty)$. > > **Steel-man:** If $g$ were the identity $g(x) = x$, then the domain would be $[0, \infty)$. The mistake treats $g$ as transparent, forgetting it transforms the input first. > > **How to fix:** Always trace: "What does $g$ output? Can $f$ handle that output?" Set up the inequality for the intermediate value. > [!mistake] Mistake 3: Treating Composition Like Multiplication > **Wrong thinking:** "Composition distributes over addition: $(f \circ (g+h))(x) = (f \circ g)(x) + (f \circ h)(x)$." > **Why it feels right:** Multiplication distributes over addition: $a(b+c) = ab + ac$. Composition uses a circle like multiplication uses $\times$. > > **The truth:** Composition does NOT distribute. By definition: > $(f \circ (g+h))(x) = f((g+h)(x)) = f(g(x) + h(x))$$ > This is NOT the same as $f(g(x)) + f(h(x))$ unless $f$ is linear. > **Steel-man:** If $f$ is linear (like $f(x) = 3x$), then $f(g(x) + h(x)) = 3(g(x)+h(x)) = 3g(x) + 3h(x) = f(g(x)) + f(h(x))$, and distribution works. The mistake overgeneralizes from this special case. > > **How to fix:** Remember composition is function **application**, not algebraic multiplication. Verify with a nonlinear example like $f(x) = x^2$. --- ## Active Recall Drills > [!recall]- Feynman Explanation (Explain to a 12-year-old) > Imagine you have two magic boxes. The first box (function $g$) turns whatever number you put in into something else—maybe it doubles it. The second box (function $f$) takes a number and adds 5to it. > > **Function composition** is like putting these boxes in a line. You drop your number into the first box ($g$), catch what comes out, then immediately drop THAT into the second box ($f$). The final answer you get is the "composed" function $f \circ g$. > Here's the trick: **the ORDER matters**! If you double-then-add-5, you get a different answer than if you add-5-then-double. Like baking a cake: adding eggs then mixing isn't the same as mixing then adding eggs. The boxes have to be in the right order, and we read them right-to-left (the rightmost box operates first on your number). > > When we write $f(g(x))$, we're saying "put $x$ into $g first, then put $g$'s answer into $f$." That's all composition is—a fancy assembly line for numbers! > [!mnemonic] Memory Aid > **"Read Right, Act Right"** > - For $f \circ g$, read from the **right**: $g$ acts first > - Think: **"fog** = "f of g" = "f gets g's output" > - Visualize: $x \xrightarrow{g} g(x) \xrightarrow{f} f(g(x))$ (the arrow flow goes left) > > **Domain Mnemonic:** "Can Only Go if Gears Fit" > - The output **g**ears of $g$ must fit the input **g**ears of $f$ > - Range of $g$ ⊆ Domain of $f$ --- ## Connections - [[Functions - definition and notation]: Composition builds on basic function evaluation - [[Domain and range of function]]: Critical for determining when composition is defined - [[Inverse functions]]: $(f \circ f^{-1})(x) = x$ and $(f^{-1} \circ f)(x) = x$ (identity) - [[Bijective functions]]: Only bijections have inverses you can compose back to identity - [[Derivatives - chain rule]]: $\frac{d}{dx}[f(g(x))] = f'(g(x)) \cdot g'(x)$ is the derivative of composition - [[Function transformations]]: Shifting/scaling graphs uses composition: $f(x+2)$ is $f \circ g$ where $g(x)=x+2$ - [[Exponential and logarithmic functions]]: $\log(\exp(x)) = x$ is composition with inverses --- #flashcards/maths What does $(f \circ g)(x)$ mean? :: Apply $g$ first, then apply $f$ to the result: $f(g(x))$. Read right-to-left. Is function composition commutative? Give an example. ::: No. Generally $f \circ g \neq g \circ f$. Example: if $f(x)=2x$ and $g(x)=x+3$, then $f(g(x))=2x+6$ but $g(f(x))=2x+3$. Is function composition associative? :: Yes. $(h \circ g) \circ f = h \circ (g \circ f)$. Both equal $h(g(f(x)))$. What is the identity function property for composition? ::: $f \circ I = I \circ f = f$, where $I(x) = x$. Composing with identity leaves $f$ unchanged. How do you find the domain of $(f \circ g)(x)$? ::: (1) Start with domain of $g$. (2) Ensure $g$'s output values lie in domain of $f$. The domain is all $x$ in domain of $g$ such that $g(x)$ is in domain of $f$. If $f(x) = x^2$ and $g(x) = x+1$, what is $(f \circ g)(x)$? ::: $(f \circ g)(x) = f(g(x)) = f(x+1) = (x+1)^2 = x^2 + 2x + 1$. If $f(x) = \sqrt{x}$ and $g(x) = x-9$, what is the domain of $(f \circ g)(x)$? ::: $(f \circ g)(x) = \sqrt{x-9}$. Need $x-9 \geq 0$, so domain is $[9, \infty)$. Given $h(x) = (3x-2)^5$, decompose into $f \circ g$. ::: Let $g(x) = 3x-2$ (inner) and $f(x) = x^5$ (outer). Then $(f \circ g)(x) = (3x-2)^5 = h(x)$. Why doesn't composition distribute over addition? ::: $f((g+h)(x)) = f(g(x)+h(x))$ is NOT generally equal to $f(g(x)) + f(h(x))$. Function application is not multiplication. Only works if $f$ is linear. For $(h \circ g \circ f)(x)$, which function acts first? ::: $f$ acts first (rightmost), then $g$, then $h$. Evaluate as $h(g(f(x)))$. ## 🖼️ Concept Map ```mermaid flowchart TD C[Function Composition] C -->|models as| A[Assembly Line Idea] C -->|defined as| D["(g∘f)(x) = g(f(x))"] D -->|requires| DR[Range of f in Domain of g] C -->|notation reads| RTL[Right-to-Left Chain] D -->|computed by| M[Inner First, Then Outer] M -->|step 1| S1[Evaluate f(x)] S1 -->|step 2| S2[Substitute into g] D -->|implies| P1[Non-Commutative] P1 -->|shown by| EX["f∘g ≠ g∘f"] D -->|implies| P2[Associative] P2 -->|both give| H["h(g(f(x)))"] ``` ## 🔊 Hinglish (regional understanding) > [!intuition]- Hinglish mein samjho > Function composition ek bahut powerful concept hai jo basically bata hai ki aap do functions ko ek sath kaise jod sakte ho. Jaise agar apke pas do machines hain - ek doubling machine (g) aur ek squaring machine (f) - toh composition ka matlab hai ki pehle aap apna input doubling machinein dalo, phir jo output aye usko squaring machine mein daalo. Is pore process ko hum f(g(x)) ya "f composed with g" bolte hain, aur iska notation hai f∘ g. > > Sabse important chez yad rakhni hai ki ORDER matters!Agar aap pehle square karo phir double karo (g ∘ f), toh result bilkul alag hoga pehle double karke phir square karne se (f ∘ g). For example, agar x=2 hai aur g(x)=2x (doubling) aur f(x)=x² (squaring) hai, toh f(g(2)) = f(4) = 16, lekin g(f(2)) = g(4) = 8. Dekha? Different results! > > Yeh concept har jagah useful hai - real life mein bhi. Jaise temperature conversion: pehle Celsius ko Fahrenheit mein convert karo, phir "feels like" temperature calculate karo. Yeh ek composition hai! Domain ki bhi tension leni padti hai - agar pehli function ka output dosri function ke domain mein nahi hai, toh composition work nahi karega. Aise samajho jaise ek machine square root nikalta hai (f), toh usko negative number mat do (g ka output) kyunki woh handle nahi kar payega. > > Composition samajhna calculus mein bhi zaroori hai kyunki chain rule pure tarike se composition ki derivative nikalta hai. Toh isko ache se practice karo - pehle simple examples se shuru karo jaise linear functions, phir slowly quadratic aur complicated functions ki taraf badho. Main mantra hai: "pehle inner function solve karo, phir us result ko outer function mein daalo." ![[audio/2.2.08-Composition-of-functions-—-f(g(x)),-g(f(x)).mp3]]