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 Field
here. See Data.NNRat.Lemmas
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
Reinterpret a rational number q
as a non-negative rational number. Returns 0
if q ≤ 0
.
Equations
- Rat.toNNRat q = { val := max q 0, property := ⋯ }
Instances For
Coercion ℚ≥0 → ℚ
as a RingHom
.
Equations
- NNRat.coeHom = { toMonoidHom := { toOneHom := { 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 = { val := Rat.divInt ↑n ↑d, property := ⋯ }
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
- NNRat.numDenCasesOn q H = Eq.mpr ⋯ (H q.num q.den ⋯ ⋯)