File: .lake/packages/batteries/Batteries/Data/Rat/Lemmas.lean

full_name: Rat.ext
code: theorem ext : {p q : Rat} → p.num = q.num → p.den = q.den → p = q
  
goal: p.num = q.num → p.den = q.den → p = q

full_name: Rat.mk_den_one
code: @[simp] theorem mk_den_one {r : Int} :
    ⟨r, 1, Nat.one_ne_zero, (Nat.coprime_one_right _)⟩ = (r : Rat) 
goal: { num := r, den := 1, den_nz := Nat.one_ne_zero, reduced := ⋯ } = ↑r

full_name: Rat.zero_num
code: @[simp] theorem zero_num : (0 : Rat).num = 0 
goal: Rat.num 0 = 0

full_name: Rat.zero_den
code: @[simp] theorem zero_den : (0 : Rat).den = 1 
goal: Rat.den 0 = 1

full_name: Rat.one_num
code: @[simp] theorem one_num : (1 : Rat).num = 1 
goal: Rat.num 1 = 1

full_name: Rat.one_den
code: @[simp] theorem one_den : (1 : Rat).den = 1 
goal: Rat.den 1 = 1

full_name: Rat.maybeNormalize_eq
code: @[simp] theorem maybeNormalize_eq {num den g} (den_nz reduced) :
    maybeNormalize num den g den_nz reduced =
    { num := num.div g, den := den / g, den_nz, reduced } 
goal: Rat.maybeNormalize num den g den_nz reduced =
  { num := num.div ↑g, den := den / g, den_nz := den_nz, reduced := reduced }

full_name: Rat.normalize.reduced'
code: theorem normalize.reduced' {num : Int} {den g : Nat} (den_nz : den ≠ 0)
    (e : g = num.natAbs.gcd den) : (num / g).natAbs.Coprime (den / g) 
goal: (num / ↑g).natAbs.Coprime (den / g)

