Index Ai Academy
Foundation · Transposition of formulas

Angles, triangles and waves: rearranging with sin, cos and tan

Sides and angles from SOH CAH TOA, principal values, arcs, polar coordinates, and a wave's time and period.

About 45 minutes · Free lesson

What it covers6

Why it matters

In trigonometry, the math of angles in triangles, circles and waves, the letter you want often sits inside a sine, a cosine or a tangent. Transposing the formula to free it needs their opposites: arcsin, arccos and arctan. They come with a catch. Many angles share the same sine, so the way back can give only one of them, the principal angle. This lesson turns the shapes module's formulas around for each of their letters, then runs a transformer's angles and a photo's tilt backward.

What you'll be able to do

  • Rearrange sin θ = o/h, cos θ = a/h and tan θ = o/a for any letter, using arcsin, arccos and arctan for the angle
  • Say which angle inverse trig gives back, the principal value, and find the other angles that share a sine or a cosine
  • Turn arc length, sector area, degrees and radians, and the distance formula around, keeping the ± and the conditions
  • Get a point's distance and angle from (x, y) with math.atan2, and say why math.atan fails on the left half
  • Find when a wave reaches a height, and its period, and run position codes, rotary angles and a photo's tilt backward
Quick check
Have a guess before you start. A ramp is 2 m long along its slope and rises 1 m. What angle does it make with the ground?
  1. 30°
  2. 26.6°
  3. 0.5°
  4. 60°
Show the answer

30°

The rise is the side opposite the angle, and the ramp is the hypotenuse, so sin θ = 1/2. The angle whose sine is 1/2 is 30°. Getting an angle back from a sine is the first thing this lesson does.

The math: undo sin, cos and tan

Purpose. Free a side or an angle from sin, cos or tan, and know which angle comes back.

In a right triangle, name the sides from one sharp angle θ: the opposite side o, the adjacent side a, and the hypotenuse h, the longest. lesson 43 gave two ratios. The third, the tangent, is rise over run:

sin⁡θ=ohcos⁡θ=ahtan⁡θ=oa\sin\theta = \frac{o}{h} \qquad \cos\theta = \frac{a}{h} \qquad \tan\theta = \frac{o}{a}

People remember them as SOH CAH TOA: Sine is Opposite over Hypotenuse, Cosine is Adjacent over Hypotenuse, and Tangent is Opposite over Adjacent. Each has an opposite that turns a ratio back into an angle:

Done to the angleUndone byIn Python
sinarcsin, also written sin⁻¹math.asin
cosarccos, or cos⁻¹math.acos
tanarctan, or tan⁻¹math.atan

As in lesson 20, the ⁻¹ means "undo", not "one over".

Quick check
From an earlier lesson: in a 5-12-13 right triangle, what is cos θ for the angle across from the side of 5?
  1. 5/13
  2. 12/13
  3. 13/12
  4. 5/12
Show the answer

12/13

Cosine is adjacent over hypotenuse. The side next to θ is 12 and the hypotenuse is 13, so cos θ = 12/13.

Watch a 10 m ladder leaning at θ = 0.6 radians, about 34°, from the ground. Its top is o = 10 sin θ up the wall: two layers on θ, sin and then × 10. The way back runs ÷ 10, then arcsin.

Try it now

Then set the angle to 2.5, about 143°: past upright, so the ladder leans the other way. Press Use these numbers.

Symbols and formula. Each ratio links three letters, so it rearranges three ways:

sin⁡θ=oh  ⇒  o=hsin⁡θ,h=osin⁡θ,θ=arcsin⁡oh\sin\theta = \frac{o}{h} \;\Rightarrow\; o = h\sin\theta, \qquad h = \frac{o}{\sin\theta}, \qquad \theta = \arcsin\frac{o}{h}

In plain words: to free a side, multiply or divide by the ratio. To free the angle, divide the two sides, then undo the sine.

Cosine and tangent work the same way: a = h cos θ, h = a/cos θ and θ = arccos(a/h); o = a tan θ, a = o/tan θ and θ = arctan(o/a).

Conditions. The hypotenuse is the longest side, so a sine or cosine is never above 1. arcsin and arccos take only numbers from −1 to 1: an o/h of 1.2 means a slip. arctan takes any number. Each returns one angle, its principal value: arcsin from −90° to 90°, arccos from 0° to 180°, and arctan between −90° and 90°.

Quick check
A kite flies 30 m up, and its string makes 40° with the ground. Which gives the string's length h?
  1. h = 30/cos 40°
  2. h = sin 40°/30
  3. h = 30 sin 40°
  4. h = 30/sin 40°
Show the answer

h = 30/sin 40°

The height is opposite the angle and the string is the hypotenuse: sin 40° = 30/h. Multiply by h, then divide by sin 40°: h = 30/sin 40° ≈ 46.7 m. Check: 46.7 × sin 40° ≈ 30.

