Course Home

The n-Qubit Hadamard Transform

An Interactive Exploration of Tensor Products, GF(2), and Quantum Superposition

Why the Hadamard Transform?

The Hadamard transform is one of the most fundamental operations in quantum computing. It creates superpositions from definite states, bridges the computational and Hadamard bases, and is at the heart of nearly every quantum algorithm — from Deutsch-Jozsa to Grover's search to Shor's factoring.

This interactive guide builds the n-qubit Hadamard transform from the ground up. Along the way, we will discover how tensor products combine single-qubit operations, how the bilinear form over GF(2) determines every matrix entry, and how the transform acts on uniform superpositions over subspaces and cosets.

The Single-Qubit Hadamard Gate

A single qubit lives in a 2-dimensional space spanned by the computational basis states \(|0\rangle\) and \(|1\rangle\). The Hadamard gate \(H\) is defined by the matrix:

\[ H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \]

Its action on the basis states is:

\[ H|0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}} = |{+}\rangle, \qquad H|1\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}} = |{-}\rangle \]

Notice the pattern: the coefficient of \(|y\rangle\) in \(H|x\rangle\) is \(\frac{1}{\sqrt{2}}(-1)^{x \cdot y}\), where \(x \cdot y\) is just the product of two bits. When \(x=0\), all signs are positive. When \(x=1\), the sign of \(|1\rangle\) flips.

\[ H|x\rangle = \frac{1}{\sqrt{2}} \sum_{y \in \{0,1\}} (-1)^{xy}\,|y\rangle \]
Interactive: Single-Qubit Hadamard

Scaling Up: Tensor Products

To apply Hadamard to multiple qubits, we use the tensor product (Kronecker product). If \(H\) acts on one qubit, then \(H^{\otimes n} = \underbrace{H \otimes H \otimes \cdots \otimes H}_{n}\) acts on \(n\) qubits independently.

The key property of the tensor product for operators is:

\[ (A \otimes B)\,(|\psi\rangle \otimes |\phi\rangle) = (A|\psi\rangle) \otimes (B|\phi\rangle) \]

As a matrix, \(A \otimes B\) is built by replacing each entry \(a_{ij}\) of \(A\) with the block \(a_{ij} \cdot B\). For \(H \otimes H\):

Visual: Tensor Product Block Structure

Hover over a block in \(H^{\otimes 2}\) to see which entry of \(H\) it corresponds to. Each 2×2 block is a copy of \(H\) scaled by the corresponding entry of \(H\).

Key insight: Because \(H^{\otimes n}\) applies \(H\) independently to each qubit, we can factor the action on any product state: \(H^{\otimes n}|x_1 x_2 \cdots x_n\rangle = H|x_1\rangle \otimes H|x_2\rangle \otimes \cdots \otimes H|x_n\rangle\).

The GF(2) Bilinear Form

\(\text{GF}(2)\) is the finite field with two elements: \(\{0, 1\}\), where addition is XOR (so \(1 + 1 = 0\)) and multiplication is AND.

An \(n\)-bit string \(x = x_1 x_2 \cdots x_n\) is a vector in \(\text{GF}(2)^n\). The bilinear form (dot product) over \(\text{GF}(2)\) is:

\[ x \cdot y = x_1 y_1 \oplus x_2 y_2 \oplus \cdots \oplus x_n y_n \]

This is computed as: multiply corresponding bits (AND), then XOR all the products. The result is always 0 or 1.

Interactive: GF(2) Dot Product Calculator
Key connection: The sign \((-1)^{x \cdot y}\) is +1 when \(x \cdot y = 0\) and −1 when \(x \cdot y = 1\). This single bit completely determines the sign of each entry in the Hadamard matrix.

The n-Qubit Hadamard Formula

Combining the tensor product structure with the single-qubit formula, we can derive the action of \(H^{\otimes n}\) on any computational basis state.

Start with a basis state \(|x\rangle = |x_1 x_2 \cdots x_n\rangle\). Factor using the tensor product: \[ H^{\otimes n}|x\rangle = H|x_1\rangle \otimes H|x_2\rangle \otimes \cdots \otimes H|x_n\rangle \]
Substitute the single-qubit formula \(H|x_i\rangle = \frac{1}{\sqrt{2}} \sum_{y_i} (-1)^{x_i y_i}|y_i\rangle\): \[ = \bigotimes_{i=1}^{n} \frac{1}{\sqrt{2}} \sum_{y_i \in \{0,1\}} (-1)^{x_i y_i}|y_i\rangle \]
Distribute the product over the sums. The exponents add: \[ = \frac{1}{\sqrt{2^n}} \sum_{y \in \{0,1\}^n} (-1)^{x_1 y_1 + x_2 y_2 + \cdots + x_n y_n}|y\rangle \]
Recognize the GF(2) dot product in the exponent: \[ \boxed{\;H^{\otimes n}|x\rangle = \frac{1}{\sqrt{2^n}} \sum_{y \in \{0,1\}^n} (-1)^{x \cdot y}\,|y\rangle\;} \]

Each matrix entry is therefore \(\bigl(H^{\otimes n}\bigr)_{y,x} = \frac{1}{\sqrt{2^n}}(-1)^{x \cdot y}\). The entire matrix is determined by the GF(2) dot product!

Explore the Hadamard Matrix

Interactive: H⊗n Matrix Heatmap

Hover over any cell to see the GF(2) computation. Rows = output \(|y\rangle\), columns = input \(|x\rangle\). Cyan = +1, Red = −1 (before the \(1/\sqrt{2^n}\) factor).

Transform a Basis State

Interactive: State Transformer

Toggle the input bits to see how \(H^{\otimes n}|x\rangle\) changes. Cyan bars = positive amplitude, red bars = negative.

