]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/matita/contribs/ng_assembly/num/byte8.ma
mod change (-x)
[helm.git] / helm / software / matita / contribs / ng_assembly / num / byte8.ma
old mode 100755 (executable)
new mode 100644 (file)
index bc7e6f9..d3d6edd
 (*                          Progetto FreeScale                            *)
 (*                                                                        *)
 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
-(*   Ultima modifica: 05/08/2009                                          *)
+(*   Sviluppo: 2008-2010                                                  *)
 (*                                                                        *)
 (* ********************************************************************** *)
 
 include "num/exadecim.ma".
+include "num/comp_num.ma".
 include "num/bitrigesim.ma".
+include "common/nat.ma".
 
 (* **** *)
 (* BYTE *)
 (* **** *)
 
-nrecord byte8 : Type ≝
- {
- b8h: exadecim;
- b8l: exadecim
- }.
+ndefinition byte8 ≝ comp_num exadecim.
+ndefinition mk_byte8 ≝ λe1,e2.mk_comp_num exadecim e1 e2.
 
 (* \langle \rangle *)
 notation "〈x,y〉" non associative with precedence 80
- for @{ 'mk_byte8 $x $y }.
-interpretation "mk_byte8" 'mk_byte8 x y = (mk_byte8 x y).
+ for @{ mk_comp_num exadecim $x $y }.
+
+(* iteratore sui byte *)
+ndefinition forall_b8 ≝ forall_cn ? forall_ex.
 
 (* operatore = *)
-ndefinition eq_b8 ≝ λb1,b2:byte8.(eq_ex (b8h b1) (b8h b2)) ⊗ (eq_ex (b8l b1) (b8l b2)).
+ndefinition eq_b8 ≝ eq2_cn ? eq_ex.
 
 (* operatore < *)
-ndefinition lt_b8 ≝
-λb1,b2:byte8.match lt_ex (b8h b1) (b8h b2) with
- [ true ⇒ true
- | false ⇒ match gt_ex (b8h b1) (b8h b2) with
-  [ true ⇒ false
-  | false ⇒ lt_ex (b8l b1) (b8l b2) ]].
+ndefinition lt_b8 ≝ ltgt_cn ? eq_ex lt_ex.
 
 (* operatore ≤ *)
-ndefinition le_b8 ≝ λb1,b2:byte8.(eq_b8 b1 b2) ⊕ (lt_b8 b1 b2). 
+ndefinition le_b8 ≝ lege_cn ? eq_ex lt_ex le_ex.
 
 (* operatore > *)
-ndefinition gt_b8 ≝ λb1,b2:byte8.⊖ (le_b8 b1 b2).
+ndefinition gt_b8 ≝ ltgt_cn ? eq_ex gt_ex.
 
 (* operatore ≥ *)
-ndefinition ge_b8 ≝ λb1,b2:byte8.⊖ (lt_b8 b1 b2).
+ndefinition ge_b8 ≝ lege_cn ? eq_ex gt_ex ge_ex.
 
 (* operatore and *)
-ndefinition and_b8 ≝
-λb1,b2:byte8.mk_byte8 (and_ex (b8h b1) (b8h b2)) (and_ex (b8l b1) (b8l b2)).
+ndefinition and_b8 ≝ fop2_cn ? and_ex.
 
 (* operatore or *)
-ndefinition or_b8 ≝
-λb1,b2:byte8.mk_byte8 (or_ex (b8h b1) (b8h b2)) (or_ex (b8l b1) (b8l b2)).
+ndefinition or_b8 ≝ fop2_cn ? or_ex.
 
 (* operatore xor *)
-ndefinition xor_b8 ≝
-λb1,b2:byte8.mk_byte8 (xor_ex (b8h b1) (b8h b2)) (xor_ex (b8l b1) (b8l b2)).
+ndefinition xor_b8 ≝ fop2_cn ? xor_ex.
+
+(* operatore Most Significant Bit *)
+ndefinition getMSB_b8 ≝ getOPH_cn ? getMSB_ex.
+ndefinition setMSB_b8 ≝ setOPH_cn ? setMSB_ex.
+ndefinition clrMSB_b8 ≝ setOPH_cn ? clrMSB_ex.
+
+(* operatore Least Significant Bit *)
+ndefinition getLSB_b8 ≝ getOPL_cn ? getLSB_ex.
+ndefinition setLSB_b8 ≝ setOPL_cn ? setLSB_ex.
+ndefinition clrLSB_b8 ≝ setOPL_cn ? clrLSB_ex.
+
+(* operatore estensione unsigned *)
+ndefinition extu_b8 ≝ λe2.〈x0,e2〉.
+
+(* operatore estensione signed *)
+ndefinition exts_b8 ≝
+λe2.〈(match getMSB_ex e2 with 
+      [ true ⇒ xF | false ⇒ x0 ]),e2〉.
 
 (* operatore rotazione destra con carry *)
-ndefinition rcr_b8 ≝
-λb:byte8.λc:bool.match rcr_ex (b8h b) c with
- [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with
-  [ pair bl' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]]. 
+ndefinition rcr_b8 ≝ opcr_cn ? rcr_ex.
 
 (* operatore shift destro *)
-ndefinition shr_b8 ≝
-λb:byte8.match rcr_ex (b8h b) false with
- [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with
-  [ pair bl' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]].
+ndefinition shr_b8 ≝ opcr_cn ? rcr_ex false.
 
 (* operatore rotazione destra *)
 ndefinition ror_b8 ≝
-λb:byte8.match rcr_ex (b8h b) false with
- [ pair bh' c' ⇒ match rcr_ex (b8l b) c' with
-  [ pair bl' c'' ⇒ match c'' with
-   [ true ⇒ mk_byte8 (or_ex x8 bh') bl'
-   | false ⇒ mk_byte8 bh' bl' ]]].
-
-(* operatore rotazione destra n-volte *)
-nlet rec ror_b8_n (b:byte8) (n:nat) on n ≝
- match n with
-  [ O ⇒ b
-  | S n' ⇒ ror_b8_n (ror_b8 b) n' ].
+λb.match shr_b8 b with
+ [ pair c b' ⇒ match c with
+  [ true ⇒ setMSB_b8 b' | false ⇒ b' ]].
 
 (* operatore rotazione sinistra con carry *)
-ndefinition rcl_b8 ≝
-λb:byte8.λc:bool.match rcl_ex (b8l b) c with
- [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with
-  [ pair bh' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]]. 
+ndefinition rcl_b8 ≝ opcl_cn ? rcl_ex.
 
 (* operatore shift sinistro *)
-ndefinition shl_b8 ≝
-λb:byte8.match rcl_ex (b8l b) false with
- [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with
-  [ pair bh' c'' ⇒ pair … (mk_byte8 bh' bl') c'' ]].
+ndefinition shl_b8 ≝ opcl_cn ? rcl_ex false.
 
 (* operatore rotazione sinistra *)
 ndefinition rol_b8 ≝
-λb:byte8.match rcl_ex (b8l b) false with
- [ pair bl' c' ⇒ match rcl_ex (b8h b) c' with
-  [ pair bh' c'' ⇒ match c'' with
-   [ true ⇒ mk_byte8 bh' (or_ex x1 bl')
-   | false ⇒ mk_byte8 bh' bl' ]]].
-
-(* operatore rotazione sinistra n-volte *)
-nlet rec rol_b8_n (b:byte8) (n:nat) on n ≝
- match n with
-  [ O ⇒ b
-  | S n' ⇒ rol_b8_n (rol_b8 b) n' ].
+λb.match shl_b8 b with
+ [ pair c b' ⇒ match c with
+  [ true ⇒ setLSB_b8 b' | false ⇒ b' ]].
 
 (* operatore not/complemento a 1 *)
-ndefinition not_b8 ≝
-λb:byte8.mk_byte8 (not_ex (b8h b)) (not_ex (b8l b)).
+ndefinition not_b8 ≝ fop_cn ? not_ex.
 
 (* operatore somma con data+carry → data+carry *)
-ndefinition plus_b8_dc_dc ≝
-λb1,b2:byte8.λc:bool.
- match plus_ex_dc_dc (b8l b1) (b8l b2) c with
-  [ pair l c ⇒ match plus_ex_dc_dc (b8h b1) (b8h b2) c with
-   [ pair h c' ⇒ pair … 〈h,l〉 c' ]].
+ndefinition plus_b8_dc_dc ≝ opcl2_cn ? plus_ex_dc_dc.
 
 (* operatore somma con data+carry → data *)
-ndefinition plus_b8_dc_d ≝
-λb1,b2:byte8.λc:bool.
- match plus_ex_dc_dc (b8l b1) (b8l b2) c with
-  [ pair l c ⇒ 〈plus_ex_dc_d (b8h b1) (b8h b2) c,l〉 ].
+ndefinition plus_b8_dc_d ≝ λc,b1,b2.snd … (plus_b8_dc_dc c b1 b2).
 
 (* operatore somma con data+carry → c *)
-ndefinition plus_b8_dc_c ≝
-λb1,b2:byte8.λc:bool.
- plus_ex_dc_c (b8h b1) (b8h b2) (plus_ex_dc_c (b8l b1) (b8l b2) c).
+ndefinition plus_b8_dc_c ≝ λc,b1,b2.fst … (plus_b8_dc_dc c b1 b2).
 
 (* operatore somma con data → data+carry *)
-ndefinition plus_b8_d_dc ≝
-λb1,b2:byte8.
- match plus_ex_d_dc (b8l b1) (b8l b2) with
-  [ pair l c ⇒ match plus_ex_dc_dc (b8h b1) (b8h b2) c with
-   [ pair h c' ⇒ pair … 〈h,l〉 c' ]].
+ndefinition plus_b8_d_dc ≝ opcl2_cn ? plus_ex_dc_dc false.
 
 (* operatore somma con data → data *)
-ndefinition plus_b8_d_d ≝
-λb1,b2:byte8.
- match plus_ex_d_dc (b8l b1) (b8l b2) with
-  [ pair l c ⇒ 〈plus_ex_dc_d (b8h b1) (b8h b2) c,l〉 ].
+ndefinition plus_b8_d_d ≝ λb1,b2.snd … (plus_b8_d_dc b1 b2).
 
 (* operatore somma con data → c *)
-ndefinition plus_b8_d_c ≝
-λb1,b2:byte8.
- plus_ex_dc_c (b8h b1) (b8h b2) (plus_ex_d_c (b8l b1) (b8l b2)).
-
-(* operatore Most Significant Bit *)
-ndefinition MSB_b8 ≝ λb:byte8.eq_ex x8 (and_ex x8 (b8h b)).
+ndefinition plus_b8_d_c ≝ λb1,b2.fst … (plus_b8_d_dc b1 b2).
 
 (* operatore predecessore *)
-ndefinition pred_b8 ≝
-λb:byte8.match eq_ex (b8l b) x0 with
- [ true ⇒ mk_byte8 (pred_ex (b8h b)) (pred_ex (b8l b))
- | false ⇒ mk_byte8 (b8h b) (pred_ex (b8l b)) ]. 
+ndefinition pred_b8 ≝ predsucc_cn ? (eq_ex x0) pred_ex.
 
 (* operatore successore *)
-ndefinition succ_b8 ≝
-λb:byte8.match eq_ex (b8l b) xF with
- [ true ⇒ mk_byte8 (succ_ex (b8h b)) (succ_ex (b8l b))
- | false ⇒ mk_byte8 (b8h b) (succ_ex (b8l b)) ]. 
+ndefinition succ_b8 ≝ predsucc_cn ? (eq_ex xF) succ_ex.
 
 (* operatore neg/complemento a 2 *)
 ndefinition compl_b8 ≝
-λb:byte8.match MSB_b8 b with
+λb:byte8.match getMSB_b8 b with
  [ true ⇒ succ_b8 (not_b8 b)
  | false ⇒ not_b8 (pred_b8 b) ].
 
+(* operatore abs *)
+ndefinition abs_b8 ≝
+λb:byte8.match getMSB_b8 b with
+ [ true ⇒ compl_b8 b | false ⇒ b ].
+
+(* operatore x in [inf,sup] o in sup],[inf *)
+ndefinition inrange_b8 ≝
+λx,inf,sup:byte8.
+ match le_b8 inf sup with
+  [ true ⇒ and_bool | false ⇒ or_bool ]
+ (le_b8 inf x) (le_b8 x sup).
+
 (* operatore moltiplicazione senza segno: e*e=[0x00,0xE1] *)
-ndefinition mul_ex ≝
+ndefinition mulu_ex ≝
 λe1,e2:exadecim.match e1 with
  [ x0 ⇒ match e2 with
   [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,x0〉   | x2 ⇒ 〈x0,x0〉   | x3 ⇒ 〈x0,x0〉
@@ -268,6 +235,91 @@ ndefinition mul_ex ≝
   | xC ⇒ 〈xB,x4〉   | xD ⇒ 〈xC,x3〉   | xE ⇒ 〈xD,x2〉   | xF ⇒ 〈xE,x1〉 ]
  ].
 
+(* operatore moltiplicazione con segno *)
+ndefinition muls_ex ≝
+λe1,e2:exadecim.match e1 with
+ [ x0 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x0〉 | x2 ⇒ 〈x0,x0〉 | x3 ⇒ 〈x0,x0〉
+  | x4 ⇒ 〈x0,x0〉 | x5 ⇒ 〈x0,x0〉 | x6 ⇒ 〈x0,x0〉 | x7 ⇒ 〈x0,x0〉
+  | x8 ⇒ 〈x0,x0〉 | x9 ⇒ 〈x0,x0〉 | xA ⇒ 〈x0,x0〉 | xB ⇒ 〈x0,x0〉
+  | xC ⇒ 〈x0,x0〉 | xD ⇒ 〈x0,x0〉 | xE ⇒ 〈x0,x0〉 | xF ⇒ 〈x0,x0〉 ]
+ | x1 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x1〉 | x2 ⇒ 〈x0,x2〉 | x3 ⇒ 〈x0,x3〉
+  | x4 ⇒ 〈x0,x4〉 | x5 ⇒ 〈x0,x5〉 | x6 ⇒ 〈x0,x6〉 | x7 ⇒ 〈x0,x7〉
+  | x8 ⇒ 〈xF,x8〉 | x9 ⇒ 〈xF,x9〉 | xA ⇒ 〈xF,xA〉 | xB ⇒ 〈xF,xB〉
+  | xC ⇒ 〈xF,xC〉 | xD ⇒ 〈xF,xD〉 | xE ⇒ 〈xF,xE〉 | xF ⇒ 〈xF,xF〉 ]
+ | x2 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x2〉 | x2 ⇒ 〈x0,x4〉 | x3 ⇒ 〈x0,x6〉
+  | x4 ⇒ 〈x0,x8〉 | x5 ⇒ 〈x0,xA〉 | x6 ⇒ 〈x0,xC〉 | x7 ⇒ 〈x0,xE〉
+  | x8 ⇒ 〈xF,x0〉 | x9 ⇒ 〈xF,x2〉 | xA ⇒ 〈xF,x4〉 | xB ⇒ 〈xF,x6〉
+  | xC ⇒ 〈xF,x8〉 | xD ⇒ 〈xF,xA〉 | xE ⇒ 〈xF,xC〉 | xF ⇒ 〈xF,xE〉 ]
+ | x3 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x3〉 | x2 ⇒ 〈x0,x6〉 | x3 ⇒ 〈x0,x9〉
+  | x4 ⇒ 〈x0,xC〉 | x5 ⇒ 〈x0,xF〉 | x6 ⇒ 〈x1,x2〉 | x7 ⇒ 〈x1,x5〉
+  | x8 ⇒ 〈xE,x8〉 | x9 ⇒ 〈xE,xB〉 | xA ⇒ 〈xE,xE〉 | xB ⇒ 〈xF,x1〉
+  | xC ⇒ 〈xF,x4〉 | xD ⇒ 〈xF,x7〉 | xE ⇒ 〈xF,xA〉 | xF ⇒ 〈xF,xD〉 ]
+ | x4 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x4〉 | x2 ⇒ 〈x0,x8〉 | x3 ⇒ 〈x0,xC〉
+  | x4 ⇒ 〈x1,x0〉 | x5 ⇒ 〈x1,x4〉 | x6 ⇒ 〈x1,x8〉 | x7 ⇒ 〈x1,xC〉
+  | x8 ⇒ 〈xE,x0〉 | x9 ⇒ 〈xE,x4〉 | xA ⇒ 〈xE,x8〉 | xB ⇒ 〈xE,xC〉
+  | xC ⇒ 〈xF,x0〉 | xD ⇒ 〈xF,x4〉 | xE ⇒ 〈xF,x8〉 | xF ⇒ 〈xF,xC〉 ]
+ | x5 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x5〉 | x2 ⇒ 〈x0,xA〉 | x3 ⇒ 〈x0,xF〉
+  | x4 ⇒ 〈x1,x4〉 | x5 ⇒ 〈x1,x9〉 | x6 ⇒ 〈x1,xE〉 | x7 ⇒ 〈x2,x3〉
+  | x8 ⇒ 〈xD,x8〉 | x9 ⇒ 〈xD,xD〉 | xA ⇒ 〈xE,x2〉 | xB ⇒ 〈xE,x7〉
+  | xC ⇒ 〈xE,xC〉 | xD ⇒ 〈xF,x1〉 | xE ⇒ 〈xF,x6〉 | xF ⇒ 〈xF,xB〉 ]
+ | x6 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x6〉 | x2 ⇒ 〈x0,xC〉 | x3 ⇒ 〈x1,x2〉
+  | x4 ⇒ 〈x1,x8〉 | x5 ⇒ 〈x1,xE〉 | x6 ⇒ 〈x2,x4〉 | x7 ⇒ 〈x2,xA〉
+  | x8 ⇒ 〈xD,x0〉 | x9 ⇒ 〈xD,x6〉 | xA ⇒ 〈xD,xC〉 | xB ⇒ 〈xE,x2〉
+  | xC ⇒ 〈xE,x8〉 | xD ⇒ 〈xE,xE〉 | xE ⇒ 〈xF,x4〉 | xF ⇒ 〈xF,xA〉 ]
+ | x7 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈x0,x7〉 | x2 ⇒ 〈x0,xE〉 | x3 ⇒ 〈x1,x5〉
+  | x4 ⇒ 〈x1,xC〉 | x5 ⇒ 〈x2,x3〉 | x6 ⇒ 〈x2,xA〉 | x7 ⇒ 〈x3,x1〉
+  | x8 ⇒ 〈xC,x8〉 | x9 ⇒ 〈xC,xF〉 | xA ⇒ 〈xD,x6〉 | xB ⇒ 〈xD,xD〉
+  | xC ⇒ 〈xE,x4〉 | xD ⇒ 〈xE,xB〉 | xE ⇒ 〈xF,x2〉 | xF ⇒ 〈xF,x9〉 ]
+ | x8 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,x8〉 | x2 ⇒ 〈xF,x0〉 | x3 ⇒ 〈xE,x8〉
+  | x4 ⇒ 〈xE,x0〉 | x5 ⇒ 〈xD,x8〉 | x6 ⇒ 〈xD,x0〉 | x7 ⇒ 〈xC,x8〉
+  | x8 ⇒ 〈x4,x0〉 | x9 ⇒ 〈x3,x8〉 | xA ⇒ 〈x3,x0〉 | xB ⇒ 〈x2,x8〉
+  | xC ⇒ 〈x2,x0〉 | xD ⇒ 〈x1,x8〉 | xE ⇒ 〈x1,x0〉 | xF ⇒ 〈x0,x8〉 ]
+ | x9 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,x9〉 | x2 ⇒ 〈xF,x2〉 | x3 ⇒ 〈xE,xB〉
+  | x4 ⇒ 〈xE,x4〉 | x5 ⇒ 〈xD,xD〉 | x6 ⇒ 〈xD,x6〉 | x7 ⇒ 〈xC,xF〉
+  | x8 ⇒ 〈x3,x8〉 | x9 ⇒ 〈x3,x1〉 | xA ⇒ 〈x2,xA〉 | xB ⇒ 〈x2,x3〉
+  | xC ⇒ 〈x1,xC〉 | xD ⇒ 〈x1,x5〉 | xE ⇒ 〈x0,xE〉 | xF ⇒ 〈x0,x7〉 ]
+ | xA ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xA〉 | x2 ⇒ 〈xF,x4〉 | x3 ⇒ 〈xE,xE〉
+  | x4 ⇒ 〈xE,x8〉 | x5 ⇒ 〈xE,x2〉 | x6 ⇒ 〈xD,xC〉 | x7 ⇒ 〈xD,x6〉
+  | x8 ⇒ 〈x3,x0〉 | x9 ⇒ 〈x2,xA〉 | xA ⇒ 〈x2,x4〉 | xB ⇒ 〈x1,xE〉
+  | xC ⇒ 〈x1,x8〉 | xD ⇒ 〈x1,x2〉 | xE ⇒ 〈x0,xC〉 | xF ⇒ 〈x0,x6〉 ]
+ | xB ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xB〉 | x2 ⇒ 〈xF,x6〉 | x3 ⇒ 〈xF,x1〉
+  | x4 ⇒ 〈xE,xC〉 | x5 ⇒ 〈xE,x7〉 | x6 ⇒ 〈xE,x2〉 | x7 ⇒ 〈xD,xD〉
+  | x8 ⇒ 〈x2,x8〉 | x9 ⇒ 〈x2,x3〉 | xA ⇒ 〈x1,xE〉 | xB ⇒ 〈x1,x9〉
+  | xC ⇒ 〈x1,x4〉 | xD ⇒ 〈x0,xF〉 | xE ⇒ 〈x0,xA〉 | xF ⇒ 〈x0,x5〉 ]
+ | xC ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xC〉 | x2 ⇒ 〈xF,x8〉 | x3 ⇒ 〈xF,x4〉
+  | x4 ⇒ 〈xF,x0〉 | x5 ⇒ 〈xE,xC〉 | x6 ⇒ 〈xE,x8〉 | x7 ⇒ 〈xE,x4〉
+  | x8 ⇒ 〈x2,x0〉 | x9 ⇒ 〈x1,xC〉 | xA ⇒ 〈x1,x8〉 | xB ⇒ 〈x1,x4〉
+  | xC ⇒ 〈x1,x0〉 | xD ⇒ 〈x0,xC〉 | xE ⇒ 〈x0,x8〉 | xF ⇒ 〈x0,x4〉 ]
+ | xD ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xD〉 | x2 ⇒ 〈xF,xA〉 | x3 ⇒ 〈xF,x7〉
+  | x4 ⇒ 〈xF,x4〉 | x5 ⇒ 〈xF,x1〉 | x6 ⇒ 〈xE,xE〉 | x7 ⇒ 〈xE,xB〉
+  | x8 ⇒ 〈x1,x8〉 | x9 ⇒ 〈x1,x5〉 | xA ⇒ 〈x1,x2〉 | xB ⇒ 〈x0,xF〉
+  | xC ⇒ 〈x0,xC〉 | xD ⇒ 〈x0,x9〉 | xE ⇒ 〈x0,x6〉 | xF ⇒ 〈x0,x3〉 ]
+ | xE ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xE〉 | x2 ⇒ 〈xF,xC〉 | x3 ⇒ 〈xF,xA〉
+  | x4 ⇒ 〈xF,x8〉 | x5 ⇒ 〈xF,x6〉 | x6 ⇒ 〈xF,x4〉 | x7 ⇒ 〈xF,x2〉
+  | x8 ⇒ 〈x1,x0〉 | x9 ⇒ 〈x0,xE〉 | xA ⇒ 〈x0,xC〉 | xB ⇒ 〈x0,xA〉
+  | xC ⇒ 〈x0,x8〉 | xD ⇒ 〈x0,x6〉 | xE ⇒ 〈x0,x4〉 | xF ⇒ 〈x0,x2〉 ]
+ | xF ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉 | x1 ⇒ 〈xF,xF〉 | x2 ⇒ 〈xF,xE〉 | x3 ⇒ 〈xF,xD〉
+  | x4 ⇒ 〈xF,xC〉 | x5 ⇒ 〈xF,xB〉 | x6 ⇒ 〈xF,xA〉 | x7 ⇒ 〈xF,x9〉
+  | x8 ⇒ 〈x0,x8〉 | x9 ⇒ 〈x0,x7〉 | xA ⇒ 〈x0,x6〉 | xB ⇒ 〈x0,x5〉
+  | xC ⇒ 〈x0,x4〉 | xD ⇒ 〈x0,x3〉 | xE ⇒ 〈x0,x2〉 | xF ⇒ 〈x0,x1〉 ]
+ ].
+
 (* correzione per somma su BCD *)
 (* input: halfcarry,carry,X(BCD+BCD) *)
 (* output: X',carry' *)
