-
Notifications
You must be signed in to change notification settings - Fork 251
/
Join.lean
227 lines (181 loc) Β· 10.5 KB
/
Join.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/-
Copyright (c) 2022 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import Mathlib.Analysis.Convex.Hull
#align_import analysis.convex.join from "leanprover-community/mathlib"@"951bf1d9e98a2042979ced62c0620bcfb3587cf8"
/-!
# Convex join
This file defines the convex join of two sets. The convex join of `s` and `t` is the union of the
segments with one end in `s` and the other in `t`. This is notably a useful gadget to deal with
convex hulls of finite sets.
-/
open Set
variable {ΞΉ : Sort*} {π E : Type*}
section OrderedSemiring
variable (π) [OrderedSemiring π] [AddCommMonoid E] [Module π E] {s t sβ sβ tβ tβ u : Set E}
{x y : E}
/-- The join of two sets is the union of the segments joining them. This can be interpreted as the
topological join, but within the original space. -/
def convexJoin (s t : Set E) : Set E :=
β (x β s) (y β t), segment π x y
#align convex_join convexJoin
variable {π}
theorem mem_convexJoin : x β convexJoin π s t β β a β s, β b β t, x β segment π a b := by
simp [convexJoin]
#align mem_convex_join mem_convexJoin
theorem convexJoin_comm (s t : Set E) : convexJoin π s t = convexJoin π t s :=
(iUnionβ_comm _).trans <| by simp_rw [convexJoin, segment_symm]
#align convex_join_comm convexJoin_comm
theorem convexJoin_mono (hs : sβ β sβ) (ht : tβ β tβ) : convexJoin π sβ tβ β convexJoin π sβ tβ :=
biUnion_mono hs fun _ _ => biUnion_subset_biUnion_left ht
#align convex_join_mono convexJoin_mono
theorem convexJoin_mono_left (hs : sβ β sβ) : convexJoin π sβ t β convexJoin π sβ t :=
convexJoin_mono hs Subset.rfl
#align convex_join_mono_left convexJoin_mono_left
theorem convexJoin_mono_right (ht : tβ β tβ) : convexJoin π s tβ β convexJoin π s tβ :=
convexJoin_mono Subset.rfl ht
#align convex_join_mono_right convexJoin_mono_right
@[simp]
theorem convexJoin_empty_left (t : Set E) : convexJoin π β
t = β
:= by simp [convexJoin]
#align convex_join_empty_left convexJoin_empty_left
@[simp]
theorem convexJoin_empty_right (s : Set E) : convexJoin π s β
= β
:= by simp [convexJoin]
#align convex_join_empty_right convexJoin_empty_right
@[simp]
theorem convexJoin_singleton_left (t : Set E) (x : E) :
convexJoin π {x} t = β y β t, segment π x y := by simp [convexJoin]
#align convex_join_singleton_left convexJoin_singleton_left
@[simp]
theorem convexJoin_singleton_right (s : Set E) (y : E) :
convexJoin π s {y} = β x β s, segment π x y := by simp [convexJoin]
#align convex_join_singleton_right convexJoin_singleton_right
-- Porting note (#10618): simp can prove it
theorem convexJoin_singletons (x : E) : convexJoin π {x} {y} = segment π x y := by simp
#align convex_join_singletons convexJoin_singletons
@[simp]
theorem convexJoin_union_left (sβ sβ t : Set E) :
convexJoin π (sβ βͺ sβ) t = convexJoin π sβ t βͺ convexJoin π sβ t := by
simp_rw [convexJoin, mem_union, iUnion_or, iUnion_union_distrib]
#align convex_join_union_left convexJoin_union_left
@[simp]
theorem convexJoin_union_right (s tβ tβ : Set E) :
convexJoin π s (tβ βͺ tβ) = convexJoin π s tβ βͺ convexJoin π s tβ := by
simp_rw [convexJoin_comm s, convexJoin_union_left]
#align convex_join_union_right convexJoin_union_right
@[simp]
theorem convexJoin_iUnion_left (s : ΞΉ β Set E) (t : Set E) :
convexJoin π (β i, s i) t = β i, convexJoin π (s i) t := by
simp_rw [convexJoin, mem_iUnion, iUnion_exists]
exact iUnion_comm _
#align convex_join_Union_left convexJoin_iUnion_left
@[simp]
theorem convexJoin_iUnion_right (s : Set E) (t : ΞΉ β Set E) :
convexJoin π s (β i, t i) = β i, convexJoin π s (t i) := by
simp_rw [convexJoin_comm s, convexJoin_iUnion_left]
#align convex_join_Union_right convexJoin_iUnion_right
theorem segment_subset_convexJoin (hx : x β s) (hy : y β t) : segment π x y β convexJoin π s t :=
subset_iUnionβ_of_subset x hx <| subset_iUnionβ (s := fun y _ β¦ segment π x y) y hy
#align segment_subset_convex_join segment_subset_convexJoin
theorem subset_convexJoin_left (h : t.Nonempty) : s β convexJoin π s t := fun _x hx =>
let β¨_y, hyβ© := h
segment_subset_convexJoin hx hy <| left_mem_segment _ _ _
#align subset_convex_join_left subset_convexJoin_left
theorem subset_convexJoin_right (h : s.Nonempty) : t β convexJoin π s t :=
convexJoin_comm (π := π) t s βΈ subset_convexJoin_left h
#align subset_convex_join_right subset_convexJoin_right
theorem convexJoin_subset (hs : s β u) (ht : t β u) (hu : Convex π u) : convexJoin π s t β u :=
iUnionβ_subset fun _x hx => iUnionβ_subset fun _y hy => hu.segment_subset (hs hx) (ht hy)
#align convex_join_subset convexJoin_subset
theorem convexJoin_subset_convexHull (s t : Set E) : convexJoin π s t β convexHull π (s βͺ t) :=
convexJoin_subset (subset_union_left.trans <| subset_convexHull _ _)
(subset_union_right.trans <| subset_convexHull _ _) <|
convex_convexHull _ _
#align convex_join_subset_convex_hull convexJoin_subset_convexHull
end OrderedSemiring
section LinearOrderedField
variable [LinearOrderedField π] [AddCommGroup E] [Module π E] {s t u : Set E} {x y : E}
theorem convexJoin_assoc_aux (s t u : Set E) :
convexJoin π (convexJoin π s t) u β convexJoin π s (convexJoin π t u) := by
simp_rw [subset_def, mem_convexJoin]
rintro _ β¨z, β¨x, hx, y, hy, aβ, bβ, haβ, hbβ, habβ, rflβ©, z, hz, aβ, bβ, haβ, hbβ, habβ, rflβ©
obtain rfl | hbβ := hbβ.eq_or_lt
Β· refine β¨x, hx, y, β¨y, hy, z, hz, left_mem_segment π _ _β©, aβ, bβ, haβ, hbβ, habβ, ?_β©
rw [add_zero] at habβ
rw [habβ, one_smul, zero_smul, add_zero]
have haβbβ : 0 β€ aβ * bβ := mul_nonneg haβ hbβ
have hab : 0 < aβ * bβ + bβ := add_pos_of_nonneg_of_pos haβbβ hbβ
refine
β¨x, hx, (aβ * bβ / (aβ * bβ + bβ)) β’ y + (bβ / (aβ * bβ + bβ)) β’ z,
β¨y, hy, z, hz, _, _, ?_, ?_, ?_, rflβ©,
aβ * aβ, aβ * bβ + bβ, mul_nonneg haβ haβ, hab.le, ?_, ?_β©
Β· exact div_nonneg haβbβ hab.le
Β· exact div_nonneg hbβ.le hab.le
Β· rw [β add_div, div_self hab.ne']
Β· rw [β add_assoc, β mul_add, habβ, mul_one, habβ]
Β· simp_rw [smul_add, β mul_smul, mul_div_cancelβ _ hab.ne', add_assoc]
#align convex_join_assoc_aux convexJoin_assoc_aux
theorem convexJoin_assoc (s t u : Set E) :
convexJoin π (convexJoin π s t) u = convexJoin π s (convexJoin π t u) := by
refine (convexJoin_assoc_aux _ _ _).antisymm ?_
simp_rw [convexJoin_comm s, convexJoin_comm _ u]
exact convexJoin_assoc_aux _ _ _
#align convex_join_assoc convexJoin_assoc
theorem convexJoin_left_comm (s t u : Set E) :
convexJoin π s (convexJoin π t u) = convexJoin π t (convexJoin π s u) := by
simp_rw [β convexJoin_assoc, convexJoin_comm]
#align convex_join_left_comm convexJoin_left_comm
theorem convexJoin_right_comm (s t u : Set E) :
convexJoin π (convexJoin π s t) u = convexJoin π (convexJoin π s u) t := by
simp_rw [convexJoin_assoc, convexJoin_comm]
#align convex_join_right_comm convexJoin_right_comm
theorem convexJoin_convexJoin_convexJoin_comm (s t u v : Set E) :
convexJoin π (convexJoin π s t) (convexJoin π u v) =
convexJoin π (convexJoin π s u) (convexJoin π t v) := by
simp_rw [β convexJoin_assoc, convexJoin_right_comm]
#align convex_join_convex_join_convex_join_comm convexJoin_convexJoin_convexJoin_comm
-- Porting note: moved 3 lemmas from below to golf
protected theorem Convex.convexJoin (hs : Convex π s) (ht : Convex π t) :
Convex π (convexJoin π s t) := by
simp only [Convex, StarConvex, convexJoin, mem_iUnion]
rintro _ β¨xβ, hxβ, yβ, hyβ, aβ, bβ, haβ, hbβ, habβ, rflβ©
_ β¨xβ, hxβ, yβ, hyβ, aβ, bβ, haβ, hbβ, habβ, rflβ© p q hp hq hpq
rcases hs.exists_mem_add_smul_eq hxβ hxβ (mul_nonneg hp haβ) (mul_nonneg hq haβ) with β¨x, hxs, hxβ©
rcases ht.exists_mem_add_smul_eq hyβ hyβ (mul_nonneg hp hbβ) (mul_nonneg hq hbβ) with β¨y, hyt, hyβ©
refine β¨_, hxs, _, hyt, p * aβ + q * aβ, p * bβ + q * bβ, ?_, ?_, ?_, ?_β© <;> try positivity
Β· rwa [add_add_add_comm, β mul_add, β mul_add, habβ, habβ, mul_one, mul_one]
Β· rw [hx, hy, add_add_add_comm]
simp only [smul_add, smul_smul]
#align convex.convex_join Convex.convexJoin
protected theorem Convex.convexHull_union (hs : Convex π s) (ht : Convex π t) (hsβ : s.Nonempty)
(htβ : t.Nonempty) : convexHull π (s βͺ t) = convexJoin π s t :=
(convexHull_min (union_subset (subset_convexJoin_left htβ) <| subset_convexJoin_right hsβ) <|
hs.convexJoin ht).antisymm <|
convexJoin_subset_convexHull _ _
#align convex.convex_hull_union Convex.convexHull_union
theorem convexHull_union (hs : s.Nonempty) (ht : t.Nonempty) :
convexHull π (s βͺ t) = convexJoin π (convexHull π s) (convexHull π t) := by
rw [β convexHull_convexHull_union_left, β convexHull_convexHull_union_right]
exact (convex_convexHull π s).convexHull_union (convex_convexHull π t) hs.convexHull ht.convexHull
#align convex_hull_union convexHull_union
theorem convexHull_insert (hs : s.Nonempty) :
convexHull π (insert x s) = convexJoin π {x} (convexHull π s) := by
rw [insert_eq, convexHull_union (singleton_nonempty _) hs, convexHull_singleton]
#align convex_hull_insert convexHull_insert
theorem convexJoin_segments (a b c d : E) :
convexJoin π (segment π a b) (segment π c d) = convexHull π {a, b, c, d} := by
simp_rw [β convexHull_pair, convexHull_insert (insert_nonempty _ _),
convexHull_insert (singleton_nonempty _), convexJoin_assoc,
convexHull_singleton]
#align convex_join_segments convexJoin_segments
theorem convexJoin_segment_singleton (a b c : E) :
convexJoin π (segment π a b) {c} = convexHull π {a, b, c} := by
rw [β pair_eq_singleton, β convexJoin_segments, segment_same, pair_eq_singleton]
#align convex_join_segment_singleton convexJoin_segment_singleton
theorem convexJoin_singleton_segment (a b c : E) :
convexJoin π {a} (segment π b c) = convexHull π {a, b, c} := by
rw [β segment_same π, convexJoin_segments, insert_idem]
#align convex_join_singleton_segment convexJoin_singleton_segment
-- Porting note: moved 3 lemmas up to golf
end LinearOrderedField