Birch and Swinnerton-Dyer: certified ranks in Lean
ECCompute: Lean that certifies rank lower bounds for 480 elliptic curves, up to rank ≥ 31. Certify more, rerun it, read what 2026 claimed about BSD

| 1 | /- |
| 2 | Copyright (c) 2026 Bhavik Mehta. All rights reserved. |
| 3 | Released under the GNU General Public License version 3.0 as described in the file LICENSE. |
| 4 | Authors: Bhavik Mehta |
| 5 | -/ |
| 6 | module |
| 7 | |
| 8 | public import ECCompute.Soundness.F2Invert |
| 9 | public import ECCompute.Soundness.LambdaCompute |
| 10 | |
| 11 | import Mathlib.Data.Nat.Bitwise |
| 12 | import ECCompute.ForLean |
| 13 | |
| 14 | /-! |
| 15 | # Soundness of the descent-matrix check |
| 16 | |
| 17 | `checkB_true` proves the kernel-reducible `checkB` (`ECCompute.Kernel`) sound: when it passes, every |
| 18 | entry of the certificate matrix `B` equals the kernel-computed descent character |
| 19 | `lambdaBitK`, read into `ZMod 2`, at the matching point. |
| 20 | -/ |
| 21 | |
| 22 | namespace ECCompute |
| 23 | |
| 24 | variable {a₂ a₄ : ℤ} {xnp xnm xden b : ℕ} {ls : List (ℕ × ℕ × ℕ)} {B : List ℕ} |
| 25 | {pt : List (ℚ × ℚ)} |
| 26 | |
| 27 | @[simp, grind =] |
| 28 | theorem checkBRowWord_nil : checkBRowWord a₂ a₄ xnp xnm xden [] = 0 := rfl |
| 29 | |
| 30 | @[simp, grind =] |
| 31 | theorem checkBRowWord_cons {l : ℕ × ℕ × ℕ} : |
| 32 | checkBRowWord a₂ a₄ xnp xnm xden (l :: ls) = |
| 33 | lambdaBitK a₂ a₄ l.1 l.2.2 l.2.1 xnp xnm xden ||| |
| 34 | checkBRowWord a₂ a₄ xnp xnm xden ls <<< 1 := rfl |
| 35 | |
| 36 | @[simp, grind =] |
| 37 | theorem checkBGo_cons_cons {bs : List ℕ} {p : ℚ × ℚ} {ps : List (ℚ × ℚ)} : |
| 38 | checkBGo a₂ a₄ ls (b :: bs) (p :: ps) = |
| 39 | (checkBRow a₂ a₄ p.1.num.toNat (-p.1.num).toNat p.1.den b ls).and |
| 40 | (checkBGo a₂ a₄ ls bs ps) := rfl |
| 41 | |
| 42 | variable {i j : ℕ} |
| 43 | |
| 44 | /-- Bit `j` of the expected row word is set iff label `j`'s descent character bit is `1`. -/ |
| 45 | theorem testBit_checkBRowWord (hj : j < ls.length) : |
| 46 | (checkBRowWord a₂ a₄ xnp xnm xden ls).testBit j ↔ |
| 47 | lambdaBitK a₂ a₄ ls[j].1 ls[j].2.2 ls[j].2.1 xnp xnm xden = 1 := by |
| 48 | induction ls generalizing j with |
| 49 | | nil => simp at hj |
| 50 | | cons l ls ih => |
| 51 | cases j with |
| 52 | | zero => |
| 53 | rw [checkBRowWord_cons, Nat.testBit_or, Nat.testBit_shiftLeft, List.getElem_cons_zero] |
| 54 | grind [lambdaBitK_eq_zero_or_one] |
| 55 | | succ k => |
| 56 | rw [checkBRowWord_cons, Nat.testBit_or, Nat.testBit_shiftLeft, List.getElem_cons_succ, |
| 57 | Nat.add_sub_cancel] |
| 58 | obtain hb | hb := lambdaBitK_eq_zero_or_one (a₂ := a₂) (a₄ := a₄) (p := l.1) (qm := l.2.2) |
| 59 | (tval := l.2.1) (xp := xnp) (xm := xnm) (xden := xden) <;> |
| 60 | simp [hb, Nat.testBit_succ, ih (by simpa using hj)] |
| 61 | |
| 62 | /-- Row correctness: if `checkBRow` passes, bit `j` of the row bitmask is set iff the descent |
| 63 | character bit of label `j` is `1`. -/ |
| 64 | theorem checkBRow_true (hb : checkBRow a₂ a₄ xnp xnm xden b ls) (hj : j < ls.length) : |
| 65 | b.testBit j ↔ lambdaBitK a₂ a₄ ls[j].1 ls[j].2.2 ls[j].2.1 xnp xnm xden = 1 := by |
| 66 | grind [checkBRow, testBit_checkBRowWord] |
| 67 | |
| 68 | /-- Row extraction: if the aggregate check passes, row `i`'s bitmask passes `checkBRow`. -/ |
| 69 | theorem checkBGo_row (h : checkBGo a₂ a₄ ls B pt) (hi : i < B.length) (hip : i < pt.length) : |
| 70 | checkBRow a₂ a₄ pt[i].1.num.toNat (-pt[i].1.num).toNat pt[i].1.den B[i] ls := by |
| 71 | induction B generalizing pt i with grind [cases List] |
| 72 | |
| 73 | /-- If the aggregate check passes, every matrix entry equals the kernel-computed descent character, |
| 74 | read into `ZMod 2`. -/ |
| 75 | public theorem checkB_true {ρ : ℕ} {ls : List (ℕ × ℤ)} {q : List ℕ} |
| 76 | (hBlen : B.length = ρ) (hplen : pt.length = ρ) (hllen : ls.length = ρ) |
| 77 | (hqlen : q.length = ρ) |
| 78 | (h : checkB a₂ a₄ ls q B pt) (i j : Fin ρ) : |
| 79 | F2Invert.toMat B ρ i j = |
| 80 | (lambdaBitK a₂ a₄ ls[j].1 (qrMask ls[j].1) (ls[j].2 % ls[j].1).toNat |
| 81 | pt[i].1.num.toNat (-pt[i].1.num).toNat pt[i].1.den : ZMod 2) := by |
| 82 | rw [checkB, Bool.and_eq_true] at h |
| 83 | set ns := toLs ls q with hnsdef |
| 84 | have hns : ns.length = ρ := by rw [hnsdef, toLs, List.length_zipWith, hllen, hqlen, Nat.min_self] |
| 85 | have hgetN : ns[j] = (ls[j].1, (ls[j].2 % ls[j].1).toNat, q[j]) := by simp [hnsdef, toLs] |
| 86 | obtain ⟨hmask, hgo⟩ := h |
| 87 | -- the supplied mask for column `j` is `qrMask ls[j].1` |
| 88 | have hqok : qrMask ls[j].1 = q[j] := by |
| 89 | have : qrMask ns[j].1 = ns[j].2.2 := by grind [checkMaskList, List.getElem_mem] |
| 90 | rwa [hgetN] at this |
| 91 | -- read off the mask-based cell value at `(i, j)` |
| 92 | have hrow := checkBGo_row (i := i) hgo (by lia) (by lia) |
| 93 | have hcell : (B[i] : ℕ).testBit j ↔ _ := checkBRow_true hrow (by lia) |
| 94 | simp only [← Fin.getElem_fin] at hcell |
| 95 | simp only [hgetN] at hcell |
| 96 | rw [F2Invert.toMat_apply (by lia), hqok] |
| 97 | obtain hb | hb := lambdaBitK_eq_zero_or_one (a₂ := a₂) (a₄ := a₄) (p := ls[j].1) (qm := q[j]) |
| 98 | (tval := (ls[j].2 % ls[j].1).toNat) (xp := pt[i].1.num.toNat) (xm := (-pt[i].1.num).toNat) |
| 99 | (xden := pt[i].1.den) <;> simp [-Fin.getElem_fin, hcell, hb] |
| 100 | |
| 101 | end ECCompute |