Lesson 5 of 15

The X Gate

The Quantum NOT Gate

The Pauli-X gate (X) is the quantum equivalent of the classical NOT gate. It flips the amplitudes:

  • X0angle=1angleX|0 angle = |1 angle
  • X1angle=0angleX|1 angle = |0 angle

As a matrix:

X = egin{pmatrix} 0 & 1 \ 1 & 0 end{pmatrix}

On a general state [alpha, eta], it simply swaps the two amplitudes:

X[alpha, eta] = [eta, alpha]

def x_gate(state):
    return [state[1], state[0]]

zero = [1.0, 0.0]
one = [0.0, 1.0]

print(x_gate(zero))  # [0.0, 1.0]  — flipped to |1⟩
print(x_gate(one))   # [1.0, 0.0]  — flipped to |0⟩

Like the Hadamard gate, X applied twice is the identity — applying NOT twice returns to the original state.

On a superposition state left[ rac{1}{sqrt{2}}, rac{1}{sqrt{2}} ight], X has no effect because both amplitudes are equal. On left[ rac{1}{sqrt{2}}, - rac{1}{sqrt{2}} ight], X flips the sign pattern.

Your Task

Implement x_gate(state) that applies the Pauli-X gate.

Python runtime loading...
Loading...
Click "Run" to execute your code.