
# Dirac Notation

> Dirac's bra–ket notation is the language of the entire field. It is not new mathematics — it is a
> brilliant *repackaging* of the inner product spaces you just built, designed so that the algebra
> reads like sentences and the bookkeeping does itself. Every later lesson, every paper, and the
> Braket SDK's mental model all speak this dialect. Master it now and the rest of the program reads
> fluently.

## Learning Objectives

After this lesson you will be able to:

1. Translate fluently between column-vector/matrix notation and **bra–ket** notation.
2. Interpret a **bra** $\langle\phi|$ as a linear functional (the dual of a ket) via the Riesz lemma.
3. Compute **inner products** $\langle\phi|\psi\rangle$ and **outer products** $|\psi\rangle\langle\phi|$.
4. Apply the **completeness relation** (resolution of the identity) to expand states and operators.
5. Read and write **matrix elements** $\langle i|A|j\rangle$.

---

## Intuition

Write a state vector as a **ket** $|\psi\rangle$. Its conjugate-transpose — the object that "eats a
ket and returns a number via the inner product" — is the **bra** $\langle\psi|$. Put a bra next to a
ket and the notation literally forms a **bra(c)ket** $\langle\phi|\psi\rangle$: a number, the overlap.
Put them the other way, $|\psi\rangle\langle\phi|$, and you get an **operator** (a matrix). The
genius is that the symbols snap together exactly the way the math allows, so manipulations become
almost mechanical:

$$
\underbrace{\langle\phi|}_{\text{row}}\;\underbrace{|\psi\rangle}_{\text{column}} = \text{number}, \qquad
\underbrace{|\psi\rangle}_{\text{column}}\;\underbrace{\langle\phi|}_{\text{row}} = \text{matrix}.
$$

---

## Theory

### Kets

A **ket** $|\psi\rangle$ is just a vector in a Hilbert space $\mathcal{H}$ (for us $\mathbb{C}^n$). In
coordinates relative to the computational basis,

$$
|\psi\rangle = \sum_k c_k\,|k\rangle \;\longleftrightarrow\; \begin{pmatrix} c_0 \\ c_1 \\ \vdots \\ c_{n-1}\end{pmatrix},
\qquad c_k \in \mathbb{C}.
$$

For a qubit, $|0\rangle = \begin{psmallmatrix}1\\0\end{psmallmatrix}$, $|1\rangle = \begin{psmallmatrix}0\\1\end{psmallmatrix}$.
The labels inside the ket are mnemonic — $|{\uparrow}\rangle$, $|0\rangle$, $|\psi\rangle$, $|01\rangle$
are all just names for vectors.

### The dual space and bras

The **dual space** $\mathcal{H}^*$ is the set of linear maps (functionals) $f:\mathcal{H}\to\mathbb{C}$.
The **Riesz representation theorem** (finite-dimensional case) says every such $f$ is "take the inner
product with some fixed vector $\phi$":

$$
\text{for each linear } f \;\exists!\, |\phi\rangle \text{ such that } f(|\psi\rangle) = \langle\phi|\psi\rangle\ \ \forall|\psi\rangle.
$$

We name this functional the **bra** $\langle\phi|$. So a bra *is* "the inner product, waiting for its
second argument." In coordinates, if $|\phi\rangle$ has components $(d_k)$, then

$$
\langle\phi| = |\phi\rangle^\dagger = \big(\overline{d_0},\ \overline{d_1},\ \dots,\ \overline{d_{n-1}}\big)
\quad\text{(a row vector — conjugate transpose of the ket).}
$$

The conjugation is the conjugate-linearity from [0.1.2](02-inner-products-norms.md): $\langle a\phi| =
\overline{a}\,\langle\phi|$, while $|a\psi\rangle = a\,|\psi\rangle$.

### Inner product as a bracket

The inner product becomes the **bracket**

$$
\langle\phi|\psi\rangle = \langle\phi| \,\big(|\psi\rangle\big) = \sum_k \overline{d_k}\, c_k .
$$

