2023-05-12 13:05:31 +00:00
|
|
|
|
import Mathlib.Data.Set.Basic
|
2023-04-11 12:46:59 +00:00
|
|
|
|
|
2023-05-12 13:05:31 +00:00
|
|
|
|
/-! # Common.Set.Basic
|
2023-05-04 22:37:54 +00:00
|
|
|
|
|
2023-05-15 14:00:01 +00:00
|
|
|
|
Additional theorems and definitions useful in the context of `Set`s.
|
2023-05-04 22:37:54 +00:00
|
|
|
|
-/
|
|
|
|
|
|
2023-05-12 13:05:31 +00:00
|
|
|
|
namespace Set
|
2023-04-11 12:46:59 +00:00
|
|
|
|
|
2023-05-22 00:32:59 +00:00
|
|
|
|
/-! ## Minkowski Sum -/
|
|
|
|
|
|
2023-05-12 13:05:31 +00:00
|
|
|
|
/-
|
2023-05-22 00:32:59 +00:00
|
|
|
|
The Minkowski sum of two `Set`s `s` and `t` is the set
|
2023-04-11 12:46:59 +00:00
|
|
|
|
`s + t = { a + b : a ∈ s, b ∈ t }`.
|
|
|
|
|
-/
|
2023-05-12 17:08:18 +00:00
|
|
|
|
def minkowskiSum {α : Type u} [Add α] (s t : Set α) :=
|
2023-04-11 12:46:59 +00:00
|
|
|
|
{ x | ∃ a ∈ s, ∃ b ∈ t, x = a + b }
|
|
|
|
|
|
2023-04-13 19:58:38 +00:00
|
|
|
|
/--
|
2023-05-22 00:32:59 +00:00
|
|
|
|
The sum of two `Set`s is nonempty **iff** the summands are nonempty.
|
2023-04-13 19:58:38 +00:00
|
|
|
|
-/
|
2023-05-12 13:05:31 +00:00
|
|
|
|
theorem nonempty_minkowski_sum_iff_nonempty_add_nonempty {α : Type u} [Add α]
|
|
|
|
|
{s t : Set α}
|
2023-05-12 17:08:18 +00:00
|
|
|
|
: (minkowskiSum s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by
|
2023-04-13 19:58:38 +00:00
|
|
|
|
apply Iff.intro
|
|
|
|
|
· intro h
|
|
|
|
|
have ⟨x, hx⟩ := h
|
|
|
|
|
have ⟨a, ⟨ha, ⟨b, ⟨hb, _⟩⟩⟩⟩ := hx
|
|
|
|
|
apply And.intro
|
|
|
|
|
· exact ⟨a, ha⟩
|
|
|
|
|
· exact ⟨b, hb⟩
|
|
|
|
|
· intro ⟨⟨a, ha⟩, ⟨b, hb⟩⟩
|
|
|
|
|
exact ⟨a + b, ⟨a, ⟨ha, ⟨b, ⟨hb, rfl⟩⟩⟩⟩⟩
|
|
|
|
|
|
2023-05-22 00:32:59 +00:00
|
|
|
|
/-! ## Characteristic Function -/
|
|
|
|
|
|
2023-05-12 13:05:31 +00:00
|
|
|
|
/--
|
2023-05-22 00:32:59 +00:00
|
|
|
|
The characteristic function of a `Set` `S`.
|
2023-05-12 13:05:31 +00:00
|
|
|
|
|
|
|
|
|
It returns `1` if the specified input belongs to `S` and `0` otherwise.
|
|
|
|
|
-/
|
2023-05-12 19:17:34 +00:00
|
|
|
|
def characteristic (S : Set α) (x : α) [Decidable (x ∈ S)] : Nat :=
|
2023-05-12 13:05:31 +00:00
|
|
|
|
if x ∈ S then 1 else 0
|
|
|
|
|
|
2023-05-22 00:32:59 +00:00
|
|
|
|
/-! ## Subsets -/
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
Every `Set` is a subset of itself.
|
|
|
|
|
-/
|
|
|
|
|
theorem subset_self (S : Set α) : S ⊆ S := by
|
|
|
|
|
intro _ hs
|
|
|
|
|
exact hs
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
If `Set` `A` is a subset of `Set` `B`, then `A ∪ B = B`.
|
|
|
|
|
-/
|
|
|
|
|
theorem left_subset_union_eq_self {A B : Set α} (h : A ⊆ B)
|
|
|
|
|
: A ∪ B = B := by
|
|
|
|
|
rw [Set.ext_iff]
|
|
|
|
|
intro x
|
|
|
|
|
apply Iff.intro
|
|
|
|
|
· intro hU
|
|
|
|
|
apply Or.elim hU
|
|
|
|
|
· intro hA
|
|
|
|
|
exact h hA
|
|
|
|
|
· simp
|
|
|
|
|
· intro hB
|
|
|
|
|
exact Or.inr hB
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
If `Set` `B` is a subset of `Set` `A`, then `A ∪ B = B`.
|
|
|
|
|
-/
|
|
|
|
|
theorem right_subset_union_eq_self {A B : Set α} (h : B ⊆ A)
|
|
|
|
|
: A ∪ B = A := by
|
|
|
|
|
rw [Set.union_comm]
|
|
|
|
|
exact left_subset_union_eq_self h
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
If `x` and `y` are members of `Set` `A`, it follows `{x, y}` is a subset of `A`.
|
|
|
|
|
-/
|
|
|
|
|
theorem mem_mem_imp_pair_subset {x y : α}
|
|
|
|
|
(hx : x ∈ A) (hy : y ∈ A) : ({x, y} : Set α) ⊆ A := by
|
|
|
|
|
intro a ha
|
|
|
|
|
apply Or.elim ha
|
|
|
|
|
· intro hx'
|
|
|
|
|
rwa [hx']
|
|
|
|
|
· intro hy'
|
|
|
|
|
rwa [hy']
|
|
|
|
|
|
2023-05-12 13:05:31 +00:00
|
|
|
|
end Set
|