Lesson 2 of 15
Normalization
Valid Quantum States
Not every pair of numbers is a valid qubit. The normalization condition requires:
|alpha|^2 + |eta|^2 = 1
This ensures the probabilities of all outcomes sum to 1. The quantity sqrt{alpha^2 + eta^2} is called the norm of the state.
import math
def norm(state):
return math.sqrt(state[0]**2 + state[1]**2)
def is_normalized(state):
return abs(norm(state) - 1.0) < 1e-9
print(is_normalized([1.0, 0.0])) # True
print(is_normalized([0.6, 0.8])) # True (0.36 + 0.64 = 1)
print(is_normalized([3.0, 4.0])) # False (9 + 16 = 25, norm = 5)
To fix an unnormalized state, divide each amplitude by the norm:
def normalize(state):
n = norm(state)
return [state[0] / n, state[1] / n]
print(normalize([3.0, 4.0])) # [0.6, 0.8]
Your Task
Implement norm(state), is_normalized(state), and normalize(state).
Python runtime loading...
Loading...
Click "Run" to execute your code.