Gradient
Lesson 2.3MathCode~50 min

Algebra: solving for the unknown

Keep both sides balanced and any unknown can be cornered. Rearranging formulas, and where two lines meet.

Module 2 · 0/9 done

The grammar of formulas

Formulas are sentences made of numbers and operations, and like sentences they have grammar. The main rule: some operations go first. Brackets first, then powers, then × and ÷, and finally + and −.

2+3×4=2+12=142 + 3 \times 4 = 2 + 12 = 14
(2+3)×4=5×4=20(2 + 3) \times 4 = 5 \times 4 = 20

In maths, multiplication is often written without a sign at all: 3x3x means 3×x3 \times x, and wx+bwx + b means (w×x)+b(w \times x) + b. A fraction bar is a division, and it acts like brackets around the top and the bottom.

Try itOrder of operations
// Multiplication and division happen before + and − …
console.log(2 + 3 * 4)        // 14, not 20
// … unless brackets say otherwise. Brackets always go first.
console.log((2 + 3) * 4)      // 20
// Powers go before multiplication:
console.log(2 * 3 ** 2)       // 2 × 9 = 18

// A fraction is just a division waiting to happen:
console.log(3 / 4, 1 / 3)
// Percentages are fractions of 100:  15% of 80
console.log(0.15 * 80)

// Formulas in ML are written the same way. Spot the brackets:
const w = 2, x = 3, b = 1
console.log(w * x + b)        // (w·x) + b = 7
console.log(w * (x + b))      // a different formula = 8
Press Run (⌘/Ctrl + Enter) to see output here.