@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
4
4
Authors: Mario Carneiro, Neil Strickland
5
5
-/
6
6
import data.nat.basic
7
+ import algebra.order.positive.ring
7
8
8
9
/-!
9
10
# The positive natural numbers
@@ -14,7 +15,8 @@ This file defines the type `ℕ+` or `pnat`, the subtype of natural numbers that
14
15
/-- `ℕ+` is the type of positive natural numbers. It is defined as a subtype,
15
16
and the VM representation of `ℕ+` is the same as `ℕ` because the proof
16
17
is not stored. -/
17
- @[derive linear_order]
18
+ @[derive [decidable_eq, add_left_cancel_semigroup, add_right_cancel_semigroup, add_comm_semigroup,
19
+ linear_ordered_cancel_comm_monoid, linear_order, has_add, has_mul, has_one, distrib] ]
18
20
def pnat := {n : ℕ // 0 < n}
19
21
notation `ℕ +` := pnat
20
22
@@ -100,8 +102,6 @@ open nat
100
102
subtraction, division and powers.
101
103
-/
102
104
103
- instance : decidable_eq ℕ+ := λ (a b : ℕ+), by apply_instance
104
-
105
105
@[simp] lemma mk_le_mk (n k : ℕ) (hn : 0 < n) (hk : 0 < k) :
106
106
(⟨n, hn⟩ : ℕ+) ≤ ⟨k, hk⟩ ↔ n ≤ k := iff.rfl
107
107
@@ -125,22 +125,17 @@ lemma coe_injective : function.injective (coe : ℕ+ → ℕ) := subtype.coe_inj
125
125
126
126
@[simp] theorem mk_coe (n h) : ((⟨n, h⟩ : ℕ+) : ℕ) = n := rfl
127
127
128
- instance : has_add ℕ+ := ⟨λ a b, ⟨(a + b : ℕ), add_pos a.pos b.pos⟩⟩
129
-
130
- instance : add_comm_semigroup ℕ+ := coe_injective.add_comm_semigroup coe (λ _ _, rfl)
131
-
132
128
@[simp] theorem add_coe (m n : ℕ+) : ((m + n : ℕ+) : ℕ) = m + n := rfl
133
129
134
130
/-- `pnat.coe` promoted to an `add_hom`, that is, a morphism which preserves addition. -/
135
131
def coe_add_hom : add_hom ℕ+ ℕ :=
136
132
{ to_fun := coe,
137
133
map_add' := add_coe }
138
134
139
- instance : add_left_cancel_semigroup ℕ+ :=
140
- coe_injective.add_left_cancel_semigroup coe (λ _ _, rfl)
141
-
142
- instance : add_right_cancel_semigroup ℕ+ :=
143
- coe_injective.add_right_cancel_semigroup coe (λ _ _, rfl)
135
+ instance : covariant_class ℕ+ ℕ+ (+) (≤) := positive.covariant_class_add_le
136
+ instance : covariant_class ℕ+ ℕ+ (+) (<) := positive.covariant_class_add_lt
137
+ instance : contravariant_class ℕ+ ℕ+ (+) (≤) := positive.contravariant_class_add_le
138
+ instance : contravariant_class ℕ+ ℕ+ (+) (<) := positive.contravariant_class_add_lt
144
139
145
140
/-- An equivalence between `ℕ+` and `ℕ` given by `pnat.nat_pred` and `nat.succ_pnat`. -/
146
141
@[simps { fully_applied := ff }] def _root_.equiv.pnat_equiv_nat : ℕ+ ≃ ℕ :=
@@ -157,22 +152,12 @@ coe_injective.add_right_cancel_semigroup coe (λ _ _, rfl)
157
152
@[simp] lemma _root_.order_iso.pnat_iso_nat_symm_apply :
158
153
⇑order_iso.pnat_iso_nat.symm = nat.succ_pnat := rfl
159
154
160
- @[priority 10 ]
161
- instance : covariant_class ℕ+ ℕ+ ((+)) (≤) :=
162
- ⟨by { rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, simp [←pnat.coe_le_coe] }⟩
163
-
164
155
@[simp] theorem ne_zero (n : ℕ+) : (n : ℕ) ≠ 0 := n.2 .ne'
165
156
166
157
theorem to_pnat'_coe {n : ℕ} : 0 < n → (n.to_pnat' : ℕ) = n := succ_pred_eq_of_pos
167
158
168
159
@[simp] theorem coe_to_pnat' (n : ℕ+) : (n : ℕ).to_pnat' = n := eq (to_pnat'_coe n.pos)
169
160
170
- instance : has_mul ℕ+ := ⟨λ m n, ⟨m.1 * n.1 , mul_pos m.2 n.2 ⟩⟩
171
- instance : has_one ℕ+ := ⟨succ_pnat 0 ⟩
172
- instance : has_pow ℕ+ ℕ := ⟨λ x n, ⟨x ^ n, pow_pos x.2 n⟩⟩
173
-
174
- instance : comm_monoid ℕ+ := coe_injective.comm_monoid coe rfl (λ _ _, rfl) (λ _ _, rfl)
175
-
176
161
theorem lt_add_one_iff : ∀ {a b : ℕ+}, a < b + 1 ↔ a ≤ b :=
177
162
λ a b, nat.lt_add_one_iff
178
163
@@ -223,8 +208,7 @@ def coe_monoid_hom : ℕ+ →* ℕ :=
223
208
224
209
@[simp] lemma coe_coe_monoid_hom : (coe_monoid_hom : ℕ+ → ℕ) = coe := rfl
225
210
226
- @[simp]
227
- lemma coe_eq_one_iff {m : ℕ+} : (m : ℕ) = 1 ↔ m = 1 := by rw [← one_coe, coe_inj]
211
+ @[simp] lemma coe_eq_one_iff {m : ℕ+} : (m : ℕ) = 1 ↔ m = 1 := subtype.coe_injective.eq_iff' one_coe
228
212
229
213
@[simp] lemma le_one_iff {n : ℕ+} : n ≤ 1 ↔ n = 1 := le_bot_iff
230
214
@@ -238,17 +222,6 @@ lemma lt_add_right (n m : ℕ+) : n < n + m := (lt_add_left n m).trans_eq (add_c
238
222
@[simp] theorem pow_coe (m : ℕ+) (n : ℕ) : ((m ^ n : ℕ+) : ℕ) = (m : ℕ) ^ n :=
239
223
rfl
240
224
241
- instance : ordered_cancel_comm_monoid ℕ+ :=
242
- { mul_le_mul_left := by { intros, apply nat.mul_le_mul_left, assumption },
243
- le_of_mul_le_mul_left := by { intros a b c h, apply nat.le_of_mul_le_mul_left h a.property, },
244
- mul_left_cancel := λ a b c h, by
245
- { replace h := congr_arg (coe : ℕ+ → ℕ) h,
246
- exact eq ((nat.mul_right_inj a.pos).mp h)},
247
- .. pnat.comm_monoid,
248
- .. pnat.linear_order }
249
-
250
- instance : distrib ℕ+ := coe_injective.distrib coe (λ _ _, rfl) (λ _ _, rfl)
251
-
252
225
/-- Subtraction a - b is defined in the obvious way when
253
226
a > b, and by a - b = 1 if a ≤ b.
254
227
-/
0 commit comments