Quarry School

Substitute the whole inside expression

Explain it like I am five

Before filling a form with letters, run the two machines with numbers. Let g multiply by 3 and add 2, and let f square its input and subtract 6. Input 0 goes to 2 and then −2. Input 1 goes to 5 and then 19. Input 2 goes to 8 and then 58. A formula records all these trips at once. Each input letter in the outer rule is a blank on the form. Put the whole inner expression into every blank. Parentheses hold its pieces together until you multiply and combine them. This replacement is substitution. You can run the same rule twice or connect three rules with the same method.

xg: 3x + 23x + 2f: u² − 6(3x + 2)² − 6firstsecond
The whole inner expression fills the outer input place.
Reminder
  • Distribution. 2(x − 4) = 2x − 8, because the factor multiplies both terms.
  • Expanding a square. (x + 1)2 = x2 + x + x + 1 = x2 + 2x + 1.
  • Subtracting a package. −(x + 2) = −x − 2.
  • Like terms. 2x + 2x = 4x, while x2 and x are different kinds of terms.
  • Nonzero denominator. 2x − 1 ≠ 0 means x ≠ 12.
  • Composition order. f(g(x)) replaces the input slots in f with g(x), not the other way around.
  • Multiplying powers. x × x2 = x × (x × x) = x3. The exponent counts three multiplied copies of x.
input xoutput f(g(x))0−2119258
The formula 9x2 + 12x − 2 reproduces every output in this row: it writes the two-machine trip once for any starting input.
Why it works. A formula describes what to do to its input, regardless of whether the input is a number or an expression. If f squares its input, then f(g(x)) must square all of g(x). Squaring a sum multiplies the sum by itself, creating middle terms as well as squares. Those terms come from distributing each part across the other package. Parentheses preserve the intended input until this multiplication is finished, so they prevent lost signs and missing terms.
RuleTo form f(g(x)), replace every input-variable occurrence in f with the whole parenthesized expression g(x).
(a + b)2 = a2 + 2ab + b2, because (a + b)(a + b) has two cross products ab.
The same idea, five ways
Say it

f of g of x; replace every outer input with the whole inner expression

Write it

The outer formula acts on the entire expression produced by the inner formula.

In math
  • f(g(x)) = (3x + 2)2 − 6
  • (f ∘ g)(x) = 9x2 + 12x − 2
  • f(u) = u2 − 6: u is the outer input place
Like

Put the same wrapped package into every blank on a form.

See it
xg: 3x + 23x + 2f: u² − 6(3x + 2)² − 6firstsecond
The whole inner expression fills the outer input place.
The same idea, other ways
As filling boxes

The outer formula x2 − x has two boxes. If the inner output is x + 2, fill both boxes with that package: (x + 2)2 − (x + 2).

f(input) = (input)2 − (input)
Input = x + 2
f(g(x)) = (x + 2)2 − (x + 2)
Both slots receive the same complete expression.
As a wrapped package

Parentheses are the wrapper. A square outside the wrapper applies to every part of the input. A minus outside the wrapper subtracts every part.

Square the package: (x + 2)2
Subtract the package: −(x + 2)
The outside operation acts on the whole package.
As a multiplication rectangle

Squaring 3x + 2 places that same group along both rectangle sides. Four products fill it: 9x2, 6x, 6x, and 4. Both middle rectangles contribute, so their total is 12x.

9x²6x3x6x423x2
Every rectangle contributes to the expanded square.
With a number check

At x = 1, the inner expression 3x + 2 gives 5, whose square is 25. The expansion gives 9 + 12 + 4 = 25. Dropping the middle term gives 13, so this test catches that mistake.

13x + 25square25firstsecond
The small-number route checks that the complete group was squared.
.1A linear outside formula

If the outer function multiplies its input by a number, that number multiplies the whole inner expression. Put in the package first, then distribute.

  • For f(x) = 3x and g(x) = x − 4, f(g(x)) = 3(x − 4).
3x−123x−4
This is a multiplication bookkeeping grid. The −4 label is a signed term, rather than a physical side length; multiplying labels still gives 3x and −12. Negative labels are bookkeeping amounts, not physical side lengths.
Worked exampleTriple the whole inside

Let f(x) = 3x and g(x) = x − 4. Find f(g(x)). You want to triple the entire g output. Plan: wrap the inner expression in parentheses in every outer input place, then distribute and collect matching terms.

5g: subtract 41f: triple3firstsecond
The direct two-stage result matches the formula.
  1. f(g(x)) = f(x − 4) = 3(x − 4).The outer input slot receives x − 4.
  2. = 3x − 12.3 multiplies x and −4.
