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
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 locale 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.
Equations
- instNNRatCommSemiring = Nonneg.commSemiring
Equations
- instNNRatLinearOrder = Subtype.instLinearOrder fun (q : ℚ) => 0 ≤ q
Equations
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 NNRat.mk_natCast
.
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 ⋯ ⋯)