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 *)
19 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
21 (* Questo materiale fa parte della tesi: *)
22 (* "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale" *)
24 (* data ultima modifica 15/11/2007 *)
25 (* ********************************************************************** *)
27 include "freescale/exadecim.ma".
29 (* ******************** *)
30 (* DEFINIZIONE DEI BYTE *)
31 (* ******************** *)
40 notation "〈x,y〉" non associative with precedence 80
41 for @{ 'mk_byte8 $x $y }.
42 interpretation "mk_byte8" 'mk_byte8 x y =
43 (cic:/matita/freescale/byte8/byte8.ind#xpointer(1/1/1) x y).
46 definition eq_b8 ≝ λb1,b2:byte8.(eq_ex (b8h b1) (b8h b2)) ⊗ (eq_ex (b8l b1) (b8l b2)).
50 λb1,b2:byte8.match lt_ex (b8h b1) (b8h b2) with
52 | false ⇒ match gt_ex (b8h b1) (b8h b2) with
54 | false ⇒ lt_ex (b8l b1) (b8l b2) ]].
57 definition le_b8 ≝ λb1,b2:byte8.(eq_b8 b1 b2) ⊕ (lt_b8 b1 b2).
60 definition gt_b8 ≝ λb1,b2:byte8.⊖ (le_b8 b1 b2).
63 definition ge_b8 ≝ λb1,b2:byte8.⊖ (lt_b8 b1 b2).
67 λb1,b2:byte8.mk_byte8 (and_ex (b8h b1) (b8h b2)) (and_ex (b8l b1) (b8l b2)).
71 λb1,b2:byte8.mk_byte8 (or_ex (b8h b1) (b8h b2)) (or_ex (b8l b1) (b8l b2)).
75 λb1,b2:byte8.mk_byte8 (xor_ex (b8h b1) (b8h b2)) (xor_ex (b8l b1) (b8l b2)).
77 (* operatore rotazione destra con carry *)
79 λb:byte8.λc:bool.match rcr_ex (b8h b) c with
80 [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with
81 [ pair bl' c'' ⇒ pair ?? (mk_byte8 bh' bl') c'' ]].
83 (* operatore shift destro *)
85 λb:byte8.match rcr_ex (b8h b) false with
86 [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with
87 [ pair bl' c'' ⇒ pair ?? (mk_byte8 bh' bl') c'' ]].
89 (* operatore rotazione destra *)
91 λb:byte8.match rcr_ex (b8h b) false with
92 [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with
93 [ pair bl' c'' ⇒ match c'' with
94 [ true ⇒ mk_byte8 (or_ex x8 bh') bl'
95 | false ⇒ mk_byte8 bh' bl' ]]].
97 (* operatore rotazione destra n-volte *)
98 let rec ror_b8_n (b:byte8) (n:nat) on n ≝
101 | S n' ⇒ ror_b8_n (ror_b8 b) n' ].
103 (* operatore rotazione sinistra con carry *)
105 λb:byte8.λc:bool.match rcl_ex (b8l b) c with
106 [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with
107 [ pair bh' c'' ⇒ pair ?? (mk_byte8 bh' bl') c'' ]].
109 (* operatore shift sinistro *)
111 λb:byte8.match rcl_ex (b8l b) false with
112 [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with
113 [ pair bh' c'' ⇒ pair ?? (mk_byte8 bh' bl') c'' ]].
115 (* operatore rotazione sinistra *)
117 λb:byte8.match rcl_ex (b8l b) false with
118 [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with
119 [ pair bh' c'' ⇒ match c'' with
120 [ true ⇒ mk_byte8 bh' (or_ex x1 bl')
121 | false ⇒ mk_byte8 bh' bl' ]]].
123 (* operatore rotazione sinistra n-volte *)
124 let rec rol_b8_n (b:byte8) (n:nat) on n ≝
127 | S n' ⇒ rol_b8_n (rol_b8 b) n' ].
129 (* operatore not/complemento a 1 *)
131 λb:byte8.mk_byte8 (not_ex (b8h b)) (not_ex (b8l b)).
133 (* operatore somma con carry *)
135 λb1,b2:byte8.λc:bool.
136 match plus_ex (b8l b1) (b8l b2) c with
137 [ pair l c' ⇒ match plus_ex (b8h b1) (b8h b2) c' with
138 [ pair h c'' ⇒ pair ?? (mk_byte8 h l) c'' ]].
140 (* operatore somma senza carry *)
141 definition plus_b8nc ≝
142 λb1,b2:byte8.fst ?? (plus_b8 b1 b2 false).
144 (* operatore carry della somma *)
145 definition plus_b8c ≝
146 λb1,b2:byte8.snd ?? (plus_b8 b1 b2 false).
148 (* operatore Most Significant Bit *)
149 definition MSB_b8 ≝ λb:byte8.eq_ex x8 (and_ex x8 (b8h b)).
151 (* byte → naturali *)
152 definition nat_of_byte8 ≝ λb:byte8.16*(b8h b) + (b8l b).
154 coercion cic:/matita/freescale/byte8/nat_of_byte8.con.
156 (* naturali → byte *)
157 definition byte8_of_nat ≝ λn.mk_byte8 (exadecim_of_nat (n/16)) (exadecim_of_nat n).
159 (* operatore predecessore *)
161 λb:byte8.match eq_ex (b8l b) x0 with
162 [ true ⇒ mk_byte8 (pred_ex (b8h b)) (pred_ex (b8l b))
163 | false ⇒ mk_byte8 (b8h b) (pred_ex (b8l b)) ].
165 (* operatore successore *)
167 λb:byte8.match eq_ex (b8l b) xF with
168 [ true ⇒ mk_byte8 (succ_ex (b8h b)) (succ_ex (b8l b))
169 | false ⇒ mk_byte8 (b8h b) (succ_ex (b8l b)) ].
171 (* operatore neg/complemento a 2 *)
172 definition compl_b8 ≝
173 λb:byte8.match MSB_b8 b with
174 [ true ⇒ succ_b8 (not_b8 b)
175 | false ⇒ not_b8 (pred_b8 b) ].
177 (* operatore moltiplicazione senza segno: e*e=[0x00,0xE1] *)
179 λe1,e2:exadecim.match e1 with
181 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x0〉 | x2 ⇒ 〈x0,x0〉 | x3 ⇒ 〈x0,x0〉
182 | x4 ⇒ 〈x0,x0〉 | x5 ⇒ 〈x0,x0〉 | x6 ⇒ 〈x0,x0〉 | x7 ⇒ 〈x0,x0〉
183 | x8 ⇒ 〈x0,x0〉 | x9 ⇒ 〈x0,x0〉 | xA ⇒ 〈x0,x0〉 | xB ⇒ 〈x0,x0〉
184 | xC ⇒ 〈x0,x0〉 | xD ⇒ 〈x0,x0〉 | xE ⇒ 〈x0,x0〉 | xF ⇒ 〈x0,x0〉 ]
186 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x1〉 | x2 ⇒ 〈x0,x2〉 | x3 ⇒ 〈x0,x3〉
187 | x4 ⇒ 〈x0,x4〉 | x5 ⇒ 〈x0,x5〉 | x6 ⇒ 〈x0,x6〉 | x7 ⇒ 〈x0,x7〉
188 | x8 ⇒ 〈x0,x8〉 | x9 ⇒ 〈x0,x9〉 | xA ⇒ 〈x0,xA〉 | xB ⇒ 〈x0,xB〉
189 | xC ⇒ 〈x0,xC〉 | xD ⇒ 〈x0,xD〉 | xE ⇒ 〈x0,xE〉 | xF ⇒ 〈x0,xF〉 ]
191 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x2〉 | x2 ⇒ 〈x0,x4〉 | x3 ⇒ 〈x0,x6〉
192 | x4 ⇒ 〈x0,x8〉 | x5 ⇒ 〈x0,xA〉 | x6 ⇒ 〈x0,xC〉 | x7 ⇒ 〈x0,xE〉
193 | x8 ⇒ 〈x1,x0〉 | x9 ⇒ 〈x1,x2〉 | xA ⇒ 〈x1,x4〉 | xB ⇒ 〈x1,x6〉
194 | xC ⇒ 〈x1,x8〉 | xD ⇒ 〈x1,xA〉 | xE ⇒ 〈x1,xC〉 | xF ⇒ 〈x1,xE〉 ]
196 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x3〉 | x2 ⇒ 〈x0,x6〉 | x3 ⇒ 〈x0,x9〉
197 | x4 ⇒ 〈x0,xC〉 | x5 ⇒ 〈x0,xF〉 | x6 ⇒ 〈x1,x2〉 | x7 ⇒ 〈x1,x5〉
198 | x8 ⇒ 〈x1,x8〉 | x9 ⇒ 〈x1,xB〉 | xA ⇒ 〈x1,xE〉 | xB ⇒ 〈x2,x1〉
199 | xC ⇒ 〈x2,x4〉 | xD ⇒ 〈x2,x7〉 | xE ⇒ 〈x2,xA〉 | xF ⇒ 〈x2,xD〉 ]
201 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x4〉 | x2 ⇒ 〈x0,x8〉 | x3 ⇒ 〈x0,xC〉
202 | x4 ⇒ 〈x1,x0〉 | x5 ⇒ 〈x1,x4〉 | x6 ⇒ 〈x1,x8〉 | x7 ⇒ 〈x1,xC〉
203 | x8 ⇒ 〈x2,x0〉 | x9 ⇒ 〈x2,x4〉 | xA ⇒ 〈x2,x8〉 | xB ⇒ 〈x2,xC〉
204 | xC ⇒ 〈x3,x0〉 | xD ⇒ 〈x3,x4〉 | xE ⇒ 〈x3,x8〉 | xF ⇒ 〈x3,xC〉 ]
206 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x5〉 | x2 ⇒ 〈x0,xA〉 | x3 ⇒ 〈x0,xF〉
207 | x4 ⇒ 〈x1,x4〉 | x5 ⇒ 〈x1,x9〉 | x6 ⇒ 〈x1,xE〉 | x7 ⇒ 〈x2,x3〉
208 | x8 ⇒ 〈x2,x8〉 | x9 ⇒ 〈x2,xD〉 | xA ⇒ 〈x3,x2〉 | xB ⇒ 〈x3,x7〉
209 | xC ⇒ 〈x3,xC〉 | xD ⇒ 〈x4,x1〉 | xE ⇒ 〈x4,x6〉 | xF ⇒ 〈x4,xB〉 ]
211 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x6〉 | x2 ⇒ 〈x0,xC〉 | x3 ⇒ 〈x1,x2〉
212 | x4 ⇒ 〈x1,x8〉 | x5 ⇒ 〈x1,xE〉 | x6 ⇒ 〈x2,x4〉 | x7 ⇒ 〈x2,xA〉
213 | x8 ⇒ 〈x3,x0〉 | x9 ⇒ 〈x3,x6〉 | xA ⇒ 〈x3,xC〉 | xB ⇒ 〈x4,x2〉
214 | xC ⇒ 〈x4,x8〉 | xD ⇒ 〈x4,xE〉 | xE ⇒ 〈x5,x4〉 | xF ⇒ 〈x5,xA〉 ]
216 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x7〉 | x2 ⇒ 〈x0,xE〉 | x3 ⇒ 〈x1,x5〉
217 | x4 ⇒ 〈x1,xC〉 | x5 ⇒ 〈x2,x3〉 | x6 ⇒ 〈x2,xA〉 | x7 ⇒ 〈x3,x1〉
218 | x8 ⇒ 〈x3,x8〉 | x9 ⇒ 〈x3,xF〉 | xA ⇒ 〈x4,x6〉 | xB ⇒ 〈x4,xD〉
219 | xC ⇒ 〈x5,x4〉 | xD ⇒ 〈x5,xB〉 | xE ⇒ 〈x6,x2〉 | xF ⇒ 〈x6,x9〉 ]
221 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x8〉 | x2 ⇒ 〈x1,x0〉 | x3 ⇒ 〈x1,x8〉
222 | x4 ⇒ 〈x2,x0〉 | x5 ⇒ 〈x2,x8〉 | x6 ⇒ 〈x3,x0〉 | x7 ⇒ 〈x3,x8〉
223 | x8 ⇒ 〈x4,x0〉 | x9 ⇒ 〈x4,x8〉 | xA ⇒ 〈x5,x0〉 | xB ⇒ 〈x5,x8〉
224 | xC ⇒ 〈x6,x0〉 | xD ⇒ 〈x6,x8〉 | xE ⇒ 〈x7,x0〉 | xF ⇒ 〈x7,x8〉 ]
226 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x9〉 | x2 ⇒ 〈x1,x2〉 | x3 ⇒ 〈x1,xB〉
227 | x4 ⇒ 〈x2,x4〉 | x5 ⇒ 〈x2,xD〉 | x6 ⇒ 〈x3,x6〉 | x7 ⇒ 〈x3,xF〉
228 | x8 ⇒ 〈x4,x8〉 | x9 ⇒ 〈x5,x1〉 | xA ⇒ 〈x5,xA〉 | xB ⇒ 〈x6,x3〉
229 | xC ⇒ 〈x6,xC〉 | xD ⇒ 〈x7,x5〉 | xE ⇒ 〈x7,xE〉 | xF ⇒ 〈x8,x7〉 ]
231 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,xA〉 | x2 ⇒ 〈x1,x4〉 | x3 ⇒ 〈x1,xE〉
232 | x4 ⇒ 〈x2,x8〉 | x5 ⇒ 〈x3,x2〉 | x6 ⇒ 〈x3,xC〉 | x7 ⇒ 〈x4,x6〉
233 | x8 ⇒ 〈x5,x0〉 | x9 ⇒ 〈x5,xA〉 | xA ⇒ 〈x6,x4〉 | xB ⇒ 〈x6,xE〉
234 | xC ⇒ 〈x7,x8〉 | xD ⇒ 〈x8,x2〉 | xE ⇒ 〈x8,xC〉 | xF ⇒ 〈x9,x6〉 ]
236 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,xB〉 | x2 ⇒ 〈x1,x6〉 | x3 ⇒ 〈x2,x1〉
237 | x4 ⇒ 〈x2,xC〉 | x5 ⇒ 〈x3,x7〉 | x6 ⇒ 〈x4,x2〉 | x7 ⇒ 〈x4,xD〉
238 | x8 ⇒ 〈x5,x8〉 | x9 ⇒ 〈x6,x3〉 | xA ⇒ 〈x6,xE〉 | xB ⇒ 〈x7,x9〉
239 | xC ⇒ 〈x8,x4〉 | xD ⇒ 〈x8,xF〉 | xE ⇒ 〈x9,xA〉 | xF ⇒ 〈xA,x5〉 ]
241 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,xC〉 | x2 ⇒ 〈x1,x8〉 | x3 ⇒ 〈x2,x4〉
242 | x4 ⇒ 〈x3,x0〉 | x5 ⇒ 〈x3,xC〉 | x6 ⇒ 〈x4,x8〉 | x7 ⇒ 〈x5,x4〉
243 | x8 ⇒ 〈x6,x0〉 | x9 ⇒ 〈x6,xC〉 | xA ⇒ 〈x7,x8〉 | xB ⇒ 〈x8,x4〉
244 | xC ⇒ 〈x9,x0〉 | xD ⇒ 〈x9,xC〉 | xE ⇒ 〈xA,x8〉 | xF ⇒ 〈xB,x4〉 ]
246 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,xD〉 | x2 ⇒ 〈x1,xA〉 | x3 ⇒ 〈x2,x7〉
247 | x4 ⇒ 〈x3,x4〉 | x5 ⇒ 〈x4,x1〉 | x6 ⇒ 〈x4,xE〉 | x7 ⇒ 〈x5,xB〉
248 | x8 ⇒ 〈x6,x8〉 | x9 ⇒ 〈x7,x5〉 | xA ⇒ 〈x8,x2〉 | xB ⇒ 〈x8,xF〉
249 | xC ⇒ 〈x9,xC〉 | xD ⇒ 〈xA,x9〉 | xE ⇒ 〈xB,x6〉 | xF ⇒ 〈xC,x3〉 ]
251 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,xE〉 | x2 ⇒ 〈x1,xC〉 | x3 ⇒ 〈x2,xA〉
252 | x4 ⇒ 〈x3,x8〉 | x5 ⇒ 〈x4,x6〉 | x6 ⇒ 〈x5,x4〉 | x7 ⇒ 〈x6,x2〉
253 | x8 ⇒ 〈x7,x0〉 | x9 ⇒ 〈x7,xE〉 | xA ⇒ 〈x8,xC〉 | xB ⇒ 〈x9,xA〉
254 | xC ⇒ 〈xA,x8〉 | xD ⇒ 〈xB,x6〉 | xE ⇒ 〈xC,x4〉 | xF ⇒ 〈xD,x2〉 ]
256 [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,xF〉 | x2 ⇒ 〈x1,xE〉 | x3 ⇒ 〈x2,xD〉
257 | x4 ⇒ 〈x3,xC〉 | x5 ⇒ 〈x4,xB〉 | x6 ⇒ 〈x5,xA〉 | x7 ⇒ 〈x6,x9〉
258 | x8 ⇒ 〈x7,x8〉 | x9 ⇒ 〈x8,x7〉 | xA ⇒ 〈x9,x6〉 | xB ⇒ 〈xA,x5〉
259 | xC ⇒ 〈xB,x4〉 | xD ⇒ 〈xC,x3〉 | xE ⇒ 〈xD,x2〉 | xF ⇒ 〈xE,x1〉 ]
262 (* correzione per somma su BCD *)
263 (* input: halfcarry,carry,X(BCD+BCD) *)
264 (* output: X',carry' *)
267 match lt_b8 X 〈x9,xA〉 with
270 (* X' = [(b16l X):0x0-0x9] X + [h=1 ? 0x06 : 0x00] + [c=1 ? 0x60 : 0x00]
271 [(b16l X):0xA-0xF] X + 0x06 + [c=1 ? 0x60 : 0x00] *)
273 let X' ≝ match (lt_ex (b8l X) xA) ⊗ (⊖h) with
275 | false ⇒ plus_b8nc X 〈x0,x6〉 ] in
276 let X'' ≝ match c with
277 [ true ⇒ plus_b8nc X' 〈x6,x0〉
282 (* X' = [X:0x9A-0xFF]
283 [(b16l X):0x0-0x9] X + [h=1 ? 0x06 : 0x00] + 0x60
284 [(b16l X):0xA-0xF] X + 0x6 + 0x60 *)
286 let X' ≝ match (lt_ex (b8l X) xA) ⊗ (⊖h) with
288 | false ⇒ plus_b8nc X 〈x0,x6〉 ] in
289 let X'' ≝ plus_b8nc X' 〈x6,x0〉 in
293 (* iteratore sui byte *)
294 definition forall_byte8 ≝
296 forall_exadecim (λbh.
297 forall_exadecim (λbl.
298 P (mk_byte8 bh bl))).
300 (* ********************** *)
301 (* TEOREMI/LEMMMI/ASSIOMI *)
302 (* ********************** *)
304 lemma byte8_of_nat_nat_of_byte8: ∀b. byte8_of_nat (nat_of_byte8 b) = b.
312 lemma lt_nat_of_byte8_256: ∀b. nat_of_byte8 b < 256.
315 letin H ≝ (lt_nat_of_exadecim_16 (b8h b)); clearbody H;
316 letin K ≝ (lt_nat_of_exadecim_16 (b8l b)); clearbody K;
317 unfold lt in H K ⊢ %;
318 letin H' ≝ (le_S_S_to_le ? ? H); clearbody H'; clear H;
319 letin K' ≝ (le_S_S_to_le ? ? K); clearbody K'; clear K;
321 cut (16*b8h b ≤ 16*15);
322 [ letin Hf ≝ (le_plus ? ? ? ? Hcut K'); clearbody Hf;
323 simplify in Hf:(? ? %);
325 | apply le_times_r. apply H'.
329 lemma nat_of_byte8_byte8_of_nat: ∀n. nat_of_byte8 (byte8_of_nat n) = n \mod 256.
331 letin H ≝ (lt_nat_of_byte8_256 (byte8_of_nat n)); clearbody H;
332 rewrite < (lt_to_eq_mod ? ? H); clear H;
335 change with ((16*(exadecim_of_nat (n/16)) + exadecim_of_nat n) \mod 256 = n \mod 256);
336 letin H ≝ (div_mod n 16 ?); clearbody H; [ autobatch | ];
337 rewrite > symmetric_times in H;
338 rewrite > nat_of_exadecim_exadecim_of_nat in ⊢ (? ? (? (? % ?) ?) ?);
339 rewrite > nat_of_exadecim_exadecim_of_nat in ⊢ (? ? (? (? ? %) ?) ?);
340 rewrite > H in ⊢ (? ? ? (? % ?)); clear H;
341 rewrite > mod_plus in ⊢ (? ? % ?);
342 rewrite > mod_plus in ⊢ (? ? ? %);
343 apply eq_mod_to_eq_plus_mod;
344 rewrite < mod_mod in ⊢ (? ? ? %); [ | autobatch];
345 rewrite < mod_mod in ⊢ (? ? % ?); [ | autobatch];
346 rewrite < (eq_mod_times_times_mod ? ? 16 256) in ⊢ (? ? (? % ?) ?); [2: reflexivity | ];
347 rewrite < mod_mod in ⊢ (? ? % ?);
353 lemma eq_nat_of_byte8_n_nat_of_byte8_mod_n_256:
354 ∀n. byte8_of_nat n = byte8_of_nat (n \mod 256).
358 [ rewrite > exadecim_of_nat_mod in ⊢ (? ? % ?);
359 rewrite > exadecim_of_nat_mod in ⊢ (? ? ? %);
362 | rewrite > exadecim_of_nat_mod;
363 rewrite > exadecim_of_nat_mod in ⊢ (? ? ? %);
364 rewrite > divides_to_eq_mod_mod_mod;
366 | apply (witness ? ? 16). reflexivity.
373 match plus_b8 b1 b2 c with
374 [ pair r c' ⇒ b1 + b2 + nat_of_bool c = nat_of_byte8 r + nat_of_bool c' * 256
380 ∀b. plus_b8 (mk_byte8 x0 x0) b false = pair ?? b false.
389 ∀x. plus_b8nc (mk_byte8 x0 x0) x = x.
392 rewrite > plusb8_O_x;
396 lemma eq_nat_of_byte8_mod: ∀b. nat_of_byte8 b = nat_of_byte8 b \mod 256.
398 lapply (lt_nat_of_byte8_256 b);
399 rewrite > (lt_to_eq_mod ? ? Hletin) in ⊢ (? ? ? %);
404 ∀b1,b2:byte8.nat_of_byte8 (plus_b8nc b1 b2) = (b1 + b2) \mod 256.
407 generalize in match (plusb8_ok b1 b2 false);
408 elim (plus_b8 b1 b2 false);
410 change with (nat_of_byte8 t = (b1 + b2) \mod 256);
411 rewrite < plus_n_O in H;
412 rewrite > H; clear H;
414 letin K ≝ (eq_nat_of_byte8_mod t); clearbody K;
415 letin K' ≝ (eq_mod_times_n_m_m_O (nat_of_bool t1) 256 ?); clearbody K';
417 autobatch paramodulation.
420 lemma eq_eqb8_x0_x0_byte8_of_nat_S_false:
421 ∀b. b < 255 → eq_b8 (mk_byte8 x0 x0) (byte8_of_nat (S b)) = false.
424 cut (b < 15 ∨ b ≥ 15);
427 change in ⊢ (? ? (? ? %) ?) with (eq_ex x0 (exadecim_of_nat (S b)));
428 rewrite > eq_eqex_S_x0_false;
429 [ elim (eq_ex (b8h (mk_byte8 x0 x0))
430 (b8h (mk_byte8 (exadecim_of_nat (S b/16)) (exadecim_of_nat (S b)))));
436 change in ⊢ (? ? (? % ?) ?) with (eq_ex x0 (exadecim_of_nat (S b/16)));
437 letin K ≝ (leq_m_n_to_eq_div_n_m_S (S b) 16 ? ?);
445 rewrite > eq_eqex_S_x0_false;
450 clear H2; clear a; clear H1; clear Hcut;
451 apply (le_times_to_le 16) [ autobatch | ] ;
452 rewrite > (div_mod (S b) 16) in H;[2:autobatch|]
453 rewrite > (div_mod 255 16) in H:(? ? %);[2:autobatch|]
454 lapply (le_to_le_plus_to_le ? ? ? ? ? H);
456 apply lt_mod_m_m;autobatch
457 |rewrite > sym_times;
458 rewrite > sym_times in ⊢ (? ? %);
459 normalize in ⊢ (? ? %);apply Hletin;
464 | elim (or_lt_le b 15);unfold ge;autobatch
468 axiom eq_mod_O_to_exists: ∀n,m. n \mod m = 0 → ∃z. n = z*m.
470 lemma eq_b8pred_S_a_a:
471 ∀a. a < 255 → pred_b8 (byte8_of_nat (S a)) = byte8_of_nat a.
474 apply (bool_elim ? (eq_ex (b8l (byte8_of_nat (S a))) x0)); intros;
475 [ change with (mk_byte8 (pred_ex (b8h (byte8_of_nat (S a)))) (pred_ex (b8l (byte8_of_nat (S a))))
477 rewrite > (eqex_true_to_eq ? ? H1);
478 normalize in ⊢ (? ? (? ? %) ?);
480 change with (mk_byte8 (pred_ex (exadecim_of_nat (S a/16))) xF =
481 mk_byte8 (exadecim_of_nat (a/16)) (exadecim_of_nat a));
482 lapply (eqex_true_to_eq ? ? H1); clear H1;
483 unfold byte8_of_nat in Hletin;
484 change in Hletin with (exadecim_of_nat (S a) = x0);
485 lapply (eq_f ? ? nat_of_exadecim ? ? Hletin); clear Hletin;
486 normalize in Hletin1:(? ? ? %);
487 rewrite > nat_of_exadecim_exadecim_of_nat in Hletin1;
488 elim (eq_mod_O_to_exists ? ? Hletin1); clear Hletin1;
490 rewrite > lt_O_to_div_times; [2: autobatch | ]
491 lapply (eq_f ? ? (λx.x/16) ? ? H1);
492 rewrite > lt_O_to_div_times in Hletin; [2: autobatch | ]
493 lapply (eq_f ? ? (λx.x \mod 16) ? ? H1);
494 rewrite > eq_mod_times_n_m_m_O in Hletin1;
496 | change with (mk_byte8 (b8h (byte8_of_nat (S a))) (pred_ex (b8l (byte8_of_nat (S a))))
499 change with (mk_byte8 (exadecim_of_nat (S a/16)) (pred_ex (exadecim_of_nat (S a)))
500 = mk_byte8 (exadecim_of_nat (a/16)) (exadecim_of_nat a));
501 lapply (eqex_false_to_not_eq ? ? H1);
502 unfold byte8_of_nat in Hletin;
503 change in Hletin with (exadecim_of_nat (S a) ≠ x0);
504 cut (nat_of_exadecim (exadecim_of_nat (S a)) ≠ 0);
507 lapply (eq_f ? ? exadecim_of_nat ? ? H2);
508 rewrite > exadecim_of_nat_nat_of_exadecim in Hletin1;
516 ∀x:byte8.∀n.plus_b8nc (byte8_of_nat (x*n)) x = byte8_of_nat (x * S n).
518 rewrite < byte8_of_nat_nat_of_byte8;
519 rewrite > (plusb8nc_ok (byte8_of_nat (x*n)) x);
520 rewrite < times_n_Sm;
521 rewrite > nat_of_byte8_byte8_of_nat in ⊢ (? ? (? (? (? % ?) ?)) ?);
522 rewrite > eq_nat_of_byte8_n_nat_of_byte8_mod_n_256 in ⊢ (? ? ? %);
523 rewrite > mod_plus in ⊢ (? ? (? %) ?);
524 rewrite > mod_plus in ⊢ (? ? ? (? %));
525 rewrite < mod_mod in ⊢ (? ? (? (? (? % ?) ?)) ?); [2: autobatch | ];
526 rewrite > sym_plus in ⊢ (? ? (? (? % ?)) ?);
530 lemma eq_plusb8c_x0_x0_x_false:
531 ∀x.plus_b8c (mk_byte8 x0 x0) x = false.
539 axiom eqb8_true_to_eq: ∀b,b'. eq_b8 b b' = true → b=b'.
541 axiom eqb8_false_to_not_eq: ∀b,b'. eq_b8 b b' = false → b ≠ b'.
543 axiom byte8_of_nat_mod: ∀n.byte8_of_nat n = byte8_of_nat (n \mod 256).
548 ∀e1,e2.nat_of_byte8 (mul_ex e1 e2) = (nat_of_exadecim e1) * (nat_of_exadecim e2).