Translating English into Equations
Most real problems arrive as sentences, not symbols. Translating a sentence into an equation means picking a letter for the unknown, turning each phrase into an operation, and writing an equals sign where the sentence says "is". This lesson gives a phrase dictionary and the common traps, especially with subtraction and division.
The phrase dictionary
| English | Operation | Example | Algebra |
|---|---|---|---|
| sum, plus, more than, increased by, total of | 6 more than a number | ||
| difference, minus, less than, decreased by, fewer than | 4 less than a number | ||
| product, times, of, twice, double, triple | twice a number | ||
| quotient, divided by, per, ratio of, half of | a number divided by 5 | ||
| is, equals, gives, results in, will be | ... is 20 | ||
| at least, no less than | at least 18 | ||
| at most, no more than | at most 30 |
The order traps
Two families of phrases reverse the order you read them in.
- "less than" and "subtracted from". "4 less than " is , not . "Subtract 9 from " is . Think of it as: start with , then take 4 away.
- "the difference of and " keeps the order: . "The quotient of and " is .
Tip: Test a translation with a number. "4 less than 10" is 6. Does your expression give 6 when ? does; gives .
Grouping words matter too. "Three times the sum of a number and 2" is : the word "sum" bundles and 2 together before the multiplication. "Three times a number, plus 2" is . The comma changes the meaning, exactly like parentheses in code.
# the same number, four translations
n = 10
print("4 less than n: ", n - 4)
print("4 minus n: ", 4 - n)
print("3 times the sum of n, 2:", 3 * (n + 2))
print("3 times n, plus 2: ", 3 * n + 2)4 less than n: 6
4 minus n: -6
3 times the sum of n, 2: 36
3 times n, plus 2: 32
Sentence to equation, step by step
"Seven more than three times a number is 31."
"A phone costs €45 less than twice the price of a tablet. The phone costs €355."
let t = tablet price
twice the tablet price → 2t
€45 less than that → 2t − 45
the phone costs 355 → 2t − 45 = 355
solve: 2t = 400, t = 200"The average of a number and 14 is 11."
SymPy is handy for checking that a translation gives the answer you expect:
from sympy import symbols, Eq, solve
n, t = symbols("n t")
print(solve(Eq(3*n + 7, 31), n))
print(solve(Eq(2*t - 45, 355), t))
print(solve(Eq((n + 14)/2, 11), n))
print(solve(Eq(5*(n - 3), 2*n), n)) # five times (n minus 3) equals twice n[8]
[200]
[8]
[5]
In software
Translating requirements into expressions is a daily programming task. A ticket says "a discount of 15% applies to orders of at least €50"; you write if total >= 50: total *= 0.85. "Users get 3 free retries, then wait twice as long each time" becomes wait = base * 2**(attempt - 3). Getting "at least" versus "more than" wrong is the classic off-by-one bug: >= and > differ exactly at the boundary.
def price(total):
# "15% off orders of at least 50"
return round(total * 0.85, 2) if total >= 50 else total
for t in [49.99, 50, 80]:
print(t, "->", price(t))49.99 -> 49.99
50 -> 42.5
80 -> 68.0
Exercises
Exercise 1: Phrases
Translate, using for the number: (a) 8 fewer than a number, (b) the quotient of a number and 3, (c) twice the difference of a number and 5, (d) 12 subtracted from half a number.
Answer
(a) , (b) , (c) , (d)
Solution
(a) "fewer than" reverses order: start with , remove 8. (b) quotient keeps order: . (c) "the difference of and 5" is grouped first, then doubled. (d) "subtracted from" reverses order: start with , remove 12.
Exercise 2: Sentence to equation
"Four times a number, decreased by 9, equals 27." Write the equation and solve it.
Answer
,
Solution
Exercise 3: Grouping matters
"Six times the sum of a number and 4 is 54." Solve it. Then solve "six times a number, plus 4, is 54" and compare.
Answer
gives . gives .
Solution
from sympy import symbols, Eq, solve
n = symbols("n")
print(solve(Eq(6*(n + 4), 54), n), solve(Eq(6*n + 4, 54), n))[5] [25/3]
Exercise 4: A requirement in code
"Shipping is free for orders over €40; otherwise it costs €4.90." Write shipping(total) and print it for 40 and 40.01. Which word decides the boundary?
Answer
4.9 for €40 and 0 for €40.01. "over" means strictly greater, so the test is total > 40.
Solution
def shipping(total):
return 0 if total > 40 else 4.9
print(shipping(40), shipping(40.01))4.9 0
Test yourself
Which expression means '5 less than a number '?
Translate: 'Twice the sum of a number and 3 is 20.'
'Players must be at least 13' translates to: