Theorem: Rat.add.aux
File: .lake/packages/batteries/Batteries/Data/Rat/Basic.lean

tactic: intro den num
state_before: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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;
  num.natAbs.gcd g = num.natAbs.gcd den
state_after: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd 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 = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd den
state_after: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd 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 = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd den
state_after: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd 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 = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd den
state_after: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd den

tactic: rw [hden, Nat.Coprime.gcd_mul_left_cancel_right]
state_before: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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
⊢ num.natAbs.gcd g = num.natAbs.gcd den
state_after: case H
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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
⊢ (ad * bd).Coprime num.natAbs

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 = a.den.gcd 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
⊢ (ad * bd).Coprime num.natAbs
state_after: case H
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
⊢ (ad * bd).Coprime num.natAbs

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 = a.den.gcd 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 : ad.Coprime bd
⊢ (ad * bd).Coprime num.natAbs
state_after: case H
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ (ad * bd).Coprime num.natAbs

tactic: apply Nat.Coprime.mul
state_before: case H
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ (ad * bd).Coprime num.natAbs
state_after: case H.H1
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ ad.Coprime num.natAbs

case H.H2
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ bd.Coprime num.natAbs

tactic: rw [Nat.mul_assoc, be]
state_before: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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
state_after: no goals

tactic: have := d.gcd_dvd_right num.natAbs
state_before: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
d : Nat
⊢ d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
state_after: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
d : Nat
this : d.gcd num.natAbs ∣ num.natAbs
⊢ d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad

tactic: rw [← Int.ofNat_dvd, Int.dvd_natAbs] at this
state_before: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
d : Nat
this : d.gcd num.natAbs ∣ num.natAbs
⊢ d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
state_after: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
d : Nat
this : ↑(d.gcd num.natAbs) ∣ num
⊢ d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad

tactic: have := Int.dvd_iff_dvd_of_dvd_add this
state_before: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
d : Nat
this : ↑(d.gcd num.natAbs) ∣ num
⊢ d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
state_after: a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
d : Nat
this✝ : ↑(d.gcd num.natAbs) ∣ num
this : ↑(d.gcd num.natAbs) ∣ a.num * ↑bd ↔ ↑(d.gcd num.natAbs) ∣ b.num * ↑ad
⊢ d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * 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 = a.den.gcd 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 : ad.Coprime bd
d : Nat
this✝ : ↑(d.gcd num.natAbs) ∣ num
this : ↑(d.gcd num.natAbs) ∣ a.num * ↑bd ↔ ↑(d.gcd num.natAbs) ∣ b.num * ↑ad
⊢ d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
state_after: no goals

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 = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ ad.Coprime num.natAbs
state_after: case H.H1
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this : ad.gcd num.natAbs ∣ a.num.natAbs * bd
⊢ ad.Coprime num.natAbs

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 = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this : ad.gcd num.natAbs ∣ a.num.natAbs * bd
⊢ ad.Coprime num.natAbs
state_after: case H.H1
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this✝ : ad.gcd num.natAbs ∣ a.num.natAbs * bd
this : ad.gcd num.natAbs ∣ a.num.natAbs
⊢ ad.Coprime num.natAbs

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 = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this✝ : ad.gcd num.natAbs ∣ a.num.natAbs * bd
this : ad.gcd num.natAbs ∣ a.num.natAbs
⊢ ad.Coprime num.natAbs
state_after: no goals

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 = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ bd.Coprime num.natAbs
state_after: case H.H2
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this : bd.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ bd.Coprime num.natAbs

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 = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this : bd.gcd num.natAbs ∣ b.num.natAbs * ad
⊢ bd.Coprime num.natAbs
state_after: case H.H2
a b : Rat
g ad bd : Nat
hg : g = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this✝ : bd.gcd num.natAbs ∣ b.num.natAbs * ad
this : bd.gcd num.natAbs ∣ b.num.natAbs
⊢ bd.Coprime num.natAbs

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 = a.den.gcd 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 : ad.Coprime bd
H1 : ∀ (d : Nat), d.gcd num.natAbs ∣ a.num.natAbs * bd ↔ d.gcd num.natAbs ∣ b.num.natAbs * ad
this✝ : bd.gcd num.natAbs ∣ b.num.natAbs * ad
this : bd.gcd num.natAbs ∣ b.num.natAbs
⊢ bd.Coprime num.natAbs
state_after: no goals