The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V02. Numbers

Mathlib.Data.Rat.Defs

61 declarations and 2 deprecated aliases. Mathlib docs · Source

Basics for the Rational Numbers

Summary

We define the integral domain structure on ℚ and prove basic lemmas about it. The definition of the field structure on ℚ will be done in Mathlib/Algebra/Field/Rat.lean once the Field class has been defined.

Main Definitions

  • Rat.divInt n d constructs a rational number q = n / d from n d : ℤ.

Notation

  • /. is infix notation for Rat.divInt.

The rational numbers are a group

theorem Rat.pos E1 #

∀ (a : ℚ), 0 < a.den

theorem Rat.mk'_num_den E1 #

∀ (q : ℚ), { num := q.num, den := q.den, den_nz := ⋯, reduced := ⋯ } = q

theorem Rat.ofInt_eq_cast E0 #

∀ (n : ℤ), Rat.ofInt n = ↑n

theorem Rat.intCast_injective E1 #

Function.Injective Int.cast

theorem Rat.natCast_injective E1 #

Function.Injective Nat.cast

theorem Rat.intCast_eq_one_iff E0 #

∀ {n : ℤ}, ↑n = 1 ↔ n = 1

theorem Rat.natCast_eq_one_iff E0 #

∀ {n : ℕ}, ↑n = 1 ↔ n = 1

theorem Rat.mkRat_eq_divInt E1 #

∀ (n : ℤ) (d : ℕ), mkRat n d = Rat.divInt n ↑d

theorem Rat.mk'_zero E0 #

∀ (d : ℕ) (h : d ≠ 0) (w : (Int.natAbs 0).Coprime d), { num := 0, den := d, den_nz := h, reduced := w } = 0

theorem Rat.num_ne_zero E1 #

∀ {q : ℚ}, q.num ≠ 0 ↔ q ≠ 0

theorem Rat.den_ne_zero E0 #

∀ (q : ℚ), q.den ≠ 0

theorem Rat.divInt_eq_zero E0 #

∀ {a b : ℤ}, b ≠ 0 → (Rat.divInt a b = 0 ↔ a = 0)

theorem Rat.divInt_ne_zero E1 #

∀ {a b : ℤ}, b ≠ 0 → (Rat.divInt a b ≠ 0 ↔ a ≠ 0)

theorem Rat.mkRat_num_den' E1 #

∀ (a : ℚ), mkRat a.num a.den = a

Alias of Rat.mkRat_self.

theorem Rat.intCast_eq_divInt E1 #

∀ (z : ℤ), ↑z = Rat.divInt z 1

theorem Rat.lift_binop_eq E0 #

∀ (f : ℚ → ℚ → ℚ) (f₁ f₂ : ℤ → ℤ → ℤ → ℤ → ℤ),
  (∀ {n₁ : ℤ} {d₁ : ℕ} {h₁ : d₁ ≠ 0} {c₁ : n₁.natAbs.Coprime d₁} {n₂ : ℤ} {d₂ : ℕ} {h₂ : d₂ ≠ 0}
      {c₂ : n₂.natAbs.Coprime d₂},
      f { num := n₁, den := d₁, den_nz := h₁, reduced := c₁ } { num := n₂, den := d₂, den_nz := h₂, reduced := c₂ } =
        Rat.divInt (f₁ n₁ (↑d₁) n₂ ↑d₂) (f₂ n₁ (↑d₁) n₂ ↑d₂)) →
    (∀ {n₁ d₁ n₂ d₂ : ℤ}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0) →
      ∀ (a b c d : ℤ),
        b ≠ 0 →
          d ≠ 0 →
            (∀ {n₁ d₁ n₂ d₂ : ℤ},
                a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) →
              f (Rat.divInt a b) (Rat.divInt c d) = Rat.divInt (f₁ a b c d) (f₂ a b c d)

theorem Rat.neg_def E0 #

∀ (q : ℚ), -q = Rat.divInt (-q.num) ↑q.den

theorem Rat.divInt_neg E0 #

∀ (n d : ℤ), Rat.divInt n (-d) = Rat.divInt (-n) d

theorem Rat.mk'_mul_mk' E1 #

∀ (n₁ n₂ : ℤ) (d₁ d₂ : ℕ) (hd₁ : d₁ ≠ 0) (hd₂ : d₂ ≠ 0) (hnd₁ : n₁.natAbs.Coprime d₁) (hnd₂ : n₂.natAbs.Coprime d₂)
  (h₁₂ : n₁.natAbs.Coprime d₂) (h₂₁ : n₂.natAbs.Coprime d₁),
  { num := n₁, den := d₁, den_nz := hd₁, reduced := hnd₁ } * { num := n₂, den := d₂, den_nz := hd₂, reduced := hnd₂ } =
    { num := n₁ * n₂, den := d₁ * d₂, den_nz := ⋯, reduced := ⋯ }

theorem Rat.mul_eq_mkRat E1 #

∀ (q r : ℚ), q * r = mkRat (q.num * r.num) (q.den * r.den)

theorem Rat.pow_eq_mkRat E1 #

∀ (q : ℚ) (n : ℕ), q ^ n = mkRat (q.num ^ n) (q.den ^ n)

theorem Rat.pow_eq_divInt E1 #

