1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (******************* SETS OVER TYPES *****************)
17 include "logic/connectives.ma".
19 nrecord powerclass (A: Type[0]) : Type[1] ≝ { mem: A → CProp[0] }.
21 interpretation "mem" 'mem a S = (mem ? S a).
22 interpretation "powerclass" 'powerset A = (powerclass A).
23 interpretation "subset construction" 'subset \eta.x = (mk_powerclass ? x).
25 ndefinition subseteq ≝ λA.λU,V.∀a:A. a ∈ U → a ∈ V.
26 interpretation "subseteq" 'subseteq U V = (subseteq ? U V).
28 ndefinition overlaps ≝ λA.λU,V.∃x:A.x ∈ U ∧ x ∈ V.
29 interpretation "overlaps" 'overlaps U V = (overlaps ? U V).
31 ndefinition intersect ≝ λA.λU,V:Ω \sup A.{ x | x ∈ U ∧ x ∈ V }.
32 interpretation "intersect" 'intersects U V = (intersect ? U V).
34 ndefinition union ≝ λA.λU,V:Ω \sup A.{ x | x ∈ U ∨ x ∈ V }.
35 interpretation "union" 'union U V = (union ? U V).
37 ndefinition big_union ≝ λA,B.λT:Ω \sup A.λf:A → Ω \sup B.{ x | ∃i. i ∈ T ∧ x ∈ f i }.
39 ndefinition big_intersection ≝ λA,B.λT:Ω \sup A.λf:A → Ω \sup B.{ x | ∀i. i ∈ T → x ∈ f i }.
41 ndefinition full_set: ∀A. Ω \sup A ≝ λA.{ x | True }.
42 (* bug dichiarazione coercion qui *)
43 (* ncoercion full_set : ∀A:Type[0]. Ω \sup A ≝ full_set on _A: Type[0] to (Ω \sup ?). *)
45 nlemma subseteq_refl: ∀A.∀S: Ω \sup A. S ⊆ S.
46 #A; #S; #x; #H; nassumption.
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.
53 include "properties/relations1.ma".
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]##]
64 include "sets/setoids1.ma".
66 ndefinition powerclass_setoid: Type[0] → setoid1.
72 unification hint 0 (∀A. (λx,y.True) (carr1 (powerclass_setoid A)) (Ω \sup A)).
74 (************ SETS OVER SETOIDS ********************)
76 include "logic/cprop.ma".
78 nrecord qpowerclass (A: setoid) : Type[1] ≝
80 mem_ok': ∀x,x':A. x=x' → (x ∈ pc) = (x' ∈ pc)
83 ndefinition Full_set: ∀A. qpowerclass A.
84 #A; napply mk_qpowerclass
86 | #x; #x'; #H; nnormalize in ⊢ (?%?%%); (* bug universi qui napply refl1;*)
87 napply mk_iff; #K; nassumption ]
90 ndefinition qseteq: ∀A. equivalence_relation1 (qpowerclass A).
91 #A; napply mk_equivalence_relation1
92 [ napply (λS,S':qpowerclass A. eq_rel1 ? (eq1 (powerclass_setoid A)) S S')
93 | #S; napply (refl1 ? (seteq A))
94 | #S; #S'; napply (sym1 ? (seteq A))
95 | #S; #T; #U; napply (trans1 ? (seteq A))]
98 ndefinition qpowerclass_setoid: setoid → setoid1.
100 [ napply (qpowerclass A)
101 | napply (qseteq A) ]
104 unification hint 0 (∀A. (λx,y.True) (carr1 (qpowerclass_setoid A)) (qpowerclass A)).
105 ncoercion qpowerclass_hint: ∀A: setoid. ∀S: qpowerclass_setoid A. Ω \sup A ≝ λA.λS.S
106 on _S: (carr1 (qpowerclass_setoid ?)) to (Ω \sup ?).
108 nlemma mem_ok: ∀A. binary_morphism1 (setoid1_of_setoid A) (qpowerclass_setoid A) CPROP.
109 #A; napply mk_binary_morphism1
110 [ napply (λx.λS: qpowerclass_setoid A. x ∈ S) (* CSC: ??? *)
111 | #a; #a'; #b; #b'; #Ha; #Hb; (* CSC: qui *; non funziona *)
112 nwhd; nwhd in ⊢ (? (? % ??) (? % ??)); napply mk_iff; #H
113 [ ncases Hb; #Hb1; #_; napply Hb1; napply (. (mem_ok' …))
114 [ nassumption | napply Ha^-1 | ##skip ]
115 ##| ncases Hb; #_; #Hb2; napply Hb2; napply (. (mem_ok' …))
116 [ nassumption | napply Ha | ##skip ]##]
119 unification hint 0 (∀A,x,S. (λx,y.True) (fun21 ??? (mem_ok A) x S) (mem A S x)).
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' a) (* anche qui, perche' serve a'? *)
126 [ nassumption | napply (subseteq_trans … a b); nassumption ]
127 ##| napply (subseteq_trans … a a') (* anche qui, perche' serve a'? *)
128 [ nassumption | napply (subseteq_trans … a' b'); nassumption ] ##]
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
135 | #a; #a'; #Ha; nwhd in ⊢ (? ? ? % %); napply mk_iff; *; #H1; #H2; napply conj
136 [##1,2: napply (. (mem_ok' …)^-1) [##3,6: nassumption |##1,4: nassumption |##*: ##skip]
137 ##|##3,4: napply (. (mem_ok' …)) [##2,5: nassumption |##1,4: 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 ]##]
143 unification hint 0 (∀A.∀U,V.(λx,y.True) (fun21 ??? (intersect_ok A) U V) (intersect A U V)).
145 nlemma test: ∀A:setoid. ∀U,V:qpowerclass A. ∀x,x':setoid1_of_setoid A. x=x' → x ∈ U ∩ V → x' ∈ U ∩ V.
146 #A; #U; #V; #x; #x'; #H; #p;
147 (* CSC: senza la change non funziona! *)
148 nchange with (x' ∈ (fun21 ??? (intersect_ok A) U V));
149 napply (. (H^-1‡#)); nassumption.
153 (* qui non funziona una cippa *)
154 ndefinition image: ∀A,B. (carr A → carr B) → Ω \sup A → Ω \sup B ≝
155 λA,B:setoid.λf:carr A → carr B.λSa:Ω \sup A.
156 {y | ∃x. x ∈ Sa ∧ eq_rel (carr B) (eq B) ? ?(*(f x) y*)}.
157 ##[##2: napply (f x); ##|##3: napply y]
158 #a; #a'; #H; nwhd; nnormalize; (* per togliere setoid1_of_setoid *) napply (mk_iff ????);
159 *; #x; #Hx; napply (ex_intro … x)
160 [ napply (. (#‡(#‡#)));
162 ndefinition counter_image: ∀A,B. (A → B) → Ω \sup B → Ω \sup A ≝
163 λA,B,f,Sb. {x | ∃y. y ∈ Sb ∧ f x = y}.
166 (******************* compatible equivalence relations **********************)
168 nrecord compatible_equivalence_relation (A: setoid) : Type[1] ≝
169 { rel:> equivalence_relation A;
170 compatibility: ∀x,x':A. x=x' → eq_rel ? rel x x' (* coercion qui non va *)
173 ndefinition quotient: ∀A. compatible_equivalence_relation A → setoid.
174 #A; #R; napply mk_setoid
179 (******************* first omomorphism theorem for sets **********************)
181 ndefinition eqrel_of_morphism:
182 ∀A,B. unary_morphism A B → compatible_equivalence_relation A.
183 #A; #B; #f; napply mk_compatible_equivalence_relation
184 [ napply mk_equivalence_relation
185 [ napply (λx,y. f x = f y)
186 | #x; napply refl | #x; #y; napply sym | #x; #y; #z; napply trans]
187 ##| #x; #x'; #H; nwhd; napply (.= (†H)); napply refl ]
190 ndefinition canonical_proj: ∀A,R. unary_morphism A (quotient A R).
191 #A; #R; napply mk_unary_morphism
192 [ napply (λx.x) | #a; #a'; #H; napply (compatibility ? R … H) ]
195 ndefinition quotiented_mor:
196 ∀A,B.∀f:unary_morphism A B.
197 unary_morphism (quotient ? (eqrel_of_morphism ?? f)) B.
198 #A; #B; #f; napply mk_unary_morphism
199 [ napply f | #a; #a'; #H; nassumption]
202 nlemma first_omomorphism_theorem_functions1:
203 ∀A,B.∀f: unary_morphism A B.
204 ∀x. f x = quotiented_mor ??? (canonical_proj ? (eqrel_of_morphism ?? f) x).
205 #A; #B; #f; #x; napply refl;
208 ndefinition surjective ≝
209 λA,B.λS: qpowerclass A.λT: qpowerclass B.λf:unary_morphism A B.
210 ∀y. y ∈ T → ∃x. x ∈ S ∧ f x = y.
212 ndefinition injective ≝
213 λA,B.λS: qpowerclass A.λf:unary_morphism A B.
214 ∀x,x'. x ∈ S → x' ∈ S → f x = f x' → x = x'.
216 nlemma first_omomorphism_theorem_functions2:
217 ∀A,B.∀f: unary_morphism A B. surjective ?? (Full_set ?) (Full_set ?) (canonical_proj ? (eqrel_of_morphism ?? f)).
218 #A; #B; #f; nwhd; #y; #Hy; napply (ex_intro … y); napply conj
219 [ napply I | napply refl]
222 nlemma first_omomorphism_theorem_functions3:
223 ∀A,B.∀f: unary_morphism A B. injective ?? (Full_set ?) (quotiented_mor ?? f).
224 #A; #B; #f; nwhd; #x; #x'; #Hx; #Hx'; #K; nassumption.
227 nrecord isomorphism (A) (B) (S: qpowerclass A) (T: qpowerclass B) : CProp[0] ≝
228 { iso_f:> unary_morphism A B;
229 f_sur: surjective ?? S T iso_f;
230 f_inj: injective ?? S iso_f