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.Theory.Descent.Character |
| 9 | public import Mathlib.Algebra.Field.ZMod |
| 10 | |
| 11 | import Mathlib.Data.Int.GCD |
| 12 | import Mathlib.Data.Rat.Lemmas |
| 13 | import Mathlib.RingTheory.Int.Basic |
| 14 | import Mathlib.RingTheory.Coprime.Lemmas |
| 15 | import ECCompute.ForMathlib.RatDenom |
| 16 | import Mathlib.Data.Rat.Cast.Defs |
| 17 | import Mathlib.Tactic.Qify |
| 18 | |
| 19 | /-! |
| 20 | # Reducing a rational affine point mod `p` |
| 21 | |
| 22 | For the integral curve `E : y² = x³ + a₂x² + a₄x + a₆` over `ℚ` and a solution `(x, y)`: the |
| 23 | denominator is a perfect square (`den_isSquare`, giving `w` with `x.den = w²` and `y.den = w³`, so |
| 24 | a point is `(u/w², v/w³)` in lowest terms), and the coordinates cast to `ZMod p`. |
| 25 | |
| 26 | ## Main declarations |
| 27 | |
| 28 | * `ECCompute.den_isSquare`: from the affine equation, `∃ w, x.den = w² ∧ y.den = w³`. |
| 29 | * `ECCompute.xbar`: the reduced `x`-coordinate `(x : ZMod p)` as a plain field element. |
| 30 | * `ECCompute.ydenom_eq_zero_iff`: the `y`-denominator vanishes mod `p` iff the `x`-denominator does. |
| 31 | -/ |
| 32 | |
| 33 | open WeierstrassCurve |
| 34 | |
| 35 | namespace ECCompute |
| 36 | |
| 37 | variable {a₂ a₄ a₆ : ℤ} |
| 38 | |
| 39 | /-- For a solution `(x, y)` of the integral curve `y² = x³ + a₂x² + a₄x + a₆`, there is a |
| 40 | natural number `w` with `x.den = w²` and `y.den = w³`. -/ |
| 41 | public theorem den_isSquare {x y : ℚ} (h : (curveQ a₂ a₄ a₆).toAffine.Equation x y) : |
| 42 | ∃ w : ℕ, x.den = w ^ 2 ∧ y.den = w ^ 3 := by |
| 43 | set N : ℤ := x.num ^ 3 + x.den * (a₂ * x.num ^ 2 + a₄ * x.num * x.den + a₆ * x.den ^ 2) |
| 44 | have key : y.num ^ 2 * x.den ^ 3 = y.den ^ 2 * N := by |
| 45 | qify [N] |
| 46 | grind [x.mul_den_eq_num, y.mul_den_eq_num] |
| 47 | have h₁ : IsCoprime ↑x.den N := x.isCoprime_num_den.symm.pow_right.add_mul_left_right _ |
| 48 | have heq : (x.den : ℤ) ^ 3 = y.den ^ 2 := Int.dvd_antisymm (by positivity) (by positivity) |
| 49 | (h₁.pow_left.dvd_of_dvd_mul_left ⟨y.num ^ 2, by grind⟩) |
| 50 | (y.isCoprime_num_den.symm.pow.dvd_of_dvd_mul_left ⟨N, key⟩) |
| 51 | exact Nat.exists_eq_pow_of_exponent_coprime_of_pow_eq_pow (by grind) (mod_cast heq) |
| 52 | |
| 53 | /-- The reduced `x`-coordinate `(x : ZMod p)` of an affine point, as a plain field element. -/ |
| 54 | @[expose] |
| 55 | public noncomputable def xbar (p : ℕ) [Fact p.Prime] (x : ℚ) : ZMod p := (x : ZMod p) |
| 56 | |
| 57 | variable {p : ℕ} |
| 58 | |
| 59 | /-- The `y`-denominator vanishes mod `p` iff the `x`-denominator does (since |
| 60 | `x.den = w²`, `y.den = w³`). -/ |
| 61 | public theorem ydenom_eq_zero_iff (hp : p.Prime) {x y : ℚ} |
| 62 | (h : (curveQ a₂ a₄ a₆).toAffine.Equation x y) : |
| 63 | (y.den : ZMod p) = 0 ↔ (x.den : ZMod p) = 0 := by |
| 64 | obtain ⟨w, hxw, hyw⟩ := den_isSquare h |
| 65 | simp only [ZMod.natCast_eq_zero_iff] |
| 66 | grind [hp.prime.dvd_pow_iff_dvd] |
| 67 | |
| 68 | end ECCompute |