I’m getting stuck on composite functions, especially the idea that \(f(g(x))\) and \(g(f(x))\) can give totally different answers. I understand the basic phrase “do the inside function first,” but my brain keeps treating it like adding ingredients to a smoothie, where banana then milk feels basically the same as milk then banana. But apparently with functions it’s more like putting socks on before shoes – the order can completely change what makes sense!\n\nFor example, if \(f(x) = 2x + 3\) and \(g(x) = x^2\), I tried finding \(f(g(x))\). My attempt was: \(g(x) = x^2\), so then \(f(g(x)) = f(x^2) = 2x^2 + 3\). I think that part is correct, but I’m not fully confident because I keep wondering if I’m supposed to square the whole \(2x + 3\) somewhere.\n\nThen for \(g(f(x))\), I think it should be \(g(2x + 3) = (2x + 3)^2\). That seems different from \(2x^2 + 3\), which makes sense algebraically, but I’m confused about how to “see” the difference without just memorising the steps. Is \(f(g(x))\) like sending \(x\) through the \(g\)-machine first and then putting that output into the \(f\)-machine?\n\nAlso, when the notation changes to something like \((f \circ g)(x)\), I know it means \(f(g(x))\), but I always hesitate because the \(f\) is written first even though \(g\) happens first. Is there a good way to remember this that doesn’t feel backwards?\n\nCould someone help me understand why my attempt works, and how to avoid mixing up which function goes first? I feel like I’m close, but the notation keeps tripping me up.
Welcome to Maths For Fun – where mathematical curiosity meets pure enjoyment for learners of all ages! Founded by a team of lifelong maths enthusiasts, we believe that numbers aren’t just for tests – they’re for exploration, discovery, and delight. Whether you’re eight or eighty, a beginner or a seasoned problem solver, you’ll find a growing collection of logic based games and puzzles that cover every corner of mathematics.
















