Theorem: PythagoreanTriple.normalize
File: Mathlib/NumberTheory/PythagoreanTriples.lean

Proof steps:
state_before: x y z : ℤ
h : PythagoreanTriple x y z
⊢ PythagoreanTriple (x / ↑(x.gcd y)) (y / ↑(x.gcd y)) (z / ↑(x.gcd y))
state_after: case pos
x y z : ℤ
h : PythagoreanTriple x y z
h0 : x.gcd y = 0
⊢ PythagoreanTriple (x / ↑(x.gcd y)) (y / ↑(x.gcd y)) (z / ↑(x.gcd y))

case neg
x y z : ℤ
h : PythagoreanTriple x y z
h0 : ¬x.gcd y = 0
⊢ PythagoreanTriple (x / ↑(x.gcd y)) (y / ↑(x.gcd y)) (z / ↑(x.gcd y))
tactic: by_cases h0 : Int.gcd x y = 0
state_before: case neg
x y z : ℤ
h : PythagoreanTriple x y z
h0 : ¬x.gcd y = 0
⊢ PythagoreanTriple (x / ↑(x.gcd y)) (y / ↑(x.gcd y)) (z / ↑(x.gcd y))
state_after: case neg.intro
x y : ℤ
h0 : ¬x.gcd y = 0
z0 : ℤ
h : PythagoreanTriple x y (↑(x.gcd y) * z0)
⊢ PythagoreanTriple (x / ↑(x.gcd y)) (y / ↑(x.gcd y)) (↑(x.gcd y) * z0 / ↑(x.gcd y))
tactic: rcases h.gcd_dvd with ⟨z0, rfl⟩
state_before: case neg.intro
x y : ℤ
h0 : ¬x.gcd y = 0
z0 : ℤ
h : PythagoreanTriple x y (↑(x.gcd y) * z0)
⊢ PythagoreanTriple (x / ↑(x.gcd y)) (y / ↑(x.gcd y)) (↑(x.gcd y) * z0 / ↑(x.gcd y))
state_after: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple (x0 * ↑k) (y0 * ↑k) (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0)
⊢ PythagoreanTriple (x0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k))) (y0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k)))
    (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0 / ↑((x0 * ↑k).gcd (y0 * ↑k)))
tactic: obtain ⟨k, x0, y0, k0, h2, rfl, rfl⟩ :
    ∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k :=
    Int.exists_gcd_one' (Nat.pos_of_ne_zero h0)
state_before: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple (x0 * ↑k) (y0 * ↑k) (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0)
⊢ PythagoreanTriple (x0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k))) (y0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k)))
    (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0 / ↑((x0 * ↑k).gcd (y0 * ↑k)))
state_after: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple (x0 * ↑k) (y0 * ↑k) (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0)
hk : ↑k ≠ 0
⊢ PythagoreanTriple (x0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k))) (y0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k)))
    (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0 / ↑((x0 * ↑k).gcd (y0 * ↑k)))
tactic: have hk : (k : ℤ) ≠ 0 := by
    norm_cast
    rwa [pos_iff_ne_zero] at k0
state_before: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple (x0 * ↑k) (y0 * ↑k) (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0)
hk : ↑k ≠ 0
⊢ PythagoreanTriple (x0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k))) (y0 * ↑k / ↑((x0 * ↑k).gcd (y0 * ↑k)))
    (↑((x0 * ↑k).gcd (y0 * ↑k)) * z0 / ↑((x0 * ↑k).gcd (y0 * ↑k)))
state_after: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple (x0 * ↑k) (y0 * ↑k) (↑k * z0)
hk : ↑k ≠ 0
⊢ PythagoreanTriple (x0 * ↑k / ↑k) (y0 * ↑k / ↑k) (↑k * z0 / ↑k)
tactic: rw [Int.gcd_mul_right, h2, Int.natAbs_ofNat, one_mul] at h ⊢
state_before: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple (x0 * ↑k) (y0 * ↑k) (↑k * z0)
hk : ↑k ≠ 0
⊢ PythagoreanTriple (x0 * ↑k / ↑k) (y0 * ↑k / ↑k) (↑k * z0 / ↑k)
state_after: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple x0 y0 z0
hk : ↑k ≠ 0
⊢ PythagoreanTriple (x0 * ↑k / ↑k) (y0 * ↑k / ↑k) (↑k * z0 / ↑k)
tactic: rw [mul_comm x0, mul_comm y0, mul_iff k hk] at h
state_before: case neg.intro.intro.intro.intro.intro.intro.intro
z0 : ℤ
k : ℕ
x0 y0 : ℤ
k0 : 0 < k
h2 : x0.gcd y0 = 1
h0 : ¬(x0 * ↑k).gcd (y0 * ↑k) = 0
h : PythagoreanTriple x0 y0 z0
hk : ↑k ≠ 0
⊢ PythagoreanTriple (x0 * ↑k / ↑k) (y0 * ↑k / ↑k) (↑k * z0 / ↑k)
state_after: no goals
tactic: rwa [Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel_left _ hk]