Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The standard-form encoding network maps |c⟩ to the encoded basis state (4.8)

Open
QAlgorithms.GottesmanThesis.stabEncoder_encodes

by Goku · Oct 13, 2026 · Mathlib 0df444a (Lean v4.33.1)

gottesman-thesislecture-notesquantum-information

Let a stabilizer on n=m+kn=m+kn=m+k qubits (m=n−km=n-km=n−k generators) be given in the standard form (4.3) of §4.1,

(IA1A2BC1C2000DIE),\left(\begin{array}{ccc|ccc} I & A_1 & A_2 & B & C_1 & C_2\\ 0 & 0 & 0 & D & I & E\end{array}\right),(I0​A1​0​A2​0​BD​C1​I​C2​E​),

with rrr rows in the first block, and assume its rows commute: HxHzT+HzHxT=0H_xH_z^{\mathsf T}+H_zH_x^{\mathsf T}=0Hx​HzT​+Hz​HxT​=0. For a binary row (a ∣ b)(a\,|\,b)(a∣b) write P(a∣b)=⨂qσzbqσxaqP(a|b)=\bigotimes_q \sigma_z^{b_q}\sigma_x^{a_q}P(a∣b)=⨂q​σzbq​​σxaq​​ (the real form, sign +1+1+1). Let Mi=P(row i)M_i=P(\text{row } i)Mi​=P(row i) be the generators and let Xˉ1,…,Xˉk\bar X_1,\dots,\bar X_kXˉ1​,…,Xˉk​ be the logical σx\sigma_xσx​ operators in the standard form of p.40: Xˉi=P(0 u2 ei ∣ v1 0 0)\bar X_i=P(0\,u_2\,e_i\,|\,v_1\,0\,0)Xˉi​=P(0u2​ei​∣v1​00) with u2u_2u2​ the iii-th row of ETE^{\mathsf T}ET and v1v_1v1​ the iii-th row of ETC1T+C2TE^{\mathsf T}C_1^{\mathsf T}+C_2^{\mathsf T}ETC1T​+C2T​.

