|q⟩ Bad Qubits

intermediate · Programming · Quantum Walks

The Shift Operator

A discrete-time quantum walk alternates two operations: first a coin toss (the coin operator, usually a Hadamard), then a conditional shift that moves the walker left or right depending on the coin's state. This lesson focuses on the shift.

The conditional shift

Label the walker's direction qubit as d|d\rangle and its position as x|x\rangle. The conditional shift SS satisfies

Sdx=dx+(1)1dmodN,S\,|d\rangle\,|x\rangle = |d\rangle\,|x + (-1)^{1-d} \bmod N\rangle,

meaning: move right (xx+1x \to x+1) when d=1d = 1, and left (xx1x \to x-1) when d=0d = 0.

On a line of N=4N = 4 positions we need 2 bits to label positions 0,1,2,30, 1, 2, 3. The coin qubit q0q_0 and position register (q1,q2)(q_1, q_2) give a 3-qubit system. The right-shift rule (d=1:xx+1mod4)(d=1: x \to x+1 \bmod 4) is a controlled binary increment:

Sright:q1q1(q0q2),q2q2q0.S_{\text{right}}: \quad q_1 \leftarrow q_1 \oplus (q_0 \land q_2), \qquad q_2 \leftarrow q_2 \oplus q_0.

The first line propagates the carry (flip the high bit only when both the coin and the low bit are 11); the second line always flips the low bit when the coin is 11. Together they increment the position by 1mod41 \bmod 4 whenever q0=1q_0 = 1.

In circuit notation this is a Toffoli gate (CCX) followed by a CNOT (CX):

CCX(q0,q2,q1)    then    CX(q0,q2).\text{CCX}(q_0,\, q_2,\, q_1) \;\;\text{then}\;\; \text{CX}(q_0,\, q_2).

Concrete example

Start with coin =1= 1 and position =1= 1 (binary 0101), i.e. the state 101|1\rangle|01\rangle:

101CCX(0,2,1)111CX(0,2)110=110.|1\,0\,1\rangle \xrightarrow{\text{CCX}(0,2,1)} |1\,1\,1\rangle \xrightarrow{\text{CX}(0,2)} |1\,1\,0\rangle = |1\rangle|10\rangle.

Position 012=101_2 = 1 has become 102=210_2 = 2: the walker moved one step to the right.

Conditionality is the key

The shift is coherent: when the coin is in superposition 12(0+1)\tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle), the walker's position entangles with the coin and spreads in both directions simultaneously. Classical random walks pick one direction per step; quantum walks create a superposition of paths, leading to the quadratically faster spreading observed in later lessons.

Try it

The circuit below starts in 101|1\rangle|01\rangle (coin =1= 1, position =1= 1). Complete the conditional shift so the final state is 110|1\rangle|10\rangle (position =2= 2). The grader checks the full statevector.

Run your code to see the quantum state.

After pressing Run, the statevector should show a single amplitude of 11 on the basis state 110=q0q1q2|110\rangle = q_0 q_1 q_2 (with qubit 0 most significant), confirming the walker moved exactly one step to the right.

Sign in on the full site to ask questions and join the discussion.