Skip to content

Precalculus

  • Logarithms turn products into sums and change the unit of information. A model’s loss in nats becomes bits by dividing by ln⁡2\ln 2; bits per byte is the comparison every tokenizer and model in the course is judged by.
  • A rotation is a multiplication by a unit complex number. Rotating a 2D pair by θ\theta is multiplying x+iyx + iy by eiθe^{i\theta}; RoPE applies that to every pair of a query and a key.
  • Geometric sequences are frequency ladders. RoPE’s inverse frequencies b−2i/db^{-2i/d} and ALiBi’s head slopes are geometric sequences; their sums and ratios decide how far a position signal reaches.
  • How you evaluate a formula matters as much as the formula. Horner’s rule is the cheapest and most stable way to evaluate a polynomial, and the textbook quadratic formula can lose most of its digits for the small root when b2≫4acb^2 \gg 4ac.

Read each OpenStax chapter with a notebook open and check every identity numerically before you trust it (math.log, cmath.exp, numpy). In the course, take the solve set S-M00 first: it is the pen-and-paper check of the four build modules, then build M00.1 to M00.4 in order with ol start <ID> and ol check <ID>.


Precalculus is the toolbox the rest of the math is written in: exponents and logarithms, trigonometry and complex numbers, sequences and series, and polynomials. Each one has a call site in an LLM system: logarithms measure information, rotations encode position, geometric ladders set frequencies, and polynomials approximate the functions a C kernel cannot call.

1. Exponents, logarithms, and units of information

Section titled “1. Exponents, logarithms, and units of information”

Key ideas:

  • Laws: aman=am+na^{m}a^{n} = a^{m+n}, log⁡b(xy)=log⁡bx+log⁡by\log_b(xy) = \log_b x + \log_b y, change of base log⁡bx=ln⁡x/ln⁡b\log_b x = \ln x / \ln b.
  • Units: a negative log-likelihood summed in nats over a text of nn bytes is bpb=nll/(nln⁡2)\text{bpb} = \text{nll} / (n \ln 2) bits per byte, a number comparable across tokenizers.
  • Call sites: M11.2 perplexity and bits per byte, L1.6 tokenizer metrics, L6.7 the model-zoo table, C1.

2. Trigonometry, rotations, and complex numbers

Section titled “2. Trigonometry, rotations, and complex numbers”

Key ideas:

  • Unit circle: (cos⁡θ,sin⁡θ)(\cos\theta, \sin\theta); a 2D rotation is the matrix (cos⁡θ−sin⁡θsin⁡θcos⁡θ)\begin{pmatrix}\cos\theta & -\sin\theta\\ \sin\theta & \cos\theta\end{pmatrix}, which preserves length and composes by adding angles: R(a)R(b)=R(a+b)R(a)R(b) = R(a+b).
  • Euler’s formula: eiθ=cos⁡θ+isin⁡θe^{i\theta} = \cos\theta + i\sin\theta, so the same rotation is one complex multiplication.
  • Call sites: L5.4 sinusoidal positional encoding, L7.3 RoPE.

3. Sequences, series, and frequency ladders

Section titled “3. Sequences, series, and frequency ladders”

Key ideas:

  • Geometric sequence: a,ar,ar2,…a, ar, ar^2, \dots with sum a(1−rn)/(1−r)a(1 - r^n)/(1 - r) for r≠1r \ne 1.
  • Ladders: RoPE inv_freq is b−2i/db^{-2i/d} for i=0,…,d/2−1i = 0, \dots, d/2 - 1; ALiBi slopes are a geometric sequence per head, with a rule for head counts that are not powers of two.
  • Call sites: L7.3 RoPE, L7.4 ALiBi and YaRN, M02.2, M10.4 schedules.

4. Polynomials, Horner’s rule, and stable roots

Section titled “4. Polynomials, Horner’s rule, and stable roots”

Key ideas:

  • Horner: a0+x(a1+x(a2+… ))a_0 + x(a_1 + x(a_2 + \dots)) uses nn multiplications and nn additions and is the form every polynomial kernel uses.
  • Cancellation: when b2≫4acb^2 \gg 4ac one root of −b±b2−4ac-b \pm \sqrt{b^2 - 4ac} subtracts two nearly equal numbers; compute the large-magnitude root first and get the other from x1x2=c/ax_1 x_2 = c/a.
  • Call sites: M02.1 Taylor polynomials, M09.6 the polynomial core of tl_expf.
ModuleTopicKindPass
S-M00Precalculus problem set (checked by SymPy)solve2
M00.1Exponents, logs, change of base, units of informationbuild2
M00.2Trig, unit circle, 2D rotations, complex numbers, Euler’s formulabuild2
M00.3Sequences, geometric series, frequency laddersbuild2
M00.4Polynomials, Horner, stable quadratic rootsbuild2
M00.5Functions, inverses, monotonicity, inequalitiessolvesolve set

M00.5 (functions, inverses, monotonicity, inequalities) is solve-only: it appears as items of S-M00 and is used by M01.1 and M05.2.

#ModuleChapterKindPass
1S-M00Solve set: functions, exp/log, trig and Euler, series, polynomials, inequalitiessolve2
2M00.1Exponents, logs, change of base, units of informationbuild2
3M00.2Trig, unit circle, 2D rotations, complex numbers, Euler’s formulabuild2
4M00.3Sequences, geometric series, frequency laddersbuild2
5M00.4Polynomials, Horner, stable quadratic rootsbuild2
TrackConnection
Calculus 1limits and derivatives build on functions, exponentials, and logarithms
Numerical Methods and Floating Pointrange reduction and polynomial approximation of exp (M09.6) start from Horner’s rule
Information Theoryentropy and perplexity are logarithms with a unit
tinyllmRoPE, ALiBi, and bits per byte are the first places this math runs