Spectral/set.hlean

187 lines
5.1 KiB
Text
Raw Normal View History

2017-03-31 18:31:56 +00:00
/-
Copyright (c) 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
2017-03-31 20:36:35 +00:00
import types.trunc .logic
open funext eq trunc is_trunc logic
2017-03-31 18:31:56 +00:00
definition set (X : Type) := X → Prop
namespace set
variable {X : Type}
/- membership and subset -/
definition mem (x : X) (a : set X) := a x
infix ∈ := mem
notation a ∉ b := ¬ mem a b
2017-04-07 19:12:31 +00:00
/-theorem ext {a b : set X} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b :=
2017-03-31 18:31:56 +00:00
eq_of_homotopy (take x, propext (H x))
2017-04-07 19:12:31 +00:00
-/
2017-03-31 18:31:56 +00:00
definition subset (a b : set X) : Prop := Prop.mk (∀⦃x⦄, x ∈ a → x ∈ b) _
infix ⊆ := subset
definition superset (s t : set X) : Prop := t ⊆ s
infix ⊇ := superset
theorem subset.refl (a : set X) : a ⊆ a := take x, assume H, H
theorem subset.trans {a b c : set X} (subab : a ⊆ b) (subbc : b ⊆ c) : a ⊆ c :=
take x, assume ax, subbc (subab ax)
2017-04-07 19:12:31 +00:00
/-
2017-03-31 18:31:56 +00:00
theorem subset.antisymm {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
ext (λ x, iff.intro (λ ina, h₁ ina) (λ inb, h₂ inb))
2017-04-07 19:12:31 +00:00
-/
2017-03-31 18:31:56 +00:00
-- an alterantive name
2017-04-07 19:12:31 +00:00
/-
2017-03-31 18:31:56 +00:00
theorem eq_of_subset_of_subset {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
subset.antisymm h₁ h₂
2017-04-07 19:12:31 +00:00
-/
2017-03-31 18:31:56 +00:00
theorem mem_of_subset_of_mem {s₁ s₂ : set X} {a : X} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ :=
assume h₁ h₂, h₁ _ h₂
/- empty set -/
2017-03-31 20:36:35 +00:00
definition empty : set X := λx, false
2017-04-07 19:12:31 +00:00
notation `∅` := set.empty
2017-03-31 18:31:56 +00:00
theorem not_mem_empty (x : X) : ¬ (x ∈ ∅) :=
2017-04-07 19:12:31 +00:00
assume H : x ∈ ∅, false.elim H
2017-03-31 18:31:56 +00:00
2017-03-31 20:36:35 +00:00
theorem mem_empty_eq (x : X) : x ∈ ∅ = false := rfl
2017-03-31 18:31:56 +00:00
2017-04-07 19:12:31 +00:00
/-
2017-03-31 18:31:56 +00:00
theorem eq_empty_of_forall_not_mem {s : set X} (H : ∀ x, x ∉ s) : s = ∅ :=
ext (take x, iff.intro
(assume xs, absurd xs (H x))
2017-03-31 20:36:35 +00:00
(assume xe, absurd xe (not_mem_empty x)))
2017-04-07 19:12:31 +00:00
-/
set_option formatter.hide_full_terms false
2017-03-31 18:31:56 +00:00
theorem ne_empty_of_mem {s : set X} {x : X} (H : x ∈ s) : s ≠ ∅ :=
2017-03-31 20:36:35 +00:00
begin intro Hs, rewrite Hs at H, apply not_mem_empty x H end
2017-03-31 18:31:56 +00:00
2017-04-07 19:12:31 +00:00
2017-03-31 18:31:56 +00:00
theorem empty_subset (s : set X) : ∅ ⊆ s :=
2017-04-07 19:12:31 +00:00
take x, assume H, false.elim H
2017-03-31 18:31:56 +00:00
2017-04-07 19:12:31 +00:00
/-theorem eq_empty_of_subset_empty {s : set X} (H : s ⊆ ∅) : s = ∅ :=
2017-03-31 18:31:56 +00:00
subset.antisymm H (empty_subset s)
theorem subset_empty_iff (s : set X) : s ⊆ ∅ ↔ s = ∅ :=
iff.intro eq_empty_of_subset_empty (take xeq, by rewrite xeq; apply subset.refl ∅)
2017-04-07 19:12:31 +00:00
-/
2017-03-31 18:31:56 +00:00
2017-03-31 20:36:35 +00:00
/- universal set -/
definition univ : set X := λx, true
theorem mem_univ (x : X) : x ∈ univ := trivial
theorem mem_univ_eq (x : X) : x ∈ univ = true := rfl
theorem empty_ne_univ [h : inhabited X] : (empty : set X) ≠ univ :=
assume H : empty = univ,
absurd (mem_univ (inhabited.value h)) (eq.rec_on H (not_mem_empty (arbitrary X)))
2017-04-07 19:12:31 +00:00
theorem subset_univ (s : set X) : s ⊆ univ := λ x H, trivial
2017-03-31 20:36:35 +00:00
2017-04-07 19:12:31 +00:00
/-
2017-03-31 20:36:35 +00:00
theorem eq_univ_of_univ_subset {s : set X} (H : univ ⊆ s) : s = univ :=
eq_of_subset_of_subset (subset_univ s) H
2017-04-07 19:12:31 +00:00
-/
2017-03-31 20:36:35 +00:00
2017-04-07 19:12:31 +00:00
/-
2017-03-31 20:36:35 +00:00
theorem eq_univ_of_forall {s : set X} (H : ∀ x, x ∈ s) : s = univ :=
2017-04-07 19:12:31 +00:00
ext (take x, iff.intro (assume H', trivial) (assume H', H x))
-/
2017-03-31 20:36:35 +00:00
/- set-builder notation -/
-- {x : X | P}
definition set_of (P : X → Prop) : set X := P
notation `{` binder ` | ` r:(scoped:1 P, set_of P) `}` := r
2017-04-07 19:12:31 +00:00
theorem mem_set_of {P : X → Prop} {a : X} (h : P a) : a ∈ {x | P x} := h
theorem of_mem_set_of {P : X → Prop} {a : X} (h : a ∈ {x | P x}) : P a := h
2017-03-31 20:36:35 +00:00
-- {x ∈ s | P}
definition sep (P : X → Prop) (s : set X) : set X := λx, x ∈ s ∧ P x
notation `{` binder ` ∈ ` s ` | ` r:(scoped:1 p, sep p s) `}` := r
/- insert -/
definition insert (x : X) (a : set X) : set X := {y : X | y = x y ∈ a}
2017-04-07 19:12:31 +00:00
abbreviation insert_same_level.{u} := @insert.{u u}
2017-03-31 20:36:35 +00:00
-- '{x, y, z}
2017-04-07 19:12:31 +00:00
notation `'{`:max a:(foldr `, ` (x b, insert_same_level x b) ∅) `}`:0 := a
2017-03-31 20:36:35 +00:00
theorem subset_insert (x : X) (a : set X) : a ⊆ insert x a :=
take y, assume ys, or.inr ys
theorem mem_insert (x : X) (s : set X) : x ∈ insert x s :=
or.inl rfl
theorem mem_insert_of_mem {x : X} {s : set X} (y : X) : x ∈ s → x ∈ insert y s :=
assume h, or.inr h
theorem eq_or_mem_of_mem_insert {x a : X} {s : set X} : x ∈ insert a s → x = a x ∈ s :=
assume h, h
2017-03-31 18:31:56 +00:00
2017-04-07 19:12:31 +00:00
/- singleton -/
open trunc_index
theorem mem_singleton_iff {X : Type} [is_set X] (a b : X) : a ∈ '{b} ↔ a = b :=
iff.intro
(assume ainb, or.elim ainb (λ aeqb, aeqb) (λ f, false.elim f))
(assume aeqb, or.inl aeqb)
theorem mem_singleton (a : X) : a ∈ '{a} := !mem_insert
theorem eq_of_mem_singleton {X : Type} [is_set X] {x y : X} (h : x ∈ '{y}) : x = y :=
or.elim (eq_or_mem_of_mem_insert h)
(suppose x = y, this)
(suppose x ∈ ∅, absurd this (not_mem_empty x))
theorem mem_singleton_of_eq {x y : X} (H : x = y) : x ∈ '{y} :=
eq.symm H ▸ mem_singleton y
/-
theorem insert_eq (x : X) (s : set X) : insert x s = '{x} s :=
ext (take y, iff.intro
(suppose y ∈ insert x s,
or.elim this (suppose y = x, or.inl (or.inl this)) (suppose y ∈ s, or.inr this))
(suppose y ∈ '{x} s,
or.elim this
(suppose y ∈ '{x}, or.inl (eq_of_mem_singleton this))
(suppose y ∈ s, or.inr this)))
-/
/-
theorem pair_eq_singleton (a : X) : '{a, a} = '{a} :=
by rewrite [insert_eq_of_mem !mem_singleton]
-/
/-
theorem singleton_ne_empty (a : X) : '{a} ≠ ∅ :=
begin
intro H,
apply not_mem_empty a,
rewrite -H,
apply mem_insert
end
-/
2017-03-31 18:31:56 +00:00
end set