Skip to content

Commit 5367f68

Browse files
committed
refactor(NumberTheory): golf Mathlib/NumberTheory/PythagoreanTriples (#38454)
- simplifies the `Int.gcd x y = 0` branches in `gcd_dvd`, `normalize`, and `classified` using `Int.gcd_eq_zero_iff` - shortens the zero case in `normalize` to a direct `simpa` from `PythagoreanTriple.zero` Extracted from #38144 [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/from-referrer/)
1 parent c58be83 commit 5367f68

1 file changed

Lines changed: 5 additions & 21 deletions

File tree

Mathlib/NumberTheory/PythagoreanTriples.lean

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,11 @@ theorem even_odd_of_coprime (hc : Int.gcd x y = 1) :
143143

144144
theorem gcd_dvd : (Int.gcd x y : ℤ) ∣ z := by
145145
by_cases h0 : Int.gcd x y = 0
146-
· have hx : x = 0 := by
147-
apply Int.natAbs_eq_zero.mp
148-
apply Nat.eq_zero_of_gcd_eq_zero_left h0
149-
have hy : y = 0 := by
150-
apply Int.natAbs_eq_zero.mp
151-
apply Nat.eq_zero_of_gcd_eq_zero_right h0
146+
· obtain ⟨hx, hy⟩ := Int.gcd_eq_zero_iff.mp h0
152147
have hz : z = 0 := by
153148
simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero,
154149
or_self_iff] using h
155-
simp only [hz, dvd_zero]
150+
simp [h0, hz]
156151
obtain ⟨k, x0, y0, _, h2, rfl, rfl⟩ :
157152
∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k :=
158153
Int.exists_gcd_one' (Nat.pos_of_ne_zero h0)
@@ -163,17 +158,11 @@ theorem gcd_dvd : (Int.gcd x y : ℤ) ∣ z := by
163158

164159
theorem normalize : PythagoreanTriple (x / Int.gcd x y) (y / Int.gcd x y) (z / Int.gcd x y) := by
165160
by_cases h0 : Int.gcd x y = 0
166-
· have hx : x = 0 := by
167-
apply Int.natAbs_eq_zero.mp
168-
apply Nat.eq_zero_of_gcd_eq_zero_left h0
169-
have hy : y = 0 := by
170-
apply Int.natAbs_eq_zero.mp
171-
apply Nat.eq_zero_of_gcd_eq_zero_right h0
161+
· obtain ⟨hx, hy⟩ := Int.gcd_eq_zero_iff.mp h0
172162
have hz : z = 0 := by
173163
simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero,
174164
or_self_iff] using h
175-
simp only [hx, hy, hz]
176-
exact zero
165+
simpa [h0, hx, hy, hz] using zero
177166
rcases h.gcd_dvd with ⟨z0, rfl⟩
178167
obtain ⟨k, x0, y0, k0, h2, rfl, rfl⟩ :
179168
∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k :=
@@ -528,12 +517,7 @@ theorem isPrimitiveClassified_of_coprime (hc : Int.gcd x y = 1) : h.IsPrimitiveC
528517

529518
theorem classified : h.IsClassified := by
530519
by_cases h0 : Int.gcd x y = 0
531-
· have hx : x = 0 := by
532-
apply Int.natAbs_eq_zero.mp
533-
apply Nat.eq_zero_of_gcd_eq_zero_left h0
534-
have hy : y = 0 := by
535-
apply Int.natAbs_eq_zero.mp
536-
apply Nat.eq_zero_of_gcd_eq_zero_right h0
520+
· obtain ⟨hx, hy⟩ := Int.gcd_eq_zero_iff.mp h0
537521
use 0, 1, 0
538522
simp [hx, hy]
539523
apply h.isClassified_of_normalize_isPrimitiveClassified

0 commit comments

Comments
 (0)