Functions and operators

O(n2d)\mathcal{O}(n^2 d) Big-O notation

How a cost grows with size, ignoring constants: O(n²) means at most proportional to n² for large n.

In ML papers

O(f(n))\mathcal{O}(f(n)) describes how fast something grows as nn gets large, up to a constant factor. Saying self-attention costs O(n2d)\mathcal{O}(n^2 d) for nn tokens of width dd means: double the sequence length and the cost roughly quadruples. Constants and smaller terms are dropped, so 3n2+100n3n^2 + 100n is O(n2)\mathcal{O}(n^2). Plain OO and calligraphic O\mathcal{O} mean the same.

Relatives: Ω(f)\Omega(f) is a lower bound (grows at least like ff), Θ(f)\Theta(f) both at once (grows exactly like ff, up to constants), and little o(f)o(f) means "grows strictly slower than ff", so o(1)o(1) is something that shrinks to zero.

How to type it

LaTeXShows
O(n^2)O(n2)O(n^2)
\mathcal{O}(n \log n) calligraphicO(nlog⁡n)\mathcal{O}(n \log n)

A worked example

n=1000→2000:n2=106→4×106n = 1000 \to 2000: \quad n^2 = 10^6 \to 4 \times 10^6

An O(n2)\mathcal{O}(n^2) step takes about four times as long; an O(n)\mathcal{O}(n) step about twice.

Common confusions

Related

X,D,L\mathcal{X}, \mathcal{D}, \mathcal{L}Calligraphic letterslim⁡h→0\lim_{h \to 0}Limit∥x∥∞\|\mathbf{x}\|_\inftyInfinitylog⁡pθ(x)\log p_\theta(x)Logarithm

Decode this example →