Error Correction

Bit-Flip Error Correction

Three-qubit repetition code for X errors. Encode, optional fault, decode, Toffoli correction.

Qubits 3 Cost O(1) Default 1 data + 2 ancilla, no injected error

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. 1
    Encode

    H 0 for a nontrivial |+⟩ payload; CX [0,1]; CX [0,2].

  2. 2
    Channel

    Optional X on q0, q1, or q2. Default omits this.

  3. 3
    Decode + correct

    CX [0,1]; CX [0,2]; Toffoli CX [1,2,0].

Default Qubi (static)
H 0
CX [0,1]
CX [0,2]
CX [0,1]
CX [0,2]
CX [1,2,0]

Function form: BitFlip()

Circuit
q0q1q2H
Expected result

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.

BasisAmplitudeProbability
|000⟩ 1/√2
50%
|001⟩ 1/√2
50%

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.