@@ -3,8 +3,7 @@ Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
3
3
Released under Apache 2.0 license as described in the file LICENSE.
4
4
Authors: Yaël Dillies, Bhavik Mehta
5
5
-/
6
- import Mathlib.Algebra.Function.Indicator
7
- import Mathlib.Algebra.Order.Nonneg.Field
6
+ import Mathlib.Algebra.Order.Nonneg.Ring
8
7
import Mathlib.Data.Int.Lemmas
9
8
import Mathlib.Data.Rat.Order
10
9
@@ -13,8 +12,10 @@ import Mathlib.Data.Rat.Order
13
12
/-!
14
13
# Nonnegative rationals
15
14
16
- This file defines the nonnegative rationals as a subtype of `Rat` and provides its algebraic order
17
- structure.
15
+ This file defines the nonnegative rationals as a subtype of `Rat` and provides its basic algebraic
16
+ order structure.
17
+
18
+ Note that `NNRat` is not declared as a `Field` here. See `Data.NNRat.Lemmas` for that instance.
18
19
19
20
We also define an instance `CanLift ℚ ℚ≥0`. This instance can be used by the `lift` tactic to
20
21
replace `x : ℚ` and `hx : 0 ≤ x` in the proof context with `x : ℚ≥0` while replacing all occurrences
@@ -31,14 +32,12 @@ open Function
31
32
32
33
/-- Nonnegative rational numbers. -/
33
34
def NNRat := { q : ℚ // 0 ≤ q } deriving
34
- CanonicallyOrderedCommSemiring, CanonicallyLinearOrderedSemifield, LinearOrderedCommGroupWithZero,
35
- Sub, Inhabited
35
+ CanonicallyOrderedCommSemiring, CanonicallyLinearOrderedAddCommMonoid, Sub, Inhabited
36
36
#align nnrat NNRat
37
37
38
38
-- Porting note: Added these instances to get `OrderedSub, DenselyOrdered, Archimedean`
39
39
-- instead of `deriving` them
40
40
instance : OrderedSub NNRat := Nonneg.orderedSub
41
- instance : DenselyOrdered NNRat := Nonneg.densely_ordered
42
41
43
42
-- mathport name: nnrat
44
43
scoped [NNRat] notation "ℚ≥0" => NNRat
@@ -47,8 +46,7 @@ namespace NNRat
47
46
48
47
variable {α : Type *} {p q : ℚ≥0 }
49
48
50
- instance : Coe ℚ≥0 ℚ :=
51
- ⟨Subtype.val⟩
49
+ instance instCoe : Coe ℚ≥0 ℚ := ⟨Subtype.val⟩
52
50
53
51
/-
54
52
-- Simp lemma to put back `n.val` into the normal form given by the coercion.
@@ -130,16 +128,6 @@ theorem coe_mul (p q : ℚ≥0) : ((p * q : ℚ≥0) : ℚ) = p * q :=
130
128
rfl
131
129
#align nnrat.coe_mul NNRat.coe_mul
132
130
133
- @[simp, norm_cast]
134
- theorem coe_inv (q : ℚ≥0 ) : ((q⁻¹ : ℚ≥0 ) : ℚ) = (q : ℚ)⁻¹ :=
135
- rfl
136
- #align nnrat.coe_inv NNRat.coe_inv
137
-
138
- @[simp, norm_cast]
139
- theorem coe_div (p q : ℚ≥0 ) : ((p / q : ℚ≥0 ) : ℚ) = p / q :=
140
- rfl
141
- #align nnrat.coe_div NNRat.coe_div
142
-
143
131
-- Porting note: `bit0` `bit1` are deprecated, so remove these theorems.
144
132
#noalign nnrat.coe_bit0
145
133
#noalign nnrat.coe_bit1
@@ -214,25 +202,11 @@ theorem mk_coe_nat (n : ℕ) : @Eq ℚ≥0 (⟨(n : ℚ), n.cast_nonneg⟩ : ℚ
214
202
ext (coe_natCast n).symm
215
203
#align nnrat.mk_coe_nat NNRat.mk_coe_nat
216
204
217
- /-- A `MulAction` over `ℚ` restricts to a `MulAction` over `ℚ≥0`. -/
218
- instance [MulAction ℚ α] : MulAction ℚ≥0 α :=
219
- MulAction.compHom α coeHom.toMonoidHom
220
-
221
- /-- A `DistribMulAction` over `ℚ` restricts to a `DistribMulAction` over `ℚ≥0`. -/
222
- instance [AddCommMonoid α] [DistribMulAction ℚ α] : DistribMulAction ℚ≥0 α :=
223
- DistribMulAction.compHom α coeHom.toMonoidHom
224
-
225
205
@[simp]
226
206
theorem coe_coeHom : ⇑coeHom = ((↑) : ℚ≥0 → ℚ) :=
227
207
rfl
228
208
#align nnrat.coe_coe_hom NNRat.coe_coeHom
229
209
230
- @[simp, norm_cast]
231
- theorem coe_indicator (s : Set α) (f : α → ℚ≥0 ) (a : α) :
232
- ((s.indicator f a : ℚ≥0 ) : ℚ) = s.indicator (fun x ↦ ↑(f x)) a :=
233
- (coeHom : ℚ≥0 →+ ℚ).map_indicator _ _ _
234
- #align nnrat.coe_indicator NNRat.coe_indicator
235
-
236
210
@[simp, norm_cast]
237
211
theorem coe_pow (q : ℚ≥0 ) (n : ℕ) : (↑(q ^ n) : ℚ) = (q : ℚ) ^ n :=
238
212
coeHom.map_pow _ _
@@ -359,21 +333,6 @@ theorem toNNRat_mul (hp : 0 ≤ p) : toNNRat (p * q) = toNNRat p * toNNRat q :=
359
333
rw [toNNRat_eq_zero.2 hq, toNNRat_eq_zero.2 hpq, mul_zero]
360
334
#align rat.to_nnrat_mul Rat.toNNRat_mul
361
335
362
- theorem toNNRat_inv (q : ℚ) : toNNRat q⁻¹ = (toNNRat q)⁻¹ := by
363
- obtain hq | hq := le_total q 0
364
- · rw [toNNRat_eq_zero.mpr hq, inv_zero, toNNRat_eq_zero.mpr (inv_nonpos.mpr hq)]
365
- · nth_rw 1 [← Rat.coe_toNNRat q hq]
366
- rw [← coe_inv, toNNRat_coe]
367
- #align rat.to_nnrat_inv Rat.toNNRat_inv
368
-
369
- theorem toNNRat_div (hp : 0 ≤ p) : toNNRat (p / q) = toNNRat p / toNNRat q := by
370
- rw [div_eq_mul_inv, div_eq_mul_inv, ← toNNRat_inv, ← toNNRat_mul hp]
371
- #align rat.to_nnrat_div Rat.toNNRat_div
372
-
373
- theorem toNNRat_div' (hq : 0 ≤ q) : toNNRat (p / q) = toNNRat p / toNNRat q := by
374
- rw [div_eq_inv_mul, div_eq_inv_mul, toNNRat_mul (inv_nonneg.2 hq), toNNRat_inv]
375
- #align rat.to_nnrat_div' Rat.toNNRat_div'
376
-
377
336
end Rat
378
337
379
338
/-- The absolute value on `ℚ` as a map to `ℚ≥0`. -/
@@ -430,18 +389,7 @@ theorem ext_num_den_iff : p = q ↔ p.num = q.num ∧ p.den = q.den :=
430
389
⟨by rintro rfl; exact ⟨rfl, rfl⟩, fun h ↦ ext_num_den h.1 h.2 ⟩
431
390
#align nnrat.ext_num_denom_iff NNRat.ext_num_den_iff
432
391
433
- @[simp]
434
- theorem num_div_den (q : ℚ≥0 ) : (q.num : ℚ≥0 ) / q.den = q := by
435
- ext1
436
- rw [coe_div, coe_natCast, coe_natCast, num, ← Int.cast_ofNat,
437
- Int.natAbs_of_nonneg (Rat.num_nonneg_iff_zero_le.2 q.prop)]
438
- exact Rat.num_div_den q
439
- #align nnrat.num_div_denom NNRat.num_div_den
440
-
441
- /-- A recursor for nonnegative rationals in terms of numerators and denominators. -/
442
- protected def rec {α : ℚ≥0 → Sort *} (h : ∀ m n : ℕ, α (m / n)) (q : ℚ≥0 ) : α q := by
443
- rw [← num_div_den q]
444
- apply h
445
- #align nnrat.rec NNRat.rec
446
-
447
392
end NNRat
393
+
394
+ -- `NNRat` needs to be available in the definition of `Field`
395
+ assert_not_exists Field
0 commit comments