refactor(library/data/set/basic.lean): take advantage of extensionality in sets
This commit is contained in:
parent
74ff43a543
commit
c6c50a61b3
1 changed files with 54 additions and 62 deletions
|
@ -1,6 +1,6 @@
|
|||
/-
|
||||
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
copyright (c) 2014 Jeremy Avigad. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LIcENSE.
|
||||
|
||||
Module: data.set.basic
|
||||
Author: Jeremy Avigad, Leonardo de Moura
|
||||
|
@ -8,110 +8,102 @@ Author: Jeremy Avigad, Leonardo de Moura
|
|||
import logic
|
||||
open eq.ops
|
||||
|
||||
definition set (T : Type) := T → Prop
|
||||
|
||||
namespace set
|
||||
definition set (T : Type) :=
|
||||
T → Prop
|
||||
definition mem [reducible] {T : Type} (x : T) (s : set T) :=
|
||||
s x
|
||||
notation e ∈ s := mem e s
|
||||
|
||||
variable {T : Type}
|
||||
definition eqv (A B : set T) : Prop :=
|
||||
∀x, x ∈ A ↔ x ∈ B
|
||||
notation a ∼ b := eqv a b
|
||||
|
||||
theorem eqv_refl (A : set T) : A ∼ A :=
|
||||
take x, iff.rfl
|
||||
definition mem [reducible] (x : T) (a : set T) := a x
|
||||
notation e ∈ a := mem e a
|
||||
|
||||
theorem eqv_symm {A B : set T} (H : A ∼ B) : B ∼ A :=
|
||||
take x, iff.symm (H x)
|
||||
theorem setext {a b : set T} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b :=
|
||||
funext (take x, propext (H x))
|
||||
|
||||
theorem eqv_trans {A B C : set T} (H1 : A ∼ B) (H2 : B ∼ C) : A ∼ C :=
|
||||
take x, iff.trans (H1 x) (H2 x)
|
||||
definition subset (a b : set T) := ∀ x, x ∈ a → x ∈ b
|
||||
infix `⊆`:50 := subset
|
||||
|
||||
definition empty [reducible] : set T :=
|
||||
λx, false
|
||||
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))
|
||||
|
||||
/- empty -/
|
||||
|
||||
definition empty [reducible] : set T := λx, false
|
||||
notation `∅` := empty
|
||||
|
||||
theorem mem_empty (x : T) : ¬ (x ∈ ∅) :=
|
||||
assume H : x ∈ ∅, H
|
||||
|
||||
definition univ : set T :=
|
||||
λx, true
|
||||
/- univ -/
|
||||
|
||||
theorem mem_univ (x : T) : x ∈ univ :=
|
||||
trivial
|
||||
definition univ : set T := λx, true
|
||||
|
||||
definition inter [reducible] (A B : set T) : set T :=
|
||||
λx, x ∈ A ∧ x ∈ B
|
||||
theorem mem_univ (x : T) : x ∈ univ := trivial
|
||||
|
||||
/- inter -/
|
||||
|
||||
definition inter [reducible] (a b : set T) : set T := λx, x ∈ a ∧ x ∈ b
|
||||
notation a ∩ b := inter a b
|
||||
|
||||
theorem mem_inter (x : T) (A B : set T) : x ∈ A ∩ B ↔ (x ∈ A ∧ x ∈ B) :=
|
||||
!iff.refl
|
||||
theorem mem_inter (x : T) (a b : set T) : x ∈ a ∩ b ↔ (x ∈ a ∧ x ∈ b) := !iff.refl
|
||||
|
||||
theorem inter_id (A : set T) : A ∩ A ∼ A :=
|
||||
take x, iff.intro
|
||||
theorem inter_self (a : set T) : a ∩ a = a :=
|
||||
setext (take x, iff.intro
|
||||
(assume H, and.elim_left H)
|
||||
(assume H, and.intro H H)
|
||||
(assume H, and.intro H H))
|
||||
|
||||
theorem inter_empty_right (A : set T) : A ∩ ∅ ∼ ∅ :=
|
||||
take x, iff.intro
|
||||
theorem inter_empty (a : set T) : a ∩ ∅ = ∅ :=
|
||||
setext (take x, iff.intro
|
||||
(assume H, and.elim_right H)
|
||||
(assume H, false.elim H)
|
||||
(assume H, false.elim H))
|
||||
|
||||
theorem inter_empty_left (A : set T) : ∅ ∩ A ∼ ∅ :=
|
||||
take x, iff.intro
|
||||
theorem empty_inter (a : set T) : ∅ ∩ a = ∅ :=
|
||||
setext (take x, iff.intro
|
||||
(assume H, and.elim_left H)
|
||||
(assume H, false.elim H)
|
||||
(assume H, false.elim H))
|
||||
|
||||
theorem inter_comm (A B : set T) : A ∩ B ∼ B ∩ A :=
|
||||
take x, !and.comm
|
||||
theorem inter.comm (a b : set T) : a ∩ b = b ∩ a :=
|
||||
setext (take x, !and.comm)
|
||||
|
||||
theorem inter_assoc (A B C : set T) : (A ∩ B) ∩ C ∼ A ∩ (B ∩ C) :=
|
||||
take x, !and.assoc
|
||||
theorem inter.assoc (a b c : set T) : (a ∩ b) ∩ c = a ∩ (b ∩ c) :=
|
||||
setext (take x, !and.assoc)
|
||||
|
||||
definition union [reducible] (A B : set T) : set T :=
|
||||
λx, x ∈ A ∨ x ∈ B
|
||||
/- union -/
|
||||
|
||||
definition union [reducible] (a b : set T) : set T := λx, x ∈ a ∨ x ∈ b
|
||||
notation a ∪ b := union a b
|
||||
|
||||
theorem mem_union (x : T) (A B : set T) : x ∈ A ∪ B ↔ (x ∈ A ∨ x ∈ B) :=
|
||||
!iff.refl
|
||||
theorem mem_union (x : T) (a b : set T) : x ∈ a ∪ b ↔ (x ∈ a ∨ x ∈ b) := !iff.refl
|
||||
|
||||
theorem union_id (A : set T) : A ∪ A ∼ A :=
|
||||
take x, iff.intro
|
||||
theorem union_self (a : set T) : a ∪ a = a :=
|
||||
setext (take x, iff.intro
|
||||
(assume H,
|
||||
match H with
|
||||
| or.inl H₁ := H₁
|
||||
| or.inr H₂ := H₂
|
||||
end)
|
||||
(assume H, or.inl H)
|
||||
(assume H, or.inl H))
|
||||
|
||||
theorem union_empty_right (A : set T) : A ∪ ∅ ∼ A :=
|
||||
take x, iff.intro
|
||||
theorem union_empty (a : set T) : a ∪ ∅ = a :=
|
||||
setext (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)
|
||||
(assume H, or.inl H))
|
||||
|
||||
theorem union_empty_left (A : set T) : ∅ ∪ A ∼ A :=
|
||||
take x, iff.intro
|
||||
theorem union_empty_left (a : set T) : ∅ ∪ a = a :=
|
||||
setext (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)
|
||||
(assume H, or.inr H))
|
||||
|
||||
theorem union_comm (A B : set T) : A ∪ B ∼ B ∪ A :=
|
||||
take x, or.comm
|
||||
theorem union.comm (a b : set T) : a ∪ b = b ∪ a :=
|
||||
setext (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)
|
||||
theorem union_assoc (a b c : set T) : (a ∪ b) ∪ c = a ∪ (b ∪ c) :=
|
||||
setext (take x, or.assoc)
|
||||
|
||||
end set
|
||||
|
|
Loading…
Add table
Reference in a new issue