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
|
|
|
|
|
-/
|
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
import data.bool
|
2014-10-02 00:51:17 +00:00
|
|
|
|
open eq.ops bool
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
|
|
|
|
namespace set
|
2014-08-26 05:54:44 +00:00
|
|
|
|
definition set (T : Type) :=
|
|
|
|
|
T → bool
|
2015-01-09 02:47:44 +00:00
|
|
|
|
definition mem [reducible] {T : Type} (x : T) (s : set T) :=
|
2014-08-26 05:54:44 +00:00
|
|
|
|
(s x) = tt
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation e ∈ s := mem e s
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
definition eqv {T : Type} (A B : set T) : Prop :=
|
|
|
|
|
∀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
|
|
|
|
|
|
|
|
|
theorem eqv_refl {T : Type} (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
|
|
|
|
|
|
|
|
|
theorem eqv_symm {T : Type} {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
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem eqv_trans {T : Type} {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-01-09 02:47:44 +00:00
|
|
|
|
definition empty [reducible] {T : Type} : set T :=
|
2014-08-26 05:54:44 +00:00
|
|
|
|
λx, ff
|
2014-08-22 23:36:47 +00:00
|
|
|
|
notation `∅` := empty
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem mem_empty {T : Type} (x : T) : ¬ (x ∈ ∅) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
|
assume H : x ∈ ∅, absurd H ff_ne_tt
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
definition univ {T : Type} : set T :=
|
|
|
|
|
λx, tt
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem mem_univ {T : Type} (x : T) : x ∈ univ :=
|
|
|
|
|
rfl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2015-01-09 02:47:44 +00:00
|
|
|
|
definition inter [reducible] {T : Type} (A B : set T) : set T :=
|
2014-08-26 05:54:44 +00:00
|
|
|
|
λx, A x && B x
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation a ∩ b := inter a b
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem mem_inter {T : Type} (x : T) (A B : set T) : x ∈ A ∩ B ↔ (x ∈ A ∧ x ∈ B) :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
iff.intro
|
2014-10-05 16:50:55 +00:00
|
|
|
|
(assume H, and.intro (band.eq_tt_elim_left H) (band.eq_tt_elim_right H))
|
2014-07-29 02:58:57 +00:00
|
|
|
|
(assume H,
|
2014-09-05 00:44:53 +00:00
|
|
|
|
have e1 : A x = tt, from and.elim_left H,
|
|
|
|
|
have e2 : B x = tt, from and.elim_right H,
|
2014-10-05 16:50:55 +00:00
|
|
|
|
show A x && B x = tt, from e1⁻¹ ▸ e2⁻¹ ▸ band.tt_left tt)
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem inter_id {T : Type} (A : set T) : A ∩ A ∼ A :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, band.id (A x) ▸ iff.rfl
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
|
|
|
|
theorem inter_empty_right {T : Type} (A : set T) : A ∩ ∅ ∼ ∅ :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, band.ff_right (A x) ▸ iff.rfl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem inter_empty_left {T : Type} (A : set T) : ∅ ∩ A ∼ ∅ :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, band.ff_left (A x) ▸ iff.rfl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem inter_comm {T : Type} (A B : set T) : A ∩ B ∼ B ∩ A :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, band.comm (A x) (B x) ▸ iff.rfl
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
|
|
|
|
theorem inter_assoc {T : Type} (A B C : set T) : (A ∩ B) ∩ C ∼ A ∩ (B ∩ C) :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, band.assoc (A x) (B x) (C x) ▸ iff.rfl
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2015-01-09 02:47:44 +00:00
|
|
|
|
definition union [reducible] {T : Type} (A B : set T) : set T :=
|
2014-08-26 05:54:44 +00:00
|
|
|
|
λx, A x || B x
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation a ∪ b := union a b
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem mem_union {T : Type} (x : T) (A B : set T) : x ∈ A ∪ B ↔ (x ∈ A ∨ x ∈ B) :=
|
2014-09-05 04:25:21 +00:00
|
|
|
|
iff.intro
|
2014-10-05 16:50:55 +00:00
|
|
|
|
(assume H, bor.to_or H)
|
2014-09-05 04:25:21 +00:00
|
|
|
|
(assume H, or.elim H
|
2014-07-29 02:58:57 +00:00
|
|
|
|
(assume Ha : A x = tt,
|
2014-10-05 16:50:55 +00:00
|
|
|
|
show A x || B x = tt, from Ha⁻¹ ▸ bor.tt_left (B x))
|
2014-07-29 02:58:57 +00:00
|
|
|
|
(assume Hb : B x = tt,
|
2014-10-05 16:50:55 +00:00
|
|
|
|
show A x || B x = tt, from Hb⁻¹ ▸ bor.tt_right (A x)))
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem union_id {T : Type} (A : set T) : A ∪ A ∼ A :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, bor.id (A x) ▸ iff.rfl
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
|
|
|
|
theorem union_empty_right {T : Type} (A : set T) : A ∪ ∅ ∼ A :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, bor.ff_right (A x) ▸ iff.rfl
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
|
|
|
|
theorem union_empty_left {T : Type} (A : set T) : ∅ ∪ A ∼ A :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, bor.ff_left (A x) ▸ iff.rfl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem union_comm {T : Type} (A B : set T) : A ∪ B ∼ B ∪ A :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, bor.comm (A x) (B x) ▸ iff.rfl
|
2014-07-27 20:18:33 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem union_assoc {T : Type} (A B C : set T) : (A ∪ B) ∪ C ∼ A ∪ (B ∪ C) :=
|
2014-10-05 16:50:55 +00:00
|
|
|
|
take x, bor.assoc (A x) (B x) (C x) ▸ iff.rfl
|
2014-08-22 23:36:47 +00:00
|
|
|
|
|
2014-08-07 23:59:08 +00:00
|
|
|
|
end set
|