]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/ng_assembly2/compiler/ast_type.ma
09e52bdc365fb2d7fca190ede7785150a080c214
[helm.git] / matita / matita / contribs / ng_assembly2 / compiler / ast_type.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 "compiler/ast_type_base.ma".
24
25 (* ************************* *)
26 (* dimensioni degli elementi *)
27 (* ************************* *)
28
29 nlemma asttype_destruct_base_base : ∀b1,b2.AST_TYPE_BASE b1 = AST_TYPE_BASE b2 → b1 = b2.
30  #b1; #b2; #H;
31  nchange with (match AST_TYPE_BASE b2 with [ AST_TYPE_BASE a ⇒ b1 = a | _ ⇒ False ]);
32  nrewrite < H;
33  nnormalize;
34  napply refl_eq.
35 nqed.
36
37 nlemma asttype_destruct_array_array_1 : ∀x1,x2,y1,y2.AST_TYPE_ARRAY x1 y1 = AST_TYPE_ARRAY x2 y2 → x1 = x2.
38  #x1; #x2; #y1; #y2; #H;
39  nchange with (match AST_TYPE_ARRAY x2 y2 with [ AST_TYPE_ARRAY a _ ⇒ x1 = a | _ ⇒ False ]);
40  nrewrite < H;
41  nnormalize;
42  napply refl_eq.
43 nqed.
44
45 nlemma asttype_destruct_array_array_2 : ∀x1,x2,y1,y2.AST_TYPE_ARRAY x1 y1 = AST_TYPE_ARRAY x2 y2 → y1 = y2.
46  #x1; #x2; #y1; #y2; #H;
47  nchange with (match AST_TYPE_ARRAY x2 y2 with [ AST_TYPE_ARRAY _ b ⇒ y1 = b | _ ⇒ False ]);
48  nrewrite < H;
49  nnormalize;
50  napply refl_eq.
51 nqed.
52
53 nlemma asttype_destruct_struct_struct : ∀b1,b2.AST_TYPE_STRUCT b1 = AST_TYPE_STRUCT b2 → b1 = b2.
54  #b1; #b2; #H;
55  nchange with (match AST_TYPE_STRUCT b2 with [ AST_TYPE_STRUCT a ⇒ b1 = a | _ ⇒ False ]);
56  nrewrite < H;
57  nnormalize;
58  napply refl_eq.
59 nqed.
60
61 ndefinition asttype_destruct_aux ≝
62 Πb1,b2:ast_type.ΠP:Prop.b1 = b2 →
63  match eq_asttype b1 b2 with [ true ⇒ P → P | false ⇒ P ].
64
65 ndefinition asttype_destruct : asttype_destruct_aux.
66  #b1; #b2; #P; #H;
67  nrewrite > H;
68  napply (ast_type_index … b2);
69  ##[ ##1: #e; nchange with (match eqc ? e e with [ true ⇒ P → P | false ⇒ P ]);
70           nrewrite > (eq_to_eqc ? e e (refl_eq …));
71           nnormalize; napply (λx.x);
72  ##| ##2: #e; #n; #H; nchange with (match (eq_asttype e e)⊗(eqc ? n n) with [ true ⇒ P → P | false ⇒ P]);
73           nrewrite > (eq_to_eqc ? n n (refl_eq …));
74           nrewrite > (symmetric_andbool (eq_asttype e e) true);
75           nchange with (match eq_asttype e e with [ true ⇒ P → P | false ⇒ P]);
76           napply H;
77  ##| ##3: #e; #H; nchange with (match eq_asttype e e with [ true ⇒ P → P | false ⇒ P]);
78           napply H;
79  ##| ##4: #hh; #tt; #H;
80           nchange with (match bfold_right_neList2 ?? tt tt with [ true ⇒ P → P | false ⇒ P ] →
81                         match (eq_asttype hh hh)⊗(bfold_right_neList2 ?? tt tt) with [ true ⇒ P → P | false ⇒ P ]);
82           #H1;
83           ncases (eq_asttype hh hh) in H:(%) ⊢ %; #H;
84           ncases (bfold_right_neList2 ? (λx1,x2.eq_asttype x1 x2) tt tt) in H1:(%) ⊢ %; #H1;
85           ##[ ##1: nnormalize; napply (λx.x);
86           ##| ##3: nnormalize in H:(%) ⊢ %; napply H
87           ##| ##*: nnormalize in H1:(%) ⊢ %; napply H1
88           ##]
89  ##]
90 nqed.
91
92 nlemma eq_to_eqasttype_aux1
93  : ∀nl1,nl2.
94   ((eq_asttype (AST_TYPE_STRUCT nl1) (AST_TYPE_STRUCT nl2)) = true) →
95   ((bfold_right_neList2 ? (λx,y.eq_asttype x y) nl1 nl2) = true).
96  #nl1; #nl2; #H;
97  napply H.
98 nqed.
99
100 nlemma eq_to_eqasttype : ∀t1,t2.t1 = t2 → eq_asttype t1 t2 = true.
101  #t1;
102  napply (ast_type_index … t1);
103  ##[ ##1: #b1; #t2; ncases t2;
104           ##[ ##1: #b2; #H; nrewrite > (asttype_destruct_base_base … H);
105                    nchange with ((eqc ? b2 b2) = true);
106                    nrewrite > (eq_to_eqc ? b2 b2 (refl_eq …));
107                    napply refl_eq
108           ##| ##2: #st2; #n2; #H; ndestruct (*napply (asttype_destruct … H)*)
109           ##| ##3: #nl2; #H; ndestruct (*napply (asttype_destruct … H)*)
110           ##]
111  ##| ##2: #st1; #n1; #H; #t2; ncases t2;
112           ##[ ##2: #st2; #n2; #H1;  nchange with (((eq_asttype st1 st2)⊗(eqc ? n1 n2)) = true);
113                    nrewrite > (H st2 (asttype_destruct_array_array_1 … H1));
114                    nrewrite > (eq_to_eqc ? n1 n2 (asttype_destruct_array_array_2 … H1));
115                    nnormalize;
116                    napply refl_eq
117           ##| ##1: #b2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
118           ##| ##3: #nl2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
119           ##]
120  ##| ##3: #hh1; #H; #t2; ncases t2;
121           ##[ ##3: #nl2; ncases nl2;
122                    ##[ ##1: #hh2; #H1; nchange with ((eq_asttype hh1 hh2) = true);
123                             nrewrite > (H hh2 (nelist_destruct_nil_nil ? hh1 hh2 (asttype_destruct_struct_struct … H1)));
124                             napply refl_eq
125                    ##| ##2: #hh2; #ll2; #H1;
126                             (* !!! ndestruct non va *)
127                             nelim (nelist_destruct_nil_cons ? hh1 hh2 ll2 (asttype_destruct_struct_struct … H1))
128                    ##]
129           ##| ##1: #b2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
130           ##| ##2: #st2; #n2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
131           ##]
132  ##| ##4: #hh1; #ll1; #H; #H1; #t2; ncases t2;
133           ##[ ##3: #nl2; ncases nl2;
134                    ##[ ##1: #hh2; #H2;
135                             (* !!! ndestruct non va *)
136                             nelim (nelist_destruct_cons_nil ? hh1 hh2 ll1 (asttype_destruct_struct_struct … H2))
137                    ##| ##2: #hh2; #ll2; #H2; nchange with (((eq_asttype hh1 hh2)⊗(bfold_right_neList2 ? (λx,y.eq_asttype x y) ll1 ll2)) = true);
138                             nrewrite > (H hh2 (nelist_destruct_cons_cons_1 … (asttype_destruct_struct_struct … H2)));
139                             nrewrite > (eq_to_eqasttype_aux1 ll1 ll2 (H1 (AST_TYPE_STRUCT ll2) ?));
140                             ##[ ##1: nnormalize; napply refl_eq
141                             ##| ##2: nrewrite > (nelist_destruct_cons_cons_2 … (asttype_destruct_struct_struct … H2));
142                                      napply refl_eq
143                             ##]
144                    ##]
145           ##| ##1: #b2; #H2; ndestruct (*napply (asttype_destruct … H2)*)
146           ##| ##2: #st2; #n2; #H2; ndestruct (*napply (asttype_destruct … H2)*)
147           ##]
148  ##]
149 nqed.
150
151 nlemma neqasttype_to_neq : ∀n1,n2.eq_asttype n1 n2 = false → n1 ≠ n2.
152  #n1; #n2; #H;
153  napply (not_to_not (n1 = n2) (eq_asttype n1 n2 = true) …);
154  ##[ ##1: napply (eq_to_eqasttype n1 n2)
155  ##| ##2: napply (eqfalse_to_neqtrue … H)
156  ##]
157 nqed.
158
159 nlemma eqasttype_to_eq : ∀t1,t2.eq_asttype t1 t2 = true → t1 = t2.
160  #t1;
161  napply (ast_type_index … t1);
162  ##[ ##1: #b1; #t2; ncases t2;
163           ##[ ##1: #b2; #H; nchange in H:(%) with ((eqc ? b1 b2) = true);
164                    nrewrite > (eqc_to_eq ? b1 b2 H);
165                    napply refl_eq
166           ##| ##2: #st2; #n2; nnormalize; #H; ndestruct (*napply (bool_destruct … H)*)
167           ##| ##3: #nl2; nnormalize; #H; ndestruct (*napply (bool_destruct … H)*)
168           ##]
169  ##| ##2: #st1; #n1; #H; #t2; ncases t2;
170           ##[ ##2: #st2; #n2; #H1; nchange in H1:(%) with (((eq_asttype st1 st2)⊗(eqc ? n1 n2)) = true);
171                    nrewrite > (H st2 (andb_true_true_l … H1));
172                    nrewrite > (eqc_to_eq ? n1 n2 (andb_true_true_r … H1));
173                    napply refl_eq
174           ##| ##1: #b2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
175           ##| ##3: #nl2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
176           ##]
177  ##| ##3: #hh1; #H; #t2; ncases t2;
178           ##[ ##3: #nl2; ncases nl2;
179                    ##[ ##1: #hh2; #H1; nchange in H1:(%) with ((eq_asttype hh1 hh2) = true);
180                             nrewrite > (H hh2 H1);
181                             napply refl_eq
182                    ##| ##2: #hh2; #ll2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
183                    ##]
184           ##| ##1: #b2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
185           ##| ##2: #st2; #n2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
186           ##]
187  ##| ##4: #hh1; #ll1; #H; #H1; #t2; ncases t2;
188           ##[ ##3: #nl2; ncases nl2;
189                    ##[ ##1: #hh2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
190                    ##| ##2: #hh2; #ll2; #H2; nchange in H2:(%) with (((eq_asttype hh1 hh2)⊗(bfold_right_neList2 ? (λx,y.eq_asttype x y) ll1 ll2)) = true);
191                             nrewrite > (H hh2 (andb_true_true_l … H2));
192                             nrewrite > (asttype_destruct_struct_struct ll1 ll2 (H1 (AST_TYPE_STRUCT ll2) (andb_true_true_r … H2)));
193                             napply refl_eq
194                    ##]
195           ##| ##1: #b2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
196           ##| ##2: #st2; #n2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
197           ##]
198  ##]
199 nqed.
200
201 nlemma neq_to_neqasttype : ∀n1,n2.n1 ≠ n2 → eq_asttype n1 n2 = false.
202  #n1; #n2; #H;
203  napply (neqtrue_to_eqfalse (eq_asttype n1 n2));
204  napply (not_to_not (eq_asttype n1 n2 = true) (n1 = n2) ? H);
205  napply (eqasttype_to_eq n1 n2).
206 nqed.
207
208 nlemma decidable_asttype : ∀x,y:ast_type.decidable (x = y).
209  #x; #y; nnormalize;
210  napply (or2_elim (eq_asttype x y = true) (eq_asttype x y = false) ? (decidable_bexpr ?));
211  ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqasttype_to_eq … H))
212  ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqasttype_to_neq … H))
213  ##]
214 nqed.
215
216 nlemma symmetric_eqasttype : symmetricT ast_type bool eq_asttype.
217  #n1; #n2;
218  napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_asttype n1 n2));
219  ##[ ##1: #H; nrewrite > H; napply refl_eq
220  ##| ##2: #H; nrewrite > (neq_to_neqasttype n1 n2 H);
221           napply (symmetric_eq ? (eq_asttype n2 n1) false);
222           napply (neq_to_neqasttype n2 n1 (symmetric_neq ? n1 n2 H))
223  ##]
224 nqed.
225
226 nlemma isbastbasetype_to_isastbasetype : ∀ast.isb_ast_base_type ast = true → is_ast_base_type ast.
227  #ast;
228  ncases ast;
229  nnormalize;
230  ##[ ##1: #t; #H; napply I
231  ##| ##2: #t; #n; #H; ndestruct (*napply (bool_destruct … H)*)
232  ##| ##3: #t; #H; ndestruct (*napply (bool_destruct … H)*)
233  ##]
234 nqed.
235
236 nlemma isntbastbasetype_to_isntastbasetype : ∀ast.isntb_ast_base_type ast = true → isnt_ast_base_type ast.
237  #ast;
238  ncases ast;
239  nnormalize;
240  ##[ ##1: #t; #H; ndestruct (*napply (bool_destruct … H)*)
241  ##| ##2: #t; #n; #H; napply I
242  ##| ##3: #l; #H; napply I
243  ##]
244 nqed.
245
246 nlemma asttype_is_comparable : comparable.
247  @ ast_type
248   ##[ napply (AST_TYPE_BASE AST_BASE_TYPE_BYTE8)
249   ##| napply (λx.false)
250   ##| napply eq_asttype
251   ##| napply eqasttype_to_eq
252   ##| napply eq_to_eqasttype
253   ##| napply neqasttype_to_neq
254   ##| napply neq_to_neqasttype
255   ##| napply decidable_asttype
256   ##| napply symmetric_eqasttype
257   ##]
258 nqed.
259
260 unification hint 0 ≔ ⊢ carr asttype_is_comparable ≡ ast_type.