AI Launch Lab
Sign in FR Get updates

Quantum computing basics · Lesson 2 of 3

Gates change the state

Quantum programs are built from gates. A one-qubit gate is a 2×2 table of numbers (a matrix). Applying it to the state [a, b] gives a new state:

[g00·a + g01·b, g10·a + g11·b]

The X gate [[0, 1], [1, 0]] swaps the amplitudes: it flips 0 and 1, like a classical NOT. The Hadamard gate H = [[s, s], [s, -s]] with s = 1/√2 turns [1, 0] into an equal superposition. Applying H twice brings the qubit back where it started: the two paths to 1 cancel out. That cancellation, called interference, is what quantum algorithms use.

Your turn

Write apply(gate, state), which returns the new state after applying a 2×2 gate to [a, b].

Loading Python (about 12 MB, once)…

    Checks

    • ○ X flips [1, 0] to [0, 1]
    • ○ H makes an equal superposition
    • ○ H twice returns to [1, 0]

    Output

    ← Previous lesson All courses