Quantum Computing: The Walsh-Hadamard Matrix — Backbone of Grover’s Diffusion Operator

QUANTUM SERIES 2026
The mathematical foundation behind Grover’s diffusion operator — derived from first principles.

In the Grover’s Algorithm — Inversion About the Mean walkthrough, the diffusion operator applies H⊗³ twice per iteration. Every single step is governed by a sign table called the Hadamard Reference. That table is not a lookup shortcut — it is the 8×8 Walsh-Hadamard Transform matrix written out in full. This post derives it from scratch: one qubit, then two, then all three, arriving at the complete matrix and the rule behind every sign in it.


1  ·  The Circuit: Three Qubits, Three Hadamard Gates

We initialise all three qubits in the ground state |0⟩ and route each through its own independent Hadamard gate. There are no two-qubit (entangling) gates here — the circuit is entirely parallel.

Qubit Input Gate Output ket
q₀ |0⟩ H (1/√2)( |0⟩ + |1⟩ )
q₁ |0⟩ H (1/√2)( |0⟩ + |1⟩ )
q₂ |0⟩ H (1/√2)( |0⟩ + |1⟩ )

All three outputs are identical because all three inputs are identical. The structure we need emerges when we take their tensor product.

2  ·  Single-Qubit Hadamard Action

The Hadamard gate H maps the two computational basis states as follows:

Input H |input⟩ Short notation
|0⟩ (1/√2)( |0⟩ + |1⟩ ) |+⟩
|1⟩ (1/√2)( |0⟩ |1⟩ ) |−⟩

In matrix form:

H  =  (1/√2)    +1   +1 
 +1   −1 
Key property: H is its own inverse — H² = I. Every element has magnitude 1/√2, so tensoring three copies multiplies the magnitudes to 1/√8 while the signs follow a precise bitwise pattern.
3  ·  Two-Qubit Tensor Product: q₀ ⊗ q₁

Expanding the tensor product of the first two post-H qubits:

|+⟩ ⊗ |+⟩
  = (1/√2)(|0⟩ + |1⟩) ⊗ (1/√2)(|0⟩ + |1⟩)
  = (1/2)( |0⟩⊗|0⟩ + |0⟩⊗|1⟩ + |1⟩⊗|0⟩ + |1⟩⊗|1⟩ )
  = (1/2)( |00⟩ + |01⟩ + |10⟩ + |11⟩ )
All four two-qubit basis states appear with equal amplitude 1/2. Measurement probability per state: (1/2)² = 25%.
4  ·  Three-Qubit Tensor Product: q₀ ⊗ q₁ ⊗ q₂

Adding the third qubit expands the superposition to all 8 three-bit strings:

|+⟩ ⊗ |+⟩ ⊗ |+⟩
  = (1/√2)³ (|0⟩+|1⟩) ⊗ (|0⟩+|1⟩) ⊗ (|0⟩+|1⟩)
  = (1/√8)( |000⟩ + |001⟩ + |010⟩ + |011⟩
            + |100⟩ + |101⟩ + |110⟩ + |111⟩ )
This is |ψinit — the uniform superposition over all 8 basis states that opens Grover’s algorithm (Phase 0 in the walkthrough). Each state carries amplitude +1/√8 ≈ 0.3535 and measurement probability 1/8 = 12.5%. All signs are positive because we only applied H to |0⟩ inputs — the sign variation appears when H⊗³ acts on states other than |000⟩.
5  ·  The 8×8 Walsh-Hadamard Sign Matrix

When H⊗³ is applied to an arbitrary basis state |j⟩, the result is:

H⊗³ |j⟩  =  (1/√8)   Σᵢ   (−1)popcount(i AND j)   |i⟩

The entry at row i, column j carries sign (−1)popcount(i AND j) divided by √8. The table below shows all 64 signs — green (+) for +1/√8 and red (−) for −1/√8:

H⊗³ |j⟩ →
output |i⟩ ↓
|000⟩ |001⟩ |010⟩ |011⟩ |100⟩ |101⟩ |110⟩ |111⟩
H|000⟩ + + + + + + + +
H|001⟩ + + + +
H|010⟩ + + + +
H|011⟩ + + + +
H|100⟩ + + + +
H|101⟩ + + + +
H|110⟩ + + + +
H|111⟩ + + + +
+  =  amplitude +1/√8 ≈ +0.3535      =  amplitude −1/√8 ≈ −0.3535
6  ·  Why the Sign is (−1)popcount(i AND j)

Because H acts independently on each qubit, H⊗³ is the tensor product of three 2×2 matrices. The entry at row i, column j is simply the product of the three corresponding single-qubit entries:

H⊗³[i, j]  =  H[i₀, j₀]  ×  H[i₁, j₁]  ×  H[i₂, j₂]

Each single-qubit factor equals +1 unless both the k-th bit of i and the k-th bit of j are 1, in which case it equals −1. So the k-th factor contributes a sign of (−1)iₖ·jₖ. Multiplying all three:

sign(i, j)  =  (−1)i₀j₀ + i₁j₁ + i₂j₂  =  (−1)popcount(i AND j)
The rule in plain terms: bitwise AND the row index and the column index, count the 1-bits, check parity. Even count → positive. Odd count → negative.

Quick verification: row H|101⟩, column |011⟩

i (row) j (col) i AND j popcount Sign
101 (= 5) 011 (= 3) 001 1 (odd) − ✓

Matches the matrix in Section 5: row H|101⟩, column |011⟩ is indeed .

7  ·  Connection to Grover’s Diffusion Operator

This matrix is the Hadamard Reference table used throughout the Grover’s Algorithm — Inversion About the Mean post. The diffusion operator D = H⊗³ (2|0⟩⟨0| − I) H⊗³ works in three sub-steps, each directly using this matrix:

Sub-step Operation Grover walkthrough steps
First H⊗³ Maps computational basis → Hadamard basis. Each amplitude spreads across all 8 columns via the sign table. 4.1  ·  6.1  ·  8.1
Phase flip 2|0⟩⟨0|−I: keeps |000⟩ unchanged, negates all other states. This is the inversion-about-the-mean mechanism. 4.2  ·  6.2  ·  8.2
Second H⊗³ Maps back to computational basis using the same sign table (H is self-inverse). Routes constructive interference into the target state. 4.3  ·  6.3  ·  8.3
The bottom line: without the sign structure of the Walsh-Hadamard matrix, neither the uniform superposition (Phase 0) nor the diffusion step (every iteration) would work. The matrix is the silent engine behind Grover’s quadratic speedup.

Quantum Series 2026  ·  Built with Qiskit 1.x

✦ This article was generated with the assistance of Claude by Anthropic

