]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/sets/sets.ma
Setoid rewriting as unification hinting. Does not work recursively yet.
[helm.git] / helm / software / matita / nlibrary / sets / sets.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (******************* SETS OVER TYPES *****************)
16
17 include "logic/connectives.ma".
18
19 nrecord powerclass (A: Type[0]) : Type[1] ≝ { mem: A → CProp[0] }.
20
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).
24
25 ndefinition subseteq ≝ λA.λU,V.∀a:A. a ∈ U → a ∈ V.
26 interpretation "subseteq" 'subseteq U V = (subseteq ? U V).
27
28 ndefinition overlaps ≝ λA.λU,V.∃x:A.x ∈ U ∧ x ∈ V.
29 interpretation "overlaps" 'overlaps U V = (overlaps ? U V).
30
31 ndefinition intersect ≝ λA.λU,V:Ω \sup A.{ x | x ∈ U ∧ x ∈ V }.
32 interpretation "intersect" 'intersects U V = (intersect ? U V).
33
34 ndefinition union ≝ λA.λU,V:Ω \sup A.{ x | x ∈ U ∨ x ∈ V }.
35 interpretation "union" 'union U V = (union ? U V).
36
37 nlemma subseteq_refl: ∀A.∀S: Ω \sup A. S ⊆ S.
38  #A; #S; #x; #H; nassumption.
39 nqed.
40
41 nlemma subseteq_trans: ∀A.∀S,T,U: Ω \sup A. S ⊆ T → T ⊆ U → S ⊆ U.
42  #A; #S; #T; #U; #H1; #H2; #x; #P; napply H2; napply H1; nassumption.
43 nqed.
44
45 include "properties/relations1.ma".
46
47 ndefinition seteq: ∀A. equivalence_relation1 (Ω \sup A).
48  #A; napply mk_equivalence_relation1
49   [ napply (λS,S'. S ⊆ S' ∧ S' ⊆ S)
50   | #S; napply conj; napply subseteq_refl
51   | #S; #S'; *; #H1; #H2; napply conj; nassumption
52   | #S; #T; #U; *; #H1; #H2; *; #H3; #H4; napply conj; napply subseteq_trans;
53      ##[##2,5: nassumption |##1,4: ##skip |##*: nassumption]##]
54 nqed. 
55
56 include "sets/setoids1.ma".
57
58 ndefinition powerclass_setoid: Type[0] → setoid1.
59  #A; napply mk_setoid1
60   [ napply (Ω \sup A)
61   | napply seteq ]
62 nqed. 
63
64 (************ SETS OVER SETOIDS ********************)
65
66 include "logic/cprop.ma".
67
68 nrecord qpowerclass (A: setoid) : Type[1] ≝
69  { pc:> Ω \sup A;
70    mem_ok': ∀x,x':A. x=x' → (x ∈ pc) = (x' ∈ pc) 
71  }.
72
73 ndefinition qseteq: ∀A. equivalence_relation1 (qpowerclass A).
74  #A; napply mk_equivalence_relation1
75   [ napply (λS,S':qpowerclass A. eq_rel1 ? (eq1 (powerclass_setoid A)) S S')
76   | #S; napply (refl1 ? (seteq A))
77   | #S; #S'; napply (sym1 ? (seteq A))
78   | #S; #T; #U; napply (trans1 ? (seteq A))]
79 nqed.
80
81 ndefinition qpowerclass_setoid: setoid → setoid1.
82  #A; napply mk_setoid1
83   [ napply (qpowerclass A)
84   | napply (qseteq A) ]
85 nqed.
86
87 unification hint 0 (∀A. (λx,y.True) (carr1 (qpowerclass_setoid A)) (qpowerclass A)).
88 ncoercion qpowerclass_hint: ∀A: setoid. ∀S: qpowerclass_setoid A. Ω \sup A ≝ λA.λS.S
89  on _S: (carr1 (qpowerclass_setoid ?)) to (Ω \sup ?). 
90
91 nlemma mem_ok: ∀A. binary_morphism1 (setoid1_of_setoid A) (qpowerclass_setoid A) CPROP.
92  #A; napply mk_binary_morphism1
93   [ napply (λx.λS: qpowerclass_setoid A. x ∈ S) (* CSC: ??? *)
94   | #a; #a'; #b; #b'; #Ha; #Hb; (* CSC: qui *; non funziona *)
95     nwhd; nwhd in ⊢ (? (? % ??) (? % ??)); napply mk_iff; #H
96      [ ncases Hb; #Hb1; #_; napply Hb1; napply (. (mem_ok' …))
97         [ nassumption | napply Ha^-1 | ##skip ]
98    ##| ncases Hb; #_; #Hb2; napply Hb2; napply (. (mem_ok' …))
99         [ nassumption | napply Ha | ##skip ]##]
100 nqed.
101
102 unification hint 0 (∀A,x,S. (λx,y.True) (fun21 ??? (mem_ok A) x S) (mem A S x)).
103   
104 nlemma subseteq_ok: ∀A. binary_morphism1 (qpowerclass_setoid A) (qpowerclass_setoid A) CPROP.
105  #A; napply mk_binary_morphism1
106   [ napply (λS,S': qpowerclass_setoid ?. S ⊆ S')
107   | #a; #a'; #b; #b'; *; #Ha1; #Ha2; *; #Hb1; #Hb2; napply mk_iff; #H
108      [ napply (subseteq_trans … a' a) (* anche qui, perche' serve a'? *)
109         [ nassumption | napply (subseteq_trans … a b); nassumption ]
110    ##| napply (subseteq_trans … a a') (* anche qui, perche' serve a'? *)
111         [ nassumption | napply (subseteq_trans … a' b'); nassumption ] ##]
112 nqed.
113
114 nlemma intersect_ok: ∀A. binary_morphism1 (qpowerclass_setoid A) (qpowerclass_setoid A) (qpowerclass_setoid A).
115  #A; napply mk_binary_morphism1
116   [ #S; #S'; napply mk_qpowerclass
117      [ napply (S ∩ S')
118      | #a; #a'; #Ha; nwhd in ⊢ (? ? ? % %); napply mk_iff; *; #H1; #H2; napply conj
119         [##1,2: napply (. (mem_ok' …)^-1) [##3,6: nassumption |##1,4: nassumption |##*: ##skip]
120       ##|##3,4: napply (. (mem_ok' …)) [##2,5: nassumption |##1,4: nassumption |##*: ##skip]##]##]
121  ##| #a; #a'; #b; #b'; #Ha; #Hb; nwhd; napply conj; #x; nwhd in ⊢ (% → %); #H
122       [ napply (. ((#‡Ha^-1)‡(#‡Hb^-1))); nassumption
123       | napply (. ((#‡Ha)‡(#‡Hb))); nassumption ]##]
124 nqed.
125
126 unification hint 0 (∀A.∀U,V.(λx,y.True) (fun21 ??? (intersect_ok A) U V) (intersect A U V)).
127
128 nlemma test: ∀A:setoid. ∀U,V:qpowerclass A. ∀x,x':setoid1_of_setoid A. x=x' → x ∈ U ∩ V → x' ∈ U ∩ V.
129  #A; #U; #V; #x; #x'; #H; #p;
130   (* CSC: senza la change non funziona! *)
131   nchange with (x' ∈ (fun21 ??? (intersect_ok A) U V));
132   napply (. (H^-1‡#)); nassumption.
133 nqed.
134
135 (*
136 (* qui non funziona una cippa *)
137 ndefinition image: ∀A,B. (carr A → carr B) → Ω \sup A → Ω \sup B ≝
138  λA,B:setoid.λf:carr A → carr B.λSa:Ω \sup A.
139   {y | ∃x. x ∈ Sa ∧ eq_rel (carr B) (eq B) ? ?(*(f x) y*)}.
140   ##[##2: napply (f x); ##|##3: napply y]
141  #a; #a'; #H; nwhd; nnormalize; (* per togliere setoid1_of_setoid *) napply (mk_iff ????);
142  *; #x; #Hx; napply (ex_intro … x)
143   [ napply (. (#‡(#‡#))); 
144
145 ndefinition counter_image: ∀A,B. (A → B) → Ω \sup B → Ω \sup A ≝
146  λA,B,f,Sb. {x | ∃y. y ∈ Sb ∧ f x = y}.
147 *)