From Derivatives to Attention

Mathematics for programmers, from undergraduate calculus to a 2026 paper on attention.

Preface

This book is for programmers who know machines well and theory less. If you can schedule a Pentium Pro's micro-ops by hand but freeze when asked to balance an AVL tree on paper, it is for you. It starts at derivatives and ends at [refinekv], a paper that speeds up language-model inference by bounding the error of a cheap attention, and it covers each idea that paper uses on the way.

How it is written:

The formulas are TeX, typeset by MathJax. Without JavaScript you see the TeX itself, which reads as it is: \(\frac{a}{b}\) is a fraction, \(x^2\) a power, \(\sum_{i=1}^{n}\) a sum over \(i = 1\) to \(n\).

Contents

Notation

WrittenReadIn C
\(x \in S\)\(x\) is a member of the set \(S\)
\(\mathbb{R}\), \(\mathbb{R}^d\)the real numbers; arrays of \(d\) realsdouble, double x[d]
\(f : A \to B\)\(f\) takes an \(A\), gives a \(B\)B f(A)
\(\sum_{i=1}^{n} a_i\)the sum of \(a_1, \dots, a_n\)for (i = 1; i <= n; i++) s += a[i];
\(\prod_{i=1}^{n} a_i\)the product of \(a_1, \dots, a_n\)p *= a[i]
\(\max_{i \in C} a_i\)the largest \(a_i\) with \(i\) in \(C\)
\(|x|\), \(\|v\|\)absolute value; length (norm) of a vectorfabs(x)
\(q^\top k\)the dot product of \(q\) and \(k\)for (j...) s += q[j]*k[j];
\(\bar{k}\), \(\hat{p}\)a mean (bar); an estimate (hat)
\(:=\)is defined as=
\(\approx\), \(\le\), \(\ge\)approximately; at most; at least
\(\Rightarrow\), \(\iff\)implies; if and only if

Greek letters used: \(\alpha\) alpha, \(\beta\) beta, \(\gamma\) gamma, \(\delta, \Delta\) delta, \(\varepsilon\) epsilon, \(\theta\) theta, \(\lambda\) lambda, \(\mu\) mu, \(\pi\) pi, \(\rho\) rho, \(\sigma, \Sigma\) sigma, \(\tau\) tau, \(\phi\) phi.


From Derivatives to Attention, a book of the ScarletNX site. GPL-3.0-or-later, as the site. Formulas typeset by MathJax 3.2.2.