full_name: Rat.normalize_eq
code: theorem normalize_eq {num den} (den_nz) : normalize num den den_nz =
    { num := num / num.natAbs.gcd den
      den := den / num.natAbs.gcd den
      den_nz := normalize.den_nz den_nz rfl
      reduced := normalize.reduced' den_nz rfl } 
goal: Rat.normalize num den den_nz =
  { num := num / ↑(num.natAbs.gcd den), den := den / num.natAbs.gcd den, den_nz := ⋯, reduced := ⋯ }

full_name: Rat.normalize_zero
code: @[simp] theorem normalize_zero (nz) : normalize 0 d nz = 0 
goal: Rat.normalize 0 d nz = 0

full_name: Rat.mk_eq_normalize
code: theorem mk_eq_normalize (num den nz c) : ⟨num, den, nz, c⟩ = normalize num den nz 
goal: { num := num, den := den, den_nz := nz, reduced := c } = Rat.normalize num den nz

full_name: Rat.normalize_self
code: theorem normalize_self (r : Rat) : normalize r.num r.den r.den_nz = r 
goal: Rat.normalize r.num r.den ⋯ = r

full_name: Rat.normalize_mul_left
code: theorem normalize_mul_left {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) :
    normalize (↑a * n) (a * d) (Nat.mul_ne_zero a0 d0) = normalize n d d0 
goal: Rat.normalize (↑a * n) (a * d) ⋯ = Rat.normalize n d d0

full_name: Rat.normalize_mul_right
code: theorem normalize_mul_right {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) :
    normalize (n * a) (d * a) (Nat.mul_ne_zero d0 a0) = normalize n d d0 
goal: Rat.normalize (n * ↑a) (d * a) ⋯ = Rat.normalize n d d0

full_name: Rat.normalize_eq_iff
code: theorem normalize_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
    normalize n₁ d₁ z₁ = normalize n₂ d₂ z₂ ↔ n₁ * d₂ = n₂ * d₁ 
goal: Rat.normalize n₁ d₁ z₁ = Rat.normalize n₂ d₂ z₂ ↔ n₁ * ↑d₂ = n₂ * ↑d₁

full_name: Rat.maybeNormalize_eq_normalize
code: theorem maybeNormalize_eq_normalize {num : Int} {den g : Nat} (den_nz reduced)
    (hn : ↑g ∣ num) (hd : g ∣ den) :
    maybeNormalize num den g den_nz reduced = normalize num den (mt (by simp [·]) den_nz) 
goal: Rat.maybeNormalize num den g den_nz reduced = Rat.normalize num den ⋯

full_name: Rat.normalize_eq_zero
code: @[simp] theorem normalize_eq_zero (d0 : d ≠ 0) : normalize n d d0 = 0 ↔ n = 0 
goal: Rat.normalize n d d0 = 0 ↔ n = 0

full_name: Rat.normalize_num_den'
code: theorem normalize_num_den' (num den nz) : ∃ d : Nat, d ≠ 0 ∧
    num = (normalize num den nz).num * d ∧ den = (normalize num den nz).den * d 
goal: ∃ d, d ≠ 0 ∧ num = (Rat.normalize num den nz).num * ↑d ∧ den = (Rat.normalize num den nz).den * d

full_name: Rat.normalize_num_den
code: theorem normalize_num_den (h : normalize n d z = ⟨n', d', z', c⟩) :
    ∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m 
goal: ∃ m, m ≠ 0 ∧ n = n' * ↑m ∧ d = d' * m

full_name: Rat.normalize_eq_mkRat
code: theorem normalize_eq_mkRat {num den} (den_nz) : normalize num den den_nz = mkRat num den 
goal: Rat.normalize num den den_nz = mkRat num den

full_name: Rat.mkRat_num_den
code: theorem mkRat_num_den (z : d ≠ 0) (h : mkRat n d = ⟨n', d', z', c⟩) :
    ∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m 
goal: ∃ m, m ≠ 0 ∧ n = n' * ↑m ∧ d = d' * m

full_name: Rat.mkRat_def
code: theorem mkRat_def (n d) : mkRat n d = if d0 : d = 0 then 0 else normalize n d d0 
goal: mkRat n d = if d0 : d = 0 then 0 else Rat.normalize n d d0

full_name: Rat.mkRat_self
code: theorem mkRat_self (a : Rat) : mkRat a.num a.den = a 
goal: mkRat a.num a.den = a

full_name: Rat.mk_eq_mkRat
code: theorem mk_eq_mkRat (num den nz c) : ⟨num, den, nz, c⟩ = mkRat num den 
goal: { num := num, den := den, den_nz := nz, reduced := c } = mkRat num den

full_name: Rat.zero_mkRat
code: @[simp] theorem zero_mkRat (n) : mkRat 0 n = 0 
goal: mkRat 0 n = 0

full_name: Rat.mkRat_zero
code: @[simp] theorem mkRat_zero (n) : mkRat n 0 = 0 
goal: mkRat n 0 = 0

full_name: Rat.mkRat_eq_zero
code: theorem mkRat_eq_zero (d0 : d ≠ 0) : mkRat n d = 0 ↔ n = 0 
goal: mkRat n d = 0 ↔ n = 0

full_name: Rat.mkRat_ne_zero
code: theorem mkRat_ne_zero (d0 : d ≠ 0) : mkRat n d ≠ 0 ↔ n ≠ 0 
goal: mkRat n d ≠ 0 ↔ n ≠ 0

full_name: Rat.mkRat_mul_left
code: theorem mkRat_mul_left {a : Nat} (a0 : a ≠ 0) : mkRat (↑a * n) (a * d) = mkRat n d 
goal: mkRat (↑a * n) (a * d) = mkRat n d

full_name: Rat.mkRat_mul_right
code: theorem mkRat_mul_right {a : Nat} (a0 : a ≠ 0) : mkRat (n * a) (d * a) = mkRat n d 
goal: mkRat (n * ↑a) (d * a) = mkRat n d

full_name: Rat.mkRat_eq_iff
code: theorem mkRat_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
    mkRat n₁ d₁ = mkRat n₂ d₂ ↔ n₁ * d₂ = n₂ * d₁ 
goal: mkRat n₁ d₁ = mkRat n₂ d₂ ↔ n₁ * ↑d₂ = n₂ * ↑d₁

full_name: Rat.divInt_ofNat
code: @[simp] theorem divInt_ofNat (num den) : num /. (den : Nat) = mkRat num den 
goal: num /. ↑den = mkRat num den

full_name: Rat.mk_eq_divInt
code: theorem mk_eq_divInt (num den nz c) : ⟨num, den, nz, c⟩ = num /. (den : Nat) 
goal: { num := num, den := den, den_nz := nz, reduced := c } = num /. ↑den

full_name: Rat.divInt_self
code: theorem divInt_self (a : Rat) : a.num /. a.den = a 
goal: a.num /. ↑a.den = a

full_name: Rat.zero_divInt
code: @[simp] theorem zero_divInt (n) : 0 /. n = 0 
goal: 0 /. n = 0

full_name: Rat.divInt_zero
code: @[simp] theorem divInt_zero (n) : n /. 0 = 0 
goal: n /. 0 = 0

full_name: Rat.neg_divInt_neg
code: theorem neg_divInt_neg (num den) : -num /. -den = num /. den 
goal: -num /. -den = num /. den

full_name: Rat.divInt_neg'
code: theorem divInt_neg' (num den) : num /. -den = -num /. den 
goal: num /. -den = -num /. den

full_name: Rat.divInt_eq_iff
code: theorem divInt_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
    n₁ /. d₁ = n₂ /. d₂ ↔ n₁ * d₂ = n₂ * d₁ 
goal: n₁ /. d₁ = n₂ /. d₂ ↔ n₁ * d₂ = n₂ * d₁

full_name: Rat.divInt_mul_left
code: theorem divInt_mul_left {a : Int} (a0 : a ≠ 0) : (a * n) /. (a * d) = n /. d 
goal: a * n /. (a * d) = n /. d

full_name: Rat.divInt_mul_right
code: theorem divInt_mul_right {a : Int} (a0 : a ≠ 0) : (n * a) /. (d * a) = n /. d 
goal: n * a /. (d * a) = n /. d

full_name: Rat.divInt_num_den
code: theorem divInt_num_den (z : d ≠ 0) (h : n /. d = ⟨n', d', z', c⟩) :
    ∃ m, m ≠ 0 ∧ n = n' * m ∧ d = d' * m 
goal: ∃ m, m ≠ 0 ∧ n = n' * m ∧ d = ↑d' * m

full_name: Rat.ofInt_ofNat
code: @[simp] theorem ofInt_ofNat : ofInt (OfNat.ofNat n) = OfNat.ofNat n 
goal: Rat.ofInt (OfNat.ofNat n) = OfNat.ofNat n

full_name: Rat.ofInt_num
code: @[simp] theorem ofInt_num : (ofInt n : Rat).num = n 
goal: (Rat.ofInt n).num = n

full_name: Rat.ofInt_den
code: @[simp] theorem ofInt_den : (ofInt n : Rat).den = 1 
goal: (Rat.ofInt n).den = 1

full_name: Rat.ofNat_num
code: @[simp] theorem ofNat_num : (OfNat.ofNat n : Rat).num = OfNat.ofNat n 
goal: Rat.num (OfNat.ofNat n) = OfNat.ofNat n

full_name: Rat.ofNat_den
code: @[simp] theorem ofNat_den : (OfNat.ofNat n : Rat).den = 1 
goal: Rat.den (OfNat.ofNat n) = 1

full_name: Rat.add_def
code: theorem add_def (a b : Rat) :
    a + b = normalize (a.num * b.den + b.num * a.den) (a.den * b.den)
      (Nat.mul_ne_zero a.den_nz b.den_nz) 
goal: a + b = Rat.normalize (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den) ⋯

full_name: Rat.add_def'
code: theorem add_def' (a b : Rat) : a + b = mkRat (a.num * b.den + b.num * a.den) (a.den * b.den) 
goal: a + b = mkRat (a.num * ↑b.den + b.num * ↑a.den) (a.den * b.den)

full_name: Rat.normalize_add_normalize
code: theorem normalize_add_normalize (n₁ n₂) {d₁ d₂} (z₁ z₂) :
    normalize n₁ d₁ z₁ + normalize n₂ d₂ z₂ =
    normalize (n₁ * d₂ + n₂ * d₁) (d₁ * d₂) (Nat.mul_ne_zero z₁ z₂) 
goal: Rat.normalize n₁ d₁ z₁ + Rat.normalize n₂ d₂ z₂ = Rat.normalize (n₁ * ↑d₂ + n₂ * ↑d₁) (d₁ * d₂) ⋯

full_name: Rat.mkRat_add_mkRat
code: theorem mkRat_add_mkRat (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
    mkRat n₁ d₁ + mkRat n₂ d₂ = mkRat (n₁ * d₂ + n₂ * d₁) (d₁ * d₂) 
goal: mkRat n₁ d₁ + mkRat n₂ d₂ = mkRat (n₁ * ↑d₂ + n₂ * ↑d₁) (d₁ * d₂)

full_name: Rat.divInt_add_divInt
code: theorem divInt_add_divInt (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
    n₁ /. d₁ + n₂ /. d₂ = (n₁ * d₂ + n₂ * d₁) /. (d₁ * d₂) 
goal: n₁ /. d₁ + n₂ /. d₂ = (n₁ * d₂ + n₂ * d₁) /. (d₁ * d₂)

full_name: Rat.neg_num
code: @[simp] theorem neg_num (a : Rat) : (-a).num = -a.num 
goal: (-a).num = -a.num

full_name: Rat.neg_den
code: @[simp] theorem neg_den (a : Rat) : (-a).den = a.den 
goal: (-a).den = a.den

full_name: Rat.neg_normalize
code: theorem neg_normalize (n d z) : -normalize n d z = normalize (-n) d z 
goal: -Rat.normalize n d z = Rat.normalize (-n) d z

full_name: Rat.neg_mkRat
code: theorem neg_mkRat (n d) : -mkRat n d = mkRat (-n) d 
goal: -mkRat n d = mkRat (-n) d

full_name: Rat.neg_divInt
code: theorem neg_divInt (n d) : -(n /. d) = -n /. d 
goal: -(n /. d) = -n /. d

full_name: Rat.sub_def
code: theorem sub_def (a b : Rat) :
    a - b = normalize (a.num * b.den - b.num * a.den) (a.den * b.den)
      (Nat.mul_ne_zero a.den_nz b.den_nz) 
goal: a - b = Rat.normalize (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den) ⋯

full_name: Rat.sub_def'
code: theorem sub_def' (a b : Rat) : a - b = mkRat (a.num * b.den - b.num * a.den) (a.den * b.den) 
goal: a - b = mkRat (a.num * ↑b.den - b.num * ↑a.den) (a.den * b.den)

full_name: Rat.sub_eq_add_neg
code: protected theorem sub_eq_add_neg (a b : Rat) : a - b = a + -b 
goal: a - b = a + -b

full_name: Rat.divInt_sub_divInt
code: theorem divInt_sub_divInt (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
    n₁ /. d₁ - n₂ /. d₂ = (n₁ * d₂ - n₂ * d₁) /. (d₁ * d₂) 
goal: n₁ /. d₁ - n₂ /. d₂ = (n₁ * d₂ - n₂ * d₁) /. (d₁ * d₂)

full_name: Rat.mul_def
code: theorem mul_def (a b : Rat) :
    a * b = normalize (a.num * b.num) (a.den * b.den) (Nat.mul_ne_zero a.den_nz b.den_nz) 
goal: a * b = Rat.normalize (a.num * b.num) (a.den * b.den) ⋯

full_name: Rat.mul_comm
code: protected theorem mul_comm (a b : Rat) : a * b = b * a 
goal: a * b = b * a

full_name: Rat.zero_mul
code: @[simp] protected theorem zero_mul (a : Rat) : 0 * a = 0 
goal: 0 * a = 0

full_name: Rat.mul_zero
code: @[simp] protected theorem mul_zero (a : Rat) : a * 0 = 0 
goal: a * 0 = 0

full_name: Rat.one_mul
code: @[simp] protected theorem one_mul (a : Rat) : 1 * a = a 
goal: 1 * a = a

full_name: Rat.mul_one
code: @[simp] protected theorem mul_one (a : Rat) : a * 1 = a 
goal: a * 1 = a

full_name: Rat.normalize_mul_normalize
code: theorem normalize_mul_normalize (n₁ n₂) {d₁ d₂} (z₁ z₂) :
    normalize n₁ d₁ z₁ * normalize n₂ d₂ z₂ =
    normalize (n₁ * n₂) (d₁ * d₂) (Nat.mul_ne_zero z₁ z₂) 
goal: Rat.normalize n₁ d₁ z₁ * Rat.normalize n₂ d₂ z₂ = Rat.normalize (n₁ * n₂) (d₁ * d₂) ⋯

full_name: Rat.mkRat_mul_mkRat
code: theorem mkRat_mul_mkRat (n₁ n₂ : Int) (d₁ d₂) :
    mkRat n₁ d₁ * mkRat n₂ d₂ = mkRat (n₁ * n₂) (d₁ * d₂) 
goal: mkRat n₁ d₁ * mkRat n₂ d₂ = mkRat (n₁ * n₂) (d₁ * d₂)

full_name: Rat.divInt_mul_divInt
code: theorem divInt_mul_divInt (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) :
    (n₁ /. d₁) * (n₂ /. d₂) = (n₁ * n₂) /. (d₁ * d₂) 
goal: n₁ /. d₁ * (n₂ /. d₂) = n₁ * n₂ /. (d₁ * d₂)

full_name: Rat.inv_def
code: theorem inv_def (a : Rat) : a.inv = a.den /. a.num 
goal: a.inv = ↑a.den /. a.num

full_name: Rat.inv_zero
code: @[simp] protected theorem inv_zero : (0 : Rat).inv = 0 
goal: Rat.inv 0 = 0

full_name: Rat.inv_divInt
code: @[simp] theorem inv_divInt (n d : Int) : (n /. d).inv = d /. n 
goal: (n /. d).inv = d /. n

full_name: Rat.div_def
code: theorem div_def (a b : Rat) : a / b = a * b.inv 
goal: a / b = a * b.inv

full_name: Rat.ofScientific_true_def
code: theorem ofScientific_true_def : Rat.ofScientific m true e = mkRat m (10 ^ e) 
goal: Rat.ofScientific m true e = mkRat (↑m) (10 ^ e)

full_name: Rat.ofScientific_false_def
code: theorem ofScientific_false_def : Rat.ofScientific m false e = (m * 10 ^ e : Nat) 
goal: Rat.ofScientific m false e = ↑(m * 10 ^ e)

full_name: Rat.ofScientific_def
code: theorem ofScientific_def : Rat.ofScientific m s e =
    if s then mkRat m (10 ^ e) else (m * 10 ^ e : Nat) 
goal: Rat.ofScientific m s e = if s = true then mkRat (↑m) (10 ^ e) else ↑(m * 10 ^ e)

full_name: Rat.intCast_den
code: @[simp] theorem intCast_den (a : Int) : (a : Rat).den = 1 
goal: (↑a).den = 1

full_name: Rat.intCast_num
code: @[simp] theorem intCast_num (a : Int) : (a : Rat).num = a 
goal: (↑a).num = a

full_name: Rat.intCast_inj
code: @[simp, norm_cast] theorem intCast_inj {a b : Int} : (a : Rat) = (b : Rat) ↔ a = b 
goal: ↑a = ↑b ↔ a = b

full_name: Rat.intCast_zero
code: theorem intCast_zero : ((0 : Int) : Rat) = (0 : Rat) 
goal: ↑0 = 0

full_name: Rat.intCast_one
code: theorem intCast_one : ((1 : Int) : Rat) = (1 : Rat) 
goal: ↑1 = 1

full_name: Rat.intCast_add
code: @[simp, norm_cast] theorem intCast_add (a b : Int) :
    ((a + b : Int) : Rat) = (a : Rat) + (b : Rat) 
goal: ↑(a + b) = ↑a + ↑b

full_name: Rat.intCast_neg
code: @[simp, norm_cast] theorem intCast_neg (a : Int) : ((-a : Int) : Rat) = -(a : Rat) 
goal: ↑(-a) = -↑a

full_name: Rat.intCast_sub
code: @[simp, norm_cast] theorem intCast_sub (a b : Int) :
    ((a - b : Int) : Rat) = (a : Rat) - (b : Rat) 
goal: ↑(a - b) = ↑a - ↑b

full_name: Rat.intCast_mul
code: @[simp, norm_cast] theorem intCast_mul (a b : Int) :
    ((a * b : Int) : Rat) = (a : Rat) * (b : Rat) 
goal: ↑(a * b) = ↑a * ↑b