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 (* Ultima modifica: 05/08/2009 *)
21 (* ********************************************************************** *)
23 include "num/word16.ma".
24 include "num/byte8_lemmas.ma".
30 nlemma word16_destruct_1 :
32 mk_word16 x1 y1 = mk_word16 x2 y2 → x1 = x2.
33 #x1; #x2; #y1; #y2; #H;
34 nchange with (match mk_word16 x2 y2 with [ mk_word16 a _ ⇒ x1 = a ]);
40 nlemma word16_destruct_2 :
42 mk_word16 x1 y1 = mk_word16 x2 y2 → y1 = y2.
43 #x1; #x2; #y1; #y2; #H;
44 nchange with (match mk_word16 x2 y2 with [ mk_word16 _ b ⇒ y1 = b ]);
50 nlemma symmetric_eqw16 : symmetricT word16 bool eq_w16.
55 nchange with (((eq_b8 b3 b1)⊗(eq_b8 b4 b2)) = ((eq_b8 b1 b3)⊗(eq_b8 b2 b4)));
56 nrewrite > (symmetric_eqb8 b1 b3);
57 nrewrite > (symmetric_eqb8 b2 b4);
61 nlemma symmetric_andw16 : symmetricT word16 word16 and_w16.
66 nchange with ((mk_word16 (and_b8 b3 b1) (and_b8 b4 b2)) = (mk_word16 (and_b8 b1 b3) (and_b8 b2 b4)));
67 nrewrite > (symmetric_andb8 b1 b3);
68 nrewrite > (symmetric_andb8 b2 b4);
72 nlemma associative_andw16 : ∀w1,w2,w3.(and_w16 (and_w16 w1 w2) w3) = (and_w16 w1 (and_w16 w2 w3)).
80 nchange with (mk_word16 (and_b8 (and_b8 b1 b3) b5) (and_b8 (and_b8 b2 b4) b6) =
81 mk_word16 (and_b8 b1 (and_b8 b3 b5)) (and_b8 b2 (and_b8 b4 b6)));
82 nrewrite < (associative_andb8 b1 b3 b5);
83 nrewrite < (associative_andb8 b2 b4 b6);
87 nlemma symmetric_orw16 : symmetricT word16 word16 or_w16.
92 nchange with ((mk_word16 (or_b8 b3 b1) (or_b8 b4 b2)) = (mk_word16 (or_b8 b1 b3) (or_b8 b2 b4)));
93 nrewrite > (symmetric_orb8 b1 b3);
94 nrewrite > (symmetric_orb8 b2 b4);
98 nlemma associative_orw16 : ∀w1,w2,w3.(or_w16 (or_w16 w1 w2) w3) = (or_w16 w1 (or_w16 w2 w3)).
106 nchange with (mk_word16 (or_b8 (or_b8 b1 b3) b5) (or_b8 (or_b8 b2 b4) b6) =
107 mk_word16 (or_b8 b1 (or_b8 b3 b5)) (or_b8 b2 (or_b8 b4 b6)));
108 nrewrite < (associative_orb8 b1 b3 b5);
109 nrewrite < (associative_orb8 b2 b4 b6);
113 nlemma symmetric_xorw16 : symmetricT word16 word16 xor_w16.
118 nchange with ((mk_word16 (xor_b8 b3 b1) (xor_b8 b4 b2)) = (mk_word16 (xor_b8 b1 b3) (xor_b8 b2 b4)));
119 nrewrite > (symmetric_xorb8 b1 b3);
120 nrewrite > (symmetric_xorb8 b2 b4);
124 nlemma associative_xorw16 : ∀w1,w2,w3.(xor_w16 (xor_w16 w1 w2) w3) = (xor_w16 w1 (xor_w16 w2 w3)).
132 nchange with (mk_word16 (xor_b8 (xor_b8 b1 b3) b5) (xor_b8 (xor_b8 b2 b4) b6) =
133 mk_word16 (xor_b8 b1 (xor_b8 b3 b5)) (xor_b8 b2 (xor_b8 b4 b6)));
134 nrewrite < (associative_xorb8 b1 b3 b5);
135 nrewrite < (associative_xorb8 b2 b4 b6);
139 nlemma symmetric_plusw16_dc_dc : ∀w1,w2,c.plus_w16_dc_dc w1 w2 c = plus_w16_dc_dc w2 w1 c.
146 match plus_b8_dc_dc b2 b4 c with [ pair l c ⇒ match plus_b8_dc_dc b1 b3 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]] =
147 match plus_b8_dc_dc b4 b2 c with [ pair l c ⇒ match plus_b8_dc_dc b3 b1 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]]);
148 nrewrite > (symmetric_plusb8_dc_dc b4 b2 c);
149 ncases (plus_b8_dc_dc b2 b4 c);
152 match plus_b8_dc_dc b1 b3 c1 with [ pair h c' ⇒ pair … 〈h:b5〉 c' ] =
153 match plus_b8_dc_dc b3 b1 c1 with [ pair h c' ⇒ pair … 〈h:b5〉 c' ]);
154 nrewrite > (symmetric_plusb8_dc_dc b1 b3 c1);
158 nlemma symmetric_plusw16_dc_d : ∀w1,w2,c.plus_w16_dc_d w1 w2 c = plus_w16_dc_d w2 w1 c.
165 match plus_b8_dc_dc b2 b4 c with [ pair l c ⇒ 〈plus_b8_dc_d b1 b3 c:l〉 ] =
166 match plus_b8_dc_dc b4 b2 c with [ pair l c ⇒ 〈plus_b8_dc_d b3 b1 c:l〉 ]);
167 nrewrite > (symmetric_plusb8_dc_dc b4 b2 c);
168 ncases (plus_b8_dc_dc b2 b4 c);
170 nchange with (〈plus_b8_dc_d b1 b3 c1:b5〉 = 〈plus_b8_dc_d b3 b1 c1:b5〉);
171 nrewrite > (symmetric_plusb8_dc_d b1 b3 c1);
175 nlemma symmetric_plusw16_dc_c : ∀w1,w2,c.plus_w16_dc_c w1 w2 c = plus_w16_dc_c w2 w1 c.
182 plus_b8_dc_c b1 b3 (plus_b8_dc_c b2 b4 c) =
183 plus_b8_dc_c b3 b1 (plus_b8_dc_c b4 b2 c));
184 nrewrite > (symmetric_plusb8_dc_c b4 b2 c);
185 nrewrite > (symmetric_plusb8_dc_c b3 b1 (plus_b8_dc_c b2 b4 c));
189 nlemma symmetric_plusw16_d_dc : ∀w1,w2.plus_w16_d_dc w1 w2 = plus_w16_d_dc w2 w1.
196 match plus_b8_d_dc b2 b4 with [ pair l c ⇒ match plus_b8_dc_dc b1 b3 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]] =
197 match plus_b8_d_dc b4 b2 with [ pair l c ⇒ match plus_b8_dc_dc b3 b1 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]]);
198 nrewrite > (symmetric_plusb8_d_dc b4 b2);
199 ncases (plus_b8_d_dc b2 b4);
202 match plus_b8_dc_dc b1 b3 c with [ pair h c' ⇒ pair … 〈h:b5〉 c' ] =
203 match plus_b8_dc_dc b3 b1 c with [ pair h c' ⇒ pair … 〈h:b5〉 c' ]);
204 nrewrite > (symmetric_plusb8_dc_dc b1 b3 c);
208 nlemma symmetric_plusw16_d_d : ∀w1,w2.plus_w16_d_d w1 w2 = plus_w16_d_d w2 w1.
215 match plus_b8_d_dc b2 b4 with [ pair l c ⇒ 〈plus_b8_dc_d b1 b3 c:l〉 ] =
216 match plus_b8_d_dc b4 b2 with [ pair l c ⇒ 〈plus_b8_dc_d b3 b1 c:l〉 ]);
217 nrewrite > (symmetric_plusb8_d_dc b4 b2);
218 ncases (plus_b8_d_dc b2 b4);
220 nchange with (〈plus_b8_dc_d b1 b3 c:b5〉 = 〈plus_b8_dc_d b3 b1 c:b5〉);
221 nrewrite > (symmetric_plusb8_dc_d b1 b3 c);
225 nlemma symmetric_plusw16_d_c : ∀w1,w2.plus_w16_d_c w1 w2 = plus_w16_d_c w2 w1.
232 plus_b8_dc_c b1 b3 (plus_b8_d_c b2 b4) =
233 plus_b8_dc_c b3 b1 (plus_b8_d_c b4 b2));
234 nrewrite > (symmetric_plusb8_d_c b4 b2);
235 nrewrite > (symmetric_plusb8_dc_c b3 b1 (plus_b8_d_c b2 b4));
239 nlemma symmetric_mulb8 : symmetricT byte8 word16 mul_b8.
245 nchange with (match mul_ex e2 e4 with
246 [ mk_byte8 t1_h t1_l ⇒ match mul_ex e1 e4 with
247 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e3 e2 with
248 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e1 e3 with
249 [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,t3_h〉:〈t3_l,x0〉〉 〈〈x0,t2_h〉:〈t2_l,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈t1_h,t1_l〉〉
250 ]]]] = match mul_ex e4 e2 with
251 [ mk_byte8 t1_h t1_l ⇒ match mul_ex e3 e2 with
252 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e1 e4 with
253 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e3 e1 with
254 [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,t3_h〉:〈t3_l,x0〉〉 〈〈x0,t2_h〉:〈t2_l,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈t1_h,t1_l〉〉
256 nrewrite < (symmetric_mulex e2 e4);
257 ncases (mul_ex e2 e4);
259 nchange with (match mul_ex e1 e4 with
260 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e3 e2 with
261 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e1 e3 with
262 [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,t3_h〉:〈t3_l,x0〉〉 〈〈x0,t2_h〉:〈t2_l,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
263 ]]] = match mul_ex e3 e2 with
264 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e1 e4 with
265 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e3 e1 with
266 [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,t3_h〉:〈t3_l,x0〉〉 〈〈x0,t2_h〉:〈t2_l,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
268 ncases (mul_ex e3 e2);
270 ncases (mul_ex e1 e4);
272 nchange with (match mul_ex e1 e3 with
273 [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e7〉:〈e8,x0〉〉 〈〈x0,e9〉:〈e10,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
274 ] = match mul_ex e3 e1 with
275 [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e9〉:〈e10,x0〉〉 〈〈x0,e7〉:〈e8,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
277 nrewrite < (symmetric_mulex e1 e3);
278 ncases (mul_ex e1 e3);
280 nchange with ((plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e7〉:〈e8,x0〉〉 〈〈x0,e9〉:〈e10,x0〉〉) 〈〈e11,e12〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉) =
281 (plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e9〉:〈e10,x0〉〉 〈〈x0,e7〉:〈e8,x0〉〉) 〈〈e11,e12〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉));
282 nrewrite > (symmetric_plusw16_d_d 〈〈x0,e7〉:〈e8,x0〉〉 〈〈x0,e9〉:〈e10,x0〉〉);
286 nlemma eqw16_to_eq : ∀w1,w2:word16.(eq_w16 w1 w2 = true) → (w1 = w2).
291 nchange in ⊢ (% → ?) with (((eq_b8 b3 b1)⊗(eq_b8 b4 b2)) = true);
293 nrewrite < (eqb8_to_eq … (andb_true_true_l … H));
294 nrewrite < (eqb8_to_eq … (andb_true_true_r … H));
298 nlemma eq_to_eqw16 : ∀w1,w2.w1 = w2 → eq_w16 w1 w2 = true.
304 nrewrite < (word16_destruct_1 … H);
305 nrewrite < (word16_destruct_2 … H);
306 nchange with (((eq_b8 b3 b3)⊗(eq_b8 b4 b4)) = true);
307 nrewrite > (eq_to_eqb8 b3 b3 (refl_eq …));
308 nrewrite > (eq_to_eqb8 b4 b4 (refl_eq …));
313 nlemma decidable_w16_aux1 : ∀b1,b2,b3,b4.b1 ≠ b3 → 〈b1:b2〉 ≠ 〈b3:b4〉.
316 napply (H (word16_destruct_1 … H1)).
319 nlemma decidable_w16_aux2 : ∀b1,b2,b3,b4.b2 ≠ b4 → 〈b1:b2〉 ≠ 〈b3:b4〉.
322 napply (H (word16_destruct_2 … H1)).
325 nlemma decidable_w16 : ∀x,y:word16.decidable (x = y).
326 #x; nelim x; #b1; #b2;
327 #y; nelim y; #b3; #b4;
329 napply (or2_elim (b1 = b3) (b1 ≠ b3) ? (decidable_b8 b1 b3) …);
330 ##[ ##2: #H; napply (or2_intro2 … (decidable_w16_aux1 b1 b2 b3 b4 H))
331 ##| ##1: #H; napply (or2_elim (b2 = b4) (b2 ≠ b4) ? (decidable_b8 b2 b4) …);
332 ##[ ##2: #H1; napply (or2_intro2 … (decidable_w16_aux2 b1 b2 b3 b4 H1))
333 ##| ##1: #H1; nrewrite > H; nrewrite > H1;
334 napply (or2_intro1 … (refl_eq ? 〈b3:b4〉))
339 nlemma neqw16_to_neq : ∀w1,w2:word16.(eq_w16 w1 w2 = false) → (w1 ≠ w2).
344 nchange with ((((eq_b8 b3 b1) ⊗ (eq_b8 b4 b2)) = false) → ?);
346 napply (or2_elim ((eq_b8 b3 b1) = false) ((eq_b8 b4 b2) = false) ? (andb_false2 … H) …);
347 ##[ ##1: #H1; napply (decidable_w16_aux1 … (neqb8_to_neq … H1))
348 ##| ##2: #H1; napply (decidable_w16_aux2 … (neqb8_to_neq … H1))
352 nlemma word16_destruct : ∀b1,b2,b3,b4.〈b1:b2〉 ≠ 〈b3:b4〉 → b1 ≠ b3 ∨ b2 ≠ b4.
355 napply (or2_elim (b1 = b3) (b1 ≠ b3) ? (decidable_b8 b1 b3) …);
356 ##[ ##2: #H1; napply (or2_intro1 … H1)
357 ##| ##1: #H1; napply (or2_elim (b2 = b4) (b2 ≠ b4) ? (decidable_b8 b2 b4) …);
358 ##[ ##2: #H2; napply (or2_intro2 … H2)
359 ##| ##1: #H2; nrewrite > H1 in H:(%);
361 #H; nelim (H (refl_eq …))
366 nlemma neq_to_neqw16 : ∀w1,w2.w1 ≠ w2 → eq_w16 w1 w2 = false.
370 #H; nchange with (((eq_b8 b1 b3) ⊗ (eq_b8 b2 b4)) = false);
371 napply (or2_elim (b1 ≠ b3) (b2 ≠ b4) ? (word16_destruct … H) …);
372 ##[ ##1: #H1; nrewrite > (neq_to_neqb8 … H1); nnormalize; napply refl_eq
373 ##| ##2: #H1; nrewrite > (neq_to_neqb8 … H1);
374 nrewrite > (symmetric_andbool (eq_b8 b1 b3) false);
375 nnormalize; napply refl_eq