Quantum Computing: Grover’s Algorithm – Inversion About the Mean

Grover’s Algorithm: Exact Mathematical Evolution

Full 3-Qubit Matrix Interference Walkthrough

What is Grover’s Algorithm? Grover’s algorithm is a quantum search procedure that locates a marked item in an unsorted list of N items in O(√N) oracle queries — a quadratic speedup over any classical approach. For N = 8 (3 qubits), this means roughly ⌊π/4 × √8⌋ = 2 optimal iterations before the probability of measuring the target state peaks.

This walkthrough tracks the exact amplitude of every basis state through each gate operation for the 3-qubit case, with target state |101>. All arithmetic is shown so each step can be verified by hand.

Structure of each iteration (Grover operator G):

  • Oracle Uf — Phase-flips the target state: |x> → -|x> if f(x) = 1, otherwise |x> → |x>.
  • Diffusion operator D = H⊗n(2|0><0| − I)H⊗n — Reflects all amplitudes about their mean, amplifying the marked state at the expense of the others.

Key insight: The oracle introduces destructive interference at the target, which the diffusion operator then converts into constructive interference by inverting amplitudes about their mean. Each iteration rotates the state vector by an angle 2θ closer to the target, where sin(θ) = 1/√N.

Circuit Overview — 3 Qubits, Target |101⟩
Init Diffusion 1 Diffusion 2
|0⟩H Uf HZ0H Uf HZ0H M
|0⟩H   H H   H H M
|0⟩H   H H   H H M
Iteration 1 Iteration 2 · optimal
H = Hadamard Uf = Oracle (phase-flips target) Z0 = 2|0⟩⟨0|−I M = Measure

Phase 0: Initialization

Steps 1 & 2: Apply H⊗3 to |000> to create a uniform superposition over all 8 basis states. Because each single-qubit Hadamard maps |0> to (|0>+|1>)/√2, applying all three simultaneously yields equal amplitude 1/√8 ≈ 0.3535 for every state. This is the starting point — every state is equally likely, and the algorithm has no preference yet.

init> = 1/√8 [ |000> + |001> + |010> + |011> + |100> + |101> + |110> + |111> ]

Hadamard Reference (Standard Signs)

The 8×8 Walsh-Hadamard matrix defines the sign pattern when H⊗3 is applied to any basis state. Element (i, j) has sign (−1)popcount(i AND j) — i.e., the number of bit positions where both row state and column state have a 1. The actual amplitude contribution is this sign divided by √8. This table is used in every Hadamard step below: each row corresponds to one input basis state, and its sign pattern determines how it distributes into all 8 output states.

Basis State000001010011100101110111
H|000>++++++++
H|001>++++
H|010>++++
H|011>++++
H|100>++++
H|101>++++
H|110>++++
H|111>++++

Round 1: [Oracle → Diffusion]

Step 3: Oracle Uf — The oracle recognises |101> as the marked state and applies a phase kickback, flipping its amplitude from +1/√8 to −1/√8. All other amplitudes remain unchanged. Physically, this encodes “this is the target” purely in phase — no measurement is made, so the superposition is preserved.

Step 4.1: Round 1 First Hadamard (H)

The diffusion operator begins by mapping from the computational basis back into the Hadamard basis. Each input state |x> with amplitude ax contributes ax/√8 to every output column, with sign given by the reference table. For all non-target states ax = +1/√8, so each cell = (+1/√8)×(Sign/√8) = Sign/8. For the oracle-marked |101>, the amplitude is −1/√8, so the entire row is sign-inverted (highlighted in red). The Net Result row is the vertical sum of all 8 rows for each column.

Source (Post-Oracle)000001010011100101110111
+H|000> (1/√8)+18+18+18+18+18+18+18+18
+H|001> (1/√8)+18-18+18-18+18-18+18-18
+H|010> (1/√8)+18+18-18-18+18+18-18-18
+H|011> (1/√8)+18-18-18+18+18-18-18+18
+H|100> (1/√8)+18+18+18+18-18-18-18-18
-H|101> (-1/√8)-18+18-18+18+18-18+18-18
+H|110> (1/√8)+18+18-18-18-18-18+18+18
+H|111> (1/√8)+18-18-18+18-18+18+18-18
Net Result 4.1+68+28-28+28+28-28+28-28

Step 4.2: Round 1 Phase Flip (Z on non-|000>)

This step implements the 2|0><0|−I operator in the computational basis. In practice it means: keep |000>’s amplitude unchanged, and negate every other state. This is the heart of inversion-about-the-mean: because the |000> column accumulated the largest positive amplitude in Step 4.1 (reflecting the mean of all amplitudes before the first H), flipping everything else relative to it creates the inversion effect that will boost the target in the next step.

State000001010011100101110111
Amp (Post-Z)+68-28+28-28-28+28-28+28

Step 4.3: Round 1 Second Hadamard (H)

The second H maps the Hadamard-basis amplitudes from Step 4.2 back to the computational basis, completing the diffusion operator. Each post-Z amplitude contributes to every output column via the reference sign table, multiplied by 1/√8, giving denominators of 8√8. Summing column |101> yields +208√8 ≈ 0.884 — a dramatic amplification from the initial 0.354 — while all other states settle to +48√8 ≈ 0.177. One iteration is complete.

Source (Post-Z)000001010011100101110111
+H|000> (68)+68√8+68√8+68√8+68√8+68√8+68√8+68√8+68√8
-H|001> (-28)-28√8+28√8-28√8+28√8-28√8+28√8-28√8+28√8
+H|010> (28)+28√8+28√8-28√8-28√8+28√8+28√8-28√8-28√8
-H|011> (-28)-28√8+28√8+28√8-28√8-28√8+28√8+28√8-28√8
-H|100> (-28)-28√8-28√8-28√8-28√8+28√8+28√8+28√8+28√8
+H|101> (28)+28√8-28√8+28√8-28√8-28√8+28√8-28√8+28√8
-H|110> (-28)-28√8-28√8+28√8+28√8+28√8+28√8-28√8-28√8
+H|111> (28)+28√8-28√8-28√8+28√8-28√8+28√8+28√8-28√8
Net Result (R1)+48√8+48√8+48√8+48√8+48√8+208√8+48√8+48√8
Decimal (R1)0.1770.1770.1770.1770.1770.8840.1770.177

Round 2: [Oracle → Diffusion]

Step 5: Oracle Uf — The oracle is applied again to the post-R1 state. |101> now carries a much larger amplitude (+208√8), so the phase flip to −208√8 creates a far more pronounced imbalance. The 7 non-target states each carry only +48√8. This large asymmetry is what will drive even stronger constructive interference in the diffusion step.

