Datasets:
Tasks:
Text Generation
Modalities:
Text
Sub-tasks:
language-modeling
Languages:
English
Size:
100K - 1M
License:
/- | |
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 analysis.convex.combination | |
/-! | |
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 | |
open_locale big_operators | |
variables {ฮน : Sort*} {๐ E : Type*} | |
section ordered_semiring | |
variables (๐) [ordered_semiring ๐] [add_comm_monoid 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 convex_join (s t : set E) : set E := โ (x โ s) (y โ t), segment ๐ x y | |
variables {๐} | |
lemma mem_convex_join : x โ convex_join ๐ s t โ โ (a โ s) (b โ t), x โ segment ๐ a b := | |
by simp [convex_join] | |
lemma convex_join_comm (s t : set E) : convex_join ๐ s t = convex_join ๐ t s := | |
(Unionโ_comm _).trans $ by simp_rw [convex_join, segment_symm] | |
lemma convex_join_mono (hs : sโ โ sโ) (ht : tโ โ tโ) : convex_join ๐ sโ tโ โ convex_join ๐ sโ tโ := | |
bUnion_mono hs $ ฮป x hx, bUnion_mono ht $ ฮป y hy, subset.rfl | |
lemma convex_join_mono_left (hs : sโ โ sโ) : convex_join ๐ sโ t โ convex_join ๐ sโ t := | |
convex_join_mono hs subset.rfl | |
lemma convex_join_mono_right (ht : tโ โ tโ) : convex_join ๐ s tโ โ convex_join ๐ s tโ := | |
convex_join_mono subset.rfl ht | |
@[simp] lemma convex_join_empty_left (t : set E) : convex_join ๐ โ t = โ := by simp [convex_join] | |
@[simp] lemma convex_join_empty_right (s : set E) : convex_join ๐ s โ = โ := by simp [convex_join] | |
@[simp] lemma convex_join_singleton_left (t : set E) (x : E) : | |
convex_join ๐ {x} t = โ (y โ t), segment ๐ x y := by simp [convex_join] | |
@[simp] lemma convex_join_singleton_right (s : set E) (y : E) : | |
convex_join ๐ s {y} = โ (x โ s), segment ๐ x y := by simp [convex_join] | |
@[simp] lemma convex_join_singletons (x : E) : convex_join ๐ {x} {y} = segment ๐ x y := | |
by simp [convex_join] | |
@[simp] lemma convex_join_union_left (sโ sโ t : set E) : | |
convex_join ๐ (sโ โช sโ) t = convex_join ๐ sโ t โช convex_join ๐ sโ t := | |
by simp_rw [convex_join, mem_union_eq, Union_or, Union_union_distrib] | |
@[simp] lemma convex_join_union_right (s tโ tโ : set E) : | |
convex_join ๐ s (tโ โช tโ) = convex_join ๐ s tโ โช convex_join ๐ s tโ := | |
by simp_rw [convex_join, mem_union_eq, Union_or, Union_union_distrib] | |
@[simp] lemma convex_join_Union_left (s : ฮน โ set E) (t : set E) : | |
convex_join ๐ (โ i, s i) t = โ i, convex_join ๐ (s i) t := | |
by { simp_rw [convex_join, mem_Union, Union_exists], exact Union_comm _ } | |
@[simp] lemma convex_join_Union_right (s : set E) (t : ฮน โ set E) : | |
convex_join ๐ s (โ i, t i) = โ i, convex_join ๐ s (t i) := | |
by simp_rw [convex_join_comm s, convex_join_Union_left] | |
lemma segment_subset_convex_join (hx : x โ s) (hy : y โ t) : segment ๐ x y โ convex_join ๐ s t := | |
(subset_Unionโ y hy).trans (subset_Unionโ x hx) | |
lemma subset_convex_join_left (h : t.nonempty) : s โ convex_join ๐ s t := | |
ฮป x hx, let โจy, hyโฉ := h in segment_subset_convex_join hx hy $ left_mem_segment _ _ _ | |
lemma subset_convex_join_right (h : s.nonempty) : t โ convex_join ๐ s t := | |
ฮป y hy, let โจx, hxโฉ := h in segment_subset_convex_join hx hy $ right_mem_segment _ _ _ | |
lemma convex_join_subset (hs : s โ u) (ht : t โ u) (hu : convex ๐ u) : convex_join ๐ s t โ u := | |
Unionโ_subset $ ฮป x hx, Unionโ_subset $ ฮป y hy, hu.segment_subset (hs hx) (ht hy) | |
lemma convex_join_subset_convex_hull (s t : set E) : convex_join ๐ s t โ convex_hull ๐ (s โช t) := | |
convex_join_subset ((subset_union_left _ _).trans $ subset_convex_hull _ _) | |
((subset_union_right _ _).trans $ subset_convex_hull _ _) $ convex_convex_hull _ _ | |
end ordered_semiring | |
section linear_ordered_field | |
variables [linear_ordered_field ๐] [add_comm_group E] [module ๐ E] {s t u : set E} {x y : E} | |
lemma convex_join_assoc_aux (s t u : set E) : | |
convex_join ๐ (convex_join ๐ s t) u โ convex_join ๐ s (convex_join ๐ t u) := | |
begin | |
simp_rw [subset_def, mem_convex_join], | |
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] } | |
end | |
lemma convex_join_assoc (s t u : set E) : | |
convex_join ๐ (convex_join ๐ s t) u = convex_join ๐ s (convex_join ๐ t u) := | |
begin | |
refine (convex_join_assoc_aux _ _ _).antisymm _, | |
simp_rw [convex_join_comm s, convex_join_comm _ u], | |
exact convex_join_assoc_aux _ _ _, | |
end | |
lemma convex_join_left_comm (s t u : set E) : | |
convex_join ๐ s (convex_join ๐ t u) = convex_join ๐ t (convex_join ๐ s u) := | |
by simp_rw [โconvex_join_assoc, convex_join_comm] | |
lemma convex_join_right_comm (s t u : set E) : | |
convex_join ๐ (convex_join ๐ s t) u = convex_join ๐ (convex_join ๐ s u) t := | |
by simp_rw [convex_join_assoc, convex_join_comm] | |
lemma convex_join_convex_join_convex_join_comm (s t u v : set E) : | |
convex_join ๐ (convex_join ๐ s t) (convex_join ๐ u v) = | |
convex_join ๐ (convex_join ๐ s u) (convex_join ๐ t v) := | |
by simp_rw [โconvex_join_assoc, convex_join_right_comm] | |
lemma convex_hull_insert (hs : s.nonempty) : | |
convex_hull ๐ (insert x s) = convex_join ๐ {x} (convex_hull ๐ s) := | |
begin | |
classical, | |
refine (convex_join_subset ((singleton_subset_iff.2 $ mem_insert _ _).trans $ subset_convex_hull | |
_ _) (convex_hull_mono $ subset_insert _ _) $ convex_convex_hull _ _).antisymm' (ฮป x hx, _), | |
rw convex_hull_eq at hx, | |
obtain โจฮน, t, w, z, hwโ, hwโ, hz, rflโฉ := hx, | |
have : (โ i in t.filter (ฮป i, z i = x), w i) โข x + โ i in t.filter (ฮป i, z i โ x), w i โข z i = | |
t.center_mass w z, | |
{ rw [finset.center_mass_eq_of_sum_1 _ _ hwโ, finset.sum_smul], | |
convert finset.sum_filter_add_sum_filter_not _ _ (w โข z) using 2, | |
refine finset.sum_congr rfl (ฮป i hi, _), | |
rw [pi.smul_apply', (finset.mem_filter.1 hi).2] }, | |
rw โthis, | |
have hwโ' : โ i โ t.filter (ฮป i, z i โ x), 0 โค w i := ฮป i hi, hwโ _ $ finset.filter_subset _ _ hi, | |
obtain hw | hw := (finset.sum_nonneg hwโ').eq_or_gt, | |
{ rw [โfinset.sum_filter_add_sum_filter_not _ (ฮป i, z i = x), hw, add_zero] at hwโ, | |
rw [hwโ, one_smul, finset.sum_eq_zero, add_zero], | |
{ exact subset_convex_join_left hs.convex_hull (mem_singleton _) }, | |
simp_rw finset.sum_eq_zero_iff_of_nonneg hwโ' at hw, | |
rintro i hi, | |
rw [hw _ hi, zero_smul] }, | |
refine mem_convex_join.2 โจx, mem_singleton _, (t.filter $ ฮป i, z i โ x).center_mass w z, | |
finset.center_mass_mem_convex_hull _ hwโ' hw (ฮป i hi, _), | |
โ i in t.filter (ฮป i, z i = x), w i, โ i in t.filter (ฮป i, z i โ x), w i, | |
finset.sum_nonneg (ฮป i hi, hwโ _ $ finset.filter_subset _ _ hi), finset.sum_nonneg hwโ', _, _โฉ, | |
{ rw finset.mem_filter at hi, | |
exact mem_of_mem_insert_of_ne (hz _ hi.1) hi.2 }, | |
{ rw [finset.sum_filter_add_sum_filter_not, hwโ] }, | |
{ rw [finset.center_mass, smul_inv_smulโ hw.ne', finset.sum_smul] } | |
end | |
lemma convex_join_segments (a b c d : E) : | |
convex_join ๐ (segment ๐ a b) (segment ๐ c d) = convex_hull ๐ {a, b, c, d} := | |
by simp only [convex_hull_insert, insert_nonempty, singleton_nonempty, convex_hull_pair, | |
โconvex_join_assoc, convex_join_singletons] | |
lemma convex_join_segment_singleton (a b c : E) : | |
convex_join ๐ (segment ๐ a b) {c} = convex_hull ๐ {a, b, c} := | |
by rw [โpair_eq_singleton, โconvex_join_segments, segment_same, pair_eq_singleton] | |
lemma convex_join_singleton_segment (a b c : E) : | |
convex_join ๐ {a} (segment ๐ b c) = convex_hull ๐ {a, b, c} := | |
by rw [โsegment_same ๐, convex_join_segments, insert_idem] | |
protected lemma convex.convex_join (hs : convex ๐ s) (ht : convex ๐ t) : | |
convex ๐ (convex_join ๐ s t) := | |
begin | |
rw convex_iff_segment_subset at โข ht hs, | |
simp_rw mem_convex_join, | |
rintro x y โจxa, hxa, xb, hxb, hxโฉ โจya, hya, yb, hyb, hyโฉ, | |
refine (segment_subset_convex_join hx hy).trans _, | |
have triv : ({xa, xb, ya, yb} : set E) = {xa, ya, xb, yb} := by simp only [set.insert_comm], | |
rw [convex_join_segments, triv, โconvex_join_segments], | |
exact convex_join_mono (hs hxa hya) (ht hxb hyb), | |
end | |
protected lemma convex.convex_hull_union (hs : convex ๐ s) (ht : convex ๐ t) (hsโ : s.nonempty) | |
(htโ : t.nonempty) : | |
convex_hull ๐ (s โช t) = convex_join ๐ s t := | |
(convex_hull_min (union_subset (subset_convex_join_left htโ) $ subset_convex_join_right hsโ) $ | |
hs.convex_join ht).antisymm $ convex_join_subset_convex_hull _ _ | |
lemma convex_hull_union (hs : s.nonempty) (ht : t.nonempty) : | |
convex_hull ๐ (s โช t) = convex_join ๐ (convex_hull ๐ s) (convex_hull ๐ t) := | |
begin | |
rw [โconvex_hull_convex_hull_union_left, โconvex_hull_convex_hull_union_right], | |
exact (convex_convex_hull ๐ s).convex_hull_union (convex_convex_hull ๐ t) | |
hs.convex_hull ht.convex_hull, | |
end | |
end linear_ordered_field | |