]> matita.cs.unibo.it Git - helm.git/blob - matitaB/matita/contribs/ng_assembly2/universe/universe.ma
71eec785e1a6d0a588e323a19a06455ad4fa5b6c
[helm.git] / matitaB / matita / contribs / ng_assembly2 / universe / universe.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 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
19 (*   Sviluppo: 2008-2010                                                  *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "common/nelist.ma".
24 include "common/prod.ma".
25
26 nlet rec nmember_natList (elem:nat) (l:ne_list nat) on l ≝
27  match l with
28   [ ne_nil h ⇒ ⊖(eqc ? elem h)
29   | ne_cons h t ⇒ match eqc ? elem h with
30    [ true ⇒ false | false ⇒ nmember_natList elem t ]
31   ].
32
33 (* elem presente una ed una sola volta in l *)
34 nlet rec member_natList (elem:nat) (l:ne_list nat) on l ≝
35  match l with
36   [ ne_nil h ⇒ eqc ? elem h
37   | ne_cons h t ⇒ match eqc ? elem h with
38     [ true ⇒ nmember_natList elem t | false ⇒ member_natList elem t ]
39   ].
40
41 (* costruttore di un sottouniverso:
42    S_EL cioe' uno qualsiasi degli elementi del sottouniverso
43 *)
44 ninductive S_UN (l:ne_list nat) : Type ≝
45  S_EL : Πx:nat.((member_natList x l) = true) → S_UN l.
46
47 ndefinition getelem : ∀l.∀e:S_UN l.nat.
48  #l; #s; nelim s;
49  #u; #dim;
50  napply u.
51 nqed.
52
53 ndefinition eq_SUN ≝ λl.λx,y:S_UN l.eq_nat (getelem ? x) (getelem ? y).
54
55 ndefinition getdim : ∀l.∀e:S_UN l.member_natList (getelem ? e) l = true.
56  #l; #s; nelim s;
57  #u; #dim;
58  napply dim.
59 nqed.
60
61 nlemma SUN_destruct_1
62  : ∀l.∀e1,e2.∀dim1,dim2.S_EL l e1 dim1 = S_EL l e2 dim2 → e1 = e2.
63  #l; #e1; #e2; #dim1; #dim2; #H;
64  nchange with (match S_EL l e2 dim2 with [ S_EL a _ ⇒ e1 = a ]);
65  nrewrite < H;
66  nnormalize;
67  napply refl_eq.
68 nqed.
69
70 (* destruct universale *)
71 ndefinition SUN_destruct : ∀l.∀x,y:S_UN l.∀P:Prop.x = y → match eq_SUN l x y with [ true ⇒ P → P | false ⇒ P ].
72  #l; #x; nelim x;
73  #u1; #dim1;
74  #y; nelim y;
75  #u2; #dim2;
76  #P;
77  nchange with (? → (match eq_nat u1 u2 with [ true ⇒ P → P | false ⇒ P ]));
78  #H;
79  nrewrite > (SUN_destruct_1 l … H);
80  nrewrite > (eq_to_eqc ? u2 u2 (refl_eq …));
81  nnormalize;
82  napply (λx.x).
83 nqed.
84
85 (* eq_to_eqxx universale *)
86 nlemma eq_to_eqSUN : ∀l.∀x,y:S_UN l.x = y → eq_SUN l x y = true.
87  #l; #x; nelim x;
88  #u1; #dim1;
89  #y; nelim y;
90  #u2; #dim2;
91  nchange with (? → (eqc ? u1 u2) = true);
92  #H; napply (eq_to_eqc ? u1 u2);
93  napply (SUN_destruct_1 l … H).
94 nqed.
95
96 (* neqxx_to_neq universale *)
97 nlemma neqSUN_to_neq : ∀l.∀x,y:S_UN l.eq_SUN l x y = false → x ≠ y.
98  #l; #n1; #n2; #H;
99  napply (not_to_not (n1 = n2) (eq_SUN l n1 n2 = true) …);
100  ##[ ##1: napply (eq_to_eqSUN l n1 n2)
101  ##| ##2: napply (eqfalse_to_neqtrue … H)
102  ##]
103 nqed.
104
105 (* eqxx_to_eq universale *)
106 (* !!! evidente ma come si fa? *)
107 naxiom eqSUN_to_eq_aux : ∀l,x,y.((getelem l x) = (getelem l y)) → x = y.
108
109 nlemma eqSUN_to_eq : ∀l.∀x,y:S_UN l.eq_SUN l x y = true → x = y.
110  #l; #x; #y;
111  nchange with (((eqc ? (getelem ? x) (getelem ? y)) = true) → x = y);
112  #H; napply (eqSUN_to_eq_aux l x y (eqc_to_eq … H)).
113 nqed.
114
115 (* neq_to_neqxx universale *)
116 nlemma neq_to_neqSUN : ∀l.∀x,y:S_UN l.x ≠ y → eq_SUN l x y = false.
117  #l; #n1; #n2; #H;
118  napply (neqtrue_to_eqfalse (eq_SUN l n1 n2));
119  napply (not_to_not (eq_SUN l n1 n2 = true) (n1 = n2) ? H);
120  napply (eqSUN_to_eq l n1 n2).
121 nqed.
122
123 (* decidibilita' universale *)
124 nlemma decidable_SUN : ∀l.∀x,y:S_UN l.decidable (x = y).
125  #l; #x; #y; nnormalize;
126  napply (or2_elim (eq_SUN l x y = true) (eq_SUN l x y = false) ? (decidable_bexpr ?));
127  ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqSUN_to_eq l … H))
128  ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqSUN_to_neq l … H))
129  ##]
130 nqed.
131
132 (* simmetria di uguaglianza universale *)
133 nlemma symmetric_eqSUN : ∀l.symmetricT (S_UN l) bool (eq_SUN l).
134  #l; #n1; #n2;
135  napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_SUN l n1 n2));
136  ##[ ##1: #H; nrewrite > H; napply refl_eq
137  ##| ##2: #H; nrewrite > (neq_to_neqSUN l n1 n2 H);
138           napply (symmetric_eq ? (eq_SUN l n2 n1) false);
139           napply (neq_to_neqSUN l n2 n1 (symmetric_neq ? n1 n2 H))
140  ##]
141 nqed.
142
143 (* scheletro di funzione generica ad 1 argomento *)
144 nlet rec farg1_auxT (T:Type) (l:ne_list nat) on l ≝
145  match l with
146   [ ne_nil _ ⇒ T
147   | ne_cons _ t ⇒ ProdT T (farg1_auxT T t)
148   ].
149
150 nlemma farg1_auxDim : ∀h,t,x.(eqc ? x h) = false → member_natList x (h§§t) = true → member_natList x t = true.
151  #h; #t; #x; #H; #H1;
152  nnormalize in H1:(%);
153  nrewrite > H in H1:(%);
154  nnormalize;
155  napply (λx.x).
156 nqed.
157
158 nlet rec farg1 (T:Type) (l:ne_list nat) on l ≝
159  match l with
160   [ ne_nil h ⇒ λarg:farg1_auxT T «£h».λx:S_UN «£h».arg
161   | ne_cons h t ⇒ λarg:farg1_auxT T (h§§t).λx:S_UN (h§§t).
162    match eqc ? (getelem ? x) h
163     return λy.(eqc ? (getelem ? x) h) = y → ?
164    with
165     [ true ⇒ λp:((eqc ? (getelem ? x) h) = true).fst … arg
166     | false ⇒ λp:((eqc ? (getelem ? x) h) = false).
167      farg1 T t
168       (snd … arg)
169       (S_EL t (getelem ? x) (farg1_auxDim h t (getelem ? x) p (getdim ? x)))
170     ] (refl_eq ? (eqc ? (getelem ? x) h))
171   ].
172
173 (* scheletro di funzione generica a 2 argomenti *)
174 nlet rec farg2 (T:Type) (l,lfix:ne_list nat) on l ≝
175  match l with
176   [ ne_nil h ⇒ λarg:farg1_auxT (farg1_auxT T lfix) «£h».λx:S_UN «£h».farg1 T lfix arg
177   | ne_cons h t ⇒ λarg:farg1_auxT (farg1_auxT T lfix) (h§§t).λx:S_UN (h§§t).
178    match eqc ? (getelem ? x) h
179     return λy.(eqc ? (getelem ? x) h) = y → ?
180    with
181     [ true ⇒ λp:((eqc ? (getelem ? x) h) = true).farg1 T lfix (fst … arg)
182     | false ⇒ λp:((eqc ? (getelem ? x) h) = false).
183      farg2 T t lfix
184       (snd … arg)
185       (S_EL t (getelem ? x) (farg1_auxDim h t (getelem ? x) p (getdim ? x)))
186     ] (refl_eq ? (eqc ? (getelem ? x) h))
187   ].
188
189 (* esempio0: universo ottale *)
190 ndefinition oct0 ≝ O.
191 ndefinition oct1 ≝ nat1.
192 ndefinition oct2 ≝ nat2.
193 ndefinition oct3 ≝ nat3.
194 ndefinition oct4 ≝ nat4.
195 ndefinition oct5 ≝ nat5.
196 ndefinition oct6 ≝ nat6.
197 ndefinition oct7 ≝ nat7.
198
199 ndefinition oct_UN ≝ « oct0 ; oct1 ; oct2 ; oct3 ; oct4 ; oct5 ; oct6 £ oct7 ».
200
201 ndefinition uoct0 ≝ S_EL oct_UN oct0 (refl_eq …).
202 ndefinition uoct1 ≝ S_EL oct_UN oct1 (refl_eq …).
203 ndefinition uoct2 ≝ S_EL oct_UN oct2 (refl_eq …).
204 ndefinition uoct3 ≝ S_EL oct_UN oct3 (refl_eq …).
205 ndefinition uoct4 ≝ S_EL oct_UN oct4 (refl_eq …).
206 ndefinition uoct5 ≝ S_EL oct_UN oct5 (refl_eq …).
207 ndefinition uoct6 ≝ S_EL oct_UN oct6 (refl_eq …).
208 ndefinition uoct7 ≝ S_EL oct_UN oct7 (refl_eq …).
209
210 (* esempio1: NOT ottale *)
211 ndefinition octNOT ≝
212  farg1 (S_UN oct_UN) oct_UN
213   (pair … uoct7 (pair … uoct6 (pair … uoct5 (pair … uoct4 (pair … uoct3 (pair … uoct2 (pair … uoct1 uoct0))))))). 
214
215 (* esempio2: AND ottale *)
216 ndefinition octAND0 ≝ pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 uoct0)))))).
217 ndefinition octAND1 ≝ pair … uoct0 (pair … uoct1 (pair … uoct0 (pair … uoct1 (pair … uoct0 (pair … uoct1 (pair … uoct0 uoct1)))))).
218 ndefinition octAND2 ≝ pair … uoct0 (pair … uoct0 (pair … uoct2 (pair … uoct2 (pair … uoct0 (pair … uoct0 (pair … uoct2 uoct2)))))).
219 ndefinition octAND3 ≝ pair … uoct0 (pair … uoct1 (pair … uoct2 (pair … uoct3 (pair … uoct0 (pair … uoct1 (pair … uoct2 uoct3)))))).
220 ndefinition octAND4 ≝ pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct4 (pair … uoct4 (pair … uoct4 uoct4)))))).
221 ndefinition octAND5 ≝ pair … uoct0 (pair … uoct1 (pair … uoct0 (pair … uoct1 (pair … uoct4 (pair … uoct5 (pair … uoct4 uoct5)))))).
222 ndefinition octAND6 ≝ pair … uoct0 (pair … uoct0 (pair … uoct2 (pair … uoct2 (pair … uoct4 (pair … uoct4 (pair … uoct6 uoct6)))))).
223 ndefinition octAND7 ≝ pair … uoct0 (pair … uoct1 (pair … uoct2 (pair … uoct3 (pair … uoct4 (pair … uoct5 (pair … uoct6 uoct7)))))).
224
225 ndefinition octAND ≝
226  farg2 (S_UN oct_UN) oct_UN oct_UN
227   (pair … octAND0 (pair … octAND1 (pair … octAND2 (pair … octAND3 (pair … octAND4 (pair … octAND5 (pair … octAND6 octAND7))))))).
228
229 (* ora e' possibile fare
230    octNOT uoctX
231    octAND uoctX uoctY
232 *)