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

Commit 9f33b7d

Browse files
committed
feat(algebra/ordered_*): arithmetic operations on monotone functions (#2634)
Also move `strict_mono` to `order/basic` and add a module docstring.
1 parent d04429f commit 9f33b7d

File tree

5 files changed

+212
-77
lines changed

5 files changed

+212
-77
lines changed

src/algebra/order_functions.lean

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2017 Mario Carneiro. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro
55
-/
6-
import algebra.ordered_group
6+
import algebra.ordered_ring
77

88
/-!
99
# strictly monotone functions, max, min and abs
@@ -12,81 +12,16 @@ This file proves basic properties about strictly monotone functions,
1212
maxima and minima on a `decidable_linear_order`, and the absolute value
1313
function on linearly ordered add_comm_groups, semirings and rings.
1414
15-
One useful result proved here is that if `f : ℕ → α` and `f n < f (n + 1)` for all `n`
16-
then f is strictly monotone (see `strict_mono.nat`).
17-
18-
## Definition
19-
20-
`strict_mono f` : a function between two types equipped with `<` is strictly monotone
21-
if `a < b` implies `f a < f b`.
22-
2315
## Tags
2416
25-
monotone, strictly monotone, min, max, abs
17+
min, max, abs
2618
-/
2719

2820
universes u v
2921
variables {α : Type u} {β : Type v}
3022

3123
attribute [simp] max_eq_left max_eq_right min_eq_left min_eq_right
3224

33-
/-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/
34-
def strict_mono [has_lt α] [has_lt β] (f : α → β) : Prop :=
35-
∀ ⦃a b⦄, a < b → f a < f b
36-
37-
namespace strict_mono
38-
open ordering function
39-
40-
section
41-
variables [linear_order α] [preorder β] {f : α → β}
42-
43-
lemma lt_iff_lt (H : strict_mono f) {a b} :
44-
f a < f b ↔ a < b :=
45-
⟨λ h, ((lt_trichotomy b a)
46-
.resolve_left $ λ h', lt_asymm h $ H h')
47-
.resolve_left $ λ e, ne_of_gt h $ congr_arg _ e, @H _ _⟩
48-
49-
lemma injective (H : strict_mono f) : injective f
50-
| a b e := ((lt_trichotomy a b)
51-
.resolve_left $ λ h, ne_of_lt (H h) e)
52-
.resolve_right $ λ h, ne_of_gt (H h) e
53-
54-
theorem compares (H : strict_mono f) {a b} :
55-
∀ {o}, compares o (f a) (f b) ↔ compares o a b
56-
| lt := H.lt_iff_lt
57-
| eq := ⟨λ h, H.injective h, congr_arg _⟩
58-
| gt := H.lt_iff_lt
59-
60-
lemma le_iff_le (H : strict_mono f) {a b} :
61-
f a ≤ f b ↔ a ≤ b :=
62-
⟨λ h, le_of_not_gt $ λ h', not_le_of_lt (H h') h,
63-
λ h, (lt_or_eq_of_le h).elim (λ h', le_of_lt (H h')) (λ h', h' ▸ le_refl _)⟩
64-
end
65-
66-
protected lemma nat {β} [preorder β] {f : ℕ → β} (h : ∀n, f n < f (n+1)) : strict_mono f :=
67-
by { intros n m hnm, induction hnm with m' hnm' ih, apply h, exact lt.trans ih (h _) }
68-
69-
-- `preorder α` isn't strong enough: if the preorder on α is an equivalence relation,
70-
-- then `strict_mono f` is vacuously true.
71-
lemma monotone [partial_order α] [preorder β] {f : α → β} (H : strict_mono f) : monotone f :=
72-
λ a b h, (lt_or_eq_of_le h).rec (le_of_lt ∘ (@H _ _)) (by rintro rfl; refl)
73-
74-
end strict_mono
75-
76-
section
77-
open function
78-
variables [partial_order α] [partial_order β] {f : α → β}
79-
80-
lemma strict_mono_of_monotone_of_injective (h₁ : monotone f) (h₂ : injective f) :
81-
strict_mono f :=
82-
λ a b h,
83-
begin
84-
rw lt_iff_le_and_ne at ⊢ h,
85-
exact ⟨h₁ h.1, λ e, h.2 (h₂ e)⟩
86-
end
87-
88-
end
89-
9025
section
9126
variables [decidable_linear_order α] [decidable_linear_order β] {f : α → β} {a b c d : α}
9227