Step 6.1: Round 2 First Hadamard (H)

Each amplitude is multiplied by 1/√8 as it spreads across the 8 columns via the reference sign table. The denominator becomes 8√8 × √8 = 64. The 7 uniform states (+48√8) form balanced Walsh-Hadamard rows that cancel perfectly for all non-|000> columns — only the oracle-perturbed |101> row breaks the symmetry, contributing an extra −24 or +24 to each non-zero column (depending on the H sign for that bit pattern). Column |000> is special: all 8 rows contribute positively, giving +864.

Source (Post-Oracle)000001010011100101110111
+H|000> (48√8)+464+464+464+464+464+464+464+464
+H|001> (48√8)+464-464+464-464+464-464+464-464
+H|010> (48√8)+464+464-464-464+464+464-464-464
+H|011> (48√8)+464-464-464+464+464-464-464+464
+H|100> (48√8)+464+464+464+464-464-464-464-464
-H|101> (-208√8)-2064+2064-2064+2064+2064-2064+2064-2064
+H|110> (48√8)+464+464-464-464-464-464+464+464
+H|111> (48√8)+464-464-464+464-464+464+464-464
Net Result 6.1+864+2464-2464+2464+2464-2464+2464-2464

Step 6.2: Phase Flip (Z on non-|000>)

Same operation as Step 4.2: negate every amplitude except |000>. The |000> column retains its +864 value. All other states flip sign, converting e.g. +2464 → −2464. This primes the second Hadamard to route amplitude toward the target state.

State000001010011100101110111
Amp (Post-Z)+864-2464+2464-2464-2464+2464-2464+2464

Step 6.3: Round 2 Second Hadamard (H)

The final H of the diffusion operator maps the post-Z amplitudes back to the computational basis. Each amplitude propagates through the Hadamard sign table with denominator 64√8. Column |101> receives a constructive sum of +17664√8 ≈ 0.972 — near-certain success. The non-target states all land at −1664√8 ≈ −0.088, where the negative sign carries no measurement consequence. This is the optimal stopping point for 3-qubit Grover search: stopping here gives the highest possible P(|101>).

Source (Post-Z)000001010011100101110111
+H|000> (864)+864√8+864√8+864√8+864√8+864√8+864√8+864√8+864√8
-H|001> (-2464)-2464√8+2464√8-2464√8+2464√8-2464√8+2464√8-2464√8+2464√8
+H|010> (2464)+2464√8+2464√8-2464√8-2464√8+2464√8+2464√8-2464√8-2464√8
-H|011> (-2464)-2464√8+2464√8+2464√8-2464√8-2464√8+2464√8+2464√8-2464√8
-H|100> (-2464)-2464√8-2464√8-2464√8-2464√8+2464√8+2464√8+2464√8+2464√8
+H|101> (2464)+2464√8-2464√8+2464√8-2464√8-2464√8+2464√8-2464√8+2464√8
-H|110> (-2464)-2464√8-2464√8+2464√8+2464√8+2464√8+2464√8-2464√8-2464√8
+H|111> (2464)+2464√8-2464√8-2464√8+2464√8-2464√8+2464√8+2464√8-2464√8
Net Result (R2)-1664√8-1664√8-1664√8-1664√8-1664√8+17664√8-1664√8-1664√8
Decimal (R2)-0.088-0.088-0.088-0.088-0.088+0.972-0.088-0.088
Success Probability: P(101) = |0.9724|2 ≈ 94.5%

Round 3: [Oracle → Diffusion] (The Overcooking Effect)

Step 7: Oracle Uf — With P(|101>) at 94.5%, one more iteration is one too many. The oracle again flips |101>’s amplitude: +17664√8 → −17664√8. The 7 non-target states each remain at −1664√8. The state vector has been rotated 2θ past its peak, and a third diffusion step will push it further away from the target, not closer.

Step 8.1: Round 3 First Hadamard (H)

The denominator grows to 512 (= 64√8 × √8). All 8 input amplitudes are now negative (after the oracle flip, |101> is −17664√8 and the rest are −1664√8), so the |000> column accumulates a strongly negative sum (−288512). The non-|000> columns are dominated by the large −|101> row contribution, which is sign-inverted from the reference table and therefore contributes ±176512. The net result is a lopsided distribution that the phase flip will convert into a push away from the target.

Source (Post-Oracle)000001010011100101110111
-H|000> (-1664√8)-16512-16512-16512-16512-16512-16512-16512-16512
-H|001> (-1664√8)-16512+16512-16512+16512-16512+16512-16512+16512
-H|010> (-1664√8)-16512-16512+16512+16512-16512-16512+16512+16512
-H|011> (-1664√8)-16512+16512+16512-16512-16512+16512+16512-16512
-H|100> (-1664√8)-16512-16512-16512-16512+16512+16512+16512+16512
-H|101> (-17664√8)-176512+176512-176512+176512+176512-176512+176512-176512
-H|110> (-1664√8)-16512-16512+16512+16512+16512+16512-16512-16512
-H|111> (-1664√8)-16512+16512+16512-16512+16512-16512-16512+16512
Net Result 8.1-288512+160512-160512+160512+160512-160512+160512-160512

Step 8.2: Round 3 Phase Flip (Z on non-|000>)

The |000> amplitude (−288512) is preserved. All other amplitudes flip sign. Notice that after R2 the non-target states had small negative amplitudes; after the phase flip here they become positive (+160512), while the target column was −160512 and now becomes +160512 as well — the diffusion has lost its asymmetry and will no longer strongly favour |101>.

State000001010011100101110111
Amp (Post-Z)-288512-160512+160512-160512-160512+160512-160512+160512

Step 8.3: Round 3 Second Hadamard (H)

The second H maps amplitudes back to the computational basis with denominators of 512√8. The large negative |000> amplitude now spreads destructive interference broadly, while the relatively uniform positive amplitudes for the remaining states partially cancel in the |101> column. The result is +832512√8 = +138√8 ≈ +0.575 for |101> and −448512√8 = −78√8 ≈ −0.309 for all non-target states. P(|101>) has fallen to ~33%, demonstrating that iterating past the optimal count hurts. Importantly, |101> still leads every other state by 3×, so a single extra iteration only partially degrades the result — it has not catastrophically lost the solution.

