# Notation

This page is the shared symbol dictionary for the curriculum. **Always read a symbol together with its domain, units, and tensor shape**—the same letter often means different things in different papers.

## 1. General mathematical notation

### Scalars, vectors, matrices, and indices

| Notation | Read as | Meaning | Example |
|---|---|---|---|
| $a,b,c$ | scalar | one number | learning rate $\alpha=10^{-4}$ |
| $\mathbf{x},\mathbf{y}$ | vector | ordered list of numbers | token state $\mathbf{x}\in\mathbb R^D$ |
| $X,Y,W$ | matrix / tensor | array of numbers | weight matrix $W\in\mathbb R^{D\times D}$ |
| $\theta$ | theta | all trainable model parameters | policy $\pi_\theta$ |
| $i,j,k$ | index | selects an item, class, feature, or sample | vocabulary logit $z_j$ |
| $t$ | time / token step | position in a trajectory or sequence | response token $y_t$ |
| $x_{<t}$ | before $t$ | $x_1,\ldots,x_{t-1}$ | autoregressive prefix |
| $f:x\mapsto y$ | maps to | function $f$ sends input $x$ to output $y$ | $\operatorname{softmax}:z\mapsto p$ |

### Operators

| Symbol | Meaning | Tiny example |
|---|---|---|
| $\sum_i$ | add over index $i$ | $\sum_i p_i=1$ |
| $\prod_i$ | multiply over index $i$ | sequence probability $p(y)=\prod_t p(y_t)$ |
| $\mathbb E[X]$ | expectation / population average | expected reward |
| $x\sim p$ | sample $x$ from distribution $p$ | $y\sim\pi_\theta(\cdot\mid x)$ |
| $p(a\mid b)$ | probability of $a$ given $b$ | next token given prefix |
| $\mathbf 1[c]$ | indicator | $1$ if condition $c$ is true, otherwise $0$ |
| $\lVert x\rVert_2$ | L2 norm | Euclidean vector length |
| $\approx$ | approximately equal | $C\approx6ND$ |
| $\propto$ | proportional to | $p(y)\propto e^{r(y)}$ |
| $\arg\max_x f(x)$ | maximizing argument | the $x$ that makes $f$ largest |

### Derivatives and optimization

| Symbol | Meaning |
|---|---|
| $\frac{df}{dx}$ | derivative of scalar $f$ with respect to scalar $x$ |
| $\frac{\partial L}{\partial z_j}$ | partial derivative: change only $z_j$ |
| $\nabla_\theta L$ | vector of derivatives for every parameter in $\theta$ |
| $\alpha$ or $\eta_{lr}$ | learning rate |
| $L(\theta)$ or $\mathcal L$ | loss to minimize |
| $J(\theta)$ | objective commonly written to maximize, especially expected reward |

Gradient descent and ascent:

$$
\theta\leftarrow\theta-\alpha\nabla_\theta L,
\qquad
\theta\leftarrow\theta+\alpha\nabla_\theta J.
$$

## 2. Context collisions: the symbols most likely to confuse you

[[NOTATION_SCOPE_MAP]]

| Symbol | Meaning 1 | Meaning 2 | Meaning 3 | Safer writing in your own answer |
|---|---|---|---|---|
| $D$ | Transformer hidden width | training-token count in scaling laws | fixed dataset in distillation | $d_{model}$, $D_{tokens}$, $\mathcal D$ |
| $L$ | number of layers | loss | sequence length | $L_{layers}$, $\mathcal L$, $T$ |
| $V$ | vocabulary size | attention values | value function | $|\mathcal V|$, $V_{attn}$, $V_\psi(s)$ |
| $H$ | attention-head count | entropy $H(p)$ | sometimes hidden state | $H_{heads}$, $\mathcal H(p)$, $h$ |
| $T$ | sequence length | number of generation steps | temperature in some papers | $T_{seq}$, $T_{steps}$, $\tau$ |
| $\beta$ | KL penalty | DPO logit scale | Adam moment decay | add a subscript: $\beta_{KL}$, $\beta_{DPO}$, $\beta_1$ |
| $\sigma$ | standard deviation | sigmoid function | policy name in some papers | $\operatorname{std}$, $\operatorname{sigmoid}$ |
| $\eta$ | learning rate | model FLOPs utilization | task success probability | $\eta_{lr}$, $\eta_{MFU}$, $p_{success}$ |