∀ (q : ℚ) (n : ℕ), q ^ n = Rat.divInt (q.num ^ n) (↑q.den ^ n)

theorem Rat.mk'_pow E0 #

∀ (num : ℤ) (den : ℕ) (hd : den ≠ 0) (hdn : num.natAbs.Coprime den) (n : ℕ),
  { num := num, den := den, den_nz := hd, reduced := hdn } ^ n =
    { num := num ^ n, den := den ^ n, den_nz := ⋯, reduced := ⋯ }

theorem Rat.inv_mkRat E0 #

∀ (a : ℤ) (b : ℕ), (mkRat a b)⁻¹ = Rat.divInt (↑b) a

theorem Rat.divInt_div_divInt E0 #

∀ (n₁ d₁ n₂ d₂ : ℤ), Rat.divInt n₁ d₁ / Rat.divInt n₂ d₂ = Rat.divInt (n₁ * d₂) (d₁ * n₂)

theorem Rat.div_def' E1 #

∀ (q r : ℚ), q / r = Rat.divInt (q.num * ↑r.den) (↑q.den * r.num)

theorem Rat.divInt_one E0 #

∀ (n : ℤ), Rat.divInt n 1 = ↑n

theorem Rat.divInt_one_one E1 #

Rat.divInt 1 1 = 1

theorem Rat.zero_ne_one E1 #

0 ≠ 1

instance Rat.nontrivial E0 #

Nontrivial ℚ

instance Rat.addCommGroup E0 #

AddCommGroup ℚ

instance Rat.addGroup E0 #

AddGroup ℚ

instance Rat.addCommMonoid E0 #

AddCommMonoid ℚ

instance Rat.addMonoid E0 #

AddMonoid ℚ

instance Rat.addLeftCancelSemigroup E0 #

AddLeftCancelSemigroup ℚ

instance Rat.addRightCancelSemigroup E0 #

AddRightCancelSemigroup ℚ

instance Rat.addCommSemigroup E0 #

AddCommSemigroup ℚ

instance Rat.addSemigroup E0 #

AddSemigroup ℚ

instance Rat.commMonoid E0 #

CommMonoid ℚ

instance Rat.monoid E0 #

Monoid ℚ

instance Rat.commSemigroup E0 #

CommSemigroup ℚ

instance Rat.semigroup E0 #

Semigroup ℚ

theorem Rat.den_neg_eq_den E0 #

∀ (q : ℚ), (-q).den = q.den

theorem Rat.num_neg_eq_neg_num E0 #

∀ (q : ℚ), (-q).num = -q.num

theorem Rat.num_zero E1 #

Rat.num 0 = 0

theorem Rat.den_zero E1 #

Rat.den 0 = 1

theorem Rat.zero_of_num_zero E1 #

∀ {q : ℚ}, q.num = 0 → q = 0

theorem Rat.zero_iff_num_zero E1 #

∀ {q : ℚ}, q = 0 ↔ q.num = 0

theorem Rat.num_one E1 #

Rat.num 1 = 1

theorem Rat.den_one E0 #

Rat.den 1 = 1

theorem Rat.mk_num_ne_zero_of_ne_zero E1 #

∀ {q : ℚ} {n d : ℤ}, q ≠ 0 → q = Rat.divInt n d → n ≠ 0

theorem Rat.mk_denom_ne_zero_of_ne_zero E1 #

∀ {q : ℚ} {n d : ℤ}, q ≠ 0 → q = Rat.divInt n d → d ≠ 0

theorem Rat.divInt_ne_zero_of_ne_zero E1 #

∀ {n d : ℤ}, n ≠ 0 → d ≠ 0 → Rat.divInt n d ≠ 0

theorem Rat.add_divInt E1 #

∀ (a b c : ℤ), Rat.divInt (a + b) c = Rat.divInt a c + Rat.divInt b c

theorem Rat.intCast_div_eq_divInt E1 #

∀ (n d : ℤ), ↑n / ↑d = Rat.divInt n d

theorem Rat.natCast_div_eq_divInt E1 #

∀ (n d : ℕ), ↑n / ↑d = Rat.divInt ↑n ↑d

theorem Rat.divInt_mul_divInt_cancel E1 #

∀ {x : ℤ}, x ≠ 0 → ∀ (n d : ℤ), Rat.divInt n x * Rat.divInt x d = Rat.divInt n d

theorem Rat.intCast_num_of_den_eq_one E1 #

∀ {q : ℚ}, q.den = 1 → ↑q.num = q

theorem Rat.den_eq_one_iff E0 #

∀ (r : ℚ), r.den = 1 ↔ ↑r.num = r

instance Rat.canLift E0 #

CanLift ℚ ℤ Int.cast fun q ↦ q.den = 1

def Rat.divCasesOn E1 #

{C : ℚ → Sort u_1} → (a : ℚ) → ((n : ℤ) → (d : ℕ) → d ≠ 0 → n.natAbs.Coprime d → C (↑n / ↑d)) → C a

A version of Rat.casesOn that uses / instead of Rat.mk'. Use as

cases r with
| div p q nonzero coprime =>

Deprecated aliases

NameNew nameSince
Rat.coe_int_injRat.intCast_inj2026-06-06
Rat.coe_int_num_of_den_eq_oneRat.intCast_num_of_den_eq_one2026-10-27