Source (Post-Z)000001010011100101110111
-H|000> (-288512)-288512√8-288512√8-288512√8-288512√8-288512√8-288512√8-288512√8-288512√8
-H|001> (-160512)-160512√8+160512√8-160512√8+160512√8-160512√8+160512√8-160512√8+160512√8
+H|010> (160512)+160512√8+160512√8-160512√8-160512√8+160512√8+160512√8-160512√8-160512√8
-H|011> (-160512)-160512√8+160512√8+160512√8-160512√8-160512√8+160512√8+160512√8-160512√8
-H|100> (-160512)-160512√8-160512√8-160512√8-160512√8+160512√8+160512√8+160512√8+160512√8
+H|101> (160512)+160512√8-160512√8+160512√8-160512√8-160512√8+160512√8-160512√8+160512√8
-H|110> (-160512)-160512√8-160512√8+160512√8+160512√8+160512√8+160512√8-160512√8-160512√8
+H|111> (160512)+160512√8-160512√8-160512√8+160512√8-160512√8+160512√8+160512√8-160512√8
Net Result (R3)-448512√8-448512√8-448512√8-448512√8-448512√8+832512√8-448512√8-448512√8
Simplified (R3)-78√8-78√8-78√8-78√8-78√8+138√8-78√8-78√8
Decimal (R3)-0.309-0.309-0.309-0.309-0.309+0.575-0.309-0.309

⚠ Overcooking Confirmed — But Not Catastrophic

The state vector has rotated past the optimal angle. P(|101>) drops from 94.5% (R2) to 33.0% — a significant fall, but |101> still has more than double the probability of any other state. The algorithm has not “lost” the answer; it has merely de-amplified it. Note also that the target amplitude is still positive (+0.575) — the vector has not crossed zero, it has simply overshot past the maximum. The 33.0% comes directly from the Born rule: P(|101>) = |amplitude|² = |+0.575|² ≈ 0.330.

The Cost of Garbage in Quantum Computing

The Hidden Witness

Why You Must Clean Up “Junk Bits” with Uncomputation

1. The “Observer” Effect

In quantum computing, anything that “knows” what a qubit is doing acts as a Witness. Leftover data (Junk Bits) on an ancilla qubit act as witnesses, destroying the interference your algorithm needs to work.

Case A: Ideal (No Junk)

H
H
|0>
|0>

100% Interference

Case B: Broken (With Junk)

H
+
H
|0>
|0>
?
|junk>

Random 50/50 Noise

2. Mathematical Working

Ideal Case: (1/2) ( |0> + |1> + |0> – |1> ) = |0>
(Identical paths cancel perfectly.)

Junk Case: (1/2) ( |00> + |10> + |01> – |11> )
(Terms cannot cancel because the ancilla bit is different. Interference is destroyed.)

3. The Solution: Uncomputation

To restore interference, we follow the Compute-Copy-Uncompute pattern. This resets our ancilla to |0> and removes the “witness.”

Input |x>
Ancilla |0>
Target |0>
COMPUTE
+
UNCOMPUTE
|x> (Clean)
|0> (Clean)
|f(x)> (Result)

4. Qiskit Implementation

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(3)
qc.h(0) 
qc.cx(0, 1) # COMPUTE: Create Junk on q1
qc.cx(1, 2) # COPY Result to q2
qc.cx(0, 1) # UNCOMPUTE: Clean Junk back to |0>
qc.h(0)     # Interference Restored!

qc.measure_all()
counts = AerSimulator().run(transpile(qc, AerSimulator())).result().get_counts()
print(f"Resulting state: {counts}")

Built with Qiskit 1.x • Quantum Series 2025

Reversible Computation in Quantum Computing

Reversible Computation in Quantum Computing

Mastering Reversibility, Ancilla Bits, and Unitary Logic

1. The Necessity of Reversibility

In classical logic, gates like AND are inherently irreversible. Because they compress two input bits into a single output bit, information is physically destroyed. For example, if an AND gate outputs ‘0’, you cannot distinguish if the original inputs were (0,0), (0,1), or (1,0). This “many-to-one” mapping results in information loss that manifests as heat dissipation.

In quantum computing, thermodynamics and the laws of physics require all operations to be Unitary (UU = I). This means every quantum gate must be a 1-to-1 (bijective) mapping; no information is ever lost, and the entire computation can be run in reverse to recover the initial state.

AND
Out: 0

The Logic Gap: If the output is 0, the input could be (0,0), (0,1), or (1,0). The path back is lost.

2. Ancilla Bits & Uncomputation

Because we cannot erase information, we use Ancilla bits as temporary “scratch space.” However, if these qubits are left in an arbitrary state, they remain entangled with the computation. Uncomputation (running gates in reverse) resets them to |0>, “cleaning” the quantum workspace.

The Toffoli Gate (CCX)

The Toffoli gate is reversible because its mapping is bijective. No two inputs result in the same output.

+
In: A
In: B
In: C
Input (A, B, C) Output (A, B, C ⊕ AB) Status
0, 0, 00, 0, 0Unique
1, 1, 01, 1, 1Flipped (AND)
1, 1, 11, 1, 0Flipped Back

The Fredkin Gate (CSWAP)

The Fredkin gate is a controlled-swap operation. It swaps the states of the two target qubits (T1 and T2) if and only if the control qubit (C) is in the state |1>. It is conservative, meaning it preserves the Hamming weight (number of 1s) from input to output.

Because it is a universal gate, we can simulate all standard classical logic by fixing certain inputs:

  • NOT: Set T1=0, T2=1. Output T2 becomes NOT C.
  • AND: Set T2=0. Output T2 becomes C AND T1.
  • OR: Set T1=B, T2=1. Output T1 becomes C OR B.
In: C
In: T1
In: T2

3. Mathematics: Unitary vs. Hermitian

Proof: Is Pauli-Y Unitary?

Y =
0i
i0
Y =
0i
i0

Pauli-Y is Unitary (YY = I). Because Y = Y, it is also Hermitian.

Unitary but NOT Hermitian: The S Gate

S =
10
0i
S =
10
0i

Since SS, you must apply the S-Dagger gate to reverse an S rotation.

4. Qiskit Verification

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(3)
qc.x([0, 1]) # Controls to |1>

# Toffoli is Hermitian (U = U†), so applying it twice cleans the ancilla
qc.ccx(0, 1, 2) # Calculation step
qc.ccx(0, 1, 2) # Uncomputation step

qc.measure_all()
counts = AerSimulator().run(transpile(qc, AerSimulator())).result().get_counts()
print(f"Resulting state: {counts}") # Expect {'011': 1024}
            

Built with Qiskit 1.x • Quantum Series 2025

Deutsch Algorithm Revisited: Quantum vs Classical Implementation in Qiskit

Deutsch Algorithm Revisited: Quantum vs Classical Implementation in Qiskit

A practical comparison showing the quantum advantage with working code

Introduction

In the previous post on the Deutsch algorithm, we explored the theoretical foundations of this groundbreaking quantum algorithm. Today, we’re taking it further by implementing both the quantum and classical approaches in Qiskit, allowing us to see the quantum advantage in action.

