]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/basics/sets.ma
list.ma moved inside lists.
[helm.git] / matita / matita / lib / basics / sets.ma
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department of the University of Bologna, Italy.                     
5     ||I||                                                                 
6     ||T||  
7     ||A||  This file is distributed under the terms of the 
8     \   /  GNU General Public License Version 2        
9      \ /      
10       V_______________________________________________________________ *)
11
12 include "basics/logic.ma".
13
14 (**** a subset of A is just an object of type A→Prop ****)
15
16 definition empty_set ≝ λA:Type[0].λa:A.False.
17 notation "\emptyv" non associative with precedence 90 for @{'empty_set}.
18 interpretation "empty set" 'empty_set = (empty_set ?).
19
20 definition singleton ≝ λA.λx,a:A.x=a.
21 (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}. *)
22 interpretation "singleton" 'singl x = (singleton ? x).
23
24 definition union : ∀A:Type[0].∀P,Q.A → Prop ≝ λA,P,Q,a.P a ∨ Q a.
25 interpretation "union" 'union a b = (union ? a b).
26
27 definition intersection : ∀A:Type[0].∀P,Q.A→Prop ≝ λA,P,Q,a.P a ∧ Q a.
28 interpretation "intersection" 'intersects a b = (intersection ? a b).
29
30 definition complement ≝ λU:Type[0].λA:U → Prop.λw.¬ A w.
31 interpretation "complement" 'not a = (complement ? a).
32
33 definition substraction := λU:Type[0].λA,B:U → Prop.λw.A w ∧ ¬ B w.
34 interpretation "substraction" 'minus a b = (substraction ? a b).
35
36 definition subset: ∀A:Type[0].∀P,Q:A→Prop.Prop ≝ λA,P,Q.∀a:A.(P a → Q a).
37 interpretation "subset" 'subseteq a b = (subset ? a b).
38
39 (* extensional equality *)
40 definition eqP ≝ λA:Type[0].λP,Q:A → Prop.∀a:A.P a ↔ Q a.
41 notation "A =1 B" non associative with precedence 45 for @{'eqP $A $B}.
42 interpretation "extensional equality" 'eqP a b = (eqP ? a b).
43
44 lemma eqP_sym: ∀U.∀A,B:U →Prop. 
45   A =1 B → B =1 A.
46 #U #A #B #eqAB #a @iff_sym @eqAB qed.
47  
48 lemma eqP_trans: ∀U.∀A,B,C:U →Prop. 
49   A =1 B → B =1 C → A =1 C.
50 #U #A #B #C #eqAB #eqBC #a @iff_trans // qed.
51
52 lemma eqP_union_r: ∀U.∀A,B,C:U →Prop. 
53   A =1 C  → A ∪ B =1 C ∪ B.
54 #U #A #B #C #eqAB #a @iff_or_r @eqAB qed.
55   
56 lemma eqP_union_l: ∀U.∀A,B,C:U →Prop. 
57   B =1 C  → A ∪ B =1 A ∪ C.
58 #U #A #B #C #eqBC #a @iff_or_l @eqBC qed.
59   
60 lemma eqP_intersect_r: ∀U.∀A,B,C:U →Prop. 
61   A =1 C  → A ∩ B =1 C ∩ B.
62 #U #A #B #C #eqAB #a @iff_and_r @eqAB qed.
63   
64 lemma eqP_intersect_l: ∀U.∀A,B,C:U →Prop. 
65   B =1 C  → A ∩ B =1 A ∩ C.
66 #U #A #B #C #eqBC #a @iff_and_l @eqBC qed.
67
68 lemma eqP_substract_r: ∀U.∀A,B,C:U →Prop. 
69   A =1 C  → A - B =1 C - B.
70 #U #A #B #C #eqAB #a @iff_and_r @eqAB qed.
71   
72 lemma eqP_substract_l: ∀U.∀A,B,C:U →Prop. 
73   B =1 C  → A - B =1 A - C.
74 #U #A #B #C #eqBC #a @iff_and_l /2/ qed.
75
76 (* set equalities *)
77 lemma union_comm : ∀U.∀A,B:U →Prop. 
78   A ∪ B =1 B ∪ A.
79 #U #A #B #a % * /2/ qed. 
80
81 lemma union_assoc: ∀U.∀A,B,C:U → Prop. 
82   A ∪ B ∪ C =1 A ∪ (B ∪ C).
83 #S #A #B #C #w % [* [* /3/ | /3/] | * [/3/ | * /3/]
84 qed.   
85
86 lemma cap_comm : ∀U.∀A,B:U →Prop. 
87   A ∩ B =1 B ∩ A.
88 #U #A #B #a % * /2/ qed. 
89
90 lemma union_idemp: ∀U.∀A:U →Prop. 
91   A ∪ A =1 A.
92 #U #A #a % [* // | /2/] qed. 
93
94 lemma cap_idemp: ∀U.∀A:U →Prop. 
95   A ∩ A =1 A.
96 #U #A #a % [* // | /2/] qed. 
97
98 (*distributivities *)
99
100 lemma distribute_intersect : ∀U.∀A,B,C:U→Prop. 
101   (A ∪ B) ∩ C =1 (A ∩ C) ∪ (B ∩ C).
102 #U #A #B #C #w % [* * /3/ | * * /3/] 
103 qed.
104   
105 lemma distribute_substract : ∀U.∀A,B,C:U→Prop. 
106   (A ∪ B) - C =1 (A - C) ∪ (B - C).
107 #U #A #B #C #w % [* * /3/ | * * /3/] 
108 qed.
109
110 (* substraction *)
111 lemma substract_def:∀U.∀A,B:U→Prop. A-B =1 A ∩ ¬B.
112 #U #A #B #w normalize /2/
113 qed.