Lesson 8 of 15
The CNOT Gate
Controlled Operations
The CNOT gate (Controlled-NOT) is the most important two-qubit gate. It flips the second qubit (target) if and only if the first qubit (control) is :
| Input | Output |
|---|---|
| $ | 00 |
| angle$ | $ |
| angle$ | |
| $ | 01 |
| angle$ | $ |
| angle$ | |
| $ | 10 |
| angle$ | $ |
| angle$ | |
| $ | 11 |
| angle$ | $ |
| angle$ |
In terms of the 4-element state vector :
Indices 2 and 3 (the and amplitudes) are swapped.
def cnot(state):
return [state[0], state[1], state[3], state[2]]
ket_10 = [0.0, 0.0, 1.0, 0.0] # |10⟩
print(cnot(ket_10)) # [0.0, 0.0, 0.0, 1.0] — becomes |11⟩
Your Task
Implement cnot(state) for a 4-element two-qubit state.
Python runtime loading...
Loading...
Click "Run" to execute your code.