Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/Data/Nat/     Datei vom 15.10.2026 mit Größe 19 kB image not shown  

Quelle  Segment.lean   Sprache: Lean

 

/-
Copyright (c) 2026 Olivia Röhrig. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Olivia Röhrig
-/


module

public import Mathlib.Geometry.Convex.Set

/-!
# Segments in convex spaces

In an R-convex space, we define the following objects:
* `Icc R x y`: Closed segment joining `x` and `y`.
* `Ioo R x y`: Open segment joining `x` and `y`.
* `Ico R x y`: Half-open segment joining `x` and `y`.

## Implementation notes

We don't provide the left-open equivalent to `Set.Ioc` since `Ico x y = Ioc y x`. This is in
contrast to `Set.Ico` and `Set.Ioc`. See also `Ioo_insert_left` and `Ioo_insert_right`.

-/


namespace Convexity

open Convexity Function

@[expose] public section

section Semiring

variable (R) {X} [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] [ConvexSpace R X] {s : Set X}
  {x y z : X}

/-- Segment in a convex space. -/
def Icc (x y : X) : Set X :=
  { z : X | ∃ (a b : R) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1),
    convexCombPair a b ha hb hab x y = z }

/-- Open segment in a convex space. Note that `Ioo R x x = {x}` instead of `∅` if the base
semiring has some element between `0` and `1`. -/

def Ioo (x y : X) : Set X :=
  { z : X | ∃ (a b : R) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1),
    convexCombPair a b ha.le hb.le hab x y = z }

/-- Left-open segment in a convex space. Note that `Ico R x x = {x}` instead of `∅` .
We do not implement a right-open segment `Ioc R a b`. Instead use `Ico R b a`.
-/

def Ico (x y : X) : Set X :=
  { z : X | ∃ (a b : R) (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1),
    convexCombPair a b ha.le hb hab x y = z }

/-- [x,y] = [y,x] -/
theorem Icc_symm (x y : X) : Icc R x y = Icc R y x := by
  ext z
  constructor
  all_goals
  · rintro ⟨m, n, hm , hn , hmn , hz⟩
    rw [convexCombPair_symm] at hz
    exact ⟨n, m, hn, hm, add_comm m n ▸ hmn, hz⟩

/-- (x,y) = (y,x) -/
theorem Ioo_symm (x y : X) : Ioo R x y = Ioo R y x := by
  ext z
  constructor
  all_goals
  · rintro ⟨m, n, hm , hn , hmn , hz⟩
    rw [convexCombPair_symm] at hz
    exact ⟨n, m, hn, hm, add_comm m n ▸ hmn, hz⟩

theorem Ioo_subset_Ico (x y : X) : Ioo R x y ⊆ Ico R x y :=
  fun _ ⟨a, b, ha, hb, hab, hz⟩ ↦ ⟨a, b, ha, hb.le, hab, hz⟩

theorem Ico_subset_Icc (x y : X) : Ico R x y ⊆ Icc R x y :=
  fun _ ⟨a, b, ha, hb, hab, hz⟩ ↦ ⟨a, b, ha.le, hb, hab, hz⟩

theorem Ioo_subset_Icc (x y : X) : Ioo R x y ⊆ Icc R x y :=
  le_trans (Ioo_subset_Ico R x y) (Ico_subset_Icc R x y)

section

variable {R}