@@ -313,12 +248,6 @@ end decidable_linear_ordered_add_comm_group
313248
section decidable_linear_ordered_semiring
314249
variables [decidable_linear_ordered_semiring α] {a b c d : α}
315250

316-
lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) :=
317-
assume b c b_le_c, mul_le_mul_of_nonneg_left b_le_c ha
318-
319-
lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) :=
320-
assume b c b_le_c, mul_le_mul_of_nonneg_right b_le_c ha
321-
322251
lemma mul_max_of_nonneg (b c : α) (ha : 0 ≤ a) : a * max b c = max (a * b) (a * c) :=
323252
(monotone_mul_left_of_nonneg ha).map_max
324253

src/algebra/ordered_field.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ lemma div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) :
138138
a / b < c / d :=
139139
(div_lt_div_iff (lt_trans d0 hbd) d0).2 (mul_lt_mul' hac hbd (le_of_lt d0) c0)
140140

141+
lemma monotone.div_const {β : Type*} [preorder β] {f : β → α} (hf : monotone f)
142+
{c : α} (hc : 0 ≤ c) :
143+
monotone (λ x, (f x) / c) :=
144+
hf.mul_const (inv_nonneg.2 hc)
145+
146+
lemma strict_mono.div_const {β : Type*} [preorder β] {f : β → α} (hf : strict_mono f)
147+
{c : α} (hc : 0 < c) :
148+
strict_mono (λ x, (f x) / c) :=
149+
hf.mul_const (inv_pos.2 hc)
150+
141151
lemma half_pos {a : α} (h : 0 < a) : 0 < a / 2 := div_pos h two_pos
142152

143153
lemma one_half_pos : (0:α) < 1 / 2 := half_pos zero_lt_one

src/algebra/ordered_group.lean

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
Copyright (c) 2017 Mario Carneiro. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro, Johannes Hölzl
5-
6-
Ordered monoids and groups.
75
-/
86
import algebra.group.units
97
import algebra.group.with_one
108
import algebra.group.type_tags
119
import order.bounded_lattice
1210

11+
/-!
12+
# Ordered monoids and groups
13+
-/
14+
1315
universe u
1416
variable {α : Type u}
1517

@@ -135,6 +137,21 @@ iff.intro
135137
lemma bit0_pos {a : α} (h : 0 < a) : 0 < bit0 a :=
136138
add_pos' h h
137139

140+
section mono
141+
142+
variables {β : Type*} [preorder β] {f g : β → α}
143+
144+
lemma monotone.add (hf : monotone f) (hg : monotone g) : monotone (λ x, f x + g x) :=
145+
λ x y h, add_le_add' (hf h) (hg h)
146+
147+
lemma monotone.add_const (hf : monotone f) (a : α) : monotone (λ x, f x + a) :=
148+
hf.add monotone_const
149+
150+
lemma monotone.const_add (hf : monotone f) (a : α) : monotone (λ x, a + f x) :=
151+
monotone_const.add hf
152+
153+
end mono
154+
138155
end ordered_add_comm_monoid
139156

140157
namespace units
@@ -471,6 +488,20 @@ lemma with_top.add_lt_add_iff_right
471488
{a b c : with_top α} : a < ⊤ → (c + a < b + a ↔ c < b) :=
472489
by simpa [add_comm] using @with_top.add_lt_add_iff_left _ _ a b c
473490

491+
section mono
492+
493+
variables {β : Type*} [preorder β] {f g : β → α}
494+
495+
lemma monotone.add_strict_mono (hf : monotone f) (hg : strict_mono g) :
496+
strict_mono (λ x, f x + g x) :=
497+
λ x y h, add_lt_add_of_le_of_lt (hf $ le_of_lt h) (hg h)
498+
499+
lemma strict_mono.add_monotone (hf : strict_mono f) (hg : monotone g) :
500+
strict_mono (λ x, f x + g x) :=
501+
λ x y h, add_lt_add_of_lt_of_le (hf h) (hg $ le_of_lt h)
502+
503+
end mono
504+
474505
end ordered_cancel_comm_monoid
475506

476507
section ordered_add_comm_group

src/algebra/ordered_ring.lean

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,59 @@ lt_of_not_ge (λ ha, absurd h (not_lt_of_ge (mul_nonpos_of_nonneg_of_nonpos ha h
184184
lemma neg_of_mul_pos_right {a b : α} (h : 0 < a * b) (ha : a ≤ 0) : b < 0 :=
185185
lt_of_not_ge (λ hb, absurd h (not_lt_of_ge (mul_nonpos_of_nonpos_of_nonneg ha hb)))
186186

187+
section mono
188+
189+
variables {β : Type*} [preorder β] {f g : β → α} {a : α}
190+
191+
lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) :=
192+
assume b c b_le_c, mul_le_mul_of_nonneg_left b_le_c ha
193+
194+
lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) :=
195+
assume b c b_le_c, mul_le_mul_of_nonneg_right b_le_c ha
196+
197+
lemma monotone.mul_const (hf : monotone f) (ha : 0 ≤ a) :
198+
monotone (λ x, (f x) * a) :=
199+
(monotone_mul_right_of_nonneg ha).comp hf
200+
201+
lemma monotone.const_mul (hf : monotone f) (ha : 0 ≤ a) :
202+
monotone (λ x, a * (f x)) :=
203+
(monotone_mul_left_of_nonneg ha).comp hf
204+
205+
lemma monotone.mul (hf : monotone f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x) (hg0 : ∀ x, 0 ≤ g x) :
206+
monotone (λ x, f x * g x) :=
207+
λ x y h, mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)
208+
209+
lemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (λ x, a * x) :=
210+
assume b c b_lt_c, (mul_lt_mul_left ha).2 b_lt_c
211+
212+
lemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (λ x, x * a) :=
213+
assume b c b_lt_c, (mul_lt_mul_right ha).2 b_lt_c
214+
215+
lemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) :
216+
strict_mono (λ x, (f x) * a) :=
217+
(strict_mono_mul_right_of_pos ha).comp hf
218+
219+
lemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) :
220+
strict_mono (λ x, a * (f x)) :=
221+
(strict_mono_mul_left_of_pos ha).comp hf
222+
223+
lemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x)
224+
(hg0 : ∀ x, 0 < g x) :
225+
strict_mono (λ x, f x * g x) :=
226+
λ x y h, mul_lt_mul (hf h) (hg $ le_of_lt h) (hg0 x) (hf0 y)
227+
228+
lemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : ∀ x, 0 < f x)
229+
(hg0 : ∀ x, 0 ≤ g x) :
230+
strict_mono (λ x, f x * g x) :=
231+
λ x y h, mul_lt_mul' (hf $ le_of_lt h) (hg h) (hg0 x) (hf0 y)
232+
233+
lemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : ∀ x, 0 ≤ f x)
234+
(hg0 : ∀ x, 0 ≤ g x) :
235+
strict_mono (λ x, f x * g x) :=
236+
λ x y h, mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)
237+
238+
end mono
239+
187240
end linear_ordered_semiring
188241

189242
section decidable_linear_ordered_semiring

0 commit comments

Comments
 (0)