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: Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
21 (* ********************************************************************** *)
23 include "freescale/byte8_lemmas.ma".
24 include "freescale/word16.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
147 [ pair l c ⇒ match plus_b8_dc_dc b1 b3 c with
148 [ pair h c' ⇒ pair ?? 〈h:l〉 c' ]] =
149 match plus_b8_dc_dc b4 b2 c with
150 [ pair l c ⇒ match plus_b8_dc_dc b3 b1 c with
151 [ pair h c' ⇒ pair ?? 〈h:l〉 c' ]]);
152 nrewrite > (symmetric_plusb8_dc_dc b4 b2 c);
153 ncases (plus_b8_dc_dc b2 b4 c);
156 match plus_b8_dc_dc b1 b3 c1 with
157 [ pair h c' ⇒ pair ?? 〈h:b5〉 c' ] =
158 match plus_b8_dc_dc b3 b1 c1 with
159 [ pair h c' ⇒ pair ?? 〈h:b5〉 c' ]);
160 nrewrite > (symmetric_plusb8_dc_dc b1 b3 c1);
164 nlemma symmetric_plusw16_dc_d : ∀w1,w2,c.plus_w16_dc_d w1 w2 c = plus_w16_dc_d w2 w1 c.
171 match plus_b8_dc_dc b2 b4 c with
172 [ pair l c ⇒ 〈plus_b8_dc_d b1 b3 c:l〉 ] =
173 match plus_b8_dc_dc b4 b2 c with
174 [ pair l c ⇒ 〈plus_b8_dc_d b3 b1 c:l〉 ]);
175 nrewrite > (symmetric_plusb8_dc_dc b4 b2 c);
176 ncases (plus_b8_dc_dc b2 b4 c);
178 nchange with (〈plus_b8_dc_d b1 b3 c1:b5〉 = 〈plus_b8_dc_d b3 b1 c1:b5〉);
179 nrewrite > (symmetric_plusb8_dc_d b1 b3 c1);
183 nlemma symmetric_plusw16_dc_c : ∀w1,w2,c.plus_w16_dc_c w1 w2 c = plus_w16_dc_c w2 w1 c.
190 plus_b8_dc_c b1 b3 (plus_b8_dc_c b2 b4 c) =
191 plus_b8_dc_c b3 b1 (plus_b8_dc_c b4 b2 c));
192 nrewrite > (symmetric_plusb8_dc_c b4 b2 c);
193 nrewrite > (symmetric_plusb8_dc_c b3 b1 (plus_b8_dc_c b2 b4 c));
197 nlemma symmetric_plusw16_d_dc : ∀w1,w2.plus_w16_d_dc w1 w2 = plus_w16_d_dc w2 w1.
204 match plus_b8_d_dc b2 b4 with
205 [ pair l c ⇒ match plus_b8_dc_dc b1 b3 c with
206 [ pair h c' ⇒ pair ?? 〈h:l〉 c' ]] =
207 match plus_b8_d_dc b4 b2 with
208 [ pair l c ⇒ match plus_b8_dc_dc b3 b1 c with
209 [ pair h c' ⇒ pair ?? 〈h:l〉 c' ]]);
210 nrewrite > (symmetric_plusb8_d_dc b4 b2);
211 ncases (plus_b8_d_dc b2 b4);
214 match plus_b8_dc_dc b1 b3 c with
215 [ pair h c' ⇒ pair ?? 〈h:b5〉 c' ] =
216 match plus_b8_dc_dc b3 b1 c with
217 [ pair h c' ⇒ pair ?? 〈h:b5〉 c' ]);
218 nrewrite > (symmetric_plusb8_dc_dc b1 b3 c);
222 nlemma symmetric_plusw16_d_d : ∀w1,w2.plus_w16_d_d w1 w2 = plus_w16_d_d w2 w1.
229 match plus_b8_d_dc b2 b4 with
230 [ pair l c ⇒ 〈plus_b8_dc_d b1 b3 c:l〉 ] =
231 match plus_b8_d_dc b4 b2 with
232 [ pair l c ⇒ 〈plus_b8_dc_d b3 b1 c:l〉 ]);
233 nrewrite > (symmetric_plusb8_d_dc b4 b2);
234 ncases (plus_b8_d_dc b2 b4);
236 nchange with (〈plus_b8_dc_d b1 b3 c:b5〉 = 〈plus_b8_dc_d b3 b1 c:b5〉);
237 nrewrite > (symmetric_plusb8_dc_d b1 b3 c);
241 nlemma symmetric_plusw16_d_c : ∀w1,w2.plus_w16_d_c w1 w2 = plus_w16_d_c w2 w1.
248 plus_b8_dc_c b1 b3 (plus_b8_d_c b2 b4) =
249 plus_b8_dc_c b3 b1 (plus_b8_d_c b4 b2));
250 nrewrite > (symmetric_plusb8_d_c b4 b2);
251 nrewrite > (symmetric_plusb8_dc_c b3 b1 (plus_b8_d_c b2 b4));
255 nlemma symmetric_mulb8 : symmetricT byte8 word16 mul_b8.
261 nchange with (match mul_ex e2 e4 with
262 [ mk_byte8 t1_h t1_l ⇒ match mul_ex e1 e4 with
263 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e3 e2 with
264 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e1 e3 with
265 [ 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〉〉
266 ]]]] = match mul_ex e4 e2 with
267 [ mk_byte8 t1_h t1_l ⇒ match mul_ex e3 e2 with
268 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e1 e4 with
269 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e3 e1 with
270 [ 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〉〉
272 nrewrite < (symmetric_mulex e2 e4);
273 ncases (mul_ex e2 e4);
275 nchange with (match mul_ex e1 e4 with
276 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e3 e2 with
277 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e1 e3 with
278 [ 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〉〉
279 ]]] = match mul_ex e3 e2 with
280 [ mk_byte8 t2_h t2_l ⇒ match mul_ex e1 e4 with
281 [ mk_byte8 t3_h t3_l ⇒ match mul_ex e3 e1 with
282 [ 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〉〉
284 ncases (mul_ex e3 e2);
286 ncases (mul_ex e1 e4);
288 nchange with (match mul_ex e1 e3 with
289 [ 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〉〉
290 ] = match mul_ex e3 e1 with
291 [ 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〉〉
293 nrewrite < (symmetric_mulex e1 e3);
294 ncases (mul_ex e1 e3);
296 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〉〉) =
297 (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〉〉));
298 nrewrite > (symmetric_plusw16_d_d 〈〈x0,e7〉:〈e8,x0〉〉 〈〈x0,e9〉:〈e10,x0〉〉);
302 nlemma eqw16_to_eq : ∀w1,w2:word16.(eq_w16 w1 w2 = true) → (w1 = w2).
307 nchange in ⊢ (% → ?) with (((eq_b8 b3 b1)⊗(eq_b8 b4 b2)) = true);
309 nrewrite < (eqb8_to_eq ?? (andb_true_true_l ?? H));
310 nrewrite < (eqb8_to_eq ?? (andb_true_true_r ?? H));
314 nlemma eq_to_eqw16 : ∀w1,w2.w1 = w2 → eq_w16 w1 w2 = true.
320 nrewrite < (word16_destruct_1 ???? H);
321 nrewrite < (word16_destruct_2 ???? H);
322 nchange with (((eq_b8 b3 b3)⊗(eq_b8 b4 b4)) = true);
323 nrewrite > (eq_to_eqb8 b3 b3 (refl_eq ??));
324 nrewrite > (eq_to_eqb8 b4 b4 (refl_eq ??));