Variance and Standard Deviation
What variance measures
The expectation value of a discrete random variable tells you its average, but two distributions can share the same average while looking very different. One might be tightly clustered near the mean; another might place most of its weight far from it. Variance quantifies that spread.
For a discrete variable taking values with probabilities , the variance is defined as the average squared deviation from the mean:
= \sum_i p_i \,(x_i - \langle X \rangle)^2.$$ Expanding the square and using linearity of expectation gives an equivalent and often more convenient form: $$\operatorname{Var}(X) = \langle X^2 \rangle - \langle X \rangle^2.$$ Here $\langle X^2 \rangle = \sum_i p_i x_i^2$ is the expectation of the square. The two forms are algebraically identical; the second is usually faster to compute. The **standard deviation** is simply $$\sigma_X = \sqrt{\operatorname{Var}(X)}.$$ Because variance is computed from squared deviations its units are the square of $X$'s units, while $\sigma_X$ has the same units as $X$ itself. Standard deviation is therefore the natural measure of spread. ## A concrete example Let $X$ take values $+1$ and $-1$ with probabilities $p$ and $1 - p$ respectively. This is the simplest possible binary distribution, and it appears directly in quantum mechanics: measuring the $z$-component of spin on a spin-1/2 particle yields $+\hbar/2$ or $-\hbar/2$, and if we express outcomes in units of $\hbar/2$ we get exactly $\pm 1$. **Step 1: mean.** $$\langle X \rangle = p \cdot (+1) + (1-p) \cdot (-1) = 2p - 1.$$ **Step 2: mean square.** Since $(\pm 1)^2 = 1$ for both outcomes, $$\langle X^2 \rangle = p \cdot 1 + (1-p) \cdot 1 = 1.$$ **Step 3: variance.** $$\operatorname{Var}(X) = \langle X^2 \rangle - \langle X \rangle^2 = 1 - (2p-1)^2.$$ Expanding: $(2p-1)^2 = 4p^2 - 4p + 1$, so $$\operatorname{Var}(X) = 1 - (4p^2 - 4p + 1) = 4p(1-p).$$ The variance is maximised at $p = 1/2$ (perfectly uncertain outcome, $\operatorname{Var} = 1$) and vanishes at $p = 0$ or $p = 1$ (certain outcome). Standard deviation is $\sigma = 2\sqrt{p(1-p)}$. For the specific case $p = 3/4$: $$\langle X \rangle = 2 \cdot \tfrac{3}{4} - 1 = \tfrac{1}{2},$$ $$\operatorname{Var}(X) = 4 \cdot \tfrac{3}{4} \cdot \tfrac{1}{4} = \tfrac{3}{4},$$ $$\sigma = \sqrt{\tfrac{3}{4}} = \frac{\sqrt{3}}{2} \approx 0.866.$$ ## Connection to quantum uncertainty In quantum mechanics the standard deviation of an observable $\hat{A}$ in state $|\psi\rangle$ is written $\Delta A$ and defined by the same formula: $$(\Delta A)^2 = \langle \hat{A}^2 \rangle - \langle \hat{A} \rangle^2.$$ The famous Heisenberg uncertainty principle states that for position $\hat{x}$ and momentum $\hat{p}$, $$\Delta x \, \Delta p \geq \frac{\hbar}{2}.$$ The left-hand side is a product of two standard deviations. Mastering their calculation is therefore a prerequisite for understanding the uncertainty principle at any quantitative level. <Callout type="tip"> A useful check: $\operatorname{Var}(X) \geq 0$ always. If your calculation gives a negative number, look for a sign error in $\langle X \rangle^2$ or a mis-squared deviation. </Callout> ## Try it This is a numerical exercise — your code should `return` a number, not a circuit. A spin-1/2 measurement yields outcome $+1$ with probability $3/4$ and outcome $-1$ with probability $1/4$. Compute the standard deviation $\sigma$. <RunnableExample />Sign in on the full site to ask questions and join the discussion.