theorem convexCombPair_mem_Icc ⦃a b : R⦄ (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
    convexCombPair a b ha hb hab x y ∈ Icc R x y :=
  ⟨a, b, ha, hb, hab, rfl⟩

theorem convexCombPair_mem_Ioo ⦃a b : R⦄ (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
    convexCombPair a b ha.le hb.le hab x y ∈ Ioo R x y :=
  ⟨a, b, ha, hb, hab, rfl⟩

theorem convexCombPair_mem_Ico ⦃a b : R⦄ (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) :
    convexCombPair a b ha.le hb hab x y ∈ Ico R x y :=
  ⟨a, b, ha, hb, hab, rfl⟩

theorem forall_mem_Icc_iff (p : X → Prop) :
    (∀ z ∈ Icc R x y, p z) ↔ ∀ ⦃a b : R⦄ (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1),
      p (convexCombPair a b ha hb hab x y) := by
  grind [Icc]

theorem forall_mem_Ioo_iff (p : X → Prop) :
   (∀ z ∈ Ioo R x y, p z) ↔ ∀ ⦃a b : R⦄ (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1),
      p (convexCombPair a b ha.le hb.le hab x y) := by
  grind [Ioo]

theorem forall_mem_Ico_iff (p : X → Prop) :
    (∀ z ∈ Ico R x y, p z) ↔ ∀ ⦃a b : R⦄ (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1),
      p (convexCombPair a b ha.le hb hab x y) := by
  grind [Ico]

theorem Icc_subset_iff :
    Icc R x y ⊆ s ↔ ∀ ⦃a b : R⦄ (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1),
      convexCombPair a b ha hb hab x y ∈ s :=
  forall_mem_Icc_iff ..

theorem Ioo_subset_iff :
    Ioo R x y ⊆ s ↔ ∀ ⦃a b : R⦄ (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1),
      convexCombPair a b ha.le hb.le hab x y ∈ s :=
  forall_mem_Ioo_iff ..

theorem Ico_subset_iff :
    Ico R x y ⊆ s ↔ ∀ ⦃a b : R⦄ (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1),
      convexCombPair a b ha.le hb hab x y ∈ s :=
  forall_mem_Ico_iff ..

end

@[simp]
theorem left_mem_Icc (x y : X) : x ∈ Icc R x y :=
  ⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [convexCombPair_one]⟩

@[simp]
theorem right_mem_Icc (x y : X) : y ∈ Icc R x y :=
  Icc_symm R y x ▸ left_mem_Icc R y x

@[simp]
theorem left_mem_Ico (x y : X) : x ∈ Ico R x y :=
  ⟨1, 0, zero_lt_one, le_refl 0, add_zero 1, convexCombPair_one⟩

variable {R} in
theorem Icc_subset_iff_mem_of_isConvexSet (hs : IsConvexSet R s) (x y : X) :
    Icc R x y ⊆ s ↔ x ∈ s ∧ y ∈ s := by
  refine ⟨fun h ↦ ⟨h <| left_mem_Icc R x y, h <| right_mem_Icc R x y⟩, ?_⟩
  rintro ⟨hx, hy⟩ z ⟨a, b, ha, hb, hab, rfl⟩
  apply hs.convexCombPair_mem hx hy

@[simp]
theorem Icc_self (x : X) : Icc R x x = {x} :=
  Set.ext <| fun z ↦ ⟨by simp +contextual [Icc], by simp +contextual⟩

theorem Ioo_subset_singleton (x : X) : Ioo R x x ⊆ {x} :=
  fun _ ⟨_, _, _, _, _, h⟩ => h ▸ convexCombPair_same ..

@[simp]
theorem Ico_self (x : X) : Ico R x x = {x} := by
  apply Set.Subset.antisymm
  · rw [← Icc_self R x]; exact Ico_subset_Icc R x x
  · simp [left_mem_Ico]

@[simp]
theorem Ioo_insert_left (x y : X) : insert x (Ioo R x y) = Ico R x y := by
  simp only [subset_antisymm_iff, Set.insert_subset_iff, left_mem_Ico, Ioo_subset_Ico, and_self,
    true_and]
  rintro z ⟨a, b, ha, hb', hab, rfl⟩
  by_cases hb : 0 < b
  · exact Set.mem_insert_of_mem x (convexCombPair_mem_Ioo ha hb hab)
  · rw [← eq_of_le_of_not_lt hb' hb] at hab
    simp [← eq_of_le_of_not_lt hb' hb, add_zero a ▸ hab]

@[simp]
theorem Ioo_insert_right (x y : X) : insert y (Ioo R x y) = Ico R y x := by
  rw [Ioo_symm, Ioo_insert_left]

@[simp]
theorem Ico_insert (x y : X) : insert y (Ico R x y) = Icc R x y := by
  simp only [subset_antisymm_iff, Set.insert_subset_iff, right_mem_Icc, Ico_subset_Icc, true_and]
  rintro z ⟨a, b, ha, hb, hab, rfl⟩
  refine ha.eq_or_lt.imp ?_ (fun hal ↦ convexCombPair_mem_Ico hal hb hab)
  rintro rfl
  simp [zero_add b ▸ hab]

namespace IsAffineMap

variable {R} {Y} [ConvexSpace R Y] {f : X → Y}

theorem image_Icc (hf : IsAffineMap R f) (a b : X) : f '' Icc R a b = Icc R (f a) (f b) :=
  Set.ext fun _ ↦ by simp [Icc, hf.map_convexCombPair]

theorem mem_Icc_image (hf : IsAffineMap R f) {a b c : X} (h : c ∈ Icc R a b) :
    f c ∈ Icc R (f a) (f b) := by
  rw [← image_Icc hf, Set.mem_image]
  exact ⟨c, h, rfl⟩

theorem image_Ioo (hf : IsAffineMap R f) (a b : X) : f '' Ioo R a b = Ioo R (f a) (f b) :=
  Set.ext fun _ ↦ by simp [Ioo, hf.map_convexCombPair]

theorem mem_Ioo_image (hf : IsAffineMap R f) {a b c : X} (h : c ∈ Ioo R a b) :
    f c ∈ Ioo R (f a) (f b) := by
  rw [← image_Ioo hf, Set.mem_image]
  exact ⟨c, h, rfl⟩

theorem image_Ico (hf : IsAffineMap R f) (a b : X) : f '' Ico R a b = Ico R (f a) (f b) :=
  Set.ext fun _ ↦ by simp [Ico, hf.map_convexCombPair]

theorem mem_Ico_image (hf : IsAffineMap R f) {a b c : X} (h : c ∈ Ico R a b) :
    f c ∈ Ico R (f a) (f b) := by
  rw [← image_Ico hf, Set.mem_image]
  exact ⟨c, h, rfl⟩

end IsAffineMap

namespace Prod

variable {Y} [ConvexSpace R Y]

theorem Icc_subset (x y : X × Y) : Icc R x y ⊆ Icc R x.1 y.1 ×ˢ Icc R x.2 y.2 := by
  rintro z ⟨a, b, ha, hb, hab, rfl⟩
  simp [convexCombPair_mem_Icc]

theorem Ioo_subset (x y : X × Y) : Ioo R x y ⊆ Ioo R x.1 y.1 ×ˢ Ioo R x.2 y.2 := by
  rintro z ⟨a, b, ha, hb, hab, rfl⟩
  simp [convexCombPair_mem_Ioo ha hb]

theorem Ico_subset (x y : X × Y) : Ico R x y ⊆ Ico R x.1 y.1 ×ˢ Ico R x.2 y.2 := by
  rintro z ⟨a, b, ha, hb, hab, rfl⟩
  simp [convexCombPair_mem_Ico ha hb]

end Prod

end Semiring

section DenselyOrdered

variable (R) {X} [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [ConvexSpace R X]
  [DenselyOrdered R]

@[simp]
theorem Ioo_self (x : X) : Ioo R x x = {x} := by
  ext
  refine ⟨by simp +contextual [Ioo], ?_⟩
  obtain ⟨a, ha₀, ha₁⟩ := exists_between (α := R) zero_lt_one
  refine fun h ↦ ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel .., ?_⟩
  rw [convexCombPair_same, Set.mem_singleton_iff.mp h]

end DenselyOrdered

section Field

variable (K) {X} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [ConvexSpace K X] {s : Set X}

theorem isConvexSet_iff_Icc_subset_of_mem : IsConvexSet K s ↔ ∀ x ∈ s, ∀ y ∈ s, Icc K x y ⊆ s := by
  refine ⟨fun h x hx y hy ↦ ?_, fun h ↦ IsConvexSet.of_convexCombPair_mem ?_⟩
  · exact (Icc_subset_iff_mem_of_isConvexSet h x y).mpr ⟨hx, hy⟩
  · intro a b ha hb hab x hx y hy
    apply h x hx y hy
    exact ⟨a, b, ha, hb, hab, by simp⟩

end Field

end

end Convexity

Messung
CHZG
9210010097

¤ Dauer der Verarbeitung: 0.9 Sekunden  ¤

*© Formatika GbR, Deutschland