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 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
18 (* Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Sviluppo: 2008-2010 *)
21 (* ********************************************************************** *)
23 include "compiler/ast_type_base.ma".
25 (* ************************* *)
26 (* dimensioni degli elementi *)
27 (* ************************* *)
29 nlemma asttype_destruct_base_base : ∀b1,b2.AST_TYPE_BASE b1 = AST_TYPE_BASE b2 → b1 = b2.
31 nchange with (match AST_TYPE_BASE b2 with [ AST_TYPE_BASE a ⇒ b1 = a | _ ⇒ False ]);
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 ]);
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 ]);
53 nlemma asttype_destruct_struct_struct : ∀b1,b2.AST_TYPE_STRUCT b1 = AST_TYPE_STRUCT b2 → b1 = b2.
55 nchange with (match AST_TYPE_STRUCT b2 with [ AST_TYPE_STRUCT a ⇒ b1 = a | _ ⇒ False ]);
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 ].
65 ndefinition asttype_destruct : asttype_destruct_aux.
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]);
77 ##| ##3: #e; #H; nchange with (match eq_asttype e e with [ true ⇒ P → P | false ⇒ P]);
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 ]);
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
92 nlemma eq_to_eqasttype_aux1
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).
100 nlemma eq_to_eqasttype : ∀t1,t2.t1 = t2 → eq_asttype t1 t2 = true.
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 …));
108 ##| ##2: #st2; #n2; #H; ndestruct (*napply (asttype_destruct … H)*)
109 ##| ##3: #nl2; #H; ndestruct (*napply (asttype_destruct … H)*)
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));
117 ##| ##1: #b2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
118 ##| ##3: #nl2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
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)));
125 ##| ##2: #hh2; #ll2; #H1;
126 (* !!! ndestruct non va *)
127 nelim (nelist_destruct_nil_cons ? hh1 hh2 ll2 (asttype_destruct_struct_struct … H1))
129 ##| ##1: #b2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
130 ##| ##2: #st2; #n2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
132 ##| ##4: #hh1; #ll1; #H; #H1; #t2; ncases t2;
133 ##[ ##3: #nl2; ncases nl2;
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));
145 ##| ##1: #b2; #H2; ndestruct (*napply (asttype_destruct … H2)*)
146 ##| ##2: #st2; #n2; #H2; ndestruct (*napply (asttype_destruct … H2)*)
151 nlemma neqasttype_to_neq : ∀n1,n2.eq_asttype n1 n2 = false → n1 ≠ n2.
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)
159 nlemma eqasttype_to_eq : ∀t1,t2.eq_asttype t1 t2 = true → t1 = t2.
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);
166 ##| ##2: #st2; #n2; nnormalize; #H; ndestruct (*napply (bool_destruct … H)*)
167 ##| ##3: #nl2; nnormalize; #H; ndestruct (*napply (bool_destruct … H)*)
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));
174 ##| ##1: #b2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
175 ##| ##3: #nl2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
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);
182 ##| ##2: #hh2; #ll2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
184 ##| ##1: #b2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
185 ##| ##2: #st2; #n2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
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)));
195 ##| ##1: #b2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
196 ##| ##2: #st2; #n2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
201 nlemma neq_to_neqasttype : ∀n1,n2.n1 ≠ n2 → eq_asttype n1 n2 = false.
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).
208 nlemma decidable_asttype : ∀x,y:ast_type.decidable (x = y).
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))
216 nlemma symmetric_eqasttype : symmetricT ast_type bool eq_asttype.
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))
226 nlemma isbastbasetype_to_isastbasetype : ∀ast.isb_ast_base_type ast = true → is_ast_base_type ast.
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)*)
236 nlemma isntbastbasetype_to_isntastbasetype : ∀ast.isntb_ast_base_type ast = true → isnt_ast_base_type ast.
240 ##[ ##1: #t; #H; ndestruct (*napply (bool_destruct … H)*)
241 ##| ##2: #t; #n; #H; napply I
242 ##| ##3: #l; #H; napply I
246 nlemma asttype_is_comparable : comparable.
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
260 unification hint 0 ≔ ⊢ carr asttype_is_comparable ≡ ast_type.