]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/num/word16.ma
freescale porting, work in progress
[helm.git] / helm / software / matita / contribs / ng_assembly / num / word16.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
19 (*   Ultima modifica: 05/08/2009                                          *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "num/byte8.ma".
24
25 (* **** *)
26 (* WORD *)
27 (* **** *)
28
29 nrecord word16 : Type ≝
30  {
31  w16h: byte8;
32  w16l: byte8
33  }.
34
35 (* \langle \rangle *)
36 notation "〈x:y〉" non associative with precedence 80
37  for @{ 'mk_word16 $x $y }.
38 interpretation "mk_word16" 'mk_word16 x y = (mk_word16 x y).
39
40 (* operatore = *)
41 ndefinition eq_w16 ≝ λw1,w2.(eq_b8 (w16h w1) (w16h w2)) ⊗ (eq_b8 (w16l w1) (w16l w2)).
42
43 (* operatore < *)
44 ndefinition lt_w16 ≝
45 λw1,w2:word16.match lt_b8 (w16h w1) (w16h w2) with
46  [ true ⇒ true
47  | false ⇒ match gt_b8 (w16h w1) (w16h w2) with
48   [ true ⇒ false
49   | false ⇒ lt_b8 (w16l w1) (w16l w2) ]].
50
51 (* operatore ≤ *)
52 ndefinition le_w16 ≝ λw1,w2:word16.(eq_w16 w1 w2) ⊕ (lt_w16 w1 w2).
53
54 (* operatore > *)
55 ndefinition gt_w16 ≝ λw1,w2:word16.⊖ (le_w16 w1 w2).
56
57 (* operatore ≥ *)
58 ndefinition ge_w16 ≝ λw1,w2:word16.⊖ (lt_w16 w1 w2).
59
60 (* operatore and *)
61 ndefinition and_w16 ≝
62 λw1,w2:word16.mk_word16 (and_b8 (w16h w1) (w16h w2)) (and_b8 (w16l w1) (w16l w2)).
63
64 (* operatore or *)
65 ndefinition or_w16 ≝
66 λw1,w2:word16.mk_word16 (or_b8 (w16h w1) (w16h w2)) (or_b8 (w16l w1) (w16l w2)).
67
68 (* operatore xor *)
69 ndefinition xor_w16 ≝
70 λw1,w2:word16.mk_word16 (xor_b8 (w16h w1) (w16h w2)) (xor_b8 (w16l w1) (w16l w2)).
71
72 (* operatore rotazione destra con carry *)
73 ndefinition rcr_w16 ≝
74 λw:word16.λc:bool.match rcr_b8 (w16h w) c with
75  [ pair wh' c' ⇒ match rcr_b8 (w16l w) c' with
76   [ pair wl' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]]. 
77
78 (* operatore shift destro *)
79 ndefinition shr_w16 ≝
80 λw:word16.match rcr_b8 (w16h w) false with
81  [ pair wh' c' ⇒ match rcr_b8 (w16l w) c' with
82   [ pair wl' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]].
83
84 (* operatore rotazione destra *)
85 ndefinition ror_w16 ≝
86 λw:word16.match rcr_b8 (w16h w) false with
87  [ pair wh' c' ⇒ match rcr_b8 (w16l w) c' with
88   [ pair wl' c'' ⇒ match c'' with
89    [ true ⇒ mk_word16 (or_b8 (mk_byte8 x8 x0) wh') wl'
90    | false ⇒ mk_word16 wh' wl' ]]].
91
92 (* operatore rotazione destra n-volte *)
93 nlet rec ror_w16_n (w:word16) (n:nat) on n ≝
94  match n with
95   [ O ⇒ w
96   | S n' ⇒ ror_w16_n (ror_w16 w) n' ].
97
98 (* operatore rotazione sinistra con carry *)
99 ndefinition rcl_w16 ≝
100 λw:word16.λc:bool.match rcl_b8 (w16l w) c with
101  [ pair wl' c' ⇒ match rcl_b8 (w16h w) c' with
102   [ pair wh' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]]. 
103
104 (* operatore shift sinistro *)
105 ndefinition shl_w16 ≝
106 λw:word16.match rcl_b8 (w16l w) false with
107  [ pair wl' c' ⇒ match rcl_b8 (w16h w) c' with
108   [ pair wh' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]].
109
110 (* operatore rotazione sinistra *)
111 ndefinition rol_w16 ≝
112 λw:word16.match rcl_b8 (w16l w) false with
113  [ pair wl' c' ⇒ match rcl_b8 (w16h w) c' with
114   [ pair wh' c'' ⇒ match c'' with
115    [ true ⇒ mk_word16 wh' (or_b8 (mk_byte8 x0 x1) wl')
116    | false ⇒ mk_word16 wh' wl' ]]].
117
118 (* operatore rotazione sinistra n-volte *)
119 nlet rec rol_w16_n (w:word16) (n:nat) on n ≝
120  match n with
121   [ O ⇒ w
122   | S n' ⇒ rol_w16_n (rol_w16 w) n' ].
123
124 (* operatore not/complemento a 1 *)
125 ndefinition not_w16 ≝
126 λw:word16.mk_word16 (not_b8 (w16h w)) (not_b8 (w16l w)).
127
128 (* operatore somma con data+carry → data+carry *)
129 ndefinition plus_w16_dc_dc ≝
130 λw1,w2:word16.λc:bool.
131  match plus_b8_dc_dc (w16l w1) (w16l w2) c with
132   [ pair l c ⇒ match plus_b8_dc_dc (w16h w1) (w16h w2) c with
133    [ pair h c' ⇒ pair … 〈h:l〉 c' ]].
134
135 (* operatore somma con data+carry → data *)
136 ndefinition plus_w16_dc_d ≝
137 λw1,w2:word16.λc:bool.
138  match plus_b8_dc_dc (w16l w1) (w16l w2) c with
139   [ pair l c ⇒ 〈plus_b8_dc_d (w16h w1) (w16h w2) c:l〉 ].
140
141 (* operatore somma con data+carry → c *)
142 ndefinition plus_w16_dc_c ≝
143 λw1,w2:word16.λc:bool.
144  plus_b8_dc_c (w16h w1) (w16h w2) (plus_b8_dc_c (w16l w1) (w16l w2) c).
145
146 (* operatore somma con data → data+carry *)
147 ndefinition plus_w16_d_dc ≝
148 λw1,w2:word16.
149  match plus_b8_d_dc (w16l w1) (w16l w2) with
150   [ pair l c ⇒ match plus_b8_dc_dc (w16h w1) (w16h w2) c with
151    [ pair h c' ⇒ pair … 〈h:l〉 c' ]].
152
153 (* operatore somma con data → data *)
154 ndefinition plus_w16_d_d ≝
155 λw1,w2:word16.
156  match plus_b8_d_dc (w16l w1) (w16l w2) with
157   [ pair l c ⇒ 〈plus_b8_dc_d (w16h w1) (w16h w2) c:l〉 ].
158
159 (* operatore somma con data → c *)
160 ndefinition plus_w16_d_c ≝
161 λw1,w2:word16.
162  plus_b8_dc_c (w16h w1) (w16h w2) (plus_b8_d_c (w16l w1) (w16l w2)).
163
164 (* operatore Most Significant Bit *)
165 ndefinition MSB_w16 ≝ λw:word16.eq_ex x8 (and_ex x8 (b8h (w16h w))).
166
167 (* operatore predecessore *)
168 ndefinition pred_w16 ≝
169 λw:word16.match eq_b8 (w16l w) (mk_byte8 x0 x0) with
170  [ true ⇒ mk_word16 (pred_b8 (w16h w)) (pred_b8 (w16l w))
171  | false ⇒ mk_word16 (w16h w) (pred_b8 (w16l w)) ].
172
173 (* operatore successore *)
174 ndefinition succ_w16 ≝
175 λw:word16.match eq_b8 (w16l w) (mk_byte8 xF xF) with
176  [ true ⇒ mk_word16 (succ_b8 (w16h w)) (succ_b8 (w16l w))
177  | false ⇒ mk_word16 (w16h w) (succ_b8 (w16l w)) ].
178
179 (* operatore neg/complemento a 2 *)
180 ndefinition compl_w16 ≝
181 λw:word16.match MSB_w16 w with
182  [ true ⇒ succ_w16 (not_w16 w)
183  | false ⇒ not_w16 (pred_w16 w) ].
184
185 (* 
186    operatore moltiplicazione senza segno: b*b=[0x0000,0xFE01]
187    ... in pratica (〈a,b〉*〈c,d〉) = (a*c)<<8+(a*d)<<4+(b*c)<<4+(b*d)
188 *)
189 ndefinition mul_b8 ≝
190 λb1,b2:byte8.match b1 with
191 [ mk_byte8 b1h b1l ⇒ match b2 with
192 [ mk_byte8 b2h b2l ⇒ match mul_ex b1l b2l with
193 [ mk_byte8 t1_h t1_l ⇒ match mul_ex b1h b2l with
194 [ mk_byte8 t2_h t2_l ⇒ match mul_ex b2h b1l with
195 [ mk_byte8 t3_h t3_l ⇒ match mul_ex b1h b2h with
196 [ mk_byte8 t4_h t4_l ⇒
197  plus_w16_d_d
198   (plus_w16_d_d
199    (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〉〉
200 ]]]]]].
201
202 (* divisione senza segno (secondo la logica delle ALU): (quoziente resto) overflow *)
203 nlet rec div_b8_aux (divd:word16) (divs:word16) (molt:byte8) (q:byte8) (c:nat) on c ≝
204  let w' ≝ plus_w16_d_d divd (compl_w16 divs) in
205   match c with
206   [ O ⇒ match le_w16 divs divd with
207    [ true ⇒ triple … (or_b8 molt q) (w16l w') (⊖ (eq_b8 (w16h w') 〈x0,x0〉))
208    | false ⇒ triple … q (w16l divd) (⊖ (eq_b8 (w16h divd) 〈x0,x0〉)) ]
209   | S c' ⇒ match le_w16 divs divd with
210    [ true ⇒ div_b8_aux w' (ror_w16 divs) (ror_b8 molt) (or_b8 molt q) c'
211    | false ⇒ div_b8_aux divd (ror_w16 divs) (ror_b8 molt) q c' ]].
212
213 ndefinition div_b8 ≝
214 λw:word16.λb:byte8.match eq_b8 b 〈x0,x0〉 with
215 (* 
216    la combinazione n/0 e' illegale, segnala solo overflow senza dare risultato
217 *)
218  [ true ⇒ triple … 〈xF,xF〉 (w16l w) true
219  | false ⇒ match eq_w16 w 〈〈x0,x0〉:〈x0,x0〉〉 with
220 (* 0 diviso qualsiasi cosa diverso da 0 da' q=0 r=0 o=false *)
221   [ true ⇒ triple … 〈x0,x0〉 〈x0,x0〉 false
222 (* 1) e' una divisione sensata che produrra' overflow/risultato *)
223 (* 2) parametri: dividendo, divisore, moltiplicatore, quoziente, contatore *)
224 (* 3) ad ogni ciclo il divisore e il moltiplicatore vengono scalati di 1 a dx *)
225 (* 4) il moltiplicatore e' la quantita' aggiunta al quoziente se il divisore *)
226 (*    puo' essere sottratto al dividendo *) 
227   | false ⇒ div_b8_aux w (rol_w16_n 〈〈x0,x0〉:b〉 7) 〈x8,x0〉 〈x0,x0〉 7 ]].
228
229 (* operatore x in [inf,sup] *)
230 ndefinition inrange_w16 ≝
231 λx,inf,sup:word16.(le_w16 inf sup) ⊗ (ge_w16 x inf) ⊗ (le_w16 x sup).
232
233 (* iteratore sulle word *)
234 ndefinition forall_w16 ≝
235  λP.
236   forall_b8 (λbh.
237   forall_b8 (λbl.
238    P (mk_word16 bh bl ))).
239
240 (* word16 ricorsive *)
241 ninductive rec_word16 : word16 → Type ≝
242   w16_O : rec_word16 〈〈x0,x0〉:〈x0,x0〉〉
243 | w16_S : ∀n.rec_word16 n → rec_word16 (succ_w16 n).
244
245 (* word16 → word16 ricorsive *)
246 ndefinition w16_to_recw16_aux1_1 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x1,x0〉〉 ≝
247 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
248  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
249  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? recw
250  ))))))))))))))).
251
252 ndefinition w16_to_recw16_aux1_2 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x2,x0〉〉 ≝
253 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
254  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
255  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_1 ? recw)
256  ))))))))))))))).
257
258 ndefinition w16_to_recw16_aux1_3 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x3,x0〉〉 ≝
259 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
260  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
261  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_2 ? recw)
262  ))))))))))))))).
263
264 ndefinition w16_to_recw16_aux1_4 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x4,x0〉〉 ≝
265 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
266  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
267  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_3 ? recw)
268  ))))))))))))))).
269
270 ndefinition w16_to_recw16_aux1_5 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x5,x0〉〉 ≝
271 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
272  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
273  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_4 ? recw)
274  ))))))))))))))).
275
276 ndefinition w16_to_recw16_aux1_6 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x6,x0〉〉 ≝
277 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
278  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
279  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_5 ? recw)
280  ))))))))))))))).
281
282 ndefinition w16_to_recw16_aux1_7 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x7,x0〉〉 ≝
283 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
284  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
285  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_6 ? recw)
286  ))))))))))))))).
287
288 ndefinition w16_to_recw16_aux1_8 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x8,x0〉〉 ≝
289 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
290  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
291  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_7 ? recw)
292  ))))))))))))))).
293
294 ndefinition w16_to_recw16_aux1_9 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x9,x0〉〉 ≝
295 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
296  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
297  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_8 ? recw)
298  ))))))))))))))).
299
300 ndefinition w16_to_recw16_aux1_10 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xA,x0〉〉 ≝
301 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
302  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
303  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_9 ? recw)
304  ))))))))))))))).
305
306 ndefinition w16_to_recw16_aux1_11 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xB,x0〉〉 ≝
307 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
308  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
309  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_10 ? recw)
310  ))))))))))))))).
311
312 ndefinition w16_to_recw16_aux1_12 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xC,x0〉〉 ≝
313 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
314  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
315  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_11 ? recw)
316  ))))))))))))))).
317
318 ndefinition w16_to_recw16_aux1_13 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xD,x0〉〉 ≝
319 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
320  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
321  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_12 ? recw)
322  ))))))))))))))).
323
324 ndefinition w16_to_recw16_aux1_14 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xE,x0〉〉 ≝
325 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
326  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
327  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_13 ? recw)
328  ))))))))))))))).
329
330 ndefinition w16_to_recw16_aux1_15 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xF,x0〉〉 ≝
331 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
332  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
333  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_14 ? recw)
334  ))))))))))))))).
335
336 ndefinition w16_to_recw16_aux1 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈(succ_b8 n):〈x0,x0〉〉 ≝
337 λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
338  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
339  w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_to_recw16_aux1_15 ? recw)
340  ))))))))))))))).
341
342 (* ... cifra byte superiore *)
343 nlet rec w16_to_recw16_aux2 (n:byte8) (r:rec_byte8 n) on r ≝
344  match r return λx.λy:rec_byte8 x.rec_word16 〈x:〈x0,x0〉〉 with
345   [ b8_O ⇒ w16_O
346   | b8_S t n' ⇒ w16_to_recw16_aux1 ? (w16_to_recw16_aux2 t n')
347   ].
348
349 (* ... cifra esadecimale n.2 *)
350 ndefinition w16_to_recw16_aux3 ≝
351 λb,n.λrecw:rec_word16 〈b:〈x0,x0〉〉.
352  match n return λx.rec_word16 〈b:〈x,x0〉〉 with
353  [ x0 ⇒ recw
354  | x1 ⇒ w16_to_recw16_aux1_1 ? recw
355  | x2 ⇒ w16_to_recw16_aux1_2 ? recw
356  | x3 ⇒ w16_to_recw16_aux1_3 ? recw
357  | x4 ⇒ w16_to_recw16_aux1_4 ? recw
358  | x5 ⇒ w16_to_recw16_aux1_5 ? recw
359  | x6 ⇒ w16_to_recw16_aux1_6 ? recw
360  | x7 ⇒ w16_to_recw16_aux1_7 ? recw
361  | x8 ⇒ w16_to_recw16_aux1_8 ? recw
362  | x9 ⇒ w16_to_recw16_aux1_9 ? recw
363  | xA ⇒ w16_to_recw16_aux1_10 ? recw
364  | xB ⇒ w16_to_recw16_aux1_11 ? recw
365  | xC ⇒ w16_to_recw16_aux1_12 ? recw
366  | xD ⇒ w16_to_recw16_aux1_13 ? recw
367  | xE ⇒ w16_to_recw16_aux1_14 ? recw
368  | xF ⇒ w16_to_recw16_aux1_15 ? recw
369  ].
370
371 nlemma w16_to_recw16_aux4_1 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x1〉〉.
372  #n; #e;
373  (* non funziona nelim e *)
374   #H;
375  nelim e in H:(%) ⊢ %; 
376  #input; napply (w16_S ? input).
377 nqed.
378
379 nlemma w16_to_recw16_aux4_2 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x2〉〉.
380  #n; #e; #H;
381  nelim e in H:(%) ⊢ %; 
382  #input; napply (w16_S ? (w16_to_recw16_aux4_1 … input)).
383 nqed.
384
385 nlemma w16_to_recw16_aux4_3 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x3〉〉.
386  #n; #e; #H;
387  nelim e in H:(%) ⊢ %; 
388  #input; napply (w16_S ? (w16_to_recw16_aux4_2 … input)).
389 nqed.
390
391 nlemma w16_to_recw16_aux4_4 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x4〉〉.
392  #n; #e; #H;
393  nelim e in H:(%) ⊢ %;
394  #input; napply (w16_S ? (w16_to_recw16_aux4_3 … input)).
395 nqed.
396
397 nlemma w16_to_recw16_aux4_5 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x5〉〉.
398  #n; #e; #H;
399  nelim e in H:(%) ⊢ %; 
400  #input; napply (w16_S ? (w16_to_recw16_aux4_4 … input)).
401 nqed.
402
403 nlemma w16_to_recw16_aux4_6 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x6〉〉.
404  #n; #e; #H;
405  nelim e in H:(%) ⊢ %; 
406  #input; napply (w16_S ? (w16_to_recw16_aux4_5 … input)).
407 nqed.
408
409 nlemma w16_to_recw16_aux4_7 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x7〉〉.
410  #n; #e; #H;
411  nelim e in H:(%) ⊢ %; 
412  #input; napply (w16_S ? (w16_to_recw16_aux4_6 … input)).
413 nqed.
414
415 nlemma w16_to_recw16_aux4_8 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x8〉〉.
416  #n; #e; #H;
417  nelim e in H:(%) ⊢ %; 
418  #input; napply (w16_S ? (w16_to_recw16_aux4_7 … input)).
419 nqed.
420
421 nlemma w16_to_recw16_aux4_9 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x9〉〉.
422  #n; #e; #H;
423  nelim e in H:(%) ⊢ %; 
424  #input; napply (w16_S ? (w16_to_recw16_aux4_8 … input)).
425 nqed.
426
427 nlemma w16_to_recw16_aux4_10 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xA〉〉.
428  #n; #e; #H;
429  nelim e in H:(%) ⊢ %; 
430  #input; napply (w16_S ? (w16_to_recw16_aux4_9 … input)).
431 nqed.
432
433 nlemma w16_to_recw16_aux4_11 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xB〉〉.
434  #n; #e; #H;
435  nelim e in H:(%) ⊢ %; 
436  #input; napply (w16_S ? (w16_to_recw16_aux4_10 … input)).
437 nqed.
438
439 nlemma w16_to_recw16_aux4_12 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xC〉〉.
440  #n; #e; #H;
441  nelim e in H:(%) ⊢ %; 
442  #input; napply (w16_S ? (w16_to_recw16_aux4_11 … input)).
443 nqed.
444
445 nlemma w16_to_recw16_aux4_13 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xD〉〉.
446  #n; #e; #H;
447  nelim e in H:(%) ⊢ %; 
448  #input; napply (w16_S ? (w16_to_recw16_aux4_12 … input)).
449 nqed.
450
451 nlemma w16_to_recw16_aux4_14 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xE〉〉.
452  #n; #e; #H;
453  nelim e in H:(%) ⊢ %; 
454  #input; napply (w16_S ? (w16_to_recw16_aux4_13 … input)).
455 nqed.
456
457 nlemma w16_to_recw16_aux4_15 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xF〉〉.
458  #n; #e; #H;
459  nelim e in H:(%) ⊢ %; 
460  #input; napply (w16_S ? (w16_to_recw16_aux4_14 … input)).
461 nqed.
462
463 (* ... cifra esadecimale n.1 *)
464 ndefinition w16_to_recw16_aux4 ≝
465 λb,e,n.λrecw:rec_word16 〈b:〈e,x0〉〉.
466  match n return λx.rec_word16 〈b:〈e,x〉〉 with
467  [ x0 ⇒ recw
468  | x1 ⇒ w16_to_recw16_aux4_1 … recw
469  | x2 ⇒ w16_to_recw16_aux4_2 … recw
470  | x3 ⇒ w16_to_recw16_aux4_3 … recw
471  | x4 ⇒ w16_to_recw16_aux4_4 … recw
472  | x5 ⇒ w16_to_recw16_aux4_5 … recw
473  | x6 ⇒ w16_to_recw16_aux4_6 … recw
474  | x7 ⇒ w16_to_recw16_aux4_7 … recw
475  | x8 ⇒ w16_to_recw16_aux4_8 … recw
476  | x9 ⇒ w16_to_recw16_aux4_9 … recw
477  | xA ⇒ w16_to_recw16_aux4_10 … recw
478  | xB ⇒ w16_to_recw16_aux4_11 … recw
479  | xC ⇒ w16_to_recw16_aux4_12 … recw
480  | xD ⇒ w16_to_recw16_aux4_13 … recw
481  | xE ⇒ w16_to_recw16_aux4_14 … recw
482  | xF ⇒ w16_to_recw16_aux4_15 … recw
483  ].
484
485 ndefinition w16_to_recw16 : Πw.rec_word16 w.
486  #w;
487  nletin K ≝ (w16_to_recw16_aux4 (w16h w) (b8h (w16l w)) (b8l (w16l w))
488               (w16_to_recw16_aux3 (w16h w) (b8h (w16l w)) (w16_to_recw16_aux2 (w16h w) (b8_to_recb8 (w16h w)))));
489  nelim w in K:(%) ⊢ %;
490  #b1; #b2;
491  nelim b2;
492  #e1; #e2; nnormalize; #H; napply H.
493 nqed.