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
@[simp]
theorem
Rat.maybeNormalize_eq
{num : Int}
{den g : Nat}
(den_nz : den / g ≠ 0)
(reduced : (num.tdiv ↑g).natAbs.Coprime (den / g))
:
Rat.maybeNormalize num den g den_nz reduced = { num := num.tdiv ↑g, den := den / g, den_nz := den_nz, reduced := reduced }
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₁ d₂ : Nat}
{n₁ 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 g : Nat}
(den_nz : den / g ≠ 0)
(reduced : (num.tdiv ↑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₁ d₂ n₁ n₂ : Int}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.divInt n₁ d₁ = Rat.divInt n₂ d₂ ↔ n₁ * d₂ = n₂ * d₁
theorem
Rat.divInt_mul_right
{n d a : Int}
(a0 : a ≠ 0)
:
Rat.divInt (n * a) (d * a) = Rat.divInt n d
theorem
Rat.normalize_add_normalize
(n₁ n₂ : Int)
{d₁ 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₁ n₂ : Int)
{d₁ 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₁ n₂ : Int)
{d₁ 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₁ n₂ : Int)
{d₁ 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₁ n₂ : Int)
{d₁ d₂ : Int}
(z₁ : d₁ ≠ 0)
(z₂ : d₂ ≠ 0)
:
Rat.divInt n₁ d₁ * Rat.divInt n₂ d₂ = Rat.divInt (n₁ * n₂) (d₁ * d₂)
@[simp]
theorem
Rat.ofScientific_ofNat_ofNat
{m : Nat}
{s : Bool}
{e : Nat}
:
Rat.ofScientific (OfNat.ofNat m) s (OfNat.ofNat e) = OfScientific.ofScientific m s e
Rat.ofScientific
applied to numeric literals is the same as a scientific literal.
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
.