17. Functions and custom symbols
Substitute carefully into custom operators. Composite functions resolve inside-out.
Core ideas
- A custom symbol is just a recipe: replace each slot with its input, using parentheses around every substituted expression.
- Composites resolve inside-out: for f(g(x)), compute g first, then feed the result to f.
- f(a + b) is almost never f(a) + f(b); compute, never assume nice behavior.
- If the definition has two slots, order matters: a # b and b # a can differ.
Worked example 1
If f(x) = x^2 - 3x, what is f(f(2))?
Show solution
Inside-out. First f(2) = 2^2 - 3(2) = 4 - 6 = -2. Then f(-2) = (-2)^2 - 3(-2) = 4 + 6 = 10. So f(f(2)) = 10. The common trap is squaring -2 to get -4; parentheses around the substituted value prevent that.
Worked example 2
Define a # b = a*b + a + b. What is 2 # (3 # 1)?
Show solution
Resolve the inner symbol first: 3 # 1 = 3*1 + 3 + 1 = 7. Then 2 # 7 = 2*7 + 2 + 7 = 14 + 9 = 23. So 2 # (3 # 1) = 23. Each application is pure substitution into the recipe, one layer at a time.
Practice set
Question 1
The function h is defined as follows: h(n) = n/2 if n is even, and h(n) = 3n + 1 if n is odd. What is the value of h(h(h(5)))?
Apply the rule three times in a row, checking parity at each step.
h(5) = 3(5) + 1 = 16 since 5 is odd. h(16) = 8 since 16 is even. h(8) = 4. So h(h(h(5))) = 4. Stopping after two applications gives 8, and one application gives 16.
Question 2
If f(x) = 2x + 1 and g(x) = x^2 for all numbers x, what is the value of f(g(3))?
Resolve the inner function first, then feed its output to the outer one.
Work inside out: g(3) = 9, then f(9) = 2(9) + 1 = 19. The trap answer 49 comes from computing g(f(3)) = g(7) = 49, which reverses the order of composition.
Question 3
For all numbers a and b with a not equal to b, the operation ◊ is defined by a ◊ b = (a + b)/(a - b). What is the value of (5 ◊ 3) ◊ 2?
Evaluate the parenthesized operation fully before using its result as the new first input.
First, 5 ◊ 3 = (5 + 3)/(5 - 3) = 8/2 = 4. Then 4 ◊ 2 = (4 + 2)/(4 - 2) = 6/2 = 3. Answer 4 is the trap of stopping after the inner operation.
Question 4
For all numbers a and b, a # b = a^2 - b. What is the value of 5 # 3?
Only the first number gets squared.
5 # 3 = 5^2 - 3 = 25 - 3 = 22. Answer 16 results from computing (5 - 3)^2, and 4 results from 5^2 - 3^2 read as (5 - 3)^2 style errors; the definition squares only a.