Lesson 6 of 15

The Z Gate

The Phase Flip Gate

The Pauli-Z gate flips the phase (sign) of the 1angle|1 angle amplitude while leaving 0angle|0 angle unchanged:

  • Z0angle=0angleZ|0 angle = |0 angle
  • Z1angle=1angleZ|1 angle = -|1 angle

As a matrix:

Z = egin{pmatrix} 1 & 0 \ 0 & -1 end{pmatrix}

On a general state [alpha, eta]:

Z[alpha, eta] = [alpha, -eta]

def z_gate(state):
    return [state[0], -state[1]]

The Z gate has no classical equivalent — it introduces a phase that is invisible when measuring in the computational basis, but becomes observable when combined with other gates.

For example, Z transforms +angle|+ angle into angle|- angle:

import math
s = 1 / math.sqrt(2)
plus = [s, s]       # |+⟩
minus = z_gate(plus) # |−⟩ = [s, -s]
print(round(minus[0], 4))   # 0.7071
print(round(minus[1], 4))   # -0.7071

Your Task

Implement z_gate(state) that applies the Pauli-Z phase flip.

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