> **Interview rule:** define overloaded symbols before using them. Saying “Here $D$ denotes training tokens, not hidden width” prevents many avoidable mistakes.

## 3. Probability, statistics, and loss functions

### Distributions and logits

| Symbol | Meaning |
|---|---|
| $z_j$ | unnormalized logit for class/token $j$ |
| $p_j$ | probability assigned to class/token $j$ |
| $p,q$ | two generic distributions |
| $\pi_\theta$ | a parameterized policy / language-model distribution |
| $\log p$ | log-probability; products become sums |
| $\sigma(u)$ | sigmoid $1/(1+e^{-u})$ when used as a function |
| $\mu$ | mean |
| $\sigma^2$ | variance when $\sigma$ is a statistic |
| $\sigma$ | standard deviation $\sqrt{\sigma^2}$ |

Softmax converts logits to probabilities:

$$
p_j=\operatorname{softmax}(z)_j
=\frac{e^{z_j}}{\sum_k e^{z_k}}.
$$

### Entropy, cross-entropy, and KL

| Quantity | Formula | Meaning |
|---|---|---|
| Entropy | $H(q)=-\sum_vq(v)\log q(v)$ | uncertainty inside $q$ |
| Cross-entropy | $H(q,p)=-\sum_vq(v)\log p(v)$ | cost of predicting $p$ when targets follow $q$ |
| Forward KL | $D_{KL}(q\,\Vert\,p)=\sum_vq(v)\log\frac{q(v)}{p(v)}$ | teacher/data-weighted mismatch |
| Reverse KL | $D_{KL}(p\,\Vert\,q)=\sum_vp(v)\log\frac{p(v)}{q(v)}$ | model-weighted mismatch |
| NLL / CE label loss | $-\log p_y$ | negative log-probability of the correct token |

Useful identity:

$$
H(q,p)=H(q)+D_{KL}(q\|p).
$$

### Sampling and Monte Carlo

| Symbol | Meaning |
|---|---|
| $N_s$ | number of Monte Carlo samples |
| $y^{(i)}$ | sampled output number $i$ |
| $\widehat{\mathbb E}[f]$ | sample-based estimate of an expectation |

$$
\mathbb E_{y\sim p}[f(y)]
\approx\frac{1}{N_s}\sum_{i=1}^{N_s}f(y^{(i)}).
$$

## 4. Transformers and language models

### Core dimensions

| Symbol | Meaning | Typical shape / relation |
|---|---|---|
| $B$ | batch size | number of sequences |
| $T$ | sequence or context length | tokens per sequence |
| $D$ or $d_{model}$ | model / hidden width | features per token |
| $V$ or $|\mathcal V|$ | vocabulary size | number of output token classes |
| $L$ | Transformer layer count | integer |
| $N$ | total model parameters | scalar count; `7B = 7×10⁹` |
| $H$ | query-head count | integer |
| $H_{kv}$ | key/value-head count | $H$ for MHA; smaller for GQA/MQA |
| $d_h$ | head dimension | $D/H$ |
| $d_{ff}$ | FFN intermediate width | often several times $D$ |
| $M$ | tokens in one batch | $BT$ |

### Attention symbols and shapes

| Symbol | Meaning | Example shape before head split |
|---|---|---|
| $X$ | input hidden states | $[B,T,D]$ |
| $W_Q,W_K,W_V$ | learned query/key/value projections | usually $[D,D]$ for MHA |
| $Q=XW_Q$ | queries: what each token seeks | $[B,T,D]$ |
| $K=XW_K$ | keys: what each token matches | $[B,T,D]$ |
| $V_{attn}=XW_V$ | values: information to mix | $[B,T,D]$ |
| $Q_h,K_h,V_h$ | per-head tensors | $[B,H,T,d_h]$ |
| $S=QK^T/\sqrt{d_h}$ | attention scores | $[B,H,T,T]$ |
| $P=\operatorname{softmax}(S)$ | attention probabilities | $[B,H,T,T]$ |
| $O=PV$ | weighted value mixture | $[B,H,T,d_h]$ |

The letter $V$ is overloaded: italic $V$ may mean **vocabulary size**, while a tensor named $V$ inside attention means **values**. State the shape to disambiguate.

### Autoregressive probability

| Symbol | Meaning |
|---|---|
| $x$ | prompt / conditioning context |
| $y=(y_1,\ldots,y_T)$ | generated response |
| $y_t$ | response token at step $t$ |
| $y_{<t}$ | all response tokens before $t$ |
| $s_t=(x,y_{<t})$ | token-level state / prefix |

