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/byte8.ma".
24 include "num/exadecim_lemmas.ma".
30 nlemma byte8_destruct_1 :
32 mk_byte8 x1 y1 = mk_byte8 x2 y2 → x1 = x2.
33 #x1; #x2; #y1; #y2; #H;
34 nchange with (match mk_byte8 x2 y2 with [ mk_byte8 a _ ⇒ x1 = a ]);
40 nlemma byte8_destruct_2 :
42 mk_byte8 x1 y1 = mk_byte8 x2 y2 → y1 = y2.
43 #x1; #x2; #y1; #y2; #H;
44 nchange with (match mk_byte8 x2 y2 with [ mk_byte8 _ b ⇒ y1 = b ]);
50 nlemma symmetric_eqb8 : symmetricT byte8 bool eq_b8.
55 nchange with (((eq_ex e3 e1)⊗(eq_ex e4 e2)) = ((eq_ex e1 e3)⊗(eq_ex e2 e4)));
56 nrewrite > (symmetric_eqex e1 e3);
57 nrewrite > (symmetric_eqex e2 e4);
61 nlemma symmetric_andb8 : symmetricT byte8 byte8 and_b8.
66 nchange with ((mk_byte8 (and_ex e3 e1) (and_ex e4 e2)) = (mk_byte8 (and_ex e1 e3) (and_ex e2 e4)));
67 nrewrite > (symmetric_andex e1 e3);
68 nrewrite > (symmetric_andex e2 e4);
72 nlemma associative_andb8 : ∀b1,b2,b3.(and_b8 (and_b8 b1 b2) b3) = (and_b8 b1 (and_b8 b2 b3)).
80 nchange with (mk_byte8 (and_ex (and_ex e1 e3) e5) (and_ex (and_ex e2 e4) e6) =
81 mk_byte8 (and_ex e1 (and_ex e3 e5)) (and_ex e2 (and_ex e4 e6)));
82 nrewrite < (associative_andex e1 e3 e5);
83 nrewrite < (associative_andex e2 e4 e6);
87 nlemma symmetric_orb8 : symmetricT byte8 byte8 or_b8.
92 nchange with ((mk_byte8 (or_ex e3 e1) (or_ex e4 e2)) = (mk_byte8 (or_ex e1 e3) (or_ex e2 e4)));
93 nrewrite > (symmetric_orex e1 e3);
94 nrewrite > (symmetric_orex e2 e4);
98 nlemma associative_orb8 : ∀b1,b2,b3.(or_b8 (or_b8 b1 b2) b3) = (or_b8 b1 (or_b8 b2 b3)).
106 nchange with (mk_byte8 (or_ex (or_ex e1 e3) e5) (or_ex (or_ex e2 e4) e6) =
107 mk_byte8 (or_ex e1 (or_ex e3 e5)) (or_ex e2 (or_ex e4 e6)));
108 nrewrite < (associative_orex e1 e3 e5);
109 nrewrite < (associative_orex e2 e4 e6);
113 nlemma symmetric_xorb8 : symmetricT byte8 byte8 xor_b8.
118 nchange with ((mk_byte8 (xor_ex e3 e1) (xor_ex e4 e2)) = (mk_byte8 (xor_ex e1 e3) (xor_ex e2 e4)));
119 nrewrite > (symmetric_xorex e1 e3);
120 nrewrite > (symmetric_xorex e2 e4);
124 nlemma associative_xorb8 : ∀b1,b2,b3.(xor_b8 (xor_b8 b1 b2) b3) = (xor_b8 b1 (xor_b8 b2 b3)).
132 nchange with (mk_byte8 (xor_ex (xor_ex e1 e3) e5) (xor_ex (xor_ex e2 e4) e6) =
133 mk_byte8 (xor_ex e1 (xor_ex e3 e5)) (xor_ex e2 (xor_ex e4 e6)));
134 nrewrite < (associative_xorex e1 e3 e5);
135 nrewrite < (associative_xorex e2 e4 e6);
139 nlemma symmetric_plusb8_dc_dc : ∀b1,b2,c.plus_b8_dc_dc b1 b2 c = plus_b8_dc_dc b2 b1 c.
146 match plus_ex_dc_dc e2 e4 c with [ pair l c ⇒ match plus_ex_dc_dc e1 e3 c with [ pair h c' ⇒ pair … 〈h,l〉 c' ]] =
147 match plus_ex_dc_dc e4 e2 c with [ pair l c ⇒ match plus_ex_dc_dc e3 e1 c with [ pair h c' ⇒ pair … 〈h,l〉 c' ]]);
148 nrewrite > (symmetric_plusex_dc_dc e4 e2 c);
149 ncases (plus_ex_dc_dc e2 e4 c);
152 match plus_ex_dc_dc e1 e3 c1 with [ pair h c' ⇒ pair … 〈h,e5〉 c' ] =
153 match plus_ex_dc_dc e3 e1 c1 with [ pair h c' ⇒ pair … 〈h,e5〉 c' ]);
154 nrewrite > (symmetric_plusex_dc_dc e1 e3 c1);
158 nlemma symmetric_plusb8_dc_d : ∀b1,b2,c.plus_b8_dc_d b1 b2 c = plus_b8_dc_d b2 b1 c.
165 match plus_ex_dc_dc e2 e4 c with [ pair l c ⇒ 〈plus_ex_dc_d e1 e3 c,l〉 ] =
166 match plus_ex_dc_dc e4 e2 c with [ pair l c ⇒ 〈plus_ex_dc_d e3 e1 c,l〉 ]);
167 nrewrite > (symmetric_plusex_dc_dc e4 e2 c);
168 ncases (plus_ex_dc_dc e2 e4 c);
170 nchange with (〈plus_ex_dc_d e1 e3 c1,e5〉 = 〈plus_ex_dc_d e3 e1 c1,e5〉);
171 nrewrite > (symmetric_plusex_dc_d e1 e3 c1);
175 nlemma symmetric_plusb8_dc_c : ∀b1,b2,c.plus_b8_dc_c b1 b2 c = plus_b8_dc_c b2 b1 c.
182 plus_ex_dc_c e1 e3 (plus_ex_dc_c e2 e4 c) =
183 plus_ex_dc_c e3 e1 (plus_ex_dc_c e4 e2 c));
184 nrewrite > (symmetric_plusex_dc_c e4 e2 c);
185 nrewrite > (symmetric_plusex_dc_c e3 e1 (plus_ex_dc_c e2 e4 c));
189 nlemma symmetric_plusb8_d_dc : ∀b1,b2.plus_b8_d_dc b1 b2 = plus_b8_d_dc b2 b1.
196 match plus_ex_d_dc e2 e4 with [ pair l c ⇒ match plus_ex_dc_dc e1 e3 c with [ pair h c' ⇒ pair … 〈h,l〉 c' ]] =
197 match plus_ex_d_dc e4 e2 with [ pair l c ⇒ match plus_ex_dc_dc e3 e1 c with [ pair h c' ⇒ pair … 〈h,l〉 c' ]]);
198 nrewrite > (symmetric_plusex_d_dc e4 e2);
199 ncases (plus_ex_d_dc e2 e4);
202 match plus_ex_dc_dc e1 e3 c with [ pair h c' ⇒ pair … 〈h,e5〉 c' ] =
203 match plus_ex_dc_dc e3 e1 c with [ pair h c' ⇒ pair … 〈h,e5〉 c' ]);
204 nrewrite > (symmetric_plusex_dc_dc e1 e3 c);
208 nlemma symmetric_plusb8_d_d : ∀b1,b2.plus_b8_d_d b1 b2 = plus_b8_d_d b2 b1.
215 match plus_ex_d_dc e2 e4 with [ pair l c ⇒ 〈plus_ex_dc_d e1 e3 c,l〉 ] =
216 match plus_ex_d_dc e4 e2 with [ pair l c ⇒ 〈plus_ex_dc_d e3 e1 c,l〉 ]);
217 nrewrite > (symmetric_plusex_d_dc e4 e2);
218 ncases (plus_ex_d_dc e2 e4);
220 nchange with (〈plus_ex_dc_d e1 e3 c,e5〉 = 〈plus_ex_dc_d e3 e1 c,e5〉);
221 nrewrite > (symmetric_plusex_dc_d e1 e3 c);
225 nlemma symmetric_plusb8_d_c : ∀b1,b2.plus_b8_d_c b1 b2 = plus_b8_d_c b2 b1.
232 plus_ex_dc_c e1 e3 (plus_ex_d_c e2 e4) =
233 plus_ex_dc_c e3 e1 (plus_ex_d_c e4 e2));
234 nrewrite > (symmetric_plusex_d_c e4 e2);
235 nrewrite > (symmetric_plusex_dc_c e3 e1 (plus_ex_d_c e2 e4));
239 nlemma symmetric_mulex : symmetricT exadecim byte8 mul_ex.
247 nlemma eqb8_to_eq : ∀b1,b2:byte8.(eq_b8 b1 b2 = true) → (b1 = b2).
252 nchange in ⊢ (% → ?) with (((eq_ex e3 e1)⊗(eq_ex e4 e2)) = true);
254 nrewrite < (eqex_to_eq … (andb_true_true_l … H));
255 nrewrite < (eqex_to_eq … (andb_true_true_r … H));
259 nlemma eq_to_eqb8 : ∀b1,b2.b1 = b2 → eq_b8 b1 b2 = true.
265 nrewrite < (byte8_destruct_1 … H);
266 nrewrite < (byte8_destruct_2 … H);
267 nchange with (((eq_ex e3 e3)⊗(eq_ex e4 e4)) = true);
268 nrewrite > (eq_to_eqex e3 e3 (refl_eq …));
269 nrewrite > (eq_to_eqex e4 e4 (refl_eq …));
274 nlemma decidable_b8_aux1 : ∀e1,e2,e3,e4.e1 ≠ e3 → 〈e1,e2〉 ≠ 〈e3,e4〉.
277 napply (H (byte8_destruct_1 … H1)).
280 nlemma decidable_b8_aux2 : ∀e1,e2,e3,e4.e2 ≠ e4 → 〈e1,e2〉 ≠ 〈e3,e4〉.
283 napply (H (byte8_destruct_2 … H1)).
286 nlemma decidable_b8 : ∀x,y:byte8.decidable (x = y).
287 #x; nelim x; #e1; #e2;
288 #y; nelim y; #e3; #e4;
290 napply (or2_elim (e1 = e3) (e1 ≠ e3) ? (decidable_ex e1 e3) …);
291 ##[ ##2: #H; napply (or2_intro2 … (decidable_b8_aux1 e1 e2 e3 e4 H))
292 ##| ##1: #H; napply (or2_elim (e2 = e4) (e2 ≠ e4) ? (decidable_ex e2 e4) …);
293 ##[ ##2: #H1; napply (or2_intro2 … (decidable_b8_aux2 e1 e2 e3 e4 H1))
294 ##| ##1: #H1; nrewrite > H; nrewrite > H1;
295 napply (or2_intro1 … (refl_eq ? 〈e3,e4〉))
300 nlemma neqb8_to_neq : ∀b1,b2:byte8.(eq_b8 b1 b2 = false) → (b1 ≠ b2).
305 nchange with ((((eq_ex e3 e1) ⊗ (eq_ex e4 e2)) = false) → ?);
307 napply (or2_elim ((eq_ex e3 e1) = false) ((eq_ex e4 e2) = false) ? (andb_false2 … H) …);
308 ##[ ##1: #H1; napply (decidable_b8_aux1 … (neqex_to_neq … H1))
309 ##| ##2: #H1; napply (decidable_b8_aux2 … (neqex_to_neq … H1))
313 nlemma byte8_destruct : ∀e1,e2,e3,e4.〈e1,e2〉 ≠ 〈e3,e4〉 → e1 ≠ e3 ∨ e2 ≠ e4.
316 napply (or2_elim (e1 = e3) (e1 ≠ e3) ? (decidable_ex e1 e3) …);
317 ##[ ##2: #H1; napply (or2_intro1 … H1)
318 ##| ##1: #H1; napply (or2_elim (e2 = e4) (e2 ≠ e4) ? (decidable_ex e2 e4) …);
319 ##[ ##2: #H2; napply (or2_intro2 … H2)
320 ##| ##1: #H2; nrewrite > H1 in H:(%);
322 #H; nelim (H (refl_eq …))
327 nlemma neq_to_neqb8 : ∀b1,b2.b1 ≠ b2 → eq_b8 b1 b2 = false.
331 #H; nchange with (((eq_ex e1 e3) ⊗ (eq_ex e2 e4)) = false);
332 napply (or2_elim (e1 ≠ e3) (e2 ≠ e4) ? (byte8_destruct … H) …);
333 ##[ ##1: #H1; nrewrite > (neq_to_neqex … H1); nnormalize; napply refl_eq
334 ##| ##2: #H1; nrewrite > (neq_to_neqex … H1);
335 nrewrite > (symmetric_andbool (eq_ex e1 e3) false);
336 nnormalize; napply refl_eq