Named mistakes.

  • Dividing by sin. From sin θ = 0.6, θ isn't 0.6/sin. sin is a step, not a number, and arcsin undoes it.
  • arcsin of one side. θ = arcsin(o/h), not arcsin(o)/h: divide first, then undo.
  • Reading sin⁻¹ x as 1/sin x. On a function, ⁻¹ means its inverse.
  • Trusting the one angle. sin(180° − θ) = sin θ, so 30° and 150° share the sine 0.5. arcsin says 30°, but an angle known to be over 90° is 150°.
Quick check
cos θ = 0.5. Which two angles from 0° to 360° fit?
  1. 60° and 240°
  2. 60° and 120°
  3. 60° and 300°
  4. 60° only
Show the answer

60° and 300°

arccos 0.5 is 60°. Cosine is the across part, so its partner is the mirror image below the middle: 360° − 60° = 300°. Sine pairs θ with 180° − θ; cosine pairs θ with 360° − θ.

A wave's timing. A wave over time t is y = A sin(ωt + φ). Its speed ω (omega) is the k of lesson 44. The period is T = 2π/ω, so ω = 2π/T, and the frequency f = 1/T, in cycles per second, gives T = 1/f. To find when the wave is at height y, peel the layers on t: ÷ A, arcsin, − φ, then ÷ ω. So t = (arcsin(y/A) − φ)/ω, which needs y between −A and A, and A and ω not 0. arcsin's angle is on the rising part, so this is a time on the way up. The wave passes y on the way down too, and both times come round every period T: if t is below 0, add T until it isn't.

Circles and distances. The module's other formulas turn around with the same moves.

  • Arc length s = rθ gives θ = s/r and r = s/θ, with θ in radians.
  • Sector area, the area of a pizza slice with angle θ, is A = ½r²θ: the slice is θ/2π of the whole circle's πr². So r² = 2A/θ, and r = √(2A/θ), keeping only the + root for a radius, with θ above 0.
  • Degrees and radians. rad = deg × π/180 is undone by × 180/π: deg = rad × 180/π.
  • Distance. Square both sides of d = √((x₂ − x₁)² + (y₂ − y₁)²), take away (y₂ − y₁)², take the root with ±, then add x₁:
x2=x1±d2−(y2−y1)2x_2 = x_1 \pm \sqrt{d^2 - (y_2 - y_1)^2}

Two points fit, one on each side of x₁. If d is less than the gap in y, no point does.

In your own words
Why does the way back through a sine give one angle, when many angles have that sine?

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

In Python: angles come back in radians

Purpose. Undo trig in code, in the right units and the right quadrant.

import math

theta = math.asin(6 / 10)
print(round(theta, 4), round(math.degrees(theta), 2), round(180 - math.degrees(theta), 2))
print(round(math.degrees(math.acos(5 / 13)), 2), round(10 * math.sin(math.radians(36.87)), 3))
print(round(6 / math.tan(theta), 3))
It runs right here in your browser, with nothing to install.

math.asin, math.acos and math.atan return radians, so math.degrees turns the answer into degrees. The other angle with this sine is 180° − 36.87° = 143.13°. Going forward, math.radians turns degrees back before math.sin: 36.87° gives a height of 6 again. math.acos(5 / 13) undoes a cosine: in the 5-12-13 triangle, the angle next to the side of 5 is 67.38°. The last line frees the adjacent side from tan θ = o/a: a = o/tan θ = 8, the third side of the 6-8-10 triangle.

Worked example

Worked example: a point to polar and back

A point can be given by its distance r from the origin and its angle θ: x = r cos θ and y = r sin θ. Turned around, Pythagoras gives r = √(x² + y²), and math.atan2(y, x) gives θ.

import math

def to_polar(x, y):
    r = math.sqrt(x ** 2 + y ** 2)
    theta = math.degrees(math.atan2(y, x))
    return (round(r, 3), round(theta, 2))

def to_xy(r, deg):
    t = math.radians(deg)
    return (round(r * math.cos(t), 3), round(r * math.sin(t), 3))

print(to_polar(4, 3), to_polar(-4, -3))
print(to_xy(5, -143.13))
In the lesson you can change this and run it.

(4, 3) is 5 from the origin at 36.87°. (−4, −3) is also 5 away, but down and to the left, at −143.13°. atan2 takes y and x separately, so it sees both signs and returns the angle in the right quadrant, anywhere from −180° to 180°. The last line goes back: 5 at −143.13° lands on (−4, −3).

Quick check
What does this print?
import math

x = -1
y = -1
print(round(math.degrees(math.atan(y / x))), round(math.degrees(math.atan2(y, x))))
  1. 45 -135
  2. -45 135
  3. 45 45
  4. -135 -135
Show the answer

45 -135

y/x = 1, the same as for (1, 1), so atan gives 45°. atan2 sees that both are negative: the point is down and to the left, at −135°.

Why atan fails. y/x throws the signs away: (1, 1) and (−1, −1) both give 1, and arctan 1 is 45°. arctan only returns angles in the right half, so every point on the left comes out pointing the wrong way. atan2 also copes with x = 0, where y/x would divide by 0. At the origin itself, r = 0 and the angle means nothing.

