]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/num/word16.ma
fix to speedup reduction making intermediate conversion problems smaller
[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 〈n:〈x0,x7〉〉 (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 〈n:〈x1,x7〉〉 (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 〈n:〈x2,x7〉〉 (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 〈n:〈x3,x7〉〉 (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 〈n:〈x4,x7〉〉 (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 〈n:〈x5,x7〉〉 (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 〈n:〈x6,x7〉〉 (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 〈n:〈x7,x7〉〉 (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 〈n:〈x8,x7〉〉 (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 〈n:〈x9,x7〉〉 (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 〈n:〈xA,x7〉〉 (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 〈n:〈xB,x7〉〉 (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 〈n:〈xC,x7〉〉 (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 〈n:〈xD,x7〉〉 (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 〈n:〈xE,x7〉〉 (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 〈n:〈xF,x7〉〉 (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; nelim e;
373  #input; napply (w16_S ? input).
374 nqed.
375
376 nlemma w16_to_recw16_aux4_2 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x2〉〉.
377  #n; #e; #H;
378  nelim e in H:(%) ⊢ %; 
379  #input; napply (w16_S ? (w16_to_recw16_aux4_1 … input)).
380 nqed.
381
382 nlemma w16_to_recw16_aux4_3 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x3〉〉.
383  #n; #e; #H;
384  nelim e in H:(%) ⊢ %; 
385  #input; napply (w16_S ? (w16_to_recw16_aux4_2 … input)).
386 nqed.
387
388 nlemma w16_to_recw16_aux4_4 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x4〉〉.
389  #n; #e; #H;
390  nelim e in H:(%) ⊢ %;
391  #input; napply (w16_S ? (w16_to_recw16_aux4_3 … input)).
392 nqed.
393
394 nlemma w16_to_recw16_aux4_5 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x5〉〉.
395  #n; #e; #H;
396  nelim e in H:(%) ⊢ %; 
397  #input; napply (w16_S ? (w16_to_recw16_aux4_4 … input)).
398 nqed.
399
400 nlemma w16_to_recw16_aux4_6 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x6〉〉.
401  #n; #e; #H;
402  nelim e in H:(%) ⊢ %; 
403  #input; napply (w16_S ? (w16_to_recw16_aux4_5 … input)).
404 nqed.
405
406 nlemma w16_to_recw16_aux4_7 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x7〉〉.
407  #n; #e; #H;
408  nelim e in H:(%) ⊢ %; 
409  #input; napply (w16_S ? (w16_to_recw16_aux4_6 … input)).
410 nqed.
411
412 nlemma w16_to_recw16_aux4_8 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x8〉〉.
413  #n; #e; #H;
414  nelim e in H:(%) ⊢ %; 
415  #input; napply (w16_S ? (w16_to_recw16_aux4_7 … input)).
416 nqed.
417
418 nlemma w16_to_recw16_aux4_9 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x9〉〉.
419  #n; #e; #H;
420  nelim e in H:(%) ⊢ %; 
421  #input; napply (w16_S ? (w16_to_recw16_aux4_8 … input)).
422 nqed.
423
424 nlemma w16_to_recw16_aux4_10 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xA〉〉.
425  #n; #e; #H;
426  nelim e in H:(%) ⊢ %; 
427  #input; napply (w16_S ? (w16_to_recw16_aux4_9 … input)).
428 nqed.
429
430 nlemma w16_to_recw16_aux4_11 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xB〉〉.
431  #n; #e; #H;
432  nelim e in H:(%) ⊢ %; 
433  #input; napply (w16_S ? (w16_to_recw16_aux4_10 … input)).
434 nqed.
435
436 nlemma w16_to_recw16_aux4_12 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xC〉〉.
437  #n; #e; #H;
438  nelim e in H:(%) ⊢ %; 
439  #input; napply (w16_S ? (w16_to_recw16_aux4_11 … input)).
440 nqed.
441
442 nlemma w16_to_recw16_aux4_13 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xD〉〉.
443  #n; #e; #H;
444  nelim e in H:(%) ⊢ %; 
445  #input; napply (w16_S ? (w16_to_recw16_aux4_12 … input)).
446 nqed.
447
448 nlemma w16_to_recw16_aux4_14 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xE〉〉.
449  #n; #e; #H;
450  nelim e in H:(%) ⊢ %; 
451  #input; napply (w16_S ? (w16_to_recw16_aux4_13 … input)).
452 nqed.
453
454 nlemma w16_to_recw16_aux4_15 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xF〉〉.
455  #n; #e; #H;
456  nelim e in H:(%) ⊢ %; 
457  #input; napply (w16_S ? (w16_to_recw16_aux4_14 … input)).
458 nqed.
459
460 (* ... cifra esadecimale n.1 *)
461 ndefinition w16_to_recw16_aux4 ≝
462 λb,e,n.λrecw:rec_word16 〈b:〈e,x0〉〉.
463  match n return λx.rec_word16 〈b:〈e,x〉〉 with
464  [ x0 ⇒ recw
465  | x1 ⇒ w16_to_recw16_aux4_1 … recw
466  | x2 ⇒ w16_to_recw16_aux4_2 … recw
467  | x3 ⇒ w16_to_recw16_aux4_3 … recw
468  | x4 ⇒ w16_to_recw16_aux4_4 … recw
469  | x5 ⇒ w16_to_recw16_aux4_5 … recw
470  | x6 ⇒ w16_to_recw16_aux4_6 … recw
471  | x7 ⇒ w16_to_recw16_aux4_7 … recw
472  | x8 ⇒ w16_to_recw16_aux4_8 … recw
473  | x9 ⇒ w16_to_recw16_aux4_9 … recw
474  | xA ⇒ w16_to_recw16_aux4_10 … recw
475  | xB ⇒ w16_to_recw16_aux4_11 … recw
476  | xC ⇒ w16_to_recw16_aux4_12 … recw
477  | xD ⇒ w16_to_recw16_aux4_13 … recw
478  | xE ⇒ w16_to_recw16_aux4_14 … recw
479  | xF ⇒ w16_to_recw16_aux4_15 … recw
480  ].
481
482 ndefinition w16_to_recw16 : Πw.rec_word16 w.
483  #w;
484  nletin K ≝ (w16_to_recw16_aux4 (w16h w) (b8h (w16l w)) (b8l (w16l w))
485               (w16_to_recw16_aux3 (w16h w) (b8h (w16l w)) (w16_to_recw16_aux2 (w16h w) (b8_to_recb8 (w16h w)))));
486  nelim w in K:(%) ⊢ %;
487  #b1; #b2;
488  nelim b2;
489  #e1; #e2; nnormalize; #H; napply H.
490 nqed.