First time studying this topic?

Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.

Topic 6.7

The Hadamard Gate: The Superposition Generator

Master the most important single-qubit gate in quantum computing: creating equal superpositions and switching between computational and diagonal bases.

Learning Objectives

  • ✓Define the Hadamard matrix: (1/sqrt(2)) * [[1, 1], [1, -1]]
  • ✓Demonstrate superposition generation: H|0> = |+> and H|1> = |->
  • ✓Visualize Hadamard as a 180-degree rotation around the diagonal (X+Z) axis
  • ✓Understand basis switching: measuring in the X-basis via H followed by Z-measurement

📖Let's Begin with a Story

French mathematician Jacques Hadamard had no idea his 1893 matrix would become the beating heart of quantum computers a century later. If you look at modern quantum circuits, almost every single one begins with a vertical column of H gates. Why? Because every quantum algorithm needs to explore multiple paths. When you start your computer, all your qubits are sleeping in the boring, classical state ∣00…0⟩|00\dots0\rangle. A single flash of the Hadamard Gate strikes every qubit like a tuning fork, kicking them into an equal, shimmering superposition of all possible states simultaneously. The Hadamard gate is the portal connecting the classical world to the quantum multiverse.

Why Should You Learn The Hadamard Gate: The Superposition Generator?

🎯 Practical & Engineering Stakes

The universal workhorse

The Hadamard gate is the most frequently executed gate in quantum computing. It creates superposition, enables basis transformation, and serves as the core of quantum Fourier transforms.

What Is It?

Simple Explanation

The Hadamard gate is the coin spinner: - If you give it ∣0⟩|0\rangle, it starts spinning: ∣+⟩=(∣0⟩+∣1⟩)/2|+\rangle = (|0\rangle + |1\rangle)/\sqrt{2}. - If you give it ∣1⟩|1\rangle, it spins with a negative twist: ∣−⟩=(∣0⟩−∣1⟩)/2|-\rangle = (|0\rangle - |1\rangle)/\sqrt{2}. - If you apply it a second time to the spinning coin, it catches it and stops it back to where it began (H⋅H=IH \cdot H = I)!

Technical Explanation

The Hadamard gate H∈U(2)H \in U(2) is a Hermitian and unitary operator: H=12(111−1)=X+Z2H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \frac{X + Z}{\sqrt{2}} It maps between the computational ZZ-basis {∣0⟩,∣1⟩}\{|0\rangle, |1\rangle\} and the transversal XX-basis {∣+⟩,∣−⟩}\{|+\rangle, |-\rangle\}: H∣0⟩=∣+⟩,H∣1⟩=∣−⟩,H∣+⟩=∣0⟩,H∣−⟩=∣1⟩H|0\rangle = |+\rangle, H|1\rangle = |-\rangle, H|+\rangle = |0\rangle, H|-\rangle = |1\rangle. Geometrically on the Bloch sphere, it represents a π\pi-rotation around the diagonal axis x^+z^2\frac{\hat{x} + \hat{z}}{\sqrt{2}}.

📚 Key Terms

Hadamard Gate (H)

Simple: The gate that creates equal superposition (50/50 chance of 0 or 1).
Technical: Unitary operator mapping ZZ-basis to XX-basis with matrix representation 12[[1,1],[1,−1]]\frac{1}{\sqrt{2}}[[1, 1], [1, -1]].

Basis Transformation

Simple: Changing your measuring perspective from North/South to East/West.
Technical: Unitary transformation rotating state space to diagonalize non-computational observables.

Q-Sphere Lab: The Hadamard Gate: The Superposition Generator

IBM Q-Sphere Model

Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 6.7

Azimuth: 45°Elevation: 25°
+Z |0⟩-Z |1⟩+X |+⟩+Y |+i⟩01|ψ⟩
Q-Sphere Phase Color:
0 π/2 π 3π/2

Quantum Statevector

dim(H) = 2
|ψ⟩ = (1.000 + 0.000i)|0⟩
     + (0.000 + 0.000i)|1⟩
Polar Angle (θ):0.0° (0.000π rad)
Phase Angle (ϕ):0.0° (0.000π rad)

Born Rule Probabilities: P(x) = |⟨x|ψ⟩|²Σ P = 1.00

P(|0⟩) = |α|²100.0%
P(|1⟩) = |β|²0.0%
Quantum Measurement

Apply Single-Qubit Unitary Gates

Presets:
Continuous Polar Angle θ (0° = |0⟩, 180° = |1⟩):0.0°
Continuous Phase Angle ϕ (0° to 360°):0.0°
Recent Operations Log:
#1Initial state: |0⟩

