Theorem: Rat.add.aux
File: Std/Data/Rat/Basic.lean

tactic: intro den num
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
⊢ let den := ad * b.den;
  let num := a.num * ↑bd + b.num * ↑ad;
  Nat.gcd (Int.natAbs num) g = Nat.gcd (Int.natAbs num) den

tactic: have ae : ad * g = a.den := had ▸ Nat.div_mul_cancel (hg ▸ Nat.gcd_dvd_left ..)
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
⊢ Nat.gcd (Int.natAbs num) g = Nat.gcd (Int.natAbs num) den

tactic: have be : bd * g = b.den := hbd ▸ Nat.div_mul_cancel (hg ▸ Nat.gcd_dvd_right ..)
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
⊢ Nat.gcd (Int.natAbs num) g = Nat.gcd (Int.natAbs num) den

tactic: have hden : den = ad * bd * g := by rw [Nat.mul_assoc, be]
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
⊢ Nat.gcd (Int.natAbs num) g = Nat.gcd (Int.natAbs num) den

tactic: rw [hden, Nat.coprime.gcd_mul_left_cancel_right]
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
⊢ Nat.gcd (Int.natAbs num) g = Nat.gcd (Int.natAbs num) den

tactic: have cop : ad.coprime bd := had ▸ hbd ▸ hg ▸
  Nat.coprime_div_gcd_div_gcd (Nat.gcd_pos_of_pos_left _ a.den_pos)
state_before: case H
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
⊢ Nat.coprime (ad * bd) (Int.natAbs num)

tactic: have H1 (d : Nat) :
    d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad := by
  have := d.gcd_dvd_right num.natAbs
  rw [← Int.ofNat_dvd, Int.dvd_natAbs] at this
  have := Int.dvd_iff_dvd_of_dvd_add this
  rwa [← Int.dvd_natAbs, Int.ofNat_dvd, Int.natAbs_mul,
    ← Int.dvd_natAbs, Int.ofNat_dvd, Int.natAbs_mul] at this
state_before: case H
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
⊢ Nat.coprime (ad * bd) (Int.natAbs num)

tactic: apply Nat.coprime.mul
state_before: case H
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
H1 :
  ∀ (d : Nat), Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad
⊢ Nat.coprime (ad * bd) (Int.natAbs num)

tactic: rw [Nat.mul_assoc, be]
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
⊢ den = ad * bd * g

tactic: have := d.gcd_dvd_right num.natAbs
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
d : Nat
⊢ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad

tactic: rw [← Int.ofNat_dvd, Int.dvd_natAbs] at this
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
d : Nat
this : Nat.gcd d (Int.natAbs num) ∣ Int.natAbs num
⊢ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad

tactic: have := Int.dvd_iff_dvd_of_dvd_add this
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
d : Nat
this : ↑(Nat.gcd d (Int.natAbs num)) ∣ num
⊢ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad

tactic: rwa [← Int.dvd_natAbs, Int.ofNat_dvd, Int.natAbs_mul,
  ← Int.dvd_natAbs, Int.ofNat_dvd, Int.natAbs_mul] at this
state_before: a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
d : Nat
this✝ : ↑(Nat.gcd d (Int.natAbs num)) ∣ num
this : ↑(Nat.gcd d (Int.natAbs num)) ∣ a.num * ↑bd ↔ ↑(Nat.gcd d (Int.natAbs num)) ∣ b.num * ↑ad
⊢ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad

tactic: have := (H1 ad).2 <| Nat.dvd_trans (Nat.gcd_dvd_left ..) (Nat.dvd_mul_left ..)
state_before: case H.H1
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
H1 :
  ∀ (d : Nat), Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad
⊢ Nat.coprime ad (Int.natAbs num)

tactic: have := (cop.coprime_dvd_left <| Nat.gcd_dvd_left ..).dvd_of_dvd_mul_right this
state_before: case H.H1
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
H1 :
  ∀ (d : Nat), Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad
this : Nat.gcd ad (Int.natAbs num) ∣ Int.natAbs a.num * bd
⊢ Nat.coprime ad (Int.natAbs num)

tactic: exact Nat.eq_one_of_dvd_one <| a.reduced.gcd_eq_one ▸ Nat.dvd_gcd this <|
  Nat.dvd_trans (Nat.gcd_dvd_left ..) (ae ▸ Nat.dvd_mul_right ..)
state_before: case H.H1
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
H1 :
  ∀ (d : Nat), Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad
this✝ : Nat.gcd ad (Int.natAbs num) ∣ Int.natAbs a.num * bd
this : Nat.gcd ad (Int.natAbs num) ∣ Int.natAbs a.num
⊢ Nat.coprime ad (Int.natAbs num)

tactic: have := (H1 bd).1 <| Nat.dvd_trans (Nat.gcd_dvd_left ..) (Nat.dvd_mul_left ..)
state_before: case H.H2
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
H1 :
  ∀ (d : Nat), Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad
⊢ Nat.coprime bd (Int.natAbs num)

tactic: have := (cop.symm.coprime_dvd_left <| Nat.gcd_dvd_left ..).dvd_of_dvd_mul_right this
state_before: case H.H2
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
H1 :
  ∀ (d : Nat), Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad
this : Nat.gcd bd (Int.natAbs num) ∣ Int.natAbs b.num * ad
⊢ Nat.coprime bd (Int.natAbs num)

tactic: exact Nat.eq_one_of_dvd_one <| b.reduced.gcd_eq_one ▸ Nat.dvd_gcd this <|
  Nat.dvd_trans (Nat.gcd_dvd_left ..) (be ▸ Nat.dvd_mul_right ..)
state_before: case H.H2
a b : Rat
g ad bd : Nat
hg : g = Nat.gcd a.den b.den
had : ad = a.den / g
hbd : bd = b.den / g
den : Nat := ad * b.den
num : Int := a.num * ↑bd + b.num * ↑ad
ae : ad * g = a.den
be : bd * g = b.den
hden : den = ad * bd * g
cop : Nat.coprime ad bd
H1 :
  ∀ (d : Nat), Nat.gcd d (Int.natAbs num) ∣ Int.natAbs a.num * bd ↔ Nat.gcd d (Int.natAbs num) ∣ Int.natAbs b.num * ad
this✝ : Nat.gcd bd (Int.natAbs num) ∣ Int.natAbs b.num * ad
this : Nat.gcd bd (Int.natAbs num) ∣ Int.natAbs b.num
⊢ Nat.coprime bd (Int.natAbs num)