Quick check
Which call stops the program with an error?
  1. math.asin(-0.5)
  2. math.acos(-1)
  3. math.asin(1.2)
  4. math.atan(1.2)
Show the answer

math.asin(1.2)

No angle has a sine of 1.2, so math.asin raises a ValueError. That's the condition |o/h| ≤ 1: check it before you undo the sine.

Drill

Fix the angle functions

ramp_angle(rise, length) should give a ramp's angle in degrees, from sin θ = o/h. angle_of(x, y) should give the angle of the point (x, y) in degrees, in every quadrant. Each has one slip.

import math

def ramp_angle(rise, length):
    return math.asin(rise / length)

def angle_of(x, y):
    return math.degrees(math.atan(y / x))

print(ramp_angle(1, 2), angle_of(-4, -3))
In the lesson, your code is checked as you write it.
In your own words
Why does math.atan2 take y and x separately, instead of y/x?

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

In AI and ML: positions, frequencies and a level photo

Purpose. Transformers turn positions into angles, and image pipelines turn photos. Running those formulas backward tells you where a number came from.

Position codes. Lesson 44 coded a position p as waves at several speeds. In the original transformer, pair i of a code d numbers long turns at frequency ω = 1/10000^(2i/d). Which pair has a given ω? Take log₁₀ of both sides, as in lesson 35. Since log₁₀ 10000 = 4, log₁₀ ω = −8i/d, so i = −d·log₁₀(ω)/8. That pair repeats every 2π/ω positions: its period.

Rotary embeddings (RoPE). Many recent language models, such as Llama, turn each pair of a query and a key by θ = p·ω instead. Turned around, p = θ/ω. But angles repeat every turn, so positions 2π/ω apart get the same turn.

import math

def index_for(omega, d):
    return -d * math.log10(omega) / 8

def position_for(theta, omega):
    return theta / omega

print(index_for(0.01, 512), round(2 * math.pi / 0.01, 1), position_for(1.5, 0.01))
Quick check
A rotary pair with ω = 0.02 has been turned by θ = 3 radians. Which position p is it?
  1. 1.5
  2. 0.0067
  3. 0.06
  4. 150
Show the answer

150

θ = p·ω, so p = θ/ω = 3 ÷ 0.02 = 150. Check: 150 × 0.02 = 3.

A level photo. Image pipelines rotate training photos, and they can straighten a crooked one. Mark a trail sign's top-left and top-right corners, in that order. The top edge points at θ = atan2(y₂ − y₁, x₂ − x₁), and rotating by −θ makes it level. If the photo is more than a quarter turn off, the right corner sits to the left, and only atan2 sees it: atan would leave the sign level but upside down. Here y is measured up, as on a graph. Many image libraries count y down from the top, which flips the angle's sign.

Quick check
What does this print?
import math

def level_angle(p1, p2):
    return math.degrees(math.atan2(p2[1] - p1[1], p2[0] - p1[0]))

print(round(level_angle((20, 30), (68, 44)), 2), round(level_angle((68, 44), (20, 30)), 2))
  1. 16.26 163.74
  2. 16.26 -163.74
  3. 16.26 16.26
  4. -16.26 -163.74
Show the answer

16.26 -163.74

In the first photo the top edge rises 14 over 48 to the right: a tilt of 16.26°. In the second, the top-left corner sits right of the top-right one, so the photo is nearly upside down: −163.74°, which is 16.26° − 180°. atan(14/48) would say 16.26° for both.

Drill

Run the position codes and the tilt backward

Write index_for(omega, d), the pair i whose frequency is ω = 1/10000^(2i/d), position_for(theta, omega), the position p of a rotary pair turned by θ = p·ω, and level_angle(p1, p2), the angle in degrees of the edge from corner p1 to corner p2. Each has one slip.

import math

def index_for(omega, d):
    return d * math.log10(omega) / 8

def position_for(theta, omega):
    return theta * omega

def level_angle(p1, p2):
    return math.degrees(math.atan((p2[1] - p1[1]) / (p2[0] - p1[0])))

print(index_for(0.01, 512), position_for(3, 0.02), level_angle((50, 40), (10, 10)))
In the lesson, your code is checked as you write it.
In your own words
A fast rotary pair can't tell position p from position p + 2π/ω. Why not, and what helps?

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

Goes deeper in

Practice what you just read

  • 3 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

sin θ = 0.5, and θ is between 90° and 180°. What is θ?

  1. 150°
  2. 30°
  3. 120°
  4. 210°

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.

Part of a free course 19 lessons

Transposition of Formulas: algebraic manipulation in every topic

Learn to make any letter of any formula the subject: layers undone in reverse order, fractions, a letter that appears twice, powers, roots, quadratics, logs, inequalities, trigonometry, vectors, matrices, calculus, probability, statistics and the formulas inside AI models, each checked in Python.

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