Sub topic 4
Working backwards through the order of operations
This chapter assumes you can do arithmetic with fractions, negative numbers, and exponents. It also assumes you know the standard order of operations and can solve a simple equation such as 3x + 2 = 11. The previous chapters covered formulas, keeping an equation balanced, and inverse operations. Here you combine those ideas into one method for formulas with several operations stacked on the target variable.
The core idea
A formula builds its result in stages. Starting from the target variable, the order of operations decides which operation happens first, which happens second, and so on. To solve for that variable, you reverse the process. Undo the last operation first and the first operation last.
Take y = 3(x + 2) - 7. To compute y from x:
- Add 2 to x.
- Multiply by 3.
- Subtract 7.
To recover x from y, reverse the list and invert each step:
- Add 7 to y.
- Divide by 3.
- Subtract 2.
The result is x = (y + 7) / 3 - 2.
This works for the same reason you take off your shoes before your socks when you put them on in the opposite order. If y = h(g(f(x))), then x is the inverse of f applied to the inverse of g applied to the inverse of h applied to y. The outermost operation is the last one performed, so its inverse comes first.
Step 1: Read the formula as a sequence
Before you change anything, write down the operations applied to the target variable in the order the formula applies them. Use the order of operations to find that sequence.
- Parentheses are evaluated first, so what is inside them happens before what is outside.
- Exponents and roots come next.
- Multiplication and division come before addition and subtraction.
- A fraction bar groups its whole numerator and its whole denominator. A bar acts like parentheses around each.
Only the operations that touch the target variable belong in your list. Other variables and constants are inputs to those operations. In P = 2L + 2W, solving for W, the term 2L does not involve W. It is simply the number that gets added after W is multiplied by 2.
| Formula | Target | Operations applied to the target, in order |
|---|---|---|
| F = (9/5)C + 32 | C | multiply by 9/5, then add 32 |
| P = 2L + 2W | W | multiply by 2, then add 2L |
| A = P(1 + rt) | t | multiply by r, add 1, multiply by P |
| T = 2π√(L/g) | L | divide by g, take the square root, multiply by 2π |
Step 2: Reverse the list and invert each step
Each inverse operation comes from the pairs you saw earlier: addition and subtraction, multiplication and division, squaring and square root. The new work is the order. Apply the inverses from the bottom of the list to the top.
Here is the temperature formula traced both ways with C = 100:
| Step | Forward (C to F) | Reverse (F to C) |
|---|---|---|
| Start | 100 | 212 |
| 1 | multiply by 9/5 gives 180 | subtract 32 gives 180 |
| 2 | add 32 gives 212 | divide by 9/5 gives 100 |
The values in the two columns mirror each other. After step 1 of the reverse trip you are back at the value the forward trip had after its first step. This mirror property is a useful check while you work.
def f_to_c(f):
# From F = 9/5 * C + 32: subtract 32, then multiply by 5/9
return 5 * (f - 32) / 9
print(f_to_c(212)) # 100.0
print(f_to_c(32)) # 0.0Dividing by 9/5 is the same as multiplying by its reciprocal, 5/9. That is why the code multiplies by 5 and divides by 9.
Step 3: Apply each inverse to the whole other side
Keeping the equation balanced means each inverse operation applies to everything on the other side, not to one piece of it. This is where most errors happen.
Start from y = 3(x + 2) - 7. Add 7 to both sides:
y + 7 = 3(x + 2)
Now divide both sides by 3. The whole left side is divided, so it needs parentheses or a fraction bar:
(y + 7) / 3 = x + 2
Then subtract 2:
x = (y + 7) / 3 - 2
A mechanical model of the method
You can model the method in code. Represent a formula as a list of steps, where each step is an operation with a constant. Inverting the formula means reversing the list and replacing each operation with its opposite.
INVERSE = {"add": "sub", "sub": "add", "mul": "div", "div": "mul"}
APPLY = {
"add": lambda v, k: v + k,
"sub": lambda v, k: v - k,
"mul": lambda v, k: v * k,
"div": lambda v, k: v / k,
}
def run(steps, value):
for op, k in steps:
value = APPLY[op](value, k)
return value
def invert(steps):
return [(INVERSE[op], k) for op, k in reversed(steps)]
# y = 3 * (x + 2) - 7
forward = [("add", 2), ("mul", 3), ("sub", 7)]
backward = invert(forward)
print(backward) # [('add', 7), ('div', 3), ('sub', 2)]
y = run(forward, 5)
print(y) # 14
print(run(backward, y)) # 5.0
# Same inverse steps, but in the wrong (forward) order
wrong = [("sub", 2), ("div", 3), ("add", 7)]
print(run(wrong, y)) # 11.0, not 5The last line shows the failure. The inverse steps are correct but applied in the wrong order, so the answer is wrong. Choosing the right inverse for each step is not enough. The sequence matters.
Worked example: simple interest
The amount owed after simple interest is A = P(1 + rt), where P is the principal, r is the rate, and t is the time. Solve for t.
Operations on t, in order of evaluation:
- Multiply t by r.
- Add 1.
- Multiply by P.
Reverse and invert:
- Divide both sides by P: A/P = 1 + rt
- Subtract 1 from both sides: A/P - 1 = rt
- Divide both sides by r: (A/P - 1) / r = t
So t = (A/P - 1) / r.
You could instead expand P(1 + rt) into P + Prt first. That is also valid, and it gives t = (A - P) / (Pr). The two answers are equal, since A/P - 1 = (A - P)/P. Reversing the order of operations is the method that works for any formula where the target appears once. It is not the only valid route. Shortcuts like expanding first are fine once you can verify them.
Worked example: a pendulum
The period of a pendulum is T = 2π√(L/g), where L is its length and g is gravitational acceleration. Solve for L.
Operations on L: divide by g, take the square root, multiply by 2π.
Reverse and invert:
- Divide both sides by 2π: T/(2π) = √(L/g)
- Square both sides: (T/(2π))² = L/g
- Multiply both sides by g: L = g (T/(2π))²
import math
def period(length, g=9.81):
return 2 * math.pi * math.sqrt(length / g)
def length_from_period(T, g=9.81):
# Reverse of: divide by g, square root, multiply by 2*pi
return g * (T / (2 * math.pi)) ** 2
L = 2.5
T = period(L)
print(round(T, 3)) # 3.172
print(round(length_from_period(T), 6)) # 2.5Squaring is the inverse of taking a square root, but only for non-negative values. Here T and L are physical quantities that cannot be negative, so no sign problem arises. For a formula where the squared quantity could be negative, you need a plus-or-minus choice. A later chapter covers that case.
Common errors
- Undoing in the forward order. Always list the forward steps first, then read the list from the bottom.
- Treating a fraction bar as a stopping point. In (y + 7)/3 - 2, the bar groups y + 7. The subtraction of 2 is a separate, later step.
- Applying an operation to only one term. Every inverse applies to the entire other side.
- Sign slips when subtracting. Subtracting a negative term adds it. If the formula is y = 5 - 2x, the first inverse step is subtracting 5, giving y - 5 = -2x. Then divide by -2, giving x = (5 - y)/2.
- Confusing a step on the target with a step on other variables. In P = 2L + 2W, solving for W, you subtract 2L as a unit. You do not divide 2L by anything yet.
Checking the order
A quick test catches most ordering mistakes. Pick a value for the target, run the formula forward to get a result, then feed that result into your rearranged formula. If you do not get your original value back, the order or an inverse is wrong. Later chapters cover checking in more depth, including units and special cases.
Exercise
The formula for the area of a trapezoid is A = (h/2)(a + b). List the operations applied to b in order, then solve for b.
Show answer
Operations on b: add a, then multiply by h/2. Reverse and invert: divide both sides by h/2 (equivalently, multiply by 2/h) to get 2A/h = a + b, then subtract a. So b = 2A/h - a.
Exercise
Solve y = 4 - 3(x - 1) for x. State the order in which you undo the operations.
Show answer
Operations on x: subtract 1, multiply by -3, add 4. Undo in reverse: subtract 4 gives y - 4 = -3(x - 1); divide by -3 gives (y - 4)/(-3) = x - 1, which is (4 - y)/3 = x - 1; add 1 gives x = (4 - y)/3 + 1. This simplifies to x = (7 - y)/3.
Exercise
A student solves y = 2(x + 5) - 1 for x and writes x = (y + 1)/2 + 5. What went wrong, and what is the correct answer?
Show answer
The student added 5 instead of subtracting it. The first operation on x was adding 5, so its inverse (subtract 5) must come last. The correct answer is x = (y + 1)/2 - 5. Check with x = 1: y = 2(6) - 1 = 11, and (11 + 1)/2 - 5 = 1.