Index Ai Academy
Foundation · Numbers

Multiplying and dividing fractions

A share of a share, dividing by flipping, and why chances in a row get small.

About 35 minutes · Free lesson

What it covers6

Why it matters

Half of a third. Three quarters of the signs, and two thirds of those. A share of a share comes up constantly, and it's a multiplication. In AI it's how chances combine: the chance of several things all happening is their chances multiplied, and it gets small fast. This lesson shows why multiplying fractions is easier than adding them, and what dividing by a fraction really asks.

What you'll be able to do

  • Read "a fraction of a fraction" as a multiplication, and multiply tops and bottoms
  • Divide by a fraction by multiplying by its flip
  • Multiply and divide Fractions in Python, and chain several shares
  • See why chances of things happening one after another multiply and shrink
Quick check
Have a guess before you start. What is half of a third of a trail bar?
  1. 1/6
  2. 1/5
  3. 5/6
  4. 2/3
Show the answer

1/6

Cut the bar into thirds, then cut one third in half: that piece is one sixth of the bar. Half of a third is 1/2 × 1/3 = 1/6.

The math: a share of a share

Purpose. "Of" turns up whenever you take a part of a part: half of a third, three quarters of the signs, two thirds of those. In math, "of" means multiply.

Picture a square trail map. Cut it into 3 columns and shade 2: that's 2/3 of the map. Now cut the same map into 4 rows, and keep 3 of the rows within the shaded columns. The piece that's shaded both ways is 3/4 of 2/3.

Count the small pieces: the map is now cut into 3 × 4 = 12 of them. The doubly shaded part is 2 × 3 = 6 of them. So 3/4 of 2/3 is 6/12, which is 1/2.

Notice what happened: the tops multiplied (2 × 3 = 6) and the bottoms multiplied (3 × 4 = 12). Unlike adding, there's no need to make the pieces the same size first. Cutting both ways makes the pieces for you.

The picture. The flow draws the map as a square, 1 wide and 1 tall. The first cut lights 2/3 of its width. The second keeps 3/4 of its height, and only the piece shaded both ways stays lit: a rectangle 2/3 wide and 3/4 tall. Under the picture, the number cells count its small pieces.

Try it now

The first cut makes 2/3. The second keeps 3 of 4 rows within it. Count the pieces shaded both ways. Then set the first fraction to 1/3 and the second to 1/2, and press Use these numbers: half of a third.

Symbols and formula.

ab×cd=a×cb×d\frac{a}{b} \times \frac{c}{d} = \frac{a \times c}{b \times d}

In plain words: multiply the tops, multiply the bottoms. Then simplify.

Multiplying by less than one shrinks. Half of something is smaller than the thing. So 3/4 × 2/3 is smaller than both 3/4 and 2/3. This surprises people, because with whole numbers multiplying makes things bigger. With fractions under 1, it takes a part, so the answer is smaller.

A shortcut: cancel first. In 2/3 × 3/4, the 3 on top and the 3 on the bottom divide out before you multiply: 2/3 × 3/4 = 2/4 = 1/2. Any top can cancel with any bottom, which keeps the numbers small.

Whole numbers are fractions too. 5 is 5/1, so 5 × 2/3 = 10/3, which is 3 and 1/3.

Quick check
What is 2/5 × 3/4?
  1. 5/9
  2. 6/9
  3. 8/15
  4. 3/10
Show the answer

3/10

Tops: 2 × 3 = 6. Bottoms: 5 × 4 = 20. 6/20 simplifies to 3/10.

Quick check
Is 2/3 × 1/2 bigger or smaller than 2/3?
  1. Smaller: it's half of 2/3
  2. It depends on the order
  3. The same: it's still 2/3
  4. Bigger: multiplying makes things bigger
Show the answer

Smaller: it's half of 2/3

Multiplying by 1/2 takes half: 2/3 × 1/2 = 1/3, smaller than 2/3. Multiplying by anything under 1 shrinks.

Dividing by a fraction. Dividing asks "how many of these fit in that?" How many quarters fit in 3? Each whole holds 4 quarters, so 3 wholes hold 12: 3 ÷ 1/4 = 12. Dividing by 1/4 gave the same answer as multiplying by 4.

