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 1angle|1 angle:

InputOutput
$00
angle$$
angle$
$01
angle$$
angle$
$10
angle$$
angle$
$11
angle$$
angle$

In terms of the 4-element state vector [alpha00,alpha01,alpha10,alpha11][alpha_{00}, alpha_{01}, alpha_{10}, alpha_{11}]:

extCNOT[alpha00,alpha01,alpha10,alpha11]=[alpha00,alpha01,alpha11,alpha10] ext{CNOT}[alpha_{00}, alpha_{01}, alpha_{10}, alpha_{11}] = [alpha_{00}, alpha_{01}, alpha_{11}, alpha_{10}]

Indices 2 and 3 (the 10angle|10 angle and 11angle|11 angle 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.