@@ -279,33 +331,26 @@ ndefinition daa_b8 ≝
   (* X' = [(b16l X):0x0-0x9] X + [h=1 ? 0x06 : 0x00] + [c=1 ? 0x60 : 0x00]
           [(b16l X):0xA-0xF] X + 0x06 + [c=1 ? 0x60 : 0x00] *)
   [ true ⇒
-   let X' ≝ match (lt_ex (b8l X) xA) ⊗ (⊖h) with
+   let X' ≝ match (lt_ex (cnL ? X) xA) ⊗ (⊖h) with
     [ true ⇒ X
     | false ⇒ plus_b8_d_d X 〈x0,x6〉 ] in
    let X'' ≝ match c with
     [ true ⇒ plus_b8_d_d X' 〈x6,x0〉
     | false ⇒ X' ] in
-   pair … X'' c
+   pair … c X''
   (* [X:0x9A-0xFF] *)
   (* c' = 1 *)
   (* X' = [X:0x9A-0xFF]
           [(b16l X):0x0-0x9] X + [h=1 ? 0x06 : 0x00] + 0x60
           [(b16l X):0xA-0xF] X + 0x6 + 0x60 *) 
   | false ⇒
-   let X' ≝ match (lt_ex (b8l X) xA) ⊗ (⊖h) with
+   let X' ≝ match (lt_ex (cnL ? X) xA) ⊗ (⊖h) with
     [ true ⇒ X
     | false ⇒ plus_b8_d_d X 〈x0,x6〉 ] in
    let X'' ≝ plus_b8_d_d X' 〈x6,x0〉 in
-   pair … X'' true
+   pair … true X''
   ].
 
-(* iteratore sui byte *)
-ndefinition forall_b8 ≝
- λP.
-  forall_ex (λbh.
-  forall_ex (λbl.
-   P (mk_byte8 bh bl))).
-
 (* byte ricorsivi *)
 ninductive rec_byte8 : byte8 → Type ≝
   b8_O : rec_byte8 〈x0,x0〉
@@ -314,8 +359,10 @@ ninductive rec_byte8 : byte8 → Type ≝
 (* byte → byte ricorsivi *)
 ndefinition b8_to_recb8_aux1 : Πn.rec_byte8 〈n,x0〉 → rec_byte8 〈succ_ex n,x0〉 ≝
 λn.λrecb:rec_byte8 〈n,x0〉.
- b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (
- b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))))))).
+ b8_S 〈n,xF〉 (b8_S 〈n,xE〉 (b8_S 〈n,xD〉 (b8_S 〈n,xC〉 (
+ b8_S 〈n,xB〉 (b8_S 〈n,xA〉 (b8_S 〈n,x9〉 (b8_S 〈n,x8〉 (
+ b8_S 〈n,x7〉 (b8_S 〈n,x6〉 (b8_S 〈n,x5〉 (b8_S 〈n,x4〉 (
+ b8_S 〈n,x3〉 (b8_S 〈n,x2〉 (b8_S 〈n,x1〉 (b8_S 〈n,x0〉 recb))))))))))))))).
 
 (* ... cifra esadecimale superiore *)
 nlet rec b8_to_recb8_aux2 (n:exadecim) (r:rec_exadecim n) on r ≝
