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
|
|
|
|
|
2015-04-05 13:27:15 +00:00
|
|
|
|
Module: data.set.basic
|
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-05 10:56:22 +00:00
|
|
|
|
definition set [reducible] (T : Type) := T → Prop
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
2014-07-27 20:18:33 +00:00
|
|
|
|
namespace set
|
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
variable {T : Type}
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- membership and subset -/
|
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
definition mem [reducible] (x : T) (a : set T) := a x
|
|
|
|
|
notation e ∈ a := mem e a
|
|
|
|
|
|
|
|
|
|
theorem setext {a b : set T} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b :=
|
|
|
|
|
funext (take x, propext (H x))
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-06 01:52:13 +00:00
|
|
|
|
definition subset (a b : set T) := ∀⦃x⦄, x ∈ a → x ∈ b
|
2015-04-05 14:12:27 +00:00
|
|
|
|
infix `⊆`:50 := subset
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- bounded quantification -/
|
|
|
|
|
|
2015-04-06 01:52:13 +00:00
|
|
|
|
abbreviation bounded_forall (a : set T) (P : T → 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-04-06 01:52:13 +00:00
|
|
|
|
abbreviation bounded_exists (a : set T) (P : T → 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
|
|
|
|
|
|
|
|
|
definition empty [reducible] : set T := λx, false
|
2014-08-22 23:36:47 +00:00
|
|
|
|
notation `∅` := empty
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem mem_empty (x : T) : ¬ (x ∈ ∅) :=
|
|
|
|
|
assume H : x ∈ ∅, H
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- universal set -/
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
|
|
|
|
definition univ : set T := λx, true
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem mem_univ (x : T) : x ∈ univ := trivial
|
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
|
|
|
|
|
|
|
|
|
definition inter [reducible] (a b : set T) : set T := λ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-04-05 14:12:27 +00:00
|
|
|
|
theorem mem_inter (x : T) (a b : set T) : x ∈ a ∩ b ↔ (x ∈ a ∧ x ∈ b) := !iff.refl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem inter_self (a : set T) : 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-04-05 14:12:27 +00:00
|
|
|
|
theorem inter_empty (a : set T) : a ∩ ∅ = ∅ :=
|
2015-04-05 16:36:54 +00:00
|
|
|
|
setext (take x, !and_false)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem empty_inter (a : set T) : ∅ ∩ a = ∅ :=
|
2015-04-05 16:36:54 +00:00
|
|
|
|
setext (take x, !false_and)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
|
|
|
|
|
theorem inter.comm (a b : set T) : a ∩ b = b ∩ a :=
|
|
|
|
|
setext (take x, !and.comm)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem inter.assoc (a b c : set T) : (a ∩ b) ∩ c = a ∩ (b ∩ c) :=
|
|
|
|
|
setext (take x, !and.assoc)
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
/- union -/
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
definition union [reducible] (a b : set T) : set T := λx, x ∈ a ∨ x ∈ b
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation a ∪ b := union a b
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem mem_union (x : T) (a b : set T) : x ∈ a ∪ b ↔ (x ∈ a ∨ x ∈ b) := !iff.refl
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem union_self (a : set T) : a ∪ a = a :=
|
2015-04-05 16:36:54 +00:00
|
|
|
|
setext (take x, !or_self)
|
2015-03-01 16:23:39 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem union_empty (a : set T) : a ∪ ∅ = a :=
|
2015-04-05 16:36:54 +00:00
|
|
|
|
setext (take x, !or_false)
|
|
|
|
|
|
|
|
|
|
theorem empty_union (a : set T) : ∅ ∪ a = a :=
|
|
|
|
|
setext (take x, !false_or)
|
2015-03-01 16:23:39 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem union.comm (a b : set T) : a ∪ b = b ∪ a :=
|
|
|
|
|
setext (take x, or.comm)
|
2015-03-01 16:23:39 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem union_assoc (a b c : set T) : (a ∪ b) ∪ c = a ∪ (b ∪ c) :=
|
|
|
|
|
setext (take x, or.assoc)
|
2014-08-22 23:36:47 +00:00
|
|
|
|
|
2015-04-05 16:36:54 +00:00
|
|
|
|
/- set-builder notation -/
|
|
|
|
|
|
|
|
|
|
-- {x : T | P}
|
|
|
|
|
definition set_of (P : T → Prop) : set T := P
|
|
|
|
|
notation `{` binders `|` r:(scoped:1 P, set_of P) `}` := r
|
|
|
|
|
|
|
|
|
|
-- {[x, y, z]} or ⦃x, y, z⦄
|
|
|
|
|
definition insert (x : T) (a : set T) : set T := {y : T | y = x ∨ y ∈ a}
|
|
|
|
|
notation `{[`:max a:(foldr `,` (x b, insert x b) ∅) `]}`:0 := a
|
|
|
|
|
notation `⦃` a:(foldr `,` (x b, insert x b) ∅) `⦄` := a
|
|
|
|
|
|
|
|
|
|
/- large unions -/
|
|
|
|
|
|
|
|
|
|
section
|
|
|
|
|
variables {I : Type}
|
|
|
|
|
variable a : set I
|
|
|
|
|
variable b : I → set T
|
|
|
|
|
variable C : set (set T)
|
|
|
|
|
|
|
|
|
|
definition Inter : set T := {x : T | ∀i, x ∈ b i}
|
|
|
|
|
definition bInter : set T := {x : T | ∀₀ i ∈ a, x ∈ b i}
|
|
|
|
|
definition sInter : set T := {x : T | ∀₀ c ∈ C, x ∈ c}
|
|
|
|
|
definition Union : set T := {x : T | ∃i, x ∈ b i}
|
|
|
|
|
definition bUnion : set T := {x : T | ∃₀ i ∈ a, x ∈ b i}
|
|
|
|
|
definition sUnion : set T := {x : T | ∃₀ c ∈ C, x ∈ c}
|
|
|
|
|
|
|
|
|
|
-- TODO: need notation for these
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-07 23:59:08 +00:00
|
|
|
|
end set
|