# 7-Qubit Steane Code

The Steane code is a CSS stabilizer code built from the classical Hamming
parity-check matrix. This repository implements state-vector encoding,
separate X/Z syndrome extraction, and single-qubit Pauli recovery.

## Parity-Check Matrix

`steane_parity_check()` returns:

```text
1 0 1 0 1 0 1
0 1 1 0 0 1 1
0 0 0 1 1 1 1
```

The same matrix is used for Z-type and X-type stabilizer checks.

## Logical States

`encode_steane(alpha_beta)` constructs `|0_L>` as the equal superposition over
the eight codewords generated by the rows of the parity-check matrix. `|1_L>`
is the bitwise complement superposition. The returned encoded state is:

```text
alpha|0_L> + beta|1_L>
```

## Stabilizers And Syndrome

`stabilizers_for_code('steane')` builds six generators:

- three Z-type checks from rows of the Hamming matrix,
- three X-type checks from the same rows.

`syndrome_steane(psi)` returns:

- `syn.x`: the syndrome from Z checks, used to locate the X component of an
  error.
- `syn.z`: the syndrome from X checks, used to locate the Z component of an
  error.

For a Y error, both syndrome parts are nonzero because Y has both X and Z
components.

## Recovery Flow

The high-level recovery helper is:

```matlab
[psi_corr, syndrome] = recover_steane(psi_noisy);
```

`correct_steane(psi, syndrome)` converts each three-bit syndrome into a qubit
index with `binary_syndrome_index(...)`. It applies an X correction for
`syn.x` and a Z correction for `syn.z`.

The tests verify recovery from every single-qubit X, Y, and Z error on an
arbitrary encoded logical state.

## Main Files

- `src/steane_parity_check.m`
- `src/encode_steane.m`
- `src/syndrome_steane.m`
- `src/correct_steane.m`
- `src/recover_steane.m`
- `src/stabilizers_for_code.m`

## Examples

```bash
octave --no-gui examples/minimal_steane_recovery.m
```

## Tests

The main checks live in:

- `tests/test_stabilizer_codes.m`

Run them through:

```bash
octave --no-gui tests/run_all_tests.m
```

## Current Limits

- Recovery is designed and tested for single-qubit Pauli errors.
- The code uses direct projective stabilizer measurements, not a circuit-level
  syndrome extraction model.
- Transversal logical gates are not implemented.
