Introduction to Algebra
Algebra uses letters to stand for numbers, so that one statement can describe a whole family of calculations and so that an unknown quantity can be found by reasoning instead of guessing. This lesson explains what a variable is, the difference between an expression and an equation, and the basic idea behind solving.
From arithmetic to algebra
Arithmetic answers questions about specific numbers: . Algebra lets you talk about every number at once. Suppose a gym charges a €25 sign-up fee and €18 per month. Instead of a table of prices, one line covers every case:
The letter is a variable: a name for a number that can change, or that we do not know yet. The idea is the same as a variable in code, with one difference. In a program, m = 4 is an instruction: "store 4 in m". In algebra, is a statement: " equals 4", which is either true or false.
Expressions and equations
| Kind | Example | Has an = sign? | What you do with it |
|---|---|---|---|
| Expression | no | evaluate it or simplify it | |
| Equation | yes | solve it: find | |
| Formula | yes | a rule linking several quantities | |
| Inequality | no (, , , ) | find all that make it true |
An expression is like a function body that has not been called. You can evaluate it by putting in a value:
def cost(m):
return 25 + 18 * m
for months in [1, 3, 6, 12]:
print(months, "months:", cost(months), "euros")1 months: 43 euros
3 months: 79 euros
6 months: 133 euros
12 months: 241 euros
Solving: running the rule backwards
The table says 6 months cost €133. But what if the question is "I paid €133; how many months?" That is the equation . You could try values until one fits, which is how the loop below works, but algebra gets there directly:
The key rule: an equation stays true if you do the same thing to both sides (add, subtract, multiply or divide by the same non-zero number). Each step peels one operation off the variable, in reverse order of how it was applied. You first met this in Solving Equations.
# guessing versus solving
target = 133
for m in range(0, 20): # brute force: try every m
if 25 + 18 * m == target:
print("found by search:", m)
break
print("found by algebra:", (target - 25) / 18)
print("paid 150, by algebra:", (150 - 25) / 18)found by search: 6
found by algebra: 6.0
paid 150, by algebra: 6.944444444444445
The last line shows why algebra beats guessing. A search over whole months could never find an answer for €150, because is not a whole number. Algebra gives the answer whether or not it is a "nice" one, and it tells you at once that €150 buys 6 full months with money left over.
Why letters are powerful
- Generality. is true for every pair of numbers. One line states infinitely many facts.
- Unknowns. A letter holds the place of a number you have not found yet, so you can write down what you know about it and then work out its value.
- Relationships. A formula like connects quantities. Knowing any two gives the third.
Tip: Choose letters that remind you of the quantity: for months, for time, for price. In code you would pick meaningful names, and the same habit helps on paper.
In software
Code is written in the language of algebra. A function def f(x): return 3*x + 2 is an expression with a variable. A config value like timeout = base * 2**attempt is a formula. And every time you invert a calculation, such as converting a pixel position back into a data value or a final price back into a pre-tax price, you are solving an equation.
Exercises
Exercise 1: Evaluate
Evaluate for , and .
Answer
5, −7 and −15
Solution
Exercise 2: Expression or equation?
Classify each: (a) , (b) , (c) , (d) .
Answer
(a) expression, (b) equation, (c) formula (an equation linking several variables), (d) inequality.
Solution
An expression has no relation sign. (b) has and one unknown, so it is an equation you can solve (). (c) is an equation relating perimeter, length and width. (d) uses , so it is an inequality, true for every .
Exercise 3: Solve the gym question
With , how many months can you get for €259?
Answer
Solution
Exercise 4: Write the inverse function
Write months_for(cost) that inverts , and print it for 79 and 241.
Answer
3.0 and 12.0
Solution
Solving for gives .
def months_for(cost):
return (cost - 25) / 18
print(months_for(79), months_for(241))3.0 12.0
Test yourself
What is the difference between and ?
- None, they are the same
- The first is an expression, the second is an equation you can solve
- The first is an equation, the second is an expression
- Both are formulas
In algebra, what does the statement mean?
- Store 4 in m
- is a constant forever
- equals 4; the statement is true or false
- is greater than 4
Which step is allowed when solving an equation?
- Add 5 to the left side only
- Divide both sides by 0
- Multiply both sides by the same non-zero number
- Square only the right side