Three-qubit repetition code for X errors. Encode, optional fault, decode, Toffoli correction.
Logical |ψ⟩ = α|0⟩+β|1⟩ encodes to α|000⟩+β|111⟩. In 1-data mode, q0 is data and q1, q2 are encoding ancillas. Reverse CNOTs write the syndrome onto the ancillas. CX [1,2,0] (Toffoli) flips q0 back if both syndrome bits are 1.
Default: prepare |+⟩ on q0, encode, no error, decode. The data qubit is still |+⟩. Inject X on a chosen wire in the simulator to see correction.
How it works
-
1
Encode
H 0 for a nontrivial |+⟩ payload; CX [0,1]; CX [0,2].
-
2
Channel
Optional X on q0, q1, or q2. Default omits this.
-
3
Decode + correct
CX [0,1]; CX [0,2]; Toffoli CX [1,2,0].
H 0 CX [0,1] CX [0,2] CX [0,1] CX [0,2] CX [1,2,0]
Function form: BitFlip()
State. q0 = |+⟩, ancillas |00⟩ (no error)
Without an injected X, P(q1=q2=0) = 1 and q0 is |+⟩ so P(q0=0)=P(q0=1)=1/2.
| Basis | Amplitude | Probability |
|---|---|---|
|000⟩ |
1/√2 |
|
|001⟩ |
1/√2 |
Notes
- This code does not correct Z (phase) errors. Use the phase-flip code (Hadamard sandwich) or the Shor 9-qubit code for both.
- 3-data + 2-ancilla mode keeps the encoded block and uses extra syndrome qubits (5 wires).
Change parameters
The write-up above is for the default circuit. Use this control to generate other variants and load them in the simulator.