📐 Mathematical Foundation

LaTeX KaTeX
H=12(111−1),H∣0⟩=∣0⟩+∣1⟩2=∣+⟩,H∣1⟩=∣0⟩−∣1⟩2=∣−⟩H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, \quad H |0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}} = |+\rangle, \quad H |1\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}} = |-\rangle

What does it mean?

The Hadamard Gate (Quantum Equalizer): The most fundamental gate in quantum computing. It converts pure classical bits (∣0⟩|0\rangle or ∣1⟩|1\rangle) into 50/50 quantum superpositions (∣+⟩|+\rangle or |–⟩), and vice-versa! Applying H twice returns the state back to the start (H² = I).

Understanding the Symbols

Symbol / TermMeaningBeginner Interpretation
HHHadamard matrixSuperposition generator (1/√2) [[1, 1], [1, -1]]
1/21/\sqrt{2}Normalization factor ≈0.7071\approx 0.7071Ensures (1/2)2=0.50(1/\sqrt{2})^2 = 0.50 (50% probability)
H∣0⟩=∣+⟩H |0\rangle = |+\rangleGround state expansionOpens ∣0⟩|0\rangle into equal superposition with ++ sign
H∣1⟩=∣−⟩H |1\rangle = |-\rangleExcited state expansionOpens ∣1⟩|1\rangle into equal superposition with −- sign

📊 Numerical Example

Demonstrating that applying H twice reverses superposition: H(H |0⟩) = |0⟩:

Step 1: First Hadamard: H ∣0⟩|0\rangle = [1/√2, 1/√2]^T = ∣+⟩|+\rangle (50% chance of 0, 50% chance of 1) Step 2: Second Hadamard: H(H ∣0⟩|0\rangle) = (1/√2) [[1, 1], [1, -1]] × [1/√2, 1/√2]^T = (1/√2) [ (1/√2 + 1/√2), (1/√2 - 1/√2) ]^T = (1/√2) [ 2/√2, 0 ]^T = [ 2/2, 0 ]^T = [1, 0]^T = ∣0⟩|0\rangle ✓

Result: Superposition is completely undone by applying Hadamard a second time (H² = I).

⚙️ How Does It Work?

1

Input Basis

Receives deterministic computational basis state |0> or |1>.

2

Equator Rotation

Rotates vector 180 degrees around diagonal (X+Z) axis onto the Bloch equator.

3

Self-Inverse Property

Because H = H_dagger = H^-1, applying H twice restores original state: H(H|psi>) = |psi>.

🌍 Where Is It Used?

Bernstein-Vazirani & Deutsch-Jozsa Algorithms

Problem: Finding a hidden N-bit binary string in a single black-box query.

Solution: Sandwiching an oracle between layers of Hadamard gates leverages constructive interference to extract the string in $O(1)$ query.

🎯 Try It Yourself

What happens if you apply a Hadamard gate to a qubit, and then immediately apply another Hadamard gate to the same qubit (H followed by H)?

Interactive activity component

🐍 Python Hands-On: Creating Equal Superposition with the Hadamard Gate in Qiskit

Construct the fundamental building block of quantum parallelism: apply the Hadamard gate and verify the basis transformation.

Open Colab

1Install Required Packages

For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:

Terminal / Notebook Install Commandbash
!pip install qiskit
Packages:
qiskit

2Import Libraries

Import Statementspython
1from qiskit import QuantumCircuit
2from qiskit.quantum_info import Statevector

from qiskit import QuantumCircuit → Circuit module

from qiskit.quantum_info import Statevector → Statevector module

3Demonstration Code & Logic

Python Execution Codepython
1# 1. Apply H to |0> -> creates |+> = (|0> + |1>)/sqrt(2)
2qc0 = QuantumCircuit(1)
3qc0.h(0)
4sv0 = Statevector.from_instruction(qc0)
5print('H on |0> -> State |+>:', sv0.data.round(4))
6print('Probabilities:', sv0.probabilities_dict())
7
8# 2. Apply H to |1> -> creates |-> = (|0> - |1>)/sqrt(2)
9qc1 = QuantumCircuit(1)
10qc1.x(0) # Make |1>
11qc1.h(0) # Apply H
12sv1 = Statevector.from_instruction(qc1)
13print('\nH on |1> -> State |->:', sv1.data.round(4))
14print('Probabilities:', sv1.probabilities_dict())
15print('\nNotice: Both have 50% probability, but |-> carries a negative phase!')
Step-by-Step Code Breakdown:

# 1. Apply H to |0> -> creates |+> = (|0> + |1>)/sqrt(2)

H on 0

qc0 = QuantumCircuit(1)

1 qubit

qc0.h(0)

Apply H

sv0 = Statevector.from_instruction(qc0)

Statevector

print('H on |0> -> State |+>:', sv0.data.round(4))

Amplitudes [0.7071, 0.7071]

print('Probabilities:', sv0.probabilities_dict())

{'0': 0.5, '1': 0.5}

# 2. Apply H to |1> -> creates |-> = (|0> - |1>)/sqrt(2)

H on 1

qc1 = QuantumCircuit(1)

1 qubit

qc1.x(0) # Make |1>

Flip to 1

qc1.h(0) # Apply H

Apply H to 1

sv1 = Statevector.from_instruction(qc1)

Statevector

print('\nH on |1> -> State |->:', sv1.data.round(4))

Amplitudes [0.7071, -0.7071]

print('Probabilities:', sv1.probabilities_dict())

{'0': 0.5, '1': 0.5}

print('\nNotice: Both have 50% probability, but |-> carries a negative phase!')

Phase note

📋 Complete Script (All-in-One)

Click "Copy for Colab", open Google Colab, paste into a single cell, and run.

Google Colab Notebook Scriptpython
1# =========================================================
2# Creating Equal Superposition with the Hadamard Gate in Qiskit
3# Prepared for Google Colab (Run with Shift + Enter)
4# =========================================================
5
6# Step 1: Install required packages
7!pip install qiskit
8
9# Step 2: Import libraries
10from qiskit import QuantumCircuit
11from qiskit.quantum_info import Statevector
12
13# Step 3: Run Demonstration
14# 1. Apply H to |0> -> creates |+> = (|0> + |1>)/sqrt(2)
15qc0 = QuantumCircuit(1)
16qc0.h(0)
17sv0 = Statevector.from_instruction(qc0)
18print('H on |0> -> State |+>:', sv0.data.round(4))
19print('Probabilities:', sv0.probabilities_dict())
20
21# 2. Apply H to |1> -> creates |-> = (|0> - |1>)/sqrt(2)
22qc1 = QuantumCircuit(1)
23qc1.x(0) # Make |1>
24qc1.h(0) # Apply H
25sv1 = Statevector.from_instruction(qc1)
26print('\nH on |1> -> State |->:', sv1.data.round(4))
27print('Probabilities:', sv1.probabilities_dict())
28print('\nNotice: Both have 50% probability, but |-> carries a negative phase!')
⚡ How to Run in Google Colab (3 Quick Steps)
  1. Click "Copy for Google Colab" above.
  2. Click Open New Google Colab Notebook (opens in a new tab).
  3. Click on the first empty code cell, press Ctrl + V (or Cmd + V) to paste, then press Shift + Enter to execute!

🔄 Algorithmic Execution Flow

1
Hadamard on |0>

Transforms Z-basis |0> into X-basis state |+>.

→
2
Hadamard on |1>

Transforms Z-basis |1> into X-basis state |->.

→
3
Phase Verification

Demonstrates equal 50% probabilities with opposite relative phases.

📥 Input / Initial State
QuantumCircuit(1) with H applied to |0> and |1>.
📤 Expected Output
H on |0>: [0.7071, 0.7071] -> P(0)=0.5, P(1)=0.5
H on |1>: [0.7071, -0.7071] -> P(0)=0.5, P(1)=0.5
💡 What Does This Demonstration Show?

The Hadamard gate acts as a 50/50 beam splitter, rotating the computational Z-basis into the superposition X-basis. It is the first gate in nearly every quantum algorithm.

Course Learning Resource • Slide DeckLesson 311 Slides

Lesson 3: Quantum Measurement with a One-Qubit Circuit

Hadamard gate, quantum registers, simulation, and histogram measurement.

Author: Dr. Syed Muzamil Basha• FDP Approved Curriculum
Open in New Tab
Available Slide Decks:

📝 Learning Check

Test your understanding with these questions. Remember, this is for learning, not examination!

Question 1: Which state is produced when a Hadamard gate is applied to state |1>?

Question 2: What is the matrix representation of the Hadamard gate?

Question 3: What happens when you apply the Hadamard gate twice?

Question 4: Which quantum algorithms critically rely on the Hadamard gate?

Question 5: What is the effect of applying Hadamard to all n qubits in state |00...0⟩?