$$
\pi_\theta(y\mid x)
=\prod_{t=1}^{T}\pi_\theta(y_t\mid x,y_{<t}),
\qquad
\log\pi_\theta(y\mid x)
=\sum_{t=1}^{T}\log\pi_\theta(y_t\mid x,y_{<t}).
$$

### Position encoding and RoPE

| Symbol | Meaning |
|---|---|
| $p$ or $m,n$ | token position |
| $d$ | position-vector dimension |
| $i$ | sine/cosine or RoPE feature-pair index |
| $\theta_{base}$ | fixed base controlling the frequency range; often `10000` |
| $\omega_i$ | angular frequency of feature pair $i$ |
| $R(\phi)$ | 2D rotation matrix by angle $\phi$ |

$$
\omega_i=\theta_{base}^{-2i/d},
\qquad
\text{angle}_{p,i}=p\omega_i.
$$

Uppercase $W$ is a learned **weight matrix**. Lowercase Greek $\omega$ is **omega**, usually a fixed rotation frequency.

## 5. Resource counting and scaling laws

Use explicit subscripts here because $D$ is especially overloaded.

| Symbol | Meaning | Unit |
|---|---|---|
| $N$ | total model parameters | scalars |
| $D_{tokens}$ | total training tokens in a scaling law | tokens |
| $C$ | total training compute | FLOPs |
| $T_{train}$ | total training tokens in a run | tokens |
| $s$ | bytes per stored scalar | bytes/value |
| $A_{mem}$ | activations and temporary buffers | bytes |
| $F_{gpu}$ | sustained or peak compute per GPU | FLOPs/second |
| $G$ | GPU count | integer |
| $t_{train}$ | wall-clock training time | seconds |
| $\eta_{MFU}$ | model FLOPs utilization | fraction in $[0,1]$ |
| $L(N,D_{tokens})$ | fitted validation loss | scalar |
| $E$ | irreducible-loss floor | loss units |

Dense-transformer planning approximations:

$$
C\approx6ND_{tokens},
\qquad
t_{train}\approx\frac{C}{G F_{gpu}\eta_{MFU}}.
$$

Memory and architecture estimates:

$$
M_{weights}=Ns,
\qquad
M_{KV}=2LBT H_{kv}d_hs,
\qquad
N_{body}\approx12LD^2.
$$

In the last equation, $D$ is hidden width—not training tokens. Units and surrounding terms reveal the meaning.

## 6. Distillation

| Symbol | Meaning |
|---|---|
| $\pi_T$ | frozen teacher policy |
| $\pi_\theta$ | trainable student policy |
| $q_t(v)=\pi_T(v\mid s_t)$ | teacher distribution over vocabulary at state $s_t$ |
| $p_{\theta,t}(v)=\pi_\theta(v\mid s_t)$ | student distribution at the same state |
| $\mathcal D$ | fixed prompt-response dataset |
| $v$ | vocabulary item inside a sum |
| $\tau$ | softmax temperature |
| $\alpha_{KD}$ | weight on the distillation term |
| $k$ | number of retained teacher alternatives in top-$k$ distillation |

Temperature-softened probability:

$$
p_i^{(\tau)}
=\frac{\exp(z_i/\tau)}{\sum_j\exp(z_j/\tau)}.
$$

Classical mixed KD objective:

$$
\mathcal L
=(1-\alpha_{KD})CE(y,p^{(1)})
+\alpha_{KD}\tau^2D_{KL}(q^{(\tau)}\|p^{(\tau)}).
$$

## 7. Reinforcement learning and preference optimization

### Shared RL notation

| Symbol | Meaning |
|---|---|
| $s_t$ | state / current token prefix |
| $a_t$ or $y_t$ | sampled action / token |
| $r_t$ | reward at step $t$ |
| $R_t$ or $\widehat R_t$ | return / estimated reward-to-go |
| $\pi_\theta$ | current trainable actor / policy |
| $\pi_{old}$ | snapshot that generated the rollout |
| $\pi_{ref}$ | frozen SFT reference policy |
| $r_\phi(x,y)$ | learned reward model or verifier score |
| $V_\psi(s_t)$ | critic estimating future return |
| $A_t$ | advantage: return relative to a baseline |
| $\delta_t$ | temporal-difference residual |
| $\gamma$ | reward discount factor |
| $\lambda$ | GAE bias–variance parameter |
| $\rho_t$ | current-to-old probability ratio |
| $\epsilon$ | PPO clipping radius |
| $\beta_{KL}$ | KL-regularization strength |