@@ -329,29 +376,55 @@ ndefinition b8_to_recb8_aux3 : Πn1,n2.rec_byte8 〈n1,x0〉 → rec_byte8 〈n1
 λn1,n2.λrecb:rec_byte8 〈n1,x0〉.
  match n2 return λx.rec_byte8 〈n1,x〉 with
   [ x0 ⇒ recb
-  | x1 ⇒ b8_S ? recb
-  | x2 ⇒ b8_S ? (b8_S ? recb)
-  | x3 ⇒ b8_S ? (b8_S ? (b8_S ? recb))
-  | x4 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))
-  | x5 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))
-  | x6 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))
-  | x7 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))
-  | x8 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))
-  | x9 ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))
-  | xA ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))))
-  | xB ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))
-  | xC ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))))))
-  | xD ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))))
-  | xE ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb)))))))))))))
-  | xF ⇒ b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? (b8_S ? recb))))))))))))))
+  | x1 ⇒ b8_S 〈n1,x0〉 recb
+  | x2 ⇒ b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb)
+  | x3 ⇒ b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb))
+  | x4 ⇒ b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb)))
+  | x5 ⇒ b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (
+         b8_S 〈n1,x0〉 recb))))
+  | x6 ⇒ b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (
+         b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb)))))
+  | x7 ⇒ b8_S 〈n1,x6〉 (b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (
+         b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb))))))
+  | x8 ⇒ b8_S 〈n1,x7〉 (b8_S 〈n1,x6〉 (b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (
+         b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb)))))))
+  | x9 ⇒ b8_S 〈n1,x8〉 (b8_S 〈n1,x7〉 (b8_S 〈n1,x6〉 (b8_S 〈n1,x5〉 (
+         b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (
+         b8_S 〈n1,x0〉 recb))))))))
+  | xA ⇒ b8_S 〈n1,x9〉 (b8_S 〈n1,x8〉 (b8_S 〈n1,x7〉 (b8_S 〈n1,x6〉 (
+         b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (
+         b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb)))))))))
+  | xB ⇒ b8_S 〈n1,xA〉 (b8_S 〈n1,x9〉 (b8_S 〈n1,x8〉 (b8_S 〈n1,x7〉 (
+         b8_S 〈n1,x6〉 (b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (
+         b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb))))))))))
+  | xC ⇒ b8_S 〈n1,xB〉 (b8_S 〈n1,xA〉 (b8_S 〈n1,x9〉 (b8_S 〈n1,x8〉 (
+         b8_S 〈n1,x7〉 (b8_S 〈n1,x6〉 (b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (
+         b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb)))))))))))
+  | xD ⇒ b8_S 〈n1,xC〉 (b8_S 〈n1,xB〉 (b8_S 〈n1,xA〉 (b8_S 〈n1,x9〉 (
+         b8_S 〈n1,x8〉 (b8_S 〈n1,x7〉 (b8_S 〈n1,x6〉 (b8_S 〈n1,x5〉 (
+         b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (
+         b8_S 〈n1,x0〉 recb))))))))))))
+  | xE ⇒ b8_S 〈n1,xD〉 (b8_S 〈n1,xC〉 (b8_S 〈n1,xB〉 (b8_S 〈n1,xA〉 (
+         b8_S 〈n1,x9〉 (b8_S 〈n1,x8〉 (b8_S 〈n1,x7〉 (b8_S 〈n1,x6〉 (
+         b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (b8_S 〈n1,x2〉 (
+         b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb)))))))))))))
+  | xF ⇒ b8_S 〈n1,xE〉 (b8_S 〈n1,xD〉 (b8_S 〈n1,xC〉 (b8_S 〈n1,xB〉 (
+         b8_S 〈n1,xA〉 (b8_S 〈n1,x9〉 (b8_S 〈n1,x8〉 (b8_S 〈n1,x7〉 (
+         b8_S 〈n1,x6〉 (b8_S 〈n1,x5〉 (b8_S 〈n1,x4〉 (b8_S 〈n1,x3〉 (
+         b8_S 〈n1,x2〉 (b8_S 〈n1,x1〉 (b8_S 〈n1,x0〉 recb))))))))))))))
   ].
 
-ndefinition b8_to_recb8 : Πb.rec_byte8 b.
- #b;
- nletin K ≝ (b8_to_recb8_aux3 (b8h b) (b8l b) (b8_to_recb8_aux2 (b8h b) (ex_to_recex (b8h b))));
nelim b in K:(%) ⊢ %;
- #e1; #e2; nnormalize; #H; napply H.
+(*
+nlemma b8_to_recb8 : Πb.rec_byte8 b.
+ #b; nletin K ≝ (b8_to_recb8_aux3 
    (b8h b) (b8l b) (b8_to_recb8_aux2 (b8h b) (ex_to_recex (b8h b))));
+ ncases b in K; #e1; #e2; #K; napply K;
 nqed.
+*)
+
+ndefinition b8_to_recb8 : Πb.rec_byte8 b ≝
+λb.match b with
+ [ mk_comp_num h l ⇒ b8_to_recb8_aux3 h l (b8_to_recb8_aux2 h (ex_to_recex h)) ].
 
 (* ottali → esadecimali *)
 ndefinition b8_of_bit ≝