Nonnegative rationals #
This file defines the nonnegative rationals as a subtype of Rat
and provides its basic algebraic
order structure.
Note that NNRat
is not declared as a Semifield
here. See Mathlib/Algebra/Field/Rat.lean
for
that instance.
We also define an instance CanLift ℚ ℚ≥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 occurrences
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 scope NNRat
.
Huge warning #
Whenever you state a lemma about the coercion ℚ≥0 → ℚ
, check that Lean inserts NNRat.cast
, not
Subtype.val
. Else your lemma will never apply.
It sometimes happens that a @[simp]
lemma declared early in the library can be proved by simp
using later, more general simp lemmas. In that case, the following reasons might be arguments for
the early lemma to be tagged @[simp high]
(rather than @[simp, nolint simpNF]
or
un@[simp]
ed):
- There is a significant portion of the library which needs the early lemma to be available via
simp
and which doesn't have access to the more general lemmas. - The more general lemmas have more complicated typeclass assumptions, causing rewrites with them to be slower.
Instances For
Equations
Equations
- instLinearOrderNNRat = Subtype.instLinearOrder fun (q : ℚ) => 0 ≤ q
Equations
- NNRat.instOrderBot = { bot := 0, bot_le := NNRat.instOrderBot._proof_1 }
Coercion ℚ≥0 → ℚ
as a RingHom
.
Equations
- NNRat.coeHom = { toFun := NNRat.cast, map_one' := NNRat.coe_one, map_mul' := NNRat.coe_mul, map_zero' := NNRat.coe_zero, map_add' := NNRat.coe_add }
Instances For
Alias of the reverse direction of Rat.toNNRat_eq_zero
.
Numerator and denominator #
Form the quotient n / d
where n d : ℕ
.
See also Rat.divInt
and mkRat
.
Equations
- NNRat.divNat n d = ⟨Rat.divInt ↑n ↑d, ⋯⟩
Instances For
Define a (dependent) function or prove ∀ r : ℚ, p r
by dealing with nonnegative rational
numbers of the form n / d
with d ≠ 0
and n
, d
coprime.
Equations
- q.numDenCasesOn H = ⋯.mpr (H q.num q.den ⋯ ⋯)