Sub topic 10
Checking Your Answer by Substitution and Sanity Tests
This chapter assumes you can rearrange formulas using inverse operations, collect and factor terms, clear fractions, and undo powers and roots. It also assumes basic Python. You now have a rearranged formula. This chapter covers how to decide whether it is right, using checks that take under a minute and catch most mistakes.
Why rearrangements go wrong
Rearranging a formula is a chain of small steps, and each step can hide a slip. The usual ones are:
- A sign error when moving a term across the equals sign.
- Dividing only one term of a sum instead of the whole side.
- Dropping parentheses when a negative or a sum is involved.
- Inverting the wrong thing, such as taking the reciprocal of one term when the whole side needed it.
- Ignoring a restriction, such as a denominator that can be zero.
A wrong result often looks plausible. Checking is how you separate "looks plausible" from "is correct". No single check catches everything, so the habit is to run several cheap ones.
Check 1: substitute numbers into the original formula
The most reliable check goes back to the original formula. Pick values for the known variables, compute the target with your rearranged formula, and plug that value into the original. If the original formula holds, the rearrangement works for those values.
Take simple interest, A = P + P*r*t, where A is the final amount, P the principal, r the yearly rate, and t the time in years. Suppose you want t and write:
t = A - P/(P*r)Test with P = 1000, r = 0.05, t = 2. Then A = 1000 + 1000*0.05*2 = 1100. Your formula gives 1100 - 1000/50 = 1100 - 20 = 1080, not 2. The formula is wrong.
The error was subtracting P and then dividing only the P by P*r. The whole numerator needed dividing. The correct version is:
t = (A - P)/(P*r)The check gives (1100 - 1000)/(1000*0.05) = 100/50 = 2, which matches.
Choose test values with these properties:
- Use values that are not 0 or 1. Zeros and ones make terms vanish, so many errors cancel out.
- Use values that are all different. If
a = c = 2, you cannot tellafromc. - Use values small enough to compute by hand, but not special.
3,5, and7work well.
Check 2: substitute the result back symbolically
You can do the same check with letters instead of numbers. Replace the target variable in the original formula with your answer and simplify. You should get a true statement such as A = A.
For t = (A - P)/(P*r) in A = P + P*r*t:
P + P*r*((A - P)/(P*r))
= P + (A - P)
= AThe P*r factors cancel, and the original formula is recovered. This proves the rearrangement for all values, not just the ones you tried. It also exposes the restriction on P*r: the cancellation needs P*r to be nonzero. The symbolic check costs more effort than a numeric one. Use it when the algebra is short, or when you want certainty.
Check 3: compare units
If the variables carry units, the rearranged formula must produce the right unit for the target. This check needs no numbers and catches structural mistakes.
Take s = u*t + (1/2)*a*t^2, where s is distance in metres, u is starting speed in m/s, t is time in seconds, and a is acceleration in m/s². Solving for a gives:
a = 2*(s - u*t)/t^2The units work out as follows:
u*tis (m/s)·s = m, sos - u*tis metres minus metres, which is valid.- Dividing metres by
t^2(seconds squared) gives m/s², the unit of acceleration.
A common wrong answer divides by t instead of t^2. That gives m/s, which is a speed, so the units reveal the error immediately.
Units also catch illegal operations. In the wrong interest formula above, A - P/(P*r) subtracts 1/r, a number of years, from A, an amount of money. You cannot subtract years from dollars. A unit check flags this before you compute anything.
Check 4: special cases and limiting behaviour
Ask what the formula should do in cases where you already know the answer, then see whether it does.
For a = 2*(s - u*t)/t^2:
- If
s = u*t, the object covered exactly the distance it would at constant speed. The acceleration should be 0, and the formula gives 0. - If
sgrows whileuandtstay fixed, the object travelled further, so it must have accelerated more. The numerator grows, soagrows.
The resistor example from earlier in the tutorial works the same way. From 1/R = 1/R1 + 1/R2 we derived R2 = R*R1/(R1 - R).
- If
R1becomes very large, it carries almost no current. The pair then behaves likeR2alone, soR2should approachR. In the formula,R*R1/(R1 - R)approachesRasR1grows. - If
R1equalsR, the formula divides by zero. That is correct: parallel resistors always give a total smaller than either one, soR1 = Rcan't happen with a finiteR2.
These checks are about direction and size. They don't prove correctness, but they are quick and catch inverted fractions and sign errors.
Check 5: restrictions and sign conditions
A rearranged formula is valid only where each step was valid. Scan your steps for these:
- Division. Every time you divided by an expression, that expression must be nonzero. State it.
- Square roots. If you took a square root, the quantity under it must be at least zero for real answers.
- Even powers. Taking a square root gives two candidates, plus and minus. Test each in the original and keep those that make sense for the problem.
- Squaring both sides. This can create answers that satisfy the squared equation but not the original.
A small example of the last point: y = sqrt(x) rearranges to x = y^2. Try y = -3. Then x = 9, but sqrt(9) = 3, not -3. The rearranged formula is valid only when y >= 0, which the original already requires. If you ignore this, you accept values that never satisfied the original.
For the circle A = pi*r^2, you get r = sqrt(A/pi). This needs A >= 0. We also discard -sqrt(A/pi) because a radius is a length. Both conditions go with the formula.
Letting code do the checking
For formulas you will reuse, write the check once. This script picks random values, computes the target with the rearranged formula, rebuilds the known quantity with the original formula, and compares. It tests the resistor formula:
import math
import random
def second_resistor(r_total, r1):
# From 1/R = 1/R1 + 1/R2, so R2 = R * R1 / (R1 - R)
if r1 == r_total:
raise ValueError("R1 must differ from R; otherwise R2 is undefined")
return r_total * r1 / (r1 - r_total)
def check_second_resistor(trials=1000):
rng = random.Random(1) # fixed seed so the run is repeatable
checked = 0
for _ in range(trials):
r_total = rng.uniform(0.5, 50)
r1 = rng.uniform(0.5, 50)
if r1 <= r_total:
continue # parallel resistors need R1 > R for a positive R2
r2 = second_resistor(r_total, r1)
rebuilt = 1 / (1 / r1 + 1 / r2) # original formula, solved for R
assert math.isclose(rebuilt, r_total, rel_tol=1e-9), (r_total, r1, r2)
checked += 1
return checked
print(check_second_resistor(), "random cases passed")The script prints the number of cases that passed, which is roughly half of the 1000 trials because the rest are skipped by the r1 <= r_total guard. Skipping those cases is itself a restriction check: the code states where the formula applies.
Use math.isclose rather than ==. Floating-point arithmetic rounds, so two equal quantities can differ in the last digits.
Why special values hide bugs
Here is a bug that a poorly chosen test value can hide. For a*x + b = c*x + d, the correct result is x = (d - b)/(a - c). A tempting wrong version has a + c in the denominator.
def correct(a, b, c, d):
return (d - b) / (a - c)
def wrong(a, b, c, d):
return (d - b) / (a + c)
def residual(a, b, c, d, x):
# left side minus right side of a*x + b = c*x + d; zero means x works
return (a * x + b) - (c * x + d)
print(residual(2, 1, 0, 7, wrong(2, 1, 0, 7))) # 0.0 (passes only because c is 0)
print(residual(2, 1, 3, 7, wrong(2, 1, 3, 7))) # about -7.2, so the bug shows
print(residual(2, 1, 3, 7, correct(2, 1, 3, 7))) # 0.0With c = 0, the terms a - c and a + c are the same, so the wrong formula passes. With c = 3, it fails. The residual is a handy tool: it is zero exactly when the candidate satisfies the original equation.
A checking routine
The order is deliberate. Units and special cases need no calculator, so they go first. Numeric substitution is the strongest test, so a formula that passes it earns your trust. The restriction scan then tells you where that trust stops.
What each check catches
| Check | Catches | Can miss |
|---|---|---|
| Numeric substitution | Almost any algebra error, if values are non-trivial | Errors hidden by special values; restrictions |
| Symbolic substitution | Any algebra error, for all values | Errors in the original formula; needs more effort |
| Units | Wrong powers, added quantities with different units, inverted fractions | Wrong numeric constants, sign errors |
| Special cases | Sign errors, inverted ratios, wrong direction of change | Errors that only show at other values |
| Restrictions scan | Division by zero, negative roots, extraneous solutions | Algebra mistakes |
Different checks cover different gaps. Units miss a sign error, while numeric substitution catches it. Numeric substitution can miss an unlucky test value, while the symbolic check does not.
Common mistakes when checking
- Checking against your own result instead of the original. If you substitute into your rearranged formula, you test nothing. Always plug into the formula you started with.
- Trusting one test. One passing point can be a coincidence. Try two or three different sets.
- Forgetting that the check applies only inside the restrictions. A formula can pass every numeric test and still fail at
a = c. Test the boundary on purpose. - Reading rounding error as a mistake, or the reverse. Differences around 1e-12 are normal in floating point. Differences like 0.1 are not.
Exercise
A student solves V = (1/3)pir^2h for h and gets h = 3V/pi*r^2 (meaning h = 3V/pi, then times r^2). Use the numbers r = 2, h = 3 to show the answer is wrong, then give the correct formula.
Show answer
With r = 2 and h = 3, V = (1/3)pi43 = 4pi. The student's formula gives 3(4pi)/pi4 = 124 = 48, not 3. The slip is that r^2 must be in the denominator along with pi. The correct formula is h = 3V/(pir^2). Check: 34pi/(pi*4) = 3. The restriction is r != 0.
Exercise
From the formula v = d/t, a student writes t = v/d. Use units alone to explain why this is wrong, then give the correct formula and a restriction.
Show answer
With d in metres and t in seconds, v is in m/s. The student's formula gives (m/s)/m = 1/s, which is not a time. The correct formula is t = d/v, which gives m/(m/s) = s. The restriction is v != 0, since dividing by zero speed is undefined.
Exercise
You solve A = pi*r^2 for r and write r = sqrt(A/pi). A friend tests it with A = -10 and says it works because a calculator gives an answer. What restriction is the friend ignoring, and what happens in real numbers?
Show answer
The formula requires A >= 0, since an area cannot be negative and a real square root needs a non-negative input. For A = -10, sqrt(-10/pi) is not a real number, so the calculator is returning a complex value or an error that has no meaning as a radius.