mathlib documentation

data.rat.nnrat

Nonnegative rationals #

This file defines the nonnegative rationals as a subtype of rat and provides its algebraic order structure.

We also define an instance can_lift ℚ ℚ≥0. This instance can be used by the lift tactic to replace x : ℚ and hx : 0 ≤ x in the proof context with x : ℚ≥0 while replacing all occurences of x with ↑x. This tactic also works for a function f : α → ℚ with a hypothesis hf : ∀ x, 0 ≤ f x.

Notation #

ℚ≥0 is notation for nnrat in locale nnrat.

@[protected, instance]
@[protected, instance]
@[protected, instance]
@[protected, instance]
@[protected, instance]
@[protected, instance]
Equations
@[simp]
theorem nnrat.val_eq_coe (q : nnrat) :
q.val = ↑q
@[protected, instance]
Equations
@[ext]
theorem nnrat.ext {p q : nnrat} :
↑p = ↑q → p = q
@[simp, norm_cast]
theorem nnrat.coe_inj {p q : nnrat} :
↑p = ↑q ↔ p = q
theorem nnrat.ext_iff {p q : nnrat} :
p = q ↔ ↑p = ↑q
theorem nnrat.ne_iff {x y : nnrat} :
↑x ≠ ↑y ↔ x ≠ y
@[norm_cast]
theorem nnrat.coe_mk (q : ℚ) (hq : 0 ≤ q) :
↑⟨q, hq⟩ = q
def rat.to_nnrat (q : ℚ) :

Reinterpret a rational number q as a non-negative rational number. Returns 0 if q ≤ 0.

Equations
theorem rat.coe_to_nnrat (q : ℚ) (hq : 0 ≤ q) :
theorem rat.le_coe_to_nnrat (q : ℚ) :
@[simp]
theorem nnrat.coe_nonneg (q : nnrat) :
0 ≤ ↑q
@[simp, norm_cast]
theorem nnrat.coe_zero  :
↑0 = 0
@[simp, norm_cast]
theorem nnrat.coe_one  :
↑1 = 1
@[simp, norm_cast]
theorem nnrat.coe_add (p q : nnrat) :
↑(p + q) = ↑p + ↑q
@[simp, norm_cast]
theorem nnrat.coe_mul (p q : nnrat) :
↑(p * q) = ↑p * ↑q
@[simp, norm_cast]
theorem nnrat.coe_inv (q : nnrat) :
@[simp, norm_cast]
theorem nnrat.coe_div (p q : nnrat) :
↑(p / q) = ↑p / ↑q
@[simp, norm_cast]
theorem nnrat.coe_bit0 (q : nnrat) :
@[simp, norm_cast]
theorem nnrat.coe_bit1 (q : nnrat) :
@[simp, norm_cast]
theorem nnrat.coe_sub {p q : nnrat} (h : q ≤ p) :
↑(p - q) = ↑p - ↑q
@[simp]
theorem nnrat.coe_eq_zero {q : nnrat} :
↑q = 0 ↔ q = 0
theorem nnrat.coe_ne_zero {q : nnrat} :
↑q ≠ 0 ↔ q ≠ 0
@[simp, norm_cast]
theorem nnrat.coe_le_coe {p q : nnrat} :
↑p ≤ ↑q ↔ p ≤ q
@[simp, norm_cast]
theorem nnrat.coe_lt_coe {p q : nnrat} :
↑p < ↑q ↔ p < q
@[simp, norm_cast]
theorem nnrat.coe_pos {q : nnrat} :
0 < ↑q ↔ 0 < q
@[simp]
theorem nnrat.to_nnrat_coe (q : nnrat) :
@[simp]
@[simp, norm_cast]
theorem nnrat.coe_nat_cast (n : ℕ) :
@[simp]
theorem nnrat.mk_coe_nat (n : ℕ) :
⟨↑n, _⟩ = ↑n
@[protected, instance]

The rational numbers are an algebra over the non-negative rationals.

Equations
@[protected, instance]
def nnrat.mul_action {α : Type u_1} [mul_action ℚ α] :

A mul_action over ℚ restricts to a mul_action over ℚ≥0.

Equations
@[protected, instance]
def nnrat.module {α : Type u_1} [add_comm_monoid α] [module ℚ α] :

A module over ℚ restricts to a module over ℚ≥0.