This hands-on implementation demonstrates why the Deutsch algorithm is considered the first example of quantum computational superiority—solving a problem with fewer oracle queries than any classical algorithm can achieve.

The Challenge

Given a black-box function f: {0,1} → {0,1}, determine whether it is:

  • Constant: f(0) = f(1) (always returns 0 or always returns 1)
  • Balanced: f(0) ≠ f(1) (returns 0 for one input, 1 for the other)
🔑 Key Question: How many times must we query the function?
  • Classical: 2 queries required
  • Quantum: 1 query required

Complete Qiskit Implementation

Oracle Functions

First, we create the oracle functions representing all possible single-bit Boolean functions:

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit_aer import AerSimulator

def create_constant_oracle(constant_value):
    """Creates a constant oracle (returns 0 or 1 for all inputs)"""
    oracle = QuantumCircuit(2, name=f"Constant_{constant_value}")
    if constant_value == 1:
        oracle.x(1)  # Flip the output qubit
    return oracle

def create_balanced_oracle(balance_type):
    """Creates a balanced oracle"""
    oracle = QuantumCircuit(2, name=f"Balanced_{balance_type}")
    if balance_type == 'identity':
        # f(x) = x
        oracle.cx(0, 1)
    elif balance_type == 'negation':
        # f(x) = NOT x
        oracle.x(0)
        oracle.cx(0, 1)
        oracle.x(0)
    return oracle

Classical Approach: Two Queries Required

The classical algorithm must query the oracle twice—once for f(0) and once for f(1):

def classical_deutsch_query1(oracle):
    """First query: Evaluate f(0)"""
    qr = QuantumRegister(2, 'q')
    cr = ClassicalRegister(1, 'c')
    qc = QuantumCircuit(qr, cr)
    
    # Input: x = 0 (already initialized to |0⟩)
    qc.barrier()
    qc.compose(oracle, inplace=True)
    qc.barrier()
    qc.measure(1, 0)  # Measure output to get f(0)
    
    return qc

def classical_deutsch_query2(oracle):
    """Second query: Evaluate f(1)"""
    qr = QuantumRegister(2, 'q')
    cr = ClassicalRegister(1, 'c')
    qc = QuantumCircuit(qr, cr)
    
    qc.x(0)  # Input: x = 1
    qc.barrier()
    qc.compose(oracle, inplace=True)
    qc.barrier()
    qc.measure(1, 0)  # Measure output to get f(1)
    
    return qc

Quantum Approach: One Query Suffices

The quantum Deutsch algorithm uses superposition and interference to determine the answer with a single oracle query:

def deutsch_algorithm(oracle):
    """Implements the Deutsch algorithm - requires only ONE query"""
    qr = QuantumRegister(2, 'q')
    cr = ClassicalRegister(1, 'c')
    qc = QuantumCircuit(qr, cr)
    
    # Step 1: Initialize q[1] to |1⟩
    qc.x(1)
    qc.barrier()
    
    # Step 2: Apply Hadamard gates (create superposition)
    qc.h(0)
    qc.h(1)
    qc.barrier()
    
    # Step 3: Apply the oracle (SINGLE QUERY!)
    qc.compose(oracle, inplace=True)
    qc.barrier()
    
    # Step 4: Apply Hadamard to input qubit
    qc.h(0)
    qc.barrier()
    
    # Step 5: Measure
    qc.measure(0, 0)
    
    return qc

Running the Comparison

Now let’s test all four possible oracles with both approaches:

oracles = [
    ("Constant 0", create_constant_oracle(0)),
    ("Constant 1", create_constant_oracle(1)),
    ("Balanced (Identity)", create_balanced_oracle('identity')),
    ("Balanced (Negation)", create_balanced_oracle('negation'))
]

simulator = AerSimulator()

for name, oracle in oracles:
    # Classical: 2 queries
    qc1 = classical_deutsch_query1(oracle)
    result1 = simulator.run(qc1, shots=1).result()
    f_0 = int(list(result1.get_counts().keys())[0])
    
    qc2 = classical_deutsch_query2(oracle)
    result2 = simulator.run(qc2, shots=1).result()
    f_1 = int(list(result2.get_counts().keys())[0])
    
    classical_result = "CONSTANT" if f_0 == f_1 else "BALANCED"
    
    # Quantum: 1 query
    qc_quantum = deutsch_algorithm(oracle)
    result_quantum = simulator.run(qc_quantum, shots=1000).result()
    counts = result_quantum.get_counts()
    
    quantum_result = "CONSTANT" if '0' in counts else "BALANCED"
    
    print(f"{name}: Classical={classical_result}, Quantum={quantum_result}")

Circuit Diagrams

Below are visual representations of the three circuit implementations. The classical approach requires two separate queries, while the quantum approach accomplishes the same task with a single query.

Classical Query 1: Evaluating f(0)

q[0]:
q[1]:
|0⟩
|0⟩
Oracle (Constant_0)
f(0)

Classical Query 1: Input qubit q[0] remains in state |0⟩ → Oracle processes the input → Output qubit q[1] is measured to obtain f(0)

Classical Query 2: Evaluating f(1)

q[0]:
q[1]:
|0⟩
|0⟩
X
|1⟩
Oracle (Constant_0)
f(1)

Classical Query 2: X gate flips q[0] from |0⟩ to |1⟩ → Oracle processes the input → Output qubit q[1] is measured to obtain f(1)

Quantum Deutsch Algorithm (Single Query)

q[0]:
q[1]:
|0⟩
|0⟩
X
H
H
Oracle (Constant_0)
H
0 or 1

Quantum Deutsch: Initialize |01⟩ → Hadamard gates create superposition → Oracle query (single query!) → Final Hadamard on q[0] → Measure q[0] to determine function type

💡 Understanding the Circuit Elements

🔵 Oracle Box: Represents the black-box function we’re querying

🟠 H Gates: Hadamard gates create quantum superposition

🔴 X Gates: Flip qubit states (NOT gate)

📊 Measurement: Extracts classical information from qubits

📏 Qubit Lines: Horizontal lines represent quantum bits

📍 Input/Output: |0⟩, |1⟩ show quantum states

🔍 Key Observation

Notice that the classical circuits measure the output qubit (q[1]) to get the function values f(0) and f(1), while the quantum circuit measures the input qubit (q[0]) after interference. This fundamental difference allows the quantum algorithm to extract global properties of the function with a single query!

Sample Output

======================================================================
Testing: Constant 0 Oracle
======================================================================

[CLASSICAL APPROACH - Requires 2 queries]
  Query 1: f(0) = 0
  Query 2: f(1) = 0
  Result: Function is CONSTANT
  Total queries needed: 2

