[GOAL]
s t : ℤ
r' : ℕ
s' t' : ℤ
⊢ xgcdAux 0 s t r' s' t' = (r', s', t')
[PROOFSTEP]
simp [xgcdAux]
[GOAL]
r : ℕ
s t : ℤ
r' : ℕ
s' t' : ℤ
h : 0 < r
⊢ xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - ↑r' / ↑r * s) (t' - ↑r' / ↑r * t) r s t
[PROOFSTEP]
obtain ⟨r, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h.ne'
[GOAL]
case intro
s t : ℤ
r' : ℕ
s' t' : ℤ
r : ℕ
h : 0 < succ r
⊢ xgcdAux (succ r) s t r' s' t' =
    xgcdAux (r' % succ r) (s' - ↑r' / ↑(succ r) * s) (t' - ↑r' / ↑(succ r) * t) (succ r) s t
[PROOFSTEP]
rfl
[GOAL]
s : ℕ
⊢ gcdA 0 s = 0
[PROOFSTEP]
unfold gcdA
[GOAL]
s : ℕ
⊢ (xgcd 0 s).fst = 0
[PROOFSTEP]
rw [xgcd, xgcd_zero_left]
[GOAL]
s : ℕ
⊢ gcdB 0 s = 1
[PROOFSTEP]
unfold gcdB
[GOAL]
s : ℕ
⊢ (xgcd 0 s).snd = 1
[PROOFSTEP]
rw [xgcd, xgcd_zero_left]
[GOAL]
s : ℕ
h : s ≠ 0
⊢ gcdA s 0 = 1
[PROOFSTEP]
unfold gcdA xgcd
[GOAL]
s : ℕ
h : s ≠ 0
⊢ (xgcdAux s 1 0 0 0 1).snd.fst = 1
[PROOFSTEP]
obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
[GOAL]
case intro
s : ℕ
h : succ s ≠ 0
⊢ (xgcdAux (succ s) 1 0 0 0 1).snd.fst = 1
[PROOFSTEP]
rw [xgcdAux_succ]
[GOAL]
case intro
s : ℕ
h : succ s ≠ 0
⊢ (xgcdAux (0 % succ s) (0 - ↑0 / ↑(succ s) * 1) (1 - ↑0 / ↑(succ s) * 0) (succ s) 1 0).snd.fst = 1
[PROOFSTEP]
rfl
[GOAL]
s : ℕ
h : s ≠ 0
⊢ gcdB s 0 = 0
[PROOFSTEP]
unfold gcdB xgcd
[GOAL]
s : ℕ
h : s ≠ 0
⊢ (xgcdAux s 1 0 0 0 1).snd.snd = 0
[PROOFSTEP]
obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
[GOAL]
case intro
s : ℕ
h : succ s ≠ 0
⊢ (xgcdAux (succ s) 1 0 0 0 1).snd.snd = 0
[PROOFSTEP]
rw [xgcdAux_succ]
[GOAL]
case intro
s : ℕ
h : succ s ≠ 0
⊢ (xgcdAux (0 % succ s) (0 - ↑0 / ↑(succ s) * 1) (1 - ↑0 / ↑(succ s) * 0) (succ s) 1 0).snd.snd = 0
[PROOFSTEP]
rfl
[GOAL]
x y : ℕ
⊢ ∀ (n : ℕ) (s t s' t' : ℤ), (xgcdAux 0 s t n s' t').fst = gcd 0 n
[PROOFSTEP]
simp
[GOAL]
x✝ y✝ x y : ℕ
h : 0 < x
IH : ∀ (s t s' t' : ℤ), (xgcdAux (y % x) s t x s' t').fst = gcd (y % x) x
s t s' t' : ℤ
⊢ (xgcdAux x s t y s' t').fst = gcd x y
[PROOFSTEP]
simp [xgcdAux_rec, h, IH]
[GOAL]
x✝ y✝ x y : ℕ
h : 0 < x
IH : ∀ (s t s' t' : ℤ), (xgcdAux (y % x) s t x s' t').fst = gcd (y % x) x
s t s' t' : ℤ
⊢ gcd (y % x) x = gcd x y
[PROOFSTEP]
rw [← gcd_rec]
[GOAL]
x y : ℕ
⊢ xgcdAux x 1 0 y 0 1 = (gcd x y, xgcd x y)
[PROOFSTEP]
rw [xgcd, ← xgcdAux_fst x y 1 0 0 1]
[GOAL]
x y : ℕ
⊢ xgcd x y = (gcdA x y, gcdB x y)
[PROOFSTEP]
unfold gcdA gcdB
[GOAL]
x y : ℕ
⊢ xgcd x y = ((xgcd x y).fst, (xgcd x y).snd)
[PROOFSTEP]
cases xgcd x y
[GOAL]
case mk
x y : ℕ
fst✝ snd✝ : ℤ
⊢ (fst✝, snd✝) = ((fst✝, snd✝).fst, (fst✝, snd✝).snd)
[PROOFSTEP]
rfl
[GOAL]
x y r r' : ℕ
⊢ ∀ {s t s' t' : ℤ}, Nat.P x y (r, s, t) → Nat.P x y (r', s', t') → Nat.P x y (xgcdAux r s t r' s' t')
[PROOFSTEP]
induction r, r' using gcd.induction with
| H0 => simp
| H1 a b h IH =>
  intro s t s' t' p p'
  rw [xgcdAux_rec h]; refine' IH _ p; dsimp [P] at *
  rw [Int.emod_def]; generalize (b / a : ℤ) = k
  rw [p, p', mul_sub, sub_add_eq_add_sub, mul_sub, add_mul, mul_comm k t, mul_comm k s, ← mul_assoc, ← mul_assoc,
    add_comm (x * s * k), ← add_sub_assoc, sub_sub]
[GOAL]
x y r r' : ℕ
⊢ ∀ {s t s' t' : ℤ}, Nat.P x y (r, s, t) → Nat.P x y (r', s', t') → Nat.P x y (xgcdAux r s t r' s' t')
[PROOFSTEP]
induction r, r' using gcd.induction with
| H0 => simp
| H1 a b h IH =>
  intro s t s' t' p p'
  rw [xgcdAux_rec h]; refine' IH _ p; dsimp [P] at *
  rw [Int.emod_def]; generalize (b / a : ℤ) = k
  rw [p, p', mul_sub, sub_add_eq_add_sub, mul_sub, add_mul, mul_comm k t, mul_comm k s, ← mul_assoc, ← mul_assoc,
    add_comm (x * s * k), ← add_sub_assoc, sub_sub]
[GOAL]
case H0
x y n✝ : ℕ
⊢ ∀ {s t s' t' : ℤ}, Nat.P x y (0, s, t) → Nat.P x y (n✝, s', t') → Nat.P x y (xgcdAux 0 s t n✝ s' t')
[PROOFSTEP]

| H0 => simp
[GOAL]
case H0
x y n✝ : ℕ
⊢ ∀ {s t s' t' : ℤ}, Nat.P x y (0, s, t) → Nat.P x y (n✝, s', t') → Nat.P x y (xgcdAux 0 s t n✝ s' t')
[PROOFSTEP]
simp
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH : ∀ {s t s' t' : ℤ}, Nat.P x y (b % a, s, t) → Nat.P x y (a, s', t') → Nat.P x y (xgcdAux (b % a) s t a s' t')
⊢ ∀ {s t s' t' : ℤ}, Nat.P x y (a, s, t) → Nat.P x y (b, s', t') → Nat.P x y (xgcdAux a s t b s' t')
[PROOFSTEP]

| H1 a b h IH =>
  intro s t s' t' p p'
  rw [xgcdAux_rec h]; refine' IH _ p; dsimp [P] at *
  rw [Int.emod_def]; generalize (b / a : ℤ) = k
  rw [p, p', mul_sub, sub_add_eq_add_sub, mul_sub, add_mul, mul_comm k t, mul_comm k s, ← mul_assoc, ← mul_assoc,
    add_comm (x * s * k), ← add_sub_assoc, sub_sub]
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH : ∀ {s t s' t' : ℤ}, Nat.P x y (b % a, s, t) → Nat.P x y (a, s', t') → Nat.P x y (xgcdAux (b % a) s t a s' t')
⊢ ∀ {s t s' t' : ℤ}, Nat.P x y (a, s, t) → Nat.P x y (b, s', t') → Nat.P x y (xgcdAux a s t b s' t')
[PROOFSTEP]
intro s t s' t' p p'
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH : ∀ {s t s' t' : ℤ}, Nat.P x y (b % a, s, t) → Nat.P x y (a, s', t') → Nat.P x y (xgcdAux (b % a) s t a s' t')
s t s' t' : ℤ
p : Nat.P x y (a, s, t)
p' : Nat.P x y (b, s', t')
⊢ Nat.P x y (xgcdAux a s t b s' t')
[PROOFSTEP]
rw [xgcdAux_rec h]
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH : ∀ {s t s' t' : ℤ}, Nat.P x y (b % a, s, t) → Nat.P x y (a, s', t') → Nat.P x y (xgcdAux (b % a) s t a s' t')
s t s' t' : ℤ
p : Nat.P x y (a, s, t)
p' : Nat.P x y (b, s', t')
⊢ Nat.P x y (xgcdAux (b % a) (s' - ↑b / ↑a * s) (t' - ↑b / ↑a * t) a s t)
[PROOFSTEP]
refine' IH _ p
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH : ∀ {s t s' t' : ℤ}, Nat.P x y (b % a, s, t) → Nat.P x y (a, s', t') → Nat.P x y (xgcdAux (b % a) s t a s' t')
s t s' t' : ℤ
p : Nat.P x y (a, s, t)
p' : Nat.P x y (b, s', t')
⊢ Nat.P x y (b % a, s' - ↑b / ↑a * s, t' - ↑b / ↑a * t)
[PROOFSTEP]
dsimp [P] at *
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH :
  ∀ {s t s' t' : ℤ},
    ↑b % ↑a = ↑x * s + ↑y * t →
      ↑a = ↑x * s' + ↑y * t' →
        ↑(xgcdAux (b % a) s t a s' t').fst =
          ↑x * (xgcdAux (b % a) s t a s' t').2.fst + ↑y * (xgcdAux (b % a) s t a s' t').2.snd
s t s' t' : ℤ
p : ↑a = ↑x * s + ↑y * t
p' : ↑b = ↑x * s' + ↑y * t'
⊢ ↑b % ↑a = ↑x * (s' - ↑b / ↑a * s) + ↑y * (t' - ↑b / ↑a * t)
[PROOFSTEP]
rw [Int.emod_def]
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH :
  ∀ {s t s' t' : ℤ},
    ↑b % ↑a = ↑x * s + ↑y * t →
      ↑a = ↑x * s' + ↑y * t' →
        ↑(xgcdAux (b % a) s t a s' t').fst =
          ↑x * (xgcdAux (b % a) s t a s' t').2.fst + ↑y * (xgcdAux (b % a) s t a s' t').2.snd
s t s' t' : ℤ
p : ↑a = ↑x * s + ↑y * t
p' : ↑b = ↑x * s' + ↑y * t'
⊢ ↑b - ↑a * (↑b / ↑a) = ↑x * (s' - ↑b / ↑a * s) + ↑y * (t' - ↑b / ↑a * t)
[PROOFSTEP]
generalize (b / a : ℤ) = k
[GOAL]
case H1
x y a b : ℕ
h : 0 < a
IH :
  ∀ {s t s' t' : ℤ},
    ↑b % ↑a = ↑x * s + ↑y * t →
      ↑a = ↑x * s' + ↑y * t' →
        ↑(xgcdAux (b % a) s t a s' t').fst =
          ↑x * (xgcdAux (b % a) s t a s' t').2.fst + ↑y * (xgcdAux (b % a) s t a s' t').2.snd
s t s' t' : ℤ
p : ↑a = ↑x * s + ↑y * t
p' : ↑b = ↑x * s' + ↑y * t'
k : ℤ
⊢ ↑b - ↑a * k = ↑x * (s' - k * s) + ↑y * (t' - k * t)
[PROOFSTEP]
rw [p, p', mul_sub, sub_add_eq_add_sub, mul_sub, add_mul, mul_comm k t, mul_comm k s, ← mul_assoc, ← mul_assoc,
  add_comm (x * s * k), ← add_sub_assoc, sub_sub]
[GOAL]
x y : ℕ
⊢ ↑(gcd x y) = ↑x * gcdA x y + ↑y * gcdB x y
[PROOFSTEP]
have := @xgcdAux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P])
[GOAL]
x y : ℕ
⊢ Nat.P x y (x, 1, 0)
[PROOFSTEP]
simp [P]
[GOAL]
x y : ℕ
⊢ Nat.P x y (y, 0, 1)
[PROOFSTEP]
simp [P]
[GOAL]
x y : ℕ
this : Nat.P x y (xgcdAux x 1 0 y 0 1)
⊢ ↑(gcd x y) = ↑x * gcdA x y + ↑y * gcdB x y
[PROOFSTEP]
rwa [xgcdAux_val, xgcd_val] at this 
[GOAL]
k n : ℕ
hk : gcd n k < k
⊢ ∃ m, n * m % k = gcd n k
[PROOFSTEP]
have hk' := Int.ofNat_ne_zero.2 (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk))
[GOAL]
k n : ℕ
hk : gcd n k < k
hk' : ↑k ≠ 0
⊢ ∃ m, n * m % k = gcd n k
[PROOFSTEP]
have key := congr_arg (fun (m : ℤ) => (m % k).toNat) (gcd_eq_gcd_ab n k)
[GOAL]
k n : ℕ
hk : gcd n k < k
hk' : ↑k ≠ 0
key : (fun m => Int.toNat (m % ↑k)) ↑(gcd n k) = (fun m => Int.toNat (m % ↑k)) (↑n * gcdA n k + ↑k * gcdB n k)
⊢ ∃ m, n * m % k = gcd n k
[PROOFSTEP]
simp only at key 
[GOAL]
k n : ℕ
hk : gcd n k < k
hk' : ↑k ≠ 0
key : Int.toNat (↑(gcd n k) % ↑k) = Int.toNat ((↑n * gcdA n k + ↑k * gcdB n k) % ↑k)
⊢ ∃ m, n * m % k = gcd n k
[PROOFSTEP]
rw [Int.add_mul_emod_self_left, ← Int.coe_nat_mod, Int.toNat_coe_nat, mod_eq_of_lt hk] at key 
[GOAL]
k n : ℕ
hk : gcd n k < k
hk' : ↑k ≠ 0
key : gcd n k = Int.toNat (↑n * gcdA n k % ↑k)
⊢ ∃ m, n * m % k = gcd n k
[PROOFSTEP]
refine' ⟨(n.gcdA k % k).toNat, Eq.trans (Int.ofNat.inj _) key.symm⟩
[GOAL]
k n : ℕ
hk : gcd n k < k
hk' : ↑k ≠ 0
key : gcd n k = Int.toNat (↑n * gcdA n k % ↑k)
⊢ Int.ofNat (n * Int.toNat (gcdA n k % ↑k) % k) = Int.ofNat (Int.toNat (↑n * gcdA n k % ↑k))
[PROOFSTEP]
rw [Int.ofNat_eq_coe, Int.coe_nat_mod, Int.ofNat_mul, Int.toNat_of_nonneg (Int.emod_nonneg _ hk'), Int.ofNat_eq_coe,
  Int.toNat_of_nonneg (Int.emod_nonneg _ hk'), Int.mul_emod, Int.emod_emod, ← Int.mul_emod]
[GOAL]
m n : ℕ
⊢ ↑(gcd ↑m -[n+1]) = ↑m * gcdA ↑m -[n+1] + -(↑n + 1) * -Nat.gcdB (natAbs ↑m) (Nat.succ n)
[PROOFSTEP]
rw [neg_mul_neg]
[GOAL]
m n : ℕ
⊢ ↑(gcd ↑m -[n+1]) = ↑m * gcdA ↑m -[n+1] + (↑n + 1) * Nat.gcdB (natAbs ↑m) (Nat.succ n)
[PROOFSTEP]
apply Nat.gcd_eq_gcd_ab
[GOAL]
m n : ℕ
⊢ ↑(gcd -[m+1] ↑n) = -(↑m + 1) * -Nat.gcdA (Nat.succ m) (natAbs ↑n) + ↑n * gcdB -[m+1] ↑n
[PROOFSTEP]
rw [neg_mul_neg]
[GOAL]
m n : ℕ
⊢ ↑(gcd -[m+1] ↑n) = (↑m + 1) * Nat.gcdA (Nat.succ m) (natAbs ↑n) + ↑n * gcdB -[m+1] ↑n
[PROOFSTEP]
apply Nat.gcd_eq_gcd_ab
[GOAL]
m n : ℕ
⊢ ↑(gcd -[m+1] -[n+1]) =
    -(↑m + 1) * -Nat.gcdA (Nat.succ m) (natAbs -[n+1]) + -(↑n + 1) * -Nat.gcdB (natAbs -[m+1]) (Nat.succ n)
[PROOFSTEP]
rw [neg_mul_neg, neg_mul_neg]
[GOAL]
m n : ℕ
⊢ ↑(gcd -[m+1] -[n+1]) =
    (↑m + 1) * Nat.gcdA (Nat.succ m) (natAbs -[n+1]) + (↑n + 1) * Nat.gcdB (natAbs -[m+1]) (Nat.succ n)
[PROOFSTEP]
apply Nat.gcd_eq_gcd_ab
[GOAL]
a b : ℤ
H : b ∣ a
⊢ natAbs (a / b) = natAbs a / natAbs b
[PROOFSTEP]
rcases Nat.eq_zero_or_pos (natAbs b) with (h | h)
[GOAL]
case inl
a b : ℤ
H : b ∣ a
h : natAbs b = 0
⊢ natAbs (a / b) = natAbs a / natAbs b
[PROOFSTEP]
rw [natAbs_eq_zero.1 h]
[GOAL]
case inl
a b : ℤ
H : b ∣ a
h : natAbs b = 0
⊢ natAbs (a / 0) = natAbs a / natAbs 0
[PROOFSTEP]
simp [Int.ediv_zero]
[GOAL]
case inr
a b : ℤ
H : b ∣ a
h : natAbs b > 0
⊢ natAbs (a / b) = natAbs a / natAbs b
[PROOFSTEP]
calc
  natAbs (a / b) = natAbs (a / b) * 1 := by rw [mul_one]
  _ = natAbs (a / b) * (natAbs b / natAbs b) := by rw [Nat.div_self h]
  _ = natAbs (a / b) * natAbs b / natAbs b := by rw [Nat.mul_div_assoc _ dvd_rfl]
  _ = natAbs (a / b * b) / natAbs b := by rw [natAbs_mul (a / b) b]
  _ = natAbs a / natAbs b := by rw [Int.ediv_mul_cancel H]
[GOAL]
a b : ℤ
H : b ∣ a
h : natAbs b > 0
⊢ natAbs (a / b) = natAbs (a / b) * 1
[PROOFSTEP]
rw [mul_one]
[GOAL]
a b : ℤ
H : b ∣ a
h : natAbs b > 0
⊢ natAbs (a / b) * 1 = natAbs (a / b) * (natAbs b / natAbs b)
[PROOFSTEP]
rw [Nat.div_self h]
[GOAL]
a b : ℤ
H : b ∣ a
h : natAbs b > 0
⊢ natAbs (a / b) * (natAbs b / natAbs b) = natAbs (a / b) * natAbs b / natAbs b
[PROOFSTEP]
rw [Nat.mul_div_assoc _ dvd_rfl]
[GOAL]
a b : ℤ
H : b ∣ a
h : natAbs b > 0
⊢ natAbs (a / b) * natAbs b / natAbs b = natAbs (a / b * b) / natAbs b
[PROOFSTEP]
rw [natAbs_mul (a / b) b]
[GOAL]
a b : ℤ
H : b ∣ a
h : natAbs b > 0
⊢ natAbs (a / b * b) / natAbs b = natAbs a / natAbs b
[PROOFSTEP]
rw [Int.ediv_mul_cancel H]
[GOAL]
i j k : ℤ
k_non_zero : k ≠ 0
H : k * i ∣ k * j
l : ℤ
H1 : k * j = k * i * l
⊢ i ∣ j
[PROOFSTEP]
rw [mul_assoc] at H1 
[GOAL]
i j k : ℤ
k_non_zero : k ≠ 0
H : k * i ∣ k * j
l : ℤ
H1 : k * j = k * (i * l)
⊢ i ∣ j
[PROOFSTEP]
exact ⟨_, mul_left_cancel₀ k_non_zero H1⟩
[GOAL]
i j k : ℤ
k_non_zero : k ≠ 0
H : i * k ∣ j * k
⊢ i ∣ j
[PROOFSTEP]
rw [mul_comm i k, mul_comm j k] at H 
[GOAL]
i j k : ℤ
k_non_zero : k ≠ 0
H : k * i ∣ k * j
⊢ i ∣ j
[PROOFSTEP]
exact dvd_of_mul_dvd_mul_left k_non_zero H
[GOAL]
i j : ℤ
⊢ gcd i j * lcm i j = natAbs (i * j)
[PROOFSTEP]
rw [Int.gcd, Int.lcm, Nat.gcd_mul_lcm, natAbs_mul]
[GOAL]
i : ℤ
⊢ gcd i i = natAbs i
[PROOFSTEP]
simp [gcd]
[GOAL]
i : ℤ
⊢ gcd 0 i = natAbs i
[PROOFSTEP]
simp [gcd]
[GOAL]
i : ℤ
⊢ gcd i 0 = natAbs i
[PROOFSTEP]
simp [gcd]
[GOAL]
x y : ℤ
⊢ gcd x (-y) = gcd x y
[PROOFSTEP]
rw [Int.gcd, Int.gcd, natAbs_neg]
[GOAL]
x y : ℤ
⊢ gcd (-x) y = gcd x y
[PROOFSTEP]
rw [Int.gcd, Int.gcd, natAbs_neg]
[GOAL]
i j k : ℤ
⊢ gcd (i * j) (i * k) = natAbs i * gcd j k
[PROOFSTEP]
rw [Int.gcd, Int.gcd, natAbs_mul, natAbs_mul]
[GOAL]
i j k : ℤ
⊢ Nat.gcd (natAbs i * natAbs j) (natAbs i * natAbs k) = natAbs i * Nat.gcd (natAbs j) (natAbs k)
[PROOFSTEP]
apply Nat.gcd_mul_left
[GOAL]
i j k : ℤ
⊢ gcd (i * j) (k * j) = gcd i k * natAbs j
[PROOFSTEP]
rw [Int.gcd, Int.gcd, natAbs_mul, natAbs_mul]
[GOAL]
i j k : ℤ
⊢ Nat.gcd (natAbs i * natAbs j) (natAbs k * natAbs j) = Nat.gcd (natAbs i) (natAbs k) * natAbs j
[PROOFSTEP]
apply Nat.gcd_mul_right
[GOAL]
i j : ℤ
⊢ gcd i j = 0 ↔ i = 0 ∧ j = 0
[PROOFSTEP]
rw [gcd, Nat.gcd_eq_zero_iff, natAbs_eq_zero, natAbs_eq_zero]
[GOAL]
i j k : ℤ
H1 : k ∣ i
H2 : k ∣ j
⊢ gcd (i / k) (j / k) = gcd i j / natAbs k
[PROOFSTEP]
rw [gcd, natAbs_ediv i k H1, natAbs_ediv j k H2]
[GOAL]
i j k : ℤ
H1 : k ∣ i
H2 : k ∣ j
⊢ Nat.gcd (natAbs i / natAbs k) (natAbs j / natAbs k) = gcd i j / natAbs k
[PROOFSTEP]
exact Nat.gcd_div (natAbs_dvd_natAbs.mpr H1) (natAbs_dvd_natAbs.mpr H2)
[GOAL]
i j : ℤ
H : 0 < gcd i j
⊢ gcd (i / ↑(gcd i j)) (j / ↑(gcd i j)) = 1
[PROOFSTEP]
rw [gcd_div (gcd_dvd_left i j) (gcd_dvd_right i j), natAbs_ofNat, Nat.div_self H]
[GOAL]
i j : ℤ
H : j ∣ i
⊢ gcd i j = natAbs j
[PROOFSTEP]
rw [gcd_comm, gcd_eq_left H]
[GOAL]
x y : ℤ
hc : gcd x y ≠ 0
⊢ x ≠ 0 ∨ y ≠ 0
[PROOFSTEP]
contrapose! hc
[GOAL]
x y : ℤ
hc : x = 0 ∧ y = 0
⊢ gcd x y = 0
[PROOFSTEP]
rw [hc.left, hc.right, gcd_zero_right, natAbs_zero]
[GOAL]
m n : ℤ
k : ℕ
k0 : 0 < k
⊢ m ^ k ∣ n ^ k ↔ m ∣ n
[PROOFSTEP]
refine' ⟨fun h => _, fun h => pow_dvd_pow_of_dvd h _⟩
[GOAL]
m n : ℤ
k : ℕ
k0 : 0 < k
h : m ^ k ∣ n ^ k
⊢ m ∣ n
[PROOFSTEP]
rwa [← natAbs_dvd_natAbs, ← Nat.pow_dvd_pow_iff k0, ← Int.natAbs_pow, ← Int.natAbs_pow, natAbs_dvd_natAbs]
[GOAL]
a b : ℤ
n : ℕ
⊢ gcd a b ∣ n ↔ ∃ x y, ↑n = a * x + b * y
[PROOFSTEP]
constructor
[GOAL]
case mp
a b : ℤ
n : ℕ
⊢ gcd a b ∣ n → ∃ x y, ↑n = a * x + b * y
[PROOFSTEP]
intro h
[GOAL]
case mp
a b : ℤ
n : ℕ
h : gcd a b ∣ n
⊢ ∃ x y, ↑n = a * x + b * y
[PROOFSTEP]
rw [← Nat.mul_div_cancel' h, Int.ofNat_mul, gcd_eq_gcd_ab, add_mul, mul_assoc, mul_assoc]
[GOAL]
case mp
a b : ℤ
n : ℕ
h : gcd a b ∣ n
⊢ ∃ x y, a * (gcdA a b * ↑(n / gcd a b)) + b * (gcdB a b * ↑(n / gcd a b)) = a * x + b * y
[PROOFSTEP]
exact ⟨_, _, rfl⟩
[GOAL]
case mpr
a b : ℤ
n : ℕ
⊢ (∃ x y, ↑n = a * x + b * y) → gcd a b ∣ n
[PROOFSTEP]
rintro ⟨x, y, h⟩
[GOAL]
case mpr.intro.intro
a b : ℤ
n : ℕ
x y : ℤ
h : ↑n = a * x + b * y
⊢ gcd a b ∣ n
[PROOFSTEP]
rw [← Int.coe_nat_dvd, h]
[GOAL]
case mpr.intro.intro
a b : ℤ
n : ℕ
x y : ℤ
h : ↑n = a * x + b * y
⊢ ↑(gcd a b) ∣ a * x + b * y
[PROOFSTEP]
exact dvd_add (dvd_mul_of_dvd_left (gcd_dvd_left a b) _) (dvd_mul_of_dvd_left (gcd_dvd_right a b) y)
[GOAL]
a b c : ℤ
habc : a ∣ b * c
hab : gcd a c = 1
⊢ a ∣ b
[PROOFSTEP]
have := gcd_eq_gcd_ab a c
[GOAL]
a b c : ℤ
habc : a ∣ b * c
hab : gcd a c = 1
this : ↑(gcd a c) = a * gcdA a c + c * gcdB a c
⊢ a ∣ b
[PROOFSTEP]
simp only [hab, Int.ofNat_zero, Int.ofNat_succ, zero_add] at this 
[GOAL]
a b c : ℤ
habc : a ∣ b * c
hab : gcd a c = 1
this : 1 = a * gcdA a c + c * gcdB a c
⊢ a ∣ b
[PROOFSTEP]
have : b * a * gcdA a c + b * c * gcdB a c = b := by simp [mul_assoc, ← mul_add, ← this]
[GOAL]
a b c : ℤ
habc : a ∣ b * c
hab : gcd a c = 1
this : 1 = a * gcdA a c + c * gcdB a c
⊢ b * a * gcdA a c + b * c * gcdB a c = b
[PROOFSTEP]
simp [mul_assoc, ← mul_add, ← this]
[GOAL]
a b c : ℤ
habc : a ∣ b * c
hab : gcd a c = 1
this✝ : 1 = a * gcdA a c + c * gcdB a c
this : b * a * gcdA a c + b * c * gcdB a c = b
⊢ a ∣ b
[PROOFSTEP]
rw [← this]
[GOAL]
a b c : ℤ
habc : a ∣ b * c
hab : gcd a c = 1
this✝ : 1 = a * gcdA a c + c * gcdB a c
this : b * a * gcdA a c + b * c * gcdB a c = b
⊢ a ∣ b * a * gcdA a c + b * c * gcdB a c
[PROOFSTEP]
exact dvd_add (dvd_mul_of_dvd_left (dvd_mul_left a b) _) (dvd_mul_of_dvd_left habc _)
[GOAL]
a b c : ℤ
habc : a ∣ b * c
hab : gcd a b = 1
⊢ a ∣ c
[PROOFSTEP]
rw [mul_comm] at habc 
[GOAL]
a b c : ℤ
habc : a ∣ c * b
hab : gcd a b = 1
⊢ a ∣ c
[PROOFSTEP]
exact dvd_of_dvd_mul_left_of_gcd_one habc hab
[GOAL]
a b : ℤ
ha : a ≠ 0
⊢ IsLeast {n | 0 < n ∧ ∃ x y, ↑n = a * x + b * y} (gcd a b)
[PROOFSTEP]
simp_rw [← gcd_dvd_iff]
[GOAL]
a b : ℤ
ha : a ≠ 0
⊢ IsLeast {n | 0 < n ∧ gcd a b ∣ n} (gcd a b)
[PROOFSTEP]
constructor
[GOAL]
case left
a b : ℤ
ha : a ≠ 0
⊢ gcd a b ∈ {n | 0 < n ∧ gcd a b ∣ n}
[PROOFSTEP]
simpa [and_true_iff, dvd_refl, Set.mem_setOf_eq] using gcd_pos_of_ne_zero_left b ha
[GOAL]
case right
a b : ℤ
ha : a ≠ 0
⊢ gcd a b ∈ lowerBounds {n | 0 < n ∧ gcd a b ∣ n}
[PROOFSTEP]
simp only [lowerBounds, and_imp, Set.mem_setOf_eq]
[GOAL]
case right
a b : ℤ
ha : a ≠ 0
⊢ ∀ ⦃a_1 : ℕ⦄, 0 < a_1 → gcd a b ∣ a_1 → gcd a b ≤ a_1
[PROOFSTEP]
exact fun n hn_pos hn => Nat.le_of_dvd hn_pos hn
[GOAL]
i j : ℤ
⊢ lcm i j = lcm j i
[PROOFSTEP]
rw [Int.lcm, Int.lcm]
[GOAL]
i j : ℤ
⊢ Nat.lcm (natAbs i) (natAbs j) = Nat.lcm (natAbs j) (natAbs i)
[PROOFSTEP]
exact Nat.lcm_comm _ _
[GOAL]
i j k : ℤ
⊢ lcm (↑(lcm i j)) k = lcm i ↑(lcm j k)
[PROOFSTEP]
rw [Int.lcm, Int.lcm, Int.lcm, Int.lcm, natAbs_ofNat, natAbs_ofNat]
[GOAL]
i j k : ℤ
⊢ Nat.lcm (Nat.lcm (natAbs i) (natAbs j)) (natAbs k) = Nat.lcm (natAbs i) (Nat.lcm (natAbs j) (natAbs k))
[PROOFSTEP]
apply Nat.lcm_assoc
[GOAL]
i : ℤ
⊢ lcm 0 i = 0
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i : ℤ
⊢ Nat.lcm (natAbs 0) (natAbs i) = 0
[PROOFSTEP]
apply Nat.lcm_zero_left
[GOAL]
i : ℤ
⊢ lcm i 0 = 0
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i : ℤ
⊢ Nat.lcm (natAbs i) (natAbs 0) = 0
[PROOFSTEP]
apply Nat.lcm_zero_right
[GOAL]
i : ℤ
⊢ lcm 1 i = natAbs i
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i : ℤ
⊢ Nat.lcm (natAbs 1) (natAbs i) = natAbs i
[PROOFSTEP]
apply Nat.lcm_one_left
[GOAL]
i : ℤ
⊢ lcm i 1 = natAbs i
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i : ℤ
⊢ Nat.lcm (natAbs i) (natAbs 1) = natAbs i
[PROOFSTEP]
apply Nat.lcm_one_right
[GOAL]
i : ℤ
⊢ lcm i i = natAbs i
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i : ℤ
⊢ Nat.lcm (natAbs i) (natAbs i) = natAbs i
[PROOFSTEP]
apply Nat.lcm_self
[GOAL]
i j : ℤ
⊢ i ∣ ↑(lcm i j)
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i j : ℤ
⊢ i ∣ ↑(Nat.lcm (natAbs i) (natAbs j))
[PROOFSTEP]
apply coe_nat_dvd_right.mpr
[GOAL]
i j : ℤ
⊢ natAbs i ∣ Nat.lcm (natAbs i) (natAbs j)
[PROOFSTEP]
apply Nat.dvd_lcm_left
[GOAL]
i j : ℤ
⊢ j ∣ ↑(lcm i j)
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i j : ℤ
⊢ j ∣ ↑(Nat.lcm (natAbs i) (natAbs j))
[PROOFSTEP]
apply coe_nat_dvd_right.mpr
[GOAL]
i j : ℤ
⊢ natAbs j ∣ Nat.lcm (natAbs i) (natAbs j)
[PROOFSTEP]
apply Nat.dvd_lcm_right
[GOAL]
i j k : ℤ
⊢ i ∣ k → j ∣ k → ↑(lcm i j) ∣ k
[PROOFSTEP]
rw [Int.lcm]
[GOAL]
i j k : ℤ
⊢ i ∣ k → j ∣ k → ↑(Nat.lcm (natAbs i) (natAbs j)) ∣ k
[PROOFSTEP]
intro hi hj
[GOAL]
i j k : ℤ
hi : i ∣ k
hj : j ∣ k
⊢ ↑(Nat.lcm (natAbs i) (natAbs j)) ∣ k
[PROOFSTEP]
exact coe_nat_dvd_left.mpr (Nat.lcm_dvd (natAbs_dvd_natAbs.mpr hi) (natAbs_dvd_natAbs.mpr hj))
[GOAL]
M : Type u_1
inst✝ : Monoid M
x : M
m n : ℕ
hm : x ^ m = 1
hn : x ^ n = 1
⊢ x ^ Nat.gcd m n = 1
[PROOFSTEP]
rcases m with (rfl | m)
[GOAL]
case zero
M : Type u_1
inst✝ : Monoid M
x : M
n : ℕ
hn : x ^ n = 1
hm : x ^ Nat.zero = 1
⊢ x ^ Nat.gcd Nat.zero n = 1
[PROOFSTEP]
simp [hn]
[GOAL]
case succ
M : Type u_1
inst✝ : Monoid M
x : M
n : ℕ
hn : x ^ n = 1
m : ℕ
hm : x ^ Nat.succ m = 1
⊢ x ^ Nat.gcd (Nat.succ m) n = 1
[PROOFSTEP]
obtain ⟨y, rfl⟩ := isUnit_ofPowEqOne hm m.succ_ne_zero
[GOAL]
case succ.intro
M : Type u_1
inst✝ : Monoid M
n m : ℕ
y : Mˣ
hn : ↑y ^ n = 1
hm : ↑y ^ Nat.succ m = 1
⊢ ↑y ^ Nat.gcd (Nat.succ m) n = 1
[PROOFSTEP]
simp only [← Units.val_pow_eq_pow_val] at *
[GOAL]
case succ.intro
M : Type u_1
inst✝ : Monoid M
n m : ℕ
y : Mˣ
hn : ↑(y ^ n) = 1
hm : ↑(y ^ Nat.succ m) = 1
⊢ ↑(y ^ Nat.gcd (Nat.succ m) n) = 1
[PROOFSTEP]
rw [← Units.val_one, ← zpow_coe_nat, ← Units.ext_iff] at *
[GOAL]
case succ.intro
M : Type u_1
inst✝ : Monoid M
n m : ℕ
y : Mˣ
hn : y ^ ↑n = 1
hm : y ^ ↑(Nat.succ m) = 1
⊢ y ^ ↑(Nat.gcd (Nat.succ m) n) = 1
[PROOFSTEP]
simp only [Nat.gcd_eq_gcd_ab, zpow_add, zpow_mul, hm, hn, one_zpow, one_mul]
