Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 24a233d

Browse files
committed
feat(algebra/order/positive): new file (#14833)
Define various algebraic structures on the set of positive numbers. I have two reasons to introduce these classes: - we can use `{x : ℝ // 0 < x}` in various filter bases; this may save us from explicit usage of `half_pos` or `div_pos` here or there; - I want to introduce a multiplicative action of `{x : ℝ // 0 < x}` on the upper half plane.
1 parent 7c4a46f commit 24a233d

File tree

3 files changed

+159
-35
lines changed

3 files changed

+159
-35
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/-
2+
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Yury Kudryashov
5+
-/
6+
import algebra.order.positive.ring
7+
import algebra.field_power
8+
9+
/-!
10+
# Algebraic structures on the set of positive numbers
11+
12+
In this file we prove that the set of positive elements of a linear ordered field is a linear
13+
ordered commutative group.
14+
-/
15+
16+
variables {K : Type*} [linear_ordered_field K]
17+
18+
namespace positive
19+
20+
instance : has_inv {x : K // 0 < x} := ⟨λ x, ⟨x⁻¹, inv_pos.2 x.2⟩⟩
21+
22+
@[simp] lemma coe_inv (x : {x : K // 0 < x}) : ↑x⁻¹ = (x⁻¹ : K) := rfl
23+
24+
instance : has_pow {x : K // 0 < x} ℤ :=
25+
⟨λ x n, ⟨x ^ n, zpow_pos_of_pos x.2 _⟩⟩
26+
27+
@[simp] lemma coe_zpow (x : {x : K // 0 < x}) (n : ℤ) : ↑(x ^ n) = (x ^ n : K) := rfl
28+
29+
instance : linear_ordered_comm_group {x : K // 0 < x} :=
30+
{ mul_left_inv := λ a, subtype.ext $ inv_mul_cancel a.2.ne',
31+
.. positive.subtype.has_inv, .. positive.subtype.linear_ordered_cancel_comm_monoid }
32+
33+
end positive
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/-
2+
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Yury Kudryashov
5+
-/
6+
import algebra.order.ring
7+
8+
/-!
9+
# Algebraic structures on the set of positive numbers
10+
11+
In this file we define various instances (`add_semigroup`, `ordered_comm_monoid` etc) on the
12+
type `{x : R // 0 < x}`. In each case we try to require the weakest possible typeclass
13+
assumptions on `R` but possibly, there is a room for improvements.
14+
-/
15+
open function
16+
17+
namespace positive
18+
19+
variables {M R K : Type*}
20+
21+
section add_basic
22+
23+
variables [add_monoid M] [preorder M] [covariant_class M M (+) (<)]
24+
25+
instance : has_add {x : M // 0 < x} := ⟨λ x y, ⟨x + y, add_pos x.2 y.2⟩⟩
26+
27+
@[simp, norm_cast] lemma coe_add (x y : {x : M // 0 < x}) : ↑(x + y) = (x + y : M) := rfl
28+
29+
instance : add_semigroup {x : M // 0 < x} := subtype.coe_injective.add_semigroup _ coe_add
30+
31+
instance {M : Type*} [add_comm_monoid M] [preorder M] [covariant_class M M (+) (<)] :
32+
add_comm_semigroup {x : M // 0 < x} :=
33+
subtype.coe_injective.add_comm_semigroup _ coe_add
34+
35+
instance {M : Type*} [add_left_cancel_monoid M] [preorder M] [covariant_class M M (+) (<)] :
36+
add_left_cancel_semigroup {x : M // 0 < x} :=
37+
subtype.coe_injective.add_left_cancel_semigroup _ coe_add
38+
39+
instance {M : Type*} [add_right_cancel_monoid M] [preorder M] [covariant_class M M (+) (<)] :
40+
add_right_cancel_semigroup {x : M // 0 < x} :=
41+
subtype.coe_injective.add_right_cancel_semigroup _ coe_add
42+
43+
instance covariant_class_add_lt : covariant_class {x : M // 0 < x} {x : M // 0 < x} (+) (<) :=
44+
⟨λ x y z hyz, subtype.coe_lt_coe.1 $ add_lt_add_left hyz _⟩
45+
46+
instance covariant_class_swap_add_lt [covariant_class M M (swap (+)) (<)] :
47+
covariant_class {x : M // 0 < x} {x : M // 0 < x} (swap (+)) (<) :=
48+
⟨λ x y z hyz, subtype.coe_lt_coe.1 $ add_lt_add_right hyz _⟩
49+
50+
instance contravariant_class_add_lt [contravariant_class M M (+) (<)] :
51+
contravariant_class {x : M // 0 < x} {x : M // 0 < x} (+) (<) :=
52+
⟨λ x y z h, subtype.coe_lt_coe.1 $ lt_of_add_lt_add_left h⟩
53+
54+
instance contravariant_class_swap_add_lt [contravariant_class M M (swap (+)) (<)] :
55+
contravariant_class {x : M // 0 < x} {x : M // 0 < x} (swap (+)) (<) :=
56+
⟨λ x y z h, subtype.coe_lt_coe.1 $ lt_of_add_lt_add_right h⟩
57+
58+
instance contravariant_class_add_le [contravariant_class M M (+) (≤)] :
59+
contravariant_class {x : M // 0 < x} {x : M // 0 < x} (+) (≤) :=
60+
⟨λ x y z h, subtype.coe_le_coe.1 $ le_of_add_le_add_left h⟩
61+
62+
instance contravariant_class_swap_add_le [contravariant_class M M (swap (+)) (≤)] :
63+
contravariant_class {x : M // 0 < x} {x : M // 0 < x} (swap (+)) (≤) :=
64+
⟨λ x y z h, subtype.coe_le_coe.1 $ le_of_add_le_add_right h⟩
65+
66+
end add_basic
67+
68+
instance covariant_class_add_le [add_monoid M] [partial_order M] [covariant_class M M (+) (<)] :
69+
covariant_class {x : M // 0 < x} {x : M // 0 < x} (+) (≤) :=
70+
⟨λ x, strict_mono.monotone $ λ _ _ h, add_lt_add_left h _⟩
71+
72+
section mul
73+
74+
variables [ordered_semiring R]
75+
76+
instance : has_mul {x : R // 0 < x} := ⟨λ x y, ⟨x * y, mul_pos x.2 y.2⟩⟩
77+
78+
@[simp] lemma coe_mul (x y : {x : R // 0 < x}) : ↑(x * y) = (x * y : R) := rfl
79+
80+
instance : has_pow {x : R // 0 < x} ℕ := ⟨λ x n, ⟨x ^ n, pow_pos x.2 n⟩⟩
81+
82+
@[simp] lemma coe_pow (x : {x : R // 0 < x}) (n : ℕ) : ↑(x ^ n) = (x ^ n : R) := rfl
83+
84+
instance : semigroup {x : R // 0 < x} := subtype.coe_injective.semigroup coe coe_mul
85+
86+
instance : distrib {x : R // 0 < x} := subtype.coe_injective.distrib _ coe_add coe_mul
87+
88+
instance [nontrivial R] : has_one {x : R // 0 < x} := ⟨⟨1, one_pos⟩⟩
89+
90+
@[simp] lemma coe_one [nontrivial R] : ((1 : {x : R // 0 < x}) : R) = 1 := rfl
91+
92+
instance [nontrivial R] : monoid {x : R // 0 < x} :=
93+
subtype.coe_injective.monoid _ coe_one coe_mul coe_pow
94+
95+
end mul
96+
97+
section mul_comm
98+
99+
instance [ordered_comm_semiring R] [nontrivial R] : ordered_comm_monoid {x : R // 0 < x} :=
100+
{ mul_le_mul_left := λ x y hxy c, subtype.coe_le_coe.1 $ mul_le_mul_of_nonneg_left hxy c.2.le,
101+
.. subtype.partial_order _,
102+
.. subtype.coe_injective.comm_monoid (coe : {x : R // 0 < x} → R) coe_one coe_mul coe_pow }
103+
104+
/-- If `R` is a nontrivial linear ordered commutative semiring, then `{x : R // 0 < x}` is a linear
105+
ordered cancellative commutative monoid. We don't have a typeclass for linear ordered commutative
106+
semirings, so we assume `[linear_ordered_semiring R] [is_commutative R (*)] instead. -/
107+
instance [linear_ordered_semiring R] [is_commutative R (*)] [nontrivial R] :
108+
linear_ordered_cancel_comm_monoid {x : R // 0 < x} :=
109+
{ mul_left_cancel := λ a b c h, subtype.ext $ (strict_mono_mul_left_of_pos a.2).injective $
110+
by convert congr_arg subtype.val h,
111+
le_of_mul_le_mul_left := λ a b c h, subtype.coe_le_coe.1 $ (mul_le_mul_left a.2).1 h,
112+
.. subtype.linear_order _,
113+
.. @positive.subtype.ordered_comm_monoid R
114+
{ mul_comm := is_commutative.comm, .. ‹linear_ordered_semiring R› } _ }
115+
116+
end mul_comm
117+
118+
end positive

src/data/pnat/basic.lean

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro, Neil Strickland
55
-/
66
import data.nat.basic
7+
import algebra.order.positive.ring
78

89
/-!
910
# The positive natural numbers
@@ -14,7 +15,8 @@ This file defines the type `ℕ+` or `pnat`, the subtype of natural numbers that
1415
/-- `ℕ+` is the type of positive natural numbers. It is defined as a subtype,
1516
and the VM representation of `ℕ+` is the same as `ℕ` because the proof
1617
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]]
1820
def pnat := {n : ℕ // 0 < n}
1921
notation `ℕ+` := pnat
2022

@@ -100,8 +102,6 @@ open nat
100102
subtraction, division and powers.
101103
-/
102104

103-
instance : decidable_eq ℕ+ := λ (a b : ℕ+), by apply_instance
104-
105105
@[simp] lemma mk_le_mk (n k : ℕ) (hn : 0 < n) (hk : 0 < k) :
106106
(⟨n, hn⟩ : ℕ+) ≤ ⟨k, hk⟩ ↔ n ≤ k := iff.rfl
107107

@@ -125,22 +125,17 @@ lemma coe_injective : function.injective (coe : ℕ+ → ℕ) := subtype.coe_inj
125125

126126
@[simp] theorem mk_coe (n h) : ((⟨n, h⟩ : ℕ+) : ℕ) = n := rfl
127127

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-
132128
@[simp] theorem add_coe (m n : ℕ+) : ((m + n : ℕ+) : ℕ) = m + n := rfl
133129

134130
/-- `pnat.coe` promoted to an `add_hom`, that is, a morphism which preserves addition. -/
135131
def coe_add_hom : add_hom ℕ+ ℕ :=
136132
{ to_fun := coe,
137133
map_add' := add_coe }
138134

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
144139

145140
/-- An equivalence between `ℕ+` and `ℕ` given by `pnat.nat_pred` and `nat.succ_pnat`. -/
146141
@[simps { fully_applied := ff }] def _root_.equiv.pnat_equiv_nat : ℕ+ ≃ ℕ :=
@@ -157,22 +152,12 @@ coe_injective.add_right_cancel_semigroup coe (λ _ _, rfl)
157152
@[simp] lemma _root_.order_iso.pnat_iso_nat_symm_apply :
158153
⇑order_iso.pnat_iso_nat.symm = nat.succ_pnat := rfl
159154

160-
@[priority 10]
161-
instance : covariant_class ℕ+ ℕ+ ((+)) (≤) :=
162-
by { rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, simp [←pnat.coe_le_coe] }⟩
163-
164155
@[simp] theorem ne_zero (n : ℕ+) : (n : ℕ) ≠ 0 := n.2.ne'
165156

166157
theorem to_pnat'_coe {n : ℕ} : 0 < n → (n.to_pnat' : ℕ) = n := succ_pred_eq_of_pos
167158

168159
@[simp] theorem coe_to_pnat' (n : ℕ+) : (n : ℕ).to_pnat' = n := eq (to_pnat'_coe n.pos)
169160

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-
176161
theorem lt_add_one_iff : ∀ {a b : ℕ+}, a < b + 1 ↔ a ≤ b :=
177162
λ a b, nat.lt_add_one_iff
178163

@@ -223,8 +208,7 @@ def coe_monoid_hom : ℕ+ →* ℕ :=
223208

224209
@[simp] lemma coe_coe_monoid_hom : (coe_monoid_hom : ℕ+ → ℕ) = coe := rfl
225210

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
228212

229213
@[simp] lemma le_one_iff {n : ℕ+} : n ≤ 1 ↔ n = 1 := le_bot_iff
230214

@@ -238,17 +222,6 @@ lemma lt_add_right (n m : ℕ+) : n < n + m := (lt_add_left n m).trans_eq (add_c
238222
@[simp] theorem pow_coe (m : ℕ+) (n : ℕ) : ((m ^ n : ℕ+) : ℕ) = (m : ℕ) ^ n :=
239223
rfl
240224

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-
252225
/-- Subtraction a - b is defined in the obvious way when
253226
a > b, and by a - b = 1 if a ≤ b.
254227
-/

0 commit comments

Comments
 (0)