Answer
f(g(x)) = 3x − 12, for every real x.
Check At x = 5, g(5) = 1 and f(1) = 3; 3(5) − 12 = 3.
Counterexamples: what it is not, and the tempting wrong moves
✗ Not this: 3(x − 4) = 3x − 4.
This triples x while leaving the second part of the same input unchanged.
✓ Instead: 3(x − 4) = 3x − 12.
Tips and tricks
  • Draw one multiplication arrow from the outside factor to each term inside.
.2A square outside formula

A square means multiplying the input by itself. If the input is a sum, both copies of the whole sum must be multiplied. The middle term comes from two cross products.

  • (x + 1)2 = x2 + 2x + 1.
  • A square does not distribute over addition.
x²xxx11x1
The two x products add to the middle term 2x.
Worked exampleA first square composition

Let f(x) = x2 and g(x) = x + 1. Find f(g(x)). You want to square the complete inner output. Plan: wrap the inner expression in parentheses in every outer input place, then distribute and collect matching terms.

x²xxx11x1
All four products belong in the expanded square.
  1. f(g(x)) = (x + 1)2 = (x + 1)(x + 1).Squaring multiplies the whole input by itself.
  2. = x2 + x + x + 1 = x2 + 2x + 1.The four products include two matching middle terms.
Answer
f(g(x)) = x2 + 2x + 1.
Check At x = 2, g(2) = 3 and f(3) = 9; 4 + 4 + 1 = 9.
Counterexamples: what it is not, and the tempting wrong moves
✗ Not this: (x + 1)2 = x2 + 1.
It misses the products x × 1 and 1 × x.
✓ Instead: (x + 1)2 = x2 + 2x + 1.
Tips and tricks
  • Multiply two written copies if the square formula is hard to remember.
.3A fraction outside formula

A fraction's denominator may also contain an input slot. Replace that slot with the complete inner expression. Then check when the new denominator would be zero.

  • For f(x) = 1x−2, f(g(x)) = 1g(x)−2.
  • The original and intermediate restrictions still matter; the next lesson develops both gates.
f(x) = 1x−2
g(x) = 3x + 1
f(g(x)) = 13x−1
Require x ≠ 13
The input slot inside the denominator also gets replaced.
Worked exampleA linear output enters a denominator

Let f(x) = 1x−2 and g(x) = 3x + 1. Find f(g(x)). You want to subtract 2 from the g output, then take the reciprocal. Plan: wrap the inner expression in parentheses in every outer input place, then distribute and collect matching terms.

1g4f1/2firstsecond
The inner output fills the denominator's input slot.
  1. f(g(x)) = 1(3x+1)−2.The whole inner expression replaces x in the denominator.
  2. = 13x−1.The constants 1 − 2 combine to −1.
  3. Find the forbidden starting input by solving 3x − 1 = 0: add 1 to get 3x = 1, then divide by 3 to get x = 13. Check: 3 × 13 − 1 = 0. Exclude that input.This finds and confirms the one start that makes the new denominator zero. The inner linear function itself accepts every real input.
Answer
f(g(x)) = 13x−1, x ≠ 13.
Check At x = 1, g(1) = 4 and f(4) = 12, agreeing with 13−1.
Counterexamples: what it is not, and the tempting wrong moves
✗ Not this: f(g(x)) = 13x+1 − 2.
The −2 belongs inside the denominator of f, so it must stay inside after substitution. At x = 1 the wrong version gives −74 instead of 12.
✓ Instead: f(g(x)) = 1(3x+1)−2 = 13x−1.
Tips and tricks
  • Copy the entire fraction first, then replace its input places.
.4Compose a function with itself

A machine can send its answer back through the same rule. The second trip uses the first answer as its input. In j(j(x)), the two j names mean two separate applications of the same instructions. This operation is different from multiplying the first answer by itself.

  • (j ∘ j)(x) = j(j(x)).
  • j(j(x)) uses the output as a new input; j(x)2 squares the output instead.
1j9j41firstsecond
The second j receives the first j’s output.
Worked exampleThe same formula can receive its own output

Let j(x) = 4x + 5. Find j(j(x)) and its value at x = 1. You run j twice, using a new input the second time. Plan: put the whole first output 4x + 5 into j, distribute 4, and check with two separate number evaluations.

1j: 4x + 59j: 4u + 541firstsecond
The same rule runs twice, but its second input is 9 rather than 1.
  1. j(j(x)) = 4(4x + 5) + 5.The outer copy of j receives 4x + 5 as its whole input.
  2. = 16x + 20 + 5 = 16x + 25.Distribution multiplies both inner terms by 4, then combines the added constants.
  3. At x = 1, j(j(1)) = 16 × 1 + 25 = 41.The composed formula gives the final output for starting input 1.