PPO/GAE core:

$$
\delta_t=r_t+\gamma V_\psi(s_{t+1})-V_\psi(s_t),
\qquad
A_t=\delta_t+\gamma\lambda A_{t+1},
$$

$$
\rho_t(\theta)
=\exp\left(\log\pi_\theta(y_t\mid s_t)-\log\pi_{old}(y_t\mid s_t)\right).
$$

### DPO notation

| Symbol | Meaning |
|---|---|
| $y_w,y_l$ | preferred winner and rejected loser |
| $r(x,y)$ | latent human reward |
| $Z(x)$ | prompt-dependent partition function; cancels in a preference difference |
| $\beta_{DPO}$ | scales the reference-relative preference logit |
| $\sigma(\cdot)$ | sigmoid mapping a margin to a preference probability |

$$
\mathcal L_{DPO}
=-\log\sigma\!\left(
\beta_{DPO}\left[
\log\frac{\pi_\theta(y_w\mid x)}{\pi_{ref}(y_w\mid x)}
-\log\frac{\pi_\theta(y_l\mid x)}{\pi_{ref}(y_l\mid x)}
\right]\right).
$$

### GRPO notation

| Symbol | Meaning |
|---|---|
| $B$ | number of prompts in a rollout batch |
| $G$ | responses sampled per prompt; not GPU count in this context |
| $y^{(i,j)}$ | response $j$ sampled for prompt $i$ |
| $r^{(i,j)}$ | reward of that response |
| $\bar r_i$ | mean reward for prompt $i$ |
| $\sigma_i$ | reward standard deviation within prompt group $i$ |
| $\widehat A^{(i,j)}$ | group-normalized advantage |

$$
\bar r_i=\frac1G\sum_{j=1}^{G}r^{(i,j)},
\qquad
\widehat A^{(i,j)}
=\frac{r^{(i,j)}-\bar r_i}{\sigma_i+\varepsilon}.
$$

## 8. How to decode a formula in an interview

### Example A — attention

$$
Q=XW_Q,\qquad S=\frac{QK^T}{\sqrt{d_h}},\qquad O=\operatorname{softmax}(S)V.
$$

Read it in this order:

1. State shapes: $X:[B,T,D]$, $W_Q:[D,D]$, therefore $Q:[B,T,D]$.
2. Split heads: $Q,K,V:[B,H,T,d_h]$.
3. $QK^T$ compares every query position with every key position: $[B,H,T,T]$.
4. Softmax creates weights; multiplication by values returns $[B,H,T,d_h]$.

### Example B — scaling

$$C\approx6ND_{tokens}.$$

- $N$: parameters.
- $D_{tokens}$: tokens processed.
- Factor 6: approximate forward plus backward compute per parameter-token pair.
- Units: parameter count × token count behaves like operation count.

### Example C — policy gradient

$$
\nabla_\theta J
=\mathbb E_{y\sim\pi_\theta}
\left[A(y)\nabla_\theta\log\pi_\theta(y\mid x)\right].
$$

- $A>0$: increase the sampled response probability.
- $A<0$: decrease it.
- Expectation: average this signal over many sampled responses, usually with Monte Carlo.

## 9. Source pages consolidated here

The repeated notation tables were moved from these curriculum pages:

- [Resource Counting](https://www.qiyuzhi.com/study/llm/flops-parameters/)
- [Scaling Laws](https://www.qiyuzhi.com/study/pre-training/scaling-laws/)
- [Positional Encoding](https://www.qiyuzhi.com/study/llm/positional-encoding/)
- [Distillation](https://www.qiyuzhi.com/study/rlhf-rlvr/distillation/)
- [PPO](https://www.qiyuzhi.com/study/rlhf-rlvr/ppo/)
- [DPO](https://www.qiyuzhi.com/study/rlhf-rlvr/dpo/)

### Final memory checklist

- Never interpret a symbol without checking its nearby definition.
- Shapes disambiguate tensors; units disambiguate compute and memory variables.
- Use subscripts in your own interview derivations when a letter is overloaded.
- Distinguish $\pi_{old}$ from $\pi_{ref}$, and KL coefficient $\beta_{KL}$ from DPO scale $\beta_{DPO}$.
- Say whether a sequence log-probability is a **sum** or length-normalized average.