[QUANTUM APPROACH - Requires only 1 query]
  Measurement results: {'0': 1000}
  Result: Function is CONSTANT
  Total queries needed: 1

  ✓ Both methods agree: True

======================================================================
Testing: Balanced (Identity) Oracle
======================================================================

[CLASSICAL APPROACH - Requires 2 queries]
  Query 1: f(0) = 0
  Query 2: f(1) = 1
  Result: Function is BALANCED
  Total queries needed: 2

[QUANTUM APPROACH - Requires only 1 query]
  Measurement results: {'1': 1000}
  Result: Function is BALANCED
  Total queries needed: 1

  ✓ Both methods agree: True

Understanding the Quantum Advantage

Classical Approach

  • Evaluate f(0) explicitly
  • Evaluate f(1) explicitly
  • Compare the two results
  • 2 queries required

Must check both inputs individually

Quantum Approach

  • Query with superposition of both inputs
  • Use interference to extract global property
  • Measure to get answer
  • 1 query required

Exploits quantum parallelism

🎯 The Key Insight

The quantum algorithm queries the oracle with a superposition of both inputs simultaneously (|0⟩ + |1⟩), then uses quantum interference to extract global properties of the function without ever evaluating it on individual inputs. The measurement result directly tells us whether the function is constant or balanced.

Measurement Interpretation

Measurement Result Function Type Explanation
|0⟩ Constant Constructive interference – f(0) ⊕ f(1) = 0
|1⟩ Balanced Destructive interference – f(0) ⊕ f(1) = 1

Running the Code

To run this code yourself, you’ll need to install Qiskit:

pip install qiskit qiskit-aer

The complete code is available as a Python script that you can run directly. It will output the comparison for all four oracle types and display the results.

Conclusion

This implementation demonstrates the Deutsch algorithm’s quantum advantage in concrete terms:

  • Quantum speedup: 2x reduction in oracle queries (from 2 to 1)
  • First proof of concept: First algorithm to show quantum advantage over classical
  • Foundational technique: Introduces key quantum concepts (superposition, interference, phase kickback)

While the speedup may seem modest for this toy problem, the techniques demonstrated here—querying a function with superposition and extracting global properties through interference—scale to more complex algorithms like Deutsch-Jozsa, Simon’s algorithm, and ultimately Shor’s algorithm for factoring.

🚀 Next Steps:
  • Experiment with the code and modify the oracles
  • Try visualizing the quantum states at each step
  • Explore the Deutsch-Jozsa algorithm (generalization to n-bit functions)
  • Study the mathematical foundations of quantum interference

Have questions or want to discuss quantum algorithms? Drop a comment below!

Happy quantum coding! 🎯⚛️

Deutsch’s Algorithm in Quantum Computing: The 4 Cases

Deutsch’s Algorithm: Complete Guide

From Initialization to Measurement.

Deutsch’s Algorithm determines if a function f(x) is Constant or Balanced using only a single query. First, we examine how these functions are physically built.

The 4 Possible Functions

In these examples, we set the bottom input to 0 so the output is exactly f(x).

1. Constant Zero Function: f(x) = 0
x
0
Identity (No Gates)
2. Constant One Function: f(x) = 1
X
3. Balanced ID Function: f(x) = x
+
4. Balanced NOT Function: f(x) = ¬x
+
X

The General Oracle (Uf)

x
y
Uf
x
y ⊕ f(x)

The Complete Circuit

To detect the function type, we initialize the bottom wire to |1⟩ and use Hadamard gates to create superposition.

|0⟩
|1⟩
H
H
Uf
KICKBACK ↑
H
|ψ₀⟩
|ψ₁⟩
|ψ₂⟩

Mathematical Proof

1. Initialization: |ψ₀⟩ = |0⟩|1⟩

2. Superposition: |ψ₁⟩ = |+⟩|-⟩ = ½(|0⟩+|1⟩)(|0⟩-|1⟩)

3. The Kickback Effect: Applying Uf to |x⟩|-⟩ results in:
Uf |x⟩|-⟩ = (-1)f(x) |x⟩|-⟩

This means the output of the function is shifted into the phase of the first qubit.

4. Global State |ψ₂⟩:
|ψ₂⟩ = 1/√2 [ (-1)f(0)|0⟩ + (-1)f(1)|1⟩ ] ⊗ |-⟩

Final Measurement

If f(0) = f(1) (Constant) → State is ±|+⟩ → Measure 0
If f(0) ≠ f(1) (Balanced) → State is ±|-⟩ → Measure 1

Understanding Phase Kickback in Quantum Computing

How the target controls the controller.

In standard classical logic, a Control Bit dictates what happens to a target. However, in quantum mechanics, the relationship is symmetric. When the target qubit is in an eigenstate of the operator, the phase is “kicked back” to the control qubit.

|+⟩
|−⟩
|−⟩
|−⟩
CNOT CIRCUIT

Notice above: The Target qubit remains unchanged (|−⟩), but the Control qubit flips from |+⟩ to |−⟩.

STEP 1: DEFINE INITIAL STATE

0⟩ = |+⟩ ⊗ |−⟩

= (1/√2) (|0⟩ + |1⟩)  ⊗  (1/√2) (|0⟩ − |1⟩)

STEP 2: EXPAND TERMS

Multiplying coefficients gives 1/2:
0⟩ = ½ [ |00⟩ − |01⟩ + |10⟩ − |11⟩ ]

STEP 3: APPLY CNOT GATE

Target flips (0↔1) only if Control is 1:
1⟩ = ½ [ |00⟩ − |01⟩ + |11⟩ − |10⟩ ]

STEP 4: FACTOR & REARRANGE

Group terms by the control qubit:
1⟩ = ½ [ |0⟩(|0⟩ − |1⟩) − |1⟩(|0⟩ − |1⟩) ]
∴ |ψ1⟩ = |−⟩ ⊗ |−⟩

Why is this important?

The math shows that while we applied the gate to the target, the relative phase of the control qubit changed from positive to negative. This mechanism is the foundation of quantum algorithms like Shor’s and Grover’s.

Introduction to Quantum Computing: Qubits, Hadamard Gates, and Superposition

What Makes Quantum Computing Different?

Classical computers process information using bits that exist in one of two states: 0 or 1. Quantum computers, however, leverage the strange and powerful principles of quantum mechanics to process information in fundamentally different ways. At the heart of this difference lies the qubit (quantum bit) and quantum gates like the Hadamard gate that manipulate these qubits.

Understanding the Qubit

