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

Commit 1f50530

Browse files
feat(data/set/intervals/image_preimage, algebra/ordered_monoid): new typeclass for interval bijection lemmas (#6629)
This commit introduces a ``has_exists_add_of_le`` typeclass extending ``ordered_add_comm_monoid``; is the assumption needed so that additively translating an interval gives a bijection. We then prove this fact for all flavours of interval. https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/Correct.20setting.20for.20positive.20shifts.20of.20intervals Co-authored-by: Peter Nelson <71660771+apnelson1@users.noreply.github.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
1 parent 1345319 commit 1f50530

File tree

3 files changed

+119
-4
lines changed

3 files changed

+119
-4
lines changed

src/algebra/ordered_group.lean

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ This file develops the basics of ordered groups.
1515
Unfortunately, the number of `'` appended to lemmas in this file
1616
may differ between the multiplicative and the additive version of a lemma.
1717
The reason is that we did not want to change existing names in the library.
18-
1918
-/
2019

2120
set_option old_structure_cmd true
@@ -71,12 +70,19 @@ begin simp [inv_mul_cancel_left] at this, assumption end
7170

7271
@[priority 100, to_additive] -- see Note [lower instance priority]
7372
instance ordered_comm_group.to_ordered_cancel_comm_monoid (α : Type u)
74-
[s : ordered_comm_group α] : ordered_cancel_comm_monoid α :=
73+
[s : ordered_comm_group α] :
74+
ordered_cancel_comm_monoid α :=
7575
{ mul_left_cancel := @mul_left_cancel α _,
7676
mul_right_cancel := @mul_right_cancel α _,
7777
le_of_mul_le_mul_left := @ordered_comm_group.le_of_mul_le_mul_left α _,
7878
..s }
7979

80+
@[priority 100, to_additive]
81+
instance ordered_comm_group.has_exists_mul_of_le (α : Type u)
82+
[ordered_comm_group α] :
83+
has_exists_mul_of_le α :=
84+
⟨λ a b hab, ⟨b * a⁻¹, (mul_inv_cancel_comm_assoc a b).symm⟩⟩
85+
8086
@[to_additive neg_le_neg]
8187
lemma inv_le_inv' (h : a ≤ b) : b⁻¹ ≤ a⁻¹ :=
8288
have 1 ≤ a⁻¹ * b, from mul_left_inv a ▸ mul_le_mul_left' h _,

src/algebra/ordered_monoid.lean

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This file develops the basics of ordered monoids.
1919
Unfortunately, the number of `'` appended to lemmas in this file
2020
may differ between the multiplicative and the additive version of a lemma.
2121
The reason is that we did not want to change existing names in the library.
22-
2322
-/
2423

2524
set_option old_structure_cmd true
@@ -42,13 +41,32 @@ class ordered_comm_monoid (α : Type*) extends comm_monoid α, partial_order α
4241
* `a ≤ b → c + a ≤ c + b` (addition is monotone)
4342
* `a + b < a + c → b < c`.
4443
-/
44+
4545
@[protect_proj, ancestor add_comm_monoid partial_order]
4646
class ordered_add_comm_monoid (α : Type*) extends add_comm_monoid α, partial_order α :=
4747
(add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b)
4848
(lt_of_add_lt_add_left : ∀ a b c : α, a + b < a + c → b < c)
4949

5050
attribute [to_additive] ordered_comm_monoid
5151

52+
/-- An `ordered_comm_monoid` with one-sided 'division' in the sense that
53+
if `a ≤ b`, there is some `c` for which `a * c = b`. This is a weaker version
54+
of the condition on canonical orderings defined by `canonically_ordered_monoid`. -/
55+
class has_exists_mul_of_le (α : Type u) [ordered_comm_monoid α] : Prop :=
56+
(exists_mul_of_le : ∀ {a b : α}, a ≤ b → ∃ (c : α), b = a * c)
57+
58+
export has_exists_mul_of_le (exists_mul_of_le)
59+
60+
/-- An `ordered_add_comm_monoid` with one-sided 'subtraction' in the sense that
61+
if `a ≤ b`, then there is some `c` for which `a + c = b`. This is a weaker version
62+
of the condition on canonical orderings defined by `canonically_ordered_add_monoid`. -/
63+
class has_exists_add_of_le (α : Type u) [ordered_add_comm_monoid α] : Prop :=
64+
(exists_add_of_le : ∀ {a b : α}, a ≤ b → ∃ (c : α), b = a + c)
65+
66+
export has_exists_add_of_le (exists_add_of_le)
67+
68+
attribute [to_additive] has_exists_mul_of_le
69+
5270
/-- A linearly ordered additive commutative monoid. -/
5371
@[protect_proj, ancestor linear_order ordered_add_comm_monoid]
5472
class linear_ordered_add_comm_monoid (α : Type*)
@@ -795,6 +813,11 @@ instance with_top.canonically_ordered_add_monoid {α : Type u} [canonically_orde
795813
.. with_top.order_bot,
796814
.. with_top.ordered_add_comm_monoid }
797815

816+
@[priority 100, to_additive]
817+
instance canonically_ordered_monoid.has_exists_mul_of_le (α : Type u)
818+
[canonically_ordered_monoid α] : has_exists_mul_of_le α :=
819+
{ exists_mul_of_le := λ a b hab, le_iff_exists_mul.mp hab }
820+
798821
end canonically_ordered_monoid
799822

800823
/-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid

src/data/set/intervals/image_preimage.lean

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,82 @@ In this file we prove a bunch of trivial lemmas like “if we add `a` to all poi
1414
then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove
1515
lemmas about preimages and images of all intervals. We also prove a few lemmas about images under
1616
`x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`.
17-
1817
-/
1918

2019
universe u
2120

2221
namespace set
22+
23+
section has_exists_add_of_le
24+
/-!
25+
The lemmas in this section state that addition maps intervals bijectively. The typeclass
26+
`has_exists_add_of_le` is defined specifically to make them work when combined with
27+
`ordered_cancel_add_comm_monoid`; the lemmas below therefore apply to all
28+
`ordered_add_comm_group`, but also to `ℕ` and `ℝ≥0`, which are not groups.
29+
30+
TODO : move as much as possible in this file to the setting of this weaker typeclass.
31+
-/
32+
33+
variables {α : Type u} [ordered_cancel_add_comm_monoid α] [has_exists_add_of_le α] (a b d : α)
34+
35+
lemma Icc_add_bij : bij_on (+d) (Icc a b) (Icc (a + d) (b + d)) :=
36+
begin
37+
refine ⟨λ _ h, ⟨add_le_add_right h.1 _, add_le_add_right h.2 _⟩,
38+
λ _ _ _ _ h, add_right_cancel h,
39+
λ _ h, _⟩,
40+
obtain ⟨c, rfl⟩ := exists_add_of_le h.1,
41+
rw [mem_Icc, add_right_comm, add_le_add_iff_right, add_le_add_iff_right] at h,
42+
exact ⟨a + c, h, by rw add_right_comm⟩,
43+
end
44+
45+
lemma Ioo_add_bij : bij_on (+d) (Ioo a b) (Ioo (a + d) (b + d)) :=
46+
begin
47+
refine ⟨λ _ h, ⟨add_lt_add_right h.1 _, add_lt_add_right h.2 _⟩,
48+
λ _ _ _ _ h, add_right_cancel h,
49+
λ _ h, _⟩,
50+
obtain ⟨c, rfl⟩ := exists_add_of_le h.1.le,
51+
rw [mem_Ioo, add_right_comm, add_lt_add_iff_right, add_lt_add_iff_right] at h,
52+
exact ⟨a + c, h, by rw add_right_comm⟩,
53+
end
54+
55+
lemma Ioc_add_bij : bij_on (+d) (Ioc a b) (Ioc (a + d) (b + d)) :=
56+
begin
57+
refine ⟨λ _ h, ⟨add_lt_add_right h.1 _, add_le_add_right h.2 _⟩,
58+
λ _ _ _ _ h, add_right_cancel h,
59+
λ _ h, _⟩,
60+
obtain ⟨c, rfl⟩ := exists_add_of_le h.1.le,
61+
rw [mem_Ioc, add_right_comm, add_lt_add_iff_right, add_le_add_iff_right] at h,
62+
exact ⟨a + c, h, by rw add_right_comm⟩,
63+
end
64+
65+
lemma Ico_add_bij : bij_on (+d) (Ico a b) (Ico (a + d) (b + d)) :=
66+
begin
67+
refine ⟨λ _ h, ⟨add_le_add_right h.1 _, add_lt_add_right h.2 _⟩,
68+
λ _ _ _ _ h, add_right_cancel h,
69+
λ _ h, _⟩,
70+
obtain ⟨c, rfl⟩ := exists_add_of_le h.1,
71+
rw [mem_Ico, add_right_comm, add_le_add_iff_right, add_lt_add_iff_right] at h,
72+
exact ⟨a + c, h, by rw add_right_comm⟩,
73+
end
74+
75+
lemma Ici_add_bij : bij_on (+d) (Ici a) (Ici (a + d)) :=
76+
begin
77+
refine ⟨λ x h, add_le_add_right (mem_Ici.mp h) _, λ _ _ _ _ h, add_right_cancel h, λ _ h, _⟩,
78+
obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ici.mp h),
79+
rw [mem_Ici, add_right_comm, add_le_add_iff_right] at h,
80+
exact ⟨a + c, h, by rw add_right_comm⟩,
81+
end
82+
83+
lemma Ioi_add_bij : bij_on (+d) (Ioi a) (Ioi (a + d)) :=
84+
begin
85+
refine ⟨λ x h, add_lt_add_right (mem_Ioi.mp h) _, λ _ _ _ _ h, add_right_cancel h, λ _ h, _⟩,
86+
obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ioi.mp h).le,
87+
rw [mem_Ioi, add_right_comm, add_lt_add_iff_right] at h,
88+
exact ⟨a + c, h, by rw add_right_comm⟩,
89+
end
90+
91+
end has_exists_add_of_le
92+
2393
section ordered_add_comm_group
2494

2595
variables {G : Type u} [ordered_add_comm_group G] (a b c : G)
@@ -268,6 +338,22 @@ by simp [sub_eq_neg_add]
268338
@[simp] lemma image_sub_const_Ioo : (λ x, x - a) '' Ioo b c = Ioo (b - a) (c - a) :=
269339
by simp [sub_eq_neg_add]
270340

341+
/-!
342+
### Bijections
343+
-/
344+
345+
lemma Iic_add_bij : bij_on (+a) (Iic b) (Iic (b + a)) :=
346+
begin
347+
refine ⟨λ x h, add_le_add_right (mem_Iic.mp h) _, λ _ _ _ _ h, add_right_cancel h, λ _ h, _⟩,
348+
simpa [add_comm a] using h,
349+
end
350+
351+
lemma Iio_add_bij : bij_on (+a) (Iio b) (Iio (b + a)) :=
352+
begin
353+
refine ⟨λ x h, add_lt_add_right (mem_Iio.mp h) _, λ _ _ _ _ h, add_right_cancel h, λ _ h, _⟩,
354+
simpa [add_comm a] using h,
355+
end
356+
271357
end ordered_add_comm_group
272358

273359
/-!

0 commit comments

Comments
 (0)