That's the rule: to divide by a fraction, multiply by its flip. The flip of 1/4 is 4/1. The flip of 2/3 is 3/2.

ab÷cd=ab×dc\frac{a}{b} \div \frac{c}{d} = \frac{a}{b} \times \frac{d}{c}

In plain words: turn the second fraction upside down, then multiply.

How many eighths fit in three quarters? 3/4 ÷ 1/8 = 3/4 × 8/1 = 24/4 = 6. Check with a picture: three quarters of a bar is six eighths of it.

In your own words
In your own words: why does dividing by 1/4 give the same answer as multiplying by 4?

Write a sentence or two, then compare it with a good answer in the lesson.

In Python: products and quotients that stay exact

Purpose. A chain of shares is easy to slip on by hand. Python checks it exactly.

First the rule written out: multiply the tops, multiply the bottoms.

a = 2
b = 3
c = 3
d = 4
print(f"{a}/{b} x {c}/{d} = {a * c}/{b * d}")
It runs right here in your browser, with nothing to install.

Then with Fraction, which multiplies and divides exactly and simplifies for you:

from fractions import Fraction

print(Fraction(2, 3) * Fraction(3, 4))
print(Fraction(3, 4) / Fraction(1, 8))     # how many eighths in three quarters
print(5 * Fraction(2, 3))                  # a whole number times a fraction

The same calculations in decimals give close, but not always exact, answers: 2/3 is 0.6666…, which a computer can't store completely.

print(2 / 3 * 3 / 4)
print(0.75 / 0.125)
Worked example

Worked example: a chain of shares

Three quarters of the trail club's signs are on the north loop. Two thirds of those are arrows. A fifth of those arrows are faded. What share of all the signs are faded north-loop arrows?

from fractions import Fraction

north = Fraction(3, 4)
arrows_of_north = Fraction(2, 3)
faded_of_those = Fraction(1, 5)
share = north * arrows_of_north * faded_of_those
print(share)
print(float(share))
print(share * 120)       # out of 120 signs
In the lesson you can change this and run it.

Each "of those" multiplies: 3/4 × 2/3 × 1/5. The tops make 6, the bottoms 60, so the share is 6/60, which Fraction shows as 1/10. float(share) turns it into a decimal, 0.1, if you want one. Out of 120 signs, that's 12. Each share in the chain was large, but the product is small: three steps took it from 3/4 down to 1/10.

Code flow. Here is the same chain one share at a time. This time a single variable, share, starts as all the signs, 1/1, and each line takes a share of whatever it holds. Watch it shrink.

Mixed numbers. A fraction with a bigger top than bottom, like 10/3, is more than one whole. People often write it as a mixed number: a whole part and a fraction part, 3 and 1/3. To convert, divide the top by the bottom: the quotient is the whole part and the remainder is the new top. That's // and % again:

print(10 // 3, "and", 10 % 3, "/ 3")    # 10/3 is 3 and 1/3
print(3 * 3 + 1)                        # back again: 3 wholes of 3 thirds, plus 1

Before multiplying or dividing, turn mixed numbers back into one fraction (3 and 1/3 is 10/3). Multiplying the whole parts and the fraction parts separately gives the wrong answer.

Quick check
What does this print?
from fractions import Fraction

print(Fraction(1, 2) * Fraction(4, 5))
print(Fraction(1, 2) / Fraction(1, 4))
  1. 5/7 2
  2. 4/10 2
  3. 2/5 2
  4. 2/5 1/8
Show the answer

2/5 2

1/2 × 4/5 = 4/10, shown simplified as 2/5. 1/2 ÷ 1/4 = 1/2 × 4 = 2: two quarters fit in a half.

Quick check
Which line works out how many eighths fit in three quarters?
  1. Fraction(3, 4) / Fraction(1, 8)
  2. Fraction(1, 8) / Fraction(3, 4)
  3. Fraction(3, 4) * Fraction(1, 8)
  4. Fraction(3, 4) - Fraction(1, 8)
Show the answer

Fraction(3, 4) / Fraction(1, 8)

"How many eighths fit in three quarters" is three quarters divided by an eighth: 6.

Drill

Scale a trail-mix recipe

A trail-mix recipe uses 3/4 of a cup of nuts and 2/3 of a cup of raisins for one batch. Set half_nuts to the nuts for half a batch, batches to how many half-cup scoops fit in the raisins for 3 batches, and nuts_per_raisin to nuts ÷ raisins for one batch. Use Fractions.

from fractions import Fraction

nuts = Fraction(3, 4)
raisins = Fraction(2, 3)
half_nuts = nuts + Fraction(1, 2)
batches = 3 * raisins * Fraction(1, 2)
nuts_per_raisin = raisins / nuts
print(half_nuts, batches, nuts_per_raisin)
In the lesson, your code is checked as you write it.
In your own words
Why does Fraction give an exact answer where decimals sometimes don't?

Write a sentence or two, then compare it with a good answer in the lesson.

In AI and ML: chances in a row multiply

Purpose. A chance is a fraction: how often something happens, out of all the times. When several things must all happen, one after another, their chances multiply, just like shares of shares.

Say the sign reader sees a sign clearly 3/4 of the time, and when it does see it clearly, it reads it right 2/3 of the time. The chance it sees a sign clearly and reads it right is:

P(clear and right)=34×23=12P(\text{clear and right}) = \frac{3}{4} \times \frac{2}{3} = \frac{1}{2}

In plain words: the chance of a chain of things all happening is their chances multiplied.

The picture. Add a step in front: before it can look, the reader has to find the sign in the photo, which it does 9 times in 10. A chance tree draws the three steps from left to right. Each step splits two ways, with its chance on each branch, and the two chances out of a step add to 1. Press Next to follow the path where all three go right.

Here is the path in code, one step at a time:

from fractions import Fraction

found = Fraction(9, 10)
clear = found * Fraction(3, 4)     # found, then seen clearly
right = clear * Fraction(2, 3)     # found, seen clearly, then read right
print(found, clear, right)
print(float(right))

The chance shrinks at every step: 9/10, then 27/40, then 9/20, which is 0.45 as a decimal.

Every step in a chain is a fraction under 1, and multiplying by less than 1 shrinks. So long chains make small chances, even when each step is likely:

from fractions import Fraction

step = Fraction(9, 10)        # each step goes right 9 times in 10
print(step * step)                            # two steps
print(step * step * step * step * step)       # five steps
print(float(step * step * step * step * step))

Five steps that each succeed 90% of the time succeed together only about 59% of the time. That's why a long chain of steps, like an AI agent doing a task in many moves, fails more often than any single step suggests.

Quick check
What does this print?
from fractions import Fraction

sharp = Fraction(3, 4)
arrow_given_sharp = Fraction(2, 3)
print(sharp * arrow_given_sharp)
  1. 17/12
  2. 6/12
  3. 5/7
  4. 1/2
Show the answer

1/2

3/4 × 2/3 = 6/12, shown simplified as 1/2: half of all the signs are sharp arrows.

Quick check
A task has 10 steps, each 95% reliable. What happens to the chance all 10 go right as you add steps?
  1. It keeps shrinking
  2. It stays at 95%
  3. It drops to 0 after 10 steps
  4. It grows toward 100%
Show the answer

It keeps shrinking

Each step multiplies by 19/20, which is under 1, so the chance shrinks with every step: after 10 steps it's about 60%.

In the real tools. In PyTorch, the library most models are built with, a model's chances sit in a tensor, a list of numbers PyTorch works on all at once. Here are the tree's three chances in one tensor, and the chance of the whole path:

Drill

A three-step chance

A second sign reader, still in training, finds the sign in the photo 4/5 of the time, crops it well 5/6 of the time after that, and reads a well-cropped sign right 9/10 of the time. Set all_right to the chance all three steps go right, and fails to the chance something goes wrong (1 minus that).

from fractions import Fraction

find = Fraction(4, 5)
crop = Fraction(5, 6)
read = Fraction(9, 10)
all_right = find + crop + read
fails = all_right - 1
print(all_right, fails)
In the lesson, your code is checked as you write it.
In your own words
Why does a long chain of likely steps end up unlikely?

Write a sentence or two, then compare it with a good answer in the lesson.

Goes deeper in

Practice what you just read

  • 7 code examples you can edit and run
  • a practice exercise that checks your code
  • a 5-question quiz
  • 9 review cards for spaced repetition

Try a quiz question

What is 2/3 of 9?

  1. 6
  2. 27/2
  3. 3
  4. 9 2/3

Answer it at the end of the lesson to see if you're right, and why.

Before this lesson

Keep learning

Where this lesson leads.

575 lessons in thirteen phases. 176 are free without an account, and a free account opens the rest. See every lesson.

Foundation · about 96 hours of study

Foundation math

From whole numbers to the math inside a neural network: each idea by hand, in Python, and in AI 118 lessons All free
  1. Numbers and place value FreeWhat a digit's place is worth, the number line, and Python as a calculator that never tires.36 min
  2. Multiplying and dividing: groups FreeEqual groups, quotient and remainder, and cutting training data into batches.35 min
  3. Order of operations, and names for numbers FreeBrackets, powers, then multiply and divide, then add and subtract; variables hold numbers.36 min
  4. Numbers below zero FreeThe number line through zero, sign rules, distance from zero, and an error's direction and size.37 min
  5. Fractions: equal parts, equal fractions, adding FreePieces of a whole, equal fractions, and re-cutting to add; accuracy as a fraction.45 min
  6. Multiplying and dividing fractions FreeA share of a share, dividing by flipping, and why chances in a row get small.35 min
  7. Decimals and rounding FreeFractions in place value, rounding, and why 0.1 + 0.2 isn't exactly 0.3.36 min
  8. Percentages FreePer hundred, percent change, percentage points, and the accuracy and error rates of models.35 min
  9. Ratios, rates and proportion FreeSharing in a ratio, rates per unit, scaling, and splitting data 80/10/10.35 min
  10. Powers and roots FreeRepeated multiplying, the laws of exponents, square roots, and squared error.43 min
  11. Very big and very small numbers FreePowers of ten, e-notation like 3e-4, orders of magnitude, and a model's size in memory.36 min
  12. Bits, bytes and floats: how numbers are stored FreeBase 2, what n bits can hold, a float as sign, power and digits, and a tensor's memory.35 min
  13. Review: find the slip (numbers) FreeBroken calculations to fix, mixed practice from the whole module, and its formula sheet.34 min
  14. Letters for numbers FreeVariables, terms and like terms, substitution, and a model's formula as a Python function.41 min
  15. Expanding and factoring FreeBrackets as areas, pulling out common factors, and a squared error expanded into a bowl.41 min
  16. Solving equations: keep the balance FreeThe same move on both sides, undoing steps in reverse, and running a model's formula backward.41 min
  17. Rearranging a formula FreeMaking any letter the subject, round-trip checks, and planning a training run.36 min
  18. Inequalities and true-or-false FreeRanges, flipping the sign, if and elif, and the thresholds, clips and ReLU inside a model.42 min
  19. Functions: a rule from input to output Freef(x) notation, tables and graphs, domain and range, loops over lists, and loss as a function.42 min
  20. Chaining and undoing functions Freeg(f(x)), inverses that undo, scaling and unscaling, and a network as a chain.42 min
  21. Straight lines: slope and intercept FreeRise over run, the line through two points, and a model's weight and bias as slope and intercept.42 min
  22. Two equations, two unknowns FreeSubstitution and elimination, where lines cross, and why models are fitted, not solved.42 min
  23. Quadratics: bowls and their lowest point FreeRoots by factoring and by formula, the discriminant, the vertex, and the best weight of a model.42 min
  24. Exponentials: growth and decay FreeThe same factor each step, the number e, and decaying learning rates.43 min
  25. Logarithms: the power question FreeTo what power?, the laws of logs, and adding log-probabilities instead of multiplying.45 min
  26. Sequences and Σ FreeArithmetic and geometric sequences, Σ as a loop that adds, and mean squared error.40 min
  27. Weighted and moving averages FreeWeights that add to 1, a window average, the exponential moving average, and smoothing a loss curve.35 min
  28. Sets, and reading the symbols FreeSets, union and intersection, ℝⁿ and f : ℝⁿ → ℝᵐ, and reading a paper's first equation.41 min
  29. Review: find the slip (algebra) FreeBroken algebra and code to fix, mixed practice from the whole module, and its formula sheet.34 min
  30. Transposing step by step: undo in reverse order FreeA formula's layers, the opposite of each, peeling from the outside in, conditions, and round-trip checks.35 min
  31. Formulas with fractions: clear them first FreeClearing denominators, cross-multiplying, a letter in the bottom, and reciprocal formulas like 1/R = 1/R₁ + 1/R₂.35 min
  32. When the letter appears twice: collect and factor FreeGathering the letter on one side, factoring it out, dividing by the bracket, and rearranging precision and F1.35 min
  33. Squares, roots and powers FreeSquare roots with ±, squaring to undo a root, cube and nth roots, and the √d inside attention.40 min
  34. When the letter is squared and plain: quadratics FreeRearranging into ax² + bx + c = 0, the formula, completing the square, and choosing the root that fits.35 min
  35. Letters in the power: exponentials and logarithms FreeTaking logs to bring a power down, exponentiating to free a letter, and the logit that undoes the sigmoid.40 min
  36. Rearranging inequalities: when the sign flips FreeThe four moves on an inequality, negatives and reciprocals that flip it, logs below 1, and sample sizes.35 min
  37. Inverse functions, lines and scaling FreeUndoing a function by making x the subject, domains that allow it, line forms, and unscaling predictions.40 min
  38. Sequences and sums: find n, a, d and r FreeEvery letter of the arithmetic and geometric formulas as the subject, and an average's window from its decay.40 min
  39. Combining formulas: substitute and eliminate FreePutting one formula inside another to remove a letter, and sizing a training run from a time or money budget.35 min
  40. Review: rearrange anything (algebra) FreeBroken rearrangements to fix, mixed practice from the whole algebra block, a strategy chart, and its formula sheet.35 min
  41. Coordinates and distance FreePoints as (x, y), Pythagoras, distance in any number of coordinates, and nearest neighbors.42 min
  42. Angles, degrees and radians FreeMeasuring a turn, converting units, arcs, and the angle between two arrows.36 min
  43. Sine and cosine FreeAcross and up: right triangles, the unit circle, and directions and rotations.42 min
  44. Waves: height, speed and shift FreeAmplitude, period and phase, sampling a wave, and position codes in transformers.37 min
  45. Review: find the slip (shapes and waves) FreeBroken geometry and code to fix, mixed practice from the module, and its formula sheet.29 min
  46. Angles, triangles and waves: rearranging with sin, cos and tan FreeSides and angles from SOH CAH TOA, principal values, arcs, polar coordinates, and a wave's time and period.45 min
  47. Vectors: lists of numbers that point FreeA list, a point and an arrow; components, dimension, NumPy arrays, and data as vectors.42 min
  48. Adding and scaling vectors FreeComponent-wise sums, scalar multiples, mixes, and the weight update w − ηg.43 min
  49. Length and distance: norms FreeL2, L1 and max norms, unit vectors, distance, and the norms inside losses and clipping.42 min
  50. The dot product FreeMultiply in pairs and add; a·a as squared length; a @ b; one neuron as a dot product.43 min
  51. Angle, cosine similarity and projection FreeDirection without length, perpendicular vectors, shadows, and search by meaning.45 min
  52. Perpendicular directions: bases and coordinates FreeOrthonormal directions, coordinates as dot products, rebuilding a vector, and taking a direction out.35 min
  53. Matrices: tables of numbers FreeRows, columns and entries; two-dimensional arrays and slices; a data set as a matrix.41 min
  54. Adding, scaling and transposing matrices FreeEntry-by-entry sums and scalings, the transpose, mean images, and tables turned around.36 min
  55. A matrix times a vector FreeEach row dotted with the vector, the size rule, A @ x, and a layer acting on one example.42 min
  56. Matrix multiplication FreeRow meets column, the size rule, order matters, and a batch through a layer: X W + b.45 min
  57. Identity, diagonal, triangular and symmetric FreeFour patterns and their jobs: rescaling, distance tables, and the causal mask.37 min
  58. Matrices as movements of space FreeStretches, flips, shears and rotations; columns as landing spots; chaining; a layer moving data.42 min
  59. Determinant and inverse FreeThe area factor ad − bc, singular matrices, undoing a matrix, and redundant features.42 min
  60. Solving systems by elimination FreeAugmented matrices, row moves, back-substitution, the three outcomes, and fitting weights.45 min
  61. Independence, span and rank FreeRedundant vectors, span, rank, outer products, and low-rank updates like LoRA.42 min
  62. Eigenvectors: directions that only stretch FreeAv = λv, checking candidates, np.linalg.eig, and the main direction of a data cloud.41 min
  63. SVD and PCA: the important directions first FreeA matrix as pieces by size, the best rank-k copy, compression, and PCA maps of data.45 min
  64. Tensors, shapes and broadcasting FreeAxes and shapes, reshape, axis=, broadcasting, and shapes through a small model.43 min
  65. One-hot vectors and lookup tables: embeddings FreeA one-hot row picks a table's row, a sentence looked up as vectors, and a score for every word.35 min
  66. Sliding dot products: convolution FreeA small pattern slid along a list and over a grid, output sizes, stride and padding, and shared weights.40 min
  67. Review: find the slip (vectors and matrices) FreeShape slips to fix, mixed practice from the module, and its formula sheet with shapes.36 min
  68. Vector equations: rearranging with arrows FreeSolving for a vector or a scale, recovering a gradient from two weight snapshots, and an angle from a dot product.40 min
  69. Matrix equations: multiply by the inverse, on the correct side FreeNo dividing by a matrix: inverses from the left or right, order, transposes, and the normal equations.40 min
  70. Rates of change FreeChange over change, secants, rates from readings with np.diff, and reading a loss curve.41 min
  71. Limits: what a value heads toward FreeApproaching from both sides, holes, corners and jumps, epsilon, and judging activations.37 min
  72. The derivative: slope at a point FreeShrinking secants, f′(x) and dy/dx, Δy ≈ f′Δx, and which way a weight should move.45 min
  73. Derivative rules FreeConstants, powers, multiples, sums, eˣ and ln x, checked numerically, and a squared error's slope.41 min
  74. The product rule and the chain rule FreeProducts and chains of functions, forward then backward, and one neuron's dL/dw.45 min
  75. Lowest points and curvature Freef′ = 0, the second-derivative test, tables, local and global minima, and convex losses.43 min
  76. Standing in for a curve near a point FreeTangent lines, a curvature term, growing error, and why learning rates must be small.37 min
  77. Partial derivatives FreeOne input at a time, ∂, nudging in Python, and the two slopes of a line's loss.41 min
  78. The gradient FreeAll the slopes as a vector, steepest climb and descent, a numerical gradient, and the loss gradient.42 min
  79. Gradient descent FreeStepping against the gradient, the learning rate, a training loop, and fitting a line.45 min
  80. Faster descent: momentum and Adam FreeMomentum and Adam by hand, the bias correction, and three optimizers down one narrow valley.40 min
  81. The chain rule with many paths: backpropagation by hand FreeGraphs, multiply along paths and add across them, gradient checks, and a 2-2-1 network by hand.45 min
  82. Automatic differentiation: how PyTorch finds every slope FreeA tape of steps walked backward, and requires_grad, backward(), .grad, zero_grad() and no_grad().40 min
  83. Jacobians and Hessians FreeSlopes of vector functions, a layer's Jacobian, second partials, and bowls, domes and saddles.42 min
  84. Integrals: adding up thin slices FreeStrip and trapezoid sums, summing undoes differencing, probability as area, and AUC.43 min
  85. Review: find the slip (calculus) FreeCalculus slips to fix, mixed practice from the module, and its formula sheet.36 min
  86. Rearranging in calculus: slopes, steps and constants FreeSetting a slope to zero, Newton's step, the chain rule turned around, constants from a point, and learning rates.45 min
  87. Counting: choices, orders and groups FreeThe counting principle, factorials, ordered picks and groups, and why attention's cost grows with the square of the length.43 min
  88. Probability: from counts to chances FreeEqually likely outcomes, the complement, distributions, seeded simulation, and a next-word model.43 min
  89. Combining events: and, or, independent FreeThe or rule, independence, probability trees, drawing with and without replacement, and chains of steps.42 min
  90. Conditional probability and Bayes' rule FreeConditionals from tables, why P(A | B) isn't P(B | A), Bayes' rule, and precision and recall.45 min
  91. Random variables and distributions FreeUncertain numbers, the probability of a range, sampling by slices, and sampling versus argmax.42 min
  92. Expected value, variance and standard deviation FreeProbability-weighted averages, spread in the data's own units, and a training loss as an expected value.42 min
  93. Bernoulli, binomial, uniform and normal FreeYes-or-no trials, counts of yeses, the 68-95-99.7 rule, z-scores, and an accuracy's error bar.45 min
  94. Two variables at once: covariance and correlation FreeJoint tables and marginals, covariance, correlation, the covariance matrix, and features that carry the same information.45 min
  95. Review: find the slip (probability) FreeProbability slips to fix, mixed practice from the module, and its formula sheet.36 min
  96. Probability formulas: solve for the missing chance FreeConditionals, Bayes' rule for the prior, the or rule, expected values, variance, and z-scores turned around.45 min
  97. Describing data: center, spread and scale FreeMean, median and mode, variance and standard deviation, percentiles, outliers, and standardizing features.42 min
  98. Samples, the law of large numbers and the central limit theorem FreeSamples and populations, the standard error σ/√n, the bell of averages, and error bars on test scores.43 min
  99. Is the difference real? Comparing two models FreePaired differences, a bootstrap interval, what a p-value is and isn't, and why many tries make lucky wins.40 min
  100. Maximum likelihood FreeLikelihoods as products, log-likelihoods as sums, grid search, underflow, and the negative log-likelihood loss.45 min
  101. Linear regression: the best line FreeResiduals, least squares by formula, three roads to one line, the matrix form, and train versus test error.45 min
  102. Logistic regression: a line that answers yes or no FreeThe sigmoid, the log loss, its slope p − y, a training loop, and choosing a threshold.45 min
  103. Scoring a classifier: confusion table, precision, recall, F1 FreeThe four cells, accuracy, precision, recall and F1, and what moving a threshold does to each.35 min
  104. Softmax: scores into probabilities FreeExponentiate and share out, shifting and temperature, the safe softmax, and a classifier's last step.43 min
  105. Surprise, entropy and cross-entropy FreeSurprise in bits, entropy, cross-entropy and KL divergence, perplexity, and a language model's loss.45 min
  106. KL divergence: how far one distribution is from another FreeKL by hand, cross-entropy as entropy plus KL, why it isn't symmetric, and a soft-target loss.35 min
  107. Review: find the slip (statistics and information) FreeStatistics slips to fix, mixed practice from the module, and its formula sheet.38 min
  108. Statistics and information: n, z, logits and bits FreeSample sizes from error bars, inputs from probabilities, logit gaps from softmax, and chances from bits and losses.40 min
  109. One neuron, start to finish FreeWeighted sum, activation, loss, slopes and update, by hand and in code, and what one straight line can and can't split.45 min
  110. A layer and a small network as matrices FreeTwo layers on a batch, the shape of every matrix, adding a hidden unit, and XOR solved.45 min
  111. Training a small network FreeThe backward pass in matrix form, gradient checks, a full training loop, and reading loss curves.45 min
  112. The same network in PyTorch Freenn.Sequential with the NumPy weights loaded, the same loss and slopes, then SGD and mini-batches.45 min
  113. Attention as matrix math FreeScaled dot-product scores, the causal mask, a row-by-row softmax, and blending value vectors.45 min
  114. Residual connections and layer norm FreeAdding the input back and why its slope keeps learning alive, layer norm by hand, and add and norm.40 min
  115. A transformer block, start to finish FreeA sentence through embeddings, attention, add and norm, a small network and next-word scores, every shape named.45 min
  116. Planning a model: rearranging the formulas of a working network FreeLayer widths from parameter counts, sizes from memory and compute, the attention scale, and a training plan.40 min
  117. Final test: transpose any formula FreeSlips to fix from every topic, mixed practice of every kind of rearranging, the strategy chart and the full sheet.45 min
  118. Capstone: a sign reader from the formulas FreeBuild, train and test a trail-sign classifier with NumPy alone, and report its accuracy with an error bar.45 min
Part of a free course 118 lessons

The Foundation Math For Ai & ML: from arithmetic to attention

Learn the math behind AI from arithmetic up: numbers, algebra, vectors and matrices, calculus, probability and statistics, each shown as numbers moving and checked in Python, ending with a network you build and train from the formulas.

Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write