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 Mathlib.Data.Rat.Defs |
| 9 | public import ECCompute.Soundness.F2Invert |
| 10 | public import ECCompute.Theory.Descent.Character |
| 11 | |
| 12 | /-! |
| 13 | # The rank-bound certificate data type |
| 14 | |
| 15 | `Certificate` bundles the data establishing a lower bound on the Mordell-Weil rank |
| 16 | of an elliptic curve over `ℚ`, `rank E(ℚ) ≥ ρ - t`. Its curve is the short integral Weierstrass |
| 17 | model `y² = x³ + a₂x² + a₄x + a₆`; `ECCompute.hasRankGE_of_certificate` transports the bound to a |
| 18 | general integral model. |
| 19 | |
| 20 | ## Main definitions |
| 21 | |
| 22 | * `ECCompute.Certificate`: the certificate record; see its field docstrings for each entry. |
| 23 | * `ECCompute.Certificate.Valid`: the checks a certificate must pass on its own data. |
| 24 | |
| 25 | ## Implementation notes |
| 26 | |
| 27 | The five lists `points`, `labels`, `B`, `M`, and `qrMasks` all have length `ρ`; the |
| 28 | `Certificate.Valid` checks enforce this. `B` / `M` follow the `List Nat` bitmask layout of |
| 29 | `ECCompute.F2Invert` (`B` and `M` both by rows), so `F2Invert.checkInv B M` applies verbatim. |
| 30 | -/ |
| 31 | |
| 32 | namespace ECCompute |
| 33 | |
| 34 | /-- A certificate for the Mordell-Weil rank bound `rank E(ℚ) ≥ ρ - t`, over the short integral |
| 35 | Weierstrass model `y² = x³ + a₂x² + a₄x + a₆`. -/ |
| 36 | public structure Certificate where |
| 37 | /-- The `x²` coefficient of the short model. -/ |
| 38 | a₂ : ℤ |
| 39 | /-- The `x` coefficient of the short model. -/ |
| 40 | a₄ : ℤ |
| 41 | /-- The constant coefficient of the short model. -/ |
| 42 | a₆ : ℤ |
| 43 | /-- A positive common multiple of the label primes; each divides it (checked in `checkLabels`). -/ |
| 44 | P : ℕ |
| 45 | /-- The residue `(a₂ mod P)`, as a `Nat` literal; verified in `checkLabels`. -/ |
| 46 | a₂r : ℕ |
| 47 | /-- The residue `(a₄ mod P)`, as a `Nat` literal; verified in `checkLabels`. -/ |
| 48 | a₄r : ℕ |
| 49 | /-- The residue `(a₆ mod P)`, as a `Nat` literal; verified in `checkLabels`. -/ |
| 50 | a₆r : ℕ |
| 51 | /-- The discriminant `discrInt a₂ a₄ a₆`, as an `Int` literal; verified in `checkLabels`. -/ |
| 52 | Δ : ℤ |
| 53 | /-- The claimed number of independent points, `ρ`; the target bound is `rank ≥ ρ - t`. -/ |
| 54 | ρ : ℕ |
| 55 | /-- The `ρ` rational points, as affine coordinates `(x, y)`. -/ |
| 56 | points : List (ℚ × ℚ) |
| 57 | /-- The `ρ` descent-column labels `(p, θ)`: a prime `p` and a root `θ` mod `p`. -/ |
| 58 | labels : List (ℕ × ℤ) |
| 59 | /-- The `ρ × ρ` character matrix `B` over `𝔽₂`, as `List Nat` row bitmasks (see `F2Invert`). -/ |
| 60 | B : List Nat |
| 61 | /-- The claimed inverse `M` of `B` over `𝔽₂`, as `List Nat` row bitmasks (see `F2Invert`). -/ |
| 62 | M : List Nat |
| 63 | /-- The `ρ` quadratic-residue masks, one per label: `qrMasks[j]` is the bitmask whose bit `a` is |
| 64 | set iff `a` is a nonzero square mod `labels[j].1`. `Certificate.Valid` checks each against |
| 65 | `qrMask`. -/ |
| 66 | qrMasks : List Nat |
| 67 | /-- The rational `2`-torsion dimension `t = dim_{𝔽₂} E(ℚ)[2]`; the target bound is |
| 68 | `rank ≥ ρ - t`. -/ |
| 69 | t : ℕ |
| 70 | /-- A prime witnessing the `2`-torsion claim (for `t = 0`, one at which the `2`-division cubic has |
| 71 | no root). -/ |
| 72 | torsionPrime : ℕ |
| 73 | |
| 74 | /-- The checks a certificate must pass on its own data: the five lists have length |
| 75 | `ρ`, the point, prime, label, and character-matrix checks pass, the claimed `𝔽₂` inverse is |
| 76 | correct, and the `2`-torsion order is at most `2 ^ t`. `hasRankGE_of_certificate` turns this, |
| 77 | together with a curve match, into a rank lower bound. -/ |
| 78 | public structure Certificate.Valid (c : Certificate) : Prop where |
| 79 | /-- The point list has `ρ` entries. -/ |
| 80 | lenP : c.points.length = c.ρ |
| 81 | /-- The label list has `ρ` entries. -/ |
| 82 | lenL : c.labels.length = c.ρ |
| 83 | /-- The row bitmask list `B` has `ρ` entries. -/ |
| 84 | lenB : c.B.length = c.ρ |
| 85 | /-- The row bitmask list `M` has `ρ` entries. -/ |
| 86 | lenM : c.M.length = c.ρ |
| 87 | /-- The quadratic-residue mask list has `ρ` entries. -/ |
| 88 | lenQ : c.qrMasks.length = c.ρ |
| 89 | /-- Each listed point lies on the short model. -/ |
| 90 | pts : checkPoints c.a₂ c.a₄ c.a₆ c.points |
| 91 | /-- Each label carries a prime. -/ |
| 92 | primes : checkPrimes c.labels |
| 93 | /-- `P`, the coefficient residues, and the discriminant match the curve, every label prime divides |
| 94 | `P`, and each label's `θ` is a root of the `2`-division cubic mod its prime. -/ |
| 95 | labels : checkLabels c.a₂ c.a₄ c.a₆ c.P c.a₂r c.a₄r c.a₆r c.Δ c.labels |
| 96 | /-- `B` is the descent-character matrix the labels induce on the points. -/ |
| 97 | matrix : checkB c.a₂ c.a₄ c.labels c.qrMasks c.B c.points |
| 98 | /-- `M` inverts `B` over `𝔽₂`. -/ |
| 99 | inv : F2Invert.checkInv c.B c.M |
| 100 | /-- The rational `2`-torsion has order at most `2 ^ t`. -/ |
| 101 | tors : (curveQ c.a₂ c.a₄ c.a₆).twoTorsionPoints.ncard ≤ 2 ^ c.t |
| 102 | |
| 103 | end ECCompute |