Bivariate-bicycle codes: circulants, , , logicals and distances
DefinitionBBCode_SettingSetting for bivariate-bicycle (BB) quantum codes.
Fix and . The monomial of is , and a polynomial is the finite set of its monomials. The circulant of is the binary matrix with entry at iff . For polynomials the code acts on qubits with
over .
- A nontrivial Z-logical is with and ; a nontrivial X-logical is with and .
- The weight is the number of nonzero coordinates.
- The Z-distance (resp. X-distance) is exactly when some nontrivial Z-logical (X-logical) has weight and all have weight .
- The code encodes logical qubits when .
IsCode A B n k dmeans , logical qubits, and .- The Tanner graph joins each qubit to the X- and Z-checks with a in its column; the code is connected when this graph is connected.
These definitions are shared by every statement of the mission.
Formalization Note is stated additively to avoid truncated natural subtraction; each distance predicate includes the existence of a logical of weight exactly , so it cannot hold vacuously.
import Mathlib
/-!
Bivariate-bicycle (BB) quantum codes, following §2 of Daugherty–Ryan–Ward,
"New distance-12 bivariate-bicycle codes with 20 and 24 logical qubits"
(Zenodo 10.5281/zenodo.23382175, v1.0.0, 2026-10-14), and Bravyi et al.,
Nature 627, 778 (2024).
-/
namespace BBCode
open Matrix
/-- The group `ℤ_l × ℤ_m`. The monomial `x^i y^j` of `𝔽₂[x,y]/(x^l - 1, y^m - 1)` is the
element `(i, j)`. -/
abbrev Grp (l m : ℕ) := ZMod l × ZMod m
/-- A polynomial of `𝔽₂[x,y]/(x^l - 1, y^m - 1)`, given by its support: the finite set of
monomials `(i, j)` whose coefficient is `1`. -/
abbrev Poly (l m : ℕ) := Finset (Grp l m)
/-- The `lm × lm` circulant of a polynomial `P`: row `g` has a `1` in column `g + t`
for each monomial `t ∈ P`, and `0` elsewhere. -/
def circulant {l m : ℕ} (P : Poly l m) : Matrix (Grp l m) (Grp l m) (ZMod 2) :=
fun g h => if h - g ∈ P then 1 else 0
/-- The physical qubits: two blocks of `lm` qubits, `n = 2lm` in total. -/
abbrev Qubit (l m : ℕ) := Grp l m ⊕ Grp l m
/-- The X-check matrix `H_X = [A | B]`. -/
def HX {l m : ℕ} (A B : Poly l m) : Matrix (Grp l m) (Qubit l m) (ZMod 2) :=
Matrix.fromCols (circulant A) (circulant B)
/-- The Z-check matrix `H_Z = [Bᵀ | Aᵀ]`. -/
def HZ {l m : ℕ} (A B : Poly l m) : Matrix (Grp l m) (Qubit l m) (ZMod 2) :=
Matrix.fromCols (circulant B)ᵀ (circulant A)ᵀ
/-- The row space of a binary matrix: the `𝔽₂`-span of its rows. -/
def rowSpace {r c : Type} (H : Matrix r c (ZMod 2)) : Submodule (ZMod 2) (c → ZMod 2) :=
Submodule.span (ZMod 2) (Set.range H)
/-- The Hamming weight of a binary vector: the number of nonzero coordinates. -/
def weight {ι : Type} [Fintype ι] (v : ι → ZMod 2) : ℕ :=
(Finset.univ.filter fun i => v i ≠ 0).card
/-- A nontrivial Z-logical operator: `H_X v = 0` and `v ∉ row(H_Z)`. -/
def IsZLogical {l m : ℕ} [NeZero l] [NeZero m] (A B : Poly l m) (v : Qubit l m → ZMod 2) :
Prop :=
HX A B *ᵥ v = 0 ∧ v ∉ rowSpace (HZ A B)
/-- A nontrivial X-logical operator: `H_Z v = 0` and `v ∉ row(H_X)`. -/
def IsXLogical {l m : ℕ} [NeZero l] [NeZero m] (A B : Poly l m) (v : Qubit l m → ZMod 2) :
Prop :=
HZ A B *ᵥ v = 0 ∧ v ∉ rowSpace (HX A B)
/-- The Z-distance is exactly `d`: some nontrivial Z-logical has weight `d`, and every
nontrivial Z-logical has weight at least `d`. -/
def HasZDistance {l m : ℕ} [NeZero l] [NeZero m] (A B : Poly l m) (d : ℕ) : Prop :=
(∃ v, IsZLogical A B v ∧ weight v = d) ∧ ∀ v, IsZLogical A B v → d ≤ weight v
/-- The X-distance is exactly `d`. -/
def HasXDistance {l m : ℕ} [NeZero l] [NeZero m] (A B : Poly l m) (d : ℕ) : Prop :=
(∃ v, IsXLogical A B v ∧ weight v = d) ∧ ∀ v, IsXLogical A B v → d ≤ weight v
/-- The code encodes `k` logical qubits: `k = n - rank H_X - rank H_Z` with `n = 2lm`
(stated additively to avoid truncated subtraction). -/
def NumLogical {l m : ℕ} [NeZero l] [NeZero m] (A B : Poly l m) (k : ℕ) : Prop :=
(HX A B).rank + (HZ A B).rank + k = 2 * (l * m)
/-- The BB code of `(A, B)` is an `[[n, k, d]]` code with `d_X = d_Z = d`. -/
def IsCode {l m : ℕ} [NeZero l] [NeZero m] (A B : Poly l m) (n k d : ℕ) : Prop :=
n = 2 * (l * m) ∧ NumLogical A B k ∧ HasXDistance A B d ∧ HasZDistance A B d
/-- The Tanner graph: qubits are joined to the X- and Z-checks that act on them. -/
def tannerGraph {l m : ℕ} (A B : Poly l m) :
SimpleGraph (Qubit l m ⊕ (Grp l m ⊕ Grp l m)) :=
SimpleGraph.fromRel fun u w =>
match u, w with
| Sum.inl q, Sum.inr (Sum.inl c) => HX A B c q = 1
| Sum.inl q, Sum.inr (Sum.inr c) => HZ A B c q = 1
| _, _ => False
/-- A BB code is connected (indecomposable) when its Tanner graph is connected. -/
def IsConnected {l m : ℕ} (A B : Poly l m) : Prop :=
(tannerGraph A B).Connected
end BBCode
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
This item is a file of definitions only; it asserts nothing by itself. Everything is parametrised by natural numbers .
- Group. (integers mod times integers mod ). Edge case: if (resp. ), the factor is the full integers , so is infinite. The definitions below that need finiteness (logical operators, distances, logical count,
IsCode) explicitly require and ; the circulant, the check matrices, the Tanner graph and its connectivity do not, and are also defined (on infinite index sets) when or . - Polynomials. A polynomial is a finite subset of , interpreted as the support of an element of , with . Because it is a set, every monomial has coefficient or and listed duplicates would silently merge.
- Circulant. is the matrix over with
so row has ones exactly at columns , . Its transpose has iff .
- Qubits. : a left block and a right block , each a copy of (so qubits when ).
- Check matrices. Rows indexed by , columns by :
the first block acting on , the second on .
- Row space. is the -linear span of the rows of .
- Weight. = number of coordinates where (Hamming weight).
- Nontrivial Z-logical (needs ): with and . Nontrivial X-logical: and . The weight used later is the weight of itself (all members of a coset are separately considered, so the minimum is over all such ).
- Exact Z-distance : there exists a nontrivial Z-logical of weight exactly , and every nontrivial Z-logical has weight ; i.e. is the minimum weight. If no nontrivial Z-logical exists (e.g. zero logical qubits) this predicate is false for every . Exact X-distance is defined identically with X-logicals.
- Number of logical qubits : . Stated additively, so there is no truncated subtraction; is uniquely determined when it holds.
IsCode: , the logical count is , the X-distance is exactly , and the Z-distance is exactly (the same for both). It contains no condition on the sizes of and no connectivity condition.- Tanner graph. A simple graph on vertex set , where and are two further copies of (X-checks and Z-checks). Edges: qubit — X-check iff ; qubit — Z-check iff ; no other edges (no qubit–qubit or check–check edges), symmetrised and loop-free.
IsConnected: the Tanner graph is connected (nonempty, and every two vertices are joined by a path). Both X- and Z-checks are in this single graph. No assumption is imposed here.
The docstrings cite Daugherty–Ryan–Ward and Bravyi et al.; those references have no formal content.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.