2014-12-22 20:33:29 +00:00
|
|
|
|
/-
|
2015-04-05 14:12:27 +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-04-05 14:12:27 +00:00
|
|
|
|
definition set (T : Type) := T → Prop
|
|
|
|
|
|
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 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-05 14:12:27 +00:00
|
|
|
|
definition subset (a b : set T) := ∀ x, x ∈ a → x ∈ b
|
|
|
|
|
infix `⊆`:50 := subset
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
definition eq_of_subset_of_subset (a b : set T) (H₁ : a ⊆ b) (H₂ : b ⊆ a) : a = b :=
|
|
|
|
|
setext (take x, iff.intro (H₁ x) (H₂ x))
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
/- empty -/
|
|
|
|
|
|
|
|
|
|
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 14:12:27 +00:00
|
|
|
|
/- univ -/
|
|
|
|
|
|
|
|
|
|
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 14:12:27 +00:00
|
|
|
|
/- inter -/
|
|
|
|
|
|
|
|
|
|
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 :=
|
|
|
|
|
setext (take x, iff.intro
|
2015-03-01 16:23:39 +00:00
|
|
|
|
(assume H, and.elim_left H)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
(assume H, and.intro H H))
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem inter_empty (a : set T) : a ∩ ∅ = ∅ :=
|
|
|
|
|
setext (take x, iff.intro
|
2015-03-01 16:23:39 +00:00
|
|
|
|
(assume H, and.elim_right H)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
(assume H, false.elim H))
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem empty_inter (a : set T) : ∅ ∩ a = ∅ :=
|
|
|
|
|
setext (take x, iff.intro
|
2015-03-01 16:23:39 +00:00
|
|
|
|
(assume H, and.elim_left H)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
(assume H, false.elim H))
|
|
|
|
|
|
|
|
|
|
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 :=
|
|
|
|
|
setext (take x, iff.intro
|
2015-03-01 16:23:39 +00:00
|
|
|
|
(assume H,
|
|
|
|
|
match H with
|
|
|
|
|
| or.inl H₁ := H₁
|
|
|
|
|
| or.inr H₂ := H₂
|
|
|
|
|
end)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
(assume H, or.inl H))
|
2015-03-01 16:23:39 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem union_empty (a : set T) : a ∪ ∅ = a :=
|
|
|
|
|
setext (take x, iff.intro
|
2015-03-01 16:23:39 +00:00
|
|
|
|
(assume H, match H with
|
|
|
|
|
| or.inl H₁ := H₁
|
|
|
|
|
| or.inr H₂ := false.elim H₂
|
|
|
|
|
end)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
(assume H, or.inl H))
|
2015-03-01 16:23:39 +00:00
|
|
|
|
|
2015-04-05 14:12:27 +00:00
|
|
|
|
theorem union_empty_left (a : set T) : ∅ ∪ a = a :=
|
|
|
|
|
setext (take x, iff.intro
|
2015-03-01 16:23:39 +00:00
|
|
|
|
(assume H, match H with
|
|
|
|
|
| or.inl H₁ := false.elim H₁
|
|
|
|
|
| or.inr H₂ := H₂
|
|
|
|
|
end)
|
2015-04-05 14:12:27 +00:00
|
|
|
|
(assume H, or.inr H))
|
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
|
|
|
|
|
2014-08-07 23:59:08 +00:00
|
|
|
|
end set
|