Lesson 4 of 15
The Hadamard Gate
Creating Superposition
The Hadamard gate (H) is the most fundamental quantum gate. It transforms basis states into equal superpositions:
- H|0 angle = rac{|0 angle + |1 angle}{sqrt{2}} = |+ angle
- H|1 angle = rac{|0 angle - |1 angle}{sqrt{2}} = |- angle
As a matrix:
H = rac{1}{sqrt{2}}egin{pmatrix} 1 & 1 \ 1 & -1 end{pmatrix}
Applied to [alpha, eta]:
ight]$$ ```python import math def hadamard(state): s = 1 / math.sqrt(2) a, b = state[0], state[1] return [s * (a + b), s * (a - b)] zero = [1.0, 0.0] plus = hadamard(zero) # |+⟩ print(round(plus[0], 4)) # 0.7071 print(round(plus[1], 4)) # 0.7071 ``` A key property: **H applied twice is the identity** — H is its own inverse. ```python original = hadamard(hadamard(zero)) print(round(original[0], 4)) # 1.0 print(round(original[1], 4)) # 0.0 ``` ### Your Task Implement the Hadamard gate.Python runtime loading...
Loading...
Click "Run" to execute your code.