]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/sets/sets.ma
2f0725d851284586220445d860c03a72d15163e6
[helm.git] / helm / software / matita / nlibrary / sets / sets.ma
1
2 (**************************************************************************)
3 (*       ___                                                              *)
4 (*      ||M||                                                             *)
5 (*      ||A||       A project by Andrea Asperti                           *)
6 (*      ||T||                                                             *)
7 (*      ||I||       Developers:                                           *)
8 (*      ||T||         The HELM team.                                      *)
9 (*      ||A||         http://helm.cs.unibo.it                             *)
10 (*      \   /                                                             *)
11 (*       \ /        This file is distributed under the terms of the       *)
12 (*        v         GNU General Public License Version 2                  *)
13 (*                                                                        *)
14 (**************************************************************************)
15
16 (******************* SETS OVER TYPES *****************)
17
18 include "logic/connectives.ma".
19
20 nrecord powerclass (A: Type[0]) : Type[1] ≝ { mem: A → CProp[0] }.
21
22 interpretation "mem" 'mem a S = (mem ? S a).
23 interpretation "powerclass" 'powerset A = (powerclass A).
24 interpretation "subset construction" 'subset \eta.x = (mk_powerclass ? x).
25
26 ndefinition subseteq ≝ λA.λU,V.∀a:A. a ∈ U → a ∈ V.
27 interpretation "subseteq" 'subseteq U V = (subseteq ? U V).
28
29 ndefinition overlaps ≝ λA.λU,V.∃x:A.x ∈ U ∧ x ∈ V.
30 interpretation "overlaps" 'overlaps U V = (overlaps ? U V).
31
32 ndefinition intersect ≝ λA.λU,V:Ω \sup A.{ x | x ∈ U ∧ x ∈ V }.
33 interpretation "intersect" 'intersects U V = (intersect ? U V).
34
35 ndefinition union ≝ λA.λU,V:Ω \sup A.{ x | x ∈ U ∨ x ∈ V }.
36 interpretation "union" 'union U V = (union ? U V).
37
38 ndefinition big_union ≝ λA,B.λT:Ω \sup A.λf:A → Ω \sup B.{ x | ∃i. i ∈ T ∧ x ∈ f i }.
39
40 ndefinition big_intersection ≝ λA,B.λT:Ω \sup A.λf:A → Ω \sup B.{ x | ∀i. i ∈ T → x ∈ f i }.
41
42 ndefinition full_set: ∀A. Ω \sup A ≝ λA.{ x | True }.
43 ncoercion full_set : ∀A:Type[0]. Ω \sup A ≝ full_set on A: Type[0] to (Ω \sup ?).
44
45 nlemma subseteq_refl: ∀A.∀S: Ω \sup A. S ⊆ S.
46  #A; #S; #x; #H; nassumption.
47 nqed.
48
49 nlemma subseteq_trans: ∀A.∀S,T,U: Ω \sup A. S ⊆ T → T ⊆ U → S ⊆ U.
50  #A; #S; #T; #U; #H1; #H2; #x; #P; napply H2; napply H1; nassumption.
51 nqed.
52
53 include "properties/relations1.ma".
54
55 ndefinition seteq: ∀A. equivalence_relation1 (Ω \sup A).
56  #A; napply mk_equivalence_relation1
57   [ napply (λS,S'. S ⊆ S' ∧ S' ⊆ S)
58   | #S; napply conj; napply subseteq_refl
59   | #S; #S'; *; #H1; #H2; napply conj; nassumption
60   | #S; #T; #U; *; #H1; #H2; *; #H3; #H4; napply conj; napply subseteq_trans;
61      ##[##2,5: nassumption |##1,4: ##skip |##*: nassumption]##]
62 nqed. 
63
64 include "sets/setoids1.ma".
65
66 ndefinition powerclass_setoid: Type[0] → setoid1.
67  #A; napply mk_setoid1
68   [ napply (Ω \sup A)
69   | napply seteq ]
70 nqed.
71
72 include "hints_declaration.ma". 
73
74 alias symbol "hint_decl" = "hint_decl_Type2".
75 unification hint 0 ≔ A : ? ⊢ carr1 (powerclass_setoid A) ≡ Ω^A.
76
77 (************ SETS OVER SETOIDS ********************)
78
79 include "logic/cprop.ma".
80
81 nrecord qpowerclass (A: setoid) : Type[1] ≝
82  { pc:> Ω^A;
83    mem_ok': ∀x,x':A. x=x' → (x ∈ pc) = (x' ∈ pc) 
84  }.
85
86 ndefinition Full_set: ∀A. qpowerclass A.
87  #A; napply mk_qpowerclass
88   [ napply (full_set A)
89   | #x; #x'; #H; napply refl1; ##]
90 nqed.
91
92 ndefinition qseteq: ∀A. equivalence_relation1 (qpowerclass A).
93  #A; napply mk_equivalence_relation1
94   [ napply (λS,S':qpowerclass A. S = S')
95   | #S; napply (refl1 ? (seteq A))
96   | #S; #S'; napply (sym1 ? (seteq A))
97   | #S; #T; #U; napply (trans1 ? (seteq A))]
98 nqed.
99
100 ndefinition qpowerclass_setoid: setoid → setoid1.
101  #A; napply mk_setoid1
102   [ napply (qpowerclass A)
103   | napply (qseteq A) ]
104 nqed.
105
106 unification hint 0 ≔ A : ? ⊢  carr1 (qpowerclass_setoid A) ≡ qpowerclass A.
107
108 nlemma mem_ok: ∀A. binary_morphism1 (setoid1_of_setoid A) (qpowerclass_setoid A) CPROP.
109  #A; napply mk_binary_morphism1
110   [ #x; napply (λS: qpowerclass_setoid ?. x ∈ S) (* ERROR CSC: ??? *)
111   | #a; #a'; #b; #b'; #Ha; *; #Hb1; #Hb2; napply mk_iff; #H;
112      ##[ napply Hb1; napply (. (mem_ok' …)); ##[##3: napply H| napply Ha^-1;##]
113      ##| napply Hb2; napply (. (mem_ok' …)); ##[##3: napply H| napply Ha;##]
114      ##]
115   ##]
116 nqed.
117
118 unification hint 0 ≔ 
119   A : setoid, x : ?, S : ? ⊢ (mem_ok A) x S ≡ mem A S x.
120   
121 nlemma subseteq_ok: ∀A. binary_morphism1 (qpowerclass_setoid A) (qpowerclass_setoid A) CPROP.
122  #A; napply mk_binary_morphism1
123   [ napply (λS,S': qpowerclass_setoid ?. S ⊆ S')
124   | #a; #a'; #b; #b'; *; #Ha1; #Ha2; *; #Hb1; #Hb2; napply mk_iff; #H
125      [ napply (subseteq_trans … a)
126         [ nassumption | napply (subseteq_trans … b); nassumption ]
127    ##| napply (subseteq_trans … a')
128         [ nassumption | napply (subseteq_trans … b'); nassumption ] ##]
129 nqed.
130
131 nlemma intersect_ok: ∀A. binary_morphism1 (qpowerclass_setoid A) (qpowerclass_setoid A) (qpowerclass_setoid A).
132  #A; napply mk_binary_morphism1
133   [ #S; #S'; napply mk_qpowerclass
134      [ napply (S ∩ S')
135      | #a; #a'; #Ha; nwhd in ⊢ (? ? ? % %); napply mk_iff; *; #H1; #H2; napply conj
136         [##1,2: napply (. (mem_ok' …)^-1) [##3,6: nassumption |##2,5: nassumption |##*: ##skip]
137       ##|##3,4: napply (. (mem_ok' …)) [##1,3,4,6: nassumption |##*: ##skip]##]##]
138  ##| #a; #a'; #b; #b'; #Ha; #Hb; nwhd; napply conj; #x; nwhd in ⊢ (% → %); #H
139       [ napply (. ((#‡Ha^-1)‡(#‡Hb^-1))); nassumption
140       | napply (. ((#‡Ha)‡(#‡Hb))); nassumption ]##]
141 nqed.
142
143 (*
144 unification hint 0 ≔ 
145    A : setoid, U : qpowerclass_setoid A, V : ? ⊢ (intersect_ok A) U V ≡ U ∩ V.
146   *)
147
148 nlemma test: ∀A:setoid. ∀U,V:qpowerclass A. ∀x,x':setoid1_of_setoid A. x=x' → x ∈ U ∩ V → x' ∈ U ∩ V.
149  #A; #U; #V; #x; #x'; #H; #p;
150   (* CSC: senza la change non funziona! *)
151   nchange with (x' ∈ (fun21 ??? (intersect_ok A) U V));
152   napply (. (H^-1‡#)); nassumption.
153 nqed.
154
155 (*
156 (* qui non funziona una cippa *)
157 ndefinition image: ∀A,B. (carr A → carr B) → Ω \sup A → Ω \sup B ≝
158  λA,B:setoid.λf:carr A → carr B.λSa:Ω \sup A.
159   {y | ∃x. x ∈ Sa ∧ eq_rel (carr B) (eq B) ? ?(*(f x) y*)}.
160   ##[##2: napply (f x); ##|##3: napply y]
161  #a; #a'; #H; nwhd; nnormalize; (* per togliere setoid1_of_setoid *) napply (mk_iff ????);
162  *; #x; #Hx; napply (ex_intro … x)
163   [ napply (. (#‡(#‡#))); 
164
165 ndefinition counter_image: ∀A,B. (A → B) → Ω \sup B → Ω \sup A ≝
166  λA,B,f,Sb. {x | ∃y. y ∈ Sb ∧ f x = y}.
167 *)
168
169 (******************* compatible equivalence relations **********************)
170
171 nrecord compatible_equivalence_relation (A: setoid) : Type[1] ≝
172  { rel:> equivalence_relation A;
173    compatibility: ∀x,x':A. x=x' → eq_rel ? rel x x' (* coercion qui non va *)
174  }.
175
176 ndefinition quotient: ∀A. compatible_equivalence_relation A → setoid.
177  #A; #R; napply mk_setoid
178   [ napply A
179   | napply R]
180 nqed.
181
182 (******************* first omomorphism theorem for sets **********************)
183
184 ndefinition eqrel_of_morphism:
185  ∀A,B. unary_morphism A B → compatible_equivalence_relation A.
186  #A; #B; #f; napply mk_compatible_equivalence_relation
187   [ napply mk_equivalence_relation
188      [ napply (λx,y. f x = f y)
189      | #x; napply refl | #x; #y; napply sym | #x; #y; #z; napply trans]
190 ##| #x; #x'; #H; nwhd; napply (.= (†H)); napply refl ]
191 nqed.
192
193 ndefinition canonical_proj: ∀A,R. unary_morphism A (quotient A R).
194  #A; #R; napply mk_unary_morphism
195   [ napply (λx.x) | #a; #a'; #H; napply (compatibility ? R … H) ]
196 nqed.
197
198 ndefinition quotiented_mor:
199  ∀A,B.∀f:unary_morphism A B.
200   unary_morphism (quotient ? (eqrel_of_morphism ?? f)) B.
201  #A; #B; #f; napply mk_unary_morphism
202   [ napply f | #a; #a'; #H; nassumption]
203 nqed.
204
205 nlemma first_omomorphism_theorem_functions1:
206  ∀A,B.∀f: unary_morphism A B.
207   ∀x. f x = quotiented_mor ??? (canonical_proj ? (eqrel_of_morphism ?? f) x).
208  #A; #B; #f; #x; napply refl;
209 nqed.
210
211 ndefinition surjective ≝
212  λA,B.λS: qpowerclass A.λT: qpowerclass B.λf:unary_morphism A B.
213   ∀y. y ∈ T → ∃x. x ∈ S ∧ f x = y.
214
215 ndefinition injective ≝
216  λA,B.λS: qpowerclass A.λf:unary_morphism A B.
217   ∀x,x'. x ∈ S → x' ∈ S → f x = f x' → x = x'.
218
219 nlemma first_omomorphism_theorem_functions2:
220  ∀A,B.∀f: unary_morphism A B. surjective ?? (Full_set ?) (Full_set ?) (canonical_proj ? (eqrel_of_morphism ?? f)).
221  #A; #B; #f; nwhd; #y; #Hy; napply (ex_intro … y); napply conj
222   [ napply I | napply refl]
223 nqed.
224
225 nlemma first_omomorphism_theorem_functions3:
226  ∀A,B.∀f: unary_morphism A B. injective ?? (Full_set ?) (quotiented_mor ?? f).
227  #A; #B; #f; nwhd; #x; #x'; #Hx; #Hx'; #K; nassumption.
228 nqed.
229
230 nrecord isomorphism (A) (B) (S: qpowerclass A) (T: qpowerclass B) : CProp[0] ≝
231  { iso_f:> unary_morphism A B;
232    f_closed: ∀x. x ∈ S → iso_f x ∈ T;
233    f_sur: surjective ?? S T iso_f;
234    f_inj: injective ?? S iso_f
235  }.