5-Qubit Perfect Code
The 5-qubit perfect code is the smallest distance-3 stabilizer code that corrects an arbitrary single-qubit Pauli error. This repository implements state-vector encoding through stabilizer projection and syndrome-table recovery.
Stabilizers
fivequbit_stabilizers() returns:
XZZXI
IXZZX
XIXZZ
ZXIXZ
These four generators define a two-dimensional code space inside the five-qubit Hilbert space.
Logical States
encode_fivequbit(alpha_beta) constructs |0_L> by projecting a computational basis seed into the stabilizer +1 eigenspace and the logical-Z +1 eigenspace. It then applies logical X:
XXXXX
to construct |1_L>. The returned encoded state is:
alpha|0_L> + beta|1_L>
The implementation uses:
logical Z = ZZZZZ
logical X = XXXXX
Syndrome And Recovery
syndrome_fivequbit(psi) measures the four stabilizer generators.
correct_fivequbit(psi, syndrome) searches all single-qubit Pauli errors:
X, Y, Z on qubits 1 through 5
For each candidate error, it computes the expected syndrome with pauli_error_syndrome(...). When the expected syndrome matches the measured one, it applies the same Pauli as the correction.
The high-level recovery helper is:
[psi_corr, syndrome] = recover_fivequbit(psi_noisy);
The tests verify recovery from every single-qubit X, Y, and Z error on an arbitrary encoded logical state.
Main Files
src/fivequbit_stabilizers.msrc/encode_fivequbit.msrc/syndrome_fivequbit.msrc/correct_fivequbit.msrc/recover_fivequbit.msrc/pauli_error_syndrome.m
Examples
The 5-qubit implementation is covered by the text example runner:
octave --no-gui examples/run_text_examples.m
The recovery functions can also be called directly after adding src/ to the Octave path.
Tests
The main checks live in:
tests/test_stabilizer_codes.m
Run them through:
octave --no-gui tests/run_all_tests.m
Current Limits
projection, not an encoding circuit.
- Recovery is designed and tested for single-qubit Pauli errors.
- The implementation uses exact state-vector operations and stabilizer
- Logical gates and fault-tolerant measurement circuits are not implemented.