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.λT:Type[0].λf:T → Ω \sup A.{ x | ∃i. x ∈ f i }.
39 ndefinition big_intersection ≝ λA.λT:Type[0].λf:T → Ω \sup A.{ x | ∀i. 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 qseteq: ∀A. equivalence_relation1 (qpowerclass A).
84 #A; napply mk_equivalence_relation1
85 [ napply (λS,S':qpowerclass A. eq_rel1 ? (eq1 (powerclass_setoid A)) S S')
86 | #S; napply (refl1 ? (seteq A))
87 | #S; #S'; napply (sym1 ? (seteq A))
88 | #S; #T; #U; napply (trans1 ? (seteq A))]
91 ndefinition qpowerclass_setoid: setoid → setoid1.
93 [ napply (qpowerclass A)
97 unification hint 0 (∀A. (λx,y.True) (carr1 (qpowerclass_setoid A)) (qpowerclass A)).
98 ncoercion qpowerclass_hint: ∀A: setoid. ∀S: qpowerclass_setoid A. Ω \sup A ≝ λA.λS.S
99 on _S: (carr1 (qpowerclass_setoid ?)) to (Ω \sup ?).
101 nlemma mem_ok: ∀A. binary_morphism1 (setoid1_of_setoid A) (qpowerclass_setoid A) CPROP.
102 #A; napply mk_binary_morphism1
103 [ napply (λx.λS: qpowerclass_setoid A. x ∈ S) (* CSC: ??? *)
104 | #a; #a'; #b; #b'; #Ha; #Hb; (* CSC: qui *; non funziona *)
105 nwhd; nwhd in ⊢ (? (? % ??) (? % ??)); napply mk_iff; #H
106 [ ncases Hb; #Hb1; #_; napply Hb1; napply (. (mem_ok' …))
107 [ nassumption | napply Ha^-1 | ##skip ]
108 ##| ncases Hb; #_; #Hb2; napply Hb2; napply (. (mem_ok' …))
109 [ nassumption | napply Ha | ##skip ]##]
112 unification hint 0 (∀A,x,S. (λx,y.True) (fun21 ??? (mem_ok A) x S) (mem A S x)).
114 nlemma subseteq_ok: ∀A. binary_morphism1 (qpowerclass_setoid A) (qpowerclass_setoid A) CPROP.
115 #A; napply mk_binary_morphism1
116 [ napply (λS,S': qpowerclass_setoid ?. S ⊆ S')
117 | #a; #a'; #b; #b'; *; #Ha1; #Ha2; *; #Hb1; #Hb2; napply mk_iff; #H
118 [ napply (subseteq_trans … a' a) (* anche qui, perche' serve a'? *)
119 [ nassumption | napply (subseteq_trans … a b); nassumption ]
120 ##| napply (subseteq_trans … a a') (* anche qui, perche' serve a'? *)
121 [ nassumption | napply (subseteq_trans … a' b'); nassumption ] ##]
124 nlemma intersect_ok: ∀A. binary_morphism1 (qpowerclass_setoid A) (qpowerclass_setoid A) (qpowerclass_setoid A).
125 #A; napply mk_binary_morphism1
126 [ #S; #S'; napply mk_qpowerclass
128 | #a; #a'; #Ha; nwhd in ⊢ (? ? ? % %); napply mk_iff; *; #H1; #H2; napply conj
129 [##1,2: napply (. (mem_ok' …)^-1) [##3,6: nassumption |##1,4: nassumption |##*: ##skip]
130 ##|##3,4: napply (. (mem_ok' …)) [##2,5: nassumption |##1,4: nassumption |##*: ##skip]##]##]
131 ##| #a; #a'; #b; #b'; #Ha; #Hb; nwhd; napply conj; #x; nwhd in ⊢ (% → %); #H
132 [ napply (. ((#‡Ha^-1)‡(#‡Hb^-1))); nassumption
133 | napply (. ((#‡Ha)‡(#‡Hb))); nassumption ]##]
136 unification hint 0 (∀A.∀U,V.(λx,y.True) (fun21 ??? (intersect_ok A) U V) (intersect A U V)).
138 nlemma test: ∀A:setoid. ∀U,V:qpowerclass A. ∀x,x':setoid1_of_setoid A. x=x' → x ∈ U ∩ V → x' ∈ U ∩ V.
139 #A; #U; #V; #x; #x'; #H; #p;
140 (* CSC: senza la change non funziona! *)
141 nchange with (x' ∈ (fun21 ??? (intersect_ok A) U V));
142 napply (. (H^-1‡#)); nassumption.
146 (* qui non funziona una cippa *)
147 ndefinition image: ∀A,B. (carr A → carr B) → Ω \sup A → Ω \sup B ≝
148 λA,B:setoid.λf:carr A → carr B.λSa:Ω \sup A.
149 {y | ∃x. x ∈ Sa ∧ eq_rel (carr B) (eq B) ? ?(*(f x) y*)}.
150 ##[##2: napply (f x); ##|##3: napply y]
151 #a; #a'; #H; nwhd; nnormalize; (* per togliere setoid1_of_setoid *) napply (mk_iff ????);
152 *; #x; #Hx; napply (ex_intro … x)
153 [ napply (. (#‡(#‡#)));
155 ndefinition counter_image: ∀A,B. (A → B) → Ω \sup B → Ω \sup A ≝
156 λA,B,f,Sb. {x | ∃y. y ∈ Sb ∧ f x = y}.
159 (******************* compatible equivalence relations **********************)
161 nrecord compatible_equivalence_relation (A: setoid) : Type[1] ≝
162 { rel:> equivalence_relation A;
163 compatibility: ∀x,x':A. x=x' → eq_rel ? rel x x' (* coercion qui non va *)
166 ndefinition quotient: ∀A. compatible_equivalence_relation A → setoid.
167 #A; #R; napply mk_setoid
172 (******************* first omomorphism theorem for sets **********************)
174 ndefinition eqrel_of_morphism:
175 ∀A,B. unary_morphism A B → compatible_equivalence_relation A.
176 #A; #B; #f; napply mk_compatible_equivalence_relation
177 [ napply mk_equivalence_relation
178 [ napply (λx,y. f x = f y)
179 | #x; napply refl | #x; #y; napply sym | #x; #y; #z; napply trans]
180 ##| #x; #x'; #H; nwhd; napply (.= (†H)); napply refl ]
183 ndefinition canonical_proj: ∀A,R. unary_morphism A (quotient A R).
184 #A; #R; napply mk_unary_morphism
185 [ napply (λx.x) | #a; #a'; #H; napply (compatibility ? R … H) ]
188 ndefinition quotiented_mor:
189 ∀A,B.∀f:unary_morphism A B.
190 unary_morphism (quotient ? (eqrel_of_morphism ?? f)) B.
191 #A; #B; #f; napply mk_unary_morphism
192 [ napply f | #a; #a'; #H; nassumption]
195 nlemma first_omomorphism_theorem_functions1:
196 ∀A,B.∀f: unary_morphism A B.
197 ∀x. f x = quotiented_mor ??? (canonical_proj ? (eqrel_of_morphism ?? f) x).
198 #A; #B; #f; #x; napply refl;
201 ndefinition surjective ≝ λA,B.λf:unary_morphism A B. ∀y.∃x. f x = y.
203 ndefinition injective ≝ λA,B.λf:unary_morphism A B. ∀x,x'. f x = f x' → x = x'.
205 nlemma first_omomorphism_theorem_functions2:
206 ∀A,B.∀f: unary_morphism A B. surjective ?? (canonical_proj ? (eqrel_of_morphism ?? f)).
207 #A; #B; #f; nwhd; #y; napply (ex_intro … y); napply refl.
210 nlemma first_omomorphism_theorem_functions3:
211 ∀A,B.∀f: unary_morphism A B. injective ?? (quotiented_mor ?? f).
212 #A; #B; #f; nwhd; #x; #x'; #H; nassumption.