
# The Density Operator

> A pure state $|\psi\rangle$ is the most you can know about a quantum system — but it is not the
> most general thing you can *have*. The moment there is classical uncertainty about which state was
> prepared, or the moment you look at one half of an entangled pair, the ket description breaks down.
> The **density operator** $\rho$ repairs it: a single Hermitian, positive, unit-trace matrix that
> encodes *every* statistical prediction, pure or mixed. It is the true state object of quantum
> mechanics, and from Term 4 onward (noise, channels, error correction) it is the *only* one we use.

## Learning Objectives

After this lesson you will be able to:

1. **Motivate** the density operator from classical ensembles and from subsystems of entangled states.
2. **Define** $\rho = \sum_i p_i|\psi_i\rangle\langle\psi_i|$ and **prove** it is Hermitian, positive
   semidefinite, and unit-trace — and that these three properties characterize valid states.
3. **Distinguish** pure ($\rho^2 = \rho$, $\operatorname{Tr}\rho^2 = 1$) from mixed
   ($\operatorname{Tr}\rho^2 < 1$) states and compute the **purity**.
4. **Derive** the expectation-value formula $\langle A\rangle = \operatorname{Tr}(\rho A)$ and the
   evolution rule $\rho \to U\rho U^\dagger$.
5. **Explain ensemble ambiguity**: different ensembles can yield the same $\rho$, and only $\rho$ is
   physically meaningful.

---

## Intuition

Two genuinely different kinds of uncertainty live inside quantum mechanics, and the ket handles only
one of them.

**Quantum uncertainty (already in the ket).** A pure state $|+\rangle = \tfrac1{\sqrt2}(|0\rangle +
|1\rangle)$ has a definite, fully-specified description, yet a $Z$-measurement still returns $0$ or
$1$ with probability $\tfrac12$ each. That randomness is intrinsic — the Born rule — and the ket
captures it perfectly.

**Classical uncertainty (the ket cannot hold it).** Now suppose a (sloppy) lab sends you a qubit that
is $|0\rangle$ with probability $\tfrac12$ and $|1\rangle$ with probability $\tfrac12$ — an honest coin
flip deciding which state was *prepared*. This is **not** the same as $|+\rangle$: there is no single
ket that means "$|0\rangle$ or $|1\rangle$, I forget which." You cannot average kets
($\tfrac12|0\rangle + \tfrac12|1\rangle$ is not normalized, and choosing relative phases would smuggle
in coherence that isn't there). We need an object that mixes *probabilities of states*, not
*amplitudes*.

There is a second, deeper reason the ket fails — and it is not about a careless experimenter at all.
Take the Bell state $|\Phi^+\rangle = \tfrac1{\sqrt2}(|00\rangle + |11\rangle)$, a perfectly definite
pure state of *two* qubits. Ask: what is the state of **qubit $A$ alone**? It has no ket — qubit $A$ is
not in any definite state, because its identity is entangled with $B$. Yet $A$ still has well-defined
measurement statistics (we will find they are completely random). Describing "one subsystem of an
entangled whole" *forces* the same machinery as classical mixing.

The fix in both cases is to package an ensemble $\{(p_i, |\psi_i\rangle)\}$ into one operator,

$$
\rho \;=\; \sum_i p_i\,|\psi_i\rangle\langle\psi_i| ,
$$

by averaging the **projectors** $|\psi_i\rangle\langle\psi_i|$ (which carry no spurious phases) with
the classical probabilities $p_i$. Everything you can measure will turn out to depend on the ensemble
*only* through this $\rho$ — which is exactly why it, and not the list of kets, is the state.

---

## Theory

### Definition

> **Definition (density operator).** Let $\{(p_i, |\psi_i\rangle)\}$ be an **ensemble**: normalized
> states $|\psi_i\rangle$ (not necessarily orthogonal) prepared with probabilities $p_i \ge 0$,
> $\sum_i p_i = 1$. The associated **density operator** is
> $$ \rho \;=\; \sum_i p_i\,|\psi_i\rangle\langle\psi_i| . $$

The notation matches [Appendix C](../../appendix/C-notation-glossary.md): each
$|\psi_i\rangle\langle\psi_i|$ is the rank-1 projector of [0.1.3](../../term-0-foundations/c01-linear-algebra/03-dirac-notation.md),
and $\rho$ is their probability-weighted convex combination. A **pure state** is the special case of a
single term, $\rho = |\psi\rangle\langle\psi|$; any other case is **mixed**.

### The three defining properties (and their proofs)

Three properties hold for *every* density operator, and — as we show afterward — they are also
*sufficient*: any operator with these properties is the density operator of some ensemble. They are
the density-matrix analog of "normalized ket."

**Property 1 — Hermitian, $\rho^\dagger = \rho$.**

$$
\rho^\dagger = \Big(\sum_i p_i\,|\psi_i\rangle\langle\psi_i|\Big)^\dagger
= \sum_i \overline{p_i}\,\big(|\psi_i\rangle\langle\psi_i|\big)^\dagger
= \sum_i p_i\,|\psi_i\rangle\langle\psi_i| = \rho .
$$

We used $(|\psi\rangle\langle\psi|)^\dagger = |\psi\rangle\langle\psi|$ from
[0.1.3 E4](../../term-0-foundations/c01-linear-algebra/03-dirac-notation.md) and the fact that $p_i$
is **real**, so $\overline{p_i} = p_i$. ∎ Hermiticity guarantees a real spectrum and an orthonormal
eigenbasis (spectral theorem, [0.1.5](../../term-0-foundations/c01-linear-algebra/05-eigen-spectral-theorem.md)).

**Property 2 — Positive semidefinite, $\rho \succeq 0$.**

For any $|\varphi\rangle$,

$$
\langle\varphi|\rho|\varphi\rangle
= \sum_i p_i\,\langle\varphi|\psi_i\rangle\langle\psi_i|\varphi\rangle
= \sum_i p_i\,\big|\langle\psi_i|\varphi\rangle\big|^2 \;\ge\; 0 ,
$$

since each $p_i \ge 0$ and each $|\langle\psi_i|\varphi\rangle|^2 \ge 0$. By the characterization in
[0.1.6](../../term-0-foundations/c01-linear-algebra/06-special-operators.md), $\rho \succeq 0$, so all
its eigenvalues are $\ge 0$. ∎ Physically these eigenvalues will be probabilities.

**Property 3 — Unit trace, $\operatorname{Tr}\rho = 1$.**

Using linearity and cyclicity of the trace ([Appendix E §4](../../appendix/E-math-identities.md)),
$\operatorname{Tr}(|\psi_i\rangle\langle\psi_i|) = \langle\psi_i|\psi_i\rangle = 1$ for each normalized
$|\psi_i\rangle$, so

$$
\operatorname{Tr}\rho = \sum_i p_i\,\operatorname{Tr}\big(|\psi_i\rangle\langle\psi_i|\big)
= \sum_i p_i\,\langle\psi_i|\psi_i\rangle = \sum_i p_i = 1 . \qquad \blacksquare
$$

> **Theorem (these properties characterize states).** An operator $\rho$ on $\mathcal H$ is the
> density operator of some ensemble **iff** $\rho = \rho^\dagger$, $\rho \succeq 0$, and
> $\operatorname{Tr}\rho = 1$.

**Proof of sufficiency.** Suppose $\rho$ has the three properties. By the spectral theorem it has an
orthonormal eigenbasis $\{|v_k\rangle\}$ with real eigenvalues $\lambda_k$:
$\rho = \sum_k \lambda_k|v_k\rangle\langle v_k|$. Positivity forces $\lambda_k \ge 0$, and unit trace
forces $\sum_k \lambda_k = \operatorname{Tr}\rho = 1$. Hence $\{(\lambda_k, |v_k\rangle)\}$ is a valid
ensemble (probabilities $\lambda_k$, orthonormal states), and it manifestly reproduces $\rho$. ∎

The set of all such $\rho$ is **convex**: if $\rho_1,\rho_2$ are states then so is
$\lambda\rho_1 + (1-\lambda)\rho_2$ for $\lambda\in[0,1]$ (each property is preserved under convex
combination — check trace and positivity termwise). The **pure states** are precisely the *extreme
points* of this convex set: those that cannot be written as a nontrivial mixture. We make this precise
next.

### Pure vs. mixed

> **Definition.** $\rho$ is **pure** if $\rho = |\psi\rangle\langle\psi|$ for some normalized
> $|\psi\rangle$; otherwise it is **mixed**.

**The idempotence test.** A density operator is pure **iff** $\rho^2 = \rho$.

**Proof.** ($\Rightarrow$) If $\rho = |\psi\rangle\langle\psi|$ with $\langle\psi|\psi\rangle = 1$, then
$\rho^2 = |\psi\rangle\langle\psi|\psi\rangle\langle\psi| = |\psi\rangle\langle\psi| = \rho$. ($\Leftarrow$)
If $\rho^2 = \rho$, then $\rho$ is a Hermitian projector ([0.1.6](../../term-0-foundations/c01-linear-algebra/06-special-operators.md)),
so its eigenvalues are $0$ or $1$. Unit trace means exactly one eigenvalue is $1$ and the rest are $0$,
i.e. $\rho = |v\rangle\langle v|$ for that eigenvector — pure. ∎

**The purity functional.** Define the **purity**

$$
\boxed{\;\gamma(\rho) := \operatorname{Tr}(\rho^2) = \sum_k \lambda_k^2\;}
$$

where $\lambda_k$ are the eigenvalues of $\rho$. Because the $\lambda_k \ge 0$ form a probability
distribution ($\sum_k\lambda_k = 1$), purity is a measure of how *peaked* that distribution is:

> **Purity bounds.** For a state on a $d$-dimensional space,
> $$ \tfrac1d \;\le\; \operatorname{Tr}(\rho^2) \;\le\; 1, $$
> with $\operatorname{Tr}(\rho^2) = 1$ **iff** $\rho$ is pure, and $\operatorname{Tr}(\rho^2) = 1/d$
> **iff** $\rho = I/d$ is **maximally mixed**.

**Proof.** Among probability distributions $(\lambda_k)$ on $d$ outcomes, $\sum_k\lambda_k^2$ is
maximized when all weight sits on one outcome (giving $1$) and minimized by the uniform distribution
$\lambda_k = 1/d$ (giving $d\cdot(1/d)^2 = 1/d$). The maximum $\sum_k\lambda_k^2 = 1$ together with
$\sum_k\lambda_k = 1$ and $\lambda_k\in[0,1]$ forces a single $\lambda_k = 1$ — exactly the pure case,
matching $\rho^2 = \rho$. The minimum forces uniform eigenvalues, i.e. $\rho = I/d$. (Formally, by
Cauchy–Schwarz / Jensen, $\sum_k\lambda_k^2 \ge \tfrac1d(\sum_k\lambda_k)^2 = \tfrac1d$.) ∎

So purity slides from $1$ (a sharp ket) down to $1/d$ (total ignorance). It is the workhorse scalar
diagnostic for "how mixed is this state," and in Lesson 3 we will see it is a clean quadratic in the
Bloch vector for a qubit.

### Expectation values from $\rho$

The whole point of $\rho$ is that it predicts measurement statistics. Recall ([1.1.2](../c01-postulates/02-observables-measurement-postulate.md))
that for a *pure* state the expectation of an observable $A = A^\dagger$ is $\langle A\rangle =
\langle\psi|A|\psi\rangle$. For an ensemble, average over the classical uncertainty:

$$
\langle A\rangle \;=\; \sum_i p_i\,\langle\psi_i|A|\psi_i\rangle .
$$

Now convert each term to a trace using the "trace trick" of
[0.1.3 E5](../../term-0-foundations/c01-linear-algebra/03-dirac-notation.md),
$\langle\psi_i|A|\psi_i\rangle = \operatorname{Tr}(A|\psi_i\rangle\langle\psi_i|)$:

$$
\langle A\rangle = \sum_i p_i\,\operatorname{Tr}\!\big(A\,|\psi_i\rangle\langle\psi_i|\big)
= \operatorname{Tr}\!\Big(A\sum_i p_i|\psi_i\rangle\langle\psi_i|\Big)
= \operatorname{Tr}(A\rho) .
$$

$$
\boxed{\;\langle A\rangle = \operatorname{Tr}(\rho A) = \operatorname{Tr}(A\rho)\;}
$$

(the two forms agree by cyclicity of the trace). This single formula subsumes the pure-state Born rule
and is **the** computational definition of measurement in the density-matrix formalism. In particular,
the probability of a projective outcome with projector $P_k$ is $\operatorname{Tr}(\rho P_k)$, since
$P_k$ is itself an observable with eigenvalue $1$ on its subspace.

Notice the formula depends on the ensemble *only* through the combination $\rho = \sum_i
p_i|\psi_i\rangle\langle\psi_i|$. Two ensembles with the same $\rho$ are **operationally
indistinguishable** — there is no measurement that tells them apart. This is not a deficiency of our
tools; it is a statement about nature, and it has a name.

### Ensemble ambiguity

> **Different ensembles can give the same $\rho$.** The map (ensemble) $\to \rho$ is many-to-one, and
> only $\rho$ is observable.

The cleanest example is the **maximally mixed qubit** $\rho = \tfrac12 I$. It arises from at least two
physically distinct preparation stories:

$$
\underbrace{\tfrac12|0\rangle\langle0| + \tfrac12|1\rangle\langle1|}_{\text{coin flip in }Z\text{ basis}}
= \tfrac12\begin{pmatrix}1&0\\0&0\end{pmatrix} + \tfrac12\begin{pmatrix}0&0\\0&1\end{pmatrix}
= \tfrac12 I,
$$
$$
\underbrace{\tfrac12|+\rangle\langle+| + \tfrac12|-\rangle\langle-|}_{\text{coin flip in }X\text{ basis}}
= \tfrac12\cdot\tfrac12\begin{pmatrix}1&1\\1&1\end{pmatrix} + \tfrac12\cdot\tfrac12\begin{pmatrix}1&-1\\-1&1\end{pmatrix}
= \tfrac12 I.
$$

One lab flipped a coin and prepared $|0\rangle$ or $|1\rangle$; another flipped a coin and prepared
$|+\rangle$ or $|-\rangle$. **No experiment can distinguish their qubits**, because $\langle A\rangle =
\operatorname{Tr}(\rho A)$ depends only on $\rho = \tfrac12 I$. The list of kets is, in this sense, more
information than physics provides — the density operator is the right, gauge-invariant object.

> **When *do* two ensembles give the same $\rho$?** The precise answer is the **unitary freedom of
> ensembles** (the Hughston–Jozsa–Wootters / Schrödinger theorem, [NC §2.4]): ensembles
> $\{\sqrt{p_i}|\psi_i\rangle\}$ and $\{\sqrt{q_j}|\phi_j\rangle\}$ generate the same $\rho$ iff their
> (sub-normalized) vectors are related by a unitary (padding the shorter list with zero vectors). We
> state it here and prove the qubit case in the exercises; the general proof rides on the partial
> trace and purification of Lesson 2.

### Evolution: $\rho \to U\rho U^\dagger$

Closed-system (unitary) evolution of a ket is $|\psi\rangle \to U|\psi\rangle$
([0.1.6](../../term-0-foundations/c01-linear-algebra/06-special-operators.md)). Push this through the
ensemble. Each pure component evolves as

$$
|\psi_i\rangle\langle\psi_i| \;\longrightarrow\; \big(U|\psi_i\rangle\big)\big(U|\psi_i\rangle\big)^\dagger
= U|\psi_i\rangle\langle\psi_i|U^\dagger ,
$$

and the classical probabilities $p_i$ are untouched (unitary evolution does not alter which state was
prepared), so by linearity

$$
\boxed{\;\rho \;\longrightarrow\; U\rho U^\dagger\;}
$$

This is the **von Neumann picture** of evolution. Differentiating $U = e^{-iHt}$
([Appendix E §3](../../appendix/E-math-identities.md), $\hbar = 1$) gives the **von Neumann equation**
$\dot\rho = -i[H,\rho]$ — the density-matrix form of Schrödinger's equation, developed in
[Term 1.6](../c06-dynamics/01-time-evolution.md). Two sanity checks: this map preserves the three
defining properties (Hermiticity, positivity, trace — since $\operatorname{Tr}(U\rho U^\dagger) =
\operatorname{Tr}(\rho U^\dagger U) = \operatorname{Tr}\rho$ by cyclicity), and it preserves purity
($\operatorname{Tr}((U\rho U^\dagger)^2) = \operatorname{Tr}(U\rho^2 U^\dagger) =
\operatorname{Tr}\rho^2$). Unitary evolution can never turn a pure state mixed — that requires the
*non*-unitary channels of Term 4.

---

## Worked Examples

### Example 1 — Pure $|+\rangle$ vs. a 50/50 classical mix: same diagonal, different state

Build both density matrices and separate them with purity and an $X$-measurement.

**Pure state** $|+\rangle = \tfrac1{\sqrt2}(|0\rangle + |1\rangle)$:

$$
\rho_+ = |+\rangle\langle+| = \tfrac12(|0\rangle+|1\rangle)(\langle0|+\langle1|)
= \tfrac12\begin{pmatrix}1 & 1\\ 1 & 1\end{pmatrix}.
$$

**Classical 50/50 mix** of $|0\rangle$ and $|1\rangle$:

$$
\rho_{\text{mix}} = \tfrac12|0\rangle\langle0| + \tfrac12|1\rangle\langle1|
= \tfrac12\begin{pmatrix}1 & 0\\ 0 & 1\end{pmatrix} = \tfrac12 I .
$$

Both have the **same diagonal** ($\tfrac12,\tfrac12$): a $Z$-measurement gives $0$ or $1$ equally for
each, so $Z$ alone *cannot* tell them apart. The **off-diagonal coherences** differ, and that is where
the physics hides.

*Purity.* $\operatorname{Tr}(\rho_+^2) = \operatorname{Tr}\!\big(\tfrac14\begin{psmallmatrix}2&2\\2&2\end{psmallmatrix}\big)
= \tfrac14(2+2) = 1$ — pure. $\operatorname{Tr}(\rho_{\text{mix}}^2) = \operatorname{Tr}(\tfrac14 I)
= \tfrac12 = 1/d$ — maximally mixed.

*An $X$-measurement separates them.* With $X = \begin{psmallmatrix}0&1\\1&0\end{psmallmatrix}$,

$$
\langle X\rangle_{+} = \operatorname{Tr}(\rho_+ X)
= \operatorname{Tr}\!\Big(\tfrac12\begin{pmatrix}1&1\\1&1\end{pmatrix}\begin{pmatrix}0&1\\1&0\end{pmatrix}\Big)
= \operatorname{Tr}\!\Big(\tfrac12\begin{pmatrix}1&1\\1&1\end{pmatrix}\Big) = 1,
$$
$$
\langle X\rangle_{\text{mix}} = \operatorname{Tr}(\tfrac12 I\,X) = \tfrac12\operatorname{Tr}(X) = 0 .
$$

The pure $|+\rangle$ is a definite $+1$ eigenstate of $X$ ($\langle X\rangle = 1$); the mix is utterly
random in *every* basis ($\langle X\rangle = 0$). The coherence in $\rho_+$ is physically real and
measurable — it just doesn't show up in the $Z$ basis.

### Example 2 — Expectation and purity of a biased single-basis mix

Let $\rho = \tfrac34|0\rangle\langle0| + \tfrac14|1\rangle\langle1| = \begin{psmallmatrix}3/4 & 0\\ 0 & 1/4\end{psmallmatrix}$
(diagonal, so already in its eigenbasis with $\lambda = \tfrac34, \tfrac14$).

*Trace check:* $\tfrac34 + \tfrac14 = 1$. ✓ *Positivity:* eigenvalues $\tfrac34,\tfrac14 \ge 0$. ✓

*Expectation of $Z = \operatorname{diag}(1,-1)$:*

$$
\langle Z\rangle = \operatorname{Tr}(\rho Z) = \tfrac34(1) + \tfrac14(-1) = \tfrac12 .
$$

(Equivalently, $P(0) - P(1) = \tfrac34 - \tfrac14 = \tfrac12$.)

*Expectation of $X$:* $\rho X = \begin{psmallmatrix}3/4&0\\0&1/4\end{psmallmatrix}\begin{psmallmatrix}0&1\\1&0\end{psmallmatrix}
= \begin{psmallmatrix}0&3/4\\1/4&0\end{psmallmatrix}$, which is traceless, so $\langle X\rangle = 0$.

*Purity:* $\operatorname{Tr}(\rho^2) = (\tfrac34)^2 + (\tfrac14)^2 = \tfrac{9}{16} + \tfrac1{16}
= \tfrac{10}{16} = \tfrac58 = 0.625$. Since $1/2 < 0.625 < 1$, this is a genuinely mixed state — more
ordered than maximally mixed, less than pure. We will read this same number off the Bloch vector
$\vec r = (0,0,\tfrac12)$ via $\operatorname{Tr}\rho^2 = \tfrac12(1 + |\vec r|^2) = \tfrac12(1 + \tfrac14)
= \tfrac58$ in Lesson 3.

---

## Hands-on (Python)

We build pure and mixed density matrices, verify the defining properties, compute expectations via
$\operatorname{Tr}(\rho A)$, measure purity, and exhibit ensemble ambiguity. NumPy is the natural home
for density matrices — they are just Hermitian arrays.

```python
import numpy as np

# --- Pauli matrices and computational basis (Appendix E) ---
I = np.eye(2, dtype=complex)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]], dtype=complex)
Z = np.array([[1, 0], [0, -1]], dtype=complex)
ket0 = np.array([[1], [0]], dtype=complex)
ket1 = np.array([[0], [1]], dtype=complex)

def proj(ket):
    """Rank-1 projector |ψ⟩⟨ψ| from a column ket (assumed normalized)."""
    return ket @ ket.conj().T

def density_from_ensemble(probs, kets):
    """ρ = Σ_i p_i |ψ_i⟩⟨ψ_i| for probabilities `probs` and column kets `kets`."""
    return sum(p * proj(k) for p, k in zip(probs, kets))

# Pure |+⟩ vs. classical 50/50 mix of |0⟩,|1⟩ (Worked Example 1)
plus = (ket0 + ket1) / np.sqrt(2)
rho_pure = proj(plus)
rho_mix  = density_from_ensemble([0.5, 0.5], [ket0, ket1])

print("rho_pure =\n", np.round(rho_pure, 3))
print("rho_mix  =\n", np.round(rho_mix, 3))
# rho_pure has off-diagonal 0.5 coherences; rho_mix is diag(0.5, 0.5) = I/2.
```

```python
def is_valid_state(rho, tol=1e-9):
    """Check the three defining properties: Hermitian, PSD, unit trace."""
    hermitian = np.allclose(rho, rho.conj().T, atol=tol)
    eigs = np.linalg.eigvalsh((rho + rho.conj().T) / 2)   # symmetrize for safety
    psd = np.all(eigs >= -tol)
    unit_trace = np.isclose(np.trace(rho).real, 1.0, atol=tol)
    return hermitian and psd and unit_trace

for name, rho in [("pure", rho_pure), ("mix", rho_mix)]:
    print(name, "valid state?", is_valid_state(rho))   # both True

def expectation(rho, A):
    """⟨A⟩ = Tr(ρ A); real for Hermitian A."""
    return np.trace(rho @ A).real

def purity(rho):
    """Tr(ρ²) ∈ [1/d, 1]; equals 1 iff pure."""
    return np.trace(rho @ rho).real

# ⟨X⟩ separates the two states even though ⟨Z⟩ does not:
print("⟨Z⟩ pure/mix:", expectation(rho_pure, Z), expectation(rho_mix, Z))  # 0.0 0.0
print("⟨X⟩ pure/mix:", expectation(rho_pure, X), expectation(rho_mix, X))  # 1.0 0.0
print("purity pure/mix:", purity(rho_pure), purity(rho_mix))               # 1.0 0.5
```

```python
# Ensemble ambiguity: two different ensembles, identical ρ = I/2.
plus  = (ket0 + ket1) / np.sqrt(2)
minus = (ket0 - ket1) / np.sqrt(2)

rho_Z = density_from_ensemble([0.5, 0.5], [ket0, ket1])     # Z-basis coin flip
rho_X = density_from_ensemble([0.5, 0.5], [plus, minus])    # X-basis coin flip
print("Same operator?", np.allclose(rho_Z, rho_X))          # True  -> indistinguishable
print(np.round(rho_X, 3))                                   # I/2

# Unitary evolution ρ → U ρ U†: a pure state stays pure, a mix stays mixed.
from scipy.linalg import expm
H_gate = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)   # Hadamard (a unitary)
print("purity after H (pure):", purity(H_gate @ rho_pure @ H_gate.conj().T))  # 1.0
print("purity after H (mix): ", purity(H_gate @ rho_mix  @ H_gate.conj().T))  # 0.5
# H rotates |+⟩ to |0⟩ (still pure); I/2 is invariant under any unitary.
```

> **Numerical note.** Density matrices accumulate tiny imaginary parts and sub-zero eigenvalues from
> floating-point error. Take `.real` of expectations/purities (the exact values are real), and
> symmetrize with `(ρ + ρ†)/2` before calling `eigvalsh`, as `is_valid_state` does. This is the same
> hygiene Term 4's noise simulations rely on.

---

## Exercises

**E1 (easy).** Write the density matrix for the ensemble "$|0\rangle$ with probability $\tfrac13$,
$|+\rangle$ with probability $\tfrac23$" as an explicit $2\times2$ matrix, and verify
$\operatorname{Tr}\rho = 1$.

<details><summary>Solution</summary>

$|0\rangle\langle0| = \begin{psmallmatrix}1&0\\0&0\end{psmallmatrix}$ and $|+\rangle\langle+| =
\tfrac12\begin{psmallmatrix}1&1\\1&1\end{psmallmatrix}$. So
$$
\rho = \tfrac13\begin{pmatrix}1&0\\0&0\end{pmatrix} + \tfrac23\cdot\tfrac12\begin{pmatrix}1&1\\1&1\end{pmatrix}
= \begin{pmatrix}\tfrac13 + \tfrac13 & \tfrac13\\[2pt] \tfrac13 & \tfrac13\end{pmatrix}
= \begin{pmatrix}\tfrac23 & \tfrac13\\[2pt] \tfrac13 & \tfrac13\end{pmatrix}.
$$
Trace $= \tfrac23 + \tfrac13 = 1$. ✓ (Hermitian and, since both diagonal entries are $\ge$ the
off-diagonal in the right way, one checks $\det = \tfrac29 - \tfrac19 = \tfrac19 \ge 0$ with positive
trace, so PSD — it is a valid state.)
</details>

**E2 (easy).** Show directly from the matrices that $\rho = |+\rangle\langle+|$ satisfies $\rho^2 =
\rho$, while $\rho = \tfrac12 I$ does not. What does each conclude about purity?

<details><summary>Solution</summary>

$|+\rangle\langle+| = \tfrac12\begin{psmallmatrix}1&1\\1&1\end{psmallmatrix}$, and
$\big(\tfrac12\begin{psmallmatrix}1&1\\1&1\end{psmallmatrix}\big)^2 = \tfrac14\begin{psmallmatrix}2&2\\2&2\end{psmallmatrix}
= \tfrac12\begin{psmallmatrix}1&1\\1&1\end{psmallmatrix}$ — equal, so $\rho^2 = \rho$: **pure**. For
$\tfrac12 I$, $(\tfrac12 I)^2 = \tfrac14 I \ne \tfrac12 I$: **not** idempotent, so mixed. Purities:
$\operatorname{Tr}(\rho^2) = 1$ vs. $\operatorname{Tr}(\tfrac14 I) = \tfrac12$.
</details>

**E3 (medium).** Prove that $\langle A\rangle = \operatorname{Tr}(\rho A)$ is **real** whenever $A$ is
Hermitian, directly from properties of $\rho$ and $A$ (do not assume $\rho$ is pure).

<details><summary>Solution</summary>

$\overline{\operatorname{Tr}(\rho A)} = \operatorname{Tr}\big((\rho A)^\dagger\big) = \operatorname{Tr}(A^\dagger\rho^\dagger)
= \operatorname{Tr}(A\rho) = \operatorname{Tr}(\rho A)$, using $\overline{\operatorname{Tr}(M)} =
\operatorname{Tr}(M^\dagger)$, then $A^\dagger = A$, $\rho^\dagger = \rho$, and cyclicity of the trace.
A number equal to its own conjugate is real. ∎
</details>

**E4 (medium).** Let $\rho = p\,|0\rangle\langle0| + (1-p)\,|1\rangle\langle1|$ for $p\in[0,1]$. Compute
$\operatorname{Tr}(\rho^2)$ as a function of $p$, find where it is minimized and maximized, and
interpret.

<details><summary>Solution</summary>

$\rho = \operatorname{diag}(p, 1-p)$, so $\operatorname{Tr}(\rho^2) = p^2 + (1-p)^2 = 1 - 2p(1-p)
= 2p^2 - 2p + 1$. Minimizing: $\frac{d}{dp}(2p^2 - 2p + 1) = 4p - 2 = 0 \Rightarrow p = \tfrac12$,
giving purity $\tfrac12$ — the maximally mixed qubit. Maxima at the endpoints $p = 0$ or $p = 1$,
giving purity $1$ — the pure states $|1\rangle$ or $|0\rangle$. Purity is a downward parabola in $p$:
most mixed at the fair coin, pure at the certain outcomes.
</details>

**E5 (hard).** Prove that a density operator $\rho$ is pure **iff** $\operatorname{Tr}(\rho^2) = 1$
(closing the loop with the $\rho^2 = \rho$ test).

<details><summary>Solution</summary>

Diagonalize $\rho = \sum_k\lambda_k|v_k\rangle\langle v_k|$ with $\lambda_k\ge0$, $\sum_k\lambda_k = 1$.
Then $\operatorname{Tr}(\rho^2) = \sum_k\lambda_k^2$. Since $0\le\lambda_k\le1$ we have $\lambda_k^2\le
\lambda_k$, so $\sum_k\lambda_k^2 \le \sum_k\lambda_k = 1$, with equality **iff** $\lambda_k^2 = \lambda_k$
for every $k$, i.e. each $\lambda_k\in\{0,1\}$. Combined with $\sum_k\lambda_k = 1$, exactly one
$\lambda_k = 1$ and the rest vanish, so $\rho = |v_k\rangle\langle v_k|$ is pure. Conversely a pure
$\rho$ has eigenvalues $(1,0,\dots)$ giving $\operatorname{Tr}(\rho^2) = 1$. ∎
</details>

**E6 (hard).** *(Unitary freedom, qubit case.)* Two qubit ensembles
$\{(\tfrac12,|0\rangle),(\tfrac12,|1\rangle)\}$ and $\{(\tfrac12,|+\rangle),(\tfrac12,|-\rangle)\}$
both give $\rho = \tfrac12 I$. Exhibit a $2\times2$ unitary $V$ relating the (sub-normalized) state
vectors $\{\sqrt{p_i}|\psi_i\rangle\}$ of the two ensembles, confirming the HJW theorem in this case.

<details><summary>Solution</summary>

The sub-normalized vectors are $|\tilde a_0\rangle = \tfrac1{\sqrt2}|0\rangle$, $|\tilde a_1\rangle =
\tfrac1{\sqrt2}|1\rangle$ for the first ensemble, and $|\tilde b_0\rangle = \tfrac1{\sqrt2}|+\rangle$,
$|\tilde b_1\rangle = \tfrac1{\sqrt2}|-\rangle$ for the second. HJW asks for unitary $V = (V_{ji})$ with
$|\tilde b_j\rangle = \sum_i V_{ji}|\tilde a_i\rangle$. Writing $|+\rangle = \tfrac1{\sqrt2}(|0\rangle +
|1\rangle)$, $|-\rangle = \tfrac1{\sqrt2}(|0\rangle - |1\rangle)$ gives $\tfrac1{\sqrt2}|+\rangle =
\tfrac1{\sqrt2}\big(\tfrac1{\sqrt2}|0\rangle + \tfrac1{\sqrt2}|1\rangle\big) = \tfrac1{\sqrt2}|\tilde a_0\rangle
+ \tfrac1{\sqrt2}|\tilde a_1\rangle$ and similarly for $|-\rangle$. So
$$
V = \tfrac1{\sqrt2}\begin{pmatrix}1 & 1\\ 1 & -1\end{pmatrix} = H,
$$
the Hadamard, which is unitary. The same Hadamard that maps the $Z$ basis to the $X$ basis maps one
ensemble's vectors to the other's — making $\rho = \tfrac12 I$ from either. ∎
</details>

---

## Checkpoint

1. Give two physically distinct situations that *require* a density operator rather than a ket.
2. State the three properties that characterize a valid density operator, and which one encodes
   "probabilities sum to 1."
3. How do you test whether $\rho$ is pure, two different ways?
4. Derive $\langle A\rangle = \operatorname{Tr}(\rho A)$ from the ensemble average. Why does it imply
   ensemble ambiguity?
5. Write the evolution rule for $\rho$ under a unitary $U$, and argue it preserves purity.

<details><summary>Answers</summary>

1. (i) Classical uncertainty about which pure state was prepared (an ensemble / "noisy preparation");
   (ii) a subsystem of an entangled pure state, which has no ket of its own (Lesson 2).
2. $\rho^\dagger = \rho$ (Hermitian, real spectrum), $\rho\succeq0$ (positive, eigenvalues are
   probabilities), $\operatorname{Tr}\rho = 1$ — the last encodes "probabilities sum to 1."
3. $\rho^2 = \rho$ (idempotent ⇔ pure), or equivalently $\operatorname{Tr}(\rho^2) = 1$ (purity $= 1$).
4. $\langle A\rangle = \sum_i p_i\langle\psi_i|A|\psi_i\rangle = \sum_i p_i\operatorname{Tr}(A|\psi_i\rangle\langle\psi_i|)
   = \operatorname{Tr}(A\rho)$. Since every expectation depends on the ensemble only through $\rho$, two
   ensembles with the same $\rho$ produce identical statistics for all $A$ — indistinguishable.
5. $\rho\to U\rho U^\dagger$. Purity is invariant: $\operatorname{Tr}((U\rho U^\dagger)^2) =
   \operatorname{Tr}(U\rho^2U^\dagger) = \operatorname{Tr}(\rho^2)$ by cyclicity, so pure stays pure and
   mixing requires non-unitary dynamics (Term 4).

</details>

---

## Further Reading

- **[NC]** Nielsen & Chuang, §2.4 — the density operator, ensembles, and the unitary-freedom theorem
  (their §2.4.3 is the HJW result used in E6).
- **[Pre]** Preskill, *Ph219*, Ch. 2–3 — density operators and the physics of mixed states.
- **[Wat]** Watrous, *Theory of Quantum Information*, Ch. 2 — density operators as the state objects of
  quantum information, with full rigor.
- **[Appendix E §1, §4](../../appendix/E-math-identities.md)** — Pauli/trace identities used throughout.

---

← Prev: [Schmidt Decomposition](../c04-entanglement/04-schmidt-decomposition.md) · Up: [Term 1](../README.md) · Next: [Partial Trace & Reduced States](02-partial-trace-reduced-states.md) →