Answer
  • j(j(x)) = 16x + 25.
  • j(j(1)) = 41.
Check The direct two-stage route gives j(1) = 9 and j(9) = 4 × 9 + 5 = 41, agreeing with the new formula.
Counterexamples: what it is not, and the tempting wrong moves
✗ Not this: j(j(1)) = j(1)2 = 81.
This squares the first output 9 instead of feeding 9 back into j.
✓ Instead: j(1) = 9, then j(9) = 41.
Tips and tricks
  • Know cold: same name means same instructions again, with a new input.
.5Connect three functions

Think of three stations in a kitchen. The first prepares something for the second, and the second prepares something for the third. In p(q(v(x))), v acts first, q second, and p last. Each completed answer replaces the next input. More functions mean more stages, while the inside-first method stays the same.

  • p(q(v(x))) runs v, then q, then p.
  • A chain is defined only when every stage accepts the answer handed to it.
2v: add 35q: square25firstsecond
Continue from 25 into p to obtain 43.
Worked exampleConnect three formulas in order

Let v(x) = x + 3, q(x) = x2, and p(x) = 2x − 7. Find p(q(v(2))) and p(q(v(x))). You run three jobs, starting with the deepest parentheses. Plan: add 3, square the result, then double and subtract 7.

2v: add 35q: square25firstsecond
The first two stages produce 25.
5q: square25p: 2u − 743firstsecond
The same middle q stage is shown again to connect its output 25 to the final rule; q runs once in the full path.
  1. v(2) = 2 + 3 = 5.v touches the starting input, so it acts first.
  2. q(v(2)) = q(5) = 25.The output 5 is now the input to the square.
  3. p(q(v(2))) = p(25) = 2 × 25 − 7 = 43.The final rule receives 25, rather than the original 2.
  4. p(q(v(x))) = 2(x + 3)2 − 7.The inner expression is squared in full and handed to the last rule.
  5. (x + 3)2 = x2 + 3x + 3x + 9 = x2 + 6x + 9.All four products belong to the square.
  6. 2(x2 + 6x + 9) − 7 = 2x2 + 12x + 18 − 7 = 2x2 + 12x + 11.The outside factor multiplies each term, then the constants combine.
Answer
  • p(q(v(2))) = 43.
  • p(q(v(x))) = 2x2 + 12x + 11.
Check At x = 2, the expanded formula gives 2 × 4 + 12 × 2 + 11 = 8 + 24 + 11 = 43, agreeing with the three numerical stages.
Counterexamples: what it is not, and the tempting wrong moves
✗ Not this: p(q(v(2))) means p(2) × q(2) × v(2).
That multiplies three independent outputs at the original input instead of passing each output to the next function.
✓ Instead: The connected path is 2 → 5 → 25 → 43.
Tips and tricks
  • Write one line for every function, starting with the innermost parentheses.
Strategy: step by step
  1. 1. Copy the outer formula and identify every input slot.
  2. 2. Write the complete inner formula in parentheses in every slot.
  3. 3. Keep powers outside those parentheses so they act on the entire input.
  4. 4. Expand with distribution. For a square, multiply the two identical parentheses and keep both cross products.
  5. 5. Combine like terms, preserve any domain restrictions, and check a small allowed input by the two-stage route.
Strategy
Build one formula for a composition
1
Does the outer input occur more than once?
YesPut the complete inner expression, in parentheses, into every occurrence.
NoPut the complete expression in its one input place.
↓
2
Is a whole sum or difference squared?
YesWrite two copies and multiply all four term pairs before collecting terms.
NoApply the indicated operations in their original order.
↓
3
Does either original stage have a denominator or an even root?
YesKeep the original requirements, and check the substituted outer input as the next domain lessons teach.
NoThese arithmetic formulas accept every real starting input unless a restricted domain is supplied. Keep any stated restriction.
  1. 1. Copy the outer formula and identify every input slot.
  2. 2. Write the complete inner formula in parentheses in every slot.
  3. 3. Keep powers outside those parentheses so they act on the entire input.
  4. 4. Expand with distribution. For a square, multiply the two identical parentheses and keep both cross products.
  5. 5. Combine like terms, preserve any domain restrictions, and check a small allowed input by the two-stage route.
Worked exampleA square makes the middle term

Let f(x) = x2 − 6 and g(x) = 3x + 2. Find (f ∘ g)(x) and (g ∘ f)(x). You want one formula for each order. Plan: put the complete inner formula into the outer input place, multiply out any square using four products, and collect matching terms.

