Sub topic 7
Nested Operations: Work from the Inside Out
Assume you can use order of operations, substitute values into algebraic rules, and evaluate integers, fractions, and exponents. This chapter focuses on expressions in which one operation supplies an input to another operation.
The inside-out rule
A defined operation is a rule with a symbol. Suppose
a ★ b = 2a + b²
The symbol ★ does not have a standard meaning here. Always replace it with the given rule.
For a nested expression such as
(1 ★ 2) ★ 3
the parentheses identify the inner operation. Evaluate that operation first:
- Find 1 ★ 2.
- Use the result as the first input of the outer operation.
- Evaluate the outer operation with 3 as its second input.
First calculate:
1 ★ 2 = 2(1) + 2² = 2 + 4 = 6
Now the expression becomes:
6 ★ 3
Apply the rule again:
6 ★ 3 = 2(6) + 3² = 12 + 9 = 21
Therefore, (1 ★ 2) ★ 3 = 21.
A useful habit is to rewrite each completed inner operation as a number before continuing. This prevents the original expression from becoming difficult to track.
def star(a, b):
return 2 * a + b ** 2
inner = star(1, 2) # 2*1 + 2**2 = 6
result = star(inner, 3) # 2*6 + 3**2 = 21
print(inner, result)Parentheses and argument positions
The expressions (a ★ b) ★ c and a ★ (b ★ c) are different. The first evaluates the left pair first. The second evaluates the right pair first.
Using a ★ b = 2a + b²:
(a ★ b) ★ c
First find a ★ b:
a ★ b = 2a + b²
Then substitute this result for the first input of the outer operation:
(a ★ b) ★ c = 2(2a + b²) + c²
Now evaluate the other grouping:
a ★ (b ★ c)
First find b ★ c:
b ★ c = 2b + c²
Then substitute this result for the second input:
a ★ (b ★ c) = 2a + (2b + c²)²
These expressions are generally not equal. Do not change the grouping unless the definition or the question allows it.
A reliable evaluation routine
Use this process for any nested defined operation:
- Locate the innermost parentheses.
- Identify the inputs in their exact positions.
- Substitute those inputs into the operation's definition.
- Simplify the result completely.
- Replace the inner expression with that result.
- Repeat until no defined-operation symbols remain.
- Check signs, exponents, and argument order.
For example, let
p ⊙ q = p² − 3q
Evaluate:
(−2 ⊙ 4) ⊙ 1
The inner operation is:
−2 ⊙ 4 = (−2)² − 3(4) = 4 − 12 = −8
The expression becomes:
−8 ⊙ 1
Now evaluate:
−8 ⊙ 1 = (−8)² − 3(1) = 64 − 3 = 61
The parentheses around −2 matter. Without them, −2² could be interpreted as −(2²), which equals −4 rather than 4.
Nested functions and composition
The same idea applies to ordinary functions. In f(g(x)), evaluate g(x) first, then put its result into f.
Let:
g(x) = x + 3 f(x) = 2x
Then:
f(g(4)) = f(4 + 3) = f(7) = 2(7) = 14
The notation f(g(x)) is called function composition. The order matters:
g(f(4)) = g(2(4)) = g(8) = 11
Thus f(g(4)) and g(f(4)) have different values.
Exercise
Exercise
If a ★ b = 2a + b², what is (2 ★ 3) ★ 1?
Show answer
First, 2 ★ 3 = 2(2) + 3² = 13. Then 13 ★ 1 = 2(13) + 1² = 27.