Additional lemmas about the Rational Numbers #
@[simp]
theorem
Rat.mk_den_one
{r : Int}
:
{ num := r, den := 1, den_nz := Nat.one_ne_zero, reduced := ⋯ } = ↑r
theorem
Rat.normalize_eq
{num : Int}
{den : Nat}
(den_nz : den ≠ 0)
:
Rat.normalize num den den_nz = { num := num / ↑(num.natAbs.gcd den), den := den / num.natAbs.gcd den, den_nz := ⋯, reduced := ⋯ }
theorem
Rat.mk_eq_normalize
(num : Int)
(den : Nat)
(nz : den ≠ 0)
(c : num.natAbs.Coprime den)
:
{ num := num, den := den, den_nz := nz, reduced := c } = Rat.normalize num den nz
theorem
Rat.normalize_mul_left
{d : Nat}
{n : Int}
{a : Nat}
(d0 : d ≠ 0)
(a0 : a ≠ 0)
:
Rat.normalize (↑a * n) (a * d) ⋯ = Rat.normalize n d d0
theorem
Rat.normalize_mul_right
{d : Nat}
{n : Int}
{a : Nat}
(d0 : d ≠ 0)
(a0 : a ≠ 0)
:
Rat.normalize (n * ↑a) (d * a) ⋯ = Rat.normalize n d d0
theorem
Rat.normalize_eq_iff
{d₁ : Nat}
{d₂ : Nat}
{n₁ : Int}
{n₂ : Int}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.normalize n₁ d₁ z₁ = Rat.normalize n₂ d₂ z₂ ↔ n₁ * ↑d₂ = n₂ * ↑d₁
theorem
Rat.maybeNormalize_eq_normalize
{num : Int}
{den : Nat}
{g : Nat}
(den_nz : den / g ≠ 0)
(reduced : (num.div ↑g).natAbs.Coprime (den / g))
(hn : ↑g ∣ num)
(hd : g ∣ den)
:
Rat.maybeNormalize num den g den_nz reduced = Rat.normalize num den ⋯
@[simp]
theorem
Rat.normalize_num_den'
(num : Int)
(den : Nat)
(nz : den ≠ 0)
:
∃ (d : Nat), d ≠ 0 ∧ num = (Rat.normalize num den nz).num * ↑d ∧ den = (Rat.normalize num den nz).den * d
theorem
Rat.normalize_eq_mkRat
{num : Int}
{den : Nat}
(den_nz : den ≠ 0)
:
Rat.normalize num den den_nz = mkRat num den
theorem
Rat.mkRat_def
(n : Int)
(d : Nat)
:
mkRat n d = if d0 : d = 0 then 0 else Rat.normalize n d d0
theorem
Rat.mk_eq_divInt
(num : Int)
(den : Nat)
(nz : den ≠ 0)
(c : num.natAbs.Coprime den)
:
{ num := num, den := den, den_nz := nz, reduced := c } = Rat.divInt num ↑den
theorem
Rat.divInt_eq_iff
{d₁ : Int}
{d₂ : Int}
{n₁ : Int}
{n₂ : Int}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.divInt n₁ d₁ = Rat.divInt n₂ d₂ ↔ n₁ * d₂ = n₂ * d₁
theorem
Rat.divInt_mul_left
{n : Int}
{d : Int}
{a : Int}
(a0 : a ≠ 0)
:
Rat.divInt (a * n) (a * d) = Rat.divInt n d
theorem
Rat.divInt_mul_right
{n : Int}
{d : Int}
{a : Int}
(a0 : a ≠ 0)
:
Rat.divInt (n * a) (d * a) = Rat.divInt n d
theorem
Rat.normalize_add_normalize
(n₁ : Int)
(n₂ : Int)
{d₁ : Nat}
{d₂ : Nat}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.normalize n₁ d₁ z₁ + Rat.normalize n₂ d₂ z₂ = Rat.normalize (n₁ * ↑d₂ + n₂ * ↑d₁) (d₁ * d₂) ⋯
theorem
Rat.divInt_add_divInt
(n₁ : Int)
(n₂ : Int)
{d₁ : Int}
{d₂ : Int}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.divInt n₁ d₁ + Rat.divInt n₂ d₂ = Rat.divInt (n₁ * d₂ + n₂ * d₁) (d₁ * d₂)
theorem
Rat.neg_normalize
(n : Int)
(d : Nat)
(z : d ≠ 0)
:
-Rat.normalize n d z = Rat.normalize (-n) d z
theorem
Rat.divInt_sub_divInt
(n₁ : Int)
(n₂ : Int)
{d₁ : Int}
{d₂ : Int}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.divInt n₁ d₁ - Rat.divInt n₂ d₂ = Rat.divInt (n₁ * d₂ - n₂ * d₁) (d₁ * d₂)
theorem
Rat.normalize_mul_normalize
(n₁ : Int)
(n₂ : Int)
{d₁ : Nat}
{d₂ : Nat}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.normalize n₁ d₁ z₁ * Rat.normalize n₂ d₂ z₂ = Rat.normalize (n₁ * n₂) (d₁ * d₂) ⋯
theorem
Rat.divInt_mul_divInt
(n₁ : Int)
(n₂ : Int)
{d₁ : Int}
{d₂ : Int}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.divInt n₁ d₁ * Rat.divInt n₂ d₂ = Rat.divInt (n₁ * n₂) (d₁ * d₂)
theorem
Rat.ofScientific_true_def
{m : Nat}
{e : Nat}
:
Rat.ofScientific m true e = mkRat (↑m) (10 ^ e)
The following lemmas are later subsumed by e.g. Int.cast_add
and Int.cast_mul
in Mathlib
but it is convenient to have these earlier, for users who only need Int
and Rat
.