Let UencU_{\mathrm{enc}}Uenc​ be the encoding network of §4.2 (with the author's errata): first, for each iii, the controlled-NOTs that apply Xˉi\bar X_iXˉi​ without its final σx\sigma_xσx​, controlled on qubit n−k+in-k+in−k+i; then, for i=1,…,ri=1,\dots,ri=1,…,r in turn, the Hadamard RRR on qubit iii, a σz\sigma_zσz​ on qubit iii if Bii=1B_{ii}=1Bii​=1, and MiM_iMi​ without its qubit-iii factor, controlled on qubit iii (controlled-σzbσxa\sigma_z^{b}\sigma_x^{a}σzb​σxa​ gates). Then for every c=c1…ck∈{0,1}kc=c_1\dots c_k\in\{0,1\}^kc=c1​…ck​∈{0,1}k,

Uenc ∣0…0⟩∣c1…ck⟩=(I+M1)⋯(I+Mn−k) Xˉ1c1⋯Xˉkck∣0…0⟩∥(I+M1)⋯(I+Mn−k) Xˉ1c1⋯Xˉkck∣0…0⟩∥,U_{\mathrm{enc}}\,|0\dots0\rangle|c_1\dots c_k\rangle=\frac{(I+M_1)\cdots(I+M_{n-k})\,\bar X_1^{c_1}\cdots\bar X_k^{c_k}|0\dots0\rangle}{\big\|(I+M_1)\cdots(I+M_{n-k})\,\bar X_1^{c_1}\cdots\bar X_k^{c_k}|0\dots0\rangle\big\|},Uenc​∣0…0⟩∣c1​…ck​⟩=​(I+M1​)⋯(I+Mn−k​)Xˉ1c1​​⋯Xˉkck​​∣0…0⟩​(I+M1​)⋯(I+Mn−k​)Xˉ1c1​​⋯Xˉkck​​∣0…0⟩​,

and in particular the vector on the right-hand side is nonzero.

This is the correctness of Gottesman's general encoding circuit for stabilizer codes: the network prepares exactly the encoded basis states, with no leftover global phase.

Formalization Note The errata are built in: the Hadamard on qubit iii comes just before that qubit's control operations, controlled-YYY gates are controlled-σzσx\sigma_z\sigma_xσz​σx​ gates in the real form, and every generator has sign +1+1+1. The page writes encoded states unnormalized; the unitary network yields the normalized vector. Since the real form σzσx=iσy\sigma_z\sigma_x=i\sigma_yσz​σx​=iσy​, a generator with an odd number of (1∣1)(1|1)(1∣1) positions is iii times a Hermitian Pauli operator; the identity is the one the page's network computes in this convention.

Preamble
import Definitions.Def_QAlgorithms_Defs_BinaryStabilizer
set_option autoImplicit false
Formal statement
namespace QAlgorithms.GottesmanThesis


/-- Gottesman thesis pp.41–43, §4.2 (unnumbered; equation (4.8)), with the author's errata:
for a stabilizer in standard form (4.3) with rank parameter `r` and commuting rows, and the
logical `X̄` operators in the standard form of p.40 (`U₃ = I`, `V₃ = 0`, `U₂ = Eᵀ`,
`V₁ = EᵀC₁ᵀ + C₂ᵀ`), the encoding network of §4.2 maps the input `|0…0⟩|c₁…c_k⟩` (the first
`n − k` qubits in `|0⟩`, `|c_i⟩` in qubit `n − k + i`) to the normalized encoded basis state
`(I + M₁)⋯(I + M_{n−k}) X̄₁^{c₁}⋯X̄_k^{c_k} |0…0⟩`.

The network (`stabEncoder`) is the controlled-NOT step (each `X̄_i` without its last `σx`,
controlled on qubit `n − k + i`), followed, for `i = 1, …, r` in turn, by `R` on qubit `i`, `σz`
on qubit `i` if `B_ii = 1`, and `M_i` (without its qubit-`i` factor) controlled on qubit `i`
(erratum: Hadamard just before the qubit's control dots). Generators and `X̄`'s are the
real-form Pauli products `σz^b σx^a` with sign `+1` (errata: controlled-`Y` is controlled-`XZ`;
the method needs every generator of sign `+1`). -/
theorem stabEncoder_encodes {m k r : ℕ} (Hx Hz : Matrix (Fin m) (Fin (m + k)) (ZMod 2))
    (hstd : IsStandardForm r Hx Hz) (hcomm : SymplecticCommuting Hx Hz) (c : Qubits k) :
    act (stabEncoder r Hx Hz).unitary (ket (Fin.append (fun _ : Fin m => false) c)) =
      normalizedVec (stabEncodedState r Hx Hz c) := by
  sorry

end QAlgorithms.GottesmanThesis
Source
Daniel Gottesman, Stabilizer Codes and Quantum Error Correction, 1997 thesis, downloaded arXiv v1 PDF; PDF title page now prints 2024, PDF p. 41, §4.2. https://arxiv.org/pdf/quant-ph/9705052v1
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Setting. Fix natural numbers m,k,rm, k, rm,k,r and m×(m+k)m\times(m+k)m×(m+k) matrices Hx,HzH_x, H_zHx​,Hz​ over F2\mathbb{F}_2F2​. The register has m+km+km+k qubits on wires 0,…,m+k−10,\dots,m+k-10,…,m+k−1. Basis states ∣z⟩|z\rangle∣z⟩ are labelled by bit strings z∈{0,1}m+kz \in \{0,1\}^{m+k}z∈{0,1}m+k, with wire 000 the most significant.

Hypotheses.

  1. Standard form with parameter rrr:
    • r≤mr\le mr≤m;
    • (Hx)ij=δij(H_x)_{ij}=\delta_{ij}(Hx​)ij​=δij​ for i,j<ri,j<ri,j<r;
    • row iii of HxH_xHx​ is zero for every i≥ri\ge ri≥r;
    • (Hz)ij=δij(H_z)_{ij}=\delta_{ij}(Hz​)ij​=δij​ for i≥ri\ge ri≥r and r≤j<mr\le j<mr≤j<m.
  2. Symplectic commutation: HxHzT+HzHxT=0H_xH_z^{\mathsf T}+H_zH_x^{\mathsf T}=0Hx​HzT​+Hz​HxT​=0 over F2\mathbb{F}_2F2​.

No linear-independence hypothesis is assumed.

Input. Take an arbitrary c∈{0,1}kc\in\{0,1\}^kc∈{0,1}k. The input is the basis state ∣0mc⟩|0^m c\rangle∣0mc⟩: wires 0,…,m−10,\dots,m-10,…,m−1 are 000 and wire m+im+im+i carries cic_ici​.

The circuit. The encoder is a list of gates applied in list order, first gate first. If the list is g1,…,gLg_1,\dots,g_Lg1​,…,gL​, its unitary is U=EL⋯E1U = E_L\cdots E_1U=EL​⋯E1​. Each EEE acts as the gate's matrix on its wires (in the listed order) and as the identity on all other wires.

A controlled gate C(V)C(V)C(V) with control wire aaa and target wire bbb acts as

∣0⟩⟨0∣a⊗1+∣1⟩⟨1∣a⊗Vb.|0\rangle\langle 0|_a\otimes 1 + |1\rangle\langle1|_a\otimes V_b.∣0⟩⟨0∣a​⊗1+∣1⟩⟨1∣a​⊗Vb​.

Here X=(0110)X=\begin{pmatrix}0&1\\1&0\end{pmatrix}X=(01​10​), Z=diag⁡(1,−1)Z=\operatorname{diag}(1,-1)Z=diag(1,−1), and HHH is the Hadamard gate.

The gate list is the concatenation of two parts.

  • Part 1. For i=0,…,k−1i=0,\dots,k-1i=0,…,k−1 in order, and within that for j=0,…,m−1j=0,\dots,m-1j=0,…,m−1 in order:
    • if j≥rj\ge rj≥r and (Hz)j,m+i=1(H_z)_{j,m+i}=1(Hz​)j,m+i​=1, apply C(X)C(X)C(X) with control wire m+im+im+i and target wire jjj.
  • Part 2. For i=0,…,m−1i=0,\dots,m-1i=0,…,m−1 in order, and only when i<ri<ri<r:
    1. apply HHH on wire iii;
    2. then, if (Hz)ii=1(H_z)_{ii}=1(Hz​)ii​=1, apply ZZZ on wire iii;
    3. then, for q=0,…,m+k−1q=0,\dots,m+k-1q=0,…,m+k−1 in order with q≠iq\ne iq=i and ((Hx)iq,(Hz)iq)≠(0,0)\big((H_x)_{iq},(H_z)_{iq}\big)\ne(0,0)((Hx​)iq​,(Hz​)iq​)=(0,0), apply C(Viq)C(V_{iq})C(Viq​) with control wire iii and target wire qqq, where
Viq=Z(Hz)iqX(Hx)iq.V_{iq}=Z^{(H_z)_{iq}}X^{(H_x)_{iq}}.Viq​=Z(Hz​)iq​X(Hx​)iq​.

Rows i≥ri\ge ri≥r contribute no gates.

The target vector. For a,b∈F2m+ka,b\in\mathbb{F}_2^{m+k}a,b∈F2m+k​, define the unphased Pauli operator

P(a,b)=⨂qZbqXaq.P(a,b)=\bigotimes_{q}Z^{b_q}X^{a_q}.P(a,b)=q⨂​Zbq​Xaq​.

In particular, YYY appears as ZXZXZX.

For each i<ki<ki<k, the logical operator is Xˉi=P(a(i),b(i))\bar X_i=P(a^{(i)},b^{(i)})Xˉi​=P(a(i),b(i)), where:

  • for j<mj<mj<m:
aj(i)={(Hz)j,m+ij≥r,0j<r;a^{(i)}_j=\begin{cases}(H_z)_{j,m+i} & j\ge r,\\ 0 & j<r;\end{cases}aj(i)​={(Hz​)j,m+i​0​j≥r,j<r;​
  • for j≥mj\ge mj≥m: aj(i)=1a^{(i)}_j=1aj(i)​=1 if j=m+ij=m+ij=m+i, and 000 otherwise;
  • for j<rj<rj<r:
bj(i)=∑r≤l<m(Hz)l,m+i(Hz)jl+(Hz)j,m+i,b^{(i)}_j=\sum_{r\le l<m}(H_z)_{l,m+i}(H_z)_{jl}+(H_z)_{j,m+i},bj(i)​=r≤l<m∑​(Hz​)l,m+i​(Hz​)jl​+(Hz​)j,m+i​,

computed in F2\mathbb{F}_2F2​;

  • for j≥rj\ge rj≥r: bj(i)=0b^{(i)}_j=0bj(i)​=0.

Define

Ψc=(∏i=m−10(1+P(rowiHx,rowiHz)))(∏i=k−10Xˉi ci)∣0m+k⟩.\Psi_c=\Big(\prod_{i=m-1}^{0}\big(1+P(\text{row}_i H_x,\text{row}_i H_z)\big)\Big)\Big(\prod_{i=k-1}^{0}\bar X_i^{\,c_i}\Big)|0^{m+k}\rangle.Ψc​=(i=m−1∏0​(1+P(rowi​Hx​,rowi​Hz​)))(i=k−1∏0​Xˉici​​)∣0m+k⟩.

In each product the factor with index 000 is applied first. The factors 1+P1+P1+P carry no 12\tfrac1221​.

Conclusion.

U ∣0mc⟩=Ψc∥Ψc∥.U\,|0^m c\rangle=\frac{\Psi_c}{\|\Psi_c\|}.U∣0mc⟩=∥Ψc​∥Ψc​​.

The normalization uses the convention ∥0∥−1=0\|0\|^{-1}=0∥0∥−1=0. So if Ψc=0\Psi_c=0Ψc​=0, the right-hand side is the zero vector.

Degenerate case. When m=0m=0m=0 the circuit is empty, so U=1U=1U=1.

Human review
  • Endorsed by Shuze Chen · Oct 13, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Goku · Oct 13, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me