2014-12-22 20:33:29 +00:00
|
|
|
|
/-
|
2015-04-06 01:52:13 +00:00
|
|
|
|
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
2014-12-22 20:33:29 +00:00
|
|
|
|
Author: Jeremy Avigad, Leonardo de Moura
|
|
|
|
|
-/
|
2015-03-01 16:23:39 +00:00
|
|
|
|
import logic
|
|
|
|
|
open eq.ops
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
definition set [reducible] (X : Type) := X → Prop
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
2014-07-27 20:18:33 +00:00
|
|
|
|
namespace set
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
variable {X : Type}
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- membership and subset -/
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
definition mem [reducible] (x : X) (a : set X) := a x
|
|
|
|
|
infix `∈` := mem
|
|
|
|
|
notation a ∉ b := ¬ mem a b
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem setext {a b : set X} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b :=
|
2015-04-05 14:12:27 +00:00
|
|
|
|
funext (take x, propext (H x))
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
definition subset (a b : set X) := ∀⦃x⦄, x ∈ a → x ∈ b
|
2015-05-20 08:33:59 +00:00
|
|
|
|
infix `⊆` := subset
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-06-04 08:51:34 +00:00
|
|
|
|
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)
|
|
|
|
|
|
2015-06-17 16:53:50 +00:00
|
|
|
|
theorem subset.antisymm (a b : set X) (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
|
|
|
|
|
setext (λ x, iff.intro (λ ina, h₁ ina) (λ inb, h₂ inb))
|
|
|
|
|
|
|
|
|
|
definition strict_subset (a b : set X) := a ⊆ b ∧ a ≠ b
|
|
|
|
|
infix `⊂`:50 := strict_subset
|
|
|
|
|
|
|
|
|
|
theorem strict_subset.irrefl (a : set X) : ¬ a ⊂ a :=
|
|
|
|
|
assume h, absurd rfl (and.elim_right h)
|
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- bounded quantification -/
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
abbreviation bounded_forall (a : set X) (P : X → Prop) := ∀⦃x⦄, x ∈ a → P x
|
2015-04-05 16:36:54 +00:00
|
|
|
|
notation `forallb` binders `∈` a `,` r:(scoped:1 P, P) := bounded_forall a r
|
|
|
|
|
notation `∀₀` binders `∈` a `,` r:(scoped:1 P, P) := bounded_forall a r
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
abbreviation bounded_exists (a : set X) (P : X → Prop) := ∃⦃x⦄, x ∈ a ∧ P x
|
2015-04-05 16:36:54 +00:00
|
|
|
|
notation `existsb` binders `∈` a `,` r:(scoped:1 P, P) := bounded_exists a r
|
|
|
|
|
notation `∃₀` binders `∈` a `,` r:(scoped:1 P, P) := bounded_exists a r
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- empty set -/
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
definition empty [reducible] : set X := λx, false
|
2014-08-22 23:36:47 +00:00
|
|
|
|
notation `∅` := empty
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem not_mem_empty (x : X) : ¬ (x ∈ ∅) :=
|
2015-03-01 16:23:39 +00:00
|
|
|
|
assume H : x ∈ ∅, H
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem mem_empty_eq (x : X) : x ∈ ∅ = false := rfl
|
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- universal set -/
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
definition univ : set X := λx, true
|
|
|
|
|
|
|
|
|
|
theorem mem_univ (x : X) : x ∈ univ := trivial
|
|
|
|
|
|
|
|
|
|
theorem mem_univ_eq (x : X) : x ∈ univ = true := rfl
|
|
|
|
|
|
2015-06-17 16:53:50 +00:00
|
|
|
|
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 _))
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
/- union -/
|
|
|
|
|
|
|
|
|
|
definition union [reducible] (a b : set X) : set X := λx, x ∈ a ∨ x ∈ b
|
|
|
|
|
notation a ∪ b := union a b
|
|
|
|
|
|
|
|
|
|
theorem mem_union (x : X) (a b : set X) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := !iff.refl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem mem_union_eq (x : X) (a b : set X) : x ∈ a ∪ b = (x ∈ a ∨ x ∈ b) := rfl
|
|
|
|
|
|
|
|
|
|
theorem union_self (a : set X) : a ∪ a = a :=
|
|
|
|
|
setext (take x, !or_self)
|
|
|
|
|
|
|
|
|
|
theorem union_empty (a : set X) : a ∪ ∅ = a :=
|
|
|
|
|
setext (take x, !or_false)
|
|
|
|
|
|
|
|
|
|
theorem empty_union (a : set X) : ∅ ∪ a = a :=
|
|
|
|
|
setext (take x, !false_or)
|
|
|
|
|
|
|
|
|
|
theorem union.comm (a b : set X) : a ∪ b = b ∪ a :=
|
|
|
|
|
setext (take x, or.comm)
|
|
|
|
|
|
2015-06-17 16:53:50 +00:00
|
|
|
|
theorem union.assoc (a b c : set X) : (a ∪ b) ∪ c = a ∪ (b ∪ c) :=
|
2015-05-08 02:52:46 +00:00
|
|
|
|
setext (take x, or.assoc)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- intersection -/
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
definition inter [reducible] (a b : set X) : set X := λx, x ∈ a ∧ x ∈ b
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation a ∩ b := inter a b
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem mem_inter (x : X) (a b : set X) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := !iff.refl
|
|
|
|
|
|
|
|
|
|
theorem mem_inter_eq (x : X) (a b : set X) : x ∈ a ∩ b = (x ∈ a ∧ x ∈ b) := rfl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem inter_self (a : set X) : a ∩ a = a :=
|
2015-04-05 16:36:54 +00:00
|
|
|
|
setext (take x, !and_self)
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem inter_empty (a : set X) : a ∩ ∅ = ∅ :=
|
2015-04-05 16:36:54 +00:00
|
|
|
|
setext (take x, !and_false)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem empty_inter (a : set X) : ∅ ∩ a = ∅ :=
|
2015-04-05 16:36:54 +00:00
|
|
|
|
setext (take x, !false_and)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem inter.comm (a b : set X) : a ∩ b = b ∩ a :=
|
2015-04-05 14:12:27 +00:00
|
|
|
|
setext (take x, !and.comm)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem inter.assoc (a b c : set X) : (a ∩ b) ∩ c = a ∩ (b ∩ c) :=
|
2015-04-05 14:12:27 +00:00
|
|
|
|
setext (take x, !and.assoc)
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-06-17 16:53:50 +00:00
|
|
|
|
theorem inter_univ (a : set X) : a ∩ univ = a :=
|
|
|
|
|
setext (take x, !and_true)
|
|
|
|
|
|
|
|
|
|
theorem univ_inter (a : set X) : univ ∩ a = a :=
|
|
|
|
|
setext (take x, !true_and)
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
/- distributivity laws -/
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem inter.distrib_left (s t u : set X) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) :=
|
|
|
|
|
setext (take x, !and.distrib_left)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem inter.distrib_right (s t u : set X) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) :=
|
|
|
|
|
setext (take x, !and.distrib_right)
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem union.distrib_left (s t u : set X) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) :=
|
|
|
|
|
setext (take x, !or.distrib_left)
|
2015-03-01 16:23:39 +00:00
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
theorem union.distrib_right (s t u : set X) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) :=
|
|
|
|
|
setext (take x, !or.distrib_right)
|
2014-08-22 23:36:47 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- set-builder notation -/
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
-- {x : X | P}
|
|
|
|
|
definition set_of (P : X → Prop) : set X := P
|
2015-04-05 16:36:54 +00:00
|
|
|
|
notation `{` binders `|` r:(scoped:1 P, set_of P) `}` := r
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
-- {x ∈ s | P}
|
|
|
|
|
definition filter (P : X → Prop) (s : set X) : set X := λx, x ∈ s ∧ P x
|
|
|
|
|
notation `{` binders ∈ s `|` r:(scoped:1 p, filter p s) `}` := r
|
|
|
|
|
|
2015-05-16 07:47:31 +00:00
|
|
|
|
-- {[x, y, z]}
|
2015-05-08 02:52:46 +00:00
|
|
|
|
definition insert (x : X) (a : set X) : set X := {y : X | y = x ∨ y ∈ a}
|
2015-04-05 16:36:54 +00:00
|
|
|
|
notation `{[`:max a:(foldr `,` (x b, insert x b) ∅) `]}`:0 := a
|
|
|
|
|
|
2015-05-08 02:52:46 +00:00
|
|
|
|
/- set difference -/
|
|
|
|
|
|
|
|
|
|
definition diff (s t : set X) : set X := {x ∈ s | x ∉ t}
|
|
|
|
|
infix `\`:70 := diff
|
|
|
|
|
|
|
|
|
|
theorem mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∈ s :=
|
|
|
|
|
and.left H
|
|
|
|
|
|
|
|
|
|
theorem not_mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∉ t :=
|
|
|
|
|
and.right H
|
|
|
|
|
|
|
|
|
|
theorem mem_diff {s t : set X} {x : X} (H1 : x ∈ s) (H2 : x ∉ t) : x ∈ s \ t :=
|
|
|
|
|
and.intro H1 H2
|
|
|
|
|
|
|
|
|
|
theorem mem_diff_iff (s t : set X) (x : X) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := !iff.refl
|
|
|
|
|
|
|
|
|
|
theorem mem_diff_eq (s t : set X) (x : X) : x ∈ s \ t = (x ∈ s ∧ x ∉ t) := rfl
|
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- large unions -/
|
|
|
|
|
|
|
|
|
|
section
|
|
|
|
|
variables {I : Type}
|
|
|
|
|
variable a : set I
|
2015-05-08 02:52:46 +00:00
|
|
|
|
variable b : I → set X
|
|
|
|
|
variable C : set (set X)
|
|
|
|
|
|
|
|
|
|
definition Inter : set X := {x : X | ∀i, x ∈ b i}
|
|
|
|
|
definition bInter : set X := {x : X | ∀₀ i ∈ a, x ∈ b i}
|
|
|
|
|
definition sInter : set X := {x : X | ∀₀ c ∈ C, x ∈ c}
|
|
|
|
|
definition Union : set X := {x : X | ∃i, x ∈ b i}
|
|
|
|
|
definition bUnion : set X := {x : X | ∃₀ i ∈ a, x ∈ b i}
|
|
|
|
|
definition sUnion : set X := {x : X | ∃₀ c ∈ C, x ∈ c}
|
2015-04-05 16:36:54 +00:00
|
|
|
|
|
|
|
|
|
-- TODO: need notation for these
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-07 23:59:08 +00:00
|
|
|
|
end set
|