Equations
@[simp, norm_cast]
theorem nnrat.coe_indicator {α : Type u_1} (s : set α) (f : α → nnrat) (a : α) :
↑(s.indicator f a) = s.indicator (λ (x : α), ↑(f x)) a
@[simp, norm_cast]
theorem nnrat.coe_pow (q : nnrat) (n : ℕ) :
↑(q ^ n) = ↑q ^ n
@[norm_cast]
theorem nnrat.coe_list_sum (l : list nnrat) :
@[norm_cast]
theorem nnrat.coe_list_prod (l : list nnrat) :
@[norm_cast]
@[norm_cast]
@[norm_cast]
theorem nnrat.coe_sum {α : Type u_1} {s : finset α} {f : α → nnrat} :
↑(s.sum (λ (a : α), f a)) = s.sum (λ (a : α), ↑(f a))
theorem nnrat.to_nnrat_sum_of_nonneg {α : Type u_1} {s : finset α} {f : α → ℚ} (hf : ∀ (a : α), a ∈ s → 0 ≤ f a) :
(s.sum (λ (a : α), f a)).to_nnrat = s.sum (λ (a : α), (f a).to_nnrat)
@[norm_cast]
theorem nnrat.coe_prod {α : Type u_1} {s : finset α} {f : α → nnrat} :
↑(s.prod (λ (a : α), f a)) = s.prod (λ (a : α), ↑(f a))
theorem nnrat.to_nnrat_prod_of_nonneg {α : Type u_1} {s : finset α} {f : α → ℚ} (hf : ∀ (a : α), a ∈ s → 0 ≤ f a) :
(s.prod (λ (a : α), f a)).to_nnrat = s.prod (λ (a : α), (f a).to_nnrat)
@[norm_cast]
theorem nnrat.nsmul_coe (q : nnrat) (n : ℕ) :
↑(n • q) = n • ↑q
@[simp, norm_cast]
@[simp, norm_cast]
theorem nnrat.sub_def (p q : nnrat) :
p - q = (↑p - ↑q).to_nnrat
@[simp]
theorem nnrat.abs_coe (q : nnrat) :
@[simp]
theorem rat.to_nnrat_zero  :
@[simp]
theorem rat.to_nnrat_one  :
@[simp]
theorem rat.to_nnrat_pos {q : ℚ} :
0 < q.to_nnrat ↔ 0 < q
@[simp]
theorem rat.to_nnrat_eq_zero {q : ℚ} :
q.to_nnrat = 0 ↔ q ≤ 0
theorem rat.to_nnrat_of_nonpos {q : ℚ} :
q ≤ 0 → q.to_nnrat = 0

Alias of the reverse direction of rat.to_nnrat_eq_zero.

@[simp]
theorem rat.to_nnrat_le_to_nnrat_iff {p q : ℚ} (hp : 0 ≤ p) :
@[simp]
theorem rat.to_nnrat_lt_to_nnrat_iff' {p q : ℚ} :
q.to_nnrat < p.to_nnrat ↔ q < p ∧ 0 < p
theorem rat.to_nnrat_lt_to_nnrat_iff {p q : ℚ} (h : 0 < p) :
theorem rat.to_nnrat_lt_to_nnrat_iff_of_nonneg {p q : ℚ} (hq : 0 ≤ q) :
@[simp]
theorem rat.to_nnrat_add {p q : ℚ} (hq : 0 ≤ q) (hp : 0 ≤ p) :
theorem rat.to_nnrat_add_le {p q : ℚ} :
theorem rat.to_nnrat_le_iff_le_coe {q : ℚ} {p : nnrat} :
theorem rat.le_to_nnrat_iff_coe_le {p : ℚ} {q : nnrat} (hp : 0 ≤ p) :
theorem rat.le_to_nnrat_iff_coe_le' {p : ℚ} {q : nnrat} (hq : 0 < q) :
theorem rat.to_nnrat_lt_iff_lt_coe {q : ℚ} {p : nnrat} (hq : 0 ≤ q) :
q.to_nnrat < p ↔ q < ↑p
theorem rat.lt_to_nnrat_iff_coe_lt {p : ℚ} {q : nnrat} :
q < p.to_nnrat ↔ ↑q < p
@[simp]
theorem rat.to_nnrat_bit0 {q : ℚ} (hq : 0 ≤ q) :
@[simp]
theorem rat.to_nnrat_bit1 {q : ℚ} (hq : 0 ≤ q) :
theorem rat.to_nnrat_mul {p q : ℚ} (hp : 0 ≤ p) :
theorem rat.to_nnrat_div {p q : ℚ} (hp : 0 ≤ p) :
theorem rat.to_nnrat_div' {p q : ℚ} (hq : 0 ≤ q) :
def rat.nnabs (x : ℚ) :

The absolute value on ℚ as a map to ℚ≥0.

Equations
@[simp, norm_cast]
theorem rat.coe_nnabs (x : ℚ) :

Numerator and denominator #

def nnrat.num (q : nnrat) :

The numerator of a nonnegative rational.

Equations
def nnrat.denom (q : nnrat) :

The denominator of a nonnegative rational.

Equations
@[simp]
@[simp]
theorem nnrat.denom_coe {q : nnrat} :
theorem nnrat.ext_num_denom {p q : nnrat} (hn : p.num = q.num) (hd : p.denom = q.denom) :
p = q
theorem nnrat.ext_num_denom_iff {p q : nnrat} :
p = q ↔ p.num = q.num ∧ p.denom = q.denom
@[simp]
theorem nnrat.num_div_denom (q : nnrat) :
↑(q.num) / ↑(q.denom) = q
@[protected]
def nnrat.rec {α : nnrat → Sort u_1} (h : Π (m n : ℕ), α (↑m / ↑n)) (q : nnrat) :
α q

A recursor for nonnegative rationals in terms of numerators and denominators.

Equations