A qubit is the basic unit of quantum information. Unlike classical bits, qubits can exist in a superposition of states, meaning they can be in state |0⟩, state |1⟩, or any quantum combination of both simultaneously.

Mathematical Representation

We represent qubit states using Dirac notation (bra-ket notation):

|0⟩ state:

1
0

|1⟩ state:

0
1

A general qubit state can be written as:

|ψ⟩ = α|0⟩ + β|1⟩

where α and β are complex numbers called probability amplitudes, and they must satisfy the normalization condition:

|α|² + |β|² = 1

When we measure a qubit in this state, we get:

  • |0⟩ with probability |α|²
  • |1⟩ with probability |β|²

The Hadamard Gate: Creating Superposition

The Hadamard gate (H) is one of the most important quantum gates. It creates an equal superposition from a classical state, which is the key to quantum algorithms’ power.

Hadamard Gate Matrix

The Hadamard gate is represented by the following 2×2 matrix:

H = (1/√2) ×

1 1
1 −1

Opening Superposition

Let’s see what happens when we apply the Hadamard gate to the |0⟩ state:

Step 1: Matrix Multiplication

H|0⟩ = (1/√2) ×
1 1
1 −1
×
1
0

Step 2: Result

= (1/√2) ×
1
1

Step 3: Final State

H|0⟩ = (1/√2)(|0⟩ + |1⟩)

🎯 Key Insight: This creates an equal superposition! The qubit now has a 50% probability of being measured as 0 and 50% as 1.

Similarly, applying H to |1⟩:

H|1⟩ = (1/√2)(|0⟩ − |1⟩)

Closing Superposition

Here’s the remarkable property: the Hadamard gate is its own inverse. Applying it twice returns the qubit to its original state.

H(H|0⟩) calculation:

= H( (1/√2)(|0⟩ + |1⟩) )

= (1/√2)(H|0⟩ + H|1⟩)

= (1/√2)( (1/√2)(|0⟩+|1⟩) + (1/√2)(|0⟩−|1⟩) )

= (1/2)(|0⟩ + |1⟩ + |0⟩ − |1⟩)

= (1/2)(2|0⟩)

= |0⟩ ✓

💡 Quantum Interference: The amplitude for |1⟩ cancels out completely, and we return to the definite state |0⟩. This is the magic of quantum interference!

Example Circuit: Creating and Collapsing Superposition

Let’s look at a simple quantum circuit:

     ┌───┐┌───┐┌─┐
q_0: ┤ H ├┤ H ├┤M├
     └───┘└───┘└─┘

Legend: H = Hadamard gate, M = Measurement

Step-by-step Execution:

Step State Description
1. Initial |ψ₀⟩ = |0⟩ Qubit starts in state 0
2. After H |ψ₁⟩ = (1/√2)(|0⟩+|1⟩) Superposition! 50% chance of 0 or 1
3. After H |ψ₂⟩ = |0⟩ Back to |0⟩! Superposition collapsed
4. Measure Result = 0 We measure 0 with 100% probability

Multi-Qubit Systems and Tensor Products

When working with multiple qubits, we use the tensor product (⊗) to describe the combined state space.

Two-Qubit System

For two qubits, we have four possible basis states:

|00⟩ = |0⟩ ⊗ |0⟩
|01⟩ = |0⟩ ⊗ |1⟩
|10⟩ = |1⟩ ⊗ |0⟩
|11⟩ = |1⟩ ⊗ |1⟩

Tensor Product Example

Let’s calculate |0⟩ ⊗ |1⟩ step by step:

|0⟩ ⊗ |1⟩ =
1
0
0
1

The tensor product stacks the results:

  • First element (1) × [0, 1] = [0, 1]
  • Second element (0) × [0, 1] = [0, 0]
  • Stack them: [0, 1, 0, 0]
Result:
0
1
0
0
= |01⟩

Creating Multi-Qubit Superposition

Consider applying Hadamard gates to both qubits starting from |00⟩:

     ┌───┐
q_0: ┤ H ├
     ├───┤
q_1: ┤ H ├
     └───┘

Initial: |ψ₀⟩ = |00⟩

After H gates on both qubits:

(H ⊗ H)|00⟩ = (H|0⟩) ⊗ (H|0⟩)

= ( (1/√2)(|0⟩+|1⟩) ) ⊗ ( (1/√2)(|0⟩+|1⟩) )

= (1/2)(|0⟩⊗|0⟩ + |0⟩⊗|1⟩ + |1⟩⊗|0⟩ + |1⟩⊗|1⟩)

= (1/2)(|00⟩ + |01⟩ + |10⟩ + |11⟩)

🌟 Amazing Result: Both qubits are now in superposition! The system has an equal 25% probability of being measured in ANY of the four possible states: |00⟩, |01⟩, |10⟩, or |11⟩.

Opening and Closing Multi-Qubit Superposition

Here’s the complete example showing interference:

     ┌───┐┌───┐
q_0: ┤ H ├┤ H ├
     ├───┤├───┤
q_1: ┤ H ├┤ H ├
     └───┘└───┘

Step 1: Initial State

|ψ₀⟩ = |00⟩

Step 2: After First H Gates (Opening Superposition)

|ψ₁⟩ = (1/2)(|00⟩ + |01⟩ + |10⟩ + |11⟩)

Equal superposition of all 4 states!

Step 3: After Second H Gates (Closing Superposition)

We need to apply H⊗H to each of the four states:

Input State After (H⊗H)
|00⟩ (1/2)(|00⟩ + |01⟩ + |10⟩ + |11⟩)
|01⟩ (1/2)(|00⟩ − |01⟩ + |10⟩ − |11⟩)
|10⟩ (1/2)(|00⟩ + |01⟩ − |10⟩ − |11⟩)
|11⟩ (1/2)(|00⟩ − |01⟩ − |10⟩ + |11⟩)

⚡ Quantum Interference Analysis:

For |00⟩: (1/4) × (+1 +1 +1 +1) = 4/4 = 1 ✓

Constructive interference!

For |01⟩: (1/4) × (+1 −1 +1 −1) = 0 ✗

Destructive interference – cancels out!

For |10⟩: (1/4) × (+1 +1 −1 −1) = 0 ✗

Destructive interference – cancels out!

For |11⟩: (1/4) × (+1 −1 −1 +1) = 0 ✗

Destructive interference – cancels out!

Final Result:

|ψ₂⟩ = |00⟩

🎉 We’re back to the original state through quantum interference!

Tensor Product of Hadamard Gates

The combined Hadamard operator H⊗H creates a 4×4 matrix:

H ⊗ H = (1/2) ×

1 1 1 1
1 −1 1 −1
1 1 −1 −1
1 −1 −1 1

This 4×4 matrix operates on the four-dimensional space of two-qubit states.