9x²6x3x6x423x2
The two middle rectangles contribute 6x each, so the middle term is 12x.
1g: 3x + 25f: u² − 619firstsecond
The input u names the entire number handed to f.
  1. (f ∘ g)(x) = f(3x + 2) = (3x + 2)2 − 6.The outer f squares its whole input before subtracting 6.
  2. (3x + 2)2 = (3x + 2)(3x + 2) = 9x2 + 6x + 6x + 4.Each of the two terms in one copy multiplies each term in the other copy.
  3. (f ∘ g)(x) = 9x2 + 12x + 4 − 6 = 9x2 + 12x − 2.The two middle products add to 12x, and 4 − 6 = −2.
  4. (g ∘ f)(x) = g(x2 − 6) = 3(x2 − 6) + 2.Now g multiplies f’s entire output by 3 and adds 2.
  5. (g ∘ f)(x) = 3x2 − 18 + 2 = 3x2 − 16.The factor 3 multiplies both x2 and −6, then −18 + 2 = −16.
Answer
  • (f ∘ g)(x) = 9x2 + 12x − 2.
  • (g ∘ f)(x) = 3x2 − 16.
  • Both domains are all real numbers.
Check At x = 1, g(1) = 5 and f(5) = 19, matching 9 + 12 − 2 = 19. Reversing gives f(1) = −5 and g(−5) = −13, matching 3 − 16 = −13.
Ladder: from easy to exam-hard. Press Try it first on any rung to hide its steps and use them as hints.
Rung 1Rung 1: a constant inner answer

Let g(x) = 4 and f(x) = x + 1. Find f(g(x)). Whatever input you start with, the first machine returns 4. Plan: wrap the inner expression in parentheses in every outer input place, then distribute and collect matching terms.

any xreturn 44add 15firstsecond
The starting input does not change this inner output.
  1. f(g(x)) = f(4).The inner output is always 4.
  2. f(4) = 4 + 1 = 5.The outer function adds 1 to its input.
Answer
f(g(x)) = 5 for every real x.
Check At x = −7, g(−7) = 4 and f(4) = 5, matching the constant formula.
Rung 2Rung 2: distribute over an inner line

Let f(x) = 2x + 3 and g(x) = x − 4. Find f(g(x)). You want to double the complete inner answer and add 3. Plan: wrap the inner expression in parentheses in every outer input place, then distribute and collect matching terms.

2x−82x−4
The factor 2 multiplies both signed terms. This grid records products; −4 is a signed term, rather than a physical side length. Negative labels are bookkeeping amounts, not physical side lengths.
  1. f(g(x)) = 2(x − 4) + 3.x − 4 replaces the outer input slot.
  2. = 2x − 8 + 3 = 2x − 5.Distribute 2 and then combine the constants.
Answer
2x − 5.
Check At 0, g(0) = −4 and f(−4) = −5, agreeing with 2(0) − 5.
Rung 3Rung 3: fill repeated slots

Let f(x) = x2 − x and g(x) = x + 2. Find f(g(x)). You must use the whole g output twice. Plan: wrap the inner expression in parentheses in every outer input place, then distribute and collect matching terms.

(x + 2)2 − (x + 2)
x2 + 4x + 4 − x − 2
x2 + 3x + 2
Both outer input slots get the same package.
  1. f(g(x)) = (x + 2)2 − (x + 2).Both occurrences of the outer input receive x + 2.
  2. = x2 + 2x + 2x + 4 − x − 2.Multiplying the square produces four terms, and subtracting the last package changes both signs.
  3. = x2 + 3x + 2.4x − x = 3x and 4 − 2 = 2.
Answer
x2 + 3x + 2.
Check At 1, g(1) = 3 and f(3) = 6; 1 + 3 + 2 = 6.
Rung 4Rung 4: a square with a negative term

Let f(x) = x2 + 1 and g(x) = 3x − 2. Find f(g(x)). You want to square the whole difference and then add 1. Plan: wrap the inner expression in parentheses in every outer input place, then distribute and collect matching terms.

9x²−6x3x−6x4−23x−2
The labels record signed products. A real rectangle cannot have side length −2, but distribution still multiplies these labels and includes all four products. Negative labels are bookkeeping amounts, not physical side lengths.
  1. f(g(x)) = (3x − 2)2 + 1.The square acts on all of g's output.
  2. (3x − 2)2 = 9x2 − 6x − 6x + 4.Each cross product contains one negative factor, while (−2)(−2) is positive.
  3. f(g(x)) = 9x2 − 12x + 5.The cross products add to −12x and 4 + 1 = 5.
