/- 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 /-! # 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 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