5 Responses
You’ve got the right instinct: think of composition as a two-step machine, where the output hose of g plugs into the input funnel of f-so f(g(x)) really is “f after g.” With your functions, f(x)=2x+3 and g(x)=x^2, you did f(g(x)) exactly right: g(x)=x^2 first, then feed that into f’s “slot,” giving f(□)=2□+3 → 2(x^2)+3=2x^2+3. Meanwhile, g(f(x)) means drop f(x)=2x+3 into the squaring slot, so you get (2x+3)^2=4x^2+12x+9-notice the +12x cross-term that wasn’t there before, a visible algebraic “fingerprint” that the order changed. A handy memory trick: write each function with a blank box-f(□)=2□+3 and g(□)=□^2-then literally plug one box into the other; or read (f ∘ g)(x) as “f after g” (right-to-left like a little conveyor belt). Geometrically, g then f means “square, then stretch by 2 and shift up 3,” while f then g means “shift and stretch first, then square,” which bends the graph differently and can even change domains in other examples (try g(x)=1/x and f(x)=x+5 to see how one order may be undefined at different points). For a clean walkthrough with more examples, this Khan Academy page is great: https://www.khanacademy.org/math/algebra2/manipulating-functions/function-composition-alg2/a/intro-to-composition-of-functions. Want to test your function-fu: if h(x)=√x, which compositions f∘h or h∘f are defined for all real x here, and why does the order gatekeep the domain?
You’re thinking about it exactly the right way: a function is a machine with a specific “recipe,” and composing two functions is like sending x through two machines in sequence. The key is that different sequences can do different things, so the order matters a lot.
Let me restate your functions using the “blank box” trick, which makes composition feel more mechanical:
– f(□) = 2·□ + 3 (double, then add 3)
– g(□) = (□)^2 (square)
Now:
– f(g(x)) means “do g first, then f,” so we feed g(x) into f:
f(g(x)) = f(x^2) = 2·(x^2) + 3 = 2x^2 + 3.
– g(f(x)) means “do f first, then g,” so we feed f(x) into g:
g(f(x)) = g(2x + 3) = (2x + 3)^2.
So your computations are spot on. Notice we didn’t square 2x + 3 in f(g(x)) because f is the “double and add 3” machine. The squaring only happens when g is the outer function.
How to “see” the difference without memorizing steps
– View each function as a transformation:
– f: multiply by 2, then shift up by 3
– g: square (which bends the line into a parabola and loses sign information)
– Compare the two sequences:
– f∘g: square first, then scale and shift. That gives y = 2x^2 + 3, a parabola opening upward with vertex at (0, 3).
– g∘f: scale and shift first, then square. That gives y = (2x + 3)^2, a parabola opening upward whose vertex occurs where 2x + 3 = 0, i.e., at x = −3/2. After squaring, the graph is y = 4(x + 3/2)^2, which is the standard parabola scaled vertically by 4 and shifted left by 3/2. Intuitively: g∘f “moves x” before it squares, so you get a horizontal shift. (Tiny slip I sometimes make: I catch myself saying “shifted left by 3,” but it’s actually 3/2 here.)
A quick numerical check helps make the difference feel concrete:
– At x = 2:
– f(g(2)) = 2·(2^2) + 3 = 11
– g(f(2)) = (2·2 + 3)^2 = 7^2 = 49
– At x = −1:
– f(g(−1)) = 2·(1) + 3 = 5
– g(f(−1)) = (−2 + 3)^2 = 1
Those are very different outputs from the same input x, purely because of order.
Why the order matters (a structural viewpoint)
Think of the pipeline of domains and outputs:
– For f∘g: x -g→ g(x) -f→ f(g(x))
– For g∘f: x -f→ f(x) -g→ g(f(x))
You can even remember the circle notation this way: f∘g means “f after g.” I like saying it out loud: “Compose f with g” or “apply f to g(x).” Another memory aid is the blank-box substitution: write f(□) = 2□ + 3 and then literally drop □ = g(x). If you make a habit of writing the outer function with a blank first, you’ll almost never mix up the order.
A note on domains
Order also affects which inputs are allowed. For example, let f(x) = √x and g(x) = x − 5.
– f∘g(x) = √(x − 5) is defined only for x ≥ 5.
– g∘f(x) = √x − 5 is defined for x ≥ 0.
Same two functions, different domains after composing, just because the order changed.
Two quick patterns worth remembering
– Composition is generally not commutative: f∘g ≠ g∘f in most cases, as your example shows vividly.
– A special case where they do agree is when f and g are inverses of each other: then f(g(x)) = g(f(x)) = x on the overlapping domain. (There are also other specific pairs that commute, but it’s not typical.)
A helpful external explanation
– Khan Academy’s intro to function composition walks through the substitution viewpoint with several examples:
https://www.khanacademy.org/math/algebra2/manipulating-functions/function-composition/a/intro-to-composition-of-functions
Follow-up thought
Would you like to try one more pair and describe the effect in words first, then compute? For instance, let f(x) = |x| + 1 and g(x) = 3 − x. What are f(g(x)) and g(f(x))? How do their graphs differ near x = 0, and which one has a “corner” shifted horizontally?
You’ve got the right idea: functions aren’t smoothies, they’re more like “do-this-then-that” instructions, and switching the order changes what actually gets done. Think “substitute into the template.” Write f(□) = 2□ + 3 and g(□) = □^2. Then f(g(x)) means drop g(x) into f’s box: f(x^2) = 2x^2 + 3. And g(f(x)) means drop f(x) into g’s box: g(2x + 3) = (2x + 3)^2. To “see” the difference, test a number: with x = 3, g first gives g(3) = 9, then f(9) = 21; the other way, f(3) = 9, then g(9) = 81. Not even close. A quick memory trick: in (f ∘ g)(x), read the circle as “after” – f after g – or just remember the function closest to x happens first. Another dead-simple check is to look at what’s being substituted: if you see f(g(x)), you should literally be replacing every x in f with g(x); if you see g(f(x)), replace every x in g with f(x). One more reason order matters: sometimes only one order is even allowed (like logs and square roots), so the “machine order” can change what’s defined. Your computations are correct: f(g(x)) = 2x^2 + 3 and g(f(x)) = (2x + 3)^2. For a clean walkthrough and more examples, see Khan Academy’s composition of functions: https://www.khanacademy.org/math/algebra/x2f8bb11595b61c86:functions/x2f8bb11595b61c86:composing-functions/a/composition-of-functions
In (f∘g)(x) you apply g then f; with f(x)=2x+3 and g(x)=x^2 we get f(g(x))=2x^2+3 but g(f(x))=(2x+3)^2-different because “square then shift/scale” is not the same as “shift/scale then square,” i.e., composition isn’t commutative (see: https://www.khanacademy.org/math/algebra2/manipulating-functions/composite-functions/a/composite-functions).
Does thinking “right-to-left: output of g becomes input to f” help, or would a quick diagram of the two machines make it click?
You’ve got the right instinct: f(g(x)) really does mean “run x through g first, then put that result into f.” With your functions, f(x) = 2x + 3 and g(x) = x^2, we substitute g(x) into f to get f(g(x)) = f(x^2) = 2x^2 + 3. And if we swap the order, g(f(x)) = g(2x + 3) = (2x + 3)^2. A quick way to “see” they’re different without memorizing is to try a test value: at x = 1, f(g(1)) = 2·1^2 + 3 = 5, but g(f(1)) = (2·1 + 3)^2 = 25. Geometrically, g(x) = x^2 folds the line so negatives become positive and creates a bowl, then f stretches and shifts that bowl upward; but doing f first shifts the input left/right before squaring, which changes where the bowl’s lowest point lands. I used to imagine I was putting an ingredient into a “function blender,” too, and it helped to remember that the name you see on the outside (f) acts last-like the label on the final jar. Tiny aside that’s not crucial here: the domain doesn’t change under composition, so you’re safe to plug in any real x.
For the “which one happens first?” tangle with the circle, a couple of habits saved me. Read (f ∘ g)(x) as “f after g.” Even better: write f(□) = 2□ + 3, then literally drop g(x) into the box-f(g(x)) = 2[g(x)] + 3 = 2x^2 + 3. If you reverse it, write g(□) = (□)^2, then insert f(x) to get (2x + 3)^2. When I was learning this, I kept mumbling the order out loud while drawing a little arrow chain: x → g → f. It felt silly, but the arrows uncluttered my brain. If you want another friendly walkthrough, this Khan Academy page on composition is great: https://www.khanacademy.org/math/algebra/algebra-functions/composite-functions/a/composite-functions. And just to keep expectations sane: people often say composition “never commutes,” but don’t worry about that now-well, except in the easy special case where both functions are linear and you can swap them without changing the outcome.