Answer
9x2 − 12x + 5.
Check At 1, g(1) = 1 and f(1) = 2; 9 − 12 + 5 = 2.
Rung 5Rung 5: slots on both sides of a fraction

Let f(x) = x+1x−1 and g(x) = 2x. Find f(g(x)). You replace the input on both top and bottom. Plan: put 2x into both places, then find the starting input that makes the entire denominator zero.

xg: 2x2xf: (u+1)/u−1(2x + 1)/(2x − 1)firstsecond
Both fraction slots receive the same inner output.
  1. f(g(x)) = 2x+12x−1.Each x slot in f receives the full expression 2x.
  2. Solve 2x − 1 = 0 to locate the forbidden input: 2x = 1, so x = 12. Plug it back in: 2 × 12 − 1 = 0. Exclude 12.The denominator must not be zero. This equation finds the starting input at which that failure would occur; g itself has no restrictions.
Answer
2x+12x−1, with x ≠ 12.
Check At 2, g(2) = 4 and f(4) = 53; the combined formula gives 4+14−1 = 53.
Rung 6Rung 6: the same function twice

Let j(x) = 4x + 5. Find j(j(x)) and its value at x = 1. You run j twice, using a new input the second time. Plan: put the whole first output 4x + 5 into j, distribute 4, and check with two separate number evaluations.

1j: 4x + 59j: 4u + 541firstsecond
The same rule runs twice, but its second input is 9 rather than 1.
  1. j(j(x)) = 4(4x + 5) + 5.The outer copy of j receives 4x + 5 as its whole input.
  2. = 16x + 20 + 5 = 16x + 25.Distribution multiplies both inner terms by 4, then combines the added constants.
  3. At x = 1, j(j(1)) = 16 × 1 + 25 = 41.The composed formula gives the final output for starting input 1.
Answer
  • j(j(x)) = 16x + 25.
  • j(j(1)) = 41.
Check The direct two-stage route gives j(1) = 9 and j(9) = 4 × 9 + 5 = 41, agreeing with the new formula.
Rung 7Rung 7: a three-stage symbolic chain

Let v(x) = x + 3, q(x) = x2, and p(x) = 2x − 7. Find p(q(v(2))) and p(q(v(x))). You run three jobs, starting with the deepest parentheses. Plan: add 3, square the result, then double and subtract 7.

2v: add 35q: square25firstsecond
The first two stages produce 25.
5q: square25p: 2u − 743firstsecond
The same middle q stage is shown again to connect its output 25 to the final rule; q runs once in the full path.
  1. v(2) = 2 + 3 = 5.v touches the starting input, so it acts first.
  2. q(v(2)) = q(5) = 25.The output 5 is now the input to the square.
  3. p(q(v(2))) = p(25) = 2 × 25 − 7 = 43.The final rule receives 25, rather than the original 2.
  4. p(q(v(x))) = 2(x + 3)2 − 7.The inner expression is squared in full and handed to the last rule.
  5. (x + 3)2 = x2 + 3x + 3x + 9 = x2 + 6x + 9.All four products belong to the square.
  6. 2(x2 + 6x + 9) − 7 = 2x2 + 12x + 18 − 7 = 2x2 + 12x + 11.The outside factor multiplies each term, then the constants combine.
Answer
  • p(q(v(2))) = 43.
  • p(q(v(x))) = 2x2 + 12x + 11.
Check At x = 2, the expanded formula gives 2 × 4 + 12 × 2 + 11 = 8 + 24 + 11 = 43, agreeing with the three numerical stages.
Counterexamples: what it is not, and the tempting wrong moves
✗ Not this: f(g(x)) = (3x + 2)2 − 6 = 9x2 − 2.
This discards the two middle products, 6x and 6x. At x = 1 it gives 7 instead of 19.
✓ Instead: f(g(x)) = 9x2 + 12x − 2.
✗ Not this: For f(x) = x2 − x, substituting x + 2 gives (x + 2)2 − x.
The second input slot was never replaced.
✓ Instead: Use (x + 2)2 − (x + 2).
Tips and tricks
  • Know cold: every slot gets the whole package. Circle each input-variable occurrence before replacing it.
  • Understand, then rebuild: the expanded formula. Parentheses and distribution can recreate it; memorizing the numbers in front of its variable terms is unnecessary.
  • Use x = 1 to check for a missing middle term. At x = 0 that term becomes zero and may hide the error.
Trap. Writing (2x + 1)2 = 4x2 + 1. The square multiplies two whole sums, so the two cross products must appear.