2014-12-22 20:33:29 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
|
|
Module: data.set
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
namespace set
|
2014-08-26 05:54:44 +00:00
|
|
|
|
definition set (T : Type) :=
|
2015-03-01 16:23:39 +00:00
|
|
|
|
T → Prop
|
2015-01-09 02:47:44 +00:00
|
|
|
|
definition mem [reducible] {T : Type} (x : T) (s : set T) :=
|
2015-03-01 16:23:39 +00:00
|
|
|
|
s x
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation e ∈ s := mem e s
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
variable {T : Type}
|
|
|
|
|
definition eqv (A B : set T) : Prop :=
|
2014-08-26 05:54:44 +00:00
|
|
|
|
∀x, x ∈ A ↔ x ∈ B
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation a ∼ b := eqv a b
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem eqv_refl (A : set T) : A ∼ A :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
take x, iff.rfl
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem eqv_symm {A B : set T} (H : A ∼ B) : B ∼ A :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
take x, iff.symm (H x)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem eqv_trans {A B C : set T} (H1 : A ∼ B) (H2 : B ∼ C) : A ∼ C :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
take x, iff.trans (H1 x) (H2 x)
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +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-03-01 16:23:39 +00:00
|
|
|
|
definition univ : set T :=
|
|
|
|
|
λx, true
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem mem_univ (x : T) : x ∈ univ :=
|
|
|
|
|
trivial
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +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-03-01 16:23:39 +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-03-01 16:23:39 +00:00
|
|
|
|
theorem inter_id (A : set T) : A ∩ A ∼ A :=
|
|
|
|
|
take x, iff.intro
|
|
|
|
|
(assume H, and.elim_left H)
|
|
|
|
|
(assume H, and.intro H H)
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem inter_empty_right (A : set T) : A ∩ ∅ ∼ ∅ :=
|
|
|
|
|
take x, iff.intro
|
|
|
|
|
(assume H, and.elim_right H)
|
|
|
|
|
(assume H, false.elim H)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem inter_empty_left (A : set T) : ∅ ∩ A ∼ ∅ :=
|
|
|
|
|
take x, iff.intro
|
|
|
|
|
(assume H, and.elim_left H)
|
|
|
|
|
(assume H, false.elim H)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem inter_comm (A B : set T) : A ∩ B ∼ B ∩ A :=
|
|
|
|
|
take x, !and.comm
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +00:00
|
|
|
|
theorem inter_assoc (A B C : set T) : (A ∩ B) ∩ C ∼ A ∩ (B ∩ C) :=
|
|
|
|
|
take x, !and.assoc
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-03-01 16:23:39 +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-03-01 16:23:39 +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-03-01 16:23:39 +00:00
|
|
|
|
theorem union_id (A : set T) : A ∪ A ∼ A :=
|
|
|
|
|
take x, iff.intro
|
|
|
|
|
(assume H,
|
|
|
|
|
match H with
|
|
|
|
|
| or.inl H₁ := H₁
|
|
|
|
|
| or.inr H₂ := H₂
|
|
|
|
|
end)
|
|
|
|
|
(assume H, or.inl H)
|
|
|
|
|
|
|
|
|
|
theorem union_empty_right (A : set T) : A ∪ ∅ ∼ A :=
|
|
|
|
|
take x, iff.intro
|
|
|
|
|
(assume H, match H with
|
|
|
|
|
| or.inl H₁ := H₁
|
|
|
|
|
| or.inr H₂ := false.elim H₂
|
|
|
|
|
end)
|
|
|
|
|
(assume H, or.inl H)
|
|
|
|
|
|
|
|
|
|
theorem union_empty_left (A : set T) : ∅ ∪ A ∼ A :=
|
|
|
|
|
take x, iff.intro
|
|
|
|
|
(assume H, match H with
|
|
|
|
|
| or.inl H₁ := false.elim H₁
|
|
|
|
|
| or.inr H₂ := H₂
|
|
|
|
|
end)
|
|
|
|
|
(assume H, or.inr H)
|
|
|
|
|
|
|
|
|
|
theorem union_comm (A B : set T) : A ∪ B ∼ B ∪ A :=
|
|
|
|
|
take x, or.comm
|
|
|
|
|
|
|
|
|
|
theorem union_assoc (A B C : set T) : (A ∪ B) ∪ C ∼ A ∪ (B ∪ C) :=
|
|
|
|
|
take x, or.assoc
|
|
|
|
|
|
|
|
|
|
definition subset (A B : set T) := ∀ x, x ∈ A → x ∈ B
|
|
|
|
|
infix `⊆`:50 := subset
|
|
|
|
|
|
|
|
|
|
definition eqv_of_subset (A B : set T) : A ⊆ B → B ⊆ A → A ∼ B :=
|
|
|
|
|
assume H₁ H₂, take x, iff.intro (H₁ x) (H₂ x)
|
2014-08-22 23:36:47 +00:00
|
|
|
|
|
2014-08-07 23:59:08 +00:00
|
|
|
|
end set
|