Why This Matters

The ability to create and manipulate superposition is what gives quantum computers their potential power. While a classical computer must check each possibility one at a time, a quantum computer in superposition can process multiple possibilities simultaneously.

The Art of Quantum Algorithm Design

  1. Opening Superposition: Using Hadamard gates to explore multiple states simultaneously
  2. Quantum Operations: Manipulating the superposition in clever ways
  3. Closing Superposition: Using interference to amplify the correct answer and cancel wrong ones

This is the foundation upon which all quantum algorithms are built, from Grover’s search algorithm to Shor’s factoring algorithm.

Conclusion

The qubit and Hadamard gate are the building blocks of quantum computation. By understanding how the Hadamard gate creates and collapses superposition through the mathematics of state vectors and tensor products, we gain insight into the fundamental principles that make quantum computing possible.

The next time you hear about quantum speedup or quantum advantage, remember that it all starts with these simple mathematical operations on qubits in superposition.


🚀 Ready to experiment yourself?

Popular quantum computing frameworks like Qiskit, Cirq, and Q# allow you to create and simulate these circuits on your own computer, and even run them on real quantum hardware through cloud platforms!

Exploring Quantum Entanglement: CHSH Game Simulator

Have you ever wondered how quantum mechanics and quantum computing defies our everyday intuition? Below is a project I built that demonstrates one of the most mind-bending phenomena in quantum physics: quantum entanglement and its ability to violate classical physics constraints.

Live Demo

🎮 Try the CHSH Game Simulator

📂 View on GitHub

What is the CHSH Game?

The CHSH (Clauser-Horne-Shimony-Holt) game is a fascinating thought experiment that reveals the strange power of quantum entanglement. It’s a cooperative game between two players, Alice and Bob, who cannot communicate with each other but share a special resource.

The Game Rules

  1. A referee sends random bits x and y to Alice and Bob respectively
  2. Alice outputs a bit a based on her input x
  3. Bob outputs a bit b based on his input y
  4. They win if: (a + b) mod 2 = x × y

The fascinating part? With classical strategies (no quantum physics), the maximum win rate is 75%. But with quantum entanglement, Alice and Bob can achieve approximately 85.4% – seemingly breaking the laws of classical physics!

Key Features

🎯 Interactive Visualization

The app features a real-time p5.js visualization that shows:

  • Entangled State: Two qubits in a maximally entangled Bell state
  • After Alice’s Measurement: How Alice’s measurement affects both qubits
  • After Bob’s Measurement: The final collapsed state after both measurements

Each stage includes:

  • Colored measurement basis quadrants (red, blue, orange, green)
  • Clear labels showing measurement outcomes (0 and 1)
  • Visual indication of quantum correlation (parallel or orthogonal)

🧪 Four Bell States

The simulator supports all four maximally entangled Bell states:

  1. |Φ+⟩ = (|00⟩ + |11⟩)/√2
  2. |Φ-⟩ = (|00⟩ – |11⟩)/√2
  3. |Ψ+⟩ = (|01⟩ + |10⟩)/√2
  4. |Ψ-⟩ = (|01⟩ – |10⟩)/√2

Each Bell state uses carefully optimized measurement angles to maximize the CHSH violation and achieve the theoretical ~85% win rate.

🎮 Strategy Comparison

Switch between:

  • Classical Strategy: Always outputs 0, achieving the theoretical 75% maximum
  • Quantum Strategy: Uses entangled qubits to beat classical limits

🎲 Flexible Input Controls

Choose input bits for Alice (x) and Bob (y):

  • Random: Simulates realistic random inputs
  • Fixed (0 or 1): Test specific measurement configurations

📊 Real-Time Statistics

Track performance with:

  • Total rounds played
  • Wins and losses
  • Win percentage that converges to theoretical predictions

🔄 Round History Navigation

Navigate through previous rounds to review specific outcomes and understand the quantum measurement process better.

The Science Behind It

Bell’s Inequality and CHSH

In 1964, physicist John Bell proved that no local hidden variable theory could reproduce all predictions of quantum mechanics. The CHSH inequality is a specific formulation of Bell’s theorem:

Classical limit: S ≤ 2

Quantum mechanics: S = 2√2 ≈ 2.828

This violation proves that quantum entanglement exhibits correlations that cannot be explained by any classical mechanism, even with shared randomness!

Measurement Angles

The key to achieving the quantum advantage lies in choosing the right measurement angles. For the standard |Φ+⟩ Bell state:

  • Alice’s bases: 0° (x=0), 45° (x=1)
  • Bob’s bases: 22.5° (y=0), -22.5° (y=1)

The probability that Alice and Bob get the same outcome is:

P(same) = cos²(δ)

where δ is the relative angle between their measurement bases. This quantum correlation is what allows them to beat the 75% classical limit.

Orthogonal vs Parallel Correlation

Different Bell states exhibit different correlation patterns:

  • Parallel correlation (|Φ+⟩, |Ψ+⟩): Qubits tend to give the same measurement outcome
  • Orthogonal correlation (|Φ-⟩, |Ψ-⟩): One qubit is rotated 90° relative to the other

The simulator accounts for these differences and adjusts the probability calculations accordingly.

Try It Yourself!

You can try the simulator and explore:

  1. Start with the Classical strategy and run 100 rounds – you’ll see it converge to ~75%
  2. Switch to Quantum with the |Φ+⟩ Bell state – watch it reach ~85%
  3. Try different Bell states and input combinations
  4. Use the round navigation to review specific outcomes

Future Enhancements

  • 3D Bloch Sphere Visualization: Show quantum states on the Bloch sphere using Three.js
  • Animated Transitions: Step-by-step animation of the measurement process
  • Educational Tutorial: Guided walkthrough explaining each concept
  • Mathematical Deep Dive: Optional panel with detailed probability calculations
  • Mobile Optimization: Touch-friendly controls and responsive layout

Open Source

The complete source code is available on GitHub. Feel free to:

  • Explore the code
  • Report issues
  • Suggest improvements
  • Fork and build your own quantum visualizations!

Conclusion

The CHSH game beautifully demonstrates that quantum entanglement isn’t just mathematical abstraction – it has measurable, observable consequences that defy classical intuition. This simulator makes that phenomenon interactive and accessible.

Whether you’re a physics student, educator, or simply curious about quantum mechanics, I hope this tool helps you develop an intuition for one of nature’s most fascinating phenomena.


Built with: React, p5.js, and Claude Code

Try it now: https://myhlow.github.io/chsh-game-simulator

Source code: https://github.com/myhlow/chsh-game-simulator


Have questions or suggestions? Leave a comment below or open an issue on GitHub!