Creating Uniform Superpositions

The most famous application: when the input is \(|0\rangle^{\otimes n}\), all dot products \(0\cdots0 \cdot y = 0\), so every sign is \(+1\):

\[ H^{\otimes n}|0\cdots0\rangle = \frac{1}{\sqrt{2^n}} \sum_{y \in \{0,1\}^n} |y\rangle \]

This is the uniform superposition over all \(2^n\) computational basis states — the standard starting state for most quantum algorithms.

Self-Inverse Property

The Hadamard gate is its own inverse: \(H^2 = I\). This extends to the \(n\)-qubit case: \((H^{\otimes n})^2 = I^{\otimes n} = I\). Applying the Hadamard twice returns to the original state. This is because \(H\) is both unitary (\(HH^\dagger = I\)) and Hermitian (\(H = H^\dagger\)), so \(H^{-1} = H^\dagger = H\).

Interactive: Verify H⊗n · H⊗n = I
Input |x⟩

H⊗n
After first H⊗n

H⊗n
After second H⊗n

No matter what input you choose, applying the Hadamard twice always returns to the original state. The middle chart shows the superposition created by the first application.

Crucial observation: The Hadamard transform converts between the computational basis and the Hadamard basis. A state that is a single basis vector in one basis becomes a uniform superposition in the other. This duality is what makes Hadamard so powerful in quantum algorithms.

Subspaces, Cosets & the Hadamard

The deepest structure of the Hadamard transform emerges when we consider its action on uniform superpositions over subspaces of \(\text{GF}(2)^n\).

Subspaces of GF(2)n

A subspace \(S \subseteq \text{GF}(2)^n\) is a subset that is closed under XOR: if \(s, t \in S\), then \(s \oplus t \in S\). It always contains \(0\cdots0\). A subspace of dimension \(k\) is spanned by \(k\) linearly independent vectors and has \(|S| = 2^k\) elements.

Orthogonal Complement

The orthogonal complement of \(S\) is: \[ S^\perp = \{y \in \text{GF}(2)^n \;:\; x \cdot y = 0 \;\;\text{for all } x \in S\} \] If \(\dim(S) = k\), then \(\dim(S^\perp) = n - k\), so \(|S| \cdot |S^\perp| = 2^n\).

The Subspace Theorem

Let \(|S\rangle = \frac{1}{\sqrt{|S|}}\sum_{s \in S}|s\rangle\) be the uniform superposition over \(S\). Then:

\[ \boxed{\; H^{\otimes n}\,|S\rangle = |S^\perp\rangle \;} \]

The Hadamard maps the uniform superposition over a subspace to the uniform superposition over its orthogonal complement!

Proof sketch: Expand \(H^{\otimes n}|S\rangle\): \[ H^{\otimes n}|S\rangle = \frac{1}{\sqrt{|S|}}\sum_{s \in S} \frac{1}{\sqrt{2^n}} \sum_y (-1)^{s \cdot y}|y\rangle = \frac{1}{\sqrt{|S| \cdot 2^n}} \sum_y \Bigl(\sum_{s \in S}(-1)^{s \cdot y}\Bigr)|y\rangle \]
The inner sum \(\sum_{s \in S}(-1)^{s \cdot y}\) equals \(|S|\) if \(y \in S^\perp\) (all terms are \(+1\)), and 0 otherwise (the terms cancel in pairs). Therefore: \[ H^{\otimes n}|S\rangle = \frac{|S|}{\sqrt{|S| \cdot 2^n}} \sum_{y \in S^\perp}|y\rangle = \frac{1}{\sqrt{|S^\perp|}} \sum_{y \in S^\perp}|y\rangle = |S^\perp\rangle \]

Cosets and Phase Shifts

A coset \(a \oplus S = \{a \oplus s \;:\; s \in S\}\) is a "shifted" copy of the subspace. When we apply the Hadamard to a uniform superposition over a coset:

\[ \boxed{\; H^{\otimes n} \frac{1}{\sqrt{|S|}}\sum_{s \in S}|a \oplus s\rangle = \frac{1}{\sqrt{|S^\perp|}} \sum_{t \in S^\perp} (-1)^{a \cdot t}\,|t\rangle \;} \]

The output still has support on \(S^\perp\), but each amplitude picks up a phase \((-1)^{a \cdot t}\) that depends on the shift vector \(a\). This is the mathematical foundation of Simon's algorithm, Bernstein-Vazirani, and related quantum algorithms.

Interactive: Subspace & Coset Explorer
S = span{basis}  (dim 0, size 1)
S⊥  (dim 0, size 1)
Coset a ⊕ S:
Input: uniform over a ⊕ S
Output: H⊗n applied

Observe: the output is supported exactly on \(S^\perp\). The shift \(a\) only affects the signs (phases) of the amplitudes, not which basis states appear.

Check Your Understanding

1. What is \(H|0\rangle\)?
\(|0\rangle\)
\(\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)\)
\(\frac{1}{\sqrt{2}}(|0\rangle - |1\rangle)\)
2. How many terms appear in the superposition \(H^{\otimes 3}|000\rangle\)?
3
4
8
16
3. What is the GF(2) dot product \(101 \cdot 110\)?
1
0
4. If \(S = \text{span}\{01, 10\}\) in \(\text{GF}(2)^2\), what is \(S^\perp\)?
\(\{00, 01, 10, 11\}\)
\(\{00\}\)
\(\{00, 11\}\)
5. What happens when you apply \(H^{\otimes n}\) twice to any state \(|\psi\rangle\)?
You get the zero state
You get back \(|\psi\rangle\)
You get the uniform superposition over all basis states