Lean / Reader
Lean reader

BealSieve.lean

95 lines8 declarationsno sorryimports Mathlib
  1. import Mathlib
  2. /-!
  3. # Round 3: the residue filter of the search, the Mordell reduction, and the square conditions of D8
  4. 1. **Soundness of the residue filter** (`filter_sound`, `pow_mod_mem_image`). The search program `o7_wheel.c`
  5. discards a pair `(P, Q)` when `sp·P^ep + sq·Q^eq` is not an `es`-th power modulo some `m`, where the table of
  6. `es`-th powers mod `m` is built as `{t^es mod m : 0 ≤ t < m}`. If `S^es = sp·P^ep + sq·Q^eq` for integers,
  7. the residue is always in that table, for every `m`. So the filter never discards a solution.
  8. 2. **Mordell reduction** (`mordell_i`, `mordell_ii`, `mordell_iii`). In each order of the signature `(3, 4, p)`,
  9. with `p = 6m + r`, a solution gives a rational point on the Mordell curve `Y² = X³ ± b^r`, where `b` is the base
  10. of the `p`-th power: the three orders give `+C^r`, `+B^r` and `−B^r`.
  11. 3. **Square conditions** (`sq_mod_four`, `sq_mod_nine`): the facts used in D8 to discard rows of the 2-adic and
  12. 3-adic tables of Freitas–Naskręcki–Stoll when `x` in `x² + y³ = z¹³` is a perfect square.
  13. -/
  14. namespace BealSieve
  15. /-- The table built by the program is complete: `s^e mod m` is `t^e mod m` for some `t < m`. -/
  16. theorem pow_mod_mem_image (s e m : ℕ) (hm : 0 < m) :
  17. s ^ e % m ∈ (Finset.range m).image (fun t => t ^ e % m) :=
  18. Finset.mem_image.mpr ⟨s % m, Finset.mem_range.mpr (Nat.mod_lt _ hm), (Nat.pow_mod s e m).symm⟩
  19. /-- Soundness of the filter, for any signs `sp, sq` and any modulus `m`: if `S^es = sp·P^ep + sq·Q^eq` over `ℤ`,
  20. then `sp·P^ep + sq·Q^eq` is an `es`-th power in `ZMod m`. -/
  21. theorem filter_sound {S P Q sp sq : ℤ} {es ep eq : ℕ} (h : S ^ es = sp * P ^ ep + sq * Q ^ eq) (m : ℕ) :
  22. ∃ t : ZMod m, t ^ es = (sp : ZMod m) * (P : ZMod m) ^ ep + (sq : ZMod m) * (Q : ZMod m) ^ eq :=
  23. ⟨(S : ZMod m), by
  24. have := congrArg (fun z : ℤ => (z : ZMod m)) h
  25. push_cast at this
  26. exact this⟩
  27. /-- Order `A³ + B⁴ = C^p`, `p = 6m + r`: the point `(−A/C^{2m}, B²/C^{3m})` lies on `Y² = X³ + C^r`. -/
  28. theorem mordell_i {A B C : ℤ} {m r : ℕ} (hC : C ≠ 0) (h : A ^ 3 + B ^ 4 = C ^ (6 * m + r)) :
  29. ((B : ℚ) ^ 2 / (C : ℚ) ^ (3 * m)) ^ 2 = (-(A : ℚ) / (C : ℚ) ^ (2 * m)) ^ 3 + (C : ℚ) ^ r := by
  30. have hC' : (C : ℚ) ≠ 0 := by exact_mod_cast hC
  31. have h' : (A : ℚ) ^ 3 + (B : ℚ) ^ 4 = (C : ℚ) ^ (6 * m + r) := by exact_mod_cast h
  32. have e : (C : ℚ) ^ (6 * m + r) = ((C : ℚ) ^ m) ^ 6 * (C : ℚ) ^ r := by ring
  33. rw [e] at h'
  34. have hm : ((C : ℚ) ^ m) ≠ 0 := pow_ne_zero _ hC'
  35. rw [show (C : ℚ) ^ (3 * m) = ((C : ℚ) ^ m) ^ 3 by ring, show (C : ℚ) ^ (2 * m) = ((C : ℚ) ^ m) ^ 2 by ring]
  36. field_simp
  37. linear_combination h'
  38. /-- Order `A³ + B^p = C⁴`, `p = 6m + r`: the point `(A/B^{2m}, C²/B^{3m})` lies on `Y² = X³ + B^r`. -/
  39. theorem mordell_ii {A B C : ℤ} {m r : ℕ} (hB : B ≠ 0) (h : A ^ 3 + B ^ (6 * m + r) = C ^ 4) :
  40. ((C : ℚ) ^ 2 / (B : ℚ) ^ (3 * m)) ^ 2 = ((A : ℚ) / (B : ℚ) ^ (2 * m)) ^ 3 + (B : ℚ) ^ r := by
  41. have hB' : (B : ℚ) ≠ 0 := by exact_mod_cast hB
  42. have h' : (A : ℚ) ^ 3 + (B : ℚ) ^ (6 * m + r) = (C : ℚ) ^ 4 := by exact_mod_cast h
  43. have e : (B : ℚ) ^ (6 * m + r) = ((B : ℚ) ^ m) ^ 6 * (B : ℚ) ^ r := by ring
  44. rw [e] at h'
  45. have hm : ((B : ℚ) ^ m) ≠ 0 := pow_ne_zero _ hB'
  46. rw [show (B : ℚ) ^ (3 * m) = ((B : ℚ) ^ m) ^ 3 by ring, show (B : ℚ) ^ (2 * m) = ((B : ℚ) ^ m) ^ 2 by ring]
  47. field_simp
  48. linear_combination -h'
  49. /-- Order `A⁴ + B^p = C³`, `p = 6m + r`: the point `(C/B^{2m}, A²/B^{3m})` lies on `Y² = X³ − B^r`. -/
  50. theorem mordell_iii {A B C : ℤ} {m r : ℕ} (hB : B ≠ 0) (h : A ^ 4 + B ^ (6 * m + r) = C ^ 3) :
  51. ((A : ℚ) ^ 2 / (B : ℚ) ^ (3 * m)) ^ 2 = ((C : ℚ) / (B : ℚ) ^ (2 * m)) ^ 3 - (B : ℚ) ^ r := by
  52. have hB' : (B : ℚ) ≠ 0 := by exact_mod_cast hB
  53. have h' : (A : ℚ) ^ 4 + (B : ℚ) ^ (6 * m + r) = (C : ℚ) ^ 3 := by exact_mod_cast h
  54. have e : (B : ℚ) ^ (6 * m + r) = ((B : ℚ) ^ m) ^ 6 * (B : ℚ) ^ r := by ring
  55. rw [e] at h'
  56. have hm : ((B : ℚ) ^ m) ≠ 0 := pow_ne_zero _ hB'
  57. rw [show (B : ℚ) ^ (3 * m) = ((B : ℚ) ^ m) ^ 3 by ring, show (B : ℚ) ^ (2 * m) = ((B : ℚ) ^ m) ^ 2 by ring]
  58. field_simp
  59. linear_combination h'
  60. /-- Squares are `0` or `1` mod 4: a perfect square `x` is never `≡ 2` or `≡ 3 (mod 4)`. -/
  61. theorem sq_mod_four (u : ℤ) : u ^ 2 % 4 = 0 ∨ u ^ 2 % 4 = 1 := by
  62. have h := Int.emod_emod_of_dvd u (by norm_num : (4 : ℤ) ∣ 4)
  63. rcases (by omega : u % 4 = 0 ∨ u % 4 = 1 ∨ u % 4 = 2 ∨ u % 4 = 3) with h0 | h0 | h0 | h0 <;>
  64. simp [pow_two, Int.mul_emod, h0]
  65. /-- Squares mod 9 are `0, 1, 4, 7`: a perfect square is never `≡ ±2, ±3 (mod 9)`; in particular `v₃(x) = 1`
  66. is impossible. -/
  67. theorem sq_mod_nine (u : ℤ) : u ^ 2 % 9 = 0 ∨ u ^ 2 % 9 = 1 ∨ u ^ 2 % 9 = 4 ∨ u ^ 2 % 9 = 7 := by
  68. rcases (by omega : u % 9 = 0 ∨ u % 9 = 1 ∨ u % 9 = 2 ∨ u % 9 = 3 ∨ u % 9 = 4 ∨ u % 9 = 5 ∨ u % 9 = 6 ∨
  69. u % 9 = 7 ∨ u % 9 = 8) with h0 | h0 | h0 | h0 | h0 | h0 | h0 | h0 | h0 <;>
  70. simp [pow_two, Int.mul_emod, h0]
  71. /-- D8 observation: if `a = u²`, the quadratic twist by `−2` of the Frey curve `y² = x³ + 3bx − 2a`, written as
  72. `Y² = X³ + 12bX + 16a`, has the rational point `(0, 4u)`. -/
  73. theorem twist_point (u b : ℤ) : (4 * u) ^ 2 = (0 : ℤ) ^ 3 + 12 * b * 0 + 16 * u ^ 2 := by ring
  74. end BealSieve
  75. #print axioms BealSieve.filter_sound
  76. #print axioms BealSieve.pow_mod_mem_image
  77. #print axioms BealSieve.mordell_i
  78. #print axioms BealSieve.mordell_ii
  79. #print axioms BealSieve.mordell_iii
  80. #print axioms BealSieve.sq_mod_four
  81. #print axioms BealSieve.sq_mod_nine