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.Model |
| 9 | public import Mathlib.AlgebraicGeometry.EllipticCurve.Projective.Basic |
| 10 | public import ECCompute.Theory.Descent.PointArith |
| 11 | public import ECCompute.ForMathlib.RatDenom |
| 12 | public import Mathlib.AlgebraicGeometry.EllipticCurve.Projective.Point |
| 13 | public import Mathlib.AlgebraicGeometry.EllipticCurve.Affine.Basic |
| 14 | public import Mathlib.Algebra.Field.ZMod |
| 15 | |
| 16 | /-! |
| 17 | # The reduction map on affine points |
| 18 | |
| 19 | For a point `P = (x, y)` on the integral curve `y² = x³ + a₂x² + a₄x + a₆` and a prime `p`, this |
| 20 | file builds the integer projective representative `intRep x y w = ![x.num·w, y.num, w³]` (where |
| 21 | `x.den = w²`, `y.den = w³`), applies `ℤ → ZMod p` to it to get the `ZMod p`-projective |
| 22 | representative `repr`, and takes its affine point to define the reduction map `redP`. |
| 23 | |
| 24 | ## Main declarations |
| 25 | |
| 26 | * `ECCompute.intRep`: the integer representative `![x.num · w, y.num, w³]`. |
| 27 | * `ECCompute.repr`: the `ZMod p`-projective representative of an affine point. |
| 28 | * `ECCompute.redP`: the reduction map, `toAffine` of `repr`. |
| 29 | * `ECCompute.redP_of_den_zero`: `redP (x, y) = 0` when `p ∣ x.den`. |
| 30 | * `ECCompute.redP_of_den_ne`: `redP (x, y) = (x̄, ȳ)` when `p ∤ x.den`. |
| 31 | -/ |
| 32 | |
| 33 | open WeierstrassCurve Projective |
| 34 | |
| 35 | namespace ECCompute |
| 36 | |
| 37 | variable {a₂ a₄ a₆ : ℤ} |
| 38 | |
| 39 | /-! ### The integer projective representative -/ |
| 40 | |
| 41 | /-- The integer projective representative `![x.num · w, y.num, w³]` of the affine point |
| 42 | `(x, y)`, where `w` is the square-root witness of the denominators (`x.den = w²`, `y.den = w³`). |
| 43 | Over `ℚ` this is `w³ • [x : y : 1]` (see `intRep_map_ℚ`). -/ |
| 44 | public def intRep (x y : ℚ) (w : ℕ) : Fin 3 → ℤ := ![x.num * w, y.num, w ^ 3] |
| 45 | |
| 46 | /-- The image of `curve` under `ℤ → ℚ`, in projective form, is the rational curve. -/ |
| 47 | theorem map_curve_toProjective : |
| 48 | (curve a₂ a₄ a₆).toProjective.map (Int.castRingHom ℚ) = (curveQ a₂ a₄ a₆).toProjective := |
| 49 | map_curveQ |
| 50 | |
| 51 | variable {x y : ℚ} {w : ℕ} |
| 52 | |
| 53 | /-- Over `ℚ`, the integer representative equals `w³ • [x : y : 1]`. -/ |
| 54 | public theorem intRep_map_ℚ (hxden : x.den = w ^ 2) (hyden : y.den = w ^ 3) : |
| 55 | Int.castRingHom ℚ ∘ intRep x y w = (w ^ 3 : ℚ) • ![x, y, 1] := by |
| 56 | simp [intRep, comp_fin3, ← Rat.mul_den_eq_num, hxden, hyden] |
| 57 | grind |
| 58 | |
| 59 | /-- The integer representative lies on the integral projective curve. -/ |
| 60 | theorem intRep_equation (h : (curveQ a₂ a₄ a₆).toAffine.Equation x y) |
| 61 | (hden : x.den = w ^ 2) (hden' : y.den = w ^ 3) : |
| 62 | (curve a₂ a₄ a₆).toProjective.Equation (intRep x y w) := by |
| 63 | have hw : w ≠ 0 := by grind [Rat.den_ne_zero] |
| 64 | rwa [← map_equation _ (Int.castRingHom ℚ).injective_int, intRep_map_ℚ hden hden', |
| 65 | equation_smul _ (isUnit_iff_ne_zero.2 (by positivity)), equation_some, |
| 66 | map_curve_toProjective] |
| 67 | |
| 68 | /-- The three coordinates of `intRep x y w`. -/ |
| 69 | @[simp] theorem intRep_zero : intRep x y w 0 = x.num * w := by simp [intRep] |
| 70 | |
| 71 | @[simp] theorem intRep_one : intRep x y w 1 = y.num := by simp [intRep] |
| 72 | |
| 73 | @[simp] theorem intRep_two : intRep x y w 2 = w ^ 3 := by simp [intRep] |
| 74 | |
| 75 | variable {p : ℕ} |
| 76 | |
| 77 | /-! ### Coordinates of the reduced representative -/ |
| 78 | |
| 79 | section |
| 80 | variable [Fact p.Prime] |
| 81 | |
| 82 | theorem intRep_coord_zero (hden : x.den = w ^ 2) (hwne : (w : ZMod p) ≠ 0) : |
| 83 | (Int.castRingHom (ZMod p) ∘ intRep x y w) 0 |
| 84 | / (Int.castRingHom (ZMod p) ∘ intRep x y w) 2 = x := by |
| 85 | simp [field, Rat.cast_def, hden] |
| 86 | |
| 87 | theorem intRep_coord_one (hden' : y.den = w ^ 3) : |
| 88 | (Int.castRingHom (ZMod p) ∘ intRep x y w) 1 |
| 89 | / (Int.castRingHom (ZMod p) ∘ intRep x y w) 2 = y := by |
| 90 | simp [field, Rat.cast_def, hden'] |
| 91 | |
| 92 | end |
| 93 | |
| 94 | /-- The reduced discriminant is nonzero (good reduction transported to `ZMod p`). -/ |
| 95 | theorem map_Δ_ne (hΔ : ((curve a₂ a₄ a₆).Δ : ZMod p) ≠ 0) : |
| 96 | (curveZMod a₂ a₄ a₆ p).Δ ≠ 0 := by |
| 97 | simpa [WeierstrassCurve.baseChange, map_Δ, eq_intCast] using hΔ |
| 98 | |
| 99 | /-! ### Nonsingularity of the reduced representative -/ |
| 100 | |
| 101 | /-- The reduced integer representative is a nonsingular projective point of the reduced curve. -/ |
| 102 | theorem red_nonsingular (hp : p.Prime) (hΔ : ((curve a₂ a₄ a₆).Δ : ZMod p) ≠ 0) |
| 103 | (h : (curveQ a₂ a₄ a₆).toAffine.Nonsingular x y) |
| 104 | (hden : x.den = w ^ 2) (hden' : y.den = w ^ 3) : |
| 105 | (curveZMod a₂ a₄ a₆ p).toProjective.Nonsingular (Int.castRingHom (ZMod p) ∘ intRep x y w) := by |
| 106 | have : Fact p.Prime := ⟨hp⟩ |
| 107 | have hEq : (curveZMod a₂ a₄ a₆ p).toProjective.Equation |
| 108 | (Int.castRingHom (ZMod p) ∘ intRep x y w) := |
| 109 | (intRep_equation h.1 hden hden').map (Int.castRingHom (ZMod p)) |
| 110 | by_cases hwz : (w : ZMod p) = 0 |
| 111 | · -- `z = 0`: the point reduces to the origin. |
| 112 | have hz0 : (Int.castRingHom (ZMod p) ∘ intRep x y w) 2 = 0 := by simp [hwz] |
| 113 | rw [nonsingular_of_Z_eq_zero hz0] |
| 114 | refine ⟨hEq, Or.inr ?_⟩ |
| 115 | have hYne : (Int.castRingHom (ZMod p) ∘ intRep x y w) 1 ≠ 0 := by |
| 116 | simp only [Function.comp_apply, intRep_one, eq_intCast, Ne, ZMod.intCast_zmod_eq_zero_iff_dvd] |
| 117 | intro hpy |
| 118 | have hpw3 : (p : ℤ) ∣ (y.den : ℤ) := by |
| 119 | rwa [Int.natCast_dvd_natCast, hden', hp.prime.dvd_pow_iff_dvd three_ne_zero, |
| 120 | ← ZMod.natCast_eq_zero_iff] |
| 121 | grind [Int.isUnit_iff, y.isCoprime_num_den.isUnit_of_dvd' hpy hpw3, hp.two_le] |
| 122 | rw [X_eq_zero_of_Z_eq_zero hEq hz0] |
| 123 | simpa using pow_ne_zero 2 hYne |
| 124 | · -- `z ≠ 0`: good reduction makes it nonsingular. |
| 125 | rw [nonsingular_of_Z_ne_zero (by simp [hwz])] |
| 126 | exact (Affine.equation_iff_nonsingular_of_Δ_ne_zero |
| 127 | (map_Δ_ne hΔ)).mp ((equation_of_Z_ne_zero (by simp [hwz])).mp hEq) |
| 128 | |
| 129 | section |
| 130 | variable [Fact p.Prime] |
| 131 | |
| 132 | /-! ### The projective representative -/ |
| 133 | |
| 134 | /-- The fixed `ZMod p`-projective representative of an affine point: `![0, 1, 0]` for the origin, |
| 135 | and `ℤ → ZMod p` applied to the integer representative `intRep` otherwise. -/ |
| 136 | public noncomputable def repr (p : ℕ) [Fact p.Prime] : |
| 137 | (curveQ a₂ a₄ a₆).toAffine.Point → Fin 3 → ZMod p |
| 138 | | .zero => ![0, 1, 0] |
| 139 | | .some x y h => Int.castRingHom (ZMod p) ∘ intRep x y (den_isSquare h.1).choose |
| 140 | |
| 141 | /-- `repr` of the origin is the fixed representative `![0, 1, 0]`. -/ |
| 142 | public theorem repr_zero : repr p (.zero : (curveQ a₂ a₄ a₆).toAffine.Point) = ![0, 1, 0] := by |
| 143 | simp [repr] |
| 144 | |
| 145 | /-- `repr` of a `some` point, through any witness `w` with `x.den = w²`, `y.den = w³`. -/ |
| 146 | public theorem repr_some (h : (curveQ a₂ a₄ a₆).toAffine.Nonsingular x y) |
| 147 | (hden : x.den = w ^ 2) (hden' : y.den = w ^ 3) : |
| 148 | repr p (.some x y h) = Int.castRingHom (ZMod p) ∘ intRep x y w := by |
| 149 | obtain rfl : w = (den_isSquare h.1).choose := |
| 150 | Nat.pow_left_injective two_ne_zero (hden.symm.trans (den_isSquare h.1).choose_spec.1) |
| 151 | rfl |
| 152 | |
| 153 | /-- `repr P` is a nonsingular representative on the reduced curve (needs good reduction `hΔ`). -/ |
| 154 | public theorem repr_nonsingular (hΔ : ((curve a₂ a₄ a₆).Δ : ZMod p) ≠ 0) |
| 155 | (P : (curveQ a₂ a₄ a₆).toAffine.Point) : |
| 156 | (curveZMod a₂ a₄ a₆ p).toProjective.Nonsingular (repr p P) := by |
| 157 | cases P with |
| 158 | | zero => exact nonsingular_zero |
| 159 | | some x y h => |
| 160 | obtain ⟨w, hden, hden'⟩ := den_isSquare h.1 |
| 161 | rw [repr_some h hden hden'] |
| 162 | exact red_nonsingular Fact.out hΔ h hden hden' |
| 163 | |
| 164 | /-! ### The reduction map -/ |
| 165 | |
| 166 | /-- The reduction map on affine points: the affine point of the reduced projective |
| 167 | representative `repr`. -/ |
| 168 | public noncomputable def redP (p : ℕ) [Fact p.Prime] |
| 169 | (P : (curveQ a₂ a₄ a₆).toAffine.Point) : |
| 170 | (curveZMod a₂ a₄ a₆ p).toAffine.Point := |
| 171 | Point.toAffine (curveZMod a₂ a₄ a₆ p).toProjective (repr p P) |
| 172 | |
| 173 | /-- `redP` is `toAffine` of the fixed representative. -/ |
| 174 | public theorem redP_eq_toAffine (P : (curveQ a₂ a₄ a₆).toAffine.Point) : |
| 175 | redP p P = Point.toAffine (curveZMod a₂ a₄ a₆ p).toProjective (repr p P) := by simp only [redP] |
| 176 | |
| 177 | @[simp] |
| 178 | public theorem redP_zero : redP p (0 : (curveQ a₂ a₄ a₆).toAffine.Point) = 0 := by |
| 179 | rw [redP_eq_toAffine]; exact Point.toAffine_zero |
| 180 | |
| 181 | /-- When `p ∣ x.den` the representative has vanishing `z`-coordinate, so the point reduces to the |
| 182 | origin. -/ |
| 183 | public theorem redP_of_den_zero (h : (curveQ a₂ a₄ a₆).toAffine.Nonsingular x y) |
| 184 | (hd : (x.den : ZMod p) = 0) : |
| 185 | redP p (.some x y h) = 0 := by |
| 186 | obtain ⟨w, hden, hden'⟩ := den_isSquare h.1 |
| 187 | rw [redP_eq_toAffine, repr_some h hden hden'] |
| 188 | exact Point.toAffine_of_Z_eq_zero (by simpa [hden] using hd) |
| 189 | |
| 190 | /-- The reduced affine coordinates lie on the reduced curve and are nonsingular. -/ |
| 191 | public theorem red_nonsingular_affine (hΔ : ((curve a₂ a₄ a₆).Δ : ZMod p) ≠ 0) |
| 192 | (h : (curveQ a₂ a₄ a₆).toAffine.Nonsingular x y) (hd : (x.den : ZMod p) ≠ 0) : |
| 193 | (curveZMod a₂ a₄ a₆ p).toAffine.Nonsingular x y := by |
| 194 | obtain ⟨w, hden, hden'⟩ := den_isSquare h.1 |
| 195 | have hwne : (w : ZMod p) ≠ 0 := by simpa [hden] using hd |
| 196 | have hns := red_nonsingular Fact.out hΔ h hden hden' |
| 197 | rwa [nonsingular_of_Z_ne_zero (by simp [hwne]), intRep_coord_zero hden hwne, |
| 198 | intRep_coord_one hden'] at hns |
| 199 | |
| 200 | /-- When `p ∤ x.den` the point reduces to the affine point with the reduced coordinates |
| 201 | `(x : ZMod p, y : ZMod p)`. -/ |
| 202 | public theorem redP_of_den_ne (hΔ : ((curve a₂ a₄ a₆).Δ : ZMod p) ≠ 0) |
| 203 | (h : (curveQ a₂ a₄ a₆).toAffine.Nonsingular x y) (hd : (x.den : ZMod p) ≠ 0) : |
| 204 | redP p (.some x y h) |
| 205 | = .some x y (red_nonsingular_affine hΔ h hd) := by |
| 206 | obtain ⟨w, hden, hden'⟩ := den_isSquare h.1 |
| 207 | have hwne : (w : ZMod p) ≠ 0 := by simpa [hden] using hd |
| 208 | have hns := red_nonsingular Fact.out hΔ h hden hden' |
| 209 | rw [redP_eq_toAffine, repr_some h hden hden', Point.toAffine_of_Z_ne_zero hns (by simp [hwne])] |
| 210 | simp only [intRep_coord_zero hden hwne, intRep_coord_one hden'] |
| 211 | |
| 212 | end |
| 213 | |
| 214 | end ECCompute |