All the [0.1.2](02-inner-products-norms.md) facts restated: $\langle\psi|\psi\rangle = \||\psi\rangle\|^2 \ge 0$;
$\langle\phi|\psi\rangle = \overline{\langle\psi|\phi\rangle}$; orthonormal basis $\langle i|j\rangle = \delta_{ij}$;
a normalized state has $\langle\psi|\psi\rangle = 1$.

### Outer products are operators

Reverse the order: $|\psi\rangle\langle\phi|$ is (column)(row) = an $n\times n$ **matrix**, hence a
**linear operator**. It acts on a ket by the associativity of the notation:

$$
\big(|\psi\rangle\langle\phi|\big)\,|\chi\rangle = |\psi\rangle\,\underbrace{\langle\phi|\chi\rangle}_{\text{number}} = \langle\phi|\chi\rangle\,|\psi\rangle .
$$

The most important case is a **projector** onto a normalized state: $P_\psi = |\psi\rangle\langle\psi|$
satisfies $P_\psi^2 = P_\psi$ (it projects, idempotently). Example for a qubit:

$$
|0\rangle\langle 0| = \begin{pmatrix}1\\0\end{pmatrix}\begin{pmatrix}1 & 0\end{pmatrix} = \begin{pmatrix}1 & 0\\0 & 0\end{pmatrix}.
$$

### The completeness relation (resolution of identity)

For any orthonormal basis $\{|k\rangle\}$,

$$
\boxed{\ \sum_k |k\rangle\langle k| = I\ }
$$

This single identity is the most-used trick in the subject. **Derivation:** apply the left side to an
arbitrary $|\psi\rangle$: $\sum_k |k\rangle\langle k|\psi\rangle = \sum_k \langle k|\psi\rangle\,|k\rangle$,
which is exactly the ONB expansion of $|\psi\rangle$ from [0.1.2](02-inner-products-norms.md) — i.e.
$|\psi\rangle$ itself. Since it returns every $|\psi\rangle$ unchanged, the operator is $I$. ∎

You "insert a complete set of states" $I = \sum_k|k\rangle\langle k|$ anywhere to switch into a basis:

$$
\langle\phi|\psi\rangle = \langle\phi|\,I\,|\psi\rangle = \sum_k \langle\phi|k\rangle\langle k|\psi\rangle .
$$

### Matrix elements

The $(i,j)$ entry of an operator $A$ in the basis $\{|k\rangle\}$ is the **matrix element**

$$
A_{ij} = \langle i|A|j\rangle .
$$

Two completeness insertions reconstruct the whole operator from its matrix elements:

$$
A = I A I = \sum_{i,j} |i\rangle\langle i|A|j\rangle\langle j| = \sum_{i,j} A_{ij}\,|i\rangle\langle j| .
$$

So "$A$ as a matrix" and "$A = \sum_{ij} A_{ij}|i\rangle\langle j|$" are the same statement.

> **Endianness reminder.** For multi-qubit kets we use **big-endian** labels: $|q_0 q_1\cdots\rangle$
> with qubit 0 leftmost, matching Braket's bit-strings (see [Appendix C](../../appendix/C-notation-glossary.md)).
> E.g. $|01\rangle = |0\rangle\otimes|1\rangle$ — tensor products are formalized in
> [0.1.7](07-tensor-products.md).

---

## Worked Examples

### Example 1 — Brackets, bras, and a projector

Let $|\psi\rangle = \tfrac1{\sqrt2}(|0\rangle + i|1\rangle)$.

Bra: $\langle\psi| = \tfrac1{\sqrt2}(\langle 0| - i\langle 1|)$ (note the sign flip from conjugation).
Norm: $\langle\psi|\psi\rangle = \tfrac12(\langle0|0\rangle - i\langle0|1\rangle + i\langle1|0\rangle - i\cdot i\langle1|1\rangle)
= \tfrac12(1 + 0 + 0 + 1) = 1$. ✓
Projector:

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

### Example 2 — Completeness in action

Compute $\langle + | 0\rangle$ by inserting the computational-basis completeness $I = |0\rangle\langle0| + |1\rangle\langle1|$:

$$
\langle +|0\rangle = \langle +|\big(|0\rangle\langle0| + |1\rangle\langle1|\big)|0\rangle
= \langle+|0\rangle\langle0|0\rangle + \langle+|1\rangle\langle1|0\rangle
= \tfrac1{\sqrt2}\cdot 1 + \tfrac1{\sqrt2}\cdot 0 = \tfrac1{\sqrt2}.
$$

(Trivial here, but the *technique* — insert $I$, split into known overlaps — is exactly how QFT and
phase-estimation derivations proceed in Term 2.)

---

## Hands-on (Python)

NumPy makes the bra/ket/outer correspondence literal.

```python
import numpy as np

ket0 = np.array([[1], [0]], dtype=complex)   # column vector = ket |0>
ket1 = np.array([[0], [1]], dtype=complex)   # column vector = ket |1>

def bra(ket):
    """⟨ψ| = |ψ⟩† : conjugate transpose turns a column ket into a row bra."""
    return ket.conj().T

# Bracket ⟨0|1⟩ is a 1x1 matrix (a number):
print((bra(ket0) @ ket1).item())             # 0j   (orthogonal)

psi = (ket0 + 1j * ket1) / np.sqrt(2)
print((bra(psi) @ psi).item())               # (1+0j)  normalized

# Outer product |ψ⟩⟨ψ| is a 2x2 operator (projector):
P = psi @ bra(psi)
print(np.round(P, 3))
# [[0.5+0.j  0. -0.5j]
#  [0. +0.5j 0.5+0.j ]]
print(np.allclose(P @ P, P))                 # True: projectors are idempotent
```

```python
# Completeness relation: sum_k |k><k| = I
basis = [ket0, ket1]
completeness = sum(k @ bra(k) for k in basis)
print(np.allclose(completeness, np.eye(2)))  # True

# Matrix element A_ij = <i|A|j>:
A = np.array([[1, 2], [3, 4]], dtype=complex)
A01 = (bra(ket0) @ A @ ket1).item()
print(A01)                                   # (2+0j)  -> the (0,1) entry
```

> Many people work with 1-D arrays (`np.array([1,0])`) and rely on `np.vdot`/`np.outer` instead of
> explicit columns. Both are fine; we use explicit `(n,1)` columns here so `@` mirrors the bra–ket
> algebra one-to-one. Pick one convention per project and stay consistent.

---

## Exercises

**E1 (easy).** Write the bra corresponding to $|\psi\rangle = (2+i)|0\rangle - 3i|1\rangle$ and compute
$\langle\psi|\psi\rangle$.

<details><summary>Solution</summary>

$\langle\psi| = (2-i)\langle0| + 3i\langle1|$. Then $\langle\psi|\psi\rangle = |2+i|^2 + |{-3i}|^2 = (4+1) + 9 = 14$.
(So $|\psi\rangle$ is *not* normalized; dividing by $\sqrt{14}$ would normalize it.)
</details>

**E2 (easy).** Compute the outer product $|0\rangle\langle 1|$ as a $2\times2$ matrix and describe what
operator it is.

<details><summary>Solution</summary>

$|0\rangle\langle1| = \begin{psmallmatrix}1\\0\end{psmallmatrix}\begin{psmallmatrix}0 & 1\end{psmallmatrix}
= \begin{psmallmatrix}0 & 1\\ 0 & 0\end{psmallmatrix}$. It maps $|1\rangle \mapsto |0\rangle$ and
$|0\rangle\mapsto 0$ — a "lowering"-type operator (it's the qubit $\sigma_- $-like map, not unitary).
</details>

**E3 (medium).** Using completeness $\sum_k|k\rangle\langle k| = I$, prove that for any operator $A$,
$\operatorname{Tr}(A) = \sum_k \langle k|A|k\rangle$ is independent of the orthonormal basis chosen.

<details><summary>Solution</summary>

Let $\{|k\rangle\}$ and $\{|m'\rangle\}$ be two ONBs. Insert completeness of the primed basis:
$\sum_k\langle k|A|k\rangle = \sum_k \langle k| \big(\sum_{m}|m'\rangle\langle m'|\big) A |k\rangle$.
Rearranging the scalars and using $\sum_k |k\rangle\langle k| = I$ again,
$= \sum_m \langle m'|A\big(\sum_k|k\rangle\langle k|\big)|m'\rangle = \sum_m\langle m'|A|m'\rangle$.
So the trace is basis-independent. ∎
</details>

**E4 (medium).** Show $\big(|\psi\rangle\langle\phi|\big)^\dagger = |\phi\rangle\langle\psi|$.

<details><summary>Solution</summary>

For matrices $(AB)^\dagger = B^\dagger A^\dagger$. Here $A = |\psi\rangle$ (column) and $B = \langle\phi|$
(row $= |\phi\rangle^\dagger$). So $\big(|\psi\rangle\langle\phi|\big)^\dagger = \langle\phi|^\dagger |\psi\rangle^\dagger
= |\phi\rangle\langle\psi|$. ∎ (Hence projectors $|\psi\rangle\langle\psi|$ are Hermitian.)
</details>

**E5 (hard).** Let $\{|u_k\rangle\}$ be an ONB. Prove the "trace trick" $\langle\phi|A|\psi\rangle =
\operatorname{Tr}\!\big(A\,|\psi\rangle\langle\phi|\big)$, and use it to express an expectation value
$\langle\psi|A|\psi\rangle$ as a trace.

<details><summary>Solution</summary>

$\operatorname{Tr}(A|\psi\rangle\langle\phi|) = \sum_k \langle u_k|A|\psi\rangle\langle\phi|u_k\rangle
= \langle\phi|\Big(\sum_k |u_k\rangle\langle u_k|\Big)A|\psi\rangle = \langle\phi|A|\psi\rangle$,
using completeness and reordering the scalar $\langle\phi|u_k\rangle$. Setting $\phi = \psi$:
$\langle\psi|A|\psi\rangle = \operatorname{Tr}(A|\psi\rangle\langle\psi|) = \operatorname{Tr}(A\rho)$
with $\rho = |\psi\rangle\langle\psi|$ — the density-matrix expectation formula previewed for
[Term 1.5](../../term-1-quantum-mechanics/c05-density-matrices/01-density-operator.md). ∎
</details>

---

## Checkpoint

1. What is a bra, formally, and how does the Riesz theorem justify the notation?
2. Why does forming $\langle\phi|\psi\rangle$ give a number but $|\psi\rangle\langle\phi|$ give an operator?
3. State the completeness relation and explain the "insert the identity" technique.
4. How do you read off the matrix element $A_{ij}$ in bra–ket notation?
5. Show in one line that $|\psi\rangle\langle\psi|$ is a projector when $\langle\psi|\psi\rangle=1$.

<details><summary>Answers</summary>

1. A bra $\langle\phi|$ is the linear functional $|\psi\rangle\mapsto\langle\phi|\psi\rangle$; Riesz
   guarantees every linear functional has this form for a unique $|\phi\rangle$, so bras ↔ kets bijectively
   (via conjugate transpose).
2. (row)(column) contracts all indices → scalar; (column)(row) leaves two free indices → matrix.
3. $\sum_k|k\rangle\langle k| = I$ for any ONB; you may insert $I$ in this form anywhere to expand in
   that basis without changing the expression.
4. $A_{ij} = \langle i|A|j\rangle$.
5. $(|\psi\rangle\langle\psi|)^2 = |\psi\rangle\langle\psi|\psi\rangle\langle\psi| = |\psi\rangle\langle\psi|$
   since $\langle\psi|\psi\rangle = 1$.

</details>

---

## Further Reading

- **[NC]** Nielsen & Chuang, §2.1.3–2.1.6 — the Dirac formalism, outer products, completeness.
- **[Sak]** Sakurai & Napolitano, §1.2–1.3 — kets, bras, and operators, the physicist's introduction.
- **[Pre]** Preskill, *Ph219*, Ch. 2.

---

← Prev: [Inner Products & Norms](02-inner-products-norms.md) · Up: [Term 0](../README.md) · Next: [Linear Operators & Matrices](04-linear-operators-matrices.md) →
