1 (* In this Chapter we shall develop a naif theory of sets represented as characteristic
2 predicates over some universe
\ 5code
\ 6A
\ 5/code
\ 6, that is as objects of type A→Prop *)
4 include "basics/logic.ma".
6 (**** For instance the empty set is defined by the always function predicate *)
8 definition empty_set ≝ λA:Type[0].λa:A.
\ 5a href="cic:/matita/basics/logic/False.ind(1,0,0)"
\ 6False
\ 5/a
\ 6.
9 notation "\emptyv" non associative with precedence 90 for @{'empty_set}.
10 interpretation "empty set" 'empty_set = (empty_set ?).
12 (* Similarly, a singleton set contaning containing an element a, is defined
13 by by the characteristic function asserting equality with a *)
15 definition singleton ≝ λA.λx,a:A.x
\ 5a title="leibnitz's equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 6a.
16 (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}. *)
17 interpretation "singleton" 'singl x = (singleton ? x).
19 (* The operations of union, intersection, complement and substraction
20 are easily defined in terms of the propositional connectives of dijunction,
21 conjunction and negation *)
23 definition union : ∀A:Type[0].∀P,Q.A → Prop ≝ λA,P,Q,a.P a
\ 5a title="logical or" href="cic:/fakeuri.def(1)"
\ 6∨
\ 5/a
\ 6 Q a.
24 interpretation "union" 'union a b = (union ? a b).
26 definition intersection : ∀A:Type[0].∀P,Q.A→Prop ≝ λA,P,Q,a.P a
\ 5a title="logical and" href="cic:/fakeuri.def(1)"
\ 6∧
\ 5/a
\ 6 Q a.
27 interpretation "intersection" 'intersects a b = (intersection ? a b).
29 definition complement ≝ λU:Type[0].λA:U → Prop.λw.
\ 5a title="logical not" href="cic:/fakeuri.def(1)"
\ 6¬
\ 5/a
\ 6 A w.
30 interpretation "complement" 'not a = (complement ? a).
32 definition substraction := λU:Type[0].λA,B:U → Prop.λw.A w
\ 5a title="logical and" href="cic:/fakeuri.def(1)"
\ 6∧
\ 5/a
\ 6 \ 5a title="logical not" href="cic:/fakeuri.def(1)"
\ 6¬
\ 5/a
\ 6 B w.
33 interpretation "substraction" 'minus a b = (substraction ? a b).
35 (* Finally, we use implication to define the inclusion relation between
38 definition subset: ∀A:Type[0].∀P,Q:A→Prop.Prop ≝ λA,P,Q.∀a:A.(P a → Q a).
39 interpretation "subset" 'subseteq a b = (subset ? a b).
41 (* Two sets are equals if and only if they have the same elements, that is,
42 if the two characteristic functions are extensionally equivalent: *)
44 definition eqP ≝ λA:Type[0].λP,Q:A → Prop.∀a:A.P a
\ 5a title="iff" href="cic:/fakeuri.def(1)"
\ 6↔
\ 5/a
\ 6 Q a.
45 notation "A =1 B" non associative with precedence 45 for @{'eqP $A $B}.
46 interpretation "extensional equality" 'eqP a b = (eqP ? a b).
48 (* This notion of equality is different from the intensional equality of
49 fucntions, hence we have to prove the usual properties: *)
51 lemma eqP_sym: ∀U.∀A,B:U →Prop.
52 A
\ 5a title="extensional equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 61 B → B
\ 5a title="extensional equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 61 A.
53 #U #A #B #eqAB #a @iff_sym @eqAB qed.
55 lemma eqP_trans: ∀U.∀A,B,C:U →Prop.
56 A =1 B → B =1 C → A =1 C.
57 #U #A #B #C #eqAB #eqBC #a @iff_trans // qed.
59 (* For the same reason, we must also prove that all the operations we have
60 lemma eqP_union_r: ∀U.∀A,B,C:U →Prop.
61 A =1 C → A ∪ B =1 C ∪ B.
62 #U #A #B #C #eqAB #a @iff_or_r @eqAB qed.
64 lemma eqP_union_l: ∀U.∀A,B,C:U →Prop.
65 B =1 C → A ∪ B =1 A ∪ C.
66 #U #A #B #C #eqBC #a @iff_or_l @eqBC qed.
68 lemma eqP_intersect_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.
72 lemma eqP_intersect_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 @eqBC qed.
76 lemma eqP_substract_r: ∀U.∀A,B,C:U →Prop.
77 A =1 C → A - B =1 C - B.
78 #U #A #B #C #eqAB #a @iff_and_r @eqAB qed.
80 lemma eqP_substract_l: ∀U.∀A,B,C:U →Prop.
81 B =1 C → A - B =1 A - C.
82 #U #A #B #C #eqBC #a @iff_and_l /2/ qed.
85 lemma union_empty_r: ∀U.∀A:U→Prop.
87 #U #A #w % [* // normalize #abs @False_ind /2/ | /2/]
90 lemma union_comm : ∀U.∀A,B:U →Prop.
92 #U #A #B #a % * /2/ qed.
94 lemma union_assoc: ∀U.∀A,B,C:U → Prop.
95 A ∪ B ∪ C =1 A ∪ (B ∪ C).
96 #S #A #B #C #w % [* [* /3/ | /3/] | * [/3/ | * /3/]
99 lemma cap_comm : ∀U.∀A,B:U →Prop.
101 #U #A #B #a % * /2/ qed.
103 lemma union_idemp: ∀U.∀A:U →Prop.
105 #U #A #a % [* // | /2/] qed.
107 lemma cap_idemp: ∀U.∀A:U →Prop.
109 #U #A #a % [* // | /2/] qed.
111 (*distributivities *)
113 lemma distribute_intersect : ∀U.∀A,B,C:U→Prop.
114 (A ∪ B) ∩ C =1 (A ∩ C) ∪ (B ∩ C).
115 #U #A #B #C #w % [* * /3/ | * * /3/]
118 lemma distribute_substract : ∀U.∀A,B,C:U→Prop.
119 (A ∪ B) - C =1 (A - C) ∪ (B - C).
120 #U #A #B #C #w % [* * /3/ | * * /3/]
124 lemma substract_def:∀U.∀A,B:U→Prop. A-B =1 A ∩ ¬B.
125 #U #A #B #w normalize /2/
128 include "basics/types.ma".
129 include "basics/bool.ma".
131 (****** DeqSet: a set with a decidbale equality ******)
133 record DeqSet : Type[1] ≝ { carr :> Type[0];
134 eqb: carr → carr → bool;
135 eqb_true: ∀x,y. (eqb x y = true) ↔ (x = y)
138 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
139 interpretation "eqb" 'eqb a b = (eqb ? a b).
141 notation "\P H" non associative with precedence 90
142 for @{(proj1 … (eqb_true ???) $H)}.
144 notation "\b H" non associative with precedence 90
145 for @{(proj2 … (eqb_true ???) $H)}.
147 lemma eqb_false: ∀S:DeqSet.∀a,b:S.
148 (eqb ? a b) = false ↔ a ≠ b.
150 [@(not_to_not … not_eq_true_false) #H1 <H @sym_eq @(\b H1)
151 |cases (true_or_false (eqb ? a b)) // #H1 @False_ind @(absurd … (\P H1) H)
155 notation "\Pf H" non associative with precedence 90
156 for @{(proj1 … (eqb_false ???) $H)}.
158 notation "\bf H" non associative with precedence 90
159 for @{(proj2 … (eqb_false ???) $H)}.
161 lemma dec_eq: ∀S:DeqSet.∀a,b:S. a = b ∨ a ≠ b.
162 #S #a #b cases (true_or_false (eqb ? a b)) #H
163 [%1 @(\P H) | %2 @(\Pf H)]
166 definition beqb ≝ λb1,b2.
167 match b1 with [ true ⇒ b2 | false ⇒ notb b2].
169 notation < "a == b" non associative with precedence 45 for @{beqb $a $b }.
170 lemma beqb_true: ∀b1,b2. iff (beqb b1 b2 = true) (b1 = b2).
171 #b1 #b2 cases b1 cases b2 normalize /2/
174 definition DeqBool ≝ mk_DeqSet bool beqb beqb_true.
176 unification hint 0 ≔ ;
177 X ≟ mk_DeqSet bool beqb beqb_true
178 (* ---------------------------------------- *) ⊢
181 unification hint 0 ≔ b1,b2:bool;
182 X ≟ mk_DeqSet bool beqb beqb_true
183 (* ---------------------------------------- *) ⊢
184 beqb b1 b2 ≡ eqb X b1 b2.
186 example exhint: ∀b:bool. (b == false) = true → b = false.
191 definition eq_pairs ≝
192 λA,B:DeqSet.λp1,p2:A×B.(\fst p1 == \fst p2) ∧ (\snd p1 == \snd p2).
194 lemma eq_pairs_true: ∀A,B:DeqSet.∀p1,p2:A×B.
195 eq_pairs A B p1 p2 = true ↔ p1 = p2.
196 #A #B * #a1 #b1 * #a2 #b2 %
197 [#H cases (andb_true …H) #eqa #eqb >(\P eqa) >(\P eqb) //
198 |#H destruct normalize >(\b (refl … a2)) >(\b (refl … b2)) //
202 definition DeqProd ≝ λA,B:DeqSet.
203 mk_DeqSet (A×B) (eq_pairs A B) (eq_pairs_true A B).
205 unification hint 0 ≔ C1,C2;
209 (* ---------------------------------------- *) ⊢
212 unification hint 0 ≔ T1,T2,p1,p2;
214 (* ---------------------------------------- *) ⊢
215 eq_pairs T1 T2 p1 p2 ≡ eqb X p1 p2.
217 example hint2: ∀b1,b2.
218 〈b1,true〉==〈false,b2〉=true → 〈b1,true〉=〈false,b2〉.