Maths for AI
Topic 2 · Refreshers: school maths you will need

Refresher: Numbers, Powers & Algebra

The school maths every later lesson assumes, explained from scratch: the order of operations, negative numbers, fractions, decimals and percentages, powers and roots, scientific notation, and rearranging an equation to find an unknown.

Show:
In this topic
Beginner

Why start here?

Machine learning maths is built from a small number of school ideas used over and over. If any of them feels shaky, everything after it feels hard, even when the new idea is simple. This lesson rebuilds those foundations quickly, with no assumptions. If you are confident with algebra, skim it and do the practice questions at the end: if you get them right, move on.

Beginner

The order of operations

When a calculation has several steps, everyone has to do them in the same order or we get different answers. The rule (often remembered as BODMAS or PEMDAS):

  1. Brackets first.
  2. Powers (and roots).
  3. Multiplication and division, left to right.
  4. Addition and subtraction, left to right.

So 2+3×4=2+12=142 + 3 \times 4 = 2 + 12 = 14, not 20, and (2+3)×4=20(2 + 3) \times 4 = 20. Also −32=−9-3^2 = -9 (the power happens before the minus), while (−3)2=9(-3)^2 = 9. Python follows exactly the same rules.

Beginner

Negative numbers

Subtracting a negative number adds: 5−(−2)=75 - (-2) = 7. When multiplying or dividing, two negatives make a positive and one negative makes a negative: (−3)×(−4)=12(-3) \times (-4) = 12, (−3)×4=−12(-3) \times 4 = -12. The absolute value ∣x∣|x| is the distance from zero, always positive: ∣−7∣=7|-7| = 7. Errors in ML are often negative (the prediction was too low), and their absolute values or squares are what we average.

Beginner

Fractions, decimals and percentages

They are three ways to write the same thing: 14=0.25=25%\tfrac{1}{4} = 0.25 = 25\%. "Per cent" means "per hundred", so x%x\% is x/100x / 100.

  • To find 15% of 80: 0.15×80=120.15 \times 80 = 12.
  • To increase 80 by 15%: 80×1.15=9280 \times 1.15 = 92. To decrease by 15%: 80×0.85=6880 \times 0.85 = 68.
  • Percentage change from old to new: new−oldold×100%\dfrac{\text{new} - \text{old}}{\text{old}} \times 100\%. From 80 to 92 is 1280=15%\tfrac{12}{80} = 15\%.
  • Fractions multiply straight across: 23×34=612=12\tfrac{2}{3} \times \tfrac{3}{4} = \tfrac{6}{12} = \tfrac{1}{2}. Dividing by a fraction is multiplying by its flip: 12÷14=12×4=2\tfrac{1}{2} \div \tfrac{1}{4} = \tfrac{1}{2} \times 4 = 2.

Model accuracy, error rates and probabilities are all fractions of this kind: an accuracy of 0.92 means 92%.

Beginner

Powers and roots

A power is repeated multiplication: 25=2×2×2×2×2=322^5 = 2 \times 2 \times 2 \times 2 \times 2 = 32. The small raised number is the exponent. The rules follow from that meaning:

RuleExample
am×an=am+na^m \times a^n = a^{m+n}23×22=25=322^3 \times 2^2 = 2^5 = 32
am/an=am−na^m / a^n = a^{m-n}105/102=10310^5 / 10^2 = 10^3
(am)n=amn(a^m)^n = a^{mn}(23)2=26=64(2^3)^2 = 2^6 = 64
a0=1a^0 = 170=17^0 = 1
a−n=1/ana^{-n} = 1/a^n2−3=1/82^{-3} = 1/8
a1/2=aa^{1/2} = \sqrt{a}91/2=39^{1/2} = 3

The square root a\sqrt{a} is the number that, squared, gives aa: 49=7\sqrt{49} = 7. Square roots appear everywhere in ML: in distances, standard deviations, and scaling inside transformers.

Beginner

Scientific notation

Very big and very small numbers are written as a number between 1 and 10 times a power of ten: 3,200,000=3.2×1063{,}200{,}000 = 3.2 \times 10^6 and 0.00045=4.5×10−40.00045 = 4.5 \times 10^{-4}. Python and most software write these as 3.2e6 and 4.5e-4, so a learning rate of 1e-3 means 0.001, and a model with 7e9 parameters has 7 billion.

Beginner

Rearranging equations

An equation says two things are equal. To find an unknown, do the same thing to both sides until the unknown is alone. Undo operations in reverse order:

3x+5=20  ⇒  3x=15  ⇒  x=53x + 5 = 20 \;\Rightarrow\; 3x = 15 \;\Rightarrow\; x = 5

(subtract 5 from both sides, then divide both sides by 3). The same works with letters instead of numbers. The straight line y=mx+by = mx + b rearranged for xx is x=(y−b)/mx = (y - b)/m. Checking your answer by putting it back in is always worth the few seconds: 3×5+5=203 \times 5 + 5 = 20 ✔.

Why this matters for AI

A trained model is an equation with numbers filled in. Reading a formula in a paper, and rearranging it to see what affects what, uses exactly these steps.

Try it

Try it: the order of operations

Pick an expression and step through how it is calculated.

Interactive: this part runs in your browser.

Beginner

Practice: check yourself

Work each question out (on paper, in your head, or in Python), type the answer and press ✔ Check. Fractions like 1/4 are fine. Hints and a worked answer are there when you need them.

Question 1.
What is 18−2×(3+4)18 - 2 \times (3 + 4)?
Question 2.
A model's error fell from 0.40 to 0.30. By what percentage did it fall?
Question 3.
Solve for xx: 5x−7=185x - 7 = 18.
Question 4.
What is 210÷272^{10} \div 2^{7}?
Beginner

Summary

Key words

order of operations
brackets, powers, × ÷, + −
absolute value ∣x∣|x|
distance from zero, never negative
percentage
a fraction out of 100
exponent
the power in ana^n: how many times a is multiplied
square root a\sqrt{a}
the number that squared gives a
scientific notation
4.5×10−44.5 \times 10^{-4}, written 4.5e-4 in code
equation
a statement that two expressions are equal

Common mistakes

  • Adding before multiplying: 2+3×42 + 3 \times 4 is 14.
  • −32-3^2 is −9, not 9: the power comes first.
  • Increasing by 15% with +0.15+0.15 instead of ×1.15\times 1.15.
  • (a+b)2≠a2+b2(a + b)^2 \ne a^2 + b^2: it is a2+2ab+b2a^2 + 2ab + b^2.
  • Doing something to only one side of an equation.
Check yourself

Quiz

1. What is 2+3×42 + 3 \times 4?

2. What is 2−22^{-2}?

3. A price of 200 rises by 10%. What is it now?

4. What does 3e-2 mean?

5. Solve 4x−6=104x - 6 = 10.

Ready