]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/basics/sets.ma
2f570c18feb503e1da38186bf9455a8c0b9e1018
[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 include "basics/core_notation/singl_1.ma".
14
15 (**** a subset of A is just an object of type A→Prop ****)
16
17 definition empty_set ≝ λA:Type[0].λa:A.False.
18 notation "\emptyv" non associative with precedence 90 for @{'empty_set}.
19 interpretation "empty set" 'empty_set = (empty_set ?).
20
21 definition singleton ≝ λA.λx,a:A.x=a.
22 (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}. *)
23 interpretation "singleton" 'singl x = (singleton ? x).
24
25 definition union : ∀A:Type[0].∀P,Q.A → Prop ≝ λA,P,Q,a.P a ∨ Q a.
26 interpretation "union" 'union a b = (union ? a b).
27
28 definition intersection : ∀A:Type[0].∀P,Q.A→Prop ≝ λA,P,Q,a.P a ∧ Q a.
29 interpretation "intersection" 'intersects a b = (intersection ? a b).
30
31 definition complement ≝ λU:Type[0].λA:U → Prop.λw.¬ A w.
32 interpretation "complement" 'not a = (complement ? a).
33
34 definition substraction := λU:Type[0].λA,B:U → Prop.λw.A w ∧ ¬ B w.
35 interpretation "substraction" 'minus a b = (substraction ? a b).
36
37 definition subset: ∀A:Type[0].∀P,Q:A→Prop.Prop ≝ λA,P,Q.∀a:A.(P a → Q a).
38 interpretation "subset" 'subseteq a b = (subset ? a b).
39
40 (* extensional equality *)
41 definition eqP ≝ λA:Type[0].λP,Q:A → Prop.∀a:A.P a ↔ Q a.
42 (* ≐ is typed as \doteq *)
43 notation "A ≐ B" non associative with precedence 45 for @{'eqP $A $B}.
44 interpretation "extensional equality" 'eqP a b = (eqP ? a b).
45
46 lemma eqP_sym: ∀U.∀A,B:U →Prop. 
47   A ≐ B → B ≐ A.
48 #U #A #B #eqAB #a @iff_sym @eqAB qed.
49  
50 lemma eqP_trans: ∀U.∀A,B,C:U →Prop. 
51   A ≐ B → B ≐ C → A ≐ C.
52 #U #A #B #C #eqAB #eqBC #a @iff_trans // qed.
53
54 lemma eqP_union_r: ∀U.∀A,B,C:U →Prop. 
55   A ≐ C  → A ∪ B ≐ C ∪ B.
56 #U #A #B #C #eqAB #a @iff_or_r @eqAB qed.
57   
58 lemma eqP_union_l: ∀U.∀A,B,C:U →Prop. 
59   B ≐ C  → A ∪ B ≐ A ∪ C.
60 #U #A #B #C #eqBC #a @iff_or_l @eqBC qed.
61   
62 lemma eqP_intersect_r: ∀U.∀A,B,C:U →Prop. 
63   A ≐ C  → A ∩ B ≐ C ∩ B.
64 #U #A #B #C #eqAB #a @iff_and_r @eqAB qed.
65   
66 lemma eqP_intersect_l: ∀U.∀A,B,C:U →Prop. 
67   B ≐ C  → A ∩ B ≐ A ∩ C.
68 #U #A #B #C #eqBC #a @iff_and_l @eqBC qed.
69
70 lemma eqP_substract_r: ∀U.∀A,B,C:U →Prop. 
71   A ≐ C  → A - B ≐ C - B.
72 #U #A #B #C #eqAB #a @iff_and_r @eqAB qed.
73   
74 lemma eqP_substract_l: ∀U.∀A,B,C:U →Prop. 
75   B ≐ C  → A - B ≐ A - C.
76 #U #A #B #C #eqBC #a @iff_and_l /2/ qed.
77
78 (* set equalities *)
79 lemma union_empty_r: ∀U.∀A:U→Prop. 
80   A ∪ ∅ ≐ A.
81 #U #A #w % [* // normalize #abs @False_ind /2/ | /2/]
82 qed.
83
84 lemma union_comm : ∀U.∀A,B:U →Prop. 
85   A ∪ B ≐ B ∪ A.
86 #U #A #B #a % * /2/ qed. 
87
88 lemma union_assoc: ∀U.∀A,B,C:U → Prop. 
89   A ∪ B ∪ C ≐ A ∪ (B ∪ C).
90 #S #A #B #C #w % [* [* /3/ | /3/] | * [/3/ | * /3/]
91 qed.   
92
93 lemma cap_comm : ∀U.∀A,B:U →Prop. 
94   A ∩ B ≐ B ∩ A.
95 #U #A #B #a % * /2/ qed. 
96
97 lemma union_idemp: ∀U.∀A:U →Prop. 
98   A ∪ A ≐ A.
99 #U #A #a % [* // | /2/] qed. 
100
101 lemma cap_idemp: ∀U.∀A:U →Prop. 
102   A ∩ A ≐ A.
103 #U #A #a % [* // | /2/] qed. 
104
105 (*distributivities *)
106
107 lemma distribute_intersect : ∀U.∀A,B,C:U→Prop. 
108   (A ∪ B) ∩ C ≐ (A ∩ C) ∪ (B ∩ C).
109 #U #A #B #C #w % [* * /3/ | * * /3/] 
110 qed.
111   
112 lemma distribute_substract : ∀U.∀A,B,C:U→Prop. 
113   (A ∪ B) - C ≐ (A - C) ∪ (B - C).
114 #U #A #B #C #w % [* * /3/ | * * /3/] 
115 qed.
116
117 (* substraction *)
118 lemma substract_def:∀U.∀A,B:U→Prop. A-B ≐ A ∩ ¬B.
119 #U #A #B #w normalize /2/
120 qed.