]> matita.cs.unibo.it Git - helm.git/commitdiff
(no commit message)
authorCosimo Oliboni <??>
Sat, 23 Jan 2010 16:16:40 +0000 (16:16 +0000)
committerCosimo Oliboni <??>
Sat, 23 Jan 2010 16:16:40 +0000 (16:16 +0000)
72 files changed:
helm/software/matita/contribs/ng_assembly/common/ascii.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/ascii_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/list.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/list_lemmas.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/list_utility.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/list_utility_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/nat.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/nat_lemmas.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/nat_to_num.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/option.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/option_lemmas.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/prod.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/prod_lemmas.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/sigma.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/string.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/common/string_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/common/theory.ma [new file with mode: 0644]
helm/software/matita/contribs/ng_assembly/compiler/ast_type.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/compiler/ast_type_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/compiler/environment.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/compiler/preast_tree.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/memory/memory_abs.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/memory/memory_bits.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/memory/memory_func.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/memory/memory_struct.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/memory/memory_trees.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_instr_mode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_opcode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_table.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_table_tests.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_instr_mode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_opcode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_table.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_table_tests.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_opcode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_table.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_table_tests.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_instr_mode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_opcode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_table.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_table_tests.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/byte_or_word.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/opcodes/opcode.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/status/HC05_status.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/status/HC08_status.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/status/RS08_status.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/status/status.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/status/status_getter.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/status/status_setter.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/translation/HC05_translation.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/translation/HC08_translation.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/translation/HCS08_translation.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/translation/RS08_translation.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/translation/translation.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/emulator/translation/translation_base.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/bitrigesim.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/bitrigesim_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/bool.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/bool_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/byte8.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/byte8_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/exadecim.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/exadecim_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/oct.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/oct_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/quatern.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/quatern_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/word16.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/word16_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/word32.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/num/word32_lemmas.ma [new file with mode: 0755]
helm/software/matita/contribs/ng_assembly/universe/universe.ma [new file with mode: 0755]

diff --git a/helm/software/matita/contribs/ng_assembly/common/ascii.ma b/helm/software/matita/contribs/ng_assembly/common/ascii.ma
new file mode 100755 (executable)
index 0000000..ddb65df
--- /dev/null
@@ -0,0 +1,167 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ************************** *)
+(* DEFINIZIONE ASCII MINIMALE *)
+(* ************************** *)
+
+ninductive ascii : Type ≝
+(* numeri *)  
+  ch_0: ascii
+| ch_1: ascii
+| ch_2: ascii
+| ch_3: ascii
+| ch_4: ascii
+| ch_5: ascii
+| ch_6: ascii
+| ch_7: ascii
+| ch_8: ascii
+| ch_9: ascii
+
+(* simboli *)
+| ch__: ascii
+
+(* maiuscole *)
+| ch_A: ascii
+| ch_B: ascii
+| ch_C: ascii
+| ch_D: ascii
+| ch_E: ascii
+| ch_F: ascii
+| ch_G: ascii
+| ch_H: ascii
+| ch_I: ascii
+| ch_J: ascii
+| ch_K: ascii
+| ch_L: ascii
+| ch_M: ascii
+| ch_N: ascii
+| ch_O: ascii
+| ch_P: ascii
+| ch_Q: ascii
+| ch_R: ascii
+| ch_S: ascii
+| ch_T: ascii
+| ch_U: ascii
+| ch_V: ascii
+| ch_W: ascii
+| ch_X: ascii
+| ch_Y: ascii
+| ch_Z: ascii
+
+(* minuscole *)
+| ch_a: ascii
+| ch_b: ascii
+| ch_c: ascii
+| ch_d: ascii
+| ch_e: ascii
+| ch_f: ascii
+| ch_g: ascii
+| ch_h: ascii
+| ch_i: ascii
+| ch_j: ascii
+| ch_k: ascii
+| ch_l: ascii
+| ch_m: ascii
+| ch_n: ascii
+| ch_o: ascii
+| ch_p: ascii
+| ch_q: ascii
+| ch_r: ascii
+| ch_s: ascii
+| ch_t: ascii
+| ch_u: ascii
+| ch_v: ascii
+| ch_w: ascii
+| ch_x: ascii
+| ch_y: ascii
+| ch_z: ascii.
+
+(* confronto fra ascii *)
+ndefinition eq_ascii ≝
+λc,c':ascii.match c with
+ [ ch_0 ⇒ match c' with [ ch_0 ⇒ true | _ ⇒ false ]
+ | ch_1 ⇒ match c' with [ ch_1 ⇒ true | _ ⇒ false ]
+ | ch_2 ⇒ match c' with [ ch_2 ⇒ true | _ ⇒ false ]
+ | ch_3 ⇒ match c' with [ ch_3 ⇒ true | _ ⇒ false ]
+ | ch_4 ⇒ match c' with [ ch_4 ⇒ true | _ ⇒ false ]
+ | ch_5 ⇒ match c' with [ ch_5 ⇒ true | _ ⇒ false ]
+ | ch_6 ⇒ match c' with [ ch_6 ⇒ true | _ ⇒ false ]
+ | ch_7 ⇒ match c' with [ ch_7 ⇒ true | _ ⇒ false ]
+ | ch_8 ⇒ match c' with [ ch_8 ⇒ true | _ ⇒ false ]
+ | ch_9 ⇒ match c' with [ ch_9 ⇒ true | _ ⇒ false ]
+ | ch__ ⇒ match c' with [ ch__ ⇒ true | _ ⇒ false ]
+ | ch_A ⇒ match c' with [ ch_A ⇒ true | _ ⇒ false ]
+ | ch_B ⇒ match c' with [ ch_B ⇒ true | _ ⇒ false ]
+ | ch_C ⇒ match c' with [ ch_C ⇒ true | _ ⇒ false ]
+ | ch_D ⇒ match c' with [ ch_D ⇒ true | _ ⇒ false ]
+ | ch_E ⇒ match c' with [ ch_E ⇒ true | _ ⇒ false ]
+ | ch_F ⇒ match c' with [ ch_F ⇒ true | _ ⇒ false ]
+ | ch_G ⇒ match c' with [ ch_G ⇒ true | _ ⇒ false ]
+ | ch_H ⇒ match c' with [ ch_H ⇒ true | _ ⇒ false ]
+ | ch_I ⇒ match c' with [ ch_I ⇒ true | _ ⇒ false ]
+ | ch_J ⇒ match c' with [ ch_J ⇒ true | _ ⇒ false ]
+ | ch_K ⇒ match c' with [ ch_K ⇒ true | _ ⇒ false ]
+ | ch_L ⇒ match c' with [ ch_L ⇒ true | _ ⇒ false ]
+ | ch_M ⇒ match c' with [ ch_M ⇒ true | _ ⇒ false ]
+ | ch_N ⇒ match c' with [ ch_N ⇒ true | _ ⇒ false ]
+ | ch_O ⇒ match c' with [ ch_O ⇒ true | _ ⇒ false ]
+ | ch_P ⇒ match c' with [ ch_P ⇒ true | _ ⇒ false ]
+ | ch_Q ⇒ match c' with [ ch_Q ⇒ true | _ ⇒ false ]
+ | ch_R ⇒ match c' with [ ch_R ⇒ true | _ ⇒ false ]
+ | ch_S ⇒ match c' with [ ch_S ⇒ true | _ ⇒ false ]
+ | ch_T ⇒ match c' with [ ch_T ⇒ true | _ ⇒ false ]
+ | ch_U ⇒ match c' with [ ch_U ⇒ true | _ ⇒ false ]
+ | ch_V ⇒ match c' with [ ch_V ⇒ true | _ ⇒ false ]
+ | ch_W ⇒ match c' with [ ch_W ⇒ true | _ ⇒ false ]
+ | ch_X ⇒ match c' with [ ch_X ⇒ true | _ ⇒ false ]
+ | ch_Y ⇒ match c' with [ ch_Y ⇒ true | _ ⇒ false ]
+ | ch_Z ⇒ match c' with [ ch_Z ⇒ true | _ ⇒ false ]
+ | ch_a ⇒ match c' with [ ch_a ⇒ true | _ ⇒ false ]
+ | ch_b ⇒ match c' with [ ch_b ⇒ true | _ ⇒ false ]
+ | ch_c ⇒ match c' with [ ch_c ⇒ true | _ ⇒ false ]
+ | ch_d ⇒ match c' with [ ch_d ⇒ true | _ ⇒ false ]
+ | ch_e ⇒ match c' with [ ch_e ⇒ true | _ ⇒ false ]
+ | ch_f ⇒ match c' with [ ch_f ⇒ true | _ ⇒ false ]
+ | ch_g ⇒ match c' with [ ch_g ⇒ true | _ ⇒ false ]
+ | ch_h ⇒ match c' with [ ch_h ⇒ true | _ ⇒ false ]
+ | ch_i ⇒ match c' with [ ch_i ⇒ true | _ ⇒ false ]
+ | ch_j ⇒ match c' with [ ch_j ⇒ true | _ ⇒ false ]
+ | ch_k ⇒ match c' with [ ch_k ⇒ true | _ ⇒ false ]
+ | ch_l ⇒ match c' with [ ch_l ⇒ true | _ ⇒ false ]
+ | ch_m ⇒ match c' with [ ch_m ⇒ true | _ ⇒ false ]
+ | ch_n ⇒ match c' with [ ch_n ⇒ true | _ ⇒ false ]
+ | ch_o ⇒ match c' with [ ch_o ⇒ true | _ ⇒ false ]
+ | ch_p ⇒ match c' with [ ch_p ⇒ true | _ ⇒ false ]
+ | ch_q ⇒ match c' with [ ch_q ⇒ true | _ ⇒ false ]
+ | ch_r ⇒ match c' with [ ch_r ⇒ true | _ ⇒ false ]
+ | ch_s ⇒ match c' with [ ch_s ⇒ true | _ ⇒ false ]
+ | ch_t ⇒ match c' with [ ch_t ⇒ true | _ ⇒ false ]
+ | ch_u ⇒ match c' with [ ch_u ⇒ true | _ ⇒ false ]
+ | ch_v ⇒ match c' with [ ch_v ⇒ true | _ ⇒ false ]
+ | ch_w ⇒ match c' with [ ch_w ⇒ true | _ ⇒ false ]
+ | ch_x ⇒ match c' with [ ch_x ⇒ true | _ ⇒ false ]
+ | ch_y ⇒ match c' with [ ch_y ⇒ true | _ ⇒ false ]
+ | ch_z ⇒ match c' with [ ch_z ⇒ true | _ ⇒ false ]
+ ].
diff --git a/helm/software/matita/contribs/ng_assembly/common/ascii_lemmas.ma b/helm/software/matita/contribs/ng_assembly/common/ascii_lemmas.ma
new file mode 100755 (executable)
index 0000000..dd1eec4
--- /dev/null
@@ -0,0 +1,183 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/ascii.ma".
+include "num/bool_lemmas.ma".
+
+(* ************************** *)
+(* DEFINIZIONE ASCII MINIMALE *)
+(* ************************** *)
+
+(*
+ndefinition ascii_destruct_aux ≝
+Πc1,c2.ΠP:Prop.c1 = c2 →
+ match eq_ascii c1 c2 with [ true ⇒ P → P | false ⇒ P ].
+
+nlemma ascii_destruct : ascii_destruct_aux.
+ #c1; #c2; #P; #H;
+ nrewrite < H;
+ nelim c1;
+ nnormalize;
+ napply (λx.x).
+nqed.
+*)
+
+nlemma eq_to_eqascii : ∀n1,n2.n1 = n2 → eq_ascii n1 n2 = true.
+ #n1; #n2; #H;
+ nrewrite > H;
+ nelim n2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma neqascii_to_neq : ∀n1,n2.eq_ascii n1 n2 = false → n1 ≠ n2.
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_ascii n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqascii n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqascii_to_eq1 : ∀a2.eq_ascii ch_0 a2 = true → ch_0 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##1: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq2 : ∀a2.eq_ascii ch_1 a2 = true → ch_1 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##2: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq3 : ∀a2.eq_ascii ch_2 a2 = true → ch_2 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##3: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq4 : ∀a2.eq_ascii ch_3 a2 = true → ch_3 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##4: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq5 : ∀a2.eq_ascii ch_4 a2 = true → ch_4 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##5: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq6 : ∀a2.eq_ascii ch_5 a2 = true → ch_5 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##6: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq7 : ∀a2.eq_ascii ch_6 a2 = true → ch_6 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##7: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq8 : ∀a2.eq_ascii ch_7 a2 = true → ch_7 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##8: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq9 : ∀a2.eq_ascii ch_8 a2 = true → ch_8 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##9: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq10 : ∀a2.eq_ascii ch_9 a2 = true → ch_9 = a2. #a2; ncases a2; nnormalize; #H; ##[ ##10: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq11 : ∀a2.eq_ascii ch__ a2 = true → ch__ = a2. #a2; ncases a2; nnormalize; #H; ##[ ##11: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq12 : ∀a2.eq_ascii ch_A a2 = true → ch_A = a2. #a2; ncases a2; nnormalize; #H; ##[ ##12: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq13 : ∀a2.eq_ascii ch_B a2 = true → ch_B = a2. #a2; ncases a2; nnormalize; #H; ##[ ##13: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq14 : ∀a2.eq_ascii ch_C a2 = true → ch_C = a2. #a2; ncases a2; nnormalize; #H; ##[ ##14: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq15 : ∀a2.eq_ascii ch_D a2 = true → ch_D = a2. #a2; ncases a2; nnormalize; #H; ##[ ##15: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq16 : ∀a2.eq_ascii ch_E a2 = true → ch_E = a2. #a2; ncases a2; nnormalize; #H; ##[ ##16: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq17 : ∀a2.eq_ascii ch_F a2 = true → ch_F = a2. #a2; ncases a2; nnormalize; #H; ##[ ##17: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq18 : ∀a2.eq_ascii ch_G a2 = true → ch_G = a2. #a2; ncases a2; nnormalize; #H; ##[ ##18: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq19 : ∀a2.eq_ascii ch_H a2 = true → ch_H = a2. #a2; ncases a2; nnormalize; #H; ##[ ##19: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq20 : ∀a2.eq_ascii ch_I a2 = true → ch_I = a2. #a2; ncases a2; nnormalize; #H; ##[ ##20: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq21 : ∀a2.eq_ascii ch_J a2 = true → ch_J = a2. #a2; ncases a2; nnormalize; #H; ##[ ##21: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq22 : ∀a2.eq_ascii ch_K a2 = true → ch_K = a2. #a2; ncases a2; nnormalize; #H; ##[ ##22: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq23 : ∀a2.eq_ascii ch_L a2 = true → ch_L = a2. #a2; ncases a2; nnormalize; #H; ##[ ##23: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq24 : ∀a2.eq_ascii ch_M a2 = true → ch_M = a2. #a2; ncases a2; nnormalize; #H; ##[ ##24: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq25 : ∀a2.eq_ascii ch_N a2 = true → ch_N = a2. #a2; ncases a2; nnormalize; #H; ##[ ##25: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq26 : ∀a2.eq_ascii ch_O a2 = true → ch_O = a2. #a2; ncases a2; nnormalize; #H; ##[ ##26: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq27 : ∀a2.eq_ascii ch_P a2 = true → ch_P = a2. #a2; ncases a2; nnormalize; #H; ##[ ##27: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq28 : ∀a2.eq_ascii ch_Q a2 = true → ch_Q = a2. #a2; ncases a2; nnormalize; #H; ##[ ##28: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq29 : ∀a2.eq_ascii ch_R a2 = true → ch_R = a2. #a2; ncases a2; nnormalize; #H; ##[ ##29: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq30 : ∀a2.eq_ascii ch_S a2 = true → ch_S = a2. #a2; ncases a2; nnormalize; #H; ##[ ##30: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq31 : ∀a2.eq_ascii ch_T a2 = true → ch_T = a2. #a2; ncases a2; nnormalize; #H; ##[ ##31: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq32 : ∀a2.eq_ascii ch_U a2 = true → ch_U = a2. #a2; ncases a2; nnormalize; #H; ##[ ##32: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq33 : ∀a2.eq_ascii ch_V a2 = true → ch_V = a2. #a2; ncases a2; nnormalize; #H; ##[ ##33: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq34 : ∀a2.eq_ascii ch_W a2 = true → ch_W = a2. #a2; ncases a2; nnormalize; #H; ##[ ##34: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq35 : ∀a2.eq_ascii ch_X a2 = true → ch_X = a2. #a2; ncases a2; nnormalize; #H; ##[ ##35: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq36 : ∀a2.eq_ascii ch_Y a2 = true → ch_Y = a2. #a2; ncases a2; nnormalize; #H; ##[ ##36: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq37 : ∀a2.eq_ascii ch_Z a2 = true → ch_Z = a2. #a2; ncases a2; nnormalize; #H; ##[ ##37: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq38 : ∀a2.eq_ascii ch_a a2 = true → ch_a = a2. #a2; ncases a2; nnormalize; #H; ##[ ##38: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq39 : ∀a2.eq_ascii ch_b a2 = true → ch_b = a2. #a2; ncases a2; nnormalize; #H; ##[ ##39: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq40 : ∀a2.eq_ascii ch_c a2 = true → ch_c = a2. #a2; ncases a2; nnormalize; #H; ##[ ##40: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq41 : ∀a2.eq_ascii ch_d a2 = true → ch_d = a2. #a2; ncases a2; nnormalize; #H; ##[ ##41: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq42 : ∀a2.eq_ascii ch_e a2 = true → ch_e = a2. #a2; ncases a2; nnormalize; #H; ##[ ##42: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq43 : ∀a2.eq_ascii ch_f a2 = true → ch_f = a2. #a2; ncases a2; nnormalize; #H; ##[ ##43: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq44 : ∀a2.eq_ascii ch_g a2 = true → ch_g = a2. #a2; ncases a2; nnormalize; #H; ##[ ##44: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq45 : ∀a2.eq_ascii ch_h a2 = true → ch_h = a2. #a2; ncases a2; nnormalize; #H; ##[ ##45: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq46 : ∀a2.eq_ascii ch_i a2 = true → ch_i = a2. #a2; ncases a2; nnormalize; #H; ##[ ##46: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq47 : ∀a2.eq_ascii ch_j a2 = true → ch_j = a2. #a2; ncases a2; nnormalize; #H; ##[ ##47: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq48 : ∀a2.eq_ascii ch_k a2 = true → ch_k = a2. #a2; ncases a2; nnormalize; #H; ##[ ##48: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq49 : ∀a2.eq_ascii ch_l a2 = true → ch_l = a2. #a2; ncases a2; nnormalize; #H; ##[ ##49: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq50 : ∀a2.eq_ascii ch_m a2 = true → ch_m = a2. #a2; ncases a2; nnormalize; #H; ##[ ##50: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq51 : ∀a2.eq_ascii ch_n a2 = true → ch_n = a2. #a2; ncases a2; nnormalize; #H; ##[ ##51: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq52 : ∀a2.eq_ascii ch_o a2 = true → ch_o = a2. #a2; ncases a2; nnormalize; #H; ##[ ##52: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq53 : ∀a2.eq_ascii ch_p a2 = true → ch_p = a2. #a2; ncases a2; nnormalize; #H; ##[ ##53: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq54 : ∀a2.eq_ascii ch_q a2 = true → ch_q = a2. #a2; ncases a2; nnormalize; #H; ##[ ##54: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq55 : ∀a2.eq_ascii ch_r a2 = true → ch_r = a2. #a2; ncases a2; nnormalize; #H; ##[ ##55: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq56 : ∀a2.eq_ascii ch_s a2 = true → ch_s = a2. #a2; ncases a2; nnormalize; #H; ##[ ##56: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq57 : ∀a2.eq_ascii ch_t a2 = true → ch_t = a2. #a2; ncases a2; nnormalize; #H; ##[ ##57: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq58 : ∀a2.eq_ascii ch_u a2 = true → ch_u = a2. #a2; ncases a2; nnormalize; #H; ##[ ##58: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq59 : ∀a2.eq_ascii ch_v a2 = true → ch_v = a2. #a2; ncases a2; nnormalize; #H; ##[ ##59: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq60 : ∀a2.eq_ascii ch_w a2 = true → ch_w = a2. #a2; ncases a2; nnormalize; #H; ##[ ##60: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq61 : ∀a2.eq_ascii ch_x a2 = true → ch_x = a2. #a2; ncases a2; nnormalize; #H; ##[ ##61: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq62 : ∀a2.eq_ascii ch_y a2 = true → ch_y = a2. #a2; ncases a2; nnormalize; #H; ##[ ##62: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqascii_to_eq63 : ∀a2.eq_ascii ch_z a2 = true → ch_z = a2. #a2; ncases a2; nnormalize; #H; ##[ ##63: napply refl_eq | ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+
+nlemma eqascii_to_eq : ∀c1,c2.eq_ascii c1 c2 = true → c1 = c2.
+ #c1; ncases c1;
+ ##[ ##1: napply eqascii_to_eq1 ##| ##2: napply eqascii_to_eq2
+ ##| ##3: napply eqascii_to_eq3 ##| ##4: napply eqascii_to_eq4
+ ##| ##5: napply eqascii_to_eq5 ##| ##6: napply eqascii_to_eq6
+ ##| ##7: napply eqascii_to_eq7 ##| ##8: napply eqascii_to_eq8 
+ ##| ##9: napply eqascii_to_eq9 ##| ##10: napply eqascii_to_eq10
+ ##| ##11: napply eqascii_to_eq11 ##| ##12: napply eqascii_to_eq12 
+ ##| ##13: napply eqascii_to_eq13 ##| ##14: napply eqascii_to_eq14 
+ ##| ##15: napply eqascii_to_eq15 ##| ##16: napply eqascii_to_eq16 
+ ##| ##17: napply eqascii_to_eq17 ##| ##18: napply eqascii_to_eq18
+ ##| ##19: napply eqascii_to_eq19 ##| ##20: napply eqascii_to_eq20 
+ ##| ##21: napply eqascii_to_eq21 ##| ##22: napply eqascii_to_eq22 
+ ##| ##23: napply eqascii_to_eq23 ##| ##24: napply eqascii_to_eq24 
+ ##| ##25: napply eqascii_to_eq25 ##| ##26: napply eqascii_to_eq26
+ ##| ##27: napply eqascii_to_eq27 ##| ##28: napply eqascii_to_eq28
+ ##| ##29: napply eqascii_to_eq29 ##| ##30: napply eqascii_to_eq30 
+ ##| ##31: napply eqascii_to_eq31 ##| ##32: napply eqascii_to_eq32 
+ ##| ##33: napply eqascii_to_eq33 ##| ##34: napply eqascii_to_eq34
+ ##| ##35: napply eqascii_to_eq35 ##| ##36: napply eqascii_to_eq36
+ ##| ##37: napply eqascii_to_eq37 ##| ##38: napply eqascii_to_eq38
+ ##| ##39: napply eqascii_to_eq39 ##| ##40: napply eqascii_to_eq40
+ ##| ##41: napply eqascii_to_eq41 ##| ##42: napply eqascii_to_eq42
+ ##| ##43: napply eqascii_to_eq43 ##| ##44: napply eqascii_to_eq44 
+ ##| ##45: napply eqascii_to_eq45 ##| ##46: napply eqascii_to_eq46
+ ##| ##47: napply eqascii_to_eq47 ##| ##48: napply eqascii_to_eq48 
+ ##| ##49: napply eqascii_to_eq49 ##| ##50: napply eqascii_to_eq50
+ ##| ##51: napply eqascii_to_eq51 ##| ##52: napply eqascii_to_eq52
+ ##| ##53: napply eqascii_to_eq53 ##| ##54: napply eqascii_to_eq54 
+ ##| ##55: napply eqascii_to_eq55 ##| ##56: napply eqascii_to_eq56
+ ##| ##57: napply eqascii_to_eq57 ##| ##58: napply eqascii_to_eq58
+ ##| ##59: napply eqascii_to_eq59 ##| ##60: napply eqascii_to_eq60 
+ ##| ##61: napply eqascii_to_eq61 ##| ##62: napply eqascii_to_eq62 
+ ##| ##63: napply eqascii_to_eq63 ##]
+nqed.
+
+nlemma neq_to_neqascii : ∀n1,n2.n1 ≠ n2 → eq_ascii n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_ascii n1 n2));
+ napply (not_to_not (eq_ascii n1 n2 = true) (n1 = n2) ? H);
+ napply (eqascii_to_eq n1 n2).
+nqed.
+
+nlemma decidable_ascii : ∀x,y:ascii.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_ascii x y = true) (eq_ascii x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqascii_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqascii_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqascii : symmetricT ascii bool eq_ascii.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_ascii n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqascii n1 n2 H);
+          napply (symmetric_eq ? (eq_ascii n2 n1) false);
+          napply (neq_to_neqascii n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/common/list.ma b/helm/software/matita/contribs/ng_assembly/common/list.ma
new file mode 100644 (file)
index 0000000..5bd83a9
--- /dev/null
@@ -0,0 +1,84 @@
+(**************************************************************************)
+(*       ___                                                               *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
+(*      ||A||       E.Tassi, S.Zacchiroli                                 *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU Lesser General Public License Version 2.1         *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/theory.ma".
+
+(* *************** *)
+(* LISTE GENERICHE *)
+(* *************** *)
+
+ninductive list (A:Type) : Type ≝
+  nil: list A
+| cons: A → list A → list A.
+
+nlet rec append A (l1: list A) l2 on l1 ≝
+ match l1 with
+  [ nil ⇒ l2
+  | (cons hd tl) ⇒ cons A hd (append A tl l2) ].
+
+notation "hvbox(hd break :: tl)"
+  right associative with precedence 47
+  for @{'cons $hd $tl}.
+
+notation "[ list0 x sep ; ]"
+  non associative with precedence 90
+  for ${fold right @'nil rec acc @{'cons $x $acc}}.
+
+notation "hvbox(l1 break @ l2)"
+  right associative with precedence 47
+  for @{'append $l1 $l2 }.
+
+interpretation "nil" 'nil = (nil ?).
+interpretation "cons" 'cons hd tl = (cons ? hd tl).
+interpretation "append" 'append l1 l2 = (append ? l1 l2).
+
+(* ************** *)
+(* NON-EMPTY LIST *)
+(* ************** *)
+
+(* lista non vuota *)
+ninductive ne_list (A:Type) : Type ≝
+  | ne_nil: A → ne_list A
+  | ne_cons: A → ne_list A → ne_list A.
+
+(* append *)
+nlet rec ne_append (A:Type) (l1,l2:ne_list A) on l1 ≝
+ match l1 with
+  [ ne_nil hd ⇒ ne_cons A hd l2
+  | ne_cons hd tl ⇒ ne_cons A hd (ne_append A tl l2) ].
+
+notation "hvbox(hd break §§ tl)"
+  right associative with precedence 46
+  for @{'ne_cons $hd $tl}.
+
+(* \laquo \raquo *)
+notation "« list0 x sep ; break £ y break »"
+  non associative with precedence 90
+  for ${fold right @{'ne_nil $y } rec acc @{'ne_cons $x $acc}}.
+
+notation "hvbox(l1 break & l2)"
+  right associative with precedence 47
+  for @{'ne_append $l1 $l2 }.
+
+interpretation "ne_nil" 'ne_nil hd = (ne_nil ? hd).
+interpretation "ne_cons" 'ne_cons hd tl = (ne_cons ? hd tl).
+interpretation "ne_append" 'ne_append l1 l2 = (ne_append ? l1 l2).
diff --git a/helm/software/matita/contribs/ng_assembly/common/list_lemmas.ma b/helm/software/matita/contribs/ng_assembly/common/list_lemmas.ma
new file mode 100644 (file)
index 0000000..3be3a0a
--- /dev/null
@@ -0,0 +1,166 @@
+(**************************************************************************)
+(*       ___                                                               *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
+(*      ||A||       E.Tassi, S.Zacchiroli                                 *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU Lesser General Public License Version 2.1         *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/list.ma".
+
+(* *************** *)
+(* LISTE GENERICHE *)
+(* *************** *)
+
+nlemma list_destruct_1 : ∀T.∀x1,x2:T.∀y1,y2:list T.cons T x1 y1 = cons T x2 y2 → x1 = x2.
+ #T; #x1; #x2; #y1; #y2; #H;
+ nchange with (match cons T x2 y2 with [ nil ⇒ False | cons a _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma list_destruct_2 : ∀T.∀x1,x2:T.∀y1,y2:list T.cons T x1 y1 = cons T x2 y2 → y1 = y2.
+ #T; #x1; #x2; #y1; #y2; #H;
+ nchange with (match cons T x2 y2 with [ nil ⇒ False | cons _ b ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+(* !!! da togliere *)
+nlemma list_destruct_cons_nil : ∀T.∀x:T.∀y:list T.cons T x y = nil T → False.
+ #T; #x; #y; #H;
+ nchange with (match cons T x y with [ nil ⇒ True | cons a b ⇒ False ]);
+ nrewrite > H;
+ nnormalize;
+ napply I.
+nqed.
+
+(* !!! da togliere *)
+nlemma list_destruct_nil_cons : ∀T.∀x:T.∀y:list T.nil T = cons T x y → False.
+ #T; #x; #y; #H;
+ nchange with (match cons T x y with [ nil ⇒ True | cons a b ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply I.
+nqed.
+
+nlemma append_nil : ∀T:Type.∀l:list T.(l@[]) = l.
+ #T; #l;
+ nelim l;
+ nnormalize;
+ ##[ ##1: napply refl_eq
+ ##| ##2: #x; #y; #H;
+          nrewrite > H;
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma associative_list : ∀T.associative (list T) (append T).
+ #T; #x; #y; #z;
+ nelim x;
+ nnormalize;
+ ##[ ##1: napply refl_eq
+ ##| ##2: #a; #b; #H;
+          nrewrite > H;
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma cons_append_commute : ∀T:Type.∀l1,l2:list T.∀a:T.a :: (l1 @ l2) = (a :: l1) @ l2.
+ #T; #l1; #l2; #a;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma append_cons_commute : ∀T:Type.∀a:T.∀l,l1:list T.l @ (a::l1) = (l@[a]) @ l1.
+ #T; #a; #l; #l1;
+ nrewrite > (associative_list T l [a] l1);
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+(* ************** *)
+(* NON-EMPTY LIST *)
+(* ************** *)
+
+nlemma nelist_destruct_nil_nil : ∀T.∀x1,x2:T.ne_nil T x1 = ne_nil T x2 → x1 = x2.
+ #T; #x1; #x2; #H;
+ nchange with (match ne_nil T x2 with [ ne_cons _ _ ⇒ False | ne_nil a ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma nelist_destruct_cons_cons_1 : ∀T.∀x1,x2:T.∀y1,y2:ne_list T.ne_cons T x1 y1 = ne_cons T x2 y2 → x1 = x2.
+ #T; #x1; #x2; #y1; #y2; #H;
+ nchange with (match ne_cons T x2 y2 with [ ne_nil _ ⇒ False | ne_cons a _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma nelist_destruct_cons_cons_2 : ∀T.∀x1,x2:T.∀y1,y2:ne_list T.ne_cons T x1 y1 = ne_cons T x2 y2 → y1 = y2.
+ #T; #x1; #x2; #y1; #y2; #H;
+ nchange with (match ne_cons T x2 y2 with [ ne_nil _ ⇒ False | ne_cons _ b ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+(* !!! da togliere *)
+nlemma nelist_destruct_cons_nil : ∀T.∀x1,x2:T.∀y1:ne_list T.ne_cons T x1 y1 = ne_nil T x2 → False.
+ #T; #x1; #x2; #y1; #H;
+ nchange with (match ne_cons T x1 y1 with [ ne_nil _ ⇒ True | ne_cons a b ⇒ False ]);
+ nrewrite > H;
+ nnormalize;
+ napply I.
+nqed.
+
+(* !!! da togliere *)
+nlemma nelist_destruct_nil_cons : ∀T.∀x1,x2:T.∀y2:ne_list T.ne_nil T x1 = ne_cons T x2 y2 → False.
+ #T; #x1; #x2; #y2; #H;
+ nchange with (match ne_cons T x2 y2 with [ ne_nil _ ⇒ True | ne_cons a b ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply I.
+nqed.
+
+nlemma associative_nelist : ∀T.associative (ne_list T) (ne_append T).
+ #T; #x; #y; #z;
+ nelim x;
+ nnormalize;
+ ##[ ##1: #hh; napply refl_eq
+ ##| ##2: #hh; #tt; #H;
+          nrewrite > H;
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma necons_append_commute : ∀T:Type.∀l1,l2:ne_list T.∀a:T.(a §§ (l1 & l2)) = ((a §§ l1) & l2).
+ #T; #l1; #l2; #a;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma append_necons_commute : ∀T:Type.∀a:T.∀l,l1:ne_list T.(l & (a §§ l1)) = (l & «£a») & l1.
+ #T; #a; #l; #l1;
+ nrewrite > (associative_nelist T l «£a» l1);
+ nnormalize;
+ napply refl_eq.
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/common/list_utility.ma b/helm/software/matita/contribs/ng_assembly/common/list_utility.ma
new file mode 100755 (executable)
index 0000000..154d85d
--- /dev/null
@@ -0,0 +1,348 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/list.ma".
+include "common/option.ma".
+include "common/nat_lemmas.ma".
+
+(* *************** *)
+(* LISTE GENERICHE *)
+(* *************** *)
+
+(* listlen *)
+nlet rec len_list (T:Type) (l:list T) on l ≝
+ match l with [ nil ⇒ O | cons _ t ⇒ S (len_list T t) ].
+
+(* vuota? *)
+ndefinition is_empty_list ≝
+λT:Type.λl:list T.match l with [ nil ⇒ True | cons _ _ ⇒ False ].
+
+ndefinition isb_empty_list ≝
+λT:Type.λl:list T.match l with [ nil ⇒ true | cons _ _ ⇒ false ].
+
+ndefinition isnot_empty_list ≝
+λT:Type.λl:list T.match l with [ nil ⇒ False | cons _ _ ⇒ True ].
+
+ndefinition isnotb_empty_list ≝
+λT:Type.λl:list T.match l with [ nil ⇒ false | cons _ _ ⇒ true ].
+
+(* reverse *)
+nlet rec reverse_list (T:Type) (l:list T) on l ≝
+ match l with
+  [ nil ⇒ nil T
+  | cons h t ⇒ (reverse_list T t)@[h]
+  ].
+
+(* getFirst *)
+ndefinition get_first_list ≝
+λT:Type.λl:list T.match l with
+ [ nil ⇒ None ?
+ | cons h _ ⇒ Some ? h ].
+
+(* getLast *)
+ndefinition get_last_list ≝
+λT:Type.λl:list T.match reverse_list T l with
+ [ nil ⇒ None ?
+ | cons h _ ⇒ Some ? h ].
+
+(* cutFirst *)
+ndefinition cut_first_list ≝
+λT:Type.λl:list T.match l with
+ [ nil ⇒ nil T
+ | cons _ t ⇒ t ].
+
+(* cutLast *)
+ndefinition cut_last_list ≝
+λT:Type.λl:list T.match reverse_list T l with
+ [ nil ⇒ nil T
+ | cons _ t ⇒ reverse_list T t ].
+
+(* apply f *)
+nlet rec apply_f_list (T1,T2:Type) (l:list T1) (f:T1 → T2) on l ≝
+match l with
+ [ nil ⇒ nil T2
+ | cons h t ⇒ cons T2 (f h) (apply_f_list T1 T2 t f) ].
+
+(* fold right *)
+nlet rec fold_right_list (T1,T2:Type) (f:T1 → T2 → T2) (acc:T2) (l:list T1) on l ≝
+  match l with
+   [ nil ⇒ acc
+   | cons h t ⇒ f h (fold_right_list T1 T2 f acc t)
+   ].
+
+(* double fold right *)
+nlemma fold_right_list2_aux1 :
+∀T.∀h,t.len_list T [] = len_list T (h::t) → False.
+ #T; #h; #t;
+ nnormalize;
+ #H;
+ ndestruct (*napply (nat_destruct_0_S ? H)*).
+nqed.
+
+nlemma fold_right_list2_aux2 :
+∀T.∀h,t.len_list T (h::t) = len_list T [] → False.
+ #T; #h; #t;
+ nnormalize;
+ #H;
+ ndestruct (*napply (nat_destruct_S_0 ? H)*).
+nqed.
+
+nlemma fold_right_list2_aux3 :
+∀T.∀h,h',t,t'.len_list T (h::t) = len_list T (h'::t') → len_list T t = len_list T t'.
+ #T; #h; #h'; #t; #t';
+ nelim t;
+ nelim t';
+ ##[ ##1: nnormalize; #H; napply refl_eq
+ ##| ##2: #a; #l'; #H; #H1;
+          nchange in H1:(%) with ((S O) = (S (S (len_list T l'))));
+          ndestruct (*nelim (nat_destruct_0_S ? (nat_destruct_S_S … H1))*)
+ ##| ##3: #a; #l'; #H; #H1;
+          nchange in H1:(%) with ((S (S (len_list T l'))) = (S O));
+          ndestruct (*nelim (nat_destruct_S_0 ? (nat_destruct_S_S … H1))*)
+ ##| ##4: #a; #l; #H; #a1; #l1; #H1; #H2;
+          nchange in H2:(%) with ((S (S (len_list T l1))) = (S (S (len_list T l))));
+          nchange with ((S (len_list T l1)) = (S (len_list T l)));
+          nrewrite > (nat_destruct_S_S … H2);
+          napply refl_eq
+ ##]
+nqed.
+
+nlet rec fold_right_list2 (T1,T2:Type) (f:T1 → T1 → T2 → T2) (acc:T2) (l1:list T1) on l1 ≝
+ match l1
+  return λl1.Πl2.len_list T1 l1 = len_list T1 l2 → T2
+ with
+  [ nil ⇒ λl2.match l2 return λl2.len_list T1 [] = len_list T1 l2 → T2 with
+   [ nil ⇒ λp:len_list T1 [] = len_list T1 [].acc
+   | cons h t ⇒ λp:len_list T1 [] = len_list T1 (h::t).
+    False_rect_Type0 ? (fold_right_list2_aux1 T1 h t p)
+   ]
+  | cons h t ⇒ λl2.match l2 return λl2.len_list T1 (h::t) = len_list T1 l2 → T2 with
+   [ nil ⇒ λp:len_list T1 (h::t) = len_list T1 [].
+    False_rect_Type0 ? (fold_right_list2_aux2 T1 h t p)
+   | cons h' t' ⇒ λp:len_list T1 (h::t) = len_list T1 (h'::t').
+    f h h' (fold_right_list2 T1 T2 f acc t t' (fold_right_list2_aux3 T1 h h' t t' p))
+   ]
+  ].
+
+nlet rec bfold_right_list2 (T1:Type) (f:T1 → T1 → bool) (l1,l2:list T1) on l1 ≝
+ match l1 with
+  [ nil ⇒ match l2 with
+   [ nil ⇒ true | cons h t ⇒ false ]
+  | cons h t ⇒ match l2 with
+   [ nil ⇒ false | cons h' t' ⇒ (f h h') ⊗ (bfold_right_list2 T1 f t t')
+   ]
+  ].
+
+(* nth elem *)
+nlet rec nth_list (T:Type) (l:list T) (n:nat) on l ≝
+ match l with
+  [ nil ⇒ None ?
+  | cons h t ⇒ match n with
+   [ O ⇒ Some ? h | S n' ⇒ nth_list T t n' ]
+  ].
+
+(* abs elem *)
+ndefinition abs_list_aux1 : ∀T:Type.∀n.((len_list T []) > n) = true → False.
+ #T; nnormalize; #n; #H; ndestruct (*napply (bool_destruct … H)*). nqed.
+
+ndefinition abs_list_aux2 : ∀T:Type.∀h:T.∀t:list T.∀n.((len_list T (h::t)) > (S n) = true) → ((len_list T t) > n) = true.
+ #T; #h; #t; #n; nnormalize; #H; napply H. nqed.
+
+nlet rec abs_list (T:Type) (l:list T) on l ≝
+ match l
+  return λl.Πn.(((len_list T l) > n) = true) → T
+ with
+  [ nil ⇒ λn.λp:(((len_list T []) > n) = true).False_rect_Type0 ? (abs_list_aux1 T n p)
+  | cons h t ⇒ λn.
+   match n with
+    [ O ⇒ λp:(((len_list T (h::t)) > O) = true).h
+    | S n' ⇒ λp:(((len_list T (h::t)) > (S n')) = true).
+     abs_list T t n' (abs_list_aux2 T h t n' p)
+    ]
+  ].
+
+(* esempio: abs_list ? [ 1; 2; 3; 4 ] 2 (refl_eq …) = 0. *)
+
+(* ************** *)
+(* NON-EMPTY LIST *)
+(* ************** *)
+
+(* listlen *)
+nlet rec len_neList (T:Type) (nl:ne_list T) on nl ≝
+ match nl with [ ne_nil _ ⇒ (S O) | ne_cons _ t ⇒ S (len_neList T t) ].
+
+(* reverse *)
+nlet rec reverse_neList (T:Type) (nl:ne_list T) on nl ≝
+ match nl with
+  [ ne_nil h ⇒ ne_nil T h
+  | ne_cons h t ⇒ (reverse_neList T t)&(ne_nil T h)
+  ].
+
+(* getFirst *)
+ndefinition get_first_neList ≝
+λT:Type.λnl:ne_list T.match nl with
+ [ ne_nil h ⇒ h
+ | ne_cons h _ ⇒ h ].
+
+(* getLast *)
+ndefinition get_last_neList ≝
+λT:Type.λnl:ne_list T.match reverse_neList T nl with
+ [ ne_nil h ⇒ h
+ | ne_cons h _ ⇒ h ].
+
+(* cutFirst *)
+ndefinition cut_first_neList ≝
+λT:Type.λnl:ne_list T.match nl with
+ [ ne_nil h ⇒ ne_nil T h
+ | ne_cons _ t ⇒ t ].
+
+(* cutLast *)
+ndefinition cut_last_neList ≝
+λT:Type.λnl:ne_list T.match reverse_neList T nl with
+ [ ne_nil h ⇒ ne_nil T h
+ | ne_cons _ t ⇒ reverse_neList T t ].
+
+(* apply f *)
+nlet rec apply_f_neList (T1,T2:Type) (nl:ne_list T1) (f:T1 → T2) on nl ≝
+match nl with
+ [ ne_nil h ⇒ ne_nil T2 (f h)
+ | ne_cons h t ⇒ ne_cons T2 (f h) (apply_f_neList T1 T2 t f) ].
+
+(* fold right *)
+nlet rec fold_right_neList (T1,T2:Type) (f:T1 → T2 → T2) (acc:T2) (nl:ne_list T1) on nl ≝
+  match nl with
+   [ ne_nil h ⇒ f h acc
+   | ne_cons h t ⇒ f h (fold_right_neList T1 T2 f acc t)
+   ].
+
+(* double fold right *)
+nlemma fold_right_neList2_aux1 :
+∀T.∀h,h',t'.len_neList T «£h» = len_neList T (h'§§t') → False.
+ #T; #h; #h'; #t';
+ nnormalize;
+ ncases t';
+ nnormalize;
+ ##[ ##1: #x; #H; ndestruct (*nelim (nat_destruct_0_S ? (nat_destruct_S_S … H))*)
+ ##| ##2: #x; #l; #H; ndestruct (*nelim (nat_destruct_0_S ? (nat_destruct_S_S … H))*)
+ ##]
+nqed.
+
+nlemma fold_right_neList2_aux2 :
+∀T.∀h,h',t.len_neList T (h§§t) = len_neList T «£h'» → False.
+ #T; #h; #h'; #t;
+ nnormalize;
+ ncases t;
+ nnormalize;
+ ##[ ##1: #x; #H; ndestruct (*nelim (nat_destruct_S_0 ? (nat_destruct_S_S … H))*)
+ ##| ##2: #x; #l; #H; ndestruct (*nelim (nat_destruct_S_0 ? (nat_destruct_S_S … H))*)
+ ##]
+nqed.
+
+nlemma fold_right_neList2_aux3 :
+∀T.∀h,h',t,t'.len_neList T (h§§t) = len_neList T (h'§§t') → len_neList T t = len_neList T t'.
+ #T; #h; #h'; #t; #t';
+ nelim t;
+ nelim t';
+ ##[ ##1: nnormalize; #x; #y; #H; napply refl_eq
+ ##| ##2: #a; #l'; #H; #x; #H1;
+          nchange in H1:(%) with ((S (len_neList T «£x»)) = (S (len_neList T (a§§l'))));
+          nrewrite > (nat_destruct_S_S … H1);
+          napply refl_eq
+ ##| ##3: #x; #a; #l'; #H; #H1;
+          nchange in H1:(%) with ((S (len_neList T (a§§l')))= (S (len_neList T «£x»)));
+          nrewrite > (nat_destruct_S_S … H1);
+          napply refl_eq
+ ##| ##4: #a; #l; #H; #a1; #l1; #H1; #H2;
+          nchange in H2:(%) with ((S (len_neList T (a1§§l1))) = (S (len_neList T (a§§l))));
+          nrewrite > (nat_destruct_S_S … H2);
+          napply refl_eq
+ ##]
+nqed.
+
+nlet rec fold_right_neList2 (T1,T2:Type) (f:T1 → T1 → T2 → T2) (acc:T2) (l1:ne_list T1) on l1 ≝
+ match l1
+  return λl1.Πl2.len_neList T1 l1 = len_neList T1 l2 → T2
+ with
+  [ ne_nil h ⇒ λl2.match l2 return λl2.len_neList T1 «£h» = len_neList T1 l2 → T2 with
+   [ ne_nil h' ⇒ λp:len_neList T1 «£h» = len_neList T1 «£h'».
+    f h h' acc
+   | ne_cons h' t' ⇒ λp:len_neList T1 «£h» = len_neList T1 (h'§§t').
+    False_rect_Type0 ? (fold_right_neList2_aux1 T1 h h' t' p)
+   ]
+  | ne_cons h t ⇒ λl2.match l2 return λl2.len_neList T1 (h§§t) = len_neList T1 l2 → T2 with
+   [ ne_nil h' ⇒ λp:len_neList T1 (h§§t) = len_neList T1 «£h'».
+    False_rect_Type0 ? (fold_right_neList2_aux2 T1 h h' t p)
+   | ne_cons h' t' ⇒ λp:len_neList T1 (h§§t) = len_neList T1 (h'§§t').
+    f h h' (fold_right_neList2 T1 T2 f acc t t' (fold_right_neList2_aux3 T1 h h' t t' p))
+   ]
+  ].
+
+nlet rec bfold_right_neList2 (T1:Type) (f:T1 → T1 → bool) (l1,l2:ne_list T1) on l1 ≝
+ match l1 with
+  [ ne_nil h ⇒ match l2 with
+   [ ne_nil h' ⇒ f h h' | ne_cons h' t' ⇒ false ]
+  | ne_cons h t ⇒ match l2 with
+   [ ne_nil h' ⇒ false | ne_cons h' t' ⇒ (f h h') ⊗ (bfold_right_neList2 T1 f t t')
+   ]
+  ].
+
+(* nth elem *)
+nlet rec nth_neList (T:Type) (nl:ne_list T) (n:nat) on nl ≝
+ match nl with
+  [ ne_nil h ⇒ match n with
+   [ O ⇒ Some ? h | S _ ⇒ None ? ]
+  | ne_cons h t ⇒ match n with
+   [ O ⇒ Some ? h | S n' ⇒ nth_neList T t n' ]
+  ].
+
+(* abs elem *)
+ndefinition abs_neList_aux1 : ∀T:Type.∀h:T.∀n.((len_neList T («£h»)) > (S n)) = true → False.
+ #T; #h; #n; nnormalize; #H; ndestruct (*napply (bool_destruct … H)*). nqed.
+
+ndefinition abs_neList_aux2 : ∀T:Type.∀h:T.∀t:ne_list T.∀n.((len_neList T (h§§t)) > (S n) = true) → ((len_neList T t) > n) = true.
+ #T; #h; #t; #n; nnormalize; #H; napply H. nqed.
+
+nlet rec abs_neList (T:Type) (l:ne_list T) on l ≝
+ match l
+  return λl.Πn.(((len_neList T l) > n) = true) → T
+ with
+  [ ne_nil h ⇒ λn.
+   match n
+    return λn.(((len_neList T (ne_nil T h)) > n) = true) → T
+   with
+    [ O ⇒ λp:(((len_neList T (ne_nil T h)) > O) = true).h
+    | S n' ⇒ λp:(((len_neList T (ne_nil T h)) > (S n')) = true).
+     False_rect_Type0 ? (abs_neList_aux1 T h n' p)
+    ]
+  | ne_cons h t ⇒ λn.
+   match n with
+    [ O ⇒ λp:(((len_neList T (ne_cons T h t)) > O) = true).h
+    | S n' ⇒ λp:(((len_neList T (ne_cons T h t)) > (S n')) = true).
+     abs_neList T t n' (abs_neList_aux2 T h t n' p)
+    ]
+  ].
+
+(* esempio: abs_neList ? « 1; 2; 3 £ 4 » 0 (refl_eq …) = 0. *)
+
+(* conversione *)
+nlet rec neList_to_list (T:Type) (nl:ne_list T) on nl : list T ≝
+ match nl with [ ne_nil h ⇒ [h] | ne_cons h t ⇒ [h]@(neList_to_list T t) ].
diff --git a/helm/software/matita/contribs/ng_assembly/common/list_utility_lemmas.ma b/helm/software/matita/contribs/ng_assembly/common/list_utility_lemmas.ma
new file mode 100755 (executable)
index 0000000..971b106
--- /dev/null
@@ -0,0 +1,585 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/list_utility.ma".
+include "common/list_lemmas.ma".
+
+(* *************** *)
+(* LISTE GENERICHE *)
+(* *************** *)
+
+nlemma symmetric_lenlist : ∀T.∀l1,l2:list T.len_list T l1 = len_list T l2 → len_list T l2 = len_list T l1.
+ #T; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2; nnormalize;
+          ##[ ##1: #H; napply refl_eq
+          ##| ##2: #h; #t; #H; ndestruct (*nelim (nat_destruct_0_S ? H)*)
+          ##]
+ ##| ##2: #h; #l2; ncases l2; nnormalize;
+          ##[ ##1: #H; #l; #H1; nrewrite < H1; napply refl_eq
+          ##| ##2: #h; #l; #H; #l3; #H1; nrewrite < H1; napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma symmetric_foldrightlist2_aux
+ : ∀T1,T2:Type.∀f:T1 → T1 → T2 → T2.∀acc:T2.∀l1,l2:list T1.
+   ∀H1:len_list T1 l1 = len_list T1 l2.∀H2:len_list T1 l2 = len_list T1 l1.
+  (∀x,y,z.f x y z = f y x z) →
+  fold_right_list2 T1 T2 f acc l1 l2 H1 = fold_right_list2 T1 T2 f acc l2 l1 H2.
+ #T1; #T2; #f; #acc; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: nnormalize; #H1; #H2; #H3; napply refl_eq
+          ##| ##2: #h; #l; #H1; #H2; #H3;
+                   nchange in H1:(%) with (O = (S (len_list ? l)));
+                   ndestruct (*nelim (nat_destruct_0_S ? H1)*)
+          ##]
+ ##| ##2: #h3; #l3; #H; #l2; ncases l2;
+          ##[ ##1: #H1; #H2; #H3; nchange in H1:(%) with ((S (len_list ? l3)) = O);
+                   ndestruct (*nelim (nat_destruct_S_0 ? H1)*)
+          ##| ##2: #h4; #l4; #H1; #H2; #H3;
+                   nchange in H1:(%) with ((S (len_list ? l3)) = (S (len_list ? l4)));
+                   nchange in H2:(%) with ((S (len_list ? l4)) = (S (len_list ? l3)));
+                   nchange with ((f h3 h4 (fold_right_list2 T1 T2 f acc l3 l4 (fold_right_list2_aux3 T1 h3 h4 l3 l4 ?))) =
+                                 (f h4 h3 (fold_right_list2 T1 T2 f acc l4 l3 (fold_right_list2_aux3 T1 h4 h3 l4 l3 ?))));
+                   nrewrite < (H l4 (fold_right_list2_aux3 T1 h3 h4 l3 l4 H1) (fold_right_list2_aux3 T1 h4 h3 l4 l3 H2) H3);
+                   nrewrite > (H3 h3 h4 (fold_right_list2 T1 T2 f acc l3 l4 ?));
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma symmetric_foldrightlist2
+ : ∀T1,T2:Type.∀f:T1 → T1 → T2 → T2.∀acc:T2.∀l1,l2:list T1.∀H:len_list T1 l1 = len_list T1 l2.
+  (∀x,y,z.f x y z = f y x z) →
+  fold_right_list2 T1 T2 f acc l1 l2 H = fold_right_list2 T1 T2 f acc l2 l1 (symmetric_lenlist T1 l1 l2 H).
+ #T1; #T2; #f; #acc; #l1; #l2; #H; #H1;
+ nrewrite > (symmetric_foldrightlist2_aux T1 T2 f acc l1 l2 H (symmetric_lenlist T1 l1 l2 H) H1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_bfoldrightlist2
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:list T1.
+  (∀x,y.f x y = f y x) →
+  bfold_right_list2 T1 f l1 l2 = bfold_right_list2 T1 f l2 l1.
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: #H; nnormalize; napply refl_eq
+          ##| ##2: #hh2; #ll2; #H; nnormalize; napply refl_eq
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #H1; nnormalize; napply refl_eq
+          ##| ##2: #hh2; #ll2; #H1; nnormalize;
+                   nrewrite > (H ll2 H1);
+                   nrewrite > (H1 hh1 hh2);
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma bfoldrightlist2_to_eq
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:list T1.
+   (∀x,y.(f x y = true → x = y)) →
+   (bfold_right_list2 T1 f l1 l2 = true → l1 = l2).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: #H; #H1; napply refl_eq
+          ##| ##2: #hh2; #ll2; #H; nnormalize; #H1;
+                   ndestruct (*napply (bool_destruct … H1)*)
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #H1; nnormalize; #H2;
+                   ndestruct (*napply (bool_destruct … H2)*)
+          ##| ##2: #hh2; #ll2; #H1; #H2;
+                   nchange in H2:(%) with (((f hh1 hh2)⊗(bfold_right_list2 T f ll1 ll2)) = true);
+                   nrewrite > (H1 hh1 hh2 (andb_true_true_l … H2));
+                   nrewrite > (H ll2 H1 (andb_true_true_r … H2));
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma eq_to_bfoldrightlist2
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:list T1.
+   (∀x,y.(x = y → f x y = true)) →
+   (l1 = l2 → bfold_right_list2 T1 f l1 l2 = true).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: #H; #H1; nnormalize; napply refl_eq
+          ##| ##2: #hh2; #ll2; #H; #H1;
+                   (* !!! ndestruct: assert false *)
+                   nelim (list_destruct_nil_cons ??? H1)
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #H1; #H2;
+                   (* !!! ndestruct: assert false *)
+                   nelim (list_destruct_cons_nil ??? H2)
+          ##| ##2: #hh2; #ll2; #H1; #H2; nnormalize;
+                   nrewrite > (list_destruct_1 … H2);
+                   nrewrite > (H1 hh2 hh2 (refl_eq …));
+                   nnormalize;
+                   nrewrite > (H ll2 H1 (list_destruct_2 … H2));
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma bfoldrightlist2_to_lenlist
+ : ∀T.∀f:T → T → bool.∀l1,l2:list T.bfold_right_list2 T f l1 l2 = true → len_list T l1 = len_list T l2.
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: nnormalize; #H; napply refl_eq
+          ##| ##2: nnormalize; #hh; #tt; #H;
+                   ndestruct (*napply (bool_destruct … H)*)
+          ##]
+ ##| ##2: #hh; #tt; #H; #l2; ncases l2;
+          ##[ ##1: nnormalize; #H1;
+                   ndestruct (*napply (bool_destruct … H1)*)
+          ##| ##2: #hh1; #tt1; #H1; nnormalize;
+                   nrewrite > (H tt1 ?);
+                   ##[ ##1: napply refl_eq
+                   ##| ##2: nchange in H1:(%) with ((? ⊗ (bfold_right_list2 T f tt tt1)) = true);
+                            napply (andb_true_true_r … H1)
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma decidable_list : ∀T.∀H:(Πx,y:T.decidable (x = y)).∀x,y:list T.decidable (x = y).
+ #T; #H; #x; nelim x;
+ ##[ ##1: #y; ncases y;
+          ##[ ##1: nnormalize; napply (or2_intro1 (? = ?) (? ≠ ?) (refl_eq …))
+          ##| ##2: #hh2; #tt2; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H1;
+                   (* !!! ndestruct: assert false *)
+                   napply (list_destruct_nil_cons T … H1)
+          ##]
+ ##| ##2: #hh1; #tt1; #H1; #y; ncases y;
+          ##[ ##1: nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (list_destruct_cons_nil T … H2)
+          ##| ##2: #hh2; #tt2; nnormalize; napply (or2_elim (hh1 = hh2) (hh1 ≠ hh2) ? (H …));
+                   ##[ ##2: #H2; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                            nnormalize; #H3; napply (H2 (list_destruct_1 T … H3))
+                   ##| ##1: #H2; napply (or2_elim (tt1 = tt2) (tt1 ≠ tt2) ? (H1 tt2));
+                            ##[ ##2: #H3; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                                     nnormalize; #H4; napply (H3 (list_destruct_2 T … H4))
+                            ##| ##1: #H3; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
+                                     nrewrite > H2; nrewrite > H3; napply refl_eq
+                            ##]
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma nbfoldrightlist2_to_neq
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:list T1.
+   (∀x,y.(f x y = false → x ≠ y)) →
+   (bfold_right_list2 T1 f l1 l2 = false → l1 ≠ l2).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: #H; nnormalize; #H1;
+                   ndestruct (*napply (bool_destruct … H1)*)
+          ##| ##2: #hh2; #ll2; #H; #H1; nnormalize; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (list_destruct_nil_cons T … H2)
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #H1; #H2; nnormalize; #H3;
+                   (* !!! ndestruct: assert false *)
+                   napply (list_destruct_cons_nil T … H3)
+          ##| ##2: #hh2; #ll2; #H1; #H2; nnormalize; #H3;
+                   nchange in H2:(%) with (((f hh1 hh2)⊗(bfold_right_list2 T f ll1 ll2)) = false);
+                   napply (H ll2 H1 ? (list_destruct_2 T … H3));
+                   napply (or2_elim ??? (andb_false2 … H2) );
+                   ##[ ##1: #H4; napply (absurd (hh1 = hh2) …);
+                            ##[ ##1: nrewrite > (list_destruct_1 T … H3); napply refl_eq
+                            ##| ##2: napply (H1 … H4)
+                            ##]
+                   ##| ##2: #H4; napply H4
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma list_destruct
+ : ∀T.∀H:(Πx,y:T.decidable (x = y)).∀h1,h2:T.∀l1,l2:list T.(h1::l1) ≠ (h2::l2) → h1 ≠ h2 ∨ l1 ≠ l2.
+ #T; #H; #h1; #h2; #l1; nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: #H1; napply (or2_intro1 (h1 ≠ h2) ([] ≠ []) …);
+                   nnormalize; #H2; nrewrite > H2 in H1:(%);
+                   nnormalize; #H1; napply (H1 (refl_eq …))
+          ##| ##2: #hh2; #ll2; #H1; napply (or2_intro2 (h1 ≠ h2) ([] ≠ (hh2::ll2)) …);
+                   nnormalize; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (list_destruct_nil_cons T … H2)
+          ##]
+ ##| ##2: #hh1; #ll1; #H1; #l2; ncases l2;
+          ##[ ##1: #H2; napply (or2_intro2 (h1 ≠ h2) ((hh1::ll1) ≠ []) …);
+                   nnormalize; #H3;
+                   (* !!! ndestruct: assert false *)
+                   napply (list_destruct_cons_nil T … H3)
+          ##| ##2: #hh2; #ll2; #H2;     
+                   napply (or2_elim (h1 = h2) (h1 ≠ h2) ? (H h1 h2) …);
+                   ##[ ##2: #H3; napply (or2_intro1 (h1 ≠ h2) ((hh1::ll1) ≠ (hh2::ll2)) H3)
+                   ##| ##1: #H3; napply (or2_intro2 (h1 ≠ h2) ((hh1::ll1) ≠ (hh2::ll2) …));
+                            nrewrite > H3 in H2:(%); #H2;
+                            nnormalize; #H4; nrewrite > (list_destruct_1 T … H4) in H2:(%); #H2;
+                            nrewrite > (list_destruct_2 T … H4) in H2:(%); #H2;
+                            napply (H2 (refl_eq …))
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_nbfoldrightlist2
+ : ∀T:Type.∀f:T → T → bool.∀l1,l2:list T.
+   (∀x,y:T.decidable (x = y)) →
+   (∀x,y.(x ≠ y → f x y = false)) →
+   (l1 ≠ l2 → bfold_right_list2 T f l1 l2 = false).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #l2; ncases l2;
+          ##[ ##1: #H; #H1; nnormalize; #H2; nelim (H2 (refl_eq …))
+          ##| ##2: #hh2; #ll2; #H; nnormalize; #H1; #H2; napply refl_eq
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #H1; #H2; nnormalize; #H3; napply refl_eq
+          ##| ##2: #hh2; #ll2; #H1; #H2; #H3;
+                   nchange with (((f hh1 hh2)⊗(bfold_right_list2 T f ll1 ll2)) = false);
+                   napply (or2_elim (hh1 ≠ hh2) (ll1 ≠ ll2) ? (list_destruct T H1 … H3) …);
+                   ##[ ##1: #H4; nrewrite > (H2 hh1 hh2 H4); nnormalize; napply refl_eq
+                   ##| ##2: #H4; nrewrite > (H ll2 H1 H2 H4);
+                            nrewrite > (symmetric_andbool (f hh1 hh2) false);
+                            nnormalize; napply refl_eq
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma isbemptylist_to_isemptylist : ∀T,l.isb_empty_list T l = true → is_empty_list T l.
+ #T; #l;
+ ncases l;
+ nnormalize;
+ ##[ ##1: #H; napply I
+ ##| ##2: #x; #l; #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma isnotbemptylist_to_isnotemptylist : ∀T,l.isnotb_empty_list T l = true → isnot_empty_list T l.
+ #T; #l;
+ ncases l;
+ nnormalize;
+ ##[ ##1: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##2: #x; #l; #H; napply I
+ ##]
+nqed.
+
+(* ************** *)
+(* NON-EMPTY LIST *)
+(* ************** *)
+
+nlemma symmetric_lennelist : ∀T.∀l1,l2:ne_list T.len_neList T l1 = len_neList T l2 → len_neList T l2 = len_neList T l1.
+ #T; #l1;
+ nelim l1;
+ ##[ ##1: #h; #l2; ncases l2; nnormalize;
+          ##[ ##1: #H; #H1; napply refl_eq
+          ##| ##2: #h; #t; #H; nrewrite > H; napply refl_eq
+          ##]
+ ##| ##2: #h; #l2; ncases l2; nnormalize;
+          ##[ ##1: #h1; #H; #l; #H1; nrewrite < H1; napply refl_eq
+          ##| ##2: #h; #l; #H; #l3; #H1; nrewrite < H1; napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma symmetric_foldrightnelist2_aux
+ : ∀T1,T2:Type.∀f:T1 → T1 → T2 → T2.∀acc:T2.∀l1,l2:ne_list T1.
+   ∀H1:len_neList T1 l1 = len_neList T1 l2.∀H2:len_neList T1 l2 = len_neList T1 l1.
+  (∀x,y,z.f x y z = f y x z) →
+  fold_right_neList2 T1 T2 f acc l1 l2 H1 = fold_right_neList2 T1 T2 f acc l2 l1 H2.
+ #T1; #T2; #f; #acc; #l1;
+ nelim l1;
+ ##[ ##1: #h; #l2; ncases l2;
+          ##[ ##1: #h1; nnormalize; #H1; #H2; #H3; nrewrite > (H3 h h1 acc); napply refl_eq
+          ##| ##2: #h1; #l; ncases l;
+                   ##[ ##1: #h3; #H1; #H2; #H3;
+                            nchange in H1:(%) with ((S O) = (S (S O)));
+                            (* !!! ndestruct: si inceppa su un'ipotesi che non e' H1 *)
+                            nelim (nat_destruct_0_S ? (nat_destruct_S_S … H1))
+                   ##| ##2: #h3; #l3; #H1; #H2; #H3;
+                            nchange in H1:(%) with ((S O) = (S (S (len_neList ? l3))));
+                            (* !!! ndestruct: si inceppa su un'ipotesi che non e' H1 *)
+                            nelim (nat_destruct_0_S ? (nat_destruct_S_S … H1))
+                   ##]                   
+          ##]
+ ##| ##2: #h3; #l3; #H; #l2; ncases l2;
+          ##[ ##1: #h4; ncases l3;
+                   ##[ ##1: #h5; #H1; #H2; #H3;
+                            nchange in H1:(%) with ((S (S O)) = (S O));
+                            (* !!! ndestruct: si inceppa su un'ipotesi che non e' H1 *)
+                            nelim (nat_destruct_S_0 ? (nat_destruct_S_S … H1))
+                   ##| ##2: #h5; #l5; #H1; #H2; #H3;
+                            nchange in H1:(%) with ((S (S (len_neList ? l5))) = (S O));
+                            (* !!! ndestruct: si inceppa su un'ipotesi che non e' H1 *)
+                            nelim (nat_destruct_S_0 ? (nat_destruct_S_S … H1))
+                   ##]
+          ##| ##2: #h4; #l4; #H1; #H2; #H3;
+                   nchange in H1:(%) with ((S (len_neList ? l3)) = (S (len_neList ? l4)));
+                   nchange in H2:(%) with ((S (len_neList ? l4)) = (S (len_neList ? l3)));
+                   nchange with ((f h3 h4 (fold_right_neList2 T1 T2 f acc l3 l4 (fold_right_neList2_aux3 T1 h3 h4 l3 l4 ?))) =
+                                 (f h4 h3 (fold_right_neList2 T1 T2 f acc l4 l3 (fold_right_neList2_aux3 T1 h4 h3 l4 l3 ?))));
+                   nrewrite < (H l4 (fold_right_neList2_aux3 T1 h3 h4 l3 l4 H1) (fold_right_neList2_aux3 T1 h4 h3 l4 l3 H2) H3);
+                   nrewrite > (H3 h3 h4 (fold_right_neList2 T1 T2 f acc l3 l4 ?));
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma symmetric_foldrightnelist2
+ : ∀T1,T2:Type.∀f:T1 → T1 → T2 → T2.∀acc:T2.∀l1,l2:ne_list T1.∀H:len_neList T1 l1 = len_neList T1 l2.
+  (∀x,y,z.f x y z = f y x z) →
+  fold_right_neList2 T1 T2 f acc l1 l2 H = fold_right_neList2 T1 T2 f acc l2 l1 (symmetric_lennelist T1 l1 l2 H).
+ #T1; #T2; #f; #acc; #l1; #l2; #H; #H1;
+ nrewrite > (symmetric_foldrightnelist2_aux T1 T2 f acc l1 l2 H (symmetric_lennelist T1 l1 l2 H) H1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_bfoldrightnelist2
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:ne_list T1.
+  (∀x,y.f x y = f y x) →
+  bfold_right_neList2 T1 f l1 l2 = bfold_right_neList2 T1 f l2 l1.
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #hh1; #l2; ncases l2;
+          ##[ ##1: #hh2; #H; nnormalize; nrewrite > (H hh1 hh2); napply refl_eq
+          ##| ##2: #hh2; #ll2; #H; nnormalize; napply refl_eq
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #hh2; #H1; nnormalize; napply refl_eq
+          ##| ##2: #hh2; #ll2; #H1; nnormalize;
+                   nrewrite > (H ll2 H1);
+                   nrewrite > (H1 hh1 hh2);
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma bfoldrightnelist2_to_eq
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:ne_list T1.
+   (∀x,y.(f x y = true → x = y)) →
+   (bfold_right_neList2 T1 f l1 l2 = true → l1 = l2).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #hh1; #l2; ncases l2;
+          ##[ ##1: #hh2; #H; #H1; nnormalize in H1:(%); nrewrite > (H hh1 hh2 H1); napply refl_eq
+          ##| ##2: #hh2; #ll2; #H; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #hh2; #H1; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
+          ##| ##2: #hh2; #ll2; #H1; #H2;
+                   nchange in H2:(%) with (((f hh1 hh2)⊗(bfold_right_neList2 T f ll1 ll2)) = true);
+                   nrewrite > (H1 hh1 hh2 (andb_true_true_l … H2));
+                   nrewrite > (H ll2 H1 (andb_true_true_r … H2));
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma eq_to_bfoldrightnelist2
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:ne_list T1.
+   (∀x,y.(x = y → f x y = true)) →
+   (l1 = l2 → bfold_right_neList2 T1 f l1 l2 = true).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #hh1; #l2; ncases l2;
+          ##[ ##1: #hh2; #H; #H1; nnormalize;
+                   nrewrite > (H hh1 hh2 (nelist_destruct_nil_nil … H1));
+                   napply refl_eq
+          ##| ##2: #hh2; #ll2; #H; #H1;
+                   (* !!! ndestruct: assert false *)
+                   nelim (nelist_destruct_nil_cons ???? H1)
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #hh2; #H1; #H2;
+                   (* !!! ndestruct: assert false *)
+                   nelim (nelist_destruct_cons_nil ???? H2)
+          ##| ##2: #hh2; #ll2; #H1; #H2; nnormalize;
+                   nrewrite > (nelist_destruct_cons_cons_1 … H2);
+                   nrewrite > (H1 hh2 hh2 (refl_eq …));
+                   nnormalize;
+                   nrewrite > (H ll2 H1 (nelist_destruct_cons_cons_2 … H2));
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma bfoldrightnelist2_to_lennelist
+ : ∀T.∀f:T → T → bool.∀l1,l2:ne_list T.bfold_right_neList2 T f l1 l2 = true → len_neList T l1 = len_neList T l2.
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #hh1; #l2; ncases l2;
+          ##[ ##1: nnormalize; #hh2; #H; napply refl_eq
+          ##| ##2: nnormalize; #hh2; #tt2; #H; ndestruct (*napply (bool_destruct … H)*)
+          ##]
+ ##| ##2: #hh1; #tt1; #H; #l2; ncases l2;
+          ##[ ##1: nnormalize; #hh2; #H1; ndestruct (*napply (bool_destruct … H1)*)
+          ##| ##2: #hh2; #tt2; #H1; nnormalize;
+                   nrewrite > (H tt2 ?);
+                   ##[ ##1: napply refl_eq
+                   ##| ##2: nchange in H1:(%) with ((? ⊗ (bfold_right_neList2 T f tt1 tt2)) = true);
+                            napply (andb_true_true_r … H1)
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma decidable_nelist : ∀T.∀H:(Πx,y:T.decidable (x = y)).∀x,y:ne_list T.decidable (x = y).
+ #T; #H; #x; nelim x;
+ ##[ ##1: #hh1; #y; ncases y;
+          ##[ ##1: #hh2; nnormalize; napply (or2_elim (hh1 = hh2) (hh1 ≠ hh2) ? (H hh1 hh2));
+                   ##[ ##1: #H1; nrewrite > H1; napply (or2_intro1 (? = ?) (? ≠ ?) (refl_eq …))
+                   ##| ##2: #H1; napply (or2_intro2 (? = ?) (? ≠ ?) ?); nnormalize;
+                            #H2; napply (H1 (nelist_destruct_nil_nil T … H2))
+                   ##]
+          ##| ##2: #hh2; #tt2; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H1;
+                   (* !!! ndestruct: assert false *)
+                   napply (nelist_destruct_nil_cons T … H1)
+          ##]
+ ##| ##2: #hh1; #tt1; #H1; #y; ncases y;
+          ##[ ##1: #hh1; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (nelist_destruct_cons_nil T … H2)
+          ##| ##2: #hh2; #tt2; nnormalize; napply (or2_elim (hh1 = hh2) (hh1 ≠ hh2) ? (H …));
+                   ##[ ##2: #H2; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                            nnormalize; #H3; napply (H2 (nelist_destruct_cons_cons_1 T … H3))
+                   ##| ##1: #H2; napply (or2_elim (tt1 = tt2) (tt1 ≠ tt2) ? (H1 tt2));
+                            ##[ ##2: #H3; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                                     nnormalize; #H4; napply (H3 (nelist_destruct_cons_cons_2 T … H4))
+                            ##| ##1: #H3; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
+                                     nrewrite > H2; nrewrite > H3; napply refl_eq
+                            ##]
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma nbfoldrightnelist2_to_neq
+ : ∀T1:Type.∀f:T1 → T1 → bool.∀l1,l2:ne_list T1.
+   (∀x,y.(f x y = false → x ≠ y)) →
+   (bfold_right_neList2 T1 f l1 l2 = false → l1 ≠ l2).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #hh1; #l2; ncases l2;
+          ##[ ##1: #hh2; #H; nnormalize; #H1; #H2; napply (H hh1 hh2 H1 (nelist_destruct_nil_nil T … H2))
+          ##| ##2: #hh2; #ll2; #H; #H1; nnormalize; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (nelist_destruct_nil_cons T … H2)
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #hh2; #H1; #H2; nnormalize; #H3;
+                   (* !!! ndestruct: assert false *)
+                   napply (nelist_destruct_cons_nil T … H3)
+          ##| ##2: #hh2; #ll2; #H1; #H2; nnormalize; #H3;
+                   nchange in H2:(%) with (((f hh1 hh2)⊗(bfold_right_neList2 T f ll1 ll2)) = false);
+                   napply (H ll2 H1 ? (nelist_destruct_cons_cons_2 T … H3));
+                   napply (or2_elim ??? (andb_false2 … H2) );
+                   ##[ ##1: #H4; napply (absurd (hh1 = hh2) …);
+                            ##[ ##1: nrewrite > (nelist_destruct_cons_cons_1 T … H3); napply refl_eq
+                            ##| ##2: napply (H1 … H4)
+                            ##]
+                   ##| ##2: #H4; napply H4
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma nelist_destruct
+ : ∀T.∀H:(Πx,y:T.decidable (x = y)).∀h1,h2:T.∀l1,l2:ne_list T.(h1§§l1) ≠ (h2§§l2) → h1 ≠ h2 ∨ l1 ≠ l2.
+ #T; #H; #h1; #h2; #l1; nelim l1;
+ ##[ ##1: #hh1; #l2; ncases l2;
+          ##[ ##1: #hh2; #H1; napply (or2_elim (h1 = h2) (h1 ≠ h2) ? (H …) …);
+                   ##[ ##2: #H2; napply (or2_intro1 (h1 ≠ h2) («£hh1» ≠ «£hh2») H2)
+                   ##| ##1: #H2; nrewrite > H2 in H1:(%); #H1;
+                            napply (or2_elim (hh1 = hh2) (hh1 ≠ hh2) ? (H …) …);
+                            ##[ ##2: #H3; napply (or2_intro2 (h2 ≠ h2) («£hh1» ≠ «£hh2») ?);
+                                     nnormalize; #H4; napply (H3 (nelist_destruct_nil_nil T … H4))
+                            ##| ##1: #H3; nrewrite > H3 in H1:(%); #H1; nelim (H1 (refl_eq …))
+                            ##]
+                   ##]
+          ##| ##2: #hh2; #ll2; #H1; napply (or2_intro2 (h1 ≠ h2) («£hh1» ≠ (hh2§§ll2)) …);
+                   nnormalize; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (nelist_destruct_nil_cons T … H2)
+          ##]
+ ##| ##2: #hh1; #ll1; #H1; #l2; ncases l2;
+          ##[ ##1: #hh2; #H2; napply (or2_intro2 (h1 ≠ h2) ((hh1§§ll1) ≠ «£hh2») …);
+                   nnormalize; #H3;
+                   (* !!! ndestruct: assert false *)
+                   napply (nelist_destruct_cons_nil T … H3)
+          ##| ##2: #hh2; #ll2; #H2;     
+                   napply (or2_elim (h1 = h2) (h1 ≠ h2) ? (H h1 h2) …);
+                   ##[ ##2: #H3; napply (or2_intro1 (h1 ≠ h2) ((hh1§§ll1) ≠ (hh2§§ll2)) H3)
+                   ##| ##1: #H3; napply (or2_intro2 (h1 ≠ h2) ((hh1§§ll1) ≠ (hh2§§ll2) …));
+                            nrewrite > H3 in H2:(%); #H2;
+                            nnormalize; #H4; nrewrite > (nelist_destruct_cons_cons_1 T … H4) in H2:(%); #H2;
+                            nrewrite > (nelist_destruct_cons_cons_2 T … H4) in H2:(%); #H2;
+                            napply (H2 (refl_eq …))
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_nbfoldrightnelist2
+ : ∀T:Type.∀f:T → T → bool.∀l1,l2:ne_list T.
+   (∀x,y:T.decidable (x = y)) →
+   (∀x,y.(x ≠ y → f x y = false)) →
+   (l1 ≠ l2 → bfold_right_neList2 T f l1 l2 = false).
+ #T; #f; #l1;
+ nelim l1;
+ ##[ ##1: #hh1; #l2; ncases l2;
+          ##[ ##1: #hh2; #H; #H1; nnormalize; #H2; napply (H1 hh1 hh2 ?);
+                   nnormalize; #H3; nrewrite > H3 in H2:(%); #H2; napply (H2 (refl_eq …))
+          ##| ##2: #hh2; #ll2; #H; nnormalize; #H1; #H2; napply refl_eq
+          ##]
+ ##| ##2: #hh1; #ll1; #H; #l2; ncases l2;
+          ##[ ##1: #hh2; #H1; #H2; nnormalize; #H3; napply refl_eq
+          ##| ##2: #hh2; #ll2; #H1; #H2; #H3;
+                   nchange with (((f hh1 hh2)⊗(bfold_right_neList2 T f ll1 ll2)) = false);
+                   napply (or2_elim (hh1 ≠ hh2) (ll1 ≠ ll2) ? (nelist_destruct T H1 … H3) …);
+                   ##[ ##1: #H4; nrewrite > (H2 hh1 hh2 H4); nnormalize; napply refl_eq
+                   ##| ##2: #H4; nrewrite > (H ll2 H1 H2 H4);
+                            nrewrite > (symmetric_andbool (f hh1 hh2) false);
+                            nnormalize; napply refl_eq
+                   ##]
+          ##]
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/common/nat.ma b/helm/software/matita/contribs/ng_assembly/common/nat.ma
new file mode 100755 (executable)
index 0000000..fe976cb
--- /dev/null
@@ -0,0 +1,219 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ******** *)
+(* NATURALI *)
+(* ******** *)
+
+ninductive nat : Type ≝
+  O : nat
+| S : nat → nat.
+
+(*
+interpretation "Natural numbers" 'N = nat.
+
+default "natural numbers" cic:/matita/common/nat/nat.ind.
+
+alias num (instance 0) = "natural number".
+*)
+
+ndefinition nat1 ≝ S O.
+ndefinition nat2 ≝ S nat1.
+ndefinition nat3 ≝ S nat2.
+ndefinition nat4 ≝ S nat3.
+ndefinition nat5 ≝ S nat4.
+ndefinition nat6 ≝ S nat5.
+ndefinition nat7 ≝ S nat6.
+ndefinition nat8 ≝ S nat7.
+ndefinition nat9 ≝ S nat8.
+ndefinition nat10 ≝ S nat9.
+ndefinition nat11 ≝ S nat10.
+ndefinition nat12 ≝ S nat11.
+ndefinition nat13 ≝ S nat12.
+ndefinition nat14 ≝ S nat13.
+ndefinition nat15 ≝ S nat14.
+ndefinition nat16 ≝ S nat15.
+ndefinition nat17 ≝ S nat16.
+ndefinition nat18 ≝ S nat17.
+ndefinition nat19 ≝ S nat18.
+ndefinition nat20 ≝ S nat19.
+ndefinition nat21 ≝ S nat20.
+ndefinition nat22 ≝ S nat21.
+ndefinition nat23 ≝ S nat22.
+ndefinition nat24 ≝ S nat23.
+ndefinition nat25 ≝ S nat24.
+ndefinition nat26 ≝ S nat25.
+ndefinition nat27 ≝ S nat26.
+ndefinition nat28 ≝ S nat27.
+ndefinition nat29 ≝ S nat28.
+ndefinition nat30 ≝ S nat29.
+ndefinition nat31 ≝ S nat30.
+ndefinition nat32 ≝ S nat31.
+ndefinition nat33 ≝ S nat32.
+ndefinition nat34 ≝ S nat33.
+ndefinition nat35 ≝ S nat34.
+ndefinition nat36 ≝ S nat35.
+ndefinition nat37 ≝ S nat36.
+ndefinition nat38 ≝ S nat37.
+ndefinition nat39 ≝ S nat38.
+ndefinition nat40 ≝ S nat39.
+ndefinition nat41 ≝ S nat40.
+ndefinition nat42 ≝ S nat41.
+ndefinition nat43 ≝ S nat42.
+ndefinition nat44 ≝ S nat43.
+ndefinition nat45 ≝ S nat44.
+ndefinition nat46 ≝ S nat45.
+ndefinition nat47 ≝ S nat46.
+ndefinition nat48 ≝ S nat47.
+ndefinition nat49 ≝ S nat48.
+ndefinition nat50 ≝ S nat49.
+ndefinition nat51 ≝ S nat50.
+ndefinition nat52 ≝ S nat51.
+ndefinition nat53 ≝ S nat52.
+ndefinition nat54 ≝ S nat53.
+ndefinition nat55 ≝ S nat54.
+ndefinition nat56 ≝ S nat55.
+ndefinition nat57 ≝ S nat56.
+ndefinition nat58 ≝ S nat57.
+ndefinition nat59 ≝ S nat58.
+ndefinition nat60 ≝ S nat59.
+ndefinition nat61 ≝ S nat60.
+ndefinition nat62 ≝ S nat61.
+ndefinition nat63 ≝ S nat62.
+ndefinition nat64 ≝ S nat63.
+ndefinition nat65 ≝ S nat64.
+ndefinition nat66 ≝ S nat65.
+ndefinition nat67 ≝ S nat66.
+ndefinition nat68 ≝ S nat67.
+ndefinition nat69 ≝ S nat68.
+ndefinition nat70 ≝ S nat69.
+ndefinition nat71 ≝ S nat70.
+ndefinition nat72 ≝ S nat71.
+ndefinition nat73 ≝ S nat72.
+ndefinition nat74 ≝ S nat73.
+ndefinition nat75 ≝ S nat74.
+ndefinition nat76 ≝ S nat75.
+ndefinition nat77 ≝ S nat76.
+ndefinition nat78 ≝ S nat77.
+ndefinition nat79 ≝ S nat78.
+ndefinition nat80 ≝ S nat79.
+ndefinition nat81 ≝ S nat80.
+ndefinition nat82 ≝ S nat81.
+ndefinition nat83 ≝ S nat82.
+ndefinition nat84 ≝ S nat83.
+ndefinition nat85 ≝ S nat84.
+ndefinition nat86 ≝ S nat85.
+ndefinition nat87 ≝ S nat86.
+ndefinition nat88 ≝ S nat87.
+ndefinition nat89 ≝ S nat88.
+ndefinition nat90 ≝ S nat89.
+ndefinition nat91 ≝ S nat90.
+ndefinition nat92 ≝ S nat91.
+ndefinition nat93 ≝ S nat92.
+ndefinition nat94 ≝ S nat93.
+ndefinition nat95 ≝ S nat94.
+ndefinition nat96 ≝ S nat95.
+ndefinition nat97 ≝ S nat96.
+ndefinition nat98 ≝ S nat97.
+ndefinition nat99 ≝ S nat98.
+ndefinition nat100 ≝ S nat99.
+
+nlet rec eq_nat (n1,n2:nat) on n1 ≝
+ match n1 with
+  [ O ⇒ match n2 with [ O ⇒ true | S _ ⇒ false ]
+  | S n1' ⇒ match n2 with [ O ⇒ false | S n2' ⇒ eq_nat n1' n2' ]
+  ].
+
+nlet rec le_nat n m ≝ 
+ match n with 
+  [ O ⇒ true
+  | (S p) ⇒ match m with 
+   [ O ⇒ false | (S q) ⇒ le_nat p q ]
+  ].
+
+interpretation "natural 'less or equal to'" 'leq x y = (le_nat x y).
+
+ndefinition lt_nat ≝ λn1,n2:nat.(le_nat n1 n2) ⊗ (⊖ (eq_nat n1 n2)).
+
+interpretation "natural 'less than'" 'lt x y = (lt_nat x y).
+
+ndefinition ge_nat ≝ λn1,n2:nat.(⊖ (le_nat n1 n2)) ⊕ (eq_nat n1 n2).
+
+interpretation "natural 'greater or equal to'" 'geq x y = (ge_nat x y).
+
+ndefinition gt_nat ≝ λn1,n2:nat.⊖ (le_nat n1 n2).
+
+interpretation "natural 'greater than'" 'gt x y = (gt_nat x y).
+
+nlet rec plus (n1,n2:nat) on n1 ≝ 
+ match n1 with
+  [ O ⇒ n2
+  | (S n1') ⇒ S (plus n1' n2) ].
+
+interpretation "natural plus" 'plus x y = (plus x y).
+
+nlet rec times (n1,n2:nat) on n1 ≝ 
+ match n1 with 
+  [ O ⇒ O
+  | (S n1') ⇒ n2 + (times n1' n2) ].
+
+interpretation "natural times" 'times x y = (times x y).
+
+nlet rec minus n m ≝ 
+ match n with 
+ [ O ⇒ O
+ | (S p) ⇒ 
+       match m with
+       [O ⇒ (S p)
+  | (S q) ⇒ minus p q ]].
+
+interpretation "natural minus" 'minus x y = (minus x y).
+
+nlet rec div_aux p m n : nat ≝
+match (le_nat m n) with
+[ true ⇒ O
+| false ⇒
+  match p with
+  [ O ⇒ O
+  | (S q) ⇒ S (div_aux q (m-(S n)) n)]].
+
+ndefinition div : nat → nat → nat ≝
+λn,m.match m with 
+ [ O ⇒ S n
+ | (S p) ⇒ div_aux n n p]. 
+
+interpretation "natural divide" 'divide x y = (div x y).
+
+ndefinition pred ≝ λn.match n with [ O ⇒ O | S n ⇒ n ].
+
+ndefinition nat128 ≝ nat64 * nat2.
+ndefinition nat256 ≝ nat128 * nat2.
+ndefinition nat512 ≝ nat256 * nat2.
+ndefinition nat1024 ≝ nat512 * nat2.
+ndefinition nat2048 ≝ nat1024 * nat2.
+ndefinition nat4096 ≝ nat2048 * nat2.
+ndefinition nat8192 ≝ nat4096 * nat2.
+ndefinition nat16384 ≝ nat8192 * nat2.
+ndefinition nat32768 ≝ nat16384 * nat2.
+ndefinition nat65536 ≝ nat32768 * nat2.
diff --git a/helm/software/matita/contribs/ng_assembly/common/nat_lemmas.ma b/helm/software/matita/contribs/ng_assembly/common/nat_lemmas.ma
new file mode 100644 (file)
index 0000000..06ace91
--- /dev/null
@@ -0,0 +1,176 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/nat.ma".
+include "num/bool_lemmas.ma".
+
+(* ******** *)
+(* NATURALI *)
+(* ******** *)
+
+nlemma nat_destruct_S_S : ∀n1,n2:nat.S n1 = S n2 → n1 = n2.
+ #n1; #n2; #H;
+ nchange with (match S n2 with [ O ⇒ False | S a ⇒ n1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+(* !!! da togliere *)
+nlemma nat_destruct_0_S : ∀n:nat.O = S n → False.
+ #n; #H;
+ nchange with (match S n with [ O ⇒ True | S a ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply I.
+nqed.
+
+(* !!! da togliere *)
+nlemma nat_destruct_S_0 : ∀n:nat.S n = O → False.
+ #n; #H;
+ nchange with (match S n with [ O ⇒ True | S a ⇒ False ]);
+ nrewrite > H;
+ nnormalize;
+ napply I.
+nqed.
+
+nlemma eq_to_eqnat : ∀n1,n2:nat.n1 = n2 → eq_nat n1 n2 = true.
+ #n1;
+ nelim n1;
+ ##[ ##1: #n2;
+          nelim n2;
+          nnormalize;
+          ##[ ##1: #H; napply refl_eq
+          ##| ##2: #n3; #H; #H1; ndestruct (*nelim (nat_destruct_0_S ? H1)*)
+          ##]
+ ##| ##2: #n2; #H; #n3; #H1;
+          ncases n3 in H1:(%) ⊢ %;
+          nnormalize;
+          ##[ ##1: #H1; ndestruct (*nelim (nat_destruct_S_0 ? H1)*)
+          ##| ##2: #n4; #H1;
+                   napply (H n4 (nat_destruct_S_S … H1))
+          ##]
+ ##]
+nqed.
+
+nlemma neqnat_to_neq : ∀n1,n2:nat.(eq_nat n1 n2 = false → n1 ≠ n2).
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_nat n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqnat n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqnat_to_eq : ∀n1,n2:nat.(eq_nat n1 n2 = true → n1 = n2).
+ #n1;
+ nelim n1;
+ ##[ ##1: #n2;
+          nelim n2;
+          nnormalize;
+          ##[ ##1: #H; napply refl_eq
+          ##| ##2: #n3; #H; #H1; ndestruct (*napply (bool_destruct … (O = S n3) H1)*)
+          ##]
+ ##| ##2: #n2; #H; #n3; #H1;
+          ncases n3 in H1:(%) ⊢ %;
+          nnormalize;
+          ##[ ##1: #H1; ndestruct (*napply (bool_destruct … (S n2 = O) H1)*)
+          ##| ##2: #n4; #H1;
+                   nrewrite > (H n4 H1);
+                   napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqnat : ∀n1,n2:nat.n1 ≠ n2 → eq_nat n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_nat n1 n2));
+ napply (not_to_not (eq_nat n1 n2 = true) (n1 = n2) ? H);
+ napply (eqnat_to_eq n1 n2).
+nqed.
+
+nlemma decidable_nat : ∀x,y:nat.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_nat x y = true) (eq_nat x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqnat_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqnat_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqnat : symmetricT nat bool eq_nat.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_nat n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqnat n1 n2 H);
+          napply (symmetric_eq ? (eq_nat n2 n1) false);
+          napply (neq_to_neqnat n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
+
+nlemma Sn_p_n_to_S_npn : ∀n1,n2.(S n1) + n2 = S (n1 + n2).
+ #n1;
+ nelim n1;
+ ##[ ##1: nnormalize; #n2; napply refl_eq
+ ##| ##2: #n; #H; #n2; nrewrite > (H n2);
+          ncases n in H:(%) ⊢ %;
+          ##[ ##1: nnormalize; #H; napply refl_eq
+          ##| ##2: #n3; nnormalize; #H; napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma n_p_Sn_to_S_npn : ∀n1,n2.n1 + (S n2) = S (n1 + n2).
+ #n1;
+ nelim n1;
+ ##[ ##1: nnormalize; #n2; napply refl_eq
+ ##| ##2: #n; #H; #n2;
+          nrewrite > (Sn_p_n_to_S_npn n (S n2));
+          nrewrite > (H n2);
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma Opn_to_n : ∀n.O + n = n.
+ #n; nnormalize; napply refl_eq.
+nqed.
+
+nlemma npO_to_n : ∀n.n + O = n.
+ #n;
+ nelim n;
+ ##[ ##1: nnormalize; napply refl_eq
+ ##| ##2: #n1; #H;
+          nrewrite > (Sn_p_n_to_S_npn n1 O); 
+          nrewrite > H;
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma symmetric_plusnat : symmetricT nat nat plus.
+ #n1;
+ nelim n1;
+ ##[ ##1: #n2; nrewrite > (npO_to_n n2); nnormalize; napply refl_eq
+ ##| ##2: #n2; #H; #n3;
+          nrewrite > (Sn_p_n_to_S_npn n2 n3);
+          nrewrite > (n_p_Sn_to_S_npn n3 n2);
+          nrewrite > (H n3);
+          napply refl_eq
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/common/nat_to_num.ma b/helm/software/matita/contribs/ng_assembly/common/nat_to_num.ma
new file mode 100755 (executable)
index 0000000..6bd7fc4
--- /dev/null
@@ -0,0 +1,78 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/nat.ma".
+include "num/word32.ma".
+
+(* ************************ *)
+(* NUMERI FINITI → NATURALI *)
+(* ************************ *)
+
+nlet rec nat_of_qu_aux n (r:rec_quatern n) on r ≝
+ match r with
+  [ qu_O ⇒ O
+  | qu_S t n' ⇒ S (nat_of_qu_aux t n')
+  ].
+
+ndefinition nat_of_qu : quatern → nat ≝ λn.nat_of_qu_aux n (qu_to_recqu n).
+
+nlet rec nat_of_oct_aux n (r:rec_oct n) on r ≝
+ match r with
+  [ oc_O ⇒ O
+  | oc_S t n' ⇒ S (nat_of_oct_aux t n')
+  ].
+
+ndefinition nat_of_oct : oct → nat ≝ λn.nat_of_oct_aux n (oct_to_recoct n).
+
+nlet rec nat_of_ex_aux n (r:rec_exadecim n) on r ≝
+ match r with
+  [ ex_O ⇒ O
+  | ex_S t n' ⇒ S (nat_of_ex_aux t n')
+  ].
+
+ndefinition nat_of_ex : exadecim → nat ≝ λn.nat_of_ex_aux n (ex_to_recex n).
+
+nlet rec nat_of_bit_aux n (r:rec_bitrigesim n) on r ≝
+ match r with
+  [ bi_O ⇒ O
+  | bi_S t n' ⇒ S (nat_of_bit_aux t n')
+  ].
+
+ndefinition nat_of_bit : bitrigesim → nat ≝ λn.nat_of_bit_aux n (bit_to_recbit n).
+
+nlet rec nat_of_b8_aux n (r:rec_byte8 n) on r ≝
+ match r with
+  [ b8_O ⇒ O
+  | b8_S t n' ⇒ S (nat_of_b8_aux t n')
+  ].
+
+ndefinition nat_of_b8 : byte8 → nat ≝ λn:byte8.nat_of_b8_aux n (b8_to_recb8 n).
+
+nlet rec nat_of_w16_aux n (r:rec_word16 n) on r : nat ≝
+ match r with
+  [ w16_O ⇒ O
+  | w16_S t n' ⇒ S (nat_of_w16_aux t n')
+  ].
+
+ndefinition nat_of_w16 : word16 → nat ≝ λn:word16.nat_of_w16_aux n (w16_to_recw16 n).
+
+ndefinition nat_of_w32 : word32 → nat ≝ λn:word32.(nat65536 * (nat_of_w16 (w32h n))) + (nat_of_w16 (w32l n)).
diff --git a/helm/software/matita/contribs/ng_assembly/common/option.ma b/helm/software/matita/contribs/ng_assembly/common/option.ma
new file mode 100644 (file)
index 0000000..244f087
--- /dev/null
@@ -0,0 +1,43 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ****** *)
+(* OPTION *)
+(* ****** *)
+
+ninductive option (A:Type) : Type ≝
+  None : option A
+| Some : A → option A.
+
+ndefinition eq_option ≝
+λT.λop1,op2:option T.λf:T → T → bool.
+ match op1 with
+  [ None ⇒ match op2 with [ None ⇒ true | Some _ ⇒ false ]
+  | Some x1 ⇒ match op2 with [ None ⇒ false | Some x2 ⇒ f x1 x2 ]
+  ].
+
+(* option map = match ... with [ None ⇒ None ? | Some .. ⇒ .. ] *)
+ndefinition opt_map ≝
+λT1,T2:Type.λt:option T1.λf:T1 → option T2.
+ match t with [ None ⇒ None ? | Some x ⇒ (f x) ].
diff --git a/helm/software/matita/contribs/ng_assembly/common/option_lemmas.ma b/helm/software/matita/contribs/ng_assembly/common/option_lemmas.ma
new file mode 100644 (file)
index 0000000..144733f
--- /dev/null
@@ -0,0 +1,172 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/option.ma".
+include "num/bool_lemmas.ma".
+
+(* ****** *)
+(* OPTION *)
+(* ****** *)
+
+nlemma option_destruct_some_some : ∀T.∀x1,x2:T.Some T x1 = Some T x2 → x1 = x2.
+ #T; #x1; #x2; #H;
+ nchange with (match Some T x2 with [ None ⇒ False | Some a ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+(* !!! da togliere *)
+nlemma option_destruct_some_none : ∀T.∀x:T.Some T x = None T → False.
+ #T; #x; #H;
+ nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
+ nrewrite > H;
+ nnormalize;
+ napply I.
+nqed.
+
+(* !!! da togliere *)
+nlemma option_destruct_none_some : ∀T.∀x:T.None T = Some T x → False.
+ #T; #x; #H;
+ nchange with (match Some T x with [ None ⇒ True | Some a ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply I.
+nqed.
+
+nlemma symmetric_eqoption :
+∀T:Type.∀op1,op2:option T.∀f:T → T → bool.
+ (symmetricT T bool f) →
+ (eq_option T op1 op2 f = eq_option T op2 op1 f).
+ #T; #op1; #op2; #f; #H;
+ nelim op1;
+ nelim op2;
+ nnormalize;
+ ##[ ##1: napply refl_eq
+ ##| ##2,3: #H; napply refl_eq
+ ##| ##4: #a; #a0;
+          nrewrite > (H a0 a);
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma eq_to_eqoption :
+∀T.∀op1,op2:option T.∀f:T → T → bool.
+ (∀x1,x2:T.x1 = x2 → f x1 x2 = true) →
+ (op1 = op2 → eq_option T op1 op2 f = true).
+ #T; #op1; #op2; #f; #H;
+ nelim op1;
+ nelim op2;
+ nnormalize;
+ ##[ ##1: #H1; napply refl_eq
+ ##| ##2: #a; #H1;
+         (* !!! ndestruct: assert false *)
+         nelim (option_destruct_none_some ?? H1)
+ ##| ##3: #a; #H1;
+          (* !!! ndestruct: assert false *)
+          nelim (option_destruct_some_none ?? H1)
+ ##| ##4: #a; #a0; #H1;
+          nrewrite > (H … (option_destruct_some_some … H1));
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma eqoption_to_eq :
+∀T.∀op1,op2:option T.∀f:T → T → bool.
+ (∀x1,x2:T.f x1 x2 = true → x1 = x2) →
+ (eq_option T op1 op2 f = true → op1 = op2).
+ #T; #op1; #op2; #f; #H;
+ nelim op1;
+ nelim op2;
+ nnormalize;
+ ##[ ##1: #H1; napply refl_eq
+ ##| ##2,3: #a; #H1; ndestruct (*napply (bool_destruct … H1)*)
+ ##| ##4: #a; #a0; #H1;
+          nrewrite > (H … H1);
+          napply refl_eq
+ ##]
+nqed.
+
+nlemma decidable_option : ∀T.∀H:(Πx,y:T.decidable (x = y)).∀x,y:option T.decidable (x = y).
+ #T; #H; #x; nelim x;
+ ##[ ##1: #y; ncases y;
+          ##[ ##1: nnormalize; napply (or2_intro1 (? = ?) (? ≠ ?) (refl_eq …))
+          ##| ##2: #yy; nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H1;
+                   (* !!! ndestruct: assert false *)
+                   napply (option_destruct_none_some T … H1)
+          ##]
+ ##| ##2: #xx; #y; ncases y;
+          ##[ ##1: nnormalize; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (option_destruct_some_none T … H2)
+          ##| ##2: #yy; nnormalize; napply (or2_elim (xx = yy) (xx ≠ yy) ? (H …));
+                   ##[ ##2: #H1; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                            nnormalize; #H2;
+                            napply (H1 (option_destruct_some_some T … H2))
+                   ##| ##1: #H1; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
+                            nrewrite > H1; napply refl_eq
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqoption :
+∀T.∀op1,op2:option T.∀f:T → T → bool.
+ (∀x1,x2:T.x1 ≠ x2 → f x1 x2 = false) →
+ (op1 ≠ op2 → eq_option T op1 op2 f = false).
+ #T; #op1; nelim op1;
+ ##[ ##1: #op2; ncases op2;
+          ##[ ##1: nnormalize; #f; #H; #H1; nelim (H1 (refl_eq …))
+          ##| ##2: #yy; #f; #H; nnormalize; #H1; napply refl_eq
+          ##]
+ ##| ##2: #xx; #op2; ncases op2;
+          ##[ ##1: #f; #H; nnormalize; #H1; napply refl_eq
+          ##| ##2: #yy; #f; #H; nnormalize; #H1; napply (H xx yy …);
+                   nnormalize; #H2; nrewrite > H2 in H1:(%); #H1;
+                   napply (H1 (refl_eq …))
+          ##]
+ ##]
+nqed.
+
+nlemma neqoption_to_neq :
+∀T.∀op1,op2:option T.∀f:T → T → bool.
+ (∀x1,x2:T.f x1 x2 = false → x1 ≠ x2) →
+ (eq_option T op1 op2 f = false → op1 ≠ op2).
+ #T; #op1; nelim op1;
+ ##[ ##1: #op2; ncases op2;
+          ##[ ##1: nnormalize; #f; #H; #H1;
+                   ndestruct (*napply (bool_destruct … H1)*)
+          ##| ##2: #yy; #f; #H; nnormalize; #H1; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (option_destruct_none_some T … H2)
+          ##]
+ ##| ##2: #xx; #op2; ncases op2;
+          ##[ ##1: nnormalize; #f; #H; #H1; #H2;
+                   (* !!! ndestruct: assert false *)
+                   napply (option_destruct_some_none T … H2)
+          ##| ##2: #yy; #f; #H; nnormalize; #H1; #H2; napply (H xx yy H1 ?);
+                   napply (option_destruct_some_some T … H2)
+          ##]
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/common/prod.ma b/helm/software/matita/contribs/ng_assembly/common/prod.ma
new file mode 100644 (file)
index 0000000..fca58bc
--- /dev/null
@@ -0,0 +1,111 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ***** *)
+(* TUPLE *)
+(* ***** *)
+
+ninductive ProdT (T1:Type) (T2:Type) : Type ≝
+ pair : T1 → T2 → ProdT T1 T2.
+
+ndefinition fst ≝
+λT1,T2:Type.λp:ProdT T1 T2.match p with [ pair  x _ ⇒ x ].
+
+ndefinition snd ≝
+λT1,T2:Type.λp:ProdT T1 T2.match p with [ pair  _ x ⇒ x ].
+
+ndefinition eq_pair ≝
+λT1,T2:Type.λp1,p2:ProdT T1 T2.
+λf1:T1 → T1 → bool.λf2:T2 → T2 → bool.
+ (f1 (fst … p1) (fst … p2)) ⊗
+ (f2 (snd … p1) (snd … p2)).
+
+ninductive Prod3T (T1:Type) (T2:Type) (T3:Type) : Type ≝
+triple : T1 → T2 → T3 → Prod3T T1 T2 T3.
+
+ndefinition fst3T ≝
+λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ triple x _ _ ⇒ x ].
+
+ndefinition snd3T ≝
+λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ triple _ x _ ⇒ x ].
+
+ndefinition thd3T ≝
+λT1.λT2.λT3.λp:Prod3T T1 T2 T3.match p with [ triple _ _ x ⇒ x ].
+
+ndefinition eq_triple ≝
+λT1,T2,T3:Type.λp1,p2:Prod3T T1 T2 T3.
+λf1:T1 → T1 → bool.λf2:T2 → T2 → bool.λf3:T3 → T3 → bool.
+ (f1 (fst3T … p1) (fst3T … p2)) ⊗
+ (f2 (snd3T … p1) (snd3T … p2)) ⊗
+ (f3 (thd3T … p1) (thd3T … p2)).
+
+ninductive Prod4T (T1:Type) (T2:Type) (T3:Type) (T4:Type) : Type ≝
+quadruple : T1 → T2 → T3 → T4 → Prod4T T1 T2 T3 T4.
+
+ndefinition fst4T ≝
+λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadruple x _ _ _ ⇒ x ].
+
+ndefinition snd4T ≝
+λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadruple _ x _ _ ⇒ x ].
+
+ndefinition thd4T ≝
+λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadruple _ _ x _ ⇒ x ].
+
+ndefinition fth4T ≝
+λT1.λT2.λT3.λT4.λp:Prod4T T1 T2 T3 T4.match p with [ quadruple _ _ _ x ⇒ x ].
+
+ndefinition eq_quadruple ≝
+λT1,T2,T3,T4:Type.λp1,p2:Prod4T T1 T2 T3 T4.
+λf1:T1 → T1 → bool.λf2:T2 → T2 → bool.λf3:T3 → T3 → bool.λf4:T4 → T4 → bool.
+ (f1 (fst4T … p1) (fst4T … p2)) ⊗
+ (f2 (snd4T … p1) (snd4T … p2)) ⊗
+ (f3 (thd4T … p1) (thd4T … p2)) ⊗
+ (f4 (fth4T … p1) (fth4T … p2)).
+
+ninductive Prod5T (T1:Type) (T2:Type) (T3:Type) (T4:Type) (T5:Type) : Type ≝
+quintuple : T1 → T2 → T3 → T4 → T5 → Prod5T T1 T2 T3 T4 T5.
+
+ndefinition fst5T ≝
+λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintuple x _ _ _ _ ⇒ x ].
+
+ndefinition snd5T ≝
+λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintuple _ x _ _ _ ⇒ x ].
+
+ndefinition thd5T ≝
+λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintuple _ _ x _ _ ⇒ x ].
+
+ndefinition fth5T ≝
+λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintuple _ _ _ x _ ⇒ x ].
+
+ndefinition fft5T ≝
+λT1.λT2.λT3.λT4.λT5.λp:Prod5T T1 T2 T3 T4 T5.match p with [ quintuple _ _ _ _ x ⇒ x ].
+
+ndefinition eq_quintuple ≝
+λT1,T2,T3,T4,T5:Type.λp1,p2:Prod5T T1 T2 T3 T4 T5.
+λf1:T1 → T1 → bool.λf2:T2 → T2 → bool.λf3:T3 → T3 → bool.λf4:T4 → T4 → bool.λf5:T5 → T5 → bool.
+ (f1 (fst5T … p1) (fst5T … p2)) ⊗
+ (f2 (snd5T … p1) (snd5T … p2)) ⊗
+ (f3 (thd5T … p1) (thd5T … p2)) ⊗
+ (f4 (fth5T … p1) (fth5T … p2)) ⊗
+ (f5 (fft5T … p1) (fft5T … p2)).
diff --git a/helm/software/matita/contribs/ng_assembly/common/prod_lemmas.ma b/helm/software/matita/contribs/ng_assembly/common/prod_lemmas.ma
new file mode 100644 (file)
index 0000000..29998a8
--- /dev/null
@@ -0,0 +1,930 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/prod.ma".
+include "num/bool_lemmas.ma".
+
+(* ********* *)
+(* TUPLE x 2 *)
+(* ********* *)
+
+nlemma pair_destruct_1 :
+∀T1,T2.∀x1,x2:T1.∀y1,y2:T2.
+ pair T1 T2 x1 y1 = pair T1 T2 x2 y2 → x1 = x2.
+ #T1; #T2; #x1; #x2; #y1; #y2; #H;
+ nchange with (match pair T1 T2 x2 y2 with [ pair a _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma pair_destruct_2 :
+∀T1,T2.∀x1,x2:T1.∀y1,y2:T2.
+ pair T1 T2 x1 y1 = pair T1 T2 x2 y2 → y1 = y2.
+ #T1; #T2; #x1; #x2; #y1; #y2; #H;
+ nchange with (match pair T1 T2 x2 y2 with [ pair _ b ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqpair :
+∀T1,T2:Type.∀p1,p2:ProdT T1 T2.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.
+ (symmetricT T1 bool f1) →
+ (symmetricT T2 bool f2) →
+ (eq_pair T1 T2 p1 p2 f1 f2 = eq_pair T1 T2 p2 p1 f1 f2).
+ #T1; #T2; #p1; #p2; #f1; #f2; #H; #H1;
+ nelim p1;
+ #x1; #y1;
+ nelim p2;
+ #x2; #y2;
+ nnormalize;
+ nrewrite > (H x1 x2);
+ ncases (f1 x2 x1);
+ nnormalize;
+ ##[ ##1: nrewrite > (H1 y1 y2); napply refl_eq
+ ##| ##2: napply refl_eq
+ ##]
+nqed.
+
+nlemma eq_to_eqpair :
+∀T1,T2.∀p1,p2:ProdT T1 T2.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.
+ (∀x,y:T1.x = y → f1 x y = true) →
+ (∀x,y:T2.x = y → f2 x y = true) →
+ (p1 = p2 → eq_pair T1 T2 p1 p2 f1 f2 = true).
+ #T1; #T2; #p1; #p2; #f1; #f2; #H1; #H2;
+ nelim p1;
+ #x1; #y1;
+ nelim p2;
+ #x2; #y2; #H;
+ nnormalize;
+ nrewrite > (H1 … (pair_destruct_1 … H));
+ nnormalize;
+ nrewrite > (H2 … (pair_destruct_2 … H));
+ napply refl_eq.
+nqed.
+
+nlemma eqpair_to_eq :
+∀T1,T2.∀p1,p2:ProdT T1 T2.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.
+ (∀x,y:T1.f1 x y = true → x = y) →
+ (∀x,y:T2.f2 x y = true → x = y) →
+ (eq_pair T1 T2 p1 p2 f1 f2 = true → p1 = p2).
+ #T1; #T2; #p1; #p2; #f1; #f2; #H1; #H2;
+ nelim p1;
+ #x1; #y1;
+ nelim p2;
+ #x2; #y2; #H;
+ nnormalize in H:(%);
+ nletin K ≝ (H1 x1 x2);
+ ncases (f1 x1 x2) in H:(%) K:(%);
+ nnormalize;
+ #H3;
+ ##[ ##2: ndestruct (*napply (bool_destruct … H3)*) ##]
+ #H4;
+ nrewrite > (H4 (refl_eq …));
+ nrewrite > (H2 y1 y2 H3);
+ napply refl_eq.
+nqed.
+
+nlemma decidable_pair
+ : ∀T1,T2.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   ∀x,y:ProdT T1 T2.decidable (x = y).
+ #T1; #T2; #H; #H1;
+ #x; nelim x; #xx1; #xx2;
+ #y; nelim y; #yy1; #yy2;
+ nnormalize;
+ napply (or2_elim (xx1 = yy1) (xx1 ≠ yy1) ? (H xx1 yy1) ?);
+ ##[ ##2: #H2; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+          nnormalize; #H3; napply (H2 (pair_destruct_1 T1 T2 … H3))
+ ##| ##1: #H2; napply (or2_elim (xx2 = yy2) (xx2 ≠ yy2) ? (H1 xx2 yy2) ?);
+          ##[ ##2: #H3; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H4; napply (H3 (pair_destruct_2 T1 T2 … H4))
+          ##| ##1: #H3; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
+                   nrewrite > H2; nrewrite > H3; napply refl_eq
+          ##]
+ ##]
+nqed.
+
+nlemma neqpair_to_neq :
+ ∀T1,T2.∀p1,p2:ProdT T1 T2.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.
+ (∀x,y:T1.f1 x y = false → x ≠ y) →
+ (∀x,y:T2.f2 x y = false → x ≠ y) →
+ (eq_pair T1 T2 p1 p2 f1 f2 = false → p1 ≠ p2).
+ #T1; #T2; #p1; #p2; #f1; #f2; #H1; #H2;
+ nelim p1;
+ #x1; #y1;
+ nelim p2;
+ #x2; #y2;
+ nchange with ((((f1 x1 x2) ⊗ (f2 y1 y2)) = false) → ?); #H;
+ nnormalize; #H3;
+ napply (or2_elim ((f1 x1 x2) = false) ((f2 y1 y2) = false) ? (andb_false2 … H) ?);
+ ##[ ##1: #H4; napply (H1 x1 x2 H4); napply (pair_destruct_1 T1 T2 … H3)
+ ##| ##2: #H4; napply (H2 y1 y2 H4); napply (pair_destruct_2 T1 T2 … H3)
+ ##]
+nqed.
+
+nlemma pair_destruct
+ : ∀T1,T2.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   ∀x1,x2:T1.∀y1,y2:T2.(pair T1 T2 x1 y1) ≠ (pair T1 T2 x2 y2) → x1 ≠ x2 ∨ y1 ≠ y2.
+ #T1; #T2; #H1; #H2; #x1; #x2; #y1; #y2;
+ nnormalize; #H;
+ napply (or2_elim (x1 = x2) (x1 ≠ x2) ? (H1 x1 x2) ?);
+ ##[ ##2: #H3; napply (or2_intro1 … H3)
+ ##| ##1: #H3; napply (or2_elim (y1 = y2) (y1 ≠ y2) ? (H2 y1 y2) ?);
+          ##[ ##2: #H4; napply (or2_intro2 … H4)
+          ##| ##1: #H4; nrewrite > H3 in H:(%);
+                   nrewrite > H4; #H; nelim (H (refl_eq …))
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqpair :
+ ∀T1,T2.∀p1,p2:ProdT T1 T2.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.
+ (∀x,y:T1.decidable (x = y)) →
+ (∀x,y:T2.decidable (x = y)) →
+ (∀x,y:T1.x ≠ y → f1 x y = false) →
+ (∀x,y:T2.x ≠ y → f2 x y = false) →
+ (p1 ≠ p2 → eq_pair T1 T2 p1 p2 f1 f2 = false).
+ #T1; #T2; #p1; #p2; #f1; #f2; #H1; #H2; #H3; #H4;
+ nelim p1;
+ #x1; #y1;
+ nelim p2;
+ #x2; #y2; #H;
+ nchange with (((f1 x1 x2) ⊗ (f2 y1 y2)) = false);
+ napply (or2_elim (x1 ≠ x2) (y1 ≠ y2) ? (pair_destruct T1 T2 H1 H2 … H) ?);
+ ##[ ##2: #H5; nrewrite > (H4 … H5); nrewrite > (andb_false2_2 (f1 x1 x2)); napply refl_eq
+ ##| ##1: #H5; nrewrite > (H3 … H5); nnormalize; napply refl_eq
+ ##]
+nqed.
+
+(* ********* *)
+(* TUPLE x 3 *)
+(* ********* *)
+
+nlemma triple_destruct_1 :
+∀T1,T2,T3.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.
+ triple T1 T2 T3 x1 y1 z1 = triple T1 T2 T3 x2 y2 z2 → x1 = x2.
+ #T1; #T2; #T3; #x1; #x2; #y1; #y2; #z1; #z2; #H;
+ nchange with (match triple T1 T2 T3 x2 y2 z2 with [ triple a _ _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma triple_destruct_2 :
+∀T1,T2,T3.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.
+ triple T1 T2 T3 x1 y1 z1 = triple T1 T2 T3 x2 y2 z2 → y1 = y2.
+ #T1; #T2; #T3; #x1; #x2; #y1; #y2; #z1; #z2; #H;
+ nchange with (match triple T1 T2 T3 x2 y2 z2 with [ triple _ b _ ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma triple_destruct_3 :
+∀T1,T2,T3.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.
+ triple T1 T2 T3 x1 y1 z1 = triple T1 T2 T3 x2 y2 z2 → z1 = z2.
+ #T1; #T2; #T3; #x1; #x2; #y1; #y2; #z1; #z2; #H;
+ nchange with (match triple T1 T2 T3 x2 y2 z2 with [ triple _ _ c ⇒ z1 = c ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqtriple :
+∀T1,T2,T3:Type.∀p1,p2:Prod3T T1 T2 T3.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.
+ (symmetricT T1 bool f1) →
+ (symmetricT T2 bool f2) →
+ (symmetricT T3 bool f3) →
+ (eq_triple T1 T2 T3 p1 p2 f1 f2 f3 = eq_triple T1 T2 T3 p2 p1 f1 f2 f3).
+ #T1; #T2; #T3; #p1; #p2; #f1; #f2; #f3; #H; #H1; #H2;
+ nelim p1;
+ #x1; #y1; #z1;
+ nelim p2;
+ #x2; #y2; #z2;
+ nnormalize;
+ nrewrite > (H x1 x2);
+ ncases (f1 x2 x1);
+ nnormalize;
+ ##[ ##1: nrewrite > (H1 y1 y2);
+          ncases (f2 y2 y1);
+          nnormalize;
+          ##[ ##1: nrewrite > (H2 z1 z2); napply refl_eq
+          ##| ##2: napply refl_eq
+          ##]
+ ##| ##2: napply refl_eq
+ ##]
+nqed.
+
+nlemma eq_to_eqtriple :
+∀T1,T2,T3.∀p1,p2:Prod3T T1 T2 T3.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.
+ (∀x1,x2:T1.x1 = x2 → f1 x1 x2 = true) →
+ (∀y1,y2:T2.y1 = y2 → f2 y1 y2 = true) →
+ (∀z1,z2:T3.z1 = z2 → f3 z1 z2 = true) →
+ (p1 = p2 → eq_triple T1 T2 T3 p1 p2 f1 f2 f3 = true).
+ #T1; #T2; #T3; #p1; #p2; #f1; #f2; #f3; #H1; #H2; #H3;
+ nelim p1;
+ #x1; #y1; #z1;
+ nelim p2;
+ #x2; #y2; #z2; #H;
+ nnormalize;
+ nrewrite > (H1 … (triple_destruct_1 … H));
+ nnormalize;
+ nrewrite > (H2 … (triple_destruct_2 … H));
+ nnormalize;
+ nrewrite > (H3 … (triple_destruct_3 … H));
+ napply refl_eq.
+nqed.
+
+nlemma eqtriple_to_eq :
+∀T1,T2,T3.∀p1,p2:Prod3T T1 T2 T3.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.
+ (∀x1,x2:T1.f1 x1 x2 = true → x1 = x2) →
+ (∀y1,y2:T2.f2 y1 y2 = true → y1 = y2) →
+ (∀z1,z2:T3.f3 z1 z2 = true → z1 = z2) →
+ (eq_triple T1 T2 T3 p1 p2 f1 f2 f3 = true → p1 = p2).
+ #T1; #T2; #T3; #p1; #p2; #f1; #f2; #f3; #H1; #H2; #H3;
+ nelim p1;
+ #x1; #y1; #z1;
+ nelim p2;
+ #x2; #y2; #z2; #H;
+ nnormalize in H:(%);
+ nletin K ≝ (H1 x1 x2);
+ ncases (f1 x1 x2) in H:(%) K:(%);
+ nnormalize;
+ ##[ ##2: #H4; ndestruct (*napply (bool_destruct … H4)*) ##]
+ nletin K1 ≝ (H2 y1 y2);
+ ncases (f2 y1 y2) in K1:(%) ⊢ %;
+ nnormalize;
+ ##[ ##2: #H4; #H5; ndestruct (*napply (bool_destruct … H5)*) ##]
+ #H4; #H5; #H6;
+ nrewrite > (H4 (refl_eq …));
+ nrewrite > (H6 (refl_eq …));
+ nrewrite > (H3 z1 z2 H5);
+ napply refl_eq.
+nqed.
+
+nlemma decidable_triple
+ : ∀T1,T2,T3.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   (∀x,y:T3.decidable (x = y)) →
+   ∀x,y:Prod3T T1 T2 T3.decidable (x = y).
+ #T1; #T2; #T3; #H; #H1; #H2;
+ #x; nelim x; #xx1; #xx2; #xx3;
+ #y; nelim y; #yy1; #yy2; #yy3;
+ nnormalize;
+ napply (or2_elim (xx1 = yy1) (xx1 ≠ yy1) ? (H xx1 yy1) ?);
+ ##[ ##2: #H3; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+          nnormalize; #H4; napply (H3 (triple_destruct_1 T1 T2 T3 … H4))
+ ##| ##1: #H3; napply (or2_elim (xx2 = yy2) (xx2 ≠ yy2) ? (H1 xx2 yy2) ?);
+          ##[ ##2: #H4; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H5; napply (H4 (triple_destruct_2 T1 T2 T3 … H5))
+          ##| ##1: #H4; napply (or2_elim (xx3 = yy3) (xx3 ≠ yy3) ? (H2 xx3 yy3) ?);
+                   ##[ ##2: #H5; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                            nnormalize; #H6; napply (H5 (triple_destruct_3 T1 T2 T3 … H6))
+                   ##| ##1: #H5; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
+                            nrewrite > H3;
+                            nrewrite > H4;
+                            nrewrite > H5;
+                            napply refl_eq
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neqtriple_to_neq :
+ ∀T1,T2,T3.∀p1,p2:Prod3T T1 T2 T3.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.
+ (∀x,y:T1.f1 x y = false → x ≠ y) →
+ (∀x,y:T2.f2 x y = false → x ≠ y) →
+ (∀x,y:T3.f3 x y = false → x ≠ y) →
+ (eq_triple T1 T2 T3 p1 p2 f1 f2 f3 = false → p1 ≠ p2).
+ #T1; #T2; #T3; #p1; #p2; #f1; #f2; #f3; #H1; #H2; #H3;
+ nelim p1;
+ #x1; #y1; #z1;
+ nelim p2;
+ #x2; #y2; #z2;
+ nchange with ((((f1 x1 x2) ⊗ (f2 y1 y2) ⊗ (f3 z1 z2)) = false) → ?); #H;
+ nnormalize; #H4;
+ napply (or3_elim ((f1 x1 x2) = false) ((f2 y1 y2) = false) ((f3 z1 z2) = false) ? (andb_false3 … H) ?);
+ ##[ ##1: #H5; napply (H1 x1 x2 H5); napply (triple_destruct_1 T1 T2 T3 … H4)
+ ##| ##2: #H5; napply (H2 y1 y2 H5); napply (triple_destruct_2 T1 T2 T3 … H4)
+ ##| ##3: #H5; napply (H3 z1 z2 H5); napply (triple_destruct_3 T1 T2 T3 … H4)
+ ##]
+nqed.
+
+nlemma triple_destruct
+ : ∀T1,T2,T3.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   (∀x,y:T3.decidable (x = y)) →
+   ∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.(triple T1 T2 T3 x1 y1 z1) ≠ (triple T1 T2 T3 x2 y2 z2) →
+                                 Or3 (x1 ≠ x2) (y1 ≠ y2) (z1 ≠ z2).
+ #T1; #T2; #T3; #H1; #H2; #H3; #x1; #x2; #y1; #y2; #z1; #z2;
+ nnormalize; #H;
+ napply (or2_elim (x1 = x2) (x1 ≠ x2) ? (H1 x1 x2) ?);
+ ##[ ##2: #H4; napply (or3_intro1 … H4)
+ ##| ##1: #H4; napply (or2_elim (y1 = y2) (y1 ≠ y2) ? (H2 y1 y2) ?);
+          ##[ ##2: #H5; napply (or3_intro2 … H5)
+          ##| ##1: #H5; napply (or2_elim (z1 = z2) (z1 ≠ z2) ? (H3 z1 z2) ?);
+                   ##[ ##2: #H6; napply (or3_intro3 … H6)
+                   ##| ##1: #H6; nrewrite > H4 in H:(%);
+                            nrewrite > H5;
+                            nrewrite > H6; #H; nelim (H (refl_eq …))
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqtriple :
+ ∀T1,T2,T3.∀p1,p2:Prod3T T1 T2 T3.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.
+ (∀x,y:T1.decidable (x = y)) →
+ (∀x,y:T2.decidable (x = y)) →
+ (∀x,y:T3.decidable (x = y)) →
+ (∀x,y:T1.x ≠ y → f1 x y = false) →
+ (∀x,y:T2.x ≠ y → f2 x y = false) →
+ (∀x,y:T3.x ≠ y → f3 x y = false) →
+ (p1 ≠ p2 → eq_triple T1 T2 T3 p1 p2 f1 f2 f3 = false).
+ #T1; #T2; #T3; #p1; #p2; #f1; #f2; #f3; #H1; #H2; #H3; #H4; #H5; #H6;
+ nelim p1;
+ #x1; #y1; #z1;
+ nelim p2;
+ #x2; #y2; #z2; #H;
+ nchange with (((f1 x1 x2) ⊗ (f2 y1 y2) ⊗ (f3 z1 z2)) = false);
+ napply (or3_elim (x1 ≠ x2) (y1 ≠ y2) (z1 ≠ z2) ? (triple_destruct T1 T2 T3 H1 H2 H3 … H) ?);
+ ##[ ##1: #H7; nrewrite > (H4 … H7); nrewrite > (andb_false3_1 (f2 y1 y2) (f3 z1 z2)); napply refl_eq
+ ##| ##2: #H7; nrewrite > (H5 … H7); nrewrite > (andb_false3_2 (f1 x1 x2) (f3 z1 z2)); napply refl_eq
+ ##| ##3: #H7; nrewrite > (H6 … H7); nrewrite > (andb_false3_3 (f1 x1 x2) (f2 y1 y2)); napply refl_eq
+ ##]
+nqed.
+
+(* ********* *)
+(* TUPLE x 4 *)
+(* ********* *)
+
+nlemma quadruple_destruct_1 :
+∀T1,T2,T3,T4.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.
+ quadruple T1 T2 T3 T4 x1 y1 z1 v1 = quadruple T1 T2 T3 T4 x2 y2 z2 v2 → x1 = x2.
+ #T1; #T2; #T3; #T4; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #H;
+ nchange with (match quadruple T1 T2 T3 T4 x2 y2 z2 v2 with [ quadruple a _ _ _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma quadruple_destruct_2 :
+∀T1,T2,T3,T4.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.
+ quadruple T1 T2 T3 T4 x1 y1 z1 v1 = quadruple T1 T2 T3 T4 x2 y2 z2 v2 → y1 = y2.
+ #T1; #T2; #T3; #T4; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #H;
+ nchange with (match quadruple T1 T2 T3 T4 x2 y2 z2 v2 with [ quadruple _ b _ _ ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma quadruple_destruct_3 :
+∀T1,T2,T3,T4.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.
+ quadruple T1 T2 T3 T4 x1 y1 z1 v1 = quadruple T1 T2 T3 T4 x2 y2 z2 v2 → z1 = z2.
+ #T1; #T2; #T3; #T4; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #H;
+ nchange with (match quadruple T1 T2 T3 T4 x2 y2 z2 v2 with [ quadruple _ _ c _ ⇒ z1 = c ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma quadruple_destruct_4 :
+∀T1,T2,T3,T4.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.
+ quadruple T1 T2 T3 T4 x1 y1 z1 v1 = quadruple T1 T2 T3 T4 x2 y2 z2 v2 → v1 = v2.
+ #T1; #T2; #T3; #T4; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #H;
+ nchange with (match quadruple T1 T2 T3 T4 x2 y2 z2 v2 with [ quadruple _ _ _ d ⇒ v1 = d ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqquadruple :
+∀T1,T2,T3,T4:Type.∀p1,p2:Prod4T T1 T2 T3 T4.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.
+ (symmetricT T1 bool f1) →
+ (symmetricT T2 bool f2) →
+ (symmetricT T3 bool f3) →
+ (symmetricT T4 bool f4) →
+ (eq_quadruple T1 T2 T3 T4 p1 p2 f1 f2 f3 f4 = eq_quadruple T1 T2 T3 T4 p2 p1 f1 f2 f3 f4).
+ #T1; #T2; #T3; #T4; #p1; #p2; #f1; #f2; #f3; #f4; #H; #H1; #H2; #H3;
+ nelim p1;
+ #x1; #y1; #z1; #v1;
+ nelim p2;
+ #x2; #y2; #z2; #v2;
+ nnormalize;
+ nrewrite > (H x1 x2);
+ ncases (f1 x2 x1);
+ nnormalize;
+ ##[ ##1: nrewrite > (H1 y1 y2);
+          ncases (f2 y2 y1);
+          nnormalize;
+          ##[ ##1: nrewrite > (H2 z1 z2);
+                   ncases (f3 z2 z1);
+                   nnormalize;
+                   ##[ ##1: nrewrite > (H3 v1 v2); napply refl_eq
+                   ##| ##2: napply refl_eq
+                   ##]
+          ##| ##2: napply refl_eq
+          ##]
+ ##| ##2: napply refl_eq
+ ##]
+nqed.
+
+nlemma eq_to_eqquadruple :
+∀T1,T2,T3,T4.∀p1,p2:Prod4T T1 T2 T3 T4.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.
+ (∀x,y:T1.x = y → f1 x y = true) →
+ (∀x,y:T2.x = y → f2 x y = true) →
+ (∀x,y:T3.x = y → f3 x y = true) →
+ (∀x,y:T4.x = y → f4 x y = true) →
+ (p1 = p2 → eq_quadruple T1 T2 T3 T4 p1 p2 f1 f2 f3 f4 = true).
+ #T1; #T2; #T3; #T4; #p1; #p2; #f1; #f2; #f3; #f4; #H1; #H2; #H3; #H4;
+ nelim p1;
+ #x1; #y1; #z1; #v1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #H;
+ nnormalize;
+ nrewrite > (H1 … (quadruple_destruct_1 … H));
+ nnormalize;
+ nrewrite > (H2 … (quadruple_destruct_2 … H));
+ nnormalize;
+ nrewrite > (H3 … (quadruple_destruct_3 … H));
+ nnormalize;
+ nrewrite > (H4 … (quadruple_destruct_4 … H));
+ napply refl_eq.
+nqed.
+
+nlemma eqquadruple_to_eq :
+∀T1,T2,T3,T4.∀p1,p2:Prod4T T1 T2 T3 T4.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.
+ (∀x,y:T1.f1 x y = true → x = y) →
+ (∀x,y:T2.f2 x y = true → x = y) →
+ (∀x,y:T3.f3 x y = true → x = y) →
+ (∀x,y:T4.f4 x y = true → x = y) →
+ (eq_quadruple T1 T2 T3 T4 p1 p2 f1 f2 f3 f4 = true → p1 = p2).
+ #T1; #T2; #T3; #T4; #p1; #p2; #f1; #f2; #f3; #f4; #H1; #H2; #H3; #H4;
+ nelim p1;
+ #x1; #y1; #z1; #v1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #H;
+ nnormalize in H:(%);
+ nletin K ≝ (H1 x1 x2);
+ ncases (f1 x1 x2) in H:(%) K:(%);
+ nnormalize;
+ ##[ ##2: #H5; ndestruct (*napply (bool_destruct … H5)*) ##]
+ nletin K1 ≝ (H2 y1 y2);
+ ncases (f2 y1 y2) in K1:(%) ⊢ %;
+ nnormalize;
+ ##[ ##2: #H5; #H6; ndestruct (*napply (bool_destruct … H6)*) ##]
+ nletin K2 ≝ (H3 z1 z2);
+ ncases (f3 z1 z2) in K2:(%) ⊢ %;
+ nnormalize;
+ ##[ ##2: #H5; #H6; #H7; ndestruct (*napply (bool_destruct … H7)*) ##]
+ #H5; #H6; #H7; #H8;
+ nrewrite > (H5 (refl_eq …));
+ nrewrite > (H6 (refl_eq …));
+ nrewrite > (H8 (refl_eq …));
+ nrewrite > (H4 v1 v2 H7);
+ napply refl_eq.
+nqed.
+
+nlemma decidable_quadruple
+ : ∀T1,T2,T3,T4.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   (∀x,y:T3.decidable (x = y)) →
+   (∀x,y:T4.decidable (x = y)) →
+   ∀x,y:Prod4T T1 T2 T3 T4.decidable (x = y).
+ #T1; #T2; #T3; #T4; #H; #H1; #H2; #H3;
+ #x; nelim x; #xx1; #xx2; #xx3; #xx4;
+ #y; nelim y; #yy1; #yy2; #yy3; #yy4;
+ nnormalize;
+ napply (or2_elim (xx1 = yy1) (xx1 ≠ yy1) ? (H xx1 yy1) ?);
+ ##[ ##2: #H4; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+          nnormalize; #H5; napply (H4 (quadruple_destruct_1 T1 T2 T3 T4 … H5))
+ ##| ##1: #H4; napply (or2_elim (xx2 = yy2) (xx2 ≠ yy2) ? (H1 xx2 yy2) ?);
+          ##[ ##2: #H5; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H6; napply (H5 (quadruple_destruct_2 T1 T2 T3 T4 … H6))
+          ##| ##1: #H5; napply (or2_elim (xx3 = yy3) (xx3 ≠ yy3) ? (H2 xx3 yy3) ?);
+                   ##[ ##2: #H6; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                            nnormalize; #H7; napply (H6 (quadruple_destruct_3 T1 T2 T3 T4 … H7))
+                   ##| ##1: #H6; napply (or2_elim (xx4 = yy4) (xx4 ≠ yy4) ? (H3 xx4 yy4) ?);
+                            ##[ ##2: #H7; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                                     nnormalize; #H8; napply (H7 (quadruple_destruct_4 T1 T2 T3 T4 … H8))
+                            ##| ##1: #H7; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
+                                     nrewrite > H4;
+                                     nrewrite > H5;
+                                     nrewrite > H6;
+                                     nrewrite > H7;
+                                     napply refl_eq
+                            ##]
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neqquadruple_to_neq :
+ ∀T1,T2,T3,T4.∀p1,p2:Prod4T T1 T2 T3 T4.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.
+ (∀x,y:T1.f1 x y = false → x ≠ y) →
+ (∀x,y:T2.f2 x y = false → x ≠ y) →
+ (∀x,y:T3.f3 x y = false → x ≠ y) →
+ (∀x,y:T4.f4 x y = false → x ≠ y) →
+ (eq_quadruple T1 T2 T3 T4 p1 p2 f1 f2 f3 f4 = false → p1 ≠ p2).
+ #T1; #T2; #T3; #T4; #p1; #p2; #f1; #f2; #f3; #f4; #H1; #H2; #H3; #H4;
+ nelim p1;
+ #x1; #y1; #z1; #v1;
+ nelim p2;
+ #x2; #y2; #z2; #v2;
+ nchange with ((((f1 x1 x2) ⊗ (f2 y1 y2) ⊗ (f3 z1 z2) ⊗ (f4 v1 v2)) = false) → ?); #H;
+ nnormalize; #H5;
+ napply (or4_elim ((f1 x1 x2) = false) ((f2 y1 y2) = false) ((f3 z1 z2) = false) ((f4 v1 v2) = false) ? (andb_false4 … H) ?);
+ ##[ ##1: #H6; napply (H1 x1 x2 H6); napply (quadruple_destruct_1 T1 T2 T3 T4 … H5)
+ ##| ##2: #H6; napply (H2 y1 y2 H6); napply (quadruple_destruct_2 T1 T2 T3 T4 … H5)
+ ##| ##3: #H6; napply (H3 z1 z2 H6); napply (quadruple_destruct_3 T1 T2 T3 T4 … H5)
+ ##| ##4: #H6; napply (H4 v1 v2 H6); napply (quadruple_destruct_4 T1 T2 T3 T4 … H5)
+ ##]
+nqed.
+
+nlemma quadruple_destruct
+ : ∀T1,T2,T3,T4.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   (∀x,y:T3.decidable (x = y)) →
+   (∀x,y:T4.decidable (x = y)) →
+   ∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.
+    (quadruple T1 T2 T3 T4 x1 y1 z1 v1) ≠ (quadruple T1 T2 T3 T4 x2 y2 z2 v2) →
+    Or4 (x1 ≠ x2) (y1 ≠ y2) (z1 ≠ z2) (v1 ≠ v2).
+ #T1; #T2; #T3; #T4; #H1; #H2; #H3; #H4;
+ #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2;
+ nnormalize; #H;
+ napply (or2_elim (x1 = x2) (x1 ≠ x2) ? (H1 x1 x2) ?);
+ ##[ ##2: #H5; napply (or4_intro1 … H5)
+ ##| ##1: #H5; napply (or2_elim (y1 = y2) (y1 ≠ y2) ? (H2 y1 y2) ?);
+          ##[ ##2: #H6; napply (or4_intro2 … H6)
+          ##| ##1: #H6; napply (or2_elim (z1 = z2) (z1 ≠ z2) ? (H3 z1 z2) ?);
+                   ##[ ##2: #H7; napply (or4_intro3 … H7)
+                   ##| ##1: #H7; napply (or2_elim (v1 = v2) (v1 ≠ v2) ? (H4 v1 v2) ?);
+                            ##[ ##2: #H8; napply (or4_intro4 … H8)
+                            ##| ##1: #H8; nrewrite > H5 in H:(%);
+                                     nrewrite > H6;
+                                     nrewrite > H7;
+                                     nrewrite > H8; #H; nelim (H (refl_eq …))
+                            ##]
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqquadruple :
+ ∀T1,T2,T3,T4.∀p1,p2:Prod4T T1 T2 T3 T4.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.
+ (∀x,y:T1.decidable (x = y)) →
+ (∀x,y:T2.decidable (x = y)) →
+ (∀x,y:T3.decidable (x = y)) →
+ (∀x,y:T4.decidable (x = y)) →
+ (∀x,y:T1.x ≠ y → f1 x y = false) →
+ (∀x,y:T2.x ≠ y → f2 x y = false) →
+ (∀x,y:T3.x ≠ y → f3 x y = false) →
+ (∀x,y:T4.x ≠ y → f4 x y = false) →
+ (p1 ≠ p2 → eq_quadruple T1 T2 T3 T4 p1 p2 f1 f2 f3 f4 = false).
+ #T1; #T2; #T3; #T4; #p1; #p2; #f1; #f2; #f3; #f4; #H1; #H2; #H3; #H4; #H5; #H6; #H7; #H8;
+ nelim p1;
+ #x1; #y1; #z1; #v1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #H;
+ nchange with (((f1 x1 x2) ⊗ (f2 y1 y2) ⊗ (f3 z1 z2) ⊗ (f4 v1 v2)) = false);
+ napply (or4_elim (x1 ≠ x2) (y1 ≠ y2) (z1 ≠ z2) (v1 ≠ v2) ? (quadruple_destruct T1 T2 T3 T4 H1 H2 H3 H4 … H) ?);
+ ##[ ##1: #H9; nrewrite > (H5 … H9); nrewrite > (andb_false4_1 (f2 y1 y2) (f3 z1 z2) (f4 v1 v2)); napply refl_eq
+ ##| ##2: #H9; nrewrite > (H6 … H9); nrewrite > (andb_false4_2 (f1 x1 x2) (f3 z1 z2) (f4 v1 v2)); napply refl_eq
+ ##| ##3: #H9; nrewrite > (H7 … H9); nrewrite > (andb_false4_3 (f1 x1 x2) (f2 y1 y2) (f4 v1 v2)); napply refl_eq
+ ##| ##4: #H9; nrewrite > (H8 … H9); nrewrite > (andb_false4_4 (f1 x1 x2) (f2 y1 y2) (f3 z1 z2)); napply refl_eq
+ ##]
+nqed.
+
+(* ********* *)
+(* TUPLE x 5 *)
+(* ********* *)
+
+nlemma quintuple_destruct_1 :
+∀T1,T2,T3,T4,T5.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.∀w1,w2:T5.
+ quintuple T1 T2 T3 T4 T5 x1 y1 z1 v1 w1 = quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 → x1 = x2.
+ #T1; #T2; #T3; #T4; #T5; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #w1; #w2; #H;
+ nchange with (match quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 with [ quintuple a _ _ _ _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma quintuple_destruct_2 :
+∀T1,T2,T3,T4,T5.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.∀w1,w2:T5.
+ quintuple T1 T2 T3 T4 T5 x1 y1 z1 v1 w1 = quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 → y1 = y2.
+ #T1; #T2; #T3; #T4; #T5; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #w1; #w2; #H;
+ nchange with (match quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 with [ quintuple _ b _ _ _ ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma quintuple_destruct_3 :
+∀T1,T2,T3,T4,T5.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.∀w1,w2:T5.
+ quintuple T1 T2 T3 T4 T5 x1 y1 z1 v1 w1 = quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 → z1 = z2.
+ #T1; #T2; #T3; #T4; #T5; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #w1; #w2; #H;
+ nchange with (match quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 with [ quintuple _ _ c _ _ ⇒ z1 = c ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma quintuple_destruct_4 :
+∀T1,T2,T3,T4,T5.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.∀w1,w2:T5.
+ quintuple T1 T2 T3 T4 T5 x1 y1 z1 v1 w1 = quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 → v1 = v2.
+ #T1; #T2; #T3; #T4; #T5; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #w1; #w2; #H;
+ nchange with (match quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 with [ quintuple _ _ _ d _ ⇒ v1 = d ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma quintuple_destruct_5 :
+∀T1,T2,T3,T4,T5.∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.∀w1,w2:T5.
+ quintuple T1 T2 T3 T4 T5 x1 y1 z1 v1 w1 = quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 → w1 = w2.
+ #T1; #T2; #T3; #T4; #T5; #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #w1; #w2; #H;
+ nchange with (match quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2 with [ quintuple _ _ _ _ e ⇒ w1 = e ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqquintuple :
+∀T1,T2,T3,T4,T5:Type.∀p1,p2:Prod5T T1 T2 T3 T4 T5.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.∀f5:T5 → T5 → bool.
+ (symmetricT T1 bool f1) →
+ (symmetricT T2 bool f2) →
+ (symmetricT T3 bool f3) →
+ (symmetricT T4 bool f4) →
+ (symmetricT T5 bool f5) →
+ (eq_quintuple T1 T2 T3 T4 T5 p1 p2 f1 f2 f3 f4 f5 = eq_quintuple T1 T2 T3 T4 T5 p2 p1 f1 f2 f3 f4 f5).
+ #T1; #T2; #T3; #T4; #T5; #p1; #p2; #f1; #f2; #f3; #f4; #f5; #H; #H1; #H2; #H3; #H4;
+ nelim p1;
+ #x1; #y1; #z1; #v1; #w1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #w2;
+ nnormalize;
+ nrewrite > (H x1 x2);
+ ncases (f1 x2 x1);
+ nnormalize;
+ ##[ ##1: nrewrite > (H1 y1 y2);
+          ncases (f2 y2 y1);
+          nnormalize;
+          ##[ ##1: nrewrite > (H2 z1 z2);
+                   ncases (f3 z2 z1);
+                   nnormalize;
+                   ##[ ##1: nrewrite > (H3 v1 v2);
+                            ncases (f4 v2 v1);
+                            nnormalize;
+                            ##[ ##1: nrewrite > (H4 w1 w2); napply refl_eq
+                            ##| ##2: napply refl_eq
+                            ##]
+                   ##| ##2: napply refl_eq
+                   ##]
+          ##| ##2: napply refl_eq
+          ##]
+ ##| ##2: napply refl_eq
+ ##]
+nqed.
+
+nlemma eq_to_eqquintuple :
+∀T1,T2,T3,T4,T5.∀p1,p2:Prod5T T1 T2 T3 T4 T5.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.∀f5:T5 → T5 → bool.
+ (∀x,y:T1.x = y → f1 x y = true) →
+ (∀x,y:T2.x = y → f2 x y = true) →
+ (∀x,y:T3.x = y → f3 x y = true) →
+ (∀x,y:T4.x = y → f4 x y = true) →
+ (∀x,y:T5.x = y → f5 x y = true) →
+ (p1 = p2 → eq_quintuple T1 T2 T3 T4 T5 p1 p2 f1 f2 f3 f4 f5 = true).
+ #T1; #T2; #T3; #T4; #T5; #p1; #p2; #f1; #f2; #f3; #f4; #f5; #H1; #H2; #H3; #H4; #H5;
+ nelim p1;
+ #x1; #y1; #z1; #v1; #w1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #w2; #H;
+ nnormalize;
+ nrewrite > (H1 … (quintuple_destruct_1 … H));
+ nnormalize;
+ nrewrite > (H2 … (quintuple_destruct_2 … H));
+ nnormalize;
+ nrewrite > (H3 … (quintuple_destruct_3 … H));
+ nnormalize;
+ nrewrite > (H4 … (quintuple_destruct_4 … H));
+ nnormalize;
+ nrewrite > (H5 … (quintuple_destruct_5 … H));
+ napply refl_eq.
+nqed.
+
+nlemma eqquintuple_to_eq :
+∀T1,T2,T3,T4,T5.∀p1,p2:Prod5T T1 T2 T3 T4 T5.
+∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.∀f5:T5 → T5 → bool.
+ (∀x,y:T1.f1 x y = true → x = y) →
+ (∀x,y:T2.f2 x y = true → x = y) →
+ (∀x,y:T3.f3 x y = true → x = y) →
+ (∀x,y:T4.f4 x y = true → x = y) →
+ (∀x,y:T5.f5 x y = true → x = y) →
+ (eq_quintuple T1 T2 T3 T4 T5 p1 p2 f1 f2 f3 f4 f5 = true → p1 = p2).
+ #T1; #T2; #T3; #T4; #T5; #p1; #p2; #f1; #f2; #f3; #f4; #f5; #H1; #H2; #H3; #H4; #H5;
+ nelim p1;
+ #x1; #y1; #z1; #v1; #w1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #w2; #H;
+ nnormalize in H:(%);
+ nletin K ≝ (H1 x1 x2);
+ ncases (f1 x1 x2) in H:(%) K:(%);
+ nnormalize;
+ ##[ ##2: #H6; ndestruct (*napply (bool_destruct … H6)*) ##]
+ nletin K1 ≝ (H2 y1 y2);
+ ncases (f2 y1 y2) in K1:(%) ⊢ %;
+ nnormalize;
+ ##[ ##2: #H6; #H7; ndestruct (*napply (bool_destruct … H7)*) ##]
+ nletin K2 ≝ (H3 z1 z2);
+ ncases (f3 z1 z2) in K2:(%) ⊢ %;
+ nnormalize;
+ ##[ ##2: #H6; #H7; #H8; ndestruct (*napply (bool_destruct … H8)*) ##]
+ nletin K3 ≝ (H4 v1 v2);
+ ncases (f4 v1 v2) in K3:(%) ⊢ %;
+ nnormalize;
+ ##[ ##2: #H6; #H7; #H8; #H9; ndestruct (*napply (bool_destruct … H9)*) ##]
+ #H6; #H7; #H8; #H9; #H10;
+ nrewrite > (H6 (refl_eq …));
+ nrewrite > (H7 (refl_eq …));
+ nrewrite > (H8 (refl_eq …));
+ nrewrite > (H10 (refl_eq …));
+ nrewrite > (H5 w1 w2 H9);
+ napply refl_eq.
+nqed.
+
+nlemma decidable_quintuple
+ : ∀T1,T2,T3,T4,T5.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   (∀x,y:T3.decidable (x = y)) →
+   (∀x,y:T4.decidable (x = y)) →
+   (∀x,y:T5.decidable (x = y)) →
+   ∀x,y:Prod5T T1 T2 T3 T4 T5.decidable (x = y).
+ #T1; #T2; #T3; #T4; #T5; #H; #H1; #H2; #H3; #H4;
+ #x; nelim x; #xx1; #xx2; #xx3; #xx4; #xx5;
+ #y; nelim y; #yy1; #yy2; #yy3; #yy4; #yy5;
+ nnormalize;
+ napply (or2_elim (xx1 = yy1) (xx1 ≠ yy1) ? (H xx1 yy1) ?);
+ ##[ ##2: #H5; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+          nnormalize; #H6; napply (H5 (quintuple_destruct_1 T1 T2 T3 T4 T5 … H6))
+ ##| ##1: #H5; napply (or2_elim (xx2 = yy2) (xx2 ≠ yy2) ? (H1 xx2 yy2) ?);
+          ##[ ##2: #H6; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                   nnormalize; #H7; napply (H6 (quintuple_destruct_2 T1 T2 T3 T4 T5 … H7))
+          ##| ##1: #H6; napply (or2_elim (xx3 = yy3) (xx3 ≠ yy3) ? (H2 xx3 yy3) ?);
+                   ##[ ##2: #H7; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                            nnormalize; #H8; napply (H7 (quintuple_destruct_3 T1 T2 T3 T4 T5 … H8))
+                   ##| ##1: #H7; napply (or2_elim (xx4 = yy4) (xx4 ≠ yy4) ? (H3 xx4 yy4) ?);
+                            ##[ ##2: #H8; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                                     nnormalize; #H9; napply (H8 (quintuple_destruct_4 T1 T2 T3 T4 T5 … H9))
+                            ##| ##1: #H8; napply (or2_elim (xx5 = yy5) (xx5 ≠ yy5) ? (H4 xx5 yy5) ?);
+                                     ##[ ##2: #H9; napply (or2_intro2 (? = ?) (? ≠ ?) ?);
+                                              nnormalize; #H10; napply (H9 (quintuple_destruct_5 T1 T2 T3 T4 T5 … H10))
+                                     ##| ##1: #H9; napply (or2_intro1 (? = ?) (? ≠ ?) ?);
+                                              nrewrite > H5;
+                                              nrewrite > H6;
+                                              nrewrite > H7;
+                                              nrewrite > H8;
+                                              nrewrite > H9;
+                                              napply refl_eq
+                                     ##]
+                            ##]
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neqquintuple_to_neq :
+ ∀T1,T2,T3,T4,T5.∀p1,p2:Prod5T T1 T2 T3 T4 T5.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.∀f5:T5 → T5 → bool.
+ (∀x,y:T1.f1 x y = false → x ≠ y) →
+ (∀x,y:T2.f2 x y = false → x ≠ y) →
+ (∀x,y:T3.f3 x y = false → x ≠ y) →
+ (∀x,y:T4.f4 x y = false → x ≠ y) →
+ (∀x,y:T5.f5 x y = false → x ≠ y) →
+ (eq_quintuple T1 T2 T3 T4 T5 p1 p2 f1 f2 f3 f4 f5 = false → p1 ≠ p2).
+ #T1; #T2; #T3; #T4; #T5; #p1; #p2; #f1; #f2; #f3; #f4; #f5; #H1; #H2; #H3; #H4; #H5;
+ nelim p1;
+ #x1; #y1; #z1; #v1; #w1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #w2;
+ nchange with ((((f1 x1 x2) ⊗ (f2 y1 y2) ⊗ (f3 z1 z2) ⊗ (f4 v1 v2) ⊗ (f5 w1 w2)) = false) → ?); #H;
+ nnormalize; #H6;
+ napply (or5_elim ((f1 x1 x2) = false) ((f2 y1 y2) = false) ((f3 z1 z2) = false) ((f4 v1 v2) = false) ((f5 w1 w2) = false) ? (andb_false5 … H) ?);
+ ##[ ##1: #H7; napply (H1 x1 x2 H7); napply (quintuple_destruct_1 T1 T2 T3 T4 T5 … H6)
+ ##| ##2: #H7; napply (H2 y1 y2 H7); napply (quintuple_destruct_2 T1 T2 T3 T4 T5 … H6)
+ ##| ##3: #H7; napply (H3 z1 z2 H7); napply (quintuple_destruct_3 T1 T2 T3 T4 T5 … H6)
+ ##| ##4: #H7; napply (H4 v1 v2 H7); napply (quintuple_destruct_4 T1 T2 T3 T4 T5 … H6)
+ ##| ##5: #H7; napply (H5 w1 w2 H7); napply (quintuple_destruct_5 T1 T2 T3 T4 T5 … H6)
+ ##]
+nqed.
+
+nlemma quintuple_destruct
+ : ∀T1,T2,T3,T4,T5.
+   (∀x,y:T1.decidable (x = y)) →
+   (∀x,y:T2.decidable (x = y)) →
+   (∀x,y:T3.decidable (x = y)) →
+   (∀x,y:T4.decidable (x = y)) →
+   (∀x,y:T5.decidable (x = y)) →
+   ∀x1,x2:T1.∀y1,y2:T2.∀z1,z2:T3.∀v1,v2:T4.∀w1,w2:T5.
+    (quintuple T1 T2 T3 T4 T5 x1 y1 z1 v1 w1) ≠ (quintuple T1 T2 T3 T4 T5 x2 y2 z2 v2 w2) →
+    Or5 (x1 ≠ x2) (y1 ≠ y2) (z1 ≠ z2) (v1 ≠ v2) (w1 ≠ w2).
+ #T1; #T2; #T3; #T4; #T5; #H1; #H2; #H3; #H4; #H5;
+ #x1; #x2; #y1; #y2; #z1; #z2; #v1; #v2; #w1; #w2;
+ nnormalize; #H;
+ napply (or2_elim (x1 = x2) (x1 ≠ x2) ? (H1 x1 x2) ?);
+ ##[ ##2: #H6; napply (or5_intro1 … H6)
+ ##| ##1: #H6; napply (or2_elim (y1 = y2) (y1 ≠ y2) ? (H2 y1 y2) ?);
+          ##[ ##2: #H7; napply (or5_intro2 … H7)
+          ##| ##1: #H7; napply (or2_elim (z1 = z2) (z1 ≠ z2) ? (H3 z1 z2) ?);
+                   ##[ ##2: #H8; napply (or5_intro3 … H8)
+                   ##| ##1: #H8; napply (or2_elim (v1 = v2) (v1 ≠ v2) ? (H4 v1 v2) ?);
+                            ##[ ##2: #H9; napply (or5_intro4 … H9)
+                            ##| ##1: #H9; napply (or2_elim (w1 = w2) (w1 ≠ w2) ? (H5 w1 w2) ?);
+                                     ##[ ##2: #H10; napply (or5_intro5 … H10)
+                                     ##| ##1: #H10; nrewrite > H6 in H:(%);
+                                              nrewrite > H7;
+                                              nrewrite > H8;
+                                              nrewrite > H9;
+                                              nrewrite > H10; #H; nelim (H (refl_eq …))
+                                     ##]
+                            ##]
+                   ##]
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqquintuple :
+ ∀T1,T2,T3,T4,T5.∀p1,p2:Prod5T T1 T2 T3 T4 T5.
+ ∀f1:T1 → T1 → bool.∀f2:T2 → T2 → bool.∀f3:T3 → T3 → bool.∀f4:T4 → T4 → bool.∀f5:T5 → T5 → bool.
+ (∀x,y:T1.decidable (x = y)) →
+ (∀x,y:T2.decidable (x = y)) →
+ (∀x,y:T3.decidable (x = y)) →
+ (∀x,y:T4.decidable (x = y)) →
+ (∀x,y:T5.decidable (x = y)) →
+ (∀x,y:T1.x ≠ y → f1 x y = false) →
+ (∀x,y:T2.x ≠ y → f2 x y = false) →
+ (∀x,y:T3.x ≠ y → f3 x y = false) →
+ (∀x,y:T4.x ≠ y → f4 x y = false) →
+ (∀x,y:T5.x ≠ y → f5 x y = false) →
+ (p1 ≠ p2 → eq_quintuple T1 T2 T3 T4 T5 p1 p2 f1 f2 f3 f4 f5 = false).
+ #T1; #T2; #T3; #T4; #T5; #p1; #p2;
+ #f1; #f2; #f3; #f4; #f5;
+ #H1; #H2; #H3; #H4; #H5; #H6; #H7; #H8; #H9; #H10;
+ nelim p1;
+ #x1; #y1; #z1; #v1; #w1;
+ nelim p2;
+ #x2; #y2; #z2; #v2; #w2; #H;
+ nchange with (((f1 x1 x2) ⊗ (f2 y1 y2) ⊗ (f3 z1 z2) ⊗ (f4 v1 v2) ⊗ (f5 w1 w2)) = false);
+ napply (or5_elim (x1 ≠ x2) (y1 ≠ y2) (z1 ≠ z2) (v1 ≠ v2) (w1 ≠ w2) ? (quintuple_destruct T1 T2 T3 T4 T5 H1 H2 H3 H4 H5 … H) ?);
+ ##[ ##1: #H11; nrewrite > (H6 … H11); nrewrite > (andb_false5_1 (f2 y1 y2) (f3 z1 z2) (f4 v1 v2) (f5 w1 w2)); napply refl_eq
+ ##| ##2: #H11; nrewrite > (H7 … H11); nrewrite > (andb_false5_2 (f1 x1 x2) (f3 z1 z2) (f4 v1 v2) (f5 w1 w2)); napply refl_eq
+ ##| ##3: #H11; nrewrite > (H8 … H11); nrewrite > (andb_false5_3 (f1 x1 x2) (f2 y1 y2) (f4 v1 v2) (f5 w1 w2)); napply refl_eq
+ ##| ##4: #H11; nrewrite > (H9 … H11); nrewrite > (andb_false5_4 (f1 x1 x2) (f2 y1 y2) (f3 z1 z2) (f5 w1 w2)); napply refl_eq
+ ##| ##5: #H11; nrewrite > (H10 … H11); nrewrite > (andb_false5_5 (f1 x1 x2) (f2 y1 y2) (f3 z1 z2) (f4 v1 v2)); napply refl_eq
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/common/sigma.ma b/helm/software/matita/contribs/ng_assembly/common/sigma.ma
new file mode 100755 (executable)
index 0000000..529ca7a
--- /dev/null
@@ -0,0 +1,52 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/theory.ma".
+
+(* coppia dipendente *)
+
+ninductive sigma (A:Type) (P:A → Type) : Type ≝
+    sigma_intro: ∀x:A.P x → sigma A P.
+
+notation < "hvbox(\Sigma ident i opt (: tx) break . p)"
+  right associative with precedence 20
+for @{ 'Sigma ${default
+  @{\lambda ${ident i} : $tx. $p}  
+  @{\lambda ${ident i} . $p}}}.
+
+notation > "\Sigma list1 ident x sep , opt (: T). term 19 Px"
+  with precedence 20
+  for ${ default
+          @{ ${ fold right @{$Px} rec acc @{'Sigma (λ${ident x}:$T.$acc)} } }
+          @{ ${ fold right @{$Px} rec acc @{'Sigma (λ${ident x}.$acc)} } }
+       }.
+
+notation "\ll term 19 a, break term 19 b \gg"
+with precedence 90 for @{'dependent_pair (λx:?.? x) $a $b}.
+interpretation "dependent pair" 'dependent_pair \eta.c a b = (sigma_intro ? c a b).
+
+interpretation "sigma" 'Sigma \eta.x = (sigma ? x).
+
+ndefinition sigmaFst ≝
+λT:Type.λf:T → Type.λs:sigma T f.match s with [ sigma_intro x _ ⇒ x ].
+ndefinition sigmaSnd ≝
+λT:Type.λf:T → Type.λs:sigma T f.match s return λs.f (sigmaFst ?? s) with [ sigma_intro _ x ⇒ x ].
diff --git a/helm/software/matita/contribs/ng_assembly/common/string.ma b/helm/software/matita/contribs/ng_assembly/common/string.ma
new file mode 100644 (file)
index 0000000..87ba113
--- /dev/null
@@ -0,0 +1,52 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/ascii.ma".
+include "common/list_utility.ma".
+
+(* ************************ *)
+(* MANIPOLAZIONE DI STRINGA *)
+(* ************************ *)
+
+(* tipo pubblico *)
+ndefinition aux_str_type ≝ list ascii.
+
+(* strcmp *)
+ndefinition eq_str ≝
+ bfold_right_list2 ascii (λx,y.eq_ascii x y).
+
+(* ************ *)
+(* STRINGA + ID *)
+(* ************ *)
+
+(* tipo pubblico *)
+nrecord strId : Type ≝
+ {
+ str_elem: aux_str_type;
+ id_elem: nat
+ }.
+
+(* confronto *)
+ndefinition eq_strId ≝
+λsid,sid':strId.
+ (eq_str (str_elem sid) (str_elem sid'))⊗
+ (eq_nat (id_elem sid) (id_elem sid')).
diff --git a/helm/software/matita/contribs/ng_assembly/common/string_lemmas.ma b/helm/software/matita/contribs/ng_assembly/common/string_lemmas.ma
new file mode 100755 (executable)
index 0000000..53dcc50
--- /dev/null
@@ -0,0 +1,183 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/string.ma".
+include "common/ascii_lemmas.ma".
+include "common/list_utility_lemmas.ma".
+
+(* ************************ *)
+(* MANIPOLAZIONE DI STRINGA *)
+(* ************************ *)
+
+nlemma symmetric_eqstr : symmetricT (list ascii) bool eq_str.
+ #s1; #s2;
+ napply (symmetric_bfoldrightlist2 ascii eq_ascii s1 s2 symmetric_eqascii).
+nqed.
+
+nlemma eqstr_to_eq : ∀s,s'.eq_str s s' = true → s = s'.
+ #s1; #s2;
+ napply (bfoldrightlist2_to_eq ascii eq_ascii s1 s2 eqascii_to_eq).
+nqed.
+
+nlemma eq_to_eqstr : ∀s,s'.s = s' → eq_str s s' = true.
+ #s1; #s2;
+ napply (eq_to_bfoldrightlist2 ascii eq_ascii s1 s2 eq_to_eqascii).
+nqed.
+
+nlemma decidable_str : ∀x,y:list ascii.decidable (x = y).
+ napply (decidable_list ascii …);
+ napply decidable_ascii. 
+nqed.
+
+nlemma neqstr_to_neq : ∀s,s'.eq_str s s' = false → s ≠ s'.
+ #s1; #s2;
+ napply (nbfoldrightlist2_to_neq ascii eq_ascii s1 s2 …);
+ napply neqascii_to_neq.
+nqed.
+
+nlemma neq_to_neqstr : ∀s,s'.s ≠ s' → eq_str s s' = false.
+ #s1; #s2;
+ napply (neq_to_nbfoldrightlist2 ascii eq_ascii s1 s2 …);
+ ##[ ##1: napply decidable_ascii
+ ##| ##2: napply neq_to_neqascii
+ ##]
+nqed.
+
+(* ************ *)
+(* STRINGA + ID *)
+(* ************ *)
+
+nlemma strid_destruct_1 : ∀x1,x2,y1,y2.mk_strId x1 y1 = mk_strId x2 y2 → x1 = x2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_strId x2 y2 with [ mk_strId a _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma strid_destruct_2 : ∀x1,x2,y1,y2.mk_strId x1 y1 = mk_strId x2 y2 → y1 = y2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_strId x2 y2 with [ mk_strId _ b ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqstrid : symmetricT strId bool eq_strId.
+ #si1; #si2;
+ nchange with (
+  ((eq_str (str_elem si1) (str_elem si2))⊗(eq_nat (id_elem si1) (id_elem si2))) =
+  ((eq_str (str_elem si2) (str_elem si1))⊗(eq_nat (id_elem si2) (id_elem si1))));
+ nrewrite > (symmetric_eqstr (str_elem si1) (str_elem si2));
+ nrewrite > (symmetric_eqnat (id_elem si1) (id_elem si2));
+ napply refl_eq.
+nqed. 
+
+nlemma eqstrid_to_eq : ∀s,s'.eq_strId s s' = true → s = s'.
+ #si1; #si2;
+ nelim si1;
+ #l1; #n1;
+ nelim si2;
+ #l2; #n2; #H;
+ nchange in H:(%) with (((eq_str l1 l2)⊗(eq_nat n1 n2)) = true);
+ nrewrite > (eqstr_to_eq l1 l2 (andb_true_true_l … H));
+ nrewrite > (eqnat_to_eq n1 n2 (andb_true_true_r … H));
+ napply refl_eq.
+nqed.
+
+nlemma eq_to_eqstrid : ∀s,s'.s = s' → eq_strId s s' = true.
+ #si1; #si2;
+ nelim si1;
+ #l1; #n1;
+ nelim si2;
+ #l2; #n2; #H;
+ nchange with (((eq_str l1 l2)⊗(eq_nat n1 n2)) = true);
+ nrewrite > (strid_destruct_1 … H);
+ nrewrite > (strid_destruct_2 … H);
+ nrewrite > (eq_to_eqstr l2 l2 (refl_eq …));
+ nrewrite > (eq_to_eqnat n2 n2 (refl_eq …));
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma decidable_strid_aux1 : ∀s1,n1,s2,n2.s1 ≠ s2 → (mk_strId s1 n1) ≠ (mk_strId s2 n2).
+ #s1; #n1; #s2; #n2;
+ nnormalize; #H; #H1;
+ napply (H (strid_destruct_1 … H1)).
+nqed.
+
+nlemma decidable_strid_aux2 : ∀s1,n1,s2,n2.n1 ≠ n2 → (mk_strId s1 n1) ≠ (mk_strId s2 n2).
+ #s1; #n1; #s2; #n2;
+ nnormalize; #H; #H1;
+ napply (H (strid_destruct_2 … H1)).
+nqed.
+
+nlemma decidable_strid : ∀x,y:strId.decidable (x = y).
+ #x; nelim x; #s1; #n1;
+ #y; nelim y; #s2; #n2;
+ nnormalize;
+ napply (or2_elim (s1 = s2) (s1 ≠ s2) ? (decidable_str s1 s2) …);
+ ##[ ##2: #H; napply (or2_intro2 … (decidable_strid_aux1 … H))
+ ##| ##1: #H; napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_nat n1 n2) …);
+          ##[ ##2: #H1; napply (or2_intro2 … (decidable_strid_aux2 … H1))
+          ##| ##1: #H1; nrewrite > H; nrewrite > H1;
+                        napply (or2_intro1 … (refl_eq ? (mk_strId s2 n2)))
+          ##]
+ ##]
+nqed.
+
+nlemma neqstrid_to_neq : ∀sid1,sid2:strId.(eq_strId sid1 sid2 = false) → (sid1 ≠ sid2).
+ #sid1; nelim sid1; #s1; #n1;
+ #sid2; nelim sid2; #s2; #n2;
+ nchange with ((((eq_str s1 s2) ⊗ (eq_nat n1 n2)) = false) → ?);
+ #H;
+ napply (or2_elim ((eq_str s1 s2) = false) ((eq_nat n1 n2) = false) ? (andb_false2 … H) …);
+ ##[ ##1: #H1; napply (decidable_strid_aux1 … (neqstr_to_neq … H1))
+ ##| ##2: #H1; napply (decidable_strid_aux2 … (neqnat_to_neq … H1))
+ ##]
+nqed.
+
+nlemma strid_destruct : ∀s1,s2,n1,n2.(mk_strId s1 n1) ≠ (mk_strId s2 n2) → s1 ≠ s2 ∨ n1 ≠ n2.
+ #s1; #s2; #n1; #n2;
+ nnormalize; #H;
+ napply (or2_elim (s1 = s2) (s1 ≠ s2) ? (decidable_str s1 s2) …);
+ ##[ ##2: #H1; napply (or2_intro1 … H1)
+ ##| ##1: #H1; napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_nat n1 n2) …);
+          ##[ ##2: #H2; napply (or2_intro2 … H2)
+          ##| ##1: #H2; nrewrite > H1 in H:(%);
+                   nrewrite > H2;
+                   #H; nelim (H (refl_eq …))
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqstrid : ∀sid1,sid2.sid1 ≠ sid2 → eq_strId sid1 sid2 = false.
+ #sid1; nelim sid1; #s1; #n1;
+ #sid2; nelim sid2; #s2; #n2;
+ #H; nchange with (((eq_str s1 s2) ⊗ (eq_nat n1 n2)) = false);
+ napply (or2_elim (s1 ≠ s2) (n1 ≠ n2) ? (strid_destruct … H) …);
+ ##[ ##1: #H1; nrewrite > (neq_to_neqstr … H1); nnormalize; napply refl_eq
+ ##| ##2: #H1; nrewrite > (neq_to_neqnat … H1);
+          nrewrite > (symmetric_andbool (eq_str s1 s2) false);
+          nnormalize; napply refl_eq
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/common/theory.ma b/helm/software/matita/contribs/ng_assembly/common/theory.ma
new file mode 100644 (file)
index 0000000..bab796d
--- /dev/null
@@ -0,0 +1,609 @@
+(**************************************************************************)
+(*       ___                                                               *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
+(*      ||A||       E.Tassi, S.Zacchiroli                                 *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU Lesser General Public License Version 2.1         *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+universe constraint Type[0] < Type[1].
+universe constraint Type[1] < Type[2].
+universe constraint Type[2] < Type[3].
+universe constraint Type[3] < Type[4].
+
+(* ********************************** *)
+(* SOTTOINSIEME MINIMALE DELLA TEORIA *)
+(* ********************************** *)
+
+(* logic/connectives.ma *)
+
+ninductive True: Prop ≝
+ I : True.
+
+ninductive False: Prop ≝.
+
+ndefinition Not: Prop → Prop ≝
+λA.(A → False).
+
+interpretation "logical not" 'not x = (Not x).
+
+nlemma absurd : ∀A,C:Prop.A → ¬A → C.
+ #A; #C; #H;
+ nnormalize;
+ #H1;
+ nelim (H1 H).
+nqed.
+
+nlemma not_to_not : ∀A,B:Prop. (A → B) → ((¬B) → (¬A)).
+ #A; #B; #H;
+ nnormalize;
+ #H1; #H2;
+ nelim (H1 (H H2)).
+nqed.
+
+nlemma prop_to_nnprop : ∀P.P → ¬¬P.
+ #P; nnormalize; #H; #H1;
+ napply (H1 H).
+nqed.
+
+ninductive And2 (A,B:Prop) : Prop ≝
+ conj2 : A → B → (And2 A B).
+
+interpretation "logical and" 'and x y = (And2 x y).
+
+nlemma proj2_1: ∀A,B:Prop.A ∧ B → A.
+ #A; #B; #H;
+ napply (And2_ind A B … H);
+ #H1; #H2;
+ napply H1.
+nqed.
+
+nlemma proj2_2: ∀A,B:Prop.A ∧ B → B.
+ #A; #B; #H;
+ napply (And2_ind A B … H);
+ #H1; #H2;
+ napply H2.
+nqed.
+
+ninductive And3 (A,B,C:Prop) : Prop ≝
+ conj3 : A → B → C → (And3 A B C).
+
+nlemma proj3_1: ∀A,B,C:Prop.And3 A B C → A.
+ #A; #B; #C; #H;
+ napply (And3_ind A B C … H);
+ #H1; #H2; #H3;
+ napply H1.
+nqed.
+
+nlemma proj3_2: ∀A,B,C:Prop.And3 A B C → B.
+ #A; #B; #C; #H;
+ napply (And3_ind A B C … H);
+ #H1; #H2; #H3;
+ napply H2.
+nqed.
+
+nlemma proj3_3: ∀A,B,C:Prop.And3 A B C → C.
+ #A; #B; #C; #H;
+ napply (And3_ind A B C … H);
+ #H1; #H2; #H3;
+ napply H3.
+nqed.
+
+ninductive And4 (A,B,C,D:Prop) : Prop ≝
+ conj4 : A → B → C → D → (And4 A B C D).
+
+nlemma proj4_1: ∀A,B,C,D:Prop.And4 A B C D → A.
+ #A; #B; #C; #D; #H;
+ napply (And4_ind A B C D … H);
+ #H1; #H2; #H3; #H4;
+ napply H1.
+nqed.
+
+nlemma proj4_2: ∀A,B,C,D:Prop.And4 A B C D → B.
+ #A; #B; #C; #D; #H;
+ napply (And4_ind A B C D … H);
+ #H1; #H2; #H3; #H4;
+ napply H2.
+nqed.
+
+nlemma proj4_3: ∀A,B,C,D:Prop.And4 A B C D → C.
+ #A; #B; #C; #D; #H;
+ napply (And4_ind A B C D … H);
+ #H1; #H2; #H3; #H4;
+ napply H3.
+nqed.
+
+nlemma proj4_4: ∀A,B,C,D:Prop.And4 A B C D → D.
+ #A; #B; #C; #D; #H;
+ napply (And4_ind A B C D … H);
+ #H1; #H2; #H3; #H4;
+ napply H4.
+nqed.
+
+ninductive And5 (A,B,C,D,E:Prop) : Prop ≝
+ conj5 : A → B → C → D → E → (And5 A B C D E).
+
+nlemma proj5_1: ∀A,B,C,D,E:Prop.And5 A B C D E → A.
+ #A; #B; #C; #D; #E; #H;
+ napply (And5_ind A B C D E … H);
+ #H1; #H2; #H3; #H4; #H5;
+ napply H1.
+nqed.
+
+nlemma proj5_2: ∀A,B,C,D,E:Prop.And5 A B C D E → B.
+ #A; #B; #C; #D; #E; #H;
+ napply (And5_ind A B C D E … H);
+ #H1; #H2; #H3; #H4; #H5;
+ napply H2.
+nqed.
+
+nlemma proj5_3: ∀A,B,C,D,E:Prop.And5 A B C D E → C.
+ #A; #B; #C; #D; #E; #H;
+ napply (And5_ind A B C D E … H);
+ #H1; #H2; #H3; #H4; #H5;
+ napply H3.
+nqed.
+
+nlemma proj5_4: ∀A,B,C,D,E:Prop.And5 A B C D E → D.
+ #A; #B; #C; #D; #E; #H;
+ napply (And5_ind A B C D E … H);
+ #H1; #H2; #H3; #H4; #H5;
+ napply H4.
+nqed.
+
+nlemma proj5_5: ∀A,B,C,D,E:Prop.And5 A B C D E → E.
+ #A; #B; #C; #D; #E; #H;
+ napply (And5_ind A B C D E … H);
+ #H1; #H2; #H3; #H4; #H5;
+ napply H5.
+nqed.
+
+ninductive Or2 (A,B:Prop) : Prop ≝
+  or2_intro1 : A → (Or2 A B)
+| or2_intro2 : B → (Or2 A B).
+
+interpretation "logical or" 'or x y = (Or2 x y).
+
+ndefinition decidable ≝ λA:Prop.A ∨ (¬A).
+
+nlemma or2_elim
+ : ∀P1,P2,Q:Prop.Or2 P1 P2 → ∀f1:P1 → Q.∀f2:P2 → Q.Q.
+ #P1; #P2; #Q; #H; #f1; #f2;
+ napply (Or2_ind P1 P2 ? f1 f2 ?);
+ napply H.
+nqed.
+
+nlemma symmetric_or2 : ∀P1,P2.Or2 P1 P2 → Or2 P2 P1.
+ #P1; #P2; #H;
+ napply (or2_elim P1 P2 ? H);
+ ##[ ##1: #H1; napply (or2_intro2 P2 P1 H1)
+ ##| ##2: #H1; napply (or2_intro1 P2 P1 H1)
+ ##]
+nqed.
+
+ninductive Or3 (A,B,C:Prop) : Prop ≝
+  or3_intro1 : A → (Or3 A B C)
+| or3_intro2 : B → (Or3 A B C)
+| or3_intro3 : C → (Or3 A B C).
+
+nlemma or3_elim
+ : ∀P1,P2,P3,Q:Prop.Or3 P1 P2 P3 → ∀f1:P1 → Q.∀f2:P2 → Q.∀f3:P3 → Q.Q.
+ #P1; #P2; #P3; #Q; #H; #f1; #f2; #f3;
+ napply (Or3_ind P1 P2 P3 ? f1 f2 f3 ?);
+ napply H.
+nqed.
+
+nlemma symmetric_or3_12 : ∀P1,P2,P3:Prop.Or3 P1 P2 P3 → Or3 P2 P1 P3.
+ #P1; #P2; #P3; #H;
+ napply (or3_elim P1 P2 P3 ? H);
+ ##[ ##1: #H1; napply (or3_intro2 P2 P1 P3 H1)
+ ##| ##2: #H1; napply (or3_intro1 P2 P1 P3 H1)
+ ##| ##3: #H1; napply (or3_intro3 P2 P1 P3 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or3_13 : ∀P1,P2,P3:Prop.Or3 P1 P2 P3 → Or3 P3 P2 P1.
+ #P1; #P2; #P3; #H;
+ napply (or3_elim P1 P2 P3 ? H);
+ ##[ ##1: #H1; napply (or3_intro3 P3 P2 P1 H1)
+ ##| ##2: #H1; napply (or3_intro2 P3 P2 P1 H1)
+ ##| ##3: #H1; napply (or3_intro1 P3 P2 P1 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or3_23 : ∀P1,P2,P3:Prop.Or3 P1 P2 P3 → Or3 P1 P3 P2.
+ #P1; #P2; #P3; #H;
+ napply (or3_elim P1 P2 P3 ? H);
+ ##[ ##1: #H1; napply (or3_intro1 P1 P3 P2 H1)
+ ##| ##2: #H1; napply (or3_intro3 P1 P3 P2 H1)
+ ##| ##3: #H1; napply (or3_intro2 P1 P3 P2 H1)
+ ##]
+nqed.
+
+ninductive Or4 (A,B,C,D:Prop) : Prop ≝
+  or4_intro1 : A → (Or4 A B C D)
+| or4_intro2 : B → (Or4 A B C D)
+| or4_intro3 : C → (Or4 A B C D)
+| or4_intro4 : D → (Or4 A B C D).
+
+nlemma or4_elim
+ : ∀P1,P2,P3,P4,Q:Prop.Or4 P1 P2 P3 P4 → ∀f1:P1 → Q.∀f2:P2 → Q.
+   ∀f3:P3 → Q.∀f4:P4 → Q.Q.
+ #P1; #P2; #P3; #P4; #Q; #H; #f1; #f2; #f3; #f4;
+ napply (Or4_ind P1 P2 P3 P4 ? f1 f2 f3 f4 ?);
+ napply H.
+nqed.
+
+nlemma symmetric_or4_12 : ∀P1,P2,P3,P4:Prop.Or4 P1 P2 P3 P4 → Or4 P2 P1 P3 P4.
+ #P1; #P2; #P3; #P4; #H;
+ napply (or4_elim P1 P2 P3 P4 ? H);
+ ##[ ##1: #H1; napply (or4_intro2 P2 P1 P3 P4 H1)
+ ##| ##2: #H1; napply (or4_intro1 P2 P1 P3 P4 H1)
+ ##| ##3: #H1; napply (or4_intro3 P2 P1 P3 P4 H1)
+ ##| ##4: #H1; napply (or4_intro4 P2 P1 P3 P4 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or4_13 : ∀P1,P2,P3,P4:Prop.Or4 P1 P2 P3 P4 → Or4 P3 P2 P1 P4.
+ #P1; #P2; #P3; #P4; #H;
+ napply (or4_elim P1 P2 P3 P4 ? H);
+ ##[ ##1: #H1; napply (or4_intro3 P3 P2 P1 P4 H1)
+ ##| ##2: #H1; napply (or4_intro2 P3 P2 P1 P4 H1)
+ ##| ##3: #H1; napply (or4_intro1 P3 P2 P1 P4 H1)
+ ##| ##4: #H1; napply (or4_intro4 P3 P2 P1 P4 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or4_14 : ∀P1,P2,P3,P4:Prop.Or4 P1 P2 P3 P4 → Or4 P4 P2 P3 P1.
+ #P1; #P2; #P3; #P4; #H;
+ napply (or4_elim P1 P2 P3 P4 ? H);
+ ##[ ##1: #H1; napply (or4_intro4 P4 P2 P3 P1 H1)
+ ##| ##2: #H1; napply (or4_intro2 P4 P2 P3 P1 H1)
+ ##| ##3: #H1; napply (or4_intro3 P4 P2 P3 P1 H1)
+ ##| ##4: #H1; napply (or4_intro1 P4 P2 P3 P1 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or4_23 : ∀P1,P2,P3,P4:Prop.Or4 P1 P2 P3 P4 → Or4 P1 P3 P2 P4.
+ #P1; #P2; #P3; #P4; #H;
+ napply (or4_elim P1 P2 P3 P4 ? H);
+ ##[ ##1: #H1; napply (or4_intro1 P1 P3 P2 P4 H1)
+ ##| ##2: #H1; napply (or4_intro3 P1 P3 P2 P4 H1)
+ ##| ##3: #H1; napply (or4_intro2 P1 P3 P2 P4 H1)
+ ##| ##4: #H1; napply (or4_intro4 P1 P3 P2 P4 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or4_24 : ∀P1,P2,P3,P4:Prop.Or4 P1 P2 P3 P4 → Or4 P1 P4 P3 P2.
+ #P1; #P2; #P3; #P4; #H;
+ napply (or4_elim P1 P2 P3 P4 ? H);
+ ##[ ##1: #H1; napply (or4_intro1 P1 P4 P3 P2 H1)
+ ##| ##2: #H1; napply (or4_intro4 P1 P4 P3 P2 H1)
+ ##| ##3: #H1; napply (or4_intro3 P1 P4 P3 P2 H1)
+ ##| ##4: #H1; napply (or4_intro2 P1 P4 P3 P2 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or4_34 : ∀P1,P2,P3,P4:Prop.Or4 P1 P2 P3 P4 → Or4 P1 P2 P4 P3.
+ #P1; #P2; #P3; #P4; #H;
+ napply (or4_elim P1 P2 P3 P4 ? H);
+ ##[ ##1: #H1; napply (or4_intro1 P1 P2 P4 P3 H1)
+ ##| ##2: #H1; napply (or4_intro2 P1 P2 P4 P3 H1)
+ ##| ##3: #H1; napply (or4_intro4 P1 P2 P4 P3 H1)
+ ##| ##4: #H1; napply (or4_intro3 P1 P2 P4 P3 H1)
+ ##]
+nqed.
+
+ninductive Or5 (A,B,C,D,E:Prop) : Prop ≝
+  or5_intro1 : A → (Or5 A B C D E)
+| or5_intro2 : B → (Or5 A B C D E)
+| or5_intro3 : C → (Or5 A B C D E)
+| or5_intro4 : D → (Or5 A B C D E)
+| or5_intro5 : E → (Or5 A B C D E).
+
+nlemma or5_elim
+ : ∀P1,P2,P3,P4,P5,Q:Prop.Or5 P1 P2 P3 P4 P5 → ∀f1:P1 → Q.∀f2:P2 → Q.
+   ∀f3:P3 → Q.∀f4:P4 → Q.∀f5:P5 → Q.Q.
+ #P1; #P2; #P3; #P4; #P5; #Q; #H; #f1; #f2; #f3; #f4; #f5;
+ napply (Or5_ind P1 P2 P3 P4 P5 ? f1 f2 f3 f4 f5 ?);
+ napply H.
+nqed.
+
+nlemma symmetric_or5_12 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P2 P1 P3 P4 P5.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro2 P2 P1 P3 P4 P5 H1)
+ ##| ##2: #H1; napply (or5_intro1 P2 P1 P3 P4 P5 H1)
+ ##| ##3: #H1; napply (or5_intro3 P2 P1 P3 P4 P5 H1)
+ ##| ##4: #H1; napply (or5_intro4 P2 P1 P3 P4 P5 H1)
+ ##| ##5: #H1; napply (or5_intro5 P2 P1 P3 P4 P5 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_13 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P3 P2 P1 P4 P5.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro3 P3 P2 P1 P4 P5 H1)
+ ##| ##2: #H1; napply (or5_intro2 P3 P2 P1 P4 P5 H1)
+ ##| ##3: #H1; napply (or5_intro1 P3 P2 P1 P4 P5 H1)
+ ##| ##4: #H1; napply (or5_intro4 P3 P2 P1 P4 P5 H1)
+ ##| ##5: #H1; napply (or5_intro5 P3 P2 P1 P4 P5 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_14 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P4 P2 P3 P1 P5.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro4 P4 P2 P3 P1 P5 H1)
+ ##| ##2: #H1; napply (or5_intro2 P4 P2 P3 P1 P5 H1)
+ ##| ##3: #H1; napply (or5_intro3 P4 P2 P3 P1 P5 H1)
+ ##| ##4: #H1; napply (or5_intro1 P4 P2 P3 P1 P5 H1)
+ ##| ##5: #H1; napply (or5_intro5 P4 P2 P3 P1 P5 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_15 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P5 P2 P3 P4 P1.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro5 P5 P2 P3 P4 P1 H1)
+ ##| ##2: #H1; napply (or5_intro2 P5 P2 P3 P4 P1 H1)
+ ##| ##3: #H1; napply (or5_intro3 P5 P2 P3 P4 P1 H1)
+ ##| ##4: #H1; napply (or5_intro4 P5 P2 P3 P4 P1 H1)
+ ##| ##5: #H1; napply (or5_intro1 P5 P2 P3 P4 P1 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_23 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P1 P3 P2 P4 P5.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro1 P1 P3 P2 P4 P5 H1)
+ ##| ##2: #H1; napply (or5_intro3 P1 P3 P2 P4 P5 H1)
+ ##| ##3: #H1; napply (or5_intro2 P1 P3 P2 P4 P5 H1)
+ ##| ##4: #H1; napply (or5_intro4 P1 P3 P2 P4 P5 H1)
+ ##| ##5: #H1; napply (or5_intro5 P1 P3 P2 P4 P5 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_24 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P1 P4 P3 P2 P5.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro1 P1 P4 P3 P2 P5 H1)
+ ##| ##2: #H1; napply (or5_intro4 P1 P4 P3 P2 P5 H1)
+ ##| ##3: #H1; napply (or5_intro3 P1 P4 P3 P2 P5 H1)
+ ##| ##4: #H1; napply (or5_intro2 P1 P4 P3 P2 P5 H1)
+ ##| ##5: #H1; napply (or5_intro5 P1 P4 P3 P2 P5 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_25 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P1 P5 P3 P4 P2.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro1 P1 P5 P3 P4 P2 H1)
+ ##| ##2: #H1; napply (or5_intro5 P1 P5 P3 P4 P2 H1)
+ ##| ##3: #H1; napply (or5_intro3 P1 P5 P3 P4 P2 H1)
+ ##| ##4: #H1; napply (or5_intro4 P1 P5 P3 P4 P2 H1)
+ ##| ##5: #H1; napply (or5_intro2 P1 P5 P3 P4 P2 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_34 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P1 P2 P4 P3 P5.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro1 P1 P2 P4 P3 P5 H1)
+ ##| ##2: #H1; napply (or5_intro2 P1 P2 P4 P3 P5 H1)
+ ##| ##3: #H1; napply (or5_intro4 P1 P2 P4 P3 P5 H1)
+ ##| ##4: #H1; napply (or5_intro3 P1 P2 P4 P3 P5 H1)
+ ##| ##5: #H1; napply (or5_intro5 P1 P2 P4 P3 P5 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_35 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P1 P2 P5 P4 P3.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro1 P1 P2 P5 P4 P3 H1)
+ ##| ##2: #H1; napply (or5_intro2 P1 P2 P5 P4 P3 H1)
+ ##| ##3: #H1; napply (or5_intro5 P1 P2 P5 P4 P3 H1)
+ ##| ##4: #H1; napply (or5_intro4 P1 P2 P5 P4 P3 H1)
+ ##| ##5: #H1; napply (or5_intro3 P1 P2 P5 P4 P3 H1)
+ ##]
+nqed.
+
+nlemma symmetric_or5_45 : ∀P1,P2,P3,P4,P5:Prop.Or5 P1 P2 P3 P4 P5 → Or5 P1 P2 P3 P5 P4.
+ #P1; #P2; #P3; #P4; #P5; #H;
+ napply (or5_elim P1 P2 P3 P4 P5 ? H);
+ ##[ ##1: #H1; napply (or5_intro1 P1 P2 P3 P5 P4 H1)
+ ##| ##2: #H1; napply (or5_intro2 P1 P2 P3 P5 P4 H1)
+ ##| ##3: #H1; napply (or5_intro3 P1 P2 P3 P5 P4 H1)
+ ##| ##4: #H1; napply (or5_intro5 P1 P2 P3 P5 P4 H1)
+ ##| ##5: #H1; napply (or5_intro4 P1 P2 P3 P5 P4 H1)
+ ##]
+nqed.
+
+ninductive ex (A:Type) (Q:A → Prop) : Prop ≝
+ ex_intro: ∀x:A.Q x → ex A Q.
+
+interpretation "exists" 'exists x = (ex ? x).
+
+ninductive ex2 (A:Type) (Q,R:A → Prop) : Prop ≝
+ ex_intro2: ∀x:A.Q x → R x → ex2 A Q R.
+
+(* higher_order_defs/relations *)
+
+ndefinition relation : Type → Type ≝
+λA.A → A → Prop. 
+
+ndefinition reflexive : ∀A:Type.∀R:relation A.Prop ≝
+λA.λR.∀x:A.R x x.
+
+ndefinition symmetric : ∀A:Type.∀R:relation A.Prop ≝
+λA.λR.∀x,y:A.R x y → R y x.
+
+ndefinition transitive : ∀A:Type.∀R:relation A.Prop ≝
+λA.λR.∀x,y,z:A.R x y → R y z → R x z.
+
+ndefinition irreflexive : ∀A:Type.∀R:relation A.Prop ≝
+λA.λR.∀x:A.¬ (R x x).
+
+ndefinition cotransitive : ∀A:Type.∀R:relation A.Prop ≝
+λA.λR.∀x,y:A.R x y → ∀z:A. R x z ∨ R z y.
+
+ndefinition tight_apart : ∀A:Type.∀eq,ap:relation A.Prop ≝
+λA.λeq,ap.∀x,y:A. (¬ (ap x y) → eq x y) ∧ (eq x y → ¬ (ap x y)).
+
+ndefinition antisymmetric : ∀A:Type.∀R:relation A.Prop ≝
+λA.λR.∀x,y:A.R x y → ¬ (R y x).
+
+(* logic/equality.ma *)
+
+ninductive eq (A:Type) (x:A) : A → Prop ≝
+ refl_eq : eq A x x.
+
+ndefinition refl ≝ refl_eq.
+
+interpretation "leibnitz's equality" 'eq t x y = (eq t x y).
+
+interpretation "leibnitz's non-equality" 'neq t x y = (Not (eq t x y)).
+
+nlemma eq_f : ∀T1,T2:Type.∀x,y:T1.∀f:T1 → T2.x = y → (f x) = (f y).
+ #T1; #T2; #x; #y; #f; #H;
+ nrewrite < H;
+ napply refl_eq.
+nqed.
+
+nlemma eq_f2 : ∀T1,T2,T3:Type.∀x1,y1:T1.∀x2,y2:T2.∀f:T1 → T2 → T3.x1 = y1 → x2 = y2 → f x1 x2 = f y1 y2.
+ #T1; #T2; #T3; #x1; #y1; #x2; #y2; #f; #H1; #H2;
+ nrewrite < H1;
+ nrewrite < H2;
+ napply refl_eq.
+nqed.
+
+nlemma neqf_to_neq : ∀T1,T2:Type.∀x,y:T1.∀f:T1 → T2.((f x) ≠ (f y)) → x ≠ y.
+ #T1; #T2; #x; #y; #f;
+ nnormalize; #H; #H1;
+ napply (H (eq_f … H1)).
+nqed.
+
+nlemma symmetric_eq: ∀A:Type. symmetric A (eq A).
+ #A;
+ nnormalize;
+ #x; #y; #H;
+ nrewrite < H;
+ napply refl_eq.
+nqed.
+
+nlemma eq_ind_r: ∀A:Type[0].∀x:A.∀P:A → Prop.P x → ∀y:A.y=x → P y.
+ #A; #x; #P; #H; #y; #H1;
+ nrewrite < (symmetric_eq … H1);
+ napply H.
+nqed.
+
+ndefinition R0 ≝ λT:Type[0].λt:T.t.
+
+ndefinition R1 ≝ eq_rect_Type0.
+
+ndefinition R2 :
+  ∀T0:Type[0].
+  ∀a0:T0.
+  ∀T1:∀x0:T0. a0=x0 → Type[0].
+  ∀a1:T1 a0 (refl_eq ? a0).
+  ∀T2:∀x0:T0. ∀p0:a0=x0. ∀x1:T1 x0 p0. R1 ?? T1 a1 ? p0 = x1 → Type[0].
+  ∀a2:T2 a0 (refl_eq ? a0) a1 (refl_eq ? a1).
+  ∀b0:T0.
+  ∀e0:a0 = b0.
+  ∀b1: T1 b0 e0.
+  ∀e1:R1 ?? T1 a1 ? e0 = b1.
+  T2 b0 e0 b1 e1.
+ #T0;#a0;#T1;#a1;#T2;#a2;#b0;#e0;#b1;#e1;
+ napply (eq_rect_Type0 ????? e1);
+ napply (R1 ?? ? ?? e0);
+ napply a2;
+nqed.
+
+ndefinition R3 :
+  ∀T0:Type[0].
+  ∀a0:T0.
+  ∀T1:∀x0:T0. a0=x0 → Type[0].
+  ∀a1:T1 a0 (refl_eq ? a0).
+  ∀T2:∀x0:T0. ∀p0:a0=x0. ∀x1:T1 x0 p0. R1 ?? T1 a1 ? p0 = x1 → Type[0].
+  ∀a2:T2 a0 (refl_eq ? a0) a1 (refl_eq ? a1).
+  ∀T3:∀x0:T0. ∀p0:a0=x0. ∀x1:T1 x0 p0.∀p1:R1 ?? T1 a1 ? p0 = x1.
+      ∀x2:T2 x0 p0 x1 p1.R2 ???? T2 a2 x0 p0 ? p1 = x2 → Type[0].
+  ∀a3:T3 a0 (refl_eq ? a0) a1 (refl_eq ? a1) a2 (refl_eq ? a2).
+  ∀b0:T0.
+  ∀e0:a0 = b0.
+  ∀b1: T1 b0 e0.
+  ∀e1:R1 ?? T1 a1 ? e0 = b1.
+  ∀b2: T2 b0 e0 b1 e1.
+  ∀e2:R2 ???? T2 a2 b0 e0 ? e1 = b2.
+  T3 b0 e0 b1 e1 b2 e2.
+ #T0;#a0;#T1;#a1;#T2;#a2;#T3;#a3;#b0;#e0;#b1;#e1;#b2;#e2;
+ napply (eq_rect_Type0 ????? e2);
+ napply (R2 ?? ? ???? e0 ? e1);
+ napply a3;
+nqed.
+
+ndefinition R4 :
+  ∀T0:Type[0].
+  ∀a0:T0.
+  ∀T1:∀x0:T0. eq T0 a0 x0 → Type[0].
+  ∀a1:T1 a0 (refl_eq T0 a0).
+  ∀T2:∀x0:T0. ∀p0:eq (T0 …) a0 x0. ∀x1:T1 x0 p0.eq (T1 …) (R1 T0 a0 T1 a1 x0 p0) x1 → Type[0].
+  ∀a2:T2 a0 (refl_eq T0 a0) a1 (refl_eq (T1 a0 (refl_eq T0 a0)) a1).
+  ∀T3:∀x0:T0. ∀p0:eq (T0 …) a0 x0. ∀x1:T1 x0 p0.∀p1:eq (T1 …) (R1 T0 a0 T1 a1 x0 p0) x1.
+      ∀x2:T2 x0 p0 x1 p1.eq (T2 …) (R2 T0 a0 T1 a1 T2 a2 x0 p0 x1 p1) x2 → Type[0].
+  ∀a3:T3 a0 (refl_eq T0 a0) a1 (refl_eq (T1 a0 (refl_eq T0 a0)) a1) 
+      a2 (refl_eq (T2 a0 (refl_eq T0 a0) a1 (refl_eq (T1 a0 (refl_eq T0 a0)) a1)) a2). 
+  ∀T4:∀x0:T0. ∀p0:eq (T0 …) a0 x0. ∀x1:T1 x0 p0.∀p1:eq (T1 …) (R1 T0 a0 T1 a1 x0 p0) x1.
+      ∀x2:T2 x0 p0 x1 p1.∀p2:eq (T2 …) (R2 T0 a0 T1 a1 T2 a2 x0 p0 x1 p1) x2.
+      ∀x3:T3 x0 p0 x1 p1 x2 p2.∀p3:eq (T3 …) (R3 T0 a0 T1 a1 T2 a2 T3 a3 x0 p0 x1 p1 x2 p2) x3. 
+      Type[0].
+  ∀a4:T4 a0 (refl_eq T0 a0) a1 (refl_eq (T1 a0 (refl_eq T0 a0)) a1) 
+      a2 (refl_eq (T2 a0 (refl_eq T0 a0) a1 (refl_eq (T1 a0 (refl_eq T0 a0)) a1)) a2) 
+      a3 (refl_eq (T3 a0 (refl_eq T0 a0) a1 (refl_eq (T1 a0 (refl_eq T0 a0)) a1) 
+                   a2 (refl_eq (T2 a0 (refl_eq T0 a0) a1 (refl_eq (T1 a0 (refl_eq T0 a0)) a1)) a2))
+                   a3).
+  ∀b0:T0.
+  ∀e0:eq (T0 …) a0 b0.
+  ∀b1: T1 b0 e0.
+  ∀e1:eq (T1 …) (R1 T0 a0 T1 a1 b0 e0) b1.
+  ∀b2: T2 b0 e0 b1 e1.
+  ∀e2:eq (T2 …) (R2 T0 a0 T1 a1 T2 a2 b0 e0 b1 e1) b2.
+  ∀b3: T3 b0 e0 b1 e1 b2 e2.
+  ∀e3:eq (T3 …) (R3 T0 a0 T1 a1 T2 a2 T3 a3 b0 e0 b1 e1 b2 e2) b3.
+  T4 b0 e0 b1 e1 b2 e2 b3 e3.
+ #T0;#a0;#T1;#a1;#T2;#a2;#T3;#a3;#T4;#a4;#b0;#e0;#b1;#e1;#b2;#e2;#b3;#e3;
+ napply (eq_rect_Type0 ????? e3);
+ napply (R3 ????????? e0 ? e1 ? e2);
+ napply a4;
+nqed.
+
+nlemma symmetric_neq : ∀T:Type.∀x,y:T.x ≠ y → y ≠ x.
+ #T; #x; #y;
+ nnormalize;
+ #H; #H1;
+ nrewrite > H1 in H:(%); #H;
+ napply (H (refl_eq …)).
+nqed.
+
+ndefinition relationT : Type → Type → Type ≝
+λA,T:Type.A → A → T.
+
+ndefinition symmetricT: ∀A,T:Type.∀R:relationT A T.Prop ≝
+λA,T.λR.∀x,y:A.R x y = R y x.
+
+ndefinition associative : ∀A:Type.∀R:relationT A A.Prop ≝
+λA.λR.∀x,y,z:A.R (R x y) z = R x (R y z).
diff --git a/helm/software/matita/contribs/ng_assembly/compiler/ast_type.ma b/helm/software/matita/contribs/ng_assembly/compiler/ast_type.ma
new file mode 100755 (executable)
index 0000000..2d4eafd
--- /dev/null
@@ -0,0 +1,136 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/list_utility.ma".
+
+(* ************************* *)
+(* dimensioni degli elementi *)
+(* ************************* *)
+
+(* usato per definire nell'ast *)
+ninductive ast_base_type : Type ≝
+  AST_BASE_TYPE_BYTE8: ast_base_type
+| AST_BASE_TYPE_WORD16: ast_base_type
+| AST_BASE_TYPE_WORD32: ast_base_type.
+
+ninductive ast_type : Type ≝
+  AST_TYPE_BASE: ast_base_type → ast_type
+| AST_TYPE_ARRAY: ast_type → nat → ast_type
+| AST_TYPE_STRUCT: ne_list ast_type → ast_type.
+
+(* principio di eliminazione arricchito *)
+nlet rec ast_type_index_aux (P:ast_type → Prop)
+                            (f:Πt.P t → P (AST_TYPE_STRUCT (ne_nil ? t)))
+                            (f1:Πh,t.P h → P (AST_TYPE_STRUCT t) → P (AST_TYPE_STRUCT (ne_cons ? h t)))
+                            (f2:Πt.P t)
+                            (t:ne_list ast_type) on t ≝
+ match t return λt.P (AST_TYPE_STRUCT t) with
+  [ ne_nil h ⇒ f h (f2 h)
+  | ne_cons h t ⇒ f1 h t (f2 h) (ast_type_index_aux P f f1 f2 t)
+  ].
+
+nlet rec ast_type_index (P:ast_type → Prop)
+                        (f:Πb.P (AST_TYPE_BASE b))
+                        (f1:Πt,n.P t → P (AST_TYPE_ARRAY t n))
+                        (f2:Πt.P t → P (AST_TYPE_STRUCT (ne_nil ? t)))
+                        (f3:Πh,t.P h → P (AST_TYPE_STRUCT t) → P (AST_TYPE_STRUCT (ne_cons ? h t)))
+                        (t:ast_type) on t : P t ≝
+ match t return λt.P t with
+  [ AST_TYPE_BASE b ⇒ f b
+  | AST_TYPE_ARRAY t' n ⇒ f1 t' n (ast_type_index P f f1 f2 f3 t')
+  | AST_TYPE_STRUCT nl ⇒ match nl with
+   [ ne_nil h ⇒ f2 h (ast_type_index P f f1 f2 f3 h)
+   | ne_cons h t ⇒ f3 h t (ast_type_index P f f1 f2 f3 h) (ast_type_index_aux P f2 f3 (ast_type_index P f f1 f2 f3) t)
+   ]
+  ]. 
+
+nlet rec ast_type_rectex_aux (P:ast_type → Type)
+                             (f:Πt.P t → P (AST_TYPE_STRUCT (ne_nil ? t)))
+                             (f1:Πh,t.P h → P (AST_TYPE_STRUCT t) → P (AST_TYPE_STRUCT (ne_cons ? h t)))
+                             (f2:Πt.P t)
+                             (t:ne_list ast_type) on t ≝
+ match t return λt.P (AST_TYPE_STRUCT t) with
+  [ ne_nil h ⇒ f h (f2 h)
+  | ne_cons h t ⇒ f1 h t (f2 h) (ast_type_rectex_aux P f f1 f2 t)
+  ].
+
+nlet rec ast_type_rectex (P:ast_type → Type)
+                         (f:Πb.P (AST_TYPE_BASE b))
+                         (f1:Πt,n.P t → P (AST_TYPE_ARRAY t n))
+                         (f2:Πt.P t → P (AST_TYPE_STRUCT (ne_nil ? t)))
+                         (f3:Πh,t.P h → P (AST_TYPE_STRUCT t) → P (AST_TYPE_STRUCT (ne_cons ? h t)))
+                         (t:ast_type) on t : P t ≝
+ match t return λt.P t with
+  [ AST_TYPE_BASE b ⇒ f b
+  | AST_TYPE_ARRAY t' n ⇒ f1 t' n (ast_type_rectex P f f1 f2 f3 t')
+  | AST_TYPE_STRUCT nl ⇒ match nl with
+   [ ne_nil h ⇒ f2 h (ast_type_rectex P f f1 f2 f3 h)
+   | ne_cons h t ⇒ f3 h t (ast_type_rectex P f f1 f2 f3 h) (ast_type_rectex_aux P f2 f3 (ast_type_rectex P f f1 f2 f3) t)
+   ]
+  ]. 
+
+ndefinition eq_astbasetype ≝
+λt1,t2:ast_base_type.match t1 with
+ [ AST_BASE_TYPE_BYTE8 ⇒ match t2 with [ AST_BASE_TYPE_BYTE8 ⇒ true | _ ⇒ false ]
+ | AST_BASE_TYPE_WORD16 ⇒ match t2 with [ AST_BASE_TYPE_WORD16 ⇒ true | _ ⇒ false ]
+ | AST_BASE_TYPE_WORD32 ⇒ match t2 with [ AST_BASE_TYPE_WORD32 ⇒ true | _ ⇒ false ]
+ ].
+
+nlet rec eq_asttype (t1,t2:ast_type) on t1 ≝
+ match t1 with
+  [ AST_TYPE_BASE bType1 ⇒ match t2 with
+   [ AST_TYPE_BASE bType2 ⇒ eq_astbasetype bType1 bType2
+   | _ ⇒ false ]
+  | AST_TYPE_ARRAY subType1 dim1 ⇒ match t2 with
+   [ AST_TYPE_ARRAY subType2 dim2 ⇒ (eq_asttype subType1 subType2) ⊗ (eq_nat dim1 dim2)
+   | _ ⇒ false ]
+  | AST_TYPE_STRUCT nelSubType1 ⇒ match t2 with
+   [ AST_TYPE_STRUCT nelSubType2 ⇒ bfold_right_neList2 ? (λx1,x2.eq_asttype x1 x2) nelSubType1 nelSubType2
+   | _ ⇒ false
+   ]
+  ].
+
+ndefinition is_ast_base_type ≝
+λast:ast_type.match ast with [ AST_TYPE_BASE _ ⇒ True | _ ⇒ False ].
+
+ndefinition isb_ast_base_type ≝
+λast:ast_type.match ast with [ AST_TYPE_BASE _ ⇒ true | _ ⇒ false ].
+
+ndefinition isnt_ast_base_type ≝
+λast:ast_type.match ast with [ AST_TYPE_BASE _ ⇒ False | _ ⇒ True ].
+
+ndefinition isntb_ast_base_type ≝
+λast:ast_type.match ast with [ AST_TYPE_BASE _ ⇒ false | _ ⇒ true ].
+
+ndefinition eval_size_base_type ≝
+λast:ast_base_type.match ast with
+ [ AST_BASE_TYPE_BYTE8 ⇒ nat1
+ | AST_BASE_TYPE_WORD16 ⇒ nat2
+ | AST_BASE_TYPE_WORD32 ⇒ nat4
+ ].
+
+nlet rec eval_size_type (ast:ast_type) on ast ≝
+ match ast with
+  [ AST_TYPE_BASE b ⇒ eval_size_base_type b
+  | AST_TYPE_ARRAY sub_ast dim ⇒ (dim + nat1)*(eval_size_type sub_ast)
+  | AST_TYPE_STRUCT nel_ast ⇒ fold_right_neList … (λt,x.(eval_size_type t)+x) O nel_ast
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/compiler/ast_type_lemmas.ma b/helm/software/matita/contribs/ng_assembly/compiler/ast_type_lemmas.ma
new file mode 100755 (executable)
index 0000000..4bc55e2
--- /dev/null
@@ -0,0 +1,309 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "compiler/ast_type.ma".
+include "common/list_utility_lemmas.ma".
+
+(* ************************* *)
+(* dimensioni degli elementi *)
+(* ************************* *)
+
+(*
+ndefinition astbasetype_destruct_aux ≝
+Πb1,b2:ast_base_type.ΠP:Prop.b1 = b2 →
+ match eq_astbasetype b1 b2 with [ true ⇒ P → P | false ⇒ P ].
+
+ndefinition astbasetype_destruct : astbasetype_destruct_aux.
+ #b1; #b2; #P; #H;
+ nrewrite < H;
+ nelim b1;
+ nnormalize;
+ napply (λx.x).
+nqed.
+*)
+
+nlemma eq_to_eqastbasetype : ∀n1,n2.n1 = n2 → eq_astbasetype n1 n2 = true.
+ #n1; #n2; #H;
+ nrewrite > H;
+ nelim n2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma neqastbasetype_to_neq : ∀n1,n2.eq_astbasetype n1 n2 = false → n1 ≠ n2.
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_astbasetype n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqastbasetype n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqastbasetype_to_eq : ∀b1,b2.eq_astbasetype b1 b2 = true → b1 = b2.
+ #b1; #b2; ncases b1; ncases b2; nnormalize;
+ ##[ ##1,5,9: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma neq_to_neqastbasetype : ∀n1,n2.n1 ≠ n2 → eq_astbasetype n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_astbasetype n1 n2));
+ napply (not_to_not (eq_astbasetype n1 n2 = true) (n1 = n2) ? H);
+ napply (eqastbasetype_to_eq n1 n2).
+nqed.
+
+nlemma decidable_astbasetype : ∀x,y:ast_base_type.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_astbasetype x y = true) (eq_astbasetype x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqastbasetype_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqastbasetype_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqastbasetype : symmetricT ast_base_type bool eq_astbasetype.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_astbasetype n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqastbasetype n1 n2 H);
+          napply (symmetric_eq ? (eq_astbasetype n2 n1) false);
+          napply (neq_to_neqastbasetype n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
+
+nlemma asttype_destruct_base_base : ∀b1,b2.AST_TYPE_BASE b1 = AST_TYPE_BASE b2 → b1 = b2.
+ #b1; #b2; #H;
+ nchange with (match AST_TYPE_BASE b2 with [ AST_TYPE_BASE a ⇒ b1 = a | _ ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma asttype_destruct_array_array_1 : ∀x1,x2,y1,y2.AST_TYPE_ARRAY x1 y1 = AST_TYPE_ARRAY x2 y2 → x1 = x2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match AST_TYPE_ARRAY x2 y2 with [ AST_TYPE_ARRAY a _ ⇒ x1 = a | _ ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma asttype_destruct_array_array_2 : ∀x1,x2,y1,y2.AST_TYPE_ARRAY x1 y1 = AST_TYPE_ARRAY x2 y2 → y1 = y2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match AST_TYPE_ARRAY x2 y2 with [ AST_TYPE_ARRAY _ b ⇒ y1 = b | _ ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma asttype_destruct_struct_struct : ∀b1,b2.AST_TYPE_STRUCT b1 = AST_TYPE_STRUCT b2 → b1 = b2.
+ #b1; #b2; #H;
+ nchange with (match AST_TYPE_STRUCT b2 with [ AST_TYPE_STRUCT a ⇒ b1 = a | _ ⇒ False ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+(*
+ndefinition asttype_destruct_aux ≝
+Πb1,b2:ast_type.ΠP:Prop.b1 = b2 →
+ match eq_asttype b1 b2 with [ true ⇒ P → P | false ⇒ P ].
+
+ndefinition asttype_destruct : asttype_destruct_aux.
+ #b1; #b2; #P; #H;
+ nrewrite > H;
+ napply (ast_type_index … b2);
+ ##[ ##1: #e; nchange with (match eq_astbasetype e e with [ true ⇒ P → P | false ⇒ P ]);
+          nrewrite > (eq_to_eqastbasetype e e (refl_eq …));
+          nnormalize; napply (λx.x);
+ ##| ##2: #e; #n; #H; nchange with (match (eq_asttype e e)⊗(eq_nat n n) with [ true ⇒ P → P | false ⇒ P]);
+          nrewrite > (eq_to_eqnat n n (refl_eq …));
+          nrewrite > (symmetric_andbool (eq_asttype e e) true);
+          nchange with (match eq_asttype e e with [ true ⇒ P → P | false ⇒ P]);
+          napply H;
+ ##| ##3: #e; #H; nchange with (match eq_asttype e e with [ true ⇒ P → P | false ⇒ P]);
+          napply H;
+ ##| ##4: #hh; #tt; #H;
+          nchange with (match bfold_right_neList2 ?? tt tt with [ true ⇒ P → P | false ⇒ P ] →
+                        match (eq_asttype hh hh)⊗(bfold_right_neList2 ?? tt tt) with [ true ⇒ P → P | false ⇒ P ]);
+          #H1;
+          ncases (eq_asttype hh hh) in H:(%) ⊢ %; #H;
+          ncases (bfold_right_neList2 ? (λx1,x2.eq_asttype x1 x2) tt tt) in H1:(%) ⊢ %; #H1;
+          ##[ ##1: nnormalize; napply (λx.x);
+          ##| ##3: nnormalize in H:(%) ⊢ %; napply H
+          ##| ##*: nnormalize in H1:(%) ⊢ %; napply H1
+          ##]
+ ##]
+nqed.
+*)
+
+nlemma eq_to_eqasttype_aux1
+ : ∀nl1,nl2.
+  ((eq_asttype (AST_TYPE_STRUCT nl1) (AST_TYPE_STRUCT nl2)) = true) →
+  ((bfold_right_neList2 ? (λx,y.eq_asttype x y) nl1 nl2) = true).
+ #nl1; #nl2; #H;
+ napply H.
+nqed.
+
+nlemma eq_to_eqasttype : ∀t1,t2.t1 = t2 → eq_asttype t1 t2 = true.
+ #t1;
+ napply (ast_type_index … t1);
+ ##[ ##1: #b1; #t2; ncases t2;
+          ##[ ##1: #b2; #H; nrewrite > (asttype_destruct_base_base … H);
+                   nchange with ((eq_astbasetype b2 b2) = true);
+                   nrewrite > (eq_to_eqastbasetype b2 b2 (refl_eq …));
+                   napply refl_eq
+          ##| ##2: #st2; #n2; #H; ndestruct (*napply (asttype_destruct … H)*)
+          ##| ##3: #nl2; #H; ndestruct (*napply (asttype_destruct … H)*)
+          ##]
+ ##| ##2: #st1; #n1; #H; #t2; ncases t2;
+          ##[ ##2: #st2; #n2; #H1;  nchange with (((eq_asttype st1 st2)⊗(eq_nat n1 n2)) = true);
+                   nrewrite > (H st2 (asttype_destruct_array_array_1 … H1));
+                   nrewrite > (eq_to_eqnat n1 n2 (asttype_destruct_array_array_2 … H1));
+                   nnormalize;
+                   napply refl_eq
+          ##| ##1: #b2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
+          ##| ##3: #nl2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
+          ##]
+ ##| ##3: #hh1; #H; #t2; ncases t2;
+          ##[ ##3: #nl2; ncases nl2;
+                   ##[ ##1: #hh2; #H1; nchange with ((eq_asttype hh1 hh2) = true);
+                            nrewrite > (H hh2 (nelist_destruct_nil_nil ? hh1 hh2 (asttype_destruct_struct_struct … H1)));
+                            napply refl_eq
+                   ##| ##2: #hh2; #ll2; #H1;
+                            (* !!! ndestruct non va *)
+                            nelim (nelist_destruct_nil_cons ? hh1 hh2 ll2 (asttype_destruct_struct_struct … H1))
+                   ##]
+          ##| ##1: #b2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
+          ##| ##2: #st2; #n2; #H1; ndestruct (*napply (asttype_destruct … H1)*)
+          ##]
+ ##| ##4: #hh1; #ll1; #H; #H1; #t2; ncases t2;
+          ##[ ##3: #nl2; ncases nl2;
+                   ##[ ##1: #hh2; #H2;
+                            (* !!! ndestruct non va *)
+                            nelim (nelist_destruct_cons_nil ? hh1 hh2 ll1 (asttype_destruct_struct_struct … H2))
+                   ##| ##2: #hh2; #ll2; #H2; nchange with (((eq_asttype hh1 hh2)⊗(bfold_right_neList2 ? (λx,y.eq_asttype x y) ll1 ll2)) = true);
+                            nrewrite > (H hh2 (nelist_destruct_cons_cons_1 … (asttype_destruct_struct_struct … H2)));
+                            nrewrite > (eq_to_eqasttype_aux1 ll1 ll2 (H1 (AST_TYPE_STRUCT ll2) ?));
+                            ##[ ##1: nnormalize; napply refl_eq
+                            ##| ##2: nrewrite > (nelist_destruct_cons_cons_2 … (asttype_destruct_struct_struct … H2));
+                                     napply refl_eq
+                            ##]
+                   ##]
+          ##| ##1: #b2; #H2; ndestruct (*napply (asttype_destruct … H2)*)
+          ##| ##2: #st2; #n2; #H2; ndestruct (*napply (asttype_destruct … H2)*)
+          ##]
+ ##]
+nqed.
+
+nlemma neqasttype_to_neq : ∀n1,n2.eq_asttype n1 n2 = false → n1 ≠ n2.
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_asttype n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqasttype n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqasttype_to_eq : ∀t1,t2.eq_asttype t1 t2 = true → t1 = t2.
+ #t1;
+ napply (ast_type_index … t1);
+ ##[ ##1: #b1; #t2; ncases t2;
+          ##[ ##1: #b2; #H; nchange in H:(%) with ((eq_astbasetype b1 b2) = true);
+                   nrewrite > (eqastbasetype_to_eq b1 b2 H);
+                   napply refl_eq
+          ##| ##2: #st2; #n2; nnormalize; #H; ndestruct (*napply (bool_destruct … H)*)
+          ##| ##3: #nl2; nnormalize; #H; ndestruct (*napply (bool_destruct … H)*)
+          ##]
+ ##| ##2: #st1; #n1; #H; #t2; ncases t2;
+          ##[ ##2: #st2; #n2; #H1; nchange in H1:(%) with (((eq_asttype st1 st2)⊗(eq_nat n1 n2)) = true);
+                   nrewrite > (H st2 (andb_true_true_l … H1));
+                   nrewrite > (eqnat_to_eq n1 n2 (andb_true_true_r … H1));
+                   napply refl_eq
+          ##| ##1: #b2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+          ##| ##3: #nl2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+          ##]
+ ##| ##3: #hh1; #H; #t2; ncases t2;
+          ##[ ##3: #nl2; ncases nl2;
+                   ##[ ##1: #hh2; #H1; nchange in H1:(%) with ((eq_asttype hh1 hh2) = true);
+                            nrewrite > (H hh2 H1);
+                            napply refl_eq
+                   ##| ##2: #hh2; #ll2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+                   ##]
+          ##| ##1: #b2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+          ##| ##2: #st2; #n2; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+          ##]
+ ##| ##4: #hh1; #ll1; #H; #H1; #t2; ncases t2;
+          ##[ ##3: #nl2; ncases nl2;
+                   ##[ ##1: #hh2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
+                   ##| ##2: #hh2; #ll2; #H2; nchange in H2:(%) with (((eq_asttype hh1 hh2)⊗(bfold_right_neList2 ? (λx,y.eq_asttype x y) ll1 ll2)) = true);
+                            nrewrite > (H hh2 (andb_true_true_l … H2));
+                            nrewrite > (asttype_destruct_struct_struct ll1 ll2 (H1 (AST_TYPE_STRUCT ll2) (andb_true_true_r … H2)));
+                            napply refl_eq
+                   ##]
+          ##| ##1: #b2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
+          ##| ##2: #st2; #n2; nnormalize; #H2; ndestruct (*napply (bool_destruct … H2)*)
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqasttype : ∀n1,n2.n1 ≠ n2 → eq_asttype n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_asttype n1 n2));
+ napply (not_to_not (eq_asttype n1 n2 = true) (n1 = n2) ? H);
+ napply (eqasttype_to_eq n1 n2).
+nqed.
+
+nlemma decidable_asttype : ∀x,y:ast_type.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_asttype x y = true) (eq_asttype x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqasttype_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqasttype_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqasttype : symmetricT ast_type bool eq_asttype.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_asttype n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqasttype n1 n2 H);
+          napply (symmetric_eq ? (eq_asttype n2 n1) false);
+          napply (neq_to_neqasttype n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
+
+nlemma isbastbasetype_to_isastbasetype : ∀ast.isb_ast_base_type ast = true → is_ast_base_type ast.
+ #ast;
+ ncases ast;
+ nnormalize;
+ ##[ ##1: #t; #H; napply I
+ ##| ##2: #t; #n; #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##3: #t; #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma isntbastbasetype_to_isntastbasetype : ∀ast.isntb_ast_base_type ast = true → isnt_ast_base_type ast.
+ #ast;
+ ncases ast;
+ nnormalize;
+ ##[ ##1: #t; #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##2: #t; #n; #H; napply I
+ ##| ##3: #l; #H; napply I
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/compiler/environment.ma b/helm/software/matita/contribs/ng_assembly/compiler/environment.ma
new file mode 100755 (executable)
index 0000000..5b14089
--- /dev/null
@@ -0,0 +1,65 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/string.ma".
+include "compiler/ast_type.ma".
+
+(* ***************** *)
+(* GESTIONE AMBIENTE *)
+(* ***************** *)
+
+(* elemento: name + const + type *)
+nrecord envDsc : Type ≝
+ {
+ nameDsc: aux_str_type;
+ constDsc: bool;
+ typeDsc: ast_type
+ }.
+
+(* ambiente globale: (ambiente base + ambienti annidati) *)
+ninductive env_list : nat → Type ≝
+  env_nil: list envDsc → env_list O
+| env_cons: ∀n.list envDsc → env_list n → env_list (S n).
+
+ndefinition defined_envList ≝
+λd.λl:env_list d.match l with [ env_nil _ ⇒ False | env_cons _ _ _ ⇒ True ].
+
+(* bisogna bypassare la carenza di inversion *)
+nlemma defined_envList_S : ∀d.∀l:env_list (S d).defined_envList (S d) l.
+ #d; #l;
+ ngeneralize in match (refl_eq ? (S d));
+ ncases l in ⊢ (? ? % ? → %);
+ ##[ ##1: #dsc; #H; ndestruct (*nelim (nat_destruct_0_S … H)*)
+ ##| ##2: #n; #dsc; #sub; #H;
+          nnormalize;
+          napply I
+ ##]
+nqed.
+
+ndefinition cut_first_envList_aux : Πd.env_list (S d) → env_list d ≝
+λd.λl:env_list (S d).
+  match l
+   return λX.λY:env_list X.defined_envList X Y → env_list (pred X)
+  with
+   [ env_nil h ⇒ λp:defined_envList O (env_nil h).False_rect_Type0 ? p
+   | env_cons n h t ⇒ λp:defined_envList (S n) (env_cons n h t).t
+   ] (defined_envList_S d l).
diff --git a/helm/software/matita/contribs/ng_assembly/compiler/preast_tree.ma b/helm/software/matita/contribs/ng_assembly/compiler/preast_tree.ma
new file mode 100755 (executable)
index 0000000..aa11418
--- /dev/null
@@ -0,0 +1,115 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/string.ma".
+include "compiler/ast_type.ma".
+include "num/word32.ma".
+
+(* ****************** *)
+(* PREALBERO DI TOKEN *)
+(* ****************** *)
+
+(* espressioni *)
+ninductive preast_expr : Type ≝
+  PREAST_EXPR_BYTE8 : byte8 → preast_expr
+| PREAST_EXPR_WORD16: word16 → preast_expr
+| PREAST_EXPR_WORD32: word32 → preast_expr
+
+| PREAST_EXPR_NEG: preast_expr → preast_expr
+| PREAST_EXPR_NOT: preast_expr → preast_expr
+| PREAST_EXPR_COM: preast_expr → preast_expr
+
+| PREAST_EXPR_ADD: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_SUB: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_MUL: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_DIV: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_SHR: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_SHL: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_AND: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_OR:  preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_XOR: preast_expr → preast_expr → preast_expr
+
+| PREAST_EXPR_GT : preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_GTE: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_LT : preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_LTE: preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_EQ : preast_expr → preast_expr → preast_expr
+| PREAST_EXPR_NEQ: preast_expr → preast_expr → preast_expr
+
+| PREAST_EXPR_B8toW16 : preast_expr → preast_expr
+| PREAST_EXPR_B8toW32 : preast_expr → preast_expr
+| PREAST_EXPR_W16toB8 : preast_expr → preast_expr
+| PREAST_EXPR_W16toW32: preast_expr → preast_expr
+| PREAST_EXPR_W32toB8 : preast_expr → preast_expr
+| PREAST_EXPR_W32toW16: preast_expr → preast_expr
+
+| PREAST_EXPR_ID: preast_var → preast_expr
+
+(* variabile: modificatori di array/struct dell'id *)
+with preast_var : Type ≝
+  PREAST_VAR_ID: aux_str_type → preast_var
+| PREAST_VAR_ARRAY: preast_var → preast_expr → preast_var
+| PREAST_VAR_STRUCT: preast_var → nat → preast_var.
+
+(* -------------------------- *)
+
+(* inizializzatori: ... valori ... *)
+ninductive preast_init_val : Type ≝
+  PREAST_INIT_VAL_BYTE8: byte8 → preast_init_val
+| PREAST_INIT_VAL_WORD16: word16 → preast_init_val
+| PREAST_INIT_VAL_WORD32: word32 → preast_init_val
+| PREAST_INIT_VAL_ARRAY: ne_list preast_init_val → preast_init_val
+| PREAST_INIT_VAL_STRUCT: ne_list preast_init_val → preast_init_val.
+
+(*
+ inizializzatori: ammesse solo due forme, no ibridi
+  1) var1 = var2
+  2) var = ... valori ...
+*)
+ninductive preast_init : Type ≝
+  PREAST_INIT_VAR: preast_var → preast_init
+| PREAST_INIT_VAL: preast_init_val → preast_init.
+
+(* -------------------------- *)
+
+(* statement: assegnamento/while/if else if else *)
+ninductive preast_stm : Type ≝
+  PREAST_STM_ASG: preast_var → preast_expr → preast_stm
+| PREAST_STM_WHILE: preast_expr → preast_decl → preast_stm
+| PREAST_STM_IF: ne_list (ProdT preast_expr preast_decl) → option preast_decl → preast_stm
+
+(* dichiarazioni *)
+with preast_decl : Type ≝
+  PREAST_NO_DECL: list preast_stm → preast_decl
+| PREAST_CONST_DECL: aux_str_type → ast_type → preast_init → preast_decl → preast_decl
+| PREAST_VAR_DECL: aux_str_type → ast_type → option preast_init → preast_decl → preast_decl.
+
+(* -------------------------- *)
+
+(* programma *)
+ninductive preast_root : Type ≝
+  PREAST_ROOT: preast_decl → preast_root.
+
+(* -------------------------- *)
+
+(* programma vuoto *)
+ndefinition empty_preast_prog ≝ PREAST_ROOT (PREAST_NO_DECL (nil ?)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_abs.ma b/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_abs.ma
new file mode 100755 (executable)
index 0000000..62e5346
--- /dev/null
@@ -0,0 +1,243 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/memory/memory_func.ma".
+include "emulator/memory/memory_trees.ma".
+include "emulator/memory/memory_bits.ma".
+
+(* ********************************************* *)
+(* ASTRAZIONE DALL'IMPLEMENTAZIONE DELLA MEMORIA *)
+(* ********************************************* *)
+
+(* tipi di implementazione della memoria *)
+ninductive memory_impl : Type ≝
+  MEM_FUNC: memory_impl
+| MEM_TREE: memory_impl
+| MEM_BITS: memory_impl.
+
+(* ausiliario per il tipo della memoria *)
+ndefinition aux_mem_type ≝
+λt:memory_impl.match t with
+ [ MEM_FUNC ⇒ word32 → byte8
+ | MEM_TREE ⇒ aux_32B_type byte8
+ | MEM_BITS ⇒ aux_32B_type (Array8T bool)
+ ].
+
+(* ausiliario per il tipo del checker *)
+ndefinition aux_chk_type ≝
+λt:memory_impl.match t with
+ [ MEM_FUNC ⇒ word32 → memory_type
+ | MEM_TREE ⇒ aux_32B_type memory_type
+ | MEM_BITS ⇒ aux_32B_type (Array8T memory_type)
+ ].
+
+(* unificazione di out_of_bound_memory *)
+ndefinition out_of_bound_memory ≝
+λt:memory_impl.
+ match t
+  return λt.aux_chk_type t
+ with
+  [ MEM_FUNC ⇒ mf_out_of_bound_memory
+  | MEM_TREE ⇒ mt_out_of_bound_memory
+  | MEM_BITS ⇒ mb_out_of_bound_memory
+  ].
+
+(* unificazione di zero_memory *)
+ndefinition zero_memory ≝
+λt:memory_impl.
+ match t
+  return λt.aux_mem_type t
+ with
+  [ MEM_FUNC ⇒ mf_zero_memory
+  | MEM_TREE ⇒ mt_zero_memory
+  | MEM_BITS ⇒ mb_zero_memory
+  ].
+
+(* unificazione della lettura senza chk: mem_read_abs mem addr *)
+ndefinition mem_read_abs ≝
+λt:memory_impl.
+ match t
+  return λt.aux_mem_type t → word32 → byte8 
+ with
+  [ MEM_FUNC ⇒ λm:aux_mem_type MEM_FUNC.
+               λaddr:word32.
+               m addr
+  | MEM_TREE ⇒ λm:aux_mem_type MEM_TREE.
+               λaddr:word32.
+               mt_visit ? m addr
+  | MEM_BITS ⇒ λm:aux_mem_type MEM_BITS.
+               λaddr:word32.
+               byte8_of_bits (mt_visit ? m addr)
+  ].
+
+(* unificazione del chk *)
+ndefinition chk_get ≝
+λt:memory_impl.
+ match t
+  return λt.aux_chk_type t → word32 → Array8T memory_type
+ with
+  [ MEM_FUNC ⇒ λc:aux_chk_type MEM_FUNC.λaddr:word32.
+   match c addr with
+    [ MEM_READ_ONLY ⇒ mk_Array8T ? MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY
+    | MEM_READ_WRITE ⇒ mk_Array8T ? MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE
+    | MEM_OUT_OF_BOUND ⇒ mk_Array8T ? MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND
+    ]
+  | MEM_TREE ⇒ λc:aux_chk_type MEM_TREE.λaddr:word32.
+   match mt_visit ? c addr with
+    [ MEM_READ_ONLY ⇒ mk_Array8T ? MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY
+    | MEM_READ_WRITE ⇒ mk_Array8T ? MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE
+    | MEM_OUT_OF_BOUND ⇒ mk_Array8T ? MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND
+    ]
+  | MEM_BITS ⇒ λc:aux_chk_type MEM_BITS.λaddr:word32.
+   mt_visit ? c addr
+  ].
+
+(* unificazione della lettura con chk: mem_read mem chk addr *)
+ndefinition mem_read ≝
+λt:memory_impl.λm:aux_mem_type t.λc:aux_chk_type t.λaddr:word32.
+ match t
+  return λt.aux_mem_type t → aux_chk_type t → word32 → option byte8 
+ with
+  [ MEM_FUNC ⇒ mf_mem_read
+  | MEM_TREE ⇒ mt_mem_read
+  | MEM_BITS ⇒ mb_mem_read
+  ] m c addr.
+
+(* unificazione della lettura di bit con chk: mem_read mem chk addr sub *)
+ndefinition mem_read_bit ≝
+λt:memory_impl.
+ match t
+  return λt.aux_mem_type t → aux_chk_type t → word32 → oct → option bool 
+ with
+  [ MEM_FUNC ⇒ λm:aux_mem_type MEM_FUNC.
+               λc:aux_chk_type MEM_FUNC.
+               λaddr:word32.
+               λo:oct.
+               opt_map … (mf_mem_read m c addr)
+                (λb.Some ? (getn_array8T o bool (bits_of_byte8 b))) 
+  | MEM_TREE ⇒ λm:aux_mem_type MEM_TREE.
+               λc:aux_chk_type MEM_TREE.
+               λaddr:word32.
+               λo:oct.
+               opt_map … (mt_mem_read m c addr)
+                (λb.Some ? (getn_array8T o bool (bits_of_byte8 b)))
+  | MEM_BITS ⇒ λm:aux_mem_type MEM_BITS.
+               λc:aux_chk_type MEM_BITS.
+               λaddr:word32.
+               λo:oct.
+               mb_mem_read_bit m c addr o
+  ].
+
+(* unificazione della scrittura con chk: mem_update mem chk addr val *)
+ndefinition mem_update ≝
+λt:memory_impl.λm:aux_mem_type t.λc:aux_chk_type t.λaddr:word32.λv:byte8.
+ match t
+  return λt.aux_mem_type t → aux_chk_type t → word32 → byte8 → option (aux_mem_type t)
+ with
+  [ MEM_FUNC ⇒ mf_mem_update
+  | MEM_TREE ⇒ mt_mem_update
+  | MEM_BITS ⇒ mb_mem_update
+  ] m c addr v.
+
+(* unificazione della scrittura di bit con chk: mem_update mem chk addr sub val *)
+ndefinition mem_update_bit ≝
+λt:memory_impl.
+ match t
+  return λt.aux_mem_type t → aux_chk_type t → word32 → oct → bool → option (aux_mem_type t) 
+ with
+  [ MEM_FUNC ⇒ λm:aux_mem_type MEM_FUNC.
+               λc:aux_chk_type MEM_FUNC.
+               λaddr:word32.
+               λo:oct.
+               λv:bool.
+               mf_mem_update m c addr (byte8_of_bits (setn_array8T o bool (bits_of_byte8 (m addr)) v))
+  | MEM_TREE ⇒ λm:aux_mem_type MEM_TREE.
+               λc:aux_chk_type MEM_TREE.
+               λaddr:word32.
+               λo:oct.
+               λv:bool.
+               mt_mem_update m c addr (byte8_of_bits (setn_array8T o bool (bits_of_byte8 (mt_visit ? m addr)) v))
+  | MEM_BITS ⇒ λm:aux_mem_type MEM_BITS.
+               λc:aux_chk_type MEM_BITS.
+               λaddr:word32.
+               λo:oct.
+               λv:bool.
+               mb_mem_update_bit m c addr o v
+  ].
+
+(* unificazione del caricamento: load_from_source_at old_mem source addr *)
+ndefinition load_from_source_at ≝
+λt:memory_impl.λm:aux_mem_type t.λl:list byte8.λaddr:word32.
+ match t
+  return λt.aux_mem_type t → list byte8 → word32 → aux_mem_type t 
+ with
+  [ MEM_FUNC ⇒ mf_load_from_source_at
+  | MEM_TREE ⇒ mt_load_from_source_at
+  | MEM_BITS ⇒ mb_load_from_source_at
+  ] m l addr.
+
+(* unificazione dell'impostazione della memoria: chk_update_ranged chk inf sup v *)
+ndefinition check_update_ranged ≝
+λt:memory_impl.
+ match t
+  return λt.aux_chk_type t → word32 → word16 → memory_type → aux_chk_type t 
+ with
+  [ MEM_FUNC ⇒ λc:aux_chk_type MEM_FUNC.
+               λaddr:word32.
+               λrange:word16.
+               λv:memory_type.
+               mf_check_update_ranged c addr range v
+  | MEM_TREE ⇒ λc:aux_chk_type MEM_TREE.
+               λaddr:word32.
+               λrange:word16.
+               λv:memory_type.
+               mt_update_ranged ? c addr ? (w16_to_recw16 range) v
+  | MEM_BITS ⇒ λc:aux_chk_type MEM_BITS.
+               λaddr:word32.
+               λrange:word16.
+               λv:memory_type.
+               mt_update_ranged ? c addr ? (w16_to_recw16 range) (mk_Array8T ? v v v v v v v v)
+  ].
+
+(* unificazione dell'impostazione dei bit: chk_update_bit chk addr sub v *)
+(* NB: dove non esiste la granularita' del bit, lascio inalterato *)
+ndefinition check_update_bit ≝
+λt:memory_impl.
+ match t
+  return λt.aux_chk_type t → word32 → oct → memory_type → aux_chk_type t
+ with
+  [ MEM_FUNC ⇒ λc:aux_chk_type MEM_FUNC.
+               λaddr:word32.
+               λo:oct.
+               λv:memory_type.
+               c
+  | MEM_TREE ⇒ λc:aux_chk_type MEM_TREE.
+               λaddr:word32.
+               λo:oct.
+               λv:memory_type.
+               c
+  | MEM_BITS ⇒ λc:aux_chk_type MEM_BITS.
+               λaddr:word32.
+               λo:oct.
+               λv:memory_type.
+               mb_chk_update_bit c addr o v
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_bits.ma b/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_bits.ma
new file mode 100755 (executable)
index 0000000..840b673
--- /dev/null
@@ -0,0 +1,181 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/memory/memory_trees.ma".
+
+(* ********************* *)
+(* MEMORIA E DESCRITTORE *)
+(* ********************* *)
+
+(* tutta la memoria non installata *)
+ndefinition mb_out_of_bound_memory ≝
+ aux_32B_filler ?
+  (mk_Array8T ? MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND
+                MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND).
+
+(* tutta la memoria a 0 *)
+ndefinition mb_zero_memory ≝
+ aux_32B_filler ? (mk_Array8T ? false false false false false false false false).
+
+(* scrivi bit controllando il tipo di memoria *)
+ndefinition mb_mem_update_bit ≝
+λmem:aux_32B_type (Array8T bool).
+λchk:aux_32B_type (Array8T memory_type).
+λaddr:word32.λsub:oct.λv:bool.
+ match getn_array8T sub ? (mt_visit ? chk addr) with
+  (* ROM? ok, ma il valore viene perso *)
+  [ MEM_READ_ONLY ⇒ Some ? mem
+  (* RAM? ok *)
+  | MEM_READ_WRITE ⇒ Some ? (mt_update ? mem addr (setn_array8T sub ? (mt_visit ? mem addr) v))
+  (* NON INSTALLATA? no *)
+  | MEM_OUT_OF_BOUND ⇒ None ? ].
+
+ndefinition mb_mem_update ≝
+λmem:aux_32B_type (Array8T bool).
+λchk:aux_32B_type (Array8T memory_type).
+λaddr:word32.λv:byte8.
+let old_value ≝ mt_visit (Array8T bool) mem addr in
+let new_value ≝ bits_of_byte8 v in
+let memtypes ≝ mt_visit (Array8T memory_type) chk addr in
+let newbit0 ≝ match getn_array8T o0 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o0 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o0 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit1 ≝ match getn_array8T o1 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o1 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o1 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit2 ≝ match getn_array8T o2 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o2 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o2 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit3 ≝ match getn_array8T o3 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o3 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o3 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit4 ≝ match getn_array8T o4 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o4 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o4 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit5 ≝ match getn_array8T o5 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o5 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o5 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit6 ≝ match getn_array8T o6 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o6 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o6 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit7 ≝ match getn_array8T o7 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o7 bool old_value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o7 bool new_value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+       opt_map … newbit0
+ (λnb0.opt_map … newbit1
+ (λnb1.opt_map … newbit2
+ (λnb2.opt_map … newbit3
+ (λnb3.opt_map … newbit4
+ (λnb4.opt_map … newbit5
+ (λnb5.opt_map … newbit6
+ (λnb6.opt_map … newbit7
+ (λnb7.Some ? (mt_update ? mem addr (mk_Array8T bool nb7 nb6 nb5 nb4 nb3 nb2 nb1 nb0)))))))))).
+
+(* scrivi tipo di bit *)
+ndefinition mb_chk_update_bit ≝
+λchk:aux_32B_type (Array8T memory_type).
+λaddr:word32.λsub:oct.λv:memory_type.
+ mt_update ? chk addr (setn_array8T sub ? (mt_visit ? chk addr) v).
+
+(* leggi bit controllando il tipo di memoria *)
+ndefinition mb_mem_read_bit ≝
+λmem:aux_32B_type (Array8T bool).
+λchk:aux_32B_type (Array8T memory_type).
+λaddr:word32.λsub:oct.
+ match getn_array8T sub ? (mt_visit ? chk addr) with
+  (* ROM? ok, ma il valore viene perso *)
+  [ MEM_READ_ONLY ⇒ Some ? (getn_array8T sub ? (mt_visit ? mem addr))
+  (* RAM? ok *)
+  | MEM_READ_WRITE ⇒ Some ? (getn_array8T sub ? (mt_visit ? mem addr))
+  (* NON INSTALLATA? no *)
+  | MEM_OUT_OF_BOUND ⇒ None ? ]. 
+
+(* leggi controllando il tipo di memoria *)
+(* NB: devono esistere tutti i bit *)
+ndefinition mb_mem_read ≝
+λmem:aux_32B_type (Array8T bool).
+λchk:aux_32B_type (Array8T memory_type).
+λaddr:word32.
+let value ≝ mt_visit (Array8T bool) mem addr in
+let memtypes ≝ mt_visit (Array8T memory_type) chk addr in
+let newbit0 ≝ match getn_array8T o0 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o0 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o0 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit1 ≝ match getn_array8T o1 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o1 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o1 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit2 ≝ match getn_array8T o2 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o2 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o2 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit3 ≝ match getn_array8T o3 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o3 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o3 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit4 ≝ match getn_array8T o4 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o4 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o4 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit5 ≝ match getn_array8T o5 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o5 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o5 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit6 ≝ match getn_array8T o6 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o6 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o6 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+let newbit7 ≝ match getn_array8T o7 memory_type memtypes with
+ [ MEM_READ_ONLY ⇒ Some bool (getn_array8T o7 bool value)
+ | MEM_READ_WRITE ⇒ Some bool (getn_array8T o7 bool value)
+ | MEM_OUT_OF_BOUND ⇒ None bool ] in
+       opt_map … newbit0
+ (λnb0.opt_map … newbit1
+ (λnb1.opt_map … newbit2
+ (λnb2.opt_map … newbit3
+ (λnb3.opt_map … newbit4
+ (λnb4.opt_map … newbit5
+ (λnb5.opt_map … newbit6
+ (λnb6.opt_map … newbit7
+ (λnb7.Some ? (byte8_of_bits (mk_Array8T bool nb7 nb6 nb5 nb4 nb3 nb2 nb1 nb0)))))))))).
+
+(* ************************** *)
+(* CARICAMENTO PROGRAMMA/DATI *)
+(* ************************** *)
+
+(* carica a paratire da addr, scartando source (pescando da old_mem) se si supera 0xFFFF... *)
+nlet rec mb_load_from_source_at (old_mem:aux_32B_type (Array8T bool))
+                                (src:list byte8) (addr:word32) on src ≝
+ match src with
+  (* fine di source: carica da old_mem *)
+  [ nil ⇒ old_mem
+  | cons hd tl ⇒ mb_load_from_source_at (mt_update ? old_mem addr (bits_of_byte8 hd)) tl (succ_w32 addr)
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_func.ma b/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_func.ma
new file mode 100755 (executable)
index 0000000..9f75b54
--- /dev/null
@@ -0,0 +1,79 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/memory/memory_struct.ma".
+include "num/word32.ma".
+include "common/option.ma".
+include "common/list.ma".
+
+(* ********************* *)
+(* MEMORIA E DESCRITTORE *)
+(* ********************* *)
+
+(* (mf_check_update_ranged chk inf sup mode) = setta tipo memoria *)
+ndefinition mf_check_update_ranged ≝
+λf:word32 → memory_type.λaddr:word32.λrange:word16.λv.
+ λx.match inrange_w32 x addr (plus_w32_d_d addr 〈〈〈x0,x0〉:〈x0,x0〉〉.range〉) with
+  [ true ⇒ v
+  | false ⇒ f x ].
+
+(* tutta la memoria non installata *)
+ndefinition mf_out_of_bound_memory ≝ λ_:word32.MEM_OUT_OF_BOUND.
+
+(* (mf_mem_update mem checked addr val) = scrivi controllando il tipo di memoria *)
+ndefinition mf_mem_update ≝
+λf:word32 → byte8.λc:word32 → memory_type.λa:word32.λv:byte8.
+ match c a with
+  (* ROM? ok, ma il valore viene perso *)
+  [ MEM_READ_ONLY ⇒ Some ? f
+  (* RAM? ok *)
+  | MEM_READ_WRITE ⇒ Some ? (λx.match eq_w32 x a with [ true ⇒ v | false ⇒ f x ])
+  (* NON INSTALLATA? no *)
+  | MEM_OUT_OF_BOUND ⇒ None ? ].  
+
+(* tutta la memoria a 0 *)
+ndefinition mf_zero_memory ≝ λ_:word32.〈x0,x0〉.
+
+(* (mf_mem_read mem check addr) = leggi controllando il tipo di memoria *)
+ndefinition mf_mem_read ≝
+λf:word32 → byte8.λc:word32 → memory_type.λa.
+ match c a with
+  [ MEM_READ_ONLY ⇒ Some ? (f a)
+  | MEM_READ_WRITE ⇒ Some ? (f a)
+  | MEM_OUT_OF_BOUND ⇒ None ? ].
+
+(* ************************** *)
+(* CARICAMENTO PROGRAMMA/DATI *)
+(* ************************** *)
+
+(* carica a paratire da addr, overflow se si supera 0xFFFF... *)
+nlet rec mf_load_from_source_at (old_mem:word32 → byte8) (src:list byte8) (addr:word32) on src ≝
+ match src with
+  (* fine di source: carica da old_mem *)
+  [ nil ⇒ old_mem
+  | cons hd tl ⇒ λx:word32.match eq_w32 addr x with
+   (* la locazione corrisponde al punto corrente di source *)
+   [ true ⇒ hd
+   (* la locazione e' piu' avanti? ricorsione *)
+   | false ⇒ (mf_load_from_source_at old_mem tl (plus_w32_d_d addr 〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:〈x0,x1〉〉〉)) x
+   ]
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_struct.ma b/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_struct.ma
new file mode 100755 (executable)
index 0000000..0e023b5
--- /dev/null
@@ -0,0 +1,659 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/oct.ma".
+include "num/byte8.ma".
+
+(* **************************** *)
+(* TIPI PER I MODULI DI MEMORIA *)
+(* **************************** *)
+
+(* tipi di memoria:RAM/ROM/non installata *)
+ninductive memory_type : Type ≝
+  MEM_READ_ONLY: memory_type
+| MEM_READ_WRITE: memory_type
+| MEM_OUT_OF_BOUND: memory_type.
+
+(* **************** *)
+(* TIPO ARRAY DA 16 *)
+(* **************** *)
+
+(* definizione di un array omogeneo di dimensione 16 *)
+nrecord Array16T (T:Type) : Type ≝
+{ a16_1  : T ; a16_2  : T ; a16_3  : T ; a16_4  : T
+; a16_5  : T ; a16_6  : T ; a16_7  : T ; a16_8  : T
+; a16_9  : T ; a16_10 : T ; a16_11 : T ; a16_12 : T
+; a16_13 : T ; a16_14 : T ; a16_15 : T ; a16_16 : T }.
+
+(* abbiamo gia' gli esadecimali come tipo induttivo quindi: *)
+(* posso definire un getter a matrice sull'array *)
+
+ndefinition getn_array16T ≝
+λn:exadecim.λT:Type.λp:Array16T T.
+ match n return λn.(Array16T T) → T with
+  [ x0 ⇒ a16_1  T | x1 ⇒ a16_2  T | x2 ⇒ a16_3  T | x3 ⇒ a16_4  T
+  | x4 ⇒ a16_5  T | x5 ⇒ a16_6  T | x6 ⇒ a16_7  T | x7 ⇒ a16_8  T
+  | x8 ⇒ a16_9  T | x9 ⇒ a16_10 T | xA ⇒ a16_11 T | xB ⇒ a16_12 T
+  | xC ⇒ a16_13 T | xD ⇒ a16_14 T | xE ⇒ a16_15 T | xF ⇒ a16_16 T
+  ] p.
+
+(* abbiamo gia' gli esadecimali come tipo induttivo quindi: *)
+(* posso definire un setter a matrice sull'array *)
+ndefinition setn_array16T ≝
+λn:exadecim.λT:Type.λp:Array16T T.λv:T.
+let e00 ≝ (a16_1 T p) in
+let e01 ≝ (a16_2 T p) in
+let e02 ≝ (a16_3 T p) in
+let e03 ≝ (a16_4 T p) in
+let e04 ≝ (a16_5 T p) in
+let e05 ≝ (a16_6 T p) in
+let e06 ≝ (a16_7 T p) in
+let e07 ≝ (a16_8 T p) in
+let e08 ≝ (a16_9 T p) in
+let e09 ≝ (a16_10 T p) in
+let e10 ≝ (a16_11 T p) in
+let e11 ≝ (a16_12 T p) in
+let e12 ≝ (a16_13 T p) in
+let e13 ≝ (a16_14 T p) in
+let e14 ≝ (a16_15 T p) in
+let e15 ≝ (a16_16 T p) in
+ match n with
+  [ x0 ⇒ mk_Array16T T v   e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+  | x1 ⇒ mk_Array16T T e00 v   e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+  | x2 ⇒ mk_Array16T T e00 e01 v   e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+  | x3 ⇒ mk_Array16T T e00 e01 e02 v   e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+  | x4 ⇒ mk_Array16T T e00 e01 e02 e03 v   e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+  | x5 ⇒ mk_Array16T T e00 e01 e02 e03 e04 v   e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+  | x6 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v   e07 e08 e09 e10 e11 e12 e13 e14 e15
+  | x7 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v   e08 e09 e10 e11 e12 e13 e14 e15
+  | x8 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v   e09 e10 e11 e12 e13 e14 e15
+  | x9 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v   e10 e11 e12 e13 e14 e15
+  | xA ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 v   e11 e12 e13 e14 e15
+  | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 v   e12 e13 e14 e15
+  | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 v   e13 e14 e15
+  | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 v   e14 e15
+  | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 v   e15
+  | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 v
+  ].
+
+(* abbiamo gia' gli esadecimali come tipo induttivo quindi: *)
+(* posso definire un setter multiplo [m,n] a matrice sull'array *)
+(* m ≤ n *)
+ndefinition setmn_array16T ≝
+λm,n:exadecim.λT:Type.λp:Array16T T.λv:T.
+let e00 ≝ (a16_1 T p) in
+let e01 ≝ (a16_2 T p) in
+let e02 ≝ (a16_3 T p) in
+let e03 ≝ (a16_4 T p) in
+let e04 ≝ (a16_5 T p) in
+let e05 ≝ (a16_6 T p) in
+let e06 ≝ (a16_7 T p) in
+let e07 ≝ (a16_8 T p) in
+let e08 ≝ (a16_9 T p) in
+let e09 ≝ (a16_10 T p) in
+let e10 ≝ (a16_11 T p) in
+let e11 ≝ (a16_12 T p) in
+let e12 ≝ (a16_13 T p) in
+let e13 ≝ (a16_14 T p) in
+let e14 ≝ (a16_15 T p) in
+let e15 ≝ (a16_16 T p) in
+ match m with
+  [ x0 ⇒ match n with
+   [ x0 ⇒ mk_Array16T T v e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x1 ⇒ mk_Array16T T v v   e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x2 ⇒ mk_Array16T T v v   v   e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x3 ⇒ mk_Array16T T v v   v   v   e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x4 ⇒ mk_Array16T T v v   v   v   v   e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x5 ⇒ mk_Array16T T v v   v   v   v   v   e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x6 ⇒ mk_Array16T T v v   v   v   v   v   v   e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x7 ⇒ mk_Array16T T v v   v   v   v   v   v   v   e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T v v   v   v   v   v   v   v   v   v   v   v   v   v   v   v ]
+  | x1 ⇒ match n with
+   [ x0 ⇒ p
+   | x1 ⇒ mk_Array16T T e00 v e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x2 ⇒ mk_Array16T T e00 v v   e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x3 ⇒ mk_Array16T T e00 v v   v   e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x4 ⇒ mk_Array16T T e00 v v   v   v   e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x5 ⇒ mk_Array16T T e00 v v   v   v   v   e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x6 ⇒ mk_Array16T T e00 v v   v   v   v   v   e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x7 ⇒ mk_Array16T T e00 v v   v   v   v   v   v   e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 v v   v   v   v   v   v   v   v   v   v   v   v   v   v ]
+  | x2 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p
+   | x2 ⇒ mk_Array16T T e00 e01 v e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x3 ⇒ mk_Array16T T e00 e01 v v   e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x4 ⇒ mk_Array16T T e00 e01 v v   v   e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x5 ⇒ mk_Array16T T e00 e01 v v   v   v   e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x6 ⇒ mk_Array16T T e00 e01 v v   v   v   v   e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x7 ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 v v   v   v   v   v   v   v   v   v   v   v   v   v ]
+  | x3 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p
+   | x3 ⇒ mk_Array16T T e00 e01 e02 v e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x4 ⇒ mk_Array16T T e00 e01 e02 v v   e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x5 ⇒ mk_Array16T T e00 e01 e02 v v   v   e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x6 ⇒ mk_Array16T T e00 e01 e02 v v   v   v   e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x7 ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 v v   v   v   v   v   v   v   v   v   v   v   v ]
+  | x4 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p
+   | x4 ⇒ mk_Array16T T e00 e01 e02 e03 v e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x5 ⇒ mk_Array16T T e00 e01 e02 e03 v v   e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x6 ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x7 ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 v v   v   v   v   v   v   v   v   v   v   v ]
+  | x5 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p
+   | x5 ⇒ mk_Array16T T e00 e01 e02 e03 e04 v e06 e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x6 ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x7 ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 v v   v   v   v   v   v   v   v   v   v ]
+  | x6 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p
+   | x6 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v e07 e08 e09 e10 e11 e12 e13 e14 e15
+   | x7 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 v v   v   v   v   v   v   v   v   v ]
+  | x7 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p
+   | x7 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v e08 e09 e10 e11 e12 e13 e14 e15
+   | x8 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 v v   v   v   v   v   v   v   v ]
+  | x8 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v e09 e10 e11 e12 e13 e14 e15
+   | x9 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v v   e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v v   v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v v   v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v v   v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v v   v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v v   v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 v v   v   v   v   v   v   v ]
+  | x9 ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p  | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ p
+   | x9 ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v e10 e11 e12 e13 e14 e15
+   | xA ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v v   e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v v   v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v v   v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v v   v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v v   v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 v v   v   v   v   v   v ]
+  | xA ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ p | x9 ⇒ p
+   | xA ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 v e11 e12 e13 e14 e15
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 v v   e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 v v   v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 v v   v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 v v   v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 v v   v   v   v   v ]
+  | xB ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ p | x9 ⇒ p | xA ⇒ p
+   | xB ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 v e12 e13 e14 e15
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 v v   e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 v v   v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 v v   v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 v v   v   v   v ]
+  | xC ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ p | x9 ⇒ p | xA ⇒ p | xB ⇒ p
+   | xC ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 v e13 e14 e15
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 v v   e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 v v   v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 v v   v   v ]
+  | xD ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ p | x9 ⇒ p | xA ⇒ p | xB ⇒ p | xC ⇒ p
+   | xD ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 v e14 e15
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 v v   e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 v v   v ]
+  | xE ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ p | x9 ⇒ p | xA ⇒ p | xB ⇒ p | xC ⇒ p | xD ⇒ p
+   | xE ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 v e15
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 v v ]
+  | xF ⇒ match n with
+   [ x0 ⇒ p | x1 ⇒ p | x2 ⇒ p | x3 ⇒ p | x4 ⇒ p | x5 ⇒ p | x6 ⇒ p | x7 ⇒ p
+   | x8 ⇒ p | x9 ⇒ p | xA ⇒ p | xB ⇒ p | xC ⇒ p | xD ⇒ p | xE ⇒ p
+   | xF ⇒ mk_Array16T T e00 e01 e02 e03 e04 e05 e06 e07 e08 e09 e10 e11 e12 e13 e14 v ]
+  ].
+
+(* abbiamo gia' gli esadecimali come tipo induttivo quindi: *)
+(* posso definire un setter composto [m+1,n-1] a matrice sull'array *)
+(* NB: obbiettivo evitare l'overflow *)
+ndefinition setmn_array16T_succ_pred ≝
+λm,n:exadecim.λT:Type.λp:Array16T T.λv:T.
+ match lt_ex m xF with
+  [ true ⇒ match gt_ex n x0 with
+   [ true ⇒ setmn_array16T (succ_ex m) (pred_ex n) T p v
+   | false ⇒ p
+   ]
+  | false ⇒ p
+  ].
+
+(* abbiamo gia' gli esadecimali come tipo induttivo quindi: *)
+(* posso definire un setter composto [m+1,F] a matrice sull'array *)
+(* NB: obbiettivo evitare l'overflow *)
+ndefinition setmn_array16T_succ ≝
+λm:exadecim.λT:Type.λp:Array16T T.λv:T.
+ match lt_ex m xF with
+  [ true ⇒ setmn_array16T (succ_ex m) xF T p v
+  | false ⇒ p
+  ].
+
+(* abbiamo gia' gli esadecimali come tipo induttivo quindi: *)
+(* posso definire un setter composto [0,n-1] a matrice sull'array *)
+(* NB: obbiettivo evitare l'overflow *)
+ndefinition setmn_array16T_pred ≝
+λn:exadecim.λT:Type.λp:Array16T T.λv:T.
+ match gt_ex n x0 with
+  [ true ⇒ setmn_array16T x0 (pred_ex n) T p v
+  | false ⇒ p
+  ].
+
+(* ************************** *)
+(* TIPO BYTE COME INSIEME BIT *)
+(* ************************** *)
+
+(* definizione di un byte come 8 bit *)
+nrecord Array8T (T:Type) : Type ≝
+{ a8_1  : T ; a8_2  : T ; a8_3  : T ; a8_4  : T
+; a8_5  : T ; a8_6  : T ; a8_7  : T ; a8_8  : T }.
+
+(* abbiamo gia' gli ottali come tipo induttivo quindi: *)
+(* posso definire un getter a matrice sull'array *)
+ndefinition getn_array8T ≝
+λn:oct.λT:Type.λp:Array8T T.
+ match n return λn.(Array8T T) → T with
+  [ o0 ⇒ a8_1  T | o1 ⇒ a8_2  T | o2 ⇒ a8_3  T | o3 ⇒ a8_4  T
+  | o4 ⇒ a8_5  T | o5 ⇒ a8_6  T | o6 ⇒ a8_7  T | o7 ⇒ a8_8  T
+  ] p.
+
+(* abbiamo gia' gli ottali come tipo induttivo quindi: *)
+(* posso definire un setter a matrice sull'array *)
+ndefinition setn_array8T ≝
+λn:oct.λT:Type.λp:Array8T T.λv:T.
+let e00 ≝ (a8_1 T p) in
+let e01 ≝ (a8_2 T p) in
+let e02 ≝ (a8_3 T p) in
+let e03 ≝ (a8_4 T p) in
+let e04 ≝ (a8_5 T p) in
+let e05 ≝ (a8_6 T p) in
+let e06 ≝ (a8_7 T p) in
+let e07 ≝ (a8_8 T p) in
+ match n with
+  [ o0 ⇒ mk_Array8T T e07 e06 e05 e04 e03 e02 e01 v
+  | o1 ⇒ mk_Array8T T e07 e06 e05 e04 e03 e02 v   e00
+  | o2 ⇒ mk_Array8T T e07 e06 e05 e04 e03 v   e01 e00
+  | o3 ⇒ mk_Array8T T e07 e06 e05 e04 v   e02 e01 e00
+  | o4 ⇒ mk_Array8T T e07 e06 e05 v   e03 e02 e01 e00
+  | o5 ⇒ mk_Array8T T e07 e06 v   e04 e03 e02 e01 e00
+  | o6 ⇒ mk_Array8T T e07 v   e05 e04 e03 e02 e01 e00
+  | o7 ⇒ mk_Array8T T v   e06 e05 e04 e03 e02 e01 e00
+  ].
+
+(* lettura byte *)
+ndefinition byte8_of_bits ≝
+λp:Array8T bool.
+   mk_byte8
+   (or_ex (match a8_8 ? p with [ true ⇒ x8 | false ⇒ x0 ])
+   (or_ex (match a8_7 ? p with [ true ⇒ x4 | false ⇒ x0 ])
+   (or_ex (match a8_6 ? p with [ true ⇒ x2 | false ⇒ x0 ])
+          (match a8_5 ? p with [ true ⇒ x1 | false ⇒ x0 ]))))
+   (or_ex (match a8_4 ? p with [ true ⇒ x8 | false ⇒ x0 ])
+   (or_ex (match a8_3 ? p with [ true ⇒ x4 | false ⇒ x0 ])
+   (or_ex (match a8_2 ? p with [ true ⇒ x2 | false ⇒ x0 ])
+          (match a8_1 ? p with [ true ⇒ x1 | false ⇒ x0 ])))).
+
+(* scrittura byte *)
+ndefinition bits_of_byte8 ≝
+λp:byte8.
+ match b8h p with
+  [ x0 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false false false false false false false false
+   | x1 ⇒ mk_Array8T bool false false false false false false false true
+   | x2 ⇒ mk_Array8T bool false false false false false false true  false
+   | x3 ⇒ mk_Array8T bool false false false false false false true  true
+   | x4 ⇒ mk_Array8T bool false false false false false true  false false
+   | x5 ⇒ mk_Array8T bool false false false false false true  false true
+   | x6 ⇒ mk_Array8T bool false false false false false true  true  false
+   | x7 ⇒ mk_Array8T bool false false false false false true  true  true
+   | x8 ⇒ mk_Array8T bool false false false false true  false false false
+   | x9 ⇒ mk_Array8T bool false false false false true  false false true
+   | xA ⇒ mk_Array8T bool false false false false true  false true  false
+   | xB ⇒ mk_Array8T bool false false false false true  false true  true
+   | xC ⇒ mk_Array8T bool false false false false true  true  false false
+   | xD ⇒ mk_Array8T bool false false false false true  true  false true
+   | xE ⇒ mk_Array8T bool false false false false true  true  true  false
+   | xF ⇒ mk_Array8T bool false false false false true  true  true  true ]
+  | x1 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false false false true  false false false false
+   | x1 ⇒ mk_Array8T bool false false false true  false false false true
+   | x2 ⇒ mk_Array8T bool false false false true  false false true  false
+   | x3 ⇒ mk_Array8T bool false false false true  false false true  true
+   | x4 ⇒ mk_Array8T bool false false false true  false true  false false
+   | x5 ⇒ mk_Array8T bool false false false true  false true  false true
+   | x6 ⇒ mk_Array8T bool false false false true  false true  true  false
+   | x7 ⇒ mk_Array8T bool false false false true  false true  true  true
+   | x8 ⇒ mk_Array8T bool false false false true  true  false false false
+   | x9 ⇒ mk_Array8T bool false false false true  true  false false true
+   | xA ⇒ mk_Array8T bool false false false true  true  false true  false
+   | xB ⇒ mk_Array8T bool false false false true  true  false true  true
+   | xC ⇒ mk_Array8T bool false false false true  true  true  false false
+   | xD ⇒ mk_Array8T bool false false false true  true  true  false true
+   | xE ⇒ mk_Array8T bool false false false true  true  true  true  false
+   | xF ⇒ mk_Array8T bool false false false true  true  true  true  true ]
+  | x2 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false false true  false false false false false
+   | x1 ⇒ mk_Array8T bool false false true  false false false false true
+   | x2 ⇒ mk_Array8T bool false false true  false false false true  false
+   | x3 ⇒ mk_Array8T bool false false true  false false false true  true
+   | x4 ⇒ mk_Array8T bool false false true  false false true  false false
+   | x5 ⇒ mk_Array8T bool false false true  false false true  false true
+   | x6 ⇒ mk_Array8T bool false false true  false false true  true  false
+   | x7 ⇒ mk_Array8T bool false false true  false false true  true  true
+   | x8 ⇒ mk_Array8T bool false false true  false true  false false false
+   | x9 ⇒ mk_Array8T bool false false true  false true  false false true
+   | xA ⇒ mk_Array8T bool false false true  false true  false true  false
+   | xB ⇒ mk_Array8T bool false false true  false true  false true  true
+   | xC ⇒ mk_Array8T bool false false true  false true  true  false false
+   | xD ⇒ mk_Array8T bool false false true  false true  true  false true
+   | xE ⇒ mk_Array8T bool false false true  false true  true  true  false
+   | xF ⇒ mk_Array8T bool false false true  false true  true  true  true ]
+  | x3 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false false true  true  false false false false
+   | x1 ⇒ mk_Array8T bool false false true  true  false false false true
+   | x2 ⇒ mk_Array8T bool false false true  true  false false true  false
+   | x3 ⇒ mk_Array8T bool false false true  true  false false true  true
+   | x4 ⇒ mk_Array8T bool false false true  true  false true  false false
+   | x5 ⇒ mk_Array8T bool false false true  true  false true  false true
+   | x6 ⇒ mk_Array8T bool false false true  true  false true  true  false
+   | x7 ⇒ mk_Array8T bool false false true  true  false true  true  true
+   | x8 ⇒ mk_Array8T bool false false true  true  true  false false false
+   | x9 ⇒ mk_Array8T bool false false true  true  true  false false true
+   | xA ⇒ mk_Array8T bool false false true  true  true  false true  false
+   | xB ⇒ mk_Array8T bool false false true  true  true  false true  true
+   | xC ⇒ mk_Array8T bool false false true  true  true  true  false false
+   | xD ⇒ mk_Array8T bool false false true  true  true  true  false true
+   | xE ⇒ mk_Array8T bool false false true  true  true  true  true  false
+   | xF ⇒ mk_Array8T bool false false true  true  true  true  true  true ]
+  | x4 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false true  false false false false false false
+   | x1 ⇒ mk_Array8T bool false true  false false false false false true
+   | x2 ⇒ mk_Array8T bool false true  false false false false true  false
+   | x3 ⇒ mk_Array8T bool false true  false false false false true  true
+   | x4 ⇒ mk_Array8T bool false true  false false false true  false false
+   | x5 ⇒ mk_Array8T bool false true  false false false true  false true
+   | x6 ⇒ mk_Array8T bool false true  false false false true  true  false
+   | x7 ⇒ mk_Array8T bool false true  false false false true  true  true
+   | x8 ⇒ mk_Array8T bool false true  false false true  false false false
+   | x9 ⇒ mk_Array8T bool false true  false false true  false false true
+   | xA ⇒ mk_Array8T bool false true  false false true  false true  false
+   | xB ⇒ mk_Array8T bool false true  false false true  false true  true
+   | xC ⇒ mk_Array8T bool false true  false false true  true  false false
+   | xD ⇒ mk_Array8T bool false true  false false true  true  false true
+   | xE ⇒ mk_Array8T bool false true  false false true  true  true  false
+   | xF ⇒ mk_Array8T bool false true  false false true  true  true  true ]
+  | x5 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false true  false true  false false false false
+   | x1 ⇒ mk_Array8T bool false true  false true  false false false true
+   | x2 ⇒ mk_Array8T bool false true  false true  false false true  false
+   | x3 ⇒ mk_Array8T bool false true  false true  false false true  true
+   | x4 ⇒ mk_Array8T bool false true  false true  false true  false false
+   | x5 ⇒ mk_Array8T bool false true  false true  false true  false true
+   | x6 ⇒ mk_Array8T bool false true  false true  false true  true  false
+   | x7 ⇒ mk_Array8T bool false true  false true  false true  true  true
+   | x8 ⇒ mk_Array8T bool false true  false true  true  false false false
+   | x9 ⇒ mk_Array8T bool false true  false true  true  false false true
+   | xA ⇒ mk_Array8T bool false true  false true  true  false true  false
+   | xB ⇒ mk_Array8T bool false true  false true  true  false true  true
+   | xC ⇒ mk_Array8T bool false true  false true  true  true  false false
+   | xD ⇒ mk_Array8T bool false true  false true  true  true  false true
+   | xE ⇒ mk_Array8T bool false true  false true  true  true  true  false
+   | xF ⇒ mk_Array8T bool false true  false true  true  true  true  true ]
+  | x6 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false true  true  false false false false false
+   | x1 ⇒ mk_Array8T bool false true  true  false false false false true
+   | x2 ⇒ mk_Array8T bool false true  true  false false false true  false
+   | x3 ⇒ mk_Array8T bool false true  true  false false false true  true
+   | x4 ⇒ mk_Array8T bool false true  true  false false true  false false
+   | x5 ⇒ mk_Array8T bool false true  true  false false true  false true
+   | x6 ⇒ mk_Array8T bool false true  true  false false true  true  false
+   | x7 ⇒ mk_Array8T bool false true  true  false false true  true  true
+   | x8 ⇒ mk_Array8T bool false true  true  false true  false false false
+   | x9 ⇒ mk_Array8T bool false true  true  false true  false false true
+   | xA ⇒ mk_Array8T bool false true  true  false true  false true  false
+   | xB ⇒ mk_Array8T bool false true  true  false true  false true  true
+   | xC ⇒ mk_Array8T bool false true  true  false true  true  false false
+   | xD ⇒ mk_Array8T bool false true  true  false true  true  false true
+   | xE ⇒ mk_Array8T bool false true  true  false true  true  true  false
+   | xF ⇒ mk_Array8T bool false true  true  false true  true  true  true ]
+  | x7 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool false true  true  true  false false false false
+   | x1 ⇒ mk_Array8T bool false true  true  true  false false false true
+   | x2 ⇒ mk_Array8T bool false true  true  true  false false true  false
+   | x3 ⇒ mk_Array8T bool false true  true  true  false false true  true
+   | x4 ⇒ mk_Array8T bool false true  true  true  false true  false false
+   | x5 ⇒ mk_Array8T bool false true  true  true  false true  false true
+   | x6 ⇒ mk_Array8T bool false true  true  true  false true  true  false
+   | x7 ⇒ mk_Array8T bool false true  true  true  false true  true  true
+   | x8 ⇒ mk_Array8T bool false true  true  true  true  false false false
+   | x9 ⇒ mk_Array8T bool false true  true  true  true  false false true
+   | xA ⇒ mk_Array8T bool false true  true  true  true  false true  false
+   | xB ⇒ mk_Array8T bool false true  true  true  true  false true  true
+   | xC ⇒ mk_Array8T bool false true  true  true  true  true  false false
+   | xD ⇒ mk_Array8T bool false true  true  true  true  true  false true
+   | xE ⇒ mk_Array8T bool false true  true  true  true  true  true  false
+   | xF ⇒ mk_Array8T bool false true  true  true  true  true  true  true ]
+  | x8 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  false false false false false false false
+   | x1 ⇒ mk_Array8T bool true  false false false false false false true
+   | x2 ⇒ mk_Array8T bool true  false false false false false true  false
+   | x3 ⇒ mk_Array8T bool true  false false false false false true  true
+   | x4 ⇒ mk_Array8T bool true  false false false false true  false false
+   | x5 ⇒ mk_Array8T bool true  false false false false true  false true
+   | x6 ⇒ mk_Array8T bool true  false false false false true  true  false
+   | x7 ⇒ mk_Array8T bool true  false false false false true  true  true
+   | x8 ⇒ mk_Array8T bool true  false false false true  false false false
+   | x9 ⇒ mk_Array8T bool true  false false false true  false false true
+   | xA ⇒ mk_Array8T bool true  false false false true  false true  false
+   | xB ⇒ mk_Array8T bool true  false false false true  false true  true
+   | xC ⇒ mk_Array8T bool true  false false false true  true  false false
+   | xD ⇒ mk_Array8T bool true  false false false true  true  false true
+   | xE ⇒ mk_Array8T bool true  false false false true  true  true  false
+   | xF ⇒ mk_Array8T bool true  false false false true  true  true  true ]
+  | x9 ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  false false true  false false false false
+   | x1 ⇒ mk_Array8T bool true  false false true  false false false true
+   | x2 ⇒ mk_Array8T bool true  false false true  false false true  false
+   | x3 ⇒ mk_Array8T bool true  false false true  false false true  true
+   | x4 ⇒ mk_Array8T bool true  false false true  false true  false false
+   | x5 ⇒ mk_Array8T bool true  false false true  false true  false true
+   | x6 ⇒ mk_Array8T bool true  false false true  false true  true  false
+   | x7 ⇒ mk_Array8T bool true  false false true  false true  true  true
+   | x8 ⇒ mk_Array8T bool true  false false true  true  false false false
+   | x9 ⇒ mk_Array8T bool true  false false true  true  false false true
+   | xA ⇒ mk_Array8T bool true  false false true  true  false true  false
+   | xB ⇒ mk_Array8T bool true  false false true  true  false true  true
+   | xC ⇒ mk_Array8T bool true  false false true  true  true  false false
+   | xD ⇒ mk_Array8T bool true  false false true  true  true  false true
+   | xE ⇒ mk_Array8T bool true  false false true  true  true  true  false
+   | xF ⇒ mk_Array8T bool true  false false true  true  true  true  true ]
+  | xA ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  false true  false false false false false
+   | x1 ⇒ mk_Array8T bool true  false true  false false false false true
+   | x2 ⇒ mk_Array8T bool true  false true  false false false true  false
+   | x3 ⇒ mk_Array8T bool true  false true  false false false true  true
+   | x4 ⇒ mk_Array8T bool true  false true  false false true  false false
+   | x5 ⇒ mk_Array8T bool true  false true  false false true  false true
+   | x6 ⇒ mk_Array8T bool true  false true  false false true  true  false
+   | x7 ⇒ mk_Array8T bool true  false true  false false true  true  true
+   | x8 ⇒ mk_Array8T bool true  false true  false true  false false false
+   | x9 ⇒ mk_Array8T bool true  false true  false true  false false true
+   | xA ⇒ mk_Array8T bool true  false true  false true  false true  false
+   | xB ⇒ mk_Array8T bool true  false true  false true  false true  true
+   | xC ⇒ mk_Array8T bool true  false true  false true  true  false false
+   | xD ⇒ mk_Array8T bool true  false true  false true  true  false true
+   | xE ⇒ mk_Array8T bool true  false true  false true  true  true  false
+   | xF ⇒ mk_Array8T bool true  false true  false true  true  true  true ]
+  | xB ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  false true  true  false false false false
+   | x1 ⇒ mk_Array8T bool true  false true  true  false false false true
+   | x2 ⇒ mk_Array8T bool true  false true  true  false false true  false
+   | x3 ⇒ mk_Array8T bool true  false true  true  false false true  true
+   | x4 ⇒ mk_Array8T bool true  false true  true  false true  false false
+   | x5 ⇒ mk_Array8T bool true  false true  true  false true  false true
+   | x6 ⇒ mk_Array8T bool true  false true  true  false true  true  false
+   | x7 ⇒ mk_Array8T bool true  false true  true  false true  true  true
+   | x8 ⇒ mk_Array8T bool true  false true  true  true  false false false
+   | x9 ⇒ mk_Array8T bool true  false true  true  true  false false true
+   | xA ⇒ mk_Array8T bool true  false true  true  true  false true  false
+   | xB ⇒ mk_Array8T bool true  false true  true  true  false true  true
+   | xC ⇒ mk_Array8T bool true  false true  true  true  true  false false
+   | xD ⇒ mk_Array8T bool true  false true  true  true  true  false true
+   | xE ⇒ mk_Array8T bool true  false true  true  true  true  true  false
+   | xF ⇒ mk_Array8T bool true  false true  true  true  true  true  true ]
+  | xC ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  true  false false false false false false
+   | x1 ⇒ mk_Array8T bool true  true  false false false false false true
+   | x2 ⇒ mk_Array8T bool true  true  false false false false true  false
+   | x3 ⇒ mk_Array8T bool true  true  false false false false true  true
+   | x4 ⇒ mk_Array8T bool true  true  false false false true  false false
+   | x5 ⇒ mk_Array8T bool true  true  false false false true  false true
+   | x6 ⇒ mk_Array8T bool true  true  false false false true  true  false
+   | x7 ⇒ mk_Array8T bool true  true  false false false true  true  true
+   | x8 ⇒ mk_Array8T bool true  true  false false true  false false false
+   | x9 ⇒ mk_Array8T bool true  true  false false true  false false true
+   | xA ⇒ mk_Array8T bool true  true  false false true  false true  false
+   | xB ⇒ mk_Array8T bool true  true  false false true  false true  true
+   | xC ⇒ mk_Array8T bool true  true  false false true  true  false false
+   | xD ⇒ mk_Array8T bool true  true  false false true  true  false true
+   | xE ⇒ mk_Array8T bool true  true  false false true  true  true  false
+   | xF ⇒ mk_Array8T bool true  true  false false true  true  true  true ]
+  | xD ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  true  false true  false false false false
+   | x1 ⇒ mk_Array8T bool true  true  false true  false false false true
+   | x2 ⇒ mk_Array8T bool true  true  false true  false false true  false
+   | x3 ⇒ mk_Array8T bool true  true  false true  false false true  true
+   | x4 ⇒ mk_Array8T bool true  true  false true  false true  false false
+   | x5 ⇒ mk_Array8T bool true  true  false true  false true  false true
+   | x6 ⇒ mk_Array8T bool true  true  false true  false true  true  false
+   | x7 ⇒ mk_Array8T bool true  true  false true  false true  true  true
+   | x8 ⇒ mk_Array8T bool true  true  false true  true  false false false
+   | x9 ⇒ mk_Array8T bool true  true  false true  true  false false true
+   | xA ⇒ mk_Array8T bool true  true  false true  true  false true  false
+   | xB ⇒ mk_Array8T bool true  true  false true  true  false true  true
+   | xC ⇒ mk_Array8T bool true  true  false true  true  true  false false
+   | xD ⇒ mk_Array8T bool true  true  false true  true  true  false true
+   | xE ⇒ mk_Array8T bool true  true  false true  true  true  true  false
+   | xF ⇒ mk_Array8T bool true  true  false true  true  true  true  true ]
+  | xE ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  true  true  false false false false false
+   | x1 ⇒ mk_Array8T bool true  true  true  false false false false true
+   | x2 ⇒ mk_Array8T bool true  true  true  false false false true  false
+   | x3 ⇒ mk_Array8T bool true  true  true  false false false true  true
+   | x4 ⇒ mk_Array8T bool true  true  true  false false true  false false
+   | x5 ⇒ mk_Array8T bool true  true  true  false false true  false true
+   | x6 ⇒ mk_Array8T bool true  true  true  false false true  true  false
+   | x7 ⇒ mk_Array8T bool true  true  true  false false true  true  true
+   | x8 ⇒ mk_Array8T bool true  true  true  false true  false false false
+   | x9 ⇒ mk_Array8T bool true  true  true  false true  false false true
+   | xA ⇒ mk_Array8T bool true  true  true  false true  false true  false
+   | xB ⇒ mk_Array8T bool true  true  true  false true  false true  true
+   | xC ⇒ mk_Array8T bool true  true  true  false true  true  false false
+   | xD ⇒ mk_Array8T bool true  true  true  false true  true  false true
+   | xE ⇒ mk_Array8T bool true  true  true  false true  true  true  false
+   | xF ⇒ mk_Array8T bool true  true  true  false true  true  true  true ]
+  | xF ⇒ match b8l p with
+   [ x0 ⇒ mk_Array8T bool true  true  true  true  false false false false
+   | x1 ⇒ mk_Array8T bool true  true  true  true  false false false true
+   | x2 ⇒ mk_Array8T bool true  true  true  true  false false true  false
+   | x3 ⇒ mk_Array8T bool true  true  true  true  false false true  true
+   | x4 ⇒ mk_Array8T bool true  true  true  true  false true  false false
+   | x5 ⇒ mk_Array8T bool true  true  true  true  false true  false true
+   | x6 ⇒ mk_Array8T bool true  true  true  true  false true  true  false
+   | x7 ⇒ mk_Array8T bool true  true  true  true  false true  true  true
+   | x8 ⇒ mk_Array8T bool true  true  true  true  true  false false false
+   | x9 ⇒ mk_Array8T bool true  true  true  true  true  false false true
+   | xA ⇒ mk_Array8T bool true  true  true  true  true  false true  false
+   | xB ⇒ mk_Array8T bool true  true  true  true  true  false true  true
+   | xC ⇒ mk_Array8T bool true  true  true  true  true  true  false false
+   | xD ⇒ mk_Array8T bool true  true  true  true  true  true  false true
+   | xE ⇒ mk_Array8T bool true  true  true  true  true  true  true  false
+   | xF ⇒ mk_Array8T bool true  true  true  true  true  true  true  true ]
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_trees.ma b/helm/software/matita/contribs/ng_assembly/emulator/memory/memory_trees.ma
new file mode 100755 (executable)
index 0000000..45bae96
--- /dev/null
@@ -0,0 +1,148 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/memory/memory_struct.ma".
+include "num/word32.ma".
+include "common/option.ma".
+include "common/list.ma".
+
+(* ********************* *)
+(* MEMORIA E DESCRITTORE *)
+(* ********************* *)
+
+ndefinition aux_32B_filler ≝
+λT:Type.λel:T.
+let lev8 ≝ mk_Array16T T el el el el el el el el el el el el el el el el in
+let lev7 ≝ mk_Array16T ?
+           lev8 lev8 lev8 lev8 lev8 lev8 lev8 lev8
+           lev8 lev8 lev8 lev8 lev8 lev8 lev8 lev8
+           in
+let lev6 ≝ mk_Array16T ?
+           lev7 lev7 lev7 lev7 lev7 lev7 lev7 lev7
+           lev7 lev7 lev7 lev7 lev7 lev7 lev7 lev7
+           in
+let lev5 ≝ mk_Array16T ?
+           lev6 lev6 lev6 lev6 lev6 lev6 lev6 lev6
+           lev6 lev6 lev6 lev6 lev6 lev6 lev6 lev6
+           in
+let lev4 ≝ mk_Array16T ?
+           lev5 lev5 lev5 lev5 lev5 lev5 lev5 lev5
+           lev5 lev5 lev5 lev5 lev5 lev5 lev5 lev5
+           in
+let lev3 ≝ mk_Array16T ?
+           lev4 lev4 lev4 lev4 lev4 lev4 lev4 lev4
+           lev4 lev4 lev4 lev4 lev4 lev4 lev4 lev4
+           in
+let lev2 ≝ mk_Array16T ?
+           lev3 lev3 lev3 lev3 lev3 lev3 lev3 lev3
+           lev3 lev3 lev3 lev3 lev3 lev3 lev3 lev3
+           in
+let lev1 ≝ mk_Array16T ?
+           lev2 lev2 lev2 lev2 lev2 lev2 lev2 lev2
+           lev2 lev2 lev2 lev2 lev2 lev2 lev2 lev2
+           in
+lev1.
+
+ndefinition aux_32B_type ≝
+λT:Type.Array16T (Array16T (Array16T (Array16T (Array16T (Array16T (Array16T (Array16T T))))))).
+
+(* tutta la memoria non installata *)
+ndefinition mt_out_of_bound_memory ≝ aux_32B_filler ? MEM_OUT_OF_BOUND.
+
+(* tutta la memoria a 0 *)
+ndefinition mt_zero_memory ≝ aux_32B_filler ? 〈x0,x0〉.
+
+(* visita di un albero da 4GB di elementi: ln16(4GB)=8 passaggi *)
+ndefinition mt_visit ≝
+λT:Type.λdata:aux_32B_type T.λaddr:word32.
+ getn_array16T (b8l (w16l (w32l addr))) ?
+  (getn_array16T (b8h (w16l (w32l addr))) ?
+   (getn_array16T (b8l (w16h (w32l addr))) ?
+    (getn_array16T (b8h (w16h (w32l addr))) ?
+     (getn_array16T (b8l (w16l (w32h addr))) ?
+      (getn_array16T (b8h (w16l (w32h addr))) ?
+       (getn_array16T (b8l (w16h (w32h addr))) ?
+        (getn_array16T (b8h (w16h (w32h addr))) ? data))))))).
+
+(* scrittura di un elemento in un albero da 4GB *)
+ndefinition mt_update ≝
+λT:Type.λdata:aux_32B_type T.λaddr:word32.λv:T.
+ let lev2 ≝ getn_array16T (b8h (w16h (w32h addr))) ? data in
+ let lev3 ≝ getn_array16T (b8l (w16h (w32h addr))) ? lev2 in
+ let lev4 ≝ getn_array16T (b8h (w16l (w32h addr))) ? lev3 in
+ let lev5 ≝ getn_array16T (b8l (w16l (w32h addr))) ? lev4 in
+ let lev6 ≝ getn_array16T (b8h (w16h (w32l addr))) ? lev5 in
+ let lev7 ≝ getn_array16T (b8l (w16h (w32l addr))) ? lev6 in
+ let lev8 ≝ getn_array16T (b8h (w16l (w32l addr))) ? lev7 in
+
+ setn_array16T (b8h (w16h (w32h addr))) ? data
+  (setn_array16T (b8l (w16h (w32h addr))) ? lev2
+   (setn_array16T (b8h (w16l (w32h addr))) ? lev3
+    (setn_array16T (b8l (w16l (w32h addr))) ? lev4
+     (setn_array16T (b8h (w16h (w32l addr))) ? lev5
+      (setn_array16T (b8l (w16h (w32l addr))) ? lev6
+       (setn_array16T (b8h (w16l (w32l addr))) ? lev7
+        (setn_array16T (b8l (w16l (w32l addr))) T lev8 v))))))).
+
+(* scrittura di un range (max 64KB) in un albero da 4GB *)
+nlet rec mt_update_ranged (T:Type) (data:aux_32B_type T) (addr:word32) (w:word16) (rw:rec_word16 w) (v:T) on rw ≝
+ match rw with
+  [ w16_O ⇒ data
+  | w16_S w' rw' ⇒ mt_update_ranged T (mt_update T data addr v)
+                                    (succ_w32 addr) w' rw' v
+  ].
+
+(* scrivi controllando il tipo di memoria *)
+ndefinition mt_mem_update ≝
+λmem:aux_32B_type byte8.
+λchk:aux_32B_type memory_type.
+λaddr:word32.λv:byte8.
+ match mt_visit ? chk addr with
+  (* ROM? ok, ma il valore viene perso *)
+  [ MEM_READ_ONLY ⇒ Some ? mem
+  (* RAM? ok *)
+  | MEM_READ_WRITE ⇒ Some ? (mt_update ? mem addr v)
+  (* NON INSTALLATA? no *)
+  | MEM_OUT_OF_BOUND ⇒ None ? ].  
+
+(* leggi controllando il tipo di memoria *)
+ndefinition mt_mem_read ≝
+λmem:aux_32B_type byte8.
+λchk:aux_32B_type memory_type.
+λaddr:word32.
+ match mt_visit ? chk addr with
+  [ MEM_READ_ONLY ⇒ Some ? (mt_visit ? mem addr)
+  | MEM_READ_WRITE ⇒ Some ? (mt_visit ? mem addr)
+  | MEM_OUT_OF_BOUND ⇒ None ? ].
+
+(* ************************** *)
+(* CARICAMENTO PROGRAMMA/DATI *)
+(* ************************** *)
+
+(* carica a paratire da addr, overflow se si supera 0xFFFF... *)
+nlet rec mt_load_from_source_at (old_mem:aux_32B_type byte8)
+                                (src:list byte8) (addr:word32) on src ≝
+ match src with
+  (* fine di source: carica da old_mem *)
+  [ nil ⇒ old_mem
+  | cons hd tl ⇒ mt_load_from_source_at (mt_update ? old_mem addr hd) tl (succ_w32 addr)
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_instr_mode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_instr_mode.ma
new file mode 100755 (executable)
index 0000000..161aa92
--- /dev/null
@@ -0,0 +1,109 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle modalita' di indirizzamento = caricamento degli operandi *)
+ninductive HC05_instr_mode: Type ≝
+  (* INHERENT = nessun operando *)
+  MODE_INH  : HC05_instr_mode
+  (* INHERENT = nessun operando (A implicito) *)
+| MODE_INHA : HC05_instr_mode
+  (* INHERENT = nessun operando (X implicito) *)
+| MODE_INHX : HC05_instr_mode
+
+  (* INHERENT_ADDRESS = nessun operando (HX implicito) *)
+| MODE_INHX0ADD : HC05_instr_mode
+  (* INHERENT_ADDRESS = nessun operando (HX implicito+0x00bb) *)
+| MODE_INHX1ADD : HC05_instr_mode
+  (* INHERENT_ADDRESS = nessun operando (HX implicito+0xwwww) *)
+| MODE_INHX2ADD : HC05_instr_mode
+
+  (* IMMEDIATE = operando valore immediato byte = 0xbb *)
+| MODE_IMM1 : HC05_instr_mode
+  (* IMMEDIATE_EXT = operando valore immediato byte = 0xbb -> esteso a word *)
+| MODE_IMM1EXT : HC05_instr_mode
+  (* IMMEDIATE = operando valore immediato word = 0xwwww *)
+| MODE_IMM2 : HC05_instr_mode
+  (* DIRECT = operando offset byte = [0x00bb] *)
+| MODE_DIR1 : HC05_instr_mode
+  (* DIRECT = operando offset word = [0xwwww] *)
+| MODE_DIR2 : HC05_instr_mode
+  (* INDEXED = nessun operando (implicito [X] *)
+| MODE_IX0  : HC05_instr_mode
+  (* INDEXED = operando offset relativo byte = [X+0x00bb] *)
+| MODE_IX1  : HC05_instr_mode
+  (* INDEXED = operando offset relativo word = [X+0xwwww] *)
+| MODE_IX2  : HC05_instr_mode
+
+  (* DIRECT(mTNY) = operando offset byte(maschera scrittura implicita 3 bit) *)
+  (* ex: DIR3 e' carica b, scrivi b con n-simo bit modificato *)
+| MODE_DIRn          : oct → HC05_instr_mode
+  (* DIRECT(mTNY) + IMMEDIATE = operando offset byte(maschera lettura implicita 3 bit) *)
+  (*                            + operando valore immediato byte  *)
+  (* ex: DIR2_and_IMM1 e' carica b, carica imm, restituisci n-simo bit di b + imm *)
+| MODE_DIRn_and_IMM1 : oct → HC05_instr_mode
+.
+
+ndefinition eq_HC05_im ≝
+λi1,i2:HC05_instr_mode.
+ match i1 with
+  [ MODE_INH ⇒ match i2 with [ MODE_INH ⇒ true | _ ⇒ false ]
+  | MODE_INHA ⇒ match i2 with [ MODE_INHA ⇒ true | _ ⇒ false ]
+  | MODE_INHX ⇒ match i2 with [ MODE_INHX ⇒ true | _ ⇒ false ]
+  | MODE_INHX0ADD ⇒ match i2 with [ MODE_INHX0ADD ⇒ true | _ ⇒ false ]
+  | MODE_INHX1ADD ⇒ match i2 with [ MODE_INHX1ADD ⇒ true | _ ⇒ false ]
+  | MODE_INHX2ADD ⇒ match i2 with [ MODE_INHX2ADD ⇒ true | _ ⇒ false ]
+  | MODE_IMM1 ⇒ match i2 with [ MODE_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_IMM1EXT ⇒ match i2 with [ MODE_IMM1EXT ⇒ true | _ ⇒ false ]
+  | MODE_IMM2 ⇒ match i2 with [ MODE_IMM2 ⇒ true | _ ⇒ false ]
+  | MODE_DIR1 ⇒ match i2 with [ MODE_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_DIR2 ⇒ match i2 with [ MODE_DIR2 ⇒ true | _ ⇒ false ]
+  | MODE_IX0 ⇒ match i2 with [ MODE_IX0 ⇒ true | _ ⇒ false ]
+  | MODE_IX1 ⇒ match i2 with [ MODE_IX1 ⇒ true | _ ⇒ false ]
+  | MODE_IX2 ⇒ match i2 with [ MODE_IX2 ⇒ true | _ ⇒ false ]
+  | MODE_DIRn n1 ⇒ match i2 with [ MODE_DIRn n2 ⇒ eq_oct n1 n2 | _ ⇒ false ]  
+  | MODE_DIRn_and_IMM1 n1 ⇒ match i2 with [ MODE_DIRn_and_IMM1 n2  ⇒ eq_oct n1 n2 | _ ⇒ false ]
+  ].        
+
+(* iteratore sulle modalita' *)
+ndefinition forall_HC05_im ≝ λP:HC05_instr_mode → bool.
+  P MODE_INH
+⊗ P MODE_INHA
+⊗ P MODE_INHX
+⊗ P MODE_INHX0ADD
+⊗ P MODE_INHX1ADD
+⊗ P MODE_INHX2ADD
+⊗ P MODE_IMM1
+⊗ P MODE_IMM1EXT
+⊗ P MODE_IMM2
+⊗ P MODE_DIR1
+⊗ P MODE_DIR2
+⊗ P MODE_IX0
+⊗ P MODE_IX1
+⊗ P MODE_IX2
+⊗ forall_oct (λo. P (MODE_DIRn o))
+⊗ forall_oct (λo. P (MODE_DIRn_and_IMM1 o)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_opcode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_opcode.ma
new file mode 100755 (executable)
index 0000000..3062ea3
--- /dev/null
@@ -0,0 +1,140 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle istruzioni *)
+ninductive HC05_opcode: Type ≝
+  ADC    : HC05_opcode (* add with carry *)
+| ADD    : HC05_opcode (* add *)
+| AND    : HC05_opcode (* and *)
+| ASL    : HC05_opcode (* aritmetic shift left *)
+| ASR    : HC05_opcode (* aritmetic shift right *)
+| BCC    : HC05_opcode (* branch if C=0 *)
+| BCLRn  : HC05_opcode (* clear bit n *)
+| BCS    : HC05_opcode (* branch if C=1 *)
+| BEQ    : HC05_opcode (* branch if Z=1 *)
+| BHCC   : HC05_opcode (* branch if H=0 *)
+| BHCS   : HC05_opcode (* branch if H=1 *)
+| BHI    : HC05_opcode (* branch if C|Z=0, (higher) *)
+| BIH    : HC05_opcode (* branch if nIRQ=1 *)
+| BIL    : HC05_opcode (* branch if nIRQ=0 *)
+| BIT    : HC05_opcode (* flag = and (bit test) *)
+| BLS    : HC05_opcode (* branch if C|Z=1 (lower or same) *)
+| BMC    : HC05_opcode (* branch if I=0 (interrupt mask clear) *)
+| BMI    : HC05_opcode (* branch if N=1 (minus) *)
+| BMS    : HC05_opcode (* branch if I=1 (interrupt mask set) *)
+| BNE    : HC05_opcode (* branch if Z=0 *)
+| BPL    : HC05_opcode (* branch if N=0 (plus) *)
+| BRA    : HC05_opcode (* branch always *)
+| BRCLRn : HC05_opcode (* branch if bit n clear *)
+| BRN    : HC05_opcode (* branch never (nop) *)
+| BRSETn : HC05_opcode (* branch if bit n set *)
+| BSETn  : HC05_opcode (* set bit n *)
+| BSR    : HC05_opcode (* branch to subroutine *)
+| CLC    : HC05_opcode (* C=0 *)
+| CLI    : HC05_opcode (* I=0 *)
+| CLR    : HC05_opcode (* operand=0 *)
+| CMP    : HC05_opcode (* flag = sub (compare A) *)
+| COM    : HC05_opcode (* not (1 complement) *)
+| CPX    : HC05_opcode (* flag = sub (compare X) *)
+| DEC    : HC05_opcode (* operand=operand-1 (decrement) *)
+| EOR    : HC05_opcode (* xor *)
+| INC    : HC05_opcode (* operand=operand+1 (increment) *)
+| JMP    : HC05_opcode (* jmp word [operand] *)
+| JSR    : HC05_opcode (* jmp to subroutine *)
+| LDA    : HC05_opcode (* load in A *)
+| LDX    : HC05_opcode (* load in X *)
+| LSR    : HC05_opcode (* logical shift right *)
+| MUL    : HC05_opcode (* mul *)
+| NEG    : HC05_opcode (* neg (2 complement) *)
+| NOP    : HC05_opcode (* nop *)
+| ORA    : HC05_opcode (* or *)
+| ROL    : HC05_opcode (* rotate left *)
+| ROR    : HC05_opcode (* rotate right *)
+| RSP    : HC05_opcode (* reset SP (0x00FF) *)
+| RTI    : HC05_opcode (* return from interrupt *)
+| RTS    : HC05_opcode (* return from subroutine *)
+| SBC    : HC05_opcode (* sub with carry*)
+| SEC    : HC05_opcode (* C=1 *)
+| SEI    : HC05_opcode (* I=1 *)
+| STA    : HC05_opcode (* store from A *)
+| STOP   : HC05_opcode (* !!stop mode!! *)
+| STX    : HC05_opcode (* store from X *)
+| SUB    : HC05_opcode (* sub *)
+| SWI    : HC05_opcode (* software interrupt *)
+| TAX    : HC05_opcode (* X=A (transfer A to X) *)
+| TST    : HC05_opcode (* flag = sub (test) *)
+| TXA    : HC05_opcode (* A=X (transfer X to A) *)
+| WAIT   : HC05_opcode (* !!wait mode!! *)
+.
+
+ndefinition eq_HC05_op ≝
+λop1,op2:HC05_opcode.
+ match op1 with
+  [ ADC ⇒ match op2 with [ ADC ⇒ true | _ ⇒ false ]       | ADD ⇒ match op2 with [ ADD ⇒ true | _ ⇒ false ]
+  | AND ⇒ match op2 with [ AND ⇒ true | _ ⇒ false ]       | ASL ⇒ match op2 with [ ASL ⇒ true | _ ⇒ false ]
+  | ASR ⇒ match op2 with [ ASR ⇒ true | _ ⇒ false ]       | BCC ⇒ match op2 with [ BCC ⇒ true | _ ⇒ false ]
+  | BCLRn ⇒ match op2 with [ BCLRn ⇒ true | _ ⇒ false ]   | BCS ⇒ match op2 with [ BCS ⇒ true | _ ⇒ false ]
+  | BEQ ⇒ match op2 with [ BEQ ⇒ true | _ ⇒ false ]       | BHCC ⇒ match op2 with [ BHCC ⇒ true | _ ⇒ false ]
+  | BHCS ⇒ match op2 with [ BHCS ⇒ true | _ ⇒ false ]     | BHI ⇒ match op2 with [ BHI ⇒ true | _ ⇒ false ]
+  | BIH ⇒ match op2 with [ BIH ⇒ true | _ ⇒ false ]       | BIL ⇒ match op2 with [ BIL ⇒ true | _ ⇒ false ]
+  | BIT ⇒ match op2 with [ BIT ⇒ true | _ ⇒ false ]       | BLS ⇒ match op2 with [ BLS ⇒ true | _ ⇒ false ]
+  | BMC ⇒ match op2 with [ BMC ⇒ true | _ ⇒ false ]       | BMI ⇒ match op2 with [ BMI ⇒ true | _ ⇒ false ]
+  | BMS ⇒ match op2 with [ BMS ⇒ true | _ ⇒ false ]       | BNE ⇒ match op2 with [ BNE ⇒ true | _ ⇒ false ]
+  | BPL ⇒ match op2 with [ BPL ⇒ true | _ ⇒ false ]       | BRA ⇒ match op2 with [ BRA ⇒ true | _ ⇒ false ]
+  | BRCLRn ⇒ match op2 with [ BRCLRn ⇒ true | _ ⇒ false ] | BRN ⇒ match op2 with [ BRN ⇒ true | _ ⇒ false ]
+  | BRSETn ⇒ match op2 with [ BRSETn ⇒ true | _ ⇒ false ] | BSETn ⇒ match op2 with [ BSETn ⇒ true | _ ⇒ false ]
+  | BSR ⇒ match op2 with [ BSR ⇒ true | _ ⇒ false ]       | CLC ⇒ match op2 with [ CLC ⇒ true | _ ⇒ false ]
+  | CLI ⇒ match op2 with [ CLI ⇒ true | _ ⇒ false ]       | CLR ⇒ match op2 with [ CLR ⇒ true | _ ⇒ false ]
+  | CMP ⇒ match op2 with [ CMP ⇒ true | _ ⇒ false ]       | COM ⇒ match op2 with [ COM ⇒ true | _ ⇒ false ] 
+  | CPX ⇒ match op2 with [ CPX ⇒ true | _ ⇒ false ]       | DEC ⇒ match op2 with [ DEC ⇒ true | _ ⇒ false ]
+  | EOR ⇒ match op2 with [ EOR ⇒ true | _ ⇒ false ]       | INC ⇒ match op2 with [ INC ⇒ true | _ ⇒ false ]
+  | JMP ⇒ match op2 with [ JMP ⇒ true | _ ⇒ false ]       | JSR ⇒ match op2 with [ JSR ⇒ true | _ ⇒ false ]
+  | LDA ⇒ match op2 with [ LDA ⇒ true | _ ⇒ false ]       | LDX ⇒ match op2 with [ LDX ⇒ true | _ ⇒ false ]
+  | LSR ⇒ match op2 with [ LSR ⇒ true | _ ⇒ false ]       | MUL ⇒ match op2 with [ MUL ⇒ true | _ ⇒ false ]
+  | NEG ⇒ match op2 with [ NEG ⇒ true | _ ⇒ false ]       | NOP ⇒ match op2 with [ NOP ⇒ true | _ ⇒ false ] 
+  | ORA ⇒ match op2 with [ ORA ⇒ true | _ ⇒ false ]       | ROL ⇒ match op2 with [ ROL ⇒ true | _ ⇒ false ]
+  | ROR ⇒ match op2 with [ ROR ⇒ true | _ ⇒ false ]       | RSP ⇒ match op2 with [ RSP ⇒ true | _ ⇒ false ]
+  | RTI ⇒ match op2 with [ RTI ⇒ true | _ ⇒ false ]       | RTS ⇒ match op2 with [ RTS ⇒ true | _ ⇒ false ]
+  | SBC ⇒ match op2 with [ SBC ⇒ true | _ ⇒ false ]       | SEC ⇒ match op2 with [ SEC ⇒ true | _ ⇒ false ]
+  | SEI ⇒ match op2 with [ SEI ⇒ true | _ ⇒ false ]       | STA ⇒ match op2 with [ STA ⇒ true | _ ⇒ false ]
+  | STOP ⇒ match op2 with [ STOP ⇒ true | _ ⇒ false ]     | STX ⇒ match op2 with [ STX ⇒ true | _ ⇒ false ]
+  | SUB ⇒ match op2 with [ SUB ⇒ true | _ ⇒ false ]       | SWI ⇒ match op2 with [ SWI ⇒ true | _ ⇒ false ] 
+  | TAX ⇒ match op2 with [ TAX ⇒ true | _ ⇒ false ]       | TST ⇒ match op2 with [ TST ⇒ true | _ ⇒ false ] 
+  | TXA ⇒ match op2 with [ TXA ⇒ true | _ ⇒ false ]       | WAIT ⇒ match op2 with [ WAIT ⇒ true | _ ⇒ false ]
+  ].
+
+(* iteratore sugli opcode *)
+ndefinition forall_HC05_op ≝ λP:HC05_opcode → bool.
+ P ADC    ⊗ P ADD    ⊗ P AND    ⊗ P ASL    ⊗ P ASR    ⊗ P BCC    ⊗ P BCLRn  ⊗ P BCS    ⊗
+ P BEQ    ⊗ P BHCC   ⊗ P BHCS   ⊗ P BHI    ⊗ P BIH    ⊗ P BIL    ⊗ P BIT    ⊗ P BLS    ⊗
+ P BMC    ⊗ P BMI    ⊗ P BMS    ⊗ P BNE    ⊗ P BPL    ⊗ P BRA    ⊗ P BRCLRn ⊗ P BRN    ⊗
+ P BRSETn ⊗ P BSETn  ⊗ P BSR    ⊗ P CLC    ⊗ P CLI    ⊗ P CLR    ⊗ P CMP    ⊗ P COM    ⊗
+ P CPX    ⊗ P DEC    ⊗ P EOR    ⊗ P INC    ⊗ P JMP    ⊗ P JSR    ⊗ P LDA    ⊗ P LDX    ⊗
+ P LSR    ⊗ P MUL    ⊗ P NEG    ⊗ P NOP    ⊗ P ORA    ⊗ P ROL    ⊗ P ROR    ⊗ P RSP    ⊗
+ P RTI    ⊗ P RTS    ⊗ P SBC    ⊗ P SEC    ⊗ P SEI    ⊗ P STA    ⊗ P STOP   ⊗ P STX    ⊗
+ P SUB    ⊗ P SWI    ⊗ P TAX    ⊗ P TST    ⊗ P TXA    ⊗ P WAIT.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_table.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_table.ma
new file mode 100755 (executable)
index 0000000..4217195
--- /dev/null
@@ -0,0 +1,379 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/HC05_opcode.ma".
+include "emulator/opcodes/HC05_instr_mode.ma".
+include "emulator/opcodes/byte_or_word.ma".
+include "common/list.ma".
+
+(* ***************** *)
+(* TABELLA DELL'HC05 *)
+(* ***************** *)
+
+(* definizione come concatenazione finale di liste per velocizzare il parsing *)
+(* ogni riga e' (any_opcode m) (instr_mode) (opcode esadecimale) (#cicli esecuzione) *)
+(* NB: l'uso di any_opcode m + concatenazione finale tutte liste
+       impedisce di introdurre opcode disomogenei (per mcu) *)
+
+ndefinition opcode_table_HC05_1 ≝
+[
+  quadruple … ADC MODE_IMM1 (Byte 〈xA,x9〉) 〈x0,x2〉
+; quadruple … ADC MODE_DIR1 (Byte 〈xB,x9〉) 〈x0,x3〉
+; quadruple … ADC MODE_DIR2 (Byte 〈xC,x9〉) 〈x0,x4〉
+; quadruple … ADC MODE_IX2  (Byte 〈xD,x9〉) 〈x0,x5〉
+; quadruple … ADC MODE_IX1  (Byte 〈xE,x9〉) 〈x0,x4〉
+; quadruple … ADC MODE_IX0  (Byte 〈xF,x9〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC05_2 ≝
+[
+  quadruple … ADD MODE_IMM1 (Byte 〈xA,xB〉) 〈x0,x2〉
+; quadruple … ADD MODE_DIR1 (Byte 〈xB,xB〉) 〈x0,x3〉
+; quadruple … ADD MODE_DIR2 (Byte 〈xC,xB〉) 〈x0,x4〉
+; quadruple … ADD MODE_IX2  (Byte 〈xD,xB〉) 〈x0,x5〉
+; quadruple … ADD MODE_IX1  (Byte 〈xE,xB〉) 〈x0,x4〉
+; quadruple … ADD MODE_IX0  (Byte 〈xF,xB〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_3 ≝
+[
+  quadruple … AND MODE_IMM1 (Byte 〈xA,x4〉) 〈x0,x2〉
+; quadruple … AND MODE_DIR1 (Byte 〈xB,x4〉) 〈x0,x3〉
+; quadruple … AND MODE_DIR2 (Byte 〈xC,x4〉) 〈x0,x4〉
+; quadruple … AND MODE_IX2  (Byte 〈xD,x4〉) 〈x0,x5〉
+; quadruple … AND MODE_IX1  (Byte 〈xE,x4〉) 〈x0,x4〉
+; quadruple … AND MODE_IX0  (Byte 〈xF,x4〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_4 ≝
+[
+  quadruple … ASL MODE_DIR1 (Byte 〈x3,x8〉) 〈x0,x5〉
+; quadruple … ASL MODE_INHA (Byte 〈x4,x8〉) 〈x0,x3〉
+; quadruple … ASL MODE_INHX (Byte 〈x5,x8〉) 〈x0,x3〉
+; quadruple … ASL MODE_IX1  (Byte 〈x6,x8〉) 〈x0,x6〉
+; quadruple … ASL MODE_IX0  (Byte 〈x7,x8〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_5 ≝
+[
+  quadruple … ASR MODE_DIR1 (Byte 〈x3,x7〉) 〈x0,x5〉
+; quadruple … ASR MODE_INHA (Byte 〈x4,x7〉) 〈x0,x3〉
+; quadruple … ASR MODE_INHX (Byte 〈x5,x7〉) 〈x0,x3〉
+; quadruple … ASR MODE_IX1  (Byte 〈x6,x7〉) 〈x0,x6〉
+; quadruple … ASR MODE_IX0  (Byte 〈x7,x7〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_6 ≝
+[
+  quadruple … BRA  MODE_IMM1 (Byte 〈x2,x0〉) 〈x0,x3〉
+; quadruple … BRN  MODE_IMM1 (Byte 〈x2,x1〉) 〈x0,x3〉
+; quadruple … BHI  MODE_IMM1 (Byte 〈x2,x2〉) 〈x0,x3〉
+; quadruple … BLS  MODE_IMM1 (Byte 〈x2,x3〉) 〈x0,x3〉
+; quadruple … BCC  MODE_IMM1 (Byte 〈x2,x4〉) 〈x0,x3〉
+; quadruple … BCS  MODE_IMM1 (Byte 〈x2,x5〉) 〈x0,x3〉
+; quadruple … BNE  MODE_IMM1 (Byte 〈x2,x6〉) 〈x0,x3〉
+; quadruple … BEQ  MODE_IMM1 (Byte 〈x2,x7〉) 〈x0,x3〉
+; quadruple … BHCC MODE_IMM1 (Byte 〈x2,x8〉) 〈x0,x3〉
+; quadruple … BHCS MODE_IMM1 (Byte 〈x2,x9〉) 〈x0,x3〉
+; quadruple … BPL  MODE_IMM1 (Byte 〈x2,xA〉) 〈x0,x3〉
+; quadruple … BMI  MODE_IMM1 (Byte 〈x2,xB〉) 〈x0,x3〉
+; quadruple … BMC  MODE_IMM1 (Byte 〈x2,xC〉) 〈x0,x3〉
+; quadruple … BMS  MODE_IMM1 (Byte 〈x2,xD〉) 〈x0,x3〉
+; quadruple … BIL  MODE_IMM1 (Byte 〈x2,xE〉) 〈x0,x3〉
+; quadruple … BIH  MODE_IMM1 (Byte 〈x2,xF〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_7 ≝
+[
+  quadruple … BSETn (MODE_DIRn o0) (Byte 〈x1,x0〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o0) (Byte 〈x1,x1〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o1) (Byte 〈x1,x2〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o1) (Byte 〈x1,x3〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o2) (Byte 〈x1,x4〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o2) (Byte 〈x1,x5〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o3) (Byte 〈x1,x6〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o3) (Byte 〈x1,x7〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o4) (Byte 〈x1,x8〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o4) (Byte 〈x1,x9〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o5) (Byte 〈x1,xA〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o5) (Byte 〈x1,xB〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o6) (Byte 〈x1,xC〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o6) (Byte 〈x1,xD〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o7) (Byte 〈x1,xE〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o7) (Byte 〈x1,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_8 ≝
+[
+  quadruple … BRSETn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x0〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x1〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x2〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x3〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x4〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x5〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x6〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x7〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x8〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x9〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xA〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xB〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xC〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xD〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xE〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_9 ≝
+[
+  quadruple … BIT MODE_IMM1 (Byte 〈xA,x5〉) 〈x0,x2〉
+; quadruple … BIT MODE_DIR1 (Byte 〈xB,x5〉) 〈x0,x3〉
+; quadruple … BIT MODE_DIR2 (Byte 〈xC,x5〉) 〈x0,x4〉
+; quadruple … BIT MODE_IX2  (Byte 〈xD,x5〉) 〈x0,x5〉
+; quadruple … BIT MODE_IX1  (Byte 〈xE,x5〉) 〈x0,x4〉
+; quadruple … BIT MODE_IX0  (Byte 〈xF,x5〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_10 ≝
+[
+  quadruple … MUL  MODE_INH (Byte 〈x4,x2〉) 〈x0,xB〉
+; quadruple … RTI  MODE_INH (Byte 〈x8,x0〉) 〈x0,x9〉
+; quadruple … RTS  MODE_INH (Byte 〈x8,x1〉) 〈x0,x6〉
+; quadruple … SWI  MODE_INH (Byte 〈x8,x3〉) 〈x0,xA〉
+; quadruple … STOP MODE_INH (Byte 〈x8,xE〉) 〈x0,x2〉
+; quadruple … WAIT MODE_INH (Byte 〈x8,xF〉) 〈x0,x2〉
+; quadruple … TAX  MODE_INH (Byte 〈x9,x7〉) 〈x0,x2〉
+; quadruple … CLC  MODE_INH (Byte 〈x9,x8〉) 〈x0,x2〉
+; quadruple … SEC  MODE_INH (Byte 〈x9,x9〉) 〈x0,x2〉
+; quadruple … CLI  MODE_INH (Byte 〈x9,xA〉) 〈x0,x2〉
+; quadruple … SEI  MODE_INH (Byte 〈x9,xB〉) 〈x0,x2〉
+; quadruple … RSP  MODE_INH (Byte 〈x9,xC〉) 〈x0,x2〉
+; quadruple … NOP  MODE_INH (Byte 〈x9,xD〉) 〈x0,x2〉
+; quadruple … TXA  MODE_INH (Byte 〈x9,xF〉) 〈x0,x2〉
+].
+
+ndefinition opcode_table_HC05_11 ≝
+[
+  quadruple … CLR MODE_DIR1 (Byte 〈x3,xF〉) 〈x0,x5〉
+; quadruple … CLR MODE_INHA (Byte 〈x4,xF〉) 〈x0,x3〉
+; quadruple … CLR MODE_INHX (Byte 〈x5,xF〉) 〈x0,x3〉
+; quadruple … CLR MODE_IX1  (Byte 〈x6,xF〉) 〈x0,x6〉
+; quadruple … CLR MODE_IX0  (Byte 〈x7,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_12 ≝
+[
+  quadruple … CMP MODE_IMM1 (Byte 〈xA,x1〉) 〈x0,x2〉
+; quadruple … CMP MODE_DIR1 (Byte 〈xB,x1〉) 〈x0,x3〉
+; quadruple … CMP MODE_DIR2 (Byte 〈xC,x1〉) 〈x0,x4〉
+; quadruple … CMP MODE_IX2  (Byte 〈xD,x1〉) 〈x0,x5〉
+; quadruple … CMP MODE_IX1  (Byte 〈xE,x1〉) 〈x0,x4〉
+; quadruple … CMP MODE_IX0  (Byte 〈xF,x1〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_13 ≝
+[
+  quadruple … COM MODE_DIR1 (Byte 〈x3,x3〉) 〈x0,x5〉
+; quadruple … COM MODE_INHA (Byte 〈x4,x3〉) 〈x0,x3〉
+; quadruple … COM MODE_INHX (Byte 〈x5,x3〉) 〈x0,x3〉
+; quadruple … COM MODE_IX1  (Byte 〈x6,x3〉) 〈x0,x6〉
+; quadruple … COM MODE_IX0  (Byte 〈x7,x3〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_14 ≝
+[
+  quadruple … CPX MODE_IMM1 (Byte 〈xA,x3〉) 〈x0,x2〉
+; quadruple … CPX MODE_DIR1 (Byte 〈xB,x3〉) 〈x0,x3〉
+; quadruple … CPX MODE_DIR2 (Byte 〈xC,x3〉) 〈x0,x4〉
+; quadruple … CPX MODE_IX2  (Byte 〈xD,x3〉) 〈x0,x5〉
+; quadruple … CPX MODE_IX1  (Byte 〈xE,x3〉) 〈x0,x4〉
+; quadruple … CPX MODE_IX0  (Byte 〈xF,x3〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_15 ≝
+[
+  quadruple … DEC MODE_DIR1 (Byte 〈x3,xA〉) 〈x0,x5〉
+; quadruple … DEC MODE_INHA (Byte 〈x4,xA〉) 〈x0,x3〉
+; quadruple … DEC MODE_INHX (Byte 〈x5,xA〉) 〈x0,x3〉
+; quadruple … DEC MODE_IX1  (Byte 〈x6,xA〉) 〈x0,x6〉
+; quadruple … DEC MODE_IX0  (Byte 〈x7,xA〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_16 ≝
+[
+  quadruple … EOR MODE_IMM1 (Byte 〈xA,x8〉) 〈x0,x2〉
+; quadruple … EOR MODE_DIR1 (Byte 〈xB,x8〉) 〈x0,x3〉
+; quadruple … EOR MODE_DIR2 (Byte 〈xC,x8〉) 〈x0,x4〉
+; quadruple … EOR MODE_IX2  (Byte 〈xD,x8〉) 〈x0,x5〉
+; quadruple … EOR MODE_IX1  (Byte 〈xE,x8〉) 〈x0,x4〉
+; quadruple … EOR MODE_IX0  (Byte 〈xF,x8〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_17 ≝
+[
+  quadruple … INC MODE_DIR1 (Byte 〈x3,xC〉) 〈x0,x5〉
+; quadruple … INC MODE_INHA (Byte 〈x4,xC〉) 〈x0,x3〉
+; quadruple … INC MODE_INHX (Byte 〈x5,xC〉) 〈x0,x3〉
+; quadruple … INC MODE_IX1  (Byte 〈x6,xC〉) 〈x0,x6〉
+; quadruple … INC MODE_IX0  (Byte 〈x7,xC〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_18 ≝
+[
+  quadruple … JMP MODE_IMM1EXT  (Byte 〈xB,xC〉) 〈x0,x2〉
+; quadruple … JMP MODE_IMM2     (Byte 〈xC,xC〉) 〈x0,x3〉
+; quadruple … JMP MODE_INHX2ADD (Byte 〈xD,xC〉) 〈x0,x4〉
+; quadruple … JMP MODE_INHX1ADD (Byte 〈xE,xC〉) 〈x0,x3〉
+; quadruple … JMP MODE_INHX0ADD (Byte 〈xF,xC〉) 〈x0,x2〉
+].
+
+ndefinition opcode_table_HC05_19 ≝
+[
+  quadruple … BSR MODE_IMM1     (Byte 〈xA,xD〉) 〈x0,x6〉
+; quadruple … JSR MODE_IMM1EXT  (Byte 〈xB,xD〉) 〈x0,x5〉
+; quadruple … JSR MODE_IMM2     (Byte 〈xC,xD〉) 〈x0,x6〉
+; quadruple … JSR MODE_INHX2ADD (Byte 〈xD,xD〉) 〈x0,x7〉
+; quadruple … JSR MODE_INHX1ADD (Byte 〈xE,xD〉) 〈x0,x6〉
+; quadruple … JSR MODE_INHX0ADD (Byte 〈xF,xD〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_20 ≝
+[
+  quadruple … LDA MODE_IMM1 (Byte 〈xA,x6〉) 〈x0,x2〉
+; quadruple … LDA MODE_DIR1 (Byte 〈xB,x6〉) 〈x0,x3〉
+; quadruple … LDA MODE_DIR2 (Byte 〈xC,x6〉) 〈x0,x4〉
+; quadruple … LDA MODE_IX2  (Byte 〈xD,x6〉) 〈x0,x5〉
+; quadruple … LDA MODE_IX1  (Byte 〈xE,x6〉) 〈x0,x4〉
+; quadruple … LDA MODE_IX0  (Byte 〈xF,x6〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_21 ≝
+[
+  quadruple … LDX MODE_IMM1 (Byte 〈xA,xE〉) 〈x0,x2〉
+; quadruple … LDX MODE_DIR1 (Byte 〈xB,xE〉) 〈x0,x3〉
+; quadruple … LDX MODE_DIR2 (Byte 〈xC,xE〉) 〈x0,x4〉
+; quadruple … LDX MODE_IX2  (Byte 〈xD,xE〉) 〈x0,x5〉
+; quadruple … LDX MODE_IX1  (Byte 〈xE,xE〉) 〈x0,x4〉
+; quadruple … LDX MODE_IX0  (Byte 〈xF,xE〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_22 ≝
+[
+  quadruple … LSR MODE_DIR1 (Byte 〈x3,x4〉) 〈x0,x5〉
+; quadruple … LSR MODE_INHA (Byte 〈x4,x4〉) 〈x0,x3〉
+; quadruple … LSR MODE_INHX (Byte 〈x5,x4〉) 〈x0,x3〉
+; quadruple … LSR MODE_IX1  (Byte 〈x6,x4〉) 〈x0,x6〉
+; quadruple … LSR MODE_IX0  (Byte 〈x7,x4〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_23 ≝
+[
+  quadruple … NEG MODE_DIR1 (Byte 〈x3,x0〉) 〈x0,x5〉
+; quadruple … NEG MODE_INHA (Byte 〈x4,x0〉) 〈x0,x3〉
+; quadruple … NEG MODE_INHX (Byte 〈x5,x0〉) 〈x0,x3〉
+; quadruple … NEG MODE_IX1  (Byte 〈x6,x0〉) 〈x0,x6〉
+; quadruple … NEG MODE_IX0  (Byte 〈x7,x0〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_24 ≝
+[
+  quadruple … ORA MODE_IMM1 (Byte 〈xA,xA〉) 〈x0,x2〉
+; quadruple … ORA MODE_DIR1 (Byte 〈xB,xA〉) 〈x0,x3〉
+; quadruple … ORA MODE_DIR2 (Byte 〈xC,xA〉) 〈x0,x4〉
+; quadruple … ORA MODE_IX2  (Byte 〈xD,xA〉) 〈x0,x5〉
+; quadruple … ORA MODE_IX1  (Byte 〈xE,xA〉) 〈x0,x4〉
+; quadruple … ORA MODE_IX0  (Byte 〈xF,xA〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_25 ≝
+[
+  quadruple … ROL MODE_DIR1 (Byte 〈x3,x9〉) 〈x0,x5〉
+; quadruple … ROL MODE_INHA (Byte 〈x4,x9〉) 〈x0,x3〉
+; quadruple … ROL MODE_INHX (Byte 〈x5,x9〉) 〈x0,x3〉
+; quadruple … ROL MODE_IX1  (Byte 〈x6,x9〉) 〈x0,x6〉
+; quadruple … ROL MODE_IX0  (Byte 〈x7,x9〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_26 ≝
+[
+  quadruple … ROR MODE_DIR1 (Byte 〈x3,x6〉) 〈x0,x5〉
+; quadruple … ROR MODE_INHA (Byte 〈x4,x6〉) 〈x0,x3〉
+; quadruple … ROR MODE_INHX (Byte 〈x5,x6〉) 〈x0,x3〉
+; quadruple … ROR MODE_IX1  (Byte 〈x6,x6〉) 〈x0,x6〉
+; quadruple … ROR MODE_IX0  (Byte 〈x7,x6〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC05_27 ≝
+[
+  quadruple … SBC MODE_IMM1 (Byte 〈xA,x2〉) 〈x0,x2〉
+; quadruple … SBC MODE_DIR1 (Byte 〈xB,x2〉) 〈x0,x3〉
+; quadruple … SBC MODE_DIR2 (Byte 〈xC,x2〉) 〈x0,x4〉
+; quadruple … SBC MODE_IX2  (Byte 〈xD,x2〉) 〈x0,x5〉
+; quadruple … SBC MODE_IX1  (Byte 〈xE,x2〉) 〈x0,x4〉
+; quadruple … SBC MODE_IX0  (Byte 〈xF,x2〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_28 ≝
+[
+  quadruple … STA MODE_DIR1 (Byte 〈xB,x7〉) 〈x0,x4〉
+; quadruple … STA MODE_DIR2 (Byte 〈xC,x7〉) 〈x0,x5〉
+; quadruple … STA MODE_IX2  (Byte 〈xD,x7〉) 〈x0,x6〉
+; quadruple … STA MODE_IX1  (Byte 〈xE,x7〉) 〈x0,x5〉
+; quadruple … STA MODE_IX0  (Byte 〈xF,x7〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC05_29 ≝
+[
+  quadruple … STX MODE_DIR1 (Byte 〈xB,xF〉) 〈x0,x4〉
+; quadruple … STX MODE_DIR2 (Byte 〈xC,xF〉) 〈x0,x5〉
+; quadruple … STX MODE_IX2  (Byte 〈xD,xF〉) 〈x0,x6〉
+; quadruple … STX MODE_IX1  (Byte 〈xE,xF〉) 〈x0,x5〉
+; quadruple … STX MODE_IX0  (Byte 〈xF,xF〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC05_30 ≝
+[
+  quadruple … SUB MODE_IMM1 (Byte 〈xA,x0〉) 〈x0,x2〉
+; quadruple … SUB MODE_DIR1 (Byte 〈xB,x0〉) 〈x0,x3〉
+; quadruple … SUB MODE_DIR2 (Byte 〈xC,x0〉) 〈x0,x4〉
+; quadruple … SUB MODE_IX2  (Byte 〈xD,x0〉) 〈x0,x5〉
+; quadruple … SUB MODE_IX1  (Byte 〈xE,x0〉) 〈x0,x4〉
+; quadruple … SUB MODE_IX0  (Byte 〈xF,x0〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC05_31 ≝
+[
+  quadruple … TST MODE_DIR1 (Byte 〈x3,xD〉) 〈x0,x4〉
+; quadruple … TST MODE_INHA (Byte 〈x4,xD〉) 〈x0,x3〉
+; quadruple … TST MODE_INHX (Byte 〈x5,xD〉) 〈x0,x3〉
+; quadruple … TST MODE_IX1  (Byte 〈x6,xD〉) 〈x0,x5〉
+; quadruple … TST MODE_IX0  (Byte 〈x7,xD〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC05 ≝
+ opcode_table_HC05_1  @ opcode_table_HC05_2  @ opcode_table_HC05_3  @ opcode_table_HC05_4  @
+ opcode_table_HC05_5  @ opcode_table_HC05_6  @ opcode_table_HC05_7  @ opcode_table_HC05_8  @
+ opcode_table_HC05_9  @ opcode_table_HC05_10 @ opcode_table_HC05_11 @ opcode_table_HC05_12 @
+ opcode_table_HC05_13 @ opcode_table_HC05_14 @ opcode_table_HC05_15 @ opcode_table_HC05_16 @
+ opcode_table_HC05_17 @ opcode_table_HC05_18 @ opcode_table_HC05_19 @ opcode_table_HC05_20 @
+ opcode_table_HC05_21 @ opcode_table_HC05_22 @ opcode_table_HC05_23 @ opcode_table_HC05_24 @
+ opcode_table_HC05_25 @ opcode_table_HC05_26 @ opcode_table_HC05_27 @ opcode_table_HC05_28 @
+ opcode_table_HC05_29 @ opcode_table_HC05_30 @ opcode_table_HC05_31.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_table_tests.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC05_table_tests.ma
new file mode 100755 (executable)
index 0000000..145e5ca
--- /dev/null
@@ -0,0 +1,70 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/opcode.ma".
+include "emulator/opcodes/HC05_table.ma".
+
+(* ***************** *)
+(* TABELLA DELL'HC05 *)
+(* ***************** *)
+
+(* HC05: opcode non implementati come da manuale *)
+ndefinition HC05_not_impl_byte ≝
+ [〈x3,x1〉;〈x3,x2〉;〈x3,x5〉;〈x3,xB〉;〈x3,xE〉
+ ;〈x4,x1〉;〈x4,x5〉;〈x4,xB〉;〈x4,xE〉
+ ;〈x5,x1〉;〈x5,x2〉;〈x5,x5〉;〈x5,xB〉;〈x5,xE〉
+ ;〈x6,x1〉;〈x6,x2〉;〈x6,x5〉;〈x6,xB〉;〈x6,xE〉
+ ;〈x7,x1〉;〈x7,x2〉;〈x7,x5〉;〈x7,xB〉;〈x7,xE〉
+ ;〈x8,x2〉;〈x8,x4〉;〈x8,x5〉;〈x8,x6〉;〈x8,x7〉;〈x8,x8〉;〈x8,x9〉;〈x8,xA〉;〈x8,xB〉;〈x8,xC〉;〈x8,xD〉
+ ;〈x9,x0〉;〈x9,x1〉;〈x9,x2〉;〈x9,x3〉;〈x9,x4〉;〈x9,x5〉;〈x9,x6〉;〈x9,xE〉
+ ;〈xA,x7〉;〈xA,xC〉;〈xA,xF〉
+ ].
+
+(* test bytecode non implementati *)
+nlemma ok_byte_table_HC05 : forall_b8 (λb.
+ (test_not_impl_byte b HC05_not_impl_byte     ⊙ eq_w16 (get_byte_count HC05 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC05) 〈〈x0,x0〉:〈x0,x1〉〉) ⊗
+ (⊖ (test_not_impl_byte b HC05_not_impl_byte) ⊙ eq_w16 (get_byte_count HC05 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC05) 〈〈x0,x0〉:〈x0,x0〉〉))
+ = true.
+ napply refl_eq.
+nqed.
+
+(* tutti op implementati *)
+nlemma ok_pseudo_table_HC05 :
+ forall_op HC05 (λo.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_pseudo_count HC05 o 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC05)) = true.
+ napply refl_eq.
+nqed.
+
+(* tutte im implementate *)
+nlemma ok_mode_table_HC05 :
+ forall_im HC05 (λi.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_mode_count HC05 i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC05)) = true.
+ napply refl_eq.
+nqed.
+
+(* nessuna ripetizione di combinazione op + imm *)
+nlemma ok_OpIm_table_HC05 :
+ forall_im HC05 (λi.
+  forall_op HC05 (λo.
+   le_w16 (get_OpIm_count HC05 o i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC05) 〈〈x0,x0〉:〈x0,x1〉〉)) = true.
+ napply refl_eq.
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_instr_mode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_instr_mode.ma
new file mode 100755 (executable)
index 0000000..419c28c
--- /dev/null
@@ -0,0 +1,175 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle modalita' di indirizzamento = caricamento degli operandi *)
+ninductive HC08_instr_mode: Type ≝
+  (* INHERENT = nessun operando *)
+  MODE_INH  : HC08_instr_mode
+  (* INHERENT = nessun operando (A implicito) *)
+| MODE_INHA : HC08_instr_mode
+  (* INHERENT = nessun operando (X implicito) *)
+| MODE_INHX : HC08_instr_mode
+  (* INHERENT = nessun operando (H implicito) *)
+| MODE_INHH : HC08_instr_mode
+
+  (* INHERENT_ADDRESS = nessun operando (HX implicito) *)
+| MODE_INHX0ADD : HC08_instr_mode
+  (* INHERENT_ADDRESS = nessun operando (HX implicito+0x00bb) *)
+| MODE_INHX1ADD : HC08_instr_mode
+  (* INHERENT_ADDRESS = nessun operando (HX implicito+0xwwww) *)
+| MODE_INHX2ADD : HC08_instr_mode
+
+  (* IMMEDIATE = operando valore immediato byte = 0xbb *)
+| MODE_IMM1 : HC08_instr_mode
+  (* IMMEDIATE_EXT = operando valore immediato byte = 0xbb -> esteso a word *)
+| MODE_IMM1EXT : HC08_instr_mode
+  (* IMMEDIATE = operando valore immediato word = 0xwwww *)
+| MODE_IMM2 : HC08_instr_mode
+  (* DIRECT = operando offset byte = [0x00bb] *)
+| MODE_DIR1 : HC08_instr_mode
+  (* DIRECT = operando offset word = [0xwwww] *)
+| MODE_DIR2 : HC08_instr_mode
+  (* INDEXED = nessun operando (implicito [X] *)
+| MODE_IX0  : HC08_instr_mode
+  (* INDEXED = operando offset relativo byte = [X+0x00bb] *)
+| MODE_IX1  : HC08_instr_mode
+  (* INDEXED = operando offset relativo word = [X+0xwwww] *)
+| MODE_IX2  : HC08_instr_mode
+  (* INDEXED = operando offset relativo byte = [SP+0x00bb] *)
+| MODE_SP1  : HC08_instr_mode
+  (* INDEXED = operando offset relativo word = [SP+0xwwww] *)
+| MODE_SP2  : HC08_instr_mode
+
+  (* DIRECT → DIRECT = carica da diretto/scrive su diretto *)
+| MODE_DIR1_to_DIR1 : HC08_instr_mode
+  (* IMMEDIATE → DIRECT = carica da immediato/scrive su diretto *)
+| MODE_IMM1_to_DIR1 : HC08_instr_mode
+  (* INDEXED++ → DIRECT = carica da [X]/scrive su diretto/H:X++ *)
+| MODE_IX0p_to_DIR1 : HC08_instr_mode
+  (* DIRECT → INDEXED++ = carica da diretto/scrive su [X]/H:X++ *)
+| MODE_DIR1_to_IX0p : HC08_instr_mode
+
+  (* INHERENT(A) + IMMEDIATE *)
+| MODE_INHA_and_IMM1 : HC08_instr_mode
+  (* INHERENT(X) + IMMEDIATE *)
+| MODE_INHX_and_IMM1 : HC08_instr_mode
+  (* IMMEDIATE + IMMEDIATE *)
+| MODE_IMM1_and_IMM1 : HC08_instr_mode
+  (* DIRECT + IMMEDIATE *)
+| MODE_DIR1_and_IMM1 : HC08_instr_mode
+  (* INDEXED + IMMEDIATE *)
+| MODE_IX0_and_IMM1  : HC08_instr_mode
+  (* INDEXED++ + IMMEDIATE *)
+| MODE_IX0p_and_IMM1 : HC08_instr_mode
+  (* INDEXED + IMMEDIATE *)
+| MODE_IX1_and_IMM1  : HC08_instr_mode
+  (* INDEXED++ + IMMEDIATE *)
+| MODE_IX1p_and_IMM1 : HC08_instr_mode
+  (* INDEXED + IMMEDIATE *)
+| MODE_SP1_and_IMM1  : HC08_instr_mode
+
+  (* DIRECT(mTNY) = operando offset byte(maschera scrittura implicita 3 bit) *)
+  (* ex: DIR3 e' carica b, scrivi b con n-simo bit modificato *)
+| MODE_DIRn          : oct → HC08_instr_mode
+  (* DIRECT(mTNY) + IMMEDIATE = operando offset byte(maschera lettura implicita 3 bit) *)
+  (*                            + operando valore immediato byte  *)
+  (* ex: DIR2_and_IMM1 e' carica b, carica imm, restituisci n-simo bit di b + imm *)
+| MODE_DIRn_and_IMM1 : oct → HC08_instr_mode
+.
+
+ndefinition eq_HC08_im ≝
+λi1,i2:HC08_instr_mode.
+ match i1 with
+  [ MODE_INH ⇒ match i2 with [ MODE_INH ⇒ true | _ ⇒ false ]
+  | MODE_INHA ⇒ match i2 with [ MODE_INHA ⇒ true | _ ⇒ false ]
+  | MODE_INHX ⇒ match i2 with [ MODE_INHX ⇒ true | _ ⇒ false ]
+  | MODE_INHH ⇒ match i2 with [ MODE_INHH ⇒ true | _ ⇒ false ]
+  | MODE_INHX0ADD ⇒ match i2 with [ MODE_INHX0ADD ⇒ true | _ ⇒ false ]
+  | MODE_INHX1ADD ⇒ match i2 with [ MODE_INHX1ADD ⇒ true | _ ⇒ false ]
+  | MODE_INHX2ADD ⇒ match i2 with [ MODE_INHX2ADD ⇒ true | _ ⇒ false ]
+  | MODE_IMM1 ⇒ match i2 with [ MODE_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_IMM1EXT ⇒ match i2 with [ MODE_IMM1EXT ⇒ true | _ ⇒ false ]
+  | MODE_IMM2 ⇒ match i2 with [ MODE_IMM2 ⇒ true | _ ⇒ false ]
+  | MODE_DIR1 ⇒ match i2 with [ MODE_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_DIR2 ⇒ match i2 with [ MODE_DIR2 ⇒ true | _ ⇒ false ]
+  | MODE_IX0 ⇒ match i2 with [ MODE_IX0 ⇒ true | _ ⇒ false ]
+  | MODE_IX1 ⇒ match i2 with [ MODE_IX1 ⇒ true | _ ⇒ false ]
+  | MODE_IX2 ⇒ match i2 with [ MODE_IX2 ⇒ true | _ ⇒ false ]
+  | MODE_SP1 ⇒ match i2 with [ MODE_SP1 ⇒ true | _ ⇒ false ]
+  | MODE_SP2 ⇒ match i2 with [ MODE_SP2 ⇒ true | _ ⇒ false ]  
+  | MODE_DIR1_to_DIR1 ⇒ match i2 with [ MODE_DIR1_to_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_IMM1_to_DIR1 ⇒ match i2 with [ MODE_IMM1_to_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_IX0p_to_DIR1 ⇒ match i2 with [ MODE_IX0p_to_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_DIR1_to_IX0p ⇒ match i2 with [ MODE_DIR1_to_IX0p ⇒ true | _ ⇒ false ]
+  | MODE_INHA_and_IMM1 ⇒ match i2 with [ MODE_INHA_and_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_INHX_and_IMM1 ⇒ match i2 with [ MODE_INHX_and_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_IMM1_and_IMM1 ⇒ match i2 with [ MODE_IMM1_and_IMM1 ⇒ true | _ ⇒ false ]  
+  | MODE_DIR1_and_IMM1 ⇒ match i2 with [ MODE_DIR1_and_IMM1 ⇒ true | _ ⇒ false ]  
+  | MODE_IX0_and_IMM1 ⇒ match i2 with [ MODE_IX0_and_IMM1 ⇒ true | _ ⇒ false ]  
+  | MODE_IX0p_and_IMM1 ⇒ match i2 with [ MODE_IX0p_and_IMM1 ⇒ true | _ ⇒ false ]  
+  | MODE_IX1_and_IMM1 ⇒ match i2 with [ MODE_IX1_and_IMM1 ⇒ true | _ ⇒ false ]  
+  | MODE_IX1p_and_IMM1 ⇒ match i2 with [ MODE_IX1p_and_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_SP1_and_IMM1 ⇒ match i2 with [ MODE_SP1_and_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_DIRn n1 ⇒ match i2 with [ MODE_DIRn n2 ⇒ eq_oct n1 n2 | _ ⇒ false ]  
+  | MODE_DIRn_and_IMM1 n1 ⇒ match i2 with [ MODE_DIRn_and_IMM1 n2  ⇒ eq_oct n1 n2 | _ ⇒ false ]
+  ].    
+
+(* iteratore sulle modalita' *)
+ndefinition forall_HC08_im ≝ λP:HC08_instr_mode → bool.
+  P MODE_INH
+⊗ P MODE_INHA
+⊗ P MODE_INHX
+⊗ P MODE_INHH
+⊗ P MODE_INHX0ADD
+⊗ P MODE_INHX1ADD
+⊗ P MODE_INHX2ADD
+⊗ P MODE_IMM1
+⊗ P MODE_IMM1EXT
+⊗ P MODE_IMM2
+⊗ P MODE_DIR1
+⊗ P MODE_DIR2
+⊗ P MODE_IX0
+⊗ P MODE_IX1
+⊗ P MODE_IX2
+⊗ P MODE_SP1
+⊗ P MODE_SP2
+⊗ P MODE_DIR1_to_DIR1
+⊗ P MODE_IMM1_to_DIR1
+⊗ P MODE_IX0p_to_DIR1
+⊗ P MODE_DIR1_to_IX0p
+⊗ P MODE_INHA_and_IMM1
+⊗ P MODE_INHX_and_IMM1
+⊗ P MODE_IMM1_and_IMM1
+⊗ P MODE_DIR1_and_IMM1
+⊗ P MODE_IX0_and_IMM1
+⊗ P MODE_IX0p_and_IMM1
+⊗ P MODE_IX1_and_IMM1
+⊗ P MODE_IX1p_and_IMM1
+⊗ P MODE_SP1_and_IMM1
+⊗ forall_oct (λo. P (MODE_DIRn o))
+⊗ forall_oct (λo. P (MODE_DIRn_and_IMM1 o)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_opcode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_opcode.ma
new file mode 100755 (executable)
index 0000000..a2a6e92
--- /dev/null
@@ -0,0 +1,182 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle istruzioni *)
+ninductive HC08_opcode: Type ≝
+  ADC    : HC08_opcode (* add with carry *)
+| ADD    : HC08_opcode (* add *)
+| AIS    : HC08_opcode (* add immediate to SP *)
+| AIX    : HC08_opcode (* add immediate to X *)
+| AND    : HC08_opcode (* and *)
+| ASL    : HC08_opcode (* aritmetic shift left *)
+| ASR    : HC08_opcode (* aritmetic shift right *)
+| BCC    : HC08_opcode (* branch if C=0 *)
+| BCLRn  : HC08_opcode (* clear bit n *)
+| BCS    : HC08_opcode (* branch if C=1 *)
+| BEQ    : HC08_opcode (* branch if Z=1 *)
+| BGE    : HC08_opcode (* branch if N⊙V=0 (great or equal) *)
+| BGT    : HC08_opcode (* branch if Z|N⊙V=0 clear (great) *)
+| BHCC   : HC08_opcode (* branch if H=0 *)
+| BHCS   : HC08_opcode (* branch if H=1 *)
+| BHI    : HC08_opcode (* branch if C|Z=0, (higher) *)
+| BIH    : HC08_opcode (* branch if nIRQ=1 *)
+| BIL    : HC08_opcode (* branch if nIRQ=0 *)
+| BIT    : HC08_opcode (* flag = and (bit test) *)
+| BLE    : HC08_opcode (* branch if Z|N⊙V=1 (less or equal) *)
+| BLS    : HC08_opcode (* branch if C|Z=1 (lower or same) *)
+| BLT    : HC08_opcode (* branch if N⊙1=1 (less) *)
+| BMC    : HC08_opcode (* branch if I=0 (interrupt mask clear) *)
+| BMI    : HC08_opcode (* branch if N=1 (minus) *)
+| BMS    : HC08_opcode (* branch if I=1 (interrupt mask set) *)
+| BNE    : HC08_opcode (* branch if Z=0 *)
+| BPL    : HC08_opcode (* branch if N=0 (plus) *)
+| BRA    : HC08_opcode (* branch always *)
+| BRCLRn : HC08_opcode (* branch if bit n clear *)
+| BRN    : HC08_opcode (* branch never (nop) *)
+| BRSETn : HC08_opcode (* branch if bit n set *)
+| BSETn  : HC08_opcode (* set bit n *)
+| BSR    : HC08_opcode (* branch to subroutine *)
+| CBEQA  : HC08_opcode (* compare (A) and BEQ *)
+| CBEQX  : HC08_opcode (* compare (X) and BEQ *)
+| CLC    : HC08_opcode (* C=0 *)
+| CLI    : HC08_opcode (* I=0 *)
+| CLR    : HC08_opcode (* operand=0 *)
+| CMP    : HC08_opcode (* flag = sub (compare A) *)
+| COM    : HC08_opcode (* not (1 complement) *)
+| CPHX   : HC08_opcode (* flag = sub (compare H:X) *)
+| CPX    : HC08_opcode (* flag = sub (compare X) *)
+| DAA    : HC08_opcode (* decimal adjust A *)
+| DBNZ   : HC08_opcode (* dec and BNE *)
+| DEC    : HC08_opcode (* operand=operand-1 (decrement) *)
+| DIV    : HC08_opcode (* div *)
+| EOR    : HC08_opcode (* xor *)
+| INC    : HC08_opcode (* operand=operand+1 (increment) *)
+| JMP    : HC08_opcode (* jmp word [operand] *)
+| JSR    : HC08_opcode (* jmp to subroutine *)
+| LDA    : HC08_opcode (* load in A *)
+| LDHX   : HC08_opcode (* load in H:X *)
+| LDX    : HC08_opcode (* load in X *)
+| LSR    : HC08_opcode (* logical shift right *)
+| MOV    : HC08_opcode (* move *)
+| MUL    : HC08_opcode (* mul *)
+| NEG    : HC08_opcode (* neg (2 complement) *)
+| NOP    : HC08_opcode (* nop *)
+| NSA    : HC08_opcode (* nibble swap A (al:ah <- ah:al) *)
+| ORA    : HC08_opcode (* or *)
+| PSHA   : HC08_opcode (* push A *)
+| PSHH   : HC08_opcode (* push H *)
+| PSHX   : HC08_opcode (* push X *)
+| PULA   : HC08_opcode (* pop A *)
+| PULH   : HC08_opcode (* pop H *)
+| PULX   : HC08_opcode (* pop X *)
+| ROL    : HC08_opcode (* rotate left *)
+| ROR    : HC08_opcode (* rotate right *)
+| RSP    : HC08_opcode (* reset SP (0x00FF) *)
+| RTI    : HC08_opcode (* return from interrupt *)
+| RTS    : HC08_opcode (* return from subroutine *)
+| SBC    : HC08_opcode (* sub with carry*)
+| SEC    : HC08_opcode (* C=1 *)
+| SEI    : HC08_opcode (* I=1 *)
+| STA    : HC08_opcode (* store from A *)
+| STHX   : HC08_opcode (* store from H:X *)
+| STOP   : HC08_opcode (* !!stop mode!! *)
+| STX    : HC08_opcode (* store from X *)
+| SUB    : HC08_opcode (* sub *)
+| SWI    : HC08_opcode (* software interrupt *)
+| TAP    : HC08_opcode (* flag=A (transfer A to process status byte *)
+| TAX    : HC08_opcode (* X=A (transfer A to X) *)
+| TPA    : HC08_opcode (* A=flag (transfer process status byte to A) *)
+| TST    : HC08_opcode (* flag = sub (test) *)
+| TSX    : HC08_opcode (* X:H=SP (transfer SP to H:X) *)
+| TXA    : HC08_opcode (* A=X (transfer X to A) *)
+| TXS    : HC08_opcode (* SP=X:H (transfer H:X to SP) *)
+| WAIT   : HC08_opcode (* !!wait mode!! *)
+.
+
+ndefinition eq_HC08_op ≝
+λop1,op2:HC08_opcode.
+ match op1 with
+  [ ADC ⇒ match op2 with [ ADC ⇒ true | _ ⇒ false ]       | ADD ⇒ match op2 with [ ADD ⇒ true | _ ⇒ false ]
+  | AIS ⇒ match op2 with [ AIS ⇒ true | _ ⇒ false ]       | AIX ⇒ match op2 with [ AIX ⇒ true | _ ⇒ false ]
+  | AND ⇒ match op2 with [ AND ⇒ true | _ ⇒ false ]       | ASL ⇒ match op2 with [ ASL ⇒ true | _ ⇒ false ]
+  | ASR ⇒ match op2 with [ ASR ⇒ true | _ ⇒ false ]       | BCC ⇒ match op2 with [ BCC ⇒ true | _ ⇒ false ]
+  | BCLRn ⇒ match op2 with [ BCLRn ⇒ true | _ ⇒ false ]   | BCS ⇒ match op2 with [ BCS ⇒ true | _ ⇒ false ]
+  | BEQ ⇒ match op2 with [ BEQ ⇒ true | _ ⇒ false ]       | BGE ⇒ match op2 with [ BGE ⇒ true | _ ⇒ false ]
+  | BGT ⇒ match op2 with [ BGT ⇒ true | _ ⇒ false ]       | BHCC ⇒ match op2 with [ BHCC ⇒ true | _ ⇒ false ]
+  | BHCS ⇒ match op2 with [ BHCS ⇒ true | _ ⇒ false ]     | BHI ⇒ match op2 with [ BHI ⇒ true | _ ⇒ false ]
+  | BIH ⇒ match op2 with [ BIH ⇒ true | _ ⇒ false ]       | BIL ⇒ match op2 with [ BIL ⇒ true | _ ⇒ false ]
+  | BIT ⇒ match op2 with [ BIT ⇒ true | _ ⇒ false ]       | BLE ⇒ match op2 with [ BLE ⇒ true | _ ⇒ false ]
+  | BLS ⇒ match op2 with [ BLS ⇒ true | _ ⇒ false ]       | BLT ⇒ match op2 with [ BLT ⇒ true | _ ⇒ false ]
+  | BMC ⇒ match op2 with [ BMC ⇒ true | _ ⇒ false ]       | BMI ⇒ match op2 with [ BMI ⇒ true | _ ⇒ false ]
+  | BMS ⇒ match op2 with [ BMS ⇒ true | _ ⇒ false ]       | BNE ⇒ match op2 with [ BNE ⇒ true | _ ⇒ false ]
+  | BPL ⇒ match op2 with [ BPL ⇒ true | _ ⇒ false ]       | BRA ⇒ match op2 with [ BRA ⇒ true | _ ⇒ false ]
+  | BRCLRn ⇒ match op2 with [ BRCLRn ⇒ true | _ ⇒ false ] | BRN ⇒ match op2 with [ BRN ⇒ true | _ ⇒ false ]
+  | BRSETn ⇒ match op2 with [ BRSETn ⇒ true | _ ⇒ false ] | BSETn ⇒ match op2 with [ BSETn ⇒ true | _ ⇒ false ]
+  | BSR ⇒ match op2 with [ BSR ⇒ true | _ ⇒ false ]       | CBEQA ⇒ match op2 with [ CBEQA ⇒ true | _ ⇒ false ]
+  | CBEQX ⇒ match op2 with [ CBEQX ⇒ true | _ ⇒ false ]   | CLC ⇒ match op2 with [ CLC ⇒ true | _ ⇒ false ]
+  | CLI ⇒ match op2 with [ CLI ⇒ true | _ ⇒ false ]       | CLR ⇒ match op2 with [ CLR ⇒ true | _ ⇒ false ]
+  | CMP ⇒ match op2 with [ CMP ⇒ true | _ ⇒ false ]       | COM ⇒ match op2 with [ COM ⇒ true | _ ⇒ false ]
+  | CPHX ⇒ match op2 with [ CPHX ⇒ true | _ ⇒ false ]     | CPX ⇒ match op2 with [ CPX ⇒ true | _ ⇒ false ]
+  | DAA ⇒ match op2 with [ DAA ⇒ true | _ ⇒ false ]       | DBNZ ⇒ match op2 with [ DBNZ ⇒ true | _ ⇒ false ]
+  | DEC ⇒ match op2 with [ DEC ⇒ true | _ ⇒ false ]       | DIV ⇒ match op2 with [ DIV ⇒ true | _ ⇒ false ]
+  | EOR ⇒ match op2 with [ EOR ⇒ true | _ ⇒ false ]       | INC ⇒ match op2 with [ INC ⇒ true | _ ⇒ false ]
+  | JMP ⇒ match op2 with [ JMP ⇒ true | _ ⇒ false ]       | JSR ⇒ match op2 with [ JSR ⇒ true | _ ⇒ false ]
+  | LDA ⇒ match op2 with [ LDA ⇒ true | _ ⇒ false ]       | LDHX ⇒ match op2 with [ LDHX ⇒ true | _ ⇒ false ]
+  | LDX ⇒ match op2 with [ LDX ⇒ true | _ ⇒ false ]       | LSR ⇒ match op2 with [ LSR ⇒ true | _ ⇒ false ]
+  | MOV ⇒ match op2 with [ MOV ⇒ true | _ ⇒ false ]       | MUL ⇒ match op2 with [ MUL ⇒ true | _ ⇒ false ]
+  | NEG ⇒ match op2 with [ NEG ⇒ true | _ ⇒ false ]       | NOP ⇒ match op2 with [ NOP ⇒ true | _ ⇒ false ]
+  | NSA ⇒ match op2 with [ NSA ⇒ true | _ ⇒ false ]       | ORA ⇒ match op2 with [ ORA ⇒ true | _ ⇒ false ]
+  | PSHA ⇒ match op2 with [ PSHA ⇒ true | _ ⇒ false ]     | PSHH ⇒ match op2 with [ PSHH ⇒ true | _ ⇒ false ]
+  | PSHX ⇒ match op2 with [ PSHX ⇒ true | _ ⇒ false ]     | PULA ⇒ match op2 with [ PULA ⇒ true | _ ⇒ false ]
+  | PULH ⇒ match op2 with [ PULH ⇒ true | _ ⇒ false ]     | PULX ⇒ match op2 with [ PULX ⇒ true | _ ⇒ false ]
+  | ROL ⇒ match op2 with [ ROL ⇒ true | _ ⇒ false ]       | ROR ⇒ match op2 with [ ROR ⇒ true | _ ⇒ false ]
+  | RSP ⇒ match op2 with [ RSP ⇒ true | _ ⇒ false ]       | RTI ⇒ match op2 with [ RTI ⇒ true | _ ⇒ false ]
+  | RTS ⇒ match op2 with [ RTS ⇒ true | _ ⇒ false ]       | SBC ⇒ match op2 with [ SBC ⇒ true | _ ⇒ false ]
+  | SEC ⇒ match op2 with [ SEC ⇒ true | _ ⇒ false ]       | SEI ⇒ match op2 with [ SEI ⇒ true | _ ⇒ false ] 
+  | STA ⇒ match op2 with [ STA ⇒ true | _ ⇒ false ]       | STHX ⇒ match op2 with [ STHX ⇒ true | _ ⇒ false ]
+  | STOP ⇒ match op2 with [ STOP ⇒ true | _ ⇒ false ]     | STX ⇒ match op2 with [ STX ⇒ true | _ ⇒ false ]
+  | SUB ⇒ match op2 with [ SUB ⇒ true | _ ⇒ false ]       | SWI ⇒ match op2 with [ SWI ⇒ true | _ ⇒ false ]
+  | TAP ⇒ match op2 with [ TAP ⇒ true | _ ⇒ false ]       | TAX ⇒ match op2 with [ TAX ⇒ true | _ ⇒ false ]
+  | TPA ⇒ match op2 with [ TPA ⇒ true | _ ⇒ false ]       | TST ⇒ match op2 with [ TST ⇒ true | _ ⇒ false ]
+  | TSX ⇒ match op2 with [ TSX ⇒ true | _ ⇒ false ]       | TXA ⇒ match op2 with [ TXA ⇒ true | _ ⇒ false ]
+  | TXS ⇒ match op2 with [ TXS ⇒ true | _ ⇒ false ]       | WAIT ⇒ match op2 with [ WAIT ⇒ true | _ ⇒ false ]
+  ].
+
+(* iteratore sugli opcode *)
+ndefinition forall_HC08_op ≝ λP:HC08_opcode → bool.
+ P ADC    ⊗ P ADD    ⊗ P AIS    ⊗ P AIX    ⊗ P AND    ⊗ P ASL    ⊗ P ASR    ⊗ P BCC    ⊗
+ P BCLRn  ⊗ P BCS    ⊗ P BEQ    ⊗ P BGE    ⊗ P BGT    ⊗ P BHCC   ⊗ P BHCS   ⊗ P BHI    ⊗
+ P BIH    ⊗ P BIL    ⊗ P BIT    ⊗ P BLE    ⊗ P BLS    ⊗ P BLT    ⊗ P BMC    ⊗ P BMI    ⊗
+ P BMS    ⊗ P BNE    ⊗ P BPL    ⊗ P BRA    ⊗ P BRCLRn ⊗ P BRN    ⊗ P BRSETn ⊗ P BSETn  ⊗
+ P BSR    ⊗ P CBEQA  ⊗ P CBEQX  ⊗ P CLC    ⊗ P CLI    ⊗ P CLR    ⊗ P CMP    ⊗ P COM    ⊗
+ P CPHX   ⊗ P CPX    ⊗ P DAA    ⊗ P DBNZ   ⊗ P DEC    ⊗ P DIV    ⊗ P EOR    ⊗ P INC    ⊗
+ P JMP    ⊗ P JSR    ⊗ P LDA    ⊗ P LDHX   ⊗ P LDX    ⊗ P LSR    ⊗ P MOV    ⊗ P MUL    ⊗
+ P NEG    ⊗ P NOP    ⊗ P NSA    ⊗ P ORA    ⊗ P PSHA   ⊗ P PSHH   ⊗ P PSHX   ⊗ P PULA   ⊗
+ P PULH   ⊗ P PULX   ⊗ P ROL    ⊗ P ROR    ⊗ P RSP    ⊗ P RTI    ⊗ P RTS    ⊗ P SBC    ⊗
+ P SEC    ⊗ P SEI    ⊗ P STA    ⊗ P STHX   ⊗ P STOP   ⊗ P STX    ⊗ P SUB    ⊗ P SWI    ⊗
+ P TAP    ⊗ P TAX    ⊗ P TPA    ⊗ P TST    ⊗ P TSX    ⊗ P TXA    ⊗ P TXS    ⊗ P WAIT.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_table.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_table.ma
new file mode 100755 (executable)
index 0000000..65e3c1e
--- /dev/null
@@ -0,0 +1,476 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/HC08_opcode.ma".
+include "emulator/opcodes/HC08_instr_mode.ma".
+include "emulator/opcodes/byte_or_word.ma".
+include "common/list.ma".
+
+(* ***************** *)
+(* TABELLA DELL'HC08 *)
+(* ***************** *)
+
+(* definizione come concatenazione finale di liste per velocizzare il parsing *)
+(* ogni riga e' (any_opcode m) (instr_mode) (opcode esadecimale) (#cicli esecuzione) *)
+(* NB: l'uso di any_opcode m + concatenazione finale tutte liste
+       impedisce di introdurre opcode disomogenei (per mcu) *)
+
+ndefinition opcode_table_HC08_1 ≝
+[
+  quadruple … ADC MODE_IMM1 (Byte 〈xA,x9〉) 〈x0,x2〉
+; quadruple … ADC MODE_DIR1 (Byte 〈xB,x9〉) 〈x0,x3〉
+; quadruple … ADC MODE_DIR2 (Byte 〈xC,x9〉) 〈x0,x4〉
+; quadruple … ADC MODE_IX2  (Byte 〈xD,x9〉) 〈x0,x4〉
+; quadruple … ADC MODE_IX1  (Byte 〈xE,x9〉) 〈x0,x3〉
+; quadruple … ADC MODE_IX0  (Byte 〈xF,x9〉) 〈x0,x2〉
+; quadruple … ADC MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x9〉〉) 〈x0,x5〉
+; quadruple … ADC MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x9〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_2 ≝
+[
+  quadruple … ADD MODE_IMM1 (Byte 〈xA,xB〉) 〈x0,x2〉
+; quadruple … ADD MODE_DIR1 (Byte 〈xB,xB〉) 〈x0,x3〉
+; quadruple … ADD MODE_DIR2 (Byte 〈xC,xB〉) 〈x0,x4〉
+; quadruple … ADD MODE_IX2  (Byte 〈xD,xB〉) 〈x0,x4〉
+; quadruple … ADD MODE_IX1  (Byte 〈xE,xB〉) 〈x0,x3〉
+; quadruple … ADD MODE_IX0  (Byte 〈xF,xB〉) 〈x0,x2〉
+; quadruple … ADD MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xB〉〉) 〈x0,x5〉
+; quadruple … ADD MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xB〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_3 ≝
+[
+  quadruple … AND MODE_IMM1 (Byte 〈xA,x4〉) 〈x0,x2〉
+; quadruple … AND MODE_DIR1 (Byte 〈xB,x4〉) 〈x0,x3〉
+; quadruple … AND MODE_DIR2 (Byte 〈xC,x4〉) 〈x0,x4〉
+; quadruple … AND MODE_IX2  (Byte 〈xD,x4〉) 〈x0,x4〉
+; quadruple … AND MODE_IX1  (Byte 〈xE,x4〉) 〈x0,x3〉
+; quadruple … AND MODE_IX0  (Byte 〈xF,x4〉) 〈x0,x2〉
+; quadruple … AND MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x4〉〉) 〈x0,x5〉
+; quadruple … AND MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x4〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_4 ≝
+[
+  quadruple … ASL MODE_DIR1 (Byte 〈x3,x8〉) 〈x0,x4〉
+; quadruple … ASL MODE_INHA (Byte 〈x4,x8〉) 〈x0,x1〉
+; quadruple … ASL MODE_INHX (Byte 〈x5,x8〉) 〈x0,x1〉
+; quadruple … ASL MODE_IX1  (Byte 〈x6,x8〉) 〈x0,x4〉
+; quadruple … ASL MODE_IX0  (Byte 〈x7,x8〉) 〈x0,x3〉
+; quadruple … ASL MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x8〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_5 ≝
+[
+  quadruple … ASR MODE_DIR1 (Byte 〈x3,x7〉) 〈x0,x4〉
+; quadruple … ASR MODE_INHA (Byte 〈x4,x7〉) 〈x0,x1〉
+; quadruple … ASR MODE_INHX (Byte 〈x5,x7〉) 〈x0,x1〉
+; quadruple … ASR MODE_IX1  (Byte 〈x6,x7〉) 〈x0,x4〉
+; quadruple … ASR MODE_IX0  (Byte 〈x7,x7〉) 〈x0,x3〉
+; quadruple … ASR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x7〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_6 ≝
+[
+  quadruple … BRA  MODE_IMM1 (Byte 〈x2,x0〉) 〈x0,x3〉
+; quadruple … BRN  MODE_IMM1 (Byte 〈x2,x1〉) 〈x0,x3〉
+; quadruple … BHI  MODE_IMM1 (Byte 〈x2,x2〉) 〈x0,x3〉
+; quadruple … BLS  MODE_IMM1 (Byte 〈x2,x3〉) 〈x0,x3〉
+; quadruple … BCC  MODE_IMM1 (Byte 〈x2,x4〉) 〈x0,x3〉
+; quadruple … BCS  MODE_IMM1 (Byte 〈x2,x5〉) 〈x0,x3〉
+; quadruple … BNE  MODE_IMM1 (Byte 〈x2,x6〉) 〈x0,x3〉
+; quadruple … BEQ  MODE_IMM1 (Byte 〈x2,x7〉) 〈x0,x3〉
+; quadruple … BHCC MODE_IMM1 (Byte 〈x2,x8〉) 〈x0,x3〉
+; quadruple … BHCS MODE_IMM1 (Byte 〈x2,x9〉) 〈x0,x3〉
+; quadruple … BPL  MODE_IMM1 (Byte 〈x2,xA〉) 〈x0,x3〉
+; quadruple … BMI  MODE_IMM1 (Byte 〈x2,xB〉) 〈x0,x3〉
+; quadruple … BMC  MODE_IMM1 (Byte 〈x2,xC〉) 〈x0,x3〉
+; quadruple … BMS  MODE_IMM1 (Byte 〈x2,xD〉) 〈x0,x3〉
+; quadruple … BIL  MODE_IMM1 (Byte 〈x2,xE〉) 〈x0,x3〉
+; quadruple … BIH  MODE_IMM1 (Byte 〈x2,xF〉) 〈x0,x3〉
+; quadruple … BGE  MODE_IMM1 (Byte 〈x9,x0〉) 〈x0,x3〉
+; quadruple … BLT  MODE_IMM1 (Byte 〈x9,x1〉) 〈x0,x3〉
+; quadruple … BGT  MODE_IMM1 (Byte 〈x9,x2〉) 〈x0,x3〉
+; quadruple … BLE  MODE_IMM1 (Byte 〈x9,x3〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC08_7 ≝
+[
+  quadruple … BSETn (MODE_DIRn o0) (Byte 〈x1,x0〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o0) (Byte 〈x1,x1〉) 〈x0,x4〉
+; quadruple … BSETn (MODE_DIRn o1) (Byte 〈x1,x2〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o1) (Byte 〈x1,x3〉) 〈x0,x4〉
+; quadruple … BSETn (MODE_DIRn o2) (Byte 〈x1,x4〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o2) (Byte 〈x1,x5〉) 〈x0,x4〉
+; quadruple … BSETn (MODE_DIRn o3) (Byte 〈x1,x6〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o3) (Byte 〈x1,x7〉) 〈x0,x4〉
+; quadruple … BSETn (MODE_DIRn o4) (Byte 〈x1,x8〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o4) (Byte 〈x1,x9〉) 〈x0,x4〉
+; quadruple … BSETn (MODE_DIRn o5) (Byte 〈x1,xA〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o5) (Byte 〈x1,xB〉) 〈x0,x4〉
+; quadruple … BSETn (MODE_DIRn o6) (Byte 〈x1,xC〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o6) (Byte 〈x1,xD〉) 〈x0,x4〉
+; quadruple … BSETn (MODE_DIRn o7) (Byte 〈x1,xE〉) 〈x0,x4〉
+; quadruple … BCLRn (MODE_DIRn o7) (Byte 〈x1,xF〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_8 ≝
+[
+  quadruple … BRSETn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x0〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x1〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x2〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x3〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x4〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x5〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x6〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x7〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x8〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x9〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xA〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xB〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xC〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xD〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xE〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_9 ≝
+[
+  quadruple … BIT MODE_IMM1 (Byte 〈xA,x5〉) 〈x0,x2〉
+; quadruple … BIT MODE_DIR1 (Byte 〈xB,x5〉) 〈x0,x3〉
+; quadruple … BIT MODE_DIR2 (Byte 〈xC,x5〉) 〈x0,x4〉
+; quadruple … BIT MODE_IX2  (Byte 〈xD,x5〉) 〈x0,x4〉
+; quadruple … BIT MODE_IX1  (Byte 〈xE,x5〉) 〈x0,x3〉
+; quadruple … BIT MODE_IX0  (Byte 〈xF,x5〉) 〈x0,x2〉
+; quadruple … BIT MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x5〉〉) 〈x0,x5〉
+; quadruple … BIT MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x5〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_10 ≝
+[
+  quadruple … MUL  MODE_INH  (Byte 〈x4,x2〉) 〈x0,x5〉
+; quadruple … DIV  MODE_INH  (Byte 〈x5,x2〉) 〈x0,x7〉
+; quadruple … NSA  MODE_INH  (Byte 〈x6,x2〉) 〈x0,x3〉
+; quadruple … DAA  MODE_INH  (Byte 〈x7,x2〉) 〈x0,x2〉
+; quadruple … RTI  MODE_INH  (Byte 〈x8,x0〉) 〈x0,x7〉
+; quadruple … RTS  MODE_INH  (Byte 〈x8,x1〉) 〈x0,x4〉
+; quadruple … SWI  MODE_INH  (Byte 〈x8,x3〉) 〈x0,x9〉
+; quadruple … TAP  MODE_INH  (Byte 〈x8,x4〉) 〈x0,x2〉
+; quadruple … TPA  MODE_INH  (Byte 〈x8,x5〉) 〈x0,x1〉
+; quadruple … PULA MODE_INH  (Byte 〈x8,x6〉) 〈x0,x2〉
+; quadruple … PSHA MODE_INH  (Byte 〈x8,x7〉) 〈x0,x2〉
+; quadruple … PULX MODE_INH  (Byte 〈x8,x8〉) 〈x0,x2〉
+; quadruple … PSHX MODE_INH  (Byte 〈x8,x9〉) 〈x0,x2〉
+; quadruple … PULH MODE_INH  (Byte 〈x8,xA〉) 〈x0,x2〉
+; quadruple … PSHH MODE_INH  (Byte 〈x8,xB〉) 〈x0,x2〉
+; quadruple … STOP MODE_INH  (Byte 〈x8,xE〉) 〈x0,x1〉
+; quadruple … WAIT MODE_INH  (Byte 〈x8,xF〉) 〈x0,x1〉
+; quadruple … TXS  MODE_INH  (Byte 〈x9,x4〉) 〈x0,x2〉
+; quadruple … TSX  MODE_INH  (Byte 〈x9,x5〉) 〈x0,x2〉
+; quadruple … TAX  MODE_INH  (Byte 〈x9,x7〉) 〈x0,x1〉
+; quadruple … CLC  MODE_INH  (Byte 〈x9,x8〉) 〈x0,x1〉
+; quadruple … SEC  MODE_INH  (Byte 〈x9,x9〉) 〈x0,x1〉
+; quadruple … CLI  MODE_INH  (Byte 〈x9,xA〉) 〈x0,x2〉
+; quadruple … SEI  MODE_INH  (Byte 〈x9,xB〉) 〈x0,x2〉
+; quadruple … RSP  MODE_INH  (Byte 〈x9,xC〉) 〈x0,x1〉
+; quadruple … NOP  MODE_INH  (Byte 〈x9,xD〉) 〈x0,x1〉
+; quadruple … TXA  MODE_INH  (Byte 〈x9,xF〉) 〈x0,x1〉
+; quadruple … AIS  MODE_IMM1 (Byte 〈xA,x7〉) 〈x0,x2〉
+; quadruple … AIX  MODE_IMM1 (Byte 〈xA,xF〉) 〈x0,x2〉
+].
+
+ndefinition opcode_table_HC08_11 ≝
+[
+  quadruple … CBEQA MODE_DIR1_and_IMM1 (Byte 〈x3,x1〉) 〈x0,x5〉
+; quadruple … CBEQA MODE_IMM1_and_IMM1 (Byte 〈x4,x1〉) 〈x0,x4〉
+; quadruple … CBEQX MODE_IMM1_and_IMM1 (Byte 〈x5,x1〉) 〈x0,x4〉
+; quadruple … CBEQA MODE_IX1p_and_IMM1 (Byte 〈x6,x1〉) 〈x0,x5〉
+; quadruple … CBEQA MODE_IX0p_and_IMM1 (Byte 〈x7,x1〉) 〈x0,x4〉
+; quadruple … CBEQA MODE_SP1_and_IMM1  (Word 〈〈x9,xE〉:〈x6,x1〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HC08_12 ≝
+[
+  quadruple … CLR MODE_DIR1 (Byte 〈x3,xF〉) 〈x0,x3〉
+; quadruple … CLR MODE_INHA (Byte 〈x4,xF〉) 〈x0,x1〉
+; quadruple … CLR MODE_INHX (Byte 〈x5,xF〉) 〈x0,x1〉
+; quadruple … CLR MODE_IX1  (Byte 〈x6,xF〉) 〈x0,x3〉
+; quadruple … CLR MODE_IX0  (Byte 〈x7,xF〉) 〈x0,x2〉
+; quadruple … CLR MODE_INHH (Byte 〈x8,xC〉) 〈x0,x1〉
+; quadruple … CLR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xF〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_13 ≝
+[
+  quadruple … CMP MODE_IMM1 (Byte 〈xA,x1〉) 〈x0,x2〉
+; quadruple … CMP MODE_DIR1 (Byte 〈xB,x1〉) 〈x0,x3〉
+; quadruple … CMP MODE_DIR2 (Byte 〈xC,x1〉) 〈x0,x4〉
+; quadruple … CMP MODE_IX2  (Byte 〈xD,x1〉) 〈x0,x4〉
+; quadruple … CMP MODE_IX1  (Byte 〈xE,x1〉) 〈x0,x3〉
+; quadruple … CMP MODE_IX0  (Byte 〈xF,x1〉) 〈x0,x2〉
+; quadruple … CMP MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x1〉〉) 〈x0,x5〉
+; quadruple … CMP MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x1〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_14 ≝
+[
+  quadruple … COM MODE_DIR1 (Byte 〈x3,x3〉) 〈x0,x4〉
+; quadruple … COM MODE_INHA (Byte 〈x4,x3〉) 〈x0,x1〉
+; quadruple … COM MODE_INHX (Byte 〈x5,x3〉) 〈x0,x1〉
+; quadruple … COM MODE_IX1  (Byte 〈x6,x3〉) 〈x0,x4〉
+; quadruple … COM MODE_IX0  (Byte 〈x7,x3〉) 〈x0,x3〉
+; quadruple … COM MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x3〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_15 ≝
+[
+  quadruple … STHX MODE_DIR1 (Byte 〈x3,x5〉) 〈x0,x4〉
+; quadruple … LDHX MODE_IMM2 (Byte 〈x4,x5〉) 〈x0,x3〉
+; quadruple … LDHX MODE_DIR1 (Byte 〈x5,x5〉) 〈x0,x4〉
+; quadruple … CPHX MODE_IMM2 (Byte 〈x6,x5〉) 〈x0,x3〉
+; quadruple … CPHX MODE_DIR1 (Byte 〈x7,x5〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_16 ≝
+[
+  quadruple … CPX MODE_IMM1 (Byte 〈xA,x3〉) 〈x0,x2〉
+; quadruple … CPX MODE_DIR1 (Byte 〈xB,x3〉) 〈x0,x3〉
+; quadruple … CPX MODE_DIR2 (Byte 〈xC,x3〉) 〈x0,x4〉
+; quadruple … CPX MODE_IX2  (Byte 〈xD,x3〉) 〈x0,x4〉
+; quadruple … CPX MODE_IX1  (Byte 〈xE,x3〉) 〈x0,x3〉
+; quadruple … CPX MODE_IX0  (Byte 〈xF,x3〉) 〈x0,x2〉
+; quadruple … CPX MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x3〉〉) 〈x0,x5〉
+; quadruple … CPX MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x3〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_17 ≝
+[
+  quadruple … DBNZ MODE_DIR1_and_IMM1 (Byte 〈x3,xB〉) 〈x0,x5〉
+; quadruple … DBNZ MODE_INHA_and_IMM1 (Byte 〈x4,xB〉) 〈x0,x3〉
+; quadruple … DBNZ MODE_INHX_and_IMM1 (Byte 〈x5,xB〉) 〈x0,x3〉
+; quadruple … DBNZ MODE_IX1_and_IMM1  (Byte 〈x6,xB〉) 〈x0,x5〉
+; quadruple … DBNZ MODE_IX0_and_IMM1  (Byte 〈x7,xB〉) 〈x0,x4〉
+; quadruple … DBNZ MODE_SP1_and_IMM1  (Word 〈〈x9,xE〉:〈x6,xB〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HC08_18 ≝
+[
+  quadruple … DEC MODE_DIR1 (Byte 〈x3,xA〉) 〈x0,x4〉
+; quadruple … DEC MODE_INHA (Byte 〈x4,xA〉) 〈x0,x1〉
+; quadruple … DEC MODE_INHX (Byte 〈x5,xA〉) 〈x0,x1〉
+; quadruple … DEC MODE_IX1  (Byte 〈x6,xA〉) 〈x0,x4〉
+; quadruple … DEC MODE_IX0  (Byte 〈x7,xA〉) 〈x0,x3〉
+; quadruple … DEC MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xA〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_19 ≝
+[
+  quadruple … EOR MODE_IMM1 (Byte 〈xA,x8〉) 〈x0,x2〉
+; quadruple … EOR MODE_DIR1 (Byte 〈xB,x8〉) 〈x0,x3〉
+; quadruple … EOR MODE_DIR2 (Byte 〈xC,x8〉) 〈x0,x4〉
+; quadruple … EOR MODE_IX2  (Byte 〈xD,x8〉) 〈x0,x4〉
+; quadruple … EOR MODE_IX1  (Byte 〈xE,x8〉) 〈x0,x3〉
+; quadruple … EOR MODE_IX0  (Byte 〈xF,x8〉) 〈x0,x2〉
+; quadruple … EOR MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x8〉〉) 〈x0,x5〉
+; quadruple … EOR MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x8〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_20 ≝
+[
+  quadruple … INC MODE_DIR1 (Byte 〈x3,xC〉) 〈x0,x4〉
+; quadruple … INC MODE_INHA (Byte 〈x4,xC〉) 〈x0,x1〉
+; quadruple … INC MODE_INHX (Byte 〈x5,xC〉) 〈x0,x1〉
+; quadruple … INC MODE_IX1  (Byte 〈x6,xC〉) 〈x0,x4〉
+; quadruple … INC MODE_IX0  (Byte 〈x7,xC〉) 〈x0,x3〉
+; quadruple … INC MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xC〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_21 ≝
+[
+  quadruple … JMP MODE_IMM1EXT  (Byte 〈xB,xC〉) 〈x0,x2〉
+; quadruple … JMP MODE_IMM2     (Byte 〈xC,xC〉) 〈x0,x3〉
+; quadruple … JMP MODE_INHX2ADD (Byte 〈xD,xC〉) 〈x0,x4〉
+; quadruple … JMP MODE_INHX1ADD (Byte 〈xE,xC〉) 〈x0,x3〉
+; quadruple … JMP MODE_INHX0ADD (Byte 〈xF,xC〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HC08_22 ≝
+[
+  quadruple … BSR MODE_IMM1     (Byte 〈xA,xD〉) 〈x0,x4〉
+; quadruple … JSR MODE_IMM1EXT  (Byte 〈xB,xD〉) 〈x0,x4〉
+; quadruple … JSR MODE_IMM2     (Byte 〈xC,xD〉) 〈x0,x5〉
+; quadruple … JSR MODE_INHX2ADD (Byte 〈xD,xD〉) 〈x0,x6〉
+; quadruple … JSR MODE_INHX1ADD (Byte 〈xE,xD〉) 〈x0,x5〉
+; quadruple … JSR MODE_INHX0ADD (Byte 〈xF,xD〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_23 ≝
+[
+  quadruple … LDA MODE_IMM1 (Byte 〈xA,x6〉) 〈x0,x2〉
+; quadruple … LDA MODE_DIR1 (Byte 〈xB,x6〉) 〈x0,x3〉
+; quadruple … LDA MODE_DIR2 (Byte 〈xC,x6〉) 〈x0,x4〉
+; quadruple … LDA MODE_IX2  (Byte 〈xD,x6〉) 〈x0,x4〉
+; quadruple … LDA MODE_IX1  (Byte 〈xE,x6〉) 〈x0,x3〉
+; quadruple … LDA MODE_IX0  (Byte 〈xF,x6〉) 〈x0,x2〉
+; quadruple … LDA MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x6〉〉) 〈x0,x5〉
+; quadruple … LDA MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x6〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_24 ≝
+[
+  quadruple … LDX MODE_IMM1 (Byte 〈xA,xE〉) 〈x0,x2〉
+; quadruple … LDX MODE_DIR1 (Byte 〈xB,xE〉) 〈x0,x3〉
+; quadruple … LDX MODE_DIR2 (Byte 〈xC,xE〉) 〈x0,x4〉
+; quadruple … LDX MODE_IX2  (Byte 〈xD,xE〉) 〈x0,x4〉
+; quadruple … LDX MODE_IX1  (Byte 〈xE,xE〉) 〈x0,x3〉
+; quadruple … LDX MODE_IX0  (Byte 〈xF,xE〉) 〈x0,x2〉
+; quadruple … LDX MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xE〉〉) 〈x0,x5〉
+; quadruple … LDX MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xE〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_25 ≝
+[
+  quadruple … LSR MODE_DIR1 (Byte 〈x3,x4〉) 〈x0,x4〉
+; quadruple … LSR MODE_INHA (Byte 〈x4,x4〉) 〈x0,x1〉
+; quadruple … LSR MODE_INHX (Byte 〈x5,x4〉) 〈x0,x1〉
+; quadruple … LSR MODE_IX1  (Byte 〈x6,x4〉) 〈x0,x4〉
+; quadruple … LSR MODE_IX0  (Byte 〈x7,x4〉) 〈x0,x3〉
+; quadruple … LSR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x4〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_26 ≝
+[
+  quadruple … MOV MODE_DIR1_to_DIR1 (Byte 〈x4,xE〉) 〈x0,x5〉
+; quadruple … MOV MODE_DIR1_to_IX0p (Byte 〈x5,xE〉) 〈x0,x4〉
+; quadruple … MOV MODE_IMM1_to_DIR1 (Byte 〈x6,xE〉) 〈x0,x4〉
+; quadruple … MOV MODE_IX0p_to_DIR1 (Byte 〈x7,xE〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_27 ≝
+[
+  quadruple … NEG MODE_DIR1 (Byte 〈x3,x0〉) 〈x0,x4〉
+; quadruple … NEG MODE_INHA (Byte 〈x4,x0〉) 〈x0,x1〉
+; quadruple … NEG MODE_INHX (Byte 〈x5,x0〉) 〈x0,x1〉
+; quadruple … NEG MODE_IX1  (Byte 〈x6,x0〉) 〈x0,x4〉
+; quadruple … NEG MODE_IX0  (Byte 〈x7,x0〉) 〈x0,x3〉
+; quadruple … NEG MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x0〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_28 ≝
+[
+  quadruple … ORA MODE_IMM1 (Byte 〈xA,xA〉) 〈x0,x2〉
+; quadruple … ORA MODE_DIR1 (Byte 〈xB,xA〉) 〈x0,x3〉
+; quadruple … ORA MODE_DIR2 (Byte 〈xC,xA〉) 〈x0,x4〉
+; quadruple … ORA MODE_IX2  (Byte 〈xD,xA〉) 〈x0,x4〉
+; quadruple … ORA MODE_IX1  (Byte 〈xE,xA〉) 〈x0,x3〉
+; quadruple … ORA MODE_IX0  (Byte 〈xF,xA〉) 〈x0,x2〉
+; quadruple … ORA MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xA〉〉) 〈x0,x5〉
+; quadruple … ORA MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xA〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_29 ≝
+[
+  quadruple … ROL MODE_DIR1 (Byte 〈x3,x9〉) 〈x0,x4〉
+; quadruple … ROL MODE_INHA (Byte 〈x4,x9〉) 〈x0,x1〉
+; quadruple … ROL MODE_INHX (Byte 〈x5,x9〉) 〈x0,x1〉
+; quadruple … ROL MODE_IX1  (Byte 〈x6,x9〉) 〈x0,x4〉
+; quadruple … ROL MODE_IX0  (Byte 〈x7,x9〉) 〈x0,x3〉
+; quadruple … ROL MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x9〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_30 ≝
+[
+  quadruple … ROR MODE_DIR1 (Byte 〈x3,x6〉) 〈x0,x4〉
+; quadruple … ROR MODE_INHA (Byte 〈x4,x6〉) 〈x0,x1〉
+; quadruple … ROR MODE_INHX (Byte 〈x5,x6〉) 〈x0,x1〉
+; quadruple … ROR MODE_IX1  (Byte 〈x6,x6〉) 〈x0,x4〉
+; quadruple … ROR MODE_IX0  (Byte 〈x7,x6〉) 〈x0,x3〉
+; quadruple … ROR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x6〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HC08_31 ≝
+[
+  quadruple … SBC MODE_IMM1 (Byte 〈xA,x2〉) 〈x0,x2〉
+; quadruple … SBC MODE_DIR1 (Byte 〈xB,x2〉) 〈x0,x3〉
+; quadruple … SBC MODE_DIR2 (Byte 〈xC,x2〉) 〈x0,x4〉
+; quadruple … SBC MODE_IX2  (Byte 〈xD,x2〉) 〈x0,x4〉
+; quadruple … SBC MODE_IX1  (Byte 〈xE,x2〉) 〈x0,x3〉
+; quadruple … SBC MODE_IX0  (Byte 〈xF,x2〉) 〈x0,x2〉
+; quadruple … SBC MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x2〉〉) 〈x0,x5〉
+; quadruple … SBC MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x2〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_32 ≝
+[
+  quadruple … STA MODE_DIR1 (Byte 〈xB,x7〉) 〈x0,x3〉
+; quadruple … STA MODE_DIR2 (Byte 〈xC,x7〉) 〈x0,x4〉
+; quadruple … STA MODE_IX2  (Byte 〈xD,x7〉) 〈x0,x4〉
+; quadruple … STA MODE_IX1  (Byte 〈xE,x7〉) 〈x0,x3〉
+; quadruple … STA MODE_IX0  (Byte 〈xF,x7〉) 〈x0,x2〉
+; quadruple … STA MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x7〉〉) 〈x0,x5〉
+; quadruple … STA MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x7〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_33 ≝
+[
+  quadruple … STX MODE_DIR1 (Byte 〈xB,xF〉) 〈x0,x3〉
+; quadruple … STX MODE_DIR2 (Byte 〈xC,xF〉) 〈x0,x4〉
+; quadruple … STX MODE_IX2  (Byte 〈xD,xF〉) 〈x0,x4〉
+; quadruple … STX MODE_IX1  (Byte 〈xE,xF〉) 〈x0,x3〉
+; quadruple … STX MODE_IX0  (Byte 〈xF,xF〉) 〈x0,x2〉
+; quadruple … STX MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xF〉〉) 〈x0,x5〉
+; quadruple … STX MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xF〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_34 ≝
+[
+  quadruple … SUB MODE_IMM1 (Byte 〈xA,x0〉) 〈x0,x2〉
+; quadruple … SUB MODE_DIR1 (Byte 〈xB,x0〉) 〈x0,x3〉
+; quadruple … SUB MODE_DIR2 (Byte 〈xC,x0〉) 〈x0,x4〉
+; quadruple … SUB MODE_IX2  (Byte 〈xD,x0〉) 〈x0,x4〉
+; quadruple … SUB MODE_IX1  (Byte 〈xE,x0〉) 〈x0,x3〉
+; quadruple … SUB MODE_IX0  (Byte 〈xF,x0〉) 〈x0,x2〉
+; quadruple … SUB MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x0〉〉) 〈x0,x5〉
+; quadruple … SUB MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x0〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08_35 ≝
+[
+  quadruple … TST MODE_DIR1 (Byte 〈x3,xD〉) 〈x0,x3〉
+; quadruple … TST MODE_INHA (Byte 〈x4,xD〉) 〈x0,x1〉
+; quadruple … TST MODE_INHX (Byte 〈x5,xD〉) 〈x0,x1〉
+; quadruple … TST MODE_IX1  (Byte 〈x6,xD〉) 〈x0,x3〉
+; quadruple … TST MODE_IX0  (Byte 〈x7,xD〉) 〈x0,x2〉
+; quadruple … TST MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xD〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HC08 ≝
+opcode_table_HC08_1  @ opcode_table_HC08_2  @ opcode_table_HC08_3  @ opcode_table_HC08_4  @
+opcode_table_HC08_5  @ opcode_table_HC08_6  @ opcode_table_HC08_7  @ opcode_table_HC08_8  @
+opcode_table_HC08_9  @ opcode_table_HC08_10 @ opcode_table_HC08_11 @ opcode_table_HC08_12 @
+opcode_table_HC08_13 @ opcode_table_HC08_14 @ opcode_table_HC08_15 @ opcode_table_HC08_16 @
+opcode_table_HC08_17 @ opcode_table_HC08_18 @ opcode_table_HC08_19 @ opcode_table_HC08_20 @
+opcode_table_HC08_21 @ opcode_table_HC08_22 @ opcode_table_HC08_23 @ opcode_table_HC08_24 @
+opcode_table_HC08_25 @ opcode_table_HC08_26 @ opcode_table_HC08_27 @ opcode_table_HC08_28 @
+opcode_table_HC08_29 @ opcode_table_HC08_30 @ opcode_table_HC08_31 @ opcode_table_HC08_32 @
+opcode_table_HC08_33 @ opcode_table_HC08_34 @ opcode_table_HC08_35.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_table_tests.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HC08_table_tests.ma
new file mode 100755 (executable)
index 0000000..aa792b5
--- /dev/null
@@ -0,0 +1,107 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/opcode.ma".
+include "emulator/opcodes/HC08_table.ma".
+
+(* ***************** *)
+(* TABELLA DELL'HC08 *)
+(* ***************** *)
+
+(* HC08: opcode non implementati come da manuale (byte) *)
+ndefinition HC08_not_impl_byte ≝
+ [〈x3,x2〉;〈x3,xE〉
+ ;〈x8,x2〉;〈x8,xD〉
+ ;〈x9,x6〉;〈x9,xE〉
+ ;〈xA,xC〉
+ ].
+
+(* test bytecode non implementati *)
+nlemma ok_byte_table_HC08 : forall_b8 (λb.
+ (test_not_impl_byte b HC08_not_impl_byte     ⊙ eq_w16 (get_byte_count HC08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC08) 〈〈x0,x0〉:〈x0,x1〉〉) ⊗
+ (⊖ (test_not_impl_byte b HC08_not_impl_byte) ⊙ eq_w16 (get_byte_count HC08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC08) 〈〈x0,x0〉:〈x0,x0〉〉))
+ = true.
+ napply refl_eq.
+nqed.
+
+(* HC08: opcode non implementati come da manuale (0x9E+byte) *)
+ndefinition HC08_not_impl_word ≝
+ [〈x0,x0〉;〈x0,x1〉;〈x0,x2〉;〈x0,x3〉;〈x0,x4〉;〈x0,x5〉;〈x0,x6〉;〈x0,x7〉
+ ;〈x0,x8〉;〈x0,x9〉;〈x0,xA〉;〈x0,xB〉;〈x0,xC〉;〈x0,xD〉;〈x0,xE〉;〈x0,xF〉
+ ;〈x1,x0〉;〈x1,x1〉;〈x1,x2〉;〈x1,x3〉;〈x1,x4〉;〈x1,x5〉;〈x1,x6〉;〈x1,x7〉
+ ;〈x1,x8〉;〈x1,x9〉;〈x1,xA〉;〈x1,xB〉;〈x1,xC〉;〈x1,xD〉;〈x1,xE〉;〈x1,xF〉
+ ;〈x2,x0〉;〈x2,x1〉;〈x2,x2〉;〈x2,x3〉;〈x2,x4〉;〈x2,x5〉;〈x2,x6〉;〈x2,x7〉
+ ;〈x2,x8〉;〈x2,x9〉;〈x2,xA〉;〈x2,xB〉;〈x2,xC〉;〈x2,xD〉;〈x2,xE〉;〈x2,xF〉
+ ;〈x3,x0〉;〈x3,x1〉;〈x3,x2〉;〈x3,x3〉;〈x3,x4〉;〈x3,x5〉;〈x3,x6〉;〈x3,x7〉
+ ;〈x3,x8〉;〈x3,x9〉;〈x3,xA〉;〈x3,xB〉;〈x3,xC〉;〈x3,xD〉;〈x3,xE〉;〈x3,xF〉
+ ;〈x4,x0〉;〈x4,x1〉;〈x4,x2〉;〈x4,x3〉;〈x4,x4〉;〈x4,x5〉;〈x4,x6〉;〈x4,x7〉
+ ;〈x4,x8〉;〈x4,x9〉;〈x4,xA〉;〈x4,xB〉;〈x4,xC〉;〈x4,xD〉;〈x4,xE〉;〈x4,xF〉
+ ;〈x5,x0〉;〈x5,x1〉;〈x5,x2〉;〈x5,x3〉;〈x5,x4〉;〈x5,x5〉;〈x5,x6〉;〈x5,x7〉
+ ;〈x5,x8〉;〈x5,x9〉;〈x5,xA〉;〈x5,xB〉;〈x5,xC〉;〈x5,xD〉;〈x5,xE〉;〈x5,xF〉
+ ;〈x6,x2〉;〈x6,x5〉;〈x6,xE〉
+ ;〈x7,x0〉;〈x7,x1〉;〈x7,x2〉;〈x7,x3〉;〈x7,x4〉;〈x7,x5〉;〈x7,x6〉;〈x7,x7〉
+ ;〈x7,x8〉;〈x7,x9〉;〈x7,xA〉;〈x7,xB〉;〈x7,xC〉;〈x7,xD〉;〈x7,xE〉;〈x7,xF〉
+ ;〈x8,x0〉;〈x8,x1〉;〈x8,x2〉;〈x8,x3〉;〈x8,x4〉;〈x8,x5〉;〈x8,x6〉;〈x8,x7〉
+ ;〈x8,x8〉;〈x8,x9〉;〈x8,xA〉;〈x8,xB〉;〈x8,xC〉;〈x8,xD〉;〈x8,xE〉;〈x8,xF〉
+ ;〈x9,x0〉;〈x9,x1〉;〈x9,x2〉;〈x9,x3〉;〈x9,x4〉;〈x9,x5〉;〈x9,x6〉;〈x9,x7〉
+ ;〈x9,x8〉;〈x9,x9〉;〈x9,xA〉;〈x9,xB〉;〈x9,xC〉;〈x9,xD〉;〈x9,xE〉;〈x9,xF〉
+ ;〈xA,x0〉;〈xA,x1〉;〈xA,x2〉;〈xA,x3〉;〈xA,x4〉;〈xA,x5〉;〈xA,x6〉;〈xA,x7〉
+ ;〈xA,x8〉;〈xA,x9〉;〈xA,xA〉;〈xA,xB〉;〈xA,xC〉;〈xA,xD〉;〈xA,xE〉;〈xA,xF〉
+ ;〈xB,x0〉;〈xB,x1〉;〈xB,x2〉;〈xB,x3〉;〈xB,x4〉;〈xB,x5〉;〈xB,x6〉;〈xB,x7〉
+ ;〈xB,x8〉;〈xB,x9〉;〈xB,xA〉;〈xB,xB〉;〈xB,xC〉;〈xB,xD〉;〈xB,xE〉;〈xB,xF〉
+ ;〈xC,x0〉;〈xC,x1〉;〈xC,x2〉;〈xC,x3〉;〈xC,x4〉;〈xC,x5〉;〈xC,x6〉;〈xC,x7〉
+ ;〈xC,x8〉;〈xC,x9〉;〈xC,xA〉;〈xC,xB〉;〈xC,xC〉;〈xC,xD〉;〈xC,xE〉;〈xC,xF〉
+ ;〈xD,xC〉;〈xD,xD〉
+ ;〈xE,xC〉;〈xE,xD〉
+ ;〈xF,x0〉;〈xF,x1〉;〈xF,x2〉;〈xF,x3〉;〈xF,x4〉;〈xF,x5〉;〈xF,x6〉;〈xF,x7〉
+ ;〈xF,x8〉;〈xF,x9〉;〈xF,xA〉;〈xF,xB〉;〈xF,xC〉;〈xF,xD〉;〈xF,xE〉;〈xF,xF〉
+ ].
+
+(* test bytecode non implementati *)
+nlemma ok_word_table_HC08 : forall_b8 (λb.
+ (test_not_impl_byte b HC08_not_impl_word     ⊙ eq_w16 (get_word_count HC08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC08) 〈〈x0,x0〉:〈x0,x1〉〉) ⊗
+ (⊖ (test_not_impl_byte b HC08_not_impl_word) ⊙ eq_w16 (get_word_count HC08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC08) 〈〈x0,x0〉:〈x0,x0〉〉))
+ = true.
+ napply refl_eq.
+nqed.
+
+(* tutti op implementati *)
+nlemma ok_pseudo_table_HC08 :
+ forall_op HC08 (λo.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_pseudo_count HC08 o 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC08)) = true.
+ napply refl_eq.
+nqed.
+
+(* tutte im implementate *)
+nlemma ok_mode_table_HC08 :
+ forall_im HC08 (λi.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_mode_count HC08 i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC08)) = true.
+ napply refl_eq.
+nqed.
+
+(* nessuna ripetizione di combinazione op + imm *)
+nlemma ok_OpIm_table_HC08 :
+ forall_im HC08 (λi.
+  forall_op HC08 (λo.
+   le_w16 (get_OpIm_count HC08 o i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HC08) 〈〈x0,x0〉:〈x0,x1〉〉)) = true.
+ napply refl_eq.
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_opcode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_opcode.ma
new file mode 100755 (executable)
index 0000000..2ccf392
--- /dev/null
@@ -0,0 +1,185 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle istruzioni *)
+ninductive HCS08_opcode: Type ≝
+  ADC    : HCS08_opcode (* add with carry *)
+| ADD    : HCS08_opcode (* add *)
+| AIS    : HCS08_opcode (* add immediate to SP *)
+| AIX    : HCS08_opcode (* add immediate to X *)
+| AND    : HCS08_opcode (* and *)
+| ASL    : HCS08_opcode (* aritmetic shift left *)
+| ASR    : HCS08_opcode (* aritmetic shift right *)
+| BCC    : HCS08_opcode (* branch if C=0 *)
+| BCLRn  : HCS08_opcode (* clear bit n *)
+| BCS    : HCS08_opcode (* branch if C=1 *)
+| BEQ    : HCS08_opcode (* branch if Z=1 *)
+| BGE    : HCS08_opcode (* branch if N⊙V=0 (great or equal) *)
+| BGND   : HCS08_opcode (* !!background mode!! *)
+| BGT    : HCS08_opcode (* branch if Z|N⊙V=0 clear (great) *)
+| BHCC   : HCS08_opcode (* branch if H=0 *)
+| BHCS   : HCS08_opcode (* branch if H=1 *)
+| BHI    : HCS08_opcode (* branch if C|Z=0, (higher) *)
+| BIH    : HCS08_opcode (* branch if nIRQ=1 *)
+| BIL    : HCS08_opcode (* branch if nIRQ=0 *)
+| BIT    : HCS08_opcode (* flag = and (bit test) *)
+| BLE    : HCS08_opcode (* branch if Z|N⊙V=1 (less or equal) *)
+| BLS    : HCS08_opcode (* branch if C|Z=1 (lower or same) *)
+| BLT    : HCS08_opcode (* branch if N⊙1=1 (less) *)
+| BMC    : HCS08_opcode (* branch if I=0 (interrupt mask clear) *)
+| BMI    : HCS08_opcode (* branch if N=1 (minus) *)
+| BMS    : HCS08_opcode (* branch if I=1 (interrupt mask set) *)
+| BNE    : HCS08_opcode (* branch if Z=0 *)
+| BPL    : HCS08_opcode (* branch if N=0 (plus) *)
+| BRA    : HCS08_opcode (* branch always *)
+| BRCLRn : HCS08_opcode (* branch if bit n clear *)
+| BRN    : HCS08_opcode (* branch never (nop) *)
+| BRSETn : HCS08_opcode (* branch if bit n set *)
+| BSETn  : HCS08_opcode (* set bit n *)
+| BSR    : HCS08_opcode (* branch to subroutine *)
+| CBEQA  : HCS08_opcode (* compare (A) and BEQ *)
+| CBEQX  : HCS08_opcode (* compare (X) and BEQ *)
+| CLC    : HCS08_opcode (* C=0 *)
+| CLI    : HCS08_opcode (* I=0 *)
+| CLR    : HCS08_opcode (* operand=0 *)
+| CMP    : HCS08_opcode (* flag = sub (compare A) *)
+| COM    : HCS08_opcode (* not (1 complement) *)
+| CPHX   : HCS08_opcode (* flag = sub (compare H:X) *)
+| CPX    : HCS08_opcode (* flag = sub (compare X) *)
+| DAA    : HCS08_opcode (* decimal adjust A *)
+| DBNZ   : HCS08_opcode (* dec and BNE *)
+| DEC    : HCS08_opcode (* operand=operand-1 (decrement) *)
+| DIV    : HCS08_opcode (* div *)
+| EOR    : HCS08_opcode (* xor *)
+| INC    : HCS08_opcode (* operand=operand+1 (increment) *)
+| JMP    : HCS08_opcode (* jmp word [operand] *)
+| JSR    : HCS08_opcode (* jmp to subroutine *)
+| LDA    : HCS08_opcode (* load in A *)
+| LDHX   : HCS08_opcode (* load in H:X *)
+| LDX    : HCS08_opcode (* load in X *)
+| LSR    : HCS08_opcode (* logical shift right *)
+| MOV    : HCS08_opcode (* move *)
+| MUL    : HCS08_opcode (* mul *)
+| NEG    : HCS08_opcode (* neg (2 complement) *)
+| NOP    : HCS08_opcode (* nop *)
+| NSA    : HCS08_opcode (* nibble swap A (al:ah <- ah:al) *)
+| ORA    : HCS08_opcode (* or *)
+| PSHA   : HCS08_opcode (* push A *)
+| PSHH   : HCS08_opcode (* push H *)
+| PSHX   : HCS08_opcode (* push X *)
+| PULA   : HCS08_opcode (* pop A *)
+| PULH   : HCS08_opcode (* pop H *)
+| PULX   : HCS08_opcode (* pop X *)
+| ROL    : HCS08_opcode (* rotate left *)
+| ROR    : HCS08_opcode (* rotate right *)
+| RSP    : HCS08_opcode (* reset SP (0x00FF) *)
+| RTI    : HCS08_opcode (* return from interrupt *)
+| RTS    : HCS08_opcode (* return from subroutine *)
+| SBC    : HCS08_opcode (* sub with carry*)
+| SEC    : HCS08_opcode (* C=1 *)
+| SEI    : HCS08_opcode (* I=1 *)
+| STA    : HCS08_opcode (* store from A *)
+| STHX   : HCS08_opcode (* store from H:X *)
+| STOP   : HCS08_opcode (* !!stop mode!! *)
+| STX    : HCS08_opcode (* store from X *)
+| SUB    : HCS08_opcode (* sub *)
+| SWI    : HCS08_opcode (* software interrupt *)
+| TAP    : HCS08_opcode (* flag=A (transfer A to process status byte *)
+| TAX    : HCS08_opcode (* X=A (transfer A to X) *)
+| TPA    : HCS08_opcode (* A=flag (transfer process status byte to A) *)
+| TST    : HCS08_opcode (* flag = sub (test) *)
+| TSX    : HCS08_opcode (* X:H=SP (transfer SP to H:X) *)
+| TXA    : HCS08_opcode (* A=X (transfer X to A) *)
+| TXS    : HCS08_opcode (* SP=X:H (transfer H:X to SP) *)
+| WAIT   : HCS08_opcode (* !!wait mode!! *)
+.
+
+ndefinition eq_HCS08_op ≝
+λop1,op2:HCS08_opcode.
+ match op1 with
+  [ ADC ⇒ match op2 with [ ADC ⇒ true | _ ⇒ false ]     | ADD ⇒ match op2 with [ ADD ⇒ true | _ ⇒ false ]
+  | AIS ⇒ match op2 with [ AIS ⇒ true | _ ⇒ false ]     | AIX ⇒ match op2 with [ AIX ⇒ true | _ ⇒ false ]
+  | AND ⇒ match op2 with [ AND ⇒ true | _ ⇒ false ]     | ASL ⇒ match op2 with [ ASL ⇒ true | _ ⇒ false ]
+  | ASR ⇒ match op2 with [ ASR ⇒ true | _ ⇒ false ]     | BCC ⇒ match op2 with [ BCC ⇒ true | _ ⇒ false ]
+  | BCLRn ⇒ match op2 with [ BCLRn ⇒ true | _ ⇒ false ] | BCS ⇒ match op2 with [ BCS ⇒ true | _ ⇒ false ]
+  | BEQ ⇒ match op2 with [ BEQ ⇒ true | _ ⇒ false ]     | BGE ⇒ match op2 with [ BGE ⇒ true | _ ⇒ false ]
+  | BGND ⇒ match op2 with [ BGND ⇒ true | _ ⇒ false ]   | BGT ⇒ match op2 with [ BGT ⇒ true | _ ⇒ false ]
+  | BHCC ⇒ match op2 with [ BHCC ⇒ true | _ ⇒ false ]   | BHCS ⇒ match op2 with [ BHCS ⇒ true | _ ⇒ false ]
+  | BHI ⇒ match op2 with [ BHI ⇒ true | _ ⇒ false ]     | BIH ⇒ match op2 with [ BIH ⇒ true | _ ⇒ false ]
+  | BIL ⇒ match op2 with [ BIL ⇒ true | _ ⇒ false ]     | BIT ⇒ match op2 with [ BIT ⇒ true | _ ⇒ false ]
+  | BLE ⇒ match op2 with [ BLE ⇒ true | _ ⇒ false ]     | BLS ⇒ match op2 with [ BLS ⇒ true | _ ⇒ false ]
+  | BLT ⇒ match op2 with [ BLT ⇒ true | _ ⇒ false ]     | BMC ⇒ match op2 with [ BMC ⇒ true | _ ⇒ false ]
+  | BMI ⇒ match op2 with [ BMI ⇒ true | _ ⇒ false ]     | BMS ⇒ match op2 with [ BMS ⇒ true | _ ⇒ false ]
+  | BNE ⇒ match op2 with [ BNE ⇒ true | _ ⇒ false ]     | BPL ⇒ match op2 with [ BPL ⇒ true | _ ⇒ false ]
+  | BRA ⇒ match op2 with [ BRA ⇒ true | _ ⇒ false ]     | BRCLRn ⇒ match op2 with [ BRCLRn ⇒ true | _ ⇒ false ]
+  | BRN ⇒ match op2 with [ BRN ⇒ true | _ ⇒ false ]     | BRSETn ⇒ match op2 with [ BRSETn ⇒ true | _ ⇒ false ]
+  | BSETn ⇒ match op2 with [ BSETn ⇒ true | _ ⇒ false ] | BSR ⇒ match op2 with [ BSR ⇒ true | _ ⇒ false ]
+  | CBEQA ⇒ match op2 with [ CBEQA ⇒ true | _ ⇒ false ] | CBEQX ⇒ match op2 with [ CBEQX ⇒ true | _ ⇒ false ]
+  | CLC ⇒ match op2 with [ CLC ⇒ true | _ ⇒ false ]     | CLI ⇒ match op2 with [ CLI ⇒ true | _ ⇒ false ]
+  | CLR ⇒ match op2 with [ CLR ⇒ true | _ ⇒ false ]     | CMP ⇒ match op2 with [ CMP ⇒ true | _ ⇒ false ]
+  | COM ⇒ match op2 with [ COM ⇒ true | _ ⇒ false ]     | CPHX ⇒ match op2 with [ CPHX ⇒ true | _ ⇒ false ]
+  | CPX ⇒ match op2 with [ CPX ⇒ true | _ ⇒ false ]     | DAA ⇒ match op2 with [ DAA ⇒ true | _ ⇒ false ]
+  | DBNZ ⇒ match op2 with [ DBNZ ⇒ true | _ ⇒ false ]   | DEC ⇒ match op2 with [ DEC ⇒ true | _ ⇒ false ]
+  | DIV ⇒ match op2 with [ DIV ⇒ true | _ ⇒ false ]     | EOR ⇒ match op2 with [ EOR ⇒ true | _ ⇒ false ]
+  | INC ⇒ match op2 with [ INC ⇒ true | _ ⇒ false ]     | JMP ⇒ match op2 with [ JMP ⇒ true | _ ⇒ false ]
+  | JSR ⇒ match op2 with [ JSR ⇒ true | _ ⇒ false ]     | LDA ⇒ match op2 with [ LDA ⇒ true | _ ⇒ false ]
+  | LDHX ⇒ match op2 with [ LDHX ⇒ true | _ ⇒ false ]   | LDX ⇒ match op2 with [ LDX ⇒ true | _ ⇒ false ]
+  | LSR ⇒ match op2 with [ LSR ⇒ true | _ ⇒ false ]     | MOV ⇒ match op2 with [ MOV ⇒ true | _ ⇒ false ]
+  | MUL ⇒ match op2 with [ MUL ⇒ true | _ ⇒ false ]     | NEG ⇒ match op2 with [ NEG ⇒ true | _ ⇒ false ]
+  | NOP ⇒ match op2 with [ NOP ⇒ true | _ ⇒ false ]     | NSA ⇒ match op2 with [ NSA ⇒ true | _ ⇒ false ]
+  | ORA ⇒ match op2 with [ ORA ⇒ true | _ ⇒ false ]     | PSHA ⇒ match op2 with [ PSHA ⇒ true | _ ⇒ false ]
+  | PSHH ⇒ match op2 with [ PSHH ⇒ true | _ ⇒ false ]   | PSHX ⇒ match op2 with [ PSHX ⇒ true | _ ⇒ false ]
+  | PULA ⇒ match op2 with [ PULA ⇒ true | _ ⇒ false ]   | PULH ⇒ match op2 with [ PULH ⇒ true | _ ⇒ false ]
+  | PULX ⇒ match op2 with [ PULX ⇒ true | _ ⇒ false ]   | ROL ⇒ match op2 with [ ROL ⇒ true | _ ⇒ false ]
+  | ROR ⇒ match op2 with [ ROR ⇒ true | _ ⇒ false ]     | RSP ⇒ match op2 with [ RSP ⇒ true | _ ⇒ false ]
+  | RTI ⇒ match op2 with [ RTI ⇒ true | _ ⇒ false ]     | RTS ⇒ match op2 with [ RTS ⇒ true | _ ⇒ false ]
+  | SBC ⇒ match op2 with [ SBC ⇒ true | _ ⇒ false ]     | SEC ⇒ match op2 with [ SEC ⇒ true | _ ⇒ false ]
+  | SEI ⇒ match op2 with [ SEI ⇒ true | _ ⇒ false ]     | STA ⇒ match op2 with [ STA ⇒ true | _ ⇒ false ]
+  | STHX ⇒ match op2 with [ STHX ⇒ true | _ ⇒ false ]   | STOP ⇒ match op2 with [ STOP ⇒ true | _ ⇒ false ]
+  | STX ⇒ match op2 with [ STX ⇒ true | _ ⇒ false ]     | SUB ⇒ match op2 with [ SUB ⇒ true | _ ⇒ false ]
+  | SWI ⇒ match op2 with [ SWI ⇒ true | _ ⇒ false ]     | TAP ⇒ match op2 with [ TAP ⇒ true | _ ⇒ false ]
+  | TAX ⇒ match op2 with [ TAX ⇒ true | _ ⇒ false ]     | TPA ⇒ match op2 with [ TPA ⇒ true | _ ⇒ false ]
+  | TST ⇒ match op2 with [ TST ⇒ true | _ ⇒ false ]     | TSX ⇒ match op2 with [ TSX ⇒ true | _ ⇒ false ]
+  | TXA ⇒ match op2 with [ TXA ⇒ true | _ ⇒ false ]     | TXS ⇒ match op2 with [ TXS ⇒ true | _ ⇒ false ]
+  | WAIT ⇒ match op2 with [ WAIT ⇒ true | _ ⇒ false ]
+  ].
+
+(* iteratore sugli opcode *)
+ndefinition forall_HCS08_op ≝ λP:HCS08_opcode → bool.
+ P ADC    ⊗ P ADD    ⊗ P AIS    ⊗ P AIX    ⊗ P AND    ⊗ P ASL    ⊗ P ASR    ⊗ P BCC    ⊗
+ P BCLRn  ⊗ P BCS    ⊗ P BEQ    ⊗ P BGE    ⊗ P BGND   ⊗ P BGT    ⊗ P BHCC   ⊗ P BHCS   ⊗
+ P BHI    ⊗ P BIH    ⊗ P BIL    ⊗ P BIT    ⊗ P BLE    ⊗ P BLS    ⊗ P BLT    ⊗ P BMC    ⊗
+ P BMI    ⊗ P BMS    ⊗ P BNE    ⊗ P BPL    ⊗ P BRA    ⊗ P BRCLRn ⊗ P BRN    ⊗ P BRSETn ⊗
+ P BSETn  ⊗ P BSR    ⊗ P CBEQA  ⊗ P CBEQX  ⊗ P CLC    ⊗ P CLI    ⊗ P CLR    ⊗ P CMP    ⊗
+ P COM    ⊗ P CPHX   ⊗ P CPX    ⊗ P DAA    ⊗ P DBNZ   ⊗ P DEC    ⊗ P DIV    ⊗ P EOR    ⊗
+ P INC    ⊗ P JMP    ⊗ P JSR    ⊗ P LDA    ⊗ P LDHX   ⊗ P LDX    ⊗ P LSR    ⊗ P MOV    ⊗
+ P MUL    ⊗ P NEG    ⊗ P NOP    ⊗ P NSA    ⊗ P ORA    ⊗ P PSHA   ⊗ P PSHH   ⊗ P PSHX   ⊗
+ P PULA   ⊗ P PULH   ⊗ P PULX   ⊗ P ROL    ⊗ P ROR    ⊗ P RSP    ⊗ P RTI    ⊗ P RTS    ⊗
+ P SBC    ⊗ P SEC    ⊗ P SEI    ⊗ P STA    ⊗ P STHX   ⊗ P STOP   ⊗ P STX    ⊗ P SUB    ⊗
+ P SWI    ⊗ P TAP    ⊗ P TAX    ⊗ P TPA    ⊗ P TST    ⊗ P TSX    ⊗ P TXA    ⊗ P TXS    ⊗
+ P WAIT.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_table.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_table.ma
new file mode 100755 (executable)
index 0000000..2982dbb
--- /dev/null
@@ -0,0 +1,488 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/HCS08_opcode.ma".
+include "emulator/opcodes/HC08_instr_mode.ma".
+include "emulator/opcodes/byte_or_word.ma".
+include "common/list.ma".
+
+(* ****************** *)
+(* TABELLA DELL'HCS08 *)
+(* ****************** *)
+
+(* definizione come concatenazione finale di liste per velocizzare il parsing *)
+(* ogni riga e' (any_opcode m) (instr_mode) (opcode esadecimale) (#cicli esecuzione) *)
+(* NB: l'uso di any_opcode m + concatenazione finale tutte liste
+       impedisce di introdurre opcode disomogenei (per mcu) *)
+
+ndefinition opcode_table_HCS08_1 ≝
+[
+  quadruple … ADC MODE_IMM1 (Byte 〈xA,x9〉) 〈x0,x2〉
+; quadruple … ADC MODE_DIR1 (Byte 〈xB,x9〉) 〈x0,x3〉
+; quadruple … ADC MODE_DIR2 (Byte 〈xC,x9〉) 〈x0,x4〉
+; quadruple … ADC MODE_IX2  (Byte 〈xD,x9〉) 〈x0,x4〉
+; quadruple … ADC MODE_IX1  (Byte 〈xE,x9〉) 〈x0,x3〉
+; quadruple … ADC MODE_IX0  (Byte 〈xF,x9〉) 〈x0,x3〉
+; quadruple … ADC MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x9〉〉) 〈x0,x5〉
+; quadruple … ADC MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x9〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_2 ≝
+[
+  quadruple … ADD MODE_IMM1 (Byte 〈xA,xB〉) 〈x0,x2〉
+; quadruple … ADD MODE_DIR1 (Byte 〈xB,xB〉) 〈x0,x3〉
+; quadruple … ADD MODE_DIR2 (Byte 〈xC,xB〉) 〈x0,x4〉
+; quadruple … ADD MODE_IX2  (Byte 〈xD,xB〉) 〈x0,x4〉
+; quadruple … ADD MODE_IX1  (Byte 〈xE,xB〉) 〈x0,x3〉
+; quadruple … ADD MODE_IX0  (Byte 〈xF,xB〉) 〈x0,x3〉
+; quadruple … ADD MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xB〉〉) 〈x0,x5〉
+; quadruple … ADD MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xB〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_3 ≝
+[
+  quadruple … AND MODE_IMM1 (Byte 〈xA,x4〉) 〈x0,x2〉
+; quadruple … AND MODE_DIR1 (Byte 〈xB,x4〉) 〈x0,x3〉
+; quadruple … AND MODE_DIR2 (Byte 〈xC,x4〉) 〈x0,x4〉
+; quadruple … AND MODE_IX2  (Byte 〈xD,x4〉) 〈x0,x4〉
+; quadruple … AND MODE_IX1  (Byte 〈xE,x4〉) 〈x0,x3〉
+; quadruple … AND MODE_IX0  (Byte 〈xF,x4〉) 〈x0,x3〉
+; quadruple … AND MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x4〉〉) 〈x0,x5〉
+; quadruple … AND MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x4〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_4 ≝
+[
+  quadruple … ASL MODE_DIR1 (Byte 〈x3,x8〉) 〈x0,x5〉
+; quadruple … ASL MODE_INHA (Byte 〈x4,x8〉) 〈x0,x1〉
+; quadruple … ASL MODE_INHX (Byte 〈x5,x8〉) 〈x0,x1〉
+; quadruple … ASL MODE_IX1  (Byte 〈x6,x8〉) 〈x0,x5〉
+; quadruple … ASL MODE_IX0  (Byte 〈x7,x8〉) 〈x0,x4〉
+; quadruple … ASL MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x8〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_5 ≝
+[
+  quadruple … ASR MODE_DIR1 (Byte 〈x3,x7〉) 〈x0,x5〉
+; quadruple … ASR MODE_INHA (Byte 〈x4,x7〉) 〈x0,x1〉
+; quadruple … ASR MODE_INHX (Byte 〈x5,x7〉) 〈x0,x1〉
+; quadruple … ASR MODE_IX1  (Byte 〈x6,x7〉) 〈x0,x5〉
+; quadruple … ASR MODE_IX0  (Byte 〈x7,x7〉) 〈x0,x4〉
+; quadruple … ASR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x7〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_6 ≝
+[
+  quadruple … BRA  MODE_IMM1 (Byte 〈x2,x0〉) 〈x0,x3〉
+; quadruple … BRN  MODE_IMM1 (Byte 〈x2,x1〉) 〈x0,x3〉
+; quadruple … BHI  MODE_IMM1 (Byte 〈x2,x2〉) 〈x0,x3〉
+; quadruple … BLS  MODE_IMM1 (Byte 〈x2,x3〉) 〈x0,x3〉
+; quadruple … BCC  MODE_IMM1 (Byte 〈x2,x4〉) 〈x0,x3〉
+; quadruple … BCS  MODE_IMM1 (Byte 〈x2,x5〉) 〈x0,x3〉
+; quadruple … BNE  MODE_IMM1 (Byte 〈x2,x6〉) 〈x0,x3〉
+; quadruple … BEQ  MODE_IMM1 (Byte 〈x2,x7〉) 〈x0,x3〉
+; quadruple … BHCC MODE_IMM1 (Byte 〈x2,x8〉) 〈x0,x3〉
+; quadruple … BHCS MODE_IMM1 (Byte 〈x2,x9〉) 〈x0,x3〉
+; quadruple … BPL  MODE_IMM1 (Byte 〈x2,xA〉) 〈x0,x3〉
+; quadruple … BMI  MODE_IMM1 (Byte 〈x2,xB〉) 〈x0,x3〉
+; quadruple … BMC  MODE_IMM1 (Byte 〈x2,xC〉) 〈x0,x3〉
+; quadruple … BMS  MODE_IMM1 (Byte 〈x2,xD〉) 〈x0,x3〉
+; quadruple … BIL  MODE_IMM1 (Byte 〈x2,xE〉) 〈x0,x3〉
+; quadruple … BIH  MODE_IMM1 (Byte 〈x2,xF〉) 〈x0,x3〉
+; quadruple … BGE  MODE_IMM1 (Byte 〈x9,x0〉) 〈x0,x3〉
+; quadruple … BLT  MODE_IMM1 (Byte 〈x9,x1〉) 〈x0,x3〉
+; quadruple … BGT  MODE_IMM1 (Byte 〈x9,x2〉) 〈x0,x3〉
+; quadruple … BLE  MODE_IMM1 (Byte 〈x9,x3〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HCS08_7 ≝
+[
+  quadruple … BSETn (MODE_DIRn o0) (Byte 〈x1,x0〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o0) (Byte 〈x1,x1〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o1) (Byte 〈x1,x2〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o1) (Byte 〈x1,x3〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o2) (Byte 〈x1,x4〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o2) (Byte 〈x1,x5〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o3) (Byte 〈x1,x6〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o3) (Byte 〈x1,x7〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o4) (Byte 〈x1,x8〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o4) (Byte 〈x1,x9〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o5) (Byte 〈x1,xA〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o5) (Byte 〈x1,xB〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o6) (Byte 〈x1,xC〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o6) (Byte 〈x1,xD〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o7) (Byte 〈x1,xE〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o7) (Byte 〈x1,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HCS08_8 ≝
+[
+  quadruple … BRSETn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x0〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x1〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x2〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x3〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x4〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x5〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x6〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x7〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x8〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x9〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xA〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xB〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xC〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xD〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xE〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HCS08_9 ≝
+[
+  quadruple … BIT MODE_IMM1 (Byte 〈xA,x5〉) 〈x0,x2〉
+; quadruple … BIT MODE_DIR1 (Byte 〈xB,x5〉) 〈x0,x3〉
+; quadruple … BIT MODE_DIR2 (Byte 〈xC,x5〉) 〈x0,x4〉
+; quadruple … BIT MODE_IX2  (Byte 〈xD,x5〉) 〈x0,x4〉
+; quadruple … BIT MODE_IX1  (Byte 〈xE,x5〉) 〈x0,x3〉
+; quadruple … BIT MODE_IX0  (Byte 〈xF,x5〉) 〈x0,x3〉
+; quadruple … BIT MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x5〉〉) 〈x0,x5〉
+; quadruple … BIT MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x5〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_10 ≝
+[
+  quadruple … MUL  MODE_INH  (Byte 〈x4,x2〉) 〈x0,x5〉
+; quadruple … DIV  MODE_INH  (Byte 〈x5,x2〉) 〈x0,x6〉
+; quadruple … NSA  MODE_INH  (Byte 〈x6,x2〉) 〈x0,x1〉
+; quadruple … DAA  MODE_INH  (Byte 〈x7,x2〉) 〈x0,x1〉
+; quadruple … RTI  MODE_INH  (Byte 〈x8,x0〉) 〈x0,x9〉
+; quadruple … RTS  MODE_INH  (Byte 〈x8,x1〉) 〈x0,x6〉
+; quadruple … SWI  MODE_INH  (Byte 〈x8,x3〉) 〈x0,xB〉
+; quadruple … BGND MODE_INH  (Byte 〈x8,x2〉) 〈x0,x5〉
+; quadruple … TAP  MODE_INH  (Byte 〈x8,x4〉) 〈x0,x1〉
+; quadruple … TPA  MODE_INH  (Byte 〈x8,x5〉) 〈x0,x1〉
+; quadruple … PULA MODE_INH  (Byte 〈x8,x6〉) 〈x0,x3〉
+; quadruple … PSHA MODE_INH  (Byte 〈x8,x7〉) 〈x0,x2〉
+; quadruple … PULX MODE_INH  (Byte 〈x8,x8〉) 〈x0,x3〉
+; quadruple … PSHX MODE_INH  (Byte 〈x8,x9〉) 〈x0,x2〉
+; quadruple … PULH MODE_INH  (Byte 〈x8,xA〉) 〈x0,x3〉
+; quadruple … PSHH MODE_INH  (Byte 〈x8,xB〉) 〈x0,x2〉
+; quadruple … STOP MODE_INH  (Byte 〈x8,xE〉) 〈x0,x2〉
+; quadruple … WAIT MODE_INH  (Byte 〈x8,xF〉) 〈x0,x2〉
+; quadruple … TXS  MODE_INH  (Byte 〈x9,x4〉) 〈x0,x2〉
+; quadruple … TSX  MODE_INH  (Byte 〈x9,x5〉) 〈x0,x2〉
+; quadruple … TAX  MODE_INH  (Byte 〈x9,x7〉) 〈x0,x1〉
+; quadruple … CLC  MODE_INH  (Byte 〈x9,x8〉) 〈x0,x1〉
+; quadruple … SEC  MODE_INH  (Byte 〈x9,x9〉) 〈x0,x1〉
+; quadruple … CLI  MODE_INH  (Byte 〈x9,xA〉) 〈x0,x1〉
+; quadruple … SEI  MODE_INH  (Byte 〈x9,xB〉) 〈x0,x1〉
+; quadruple … RSP  MODE_INH  (Byte 〈x9,xC〉) 〈x0,x1〉
+; quadruple … NOP  MODE_INH  (Byte 〈x9,xD〉) 〈x0,x1〉
+; quadruple … TXA  MODE_INH  (Byte 〈x9,xF〉) 〈x0,x1〉
+; quadruple … AIS  MODE_IMM1 (Byte 〈xA,x7〉) 〈x0,x2〉
+; quadruple … AIX  MODE_IMM1 (Byte 〈xA,xF〉) 〈x0,x2〉
+].
+
+ndefinition opcode_table_HCS08_11 ≝
+[
+  quadruple … CBEQA MODE_DIR1_and_IMM1 (Byte 〈x3,x1〉) 〈x0,x5〉
+; quadruple … CBEQA MODE_IMM1_and_IMM1 (Byte 〈x4,x1〉) 〈x0,x4〉
+; quadruple … CBEQX MODE_IMM1_and_IMM1 (Byte 〈x5,x1〉) 〈x0,x4〉
+; quadruple … CBEQA MODE_IX1p_and_IMM1 (Byte 〈x6,x1〉) 〈x0,x5〉
+; quadruple … CBEQA MODE_IX0p_and_IMM1 (Byte 〈x7,x1〉) 〈x0,x5〉
+; quadruple … CBEQA MODE_SP1_and_IMM1  (Word 〈〈x9,xE〉:〈x6,x1〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_12 ≝
+[
+  quadruple … CLR MODE_DIR1 (Byte 〈x3,xF〉) 〈x0,x5〉
+; quadruple … CLR MODE_INHA (Byte 〈x4,xF〉) 〈x0,x1〉
+; quadruple … CLR MODE_INHX (Byte 〈x5,xF〉) 〈x0,x1〉
+; quadruple … CLR MODE_IX1  (Byte 〈x6,xF〉) 〈x0,x5〉
+; quadruple … CLR MODE_IX0  (Byte 〈x7,xF〉) 〈x0,x4〉
+; quadruple … CLR MODE_INHH (Byte 〈x8,xC〉) 〈x0,x1〉
+; quadruple … CLR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xF〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_13 ≝
+[
+  quadruple … CMP MODE_IMM1 (Byte 〈xA,x1〉) 〈x0,x2〉
+; quadruple … CMP MODE_DIR1 (Byte 〈xB,x1〉) 〈x0,x3〉
+; quadruple … CMP MODE_DIR2 (Byte 〈xC,x1〉) 〈x0,x4〉
+; quadruple … CMP MODE_IX2  (Byte 〈xD,x1〉) 〈x0,x4〉
+; quadruple … CMP MODE_IX1  (Byte 〈xE,x1〉) 〈x0,x3〉
+; quadruple … CMP MODE_IX0  (Byte 〈xF,x1〉) 〈x0,x3〉
+; quadruple … CMP MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x1〉〉) 〈x0,x5〉
+; quadruple … CMP MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x1〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_14 ≝
+[
+  quadruple … COM MODE_DIR1 (Byte 〈x3,x3〉) 〈x0,x5〉
+; quadruple … COM MODE_INHA (Byte 〈x4,x3〉) 〈x0,x1〉
+; quadruple … COM MODE_INHX (Byte 〈x5,x3〉) 〈x0,x1〉
+; quadruple … COM MODE_IX1  (Byte 〈x6,x3〉) 〈x0,x5〉
+; quadruple … COM MODE_IX0  (Byte 〈x7,x3〉) 〈x0,x4〉
+; quadruple … COM MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x3〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_15 ≝
+[
+  quadruple … CPHX MODE_DIR2 (Byte 〈x3,xE〉) 〈x0,x6〉
+; quadruple … CPHX MODE_IMM2 (Byte 〈x6,x5〉) 〈x0,x3〉
+; quadruple … CPHX MODE_DIR1 (Byte 〈x7,x5〉) 〈x0,x5〉
+; quadruple … CPHX MODE_SP1  (Word 〈〈x9,xE〉:〈xF,x3〉〉) 〈x0,x6〉
+
+; quadruple … LDHX MODE_DIR2 (Byte 〈x3,x2〉) 〈x0,x5〉
+; quadruple … LDHX MODE_IMM2 (Byte 〈x4,x5〉) 〈x0,x3〉
+; quadruple … LDHX MODE_DIR1 (Byte 〈x5,x5〉) 〈x0,x4〉
+; quadruple … LDHX MODE_IX0  (Word 〈〈x9,xE〉:〈xA,xE〉〉) 〈x0,x5〉
+; quadruple … LDHX MODE_IX2  (Word 〈〈x9,xE〉:〈xB,xE〉〉) 〈x0,x6〉
+; quadruple … LDHX MODE_IX1  (Word 〈〈x9,xE〉:〈xC,xE〉〉) 〈x0,x5〉
+; quadruple … LDHX MODE_SP1  (Word 〈〈x9,xE〉:〈xF,xE〉〉) 〈x0,x5〉
+
+; quadruple … STHX MODE_DIR1 (Byte 〈x3,x5〉) 〈x0,x4〉
+; quadruple … STHX MODE_DIR2 (Byte 〈x9,x6〉) 〈x0,x5〉
+; quadruple … STHX MODE_SP1  (Word 〈〈x9,xE〉:〈xF,xF〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HCS08_16 ≝
+[
+  quadruple … CPX MODE_IMM1 (Byte 〈xA,x3〉) 〈x0,x2〉
+; quadruple … CPX MODE_DIR1 (Byte 〈xB,x3〉) 〈x0,x3〉
+; quadruple … CPX MODE_DIR2 (Byte 〈xC,x3〉) 〈x0,x4〉
+; quadruple … CPX MODE_IX2  (Byte 〈xD,x3〉) 〈x0,x4〉
+; quadruple … CPX MODE_IX1  (Byte 〈xE,x3〉) 〈x0,x3〉
+; quadruple … CPX MODE_IX0  (Byte 〈xF,x3〉) 〈x0,x3〉
+; quadruple … CPX MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x3〉〉) 〈x0,x5〉
+; quadruple … CPX MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x3〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_17 ≝
+[
+  quadruple … DBNZ MODE_DIR1_and_IMM1 (Byte 〈x3,xB〉) 〈x0,x7〉
+; quadruple … DBNZ MODE_INHA_and_IMM1 (Byte 〈x4,xB〉) 〈x0,x4〉
+; quadruple … DBNZ MODE_INHX_and_IMM1 (Byte 〈x5,xB〉) 〈x0,x4〉
+; quadruple … DBNZ MODE_IX1_and_IMM1  (Byte 〈x6,xB〉) 〈x0,x7〉
+; quadruple … DBNZ MODE_IX0_and_IMM1  (Byte 〈x7,xB〉) 〈x0,x6〉
+; quadruple … DBNZ MODE_SP1_and_IMM1  (Word 〈〈x9,xE〉:〈x6,xB〉〉) 〈x0,x8〉
+].
+
+ndefinition opcode_table_HCS08_18 ≝
+[
+  quadruple … DEC MODE_DIR1 (Byte 〈x3,xA〉) 〈x0,x5〉
+; quadruple … DEC MODE_INHA (Byte 〈x4,xA〉) 〈x0,x1〉
+; quadruple … DEC MODE_INHX (Byte 〈x5,xA〉) 〈x0,x1〉
+; quadruple … DEC MODE_IX1  (Byte 〈x6,xA〉) 〈x0,x5〉
+; quadruple … DEC MODE_IX0  (Byte 〈x7,xA〉) 〈x0,x4〉
+; quadruple … DEC MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xA〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_19 ≝
+[
+  quadruple … EOR MODE_IMM1 (Byte 〈xA,x8〉) 〈x0,x2〉
+; quadruple … EOR MODE_DIR1 (Byte 〈xB,x8〉) 〈x0,x3〉
+; quadruple … EOR MODE_DIR2 (Byte 〈xC,x8〉) 〈x0,x4〉
+; quadruple … EOR MODE_IX2  (Byte 〈xD,x8〉) 〈x0,x4〉
+; quadruple … EOR MODE_IX1  (Byte 〈xE,x8〉) 〈x0,x3〉
+; quadruple … EOR MODE_IX0  (Byte 〈xF,x8〉) 〈x0,x3〉
+; quadruple … EOR MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x8〉〉) 〈x0,x5〉
+; quadruple … EOR MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x8〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_20 ≝
+[
+  quadruple … INC MODE_DIR1 (Byte 〈x3,xC〉) 〈x0,x5〉
+; quadruple … INC MODE_INHA (Byte 〈x4,xC〉) 〈x0,x1〉
+; quadruple … INC MODE_INHX (Byte 〈x5,xC〉) 〈x0,x1〉
+; quadruple … INC MODE_IX1  (Byte 〈x6,xC〉) 〈x0,x5〉
+; quadruple … INC MODE_IX0  (Byte 〈x7,xC〉) 〈x0,x4〉
+; quadruple … INC MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xC〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_21 ≝
+[
+  quadruple … JMP MODE_IMM1EXT  (Byte 〈xB,xC〉) 〈x0,x3〉
+; quadruple … JMP MODE_IMM2     (Byte 〈xC,xC〉) 〈x0,x4〉
+; quadruple … JMP MODE_INHX2ADD (Byte 〈xD,xC〉) 〈x0,x4〉
+; quadruple … JMP MODE_INHX1ADD (Byte 〈xE,xC〉) 〈x0,x3〉
+; quadruple … JMP MODE_INHX0ADD (Byte 〈xF,xC〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_HCS08_22 ≝
+[
+  quadruple … BSR MODE_IMM1     (Byte 〈xA,xD〉) 〈x0,x5〉
+; quadruple … JSR MODE_IMM1EXT  (Byte 〈xB,xD〉) 〈x0,x5〉
+; quadruple … JSR MODE_IMM2     (Byte 〈xC,xD〉) 〈x0,x6〉
+; quadruple … JSR MODE_INHX2ADD (Byte 〈xD,xD〉) 〈x0,x6〉
+; quadruple … JSR MODE_INHX1ADD (Byte 〈xE,xD〉) 〈x0,x5〉
+; quadruple … JSR MODE_INHX0ADD (Byte 〈xF,xD〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HCS08_23 ≝
+[
+  quadruple … LDA MODE_IMM1 (Byte 〈xA,x6〉) 〈x0,x2〉
+; quadruple … LDA MODE_DIR1 (Byte 〈xB,x6〉) 〈x0,x3〉
+; quadruple … LDA MODE_DIR2 (Byte 〈xC,x6〉) 〈x0,x4〉
+; quadruple … LDA MODE_IX2  (Byte 〈xD,x6〉) 〈x0,x4〉
+; quadruple … LDA MODE_IX1  (Byte 〈xE,x6〉) 〈x0,x3〉
+; quadruple … LDA MODE_IX0  (Byte 〈xF,x6〉) 〈x0,x3〉
+; quadruple … LDA MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x6〉〉) 〈x0,x5〉
+; quadruple … LDA MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x6〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_24 ≝
+[
+  quadruple … LDX MODE_IMM1 (Byte 〈xA,xE〉) 〈x0,x2〉
+; quadruple … LDX MODE_DIR1 (Byte 〈xB,xE〉) 〈x0,x3〉
+; quadruple … LDX MODE_DIR2 (Byte 〈xC,xE〉) 〈x0,x4〉
+; quadruple … LDX MODE_IX2  (Byte 〈xD,xE〉) 〈x0,x4〉
+; quadruple … LDX MODE_IX1  (Byte 〈xE,xE〉) 〈x0,x3〉
+; quadruple … LDX MODE_IX0  (Byte 〈xF,xE〉) 〈x0,x3〉
+; quadruple … LDX MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xE〉〉) 〈x0,x5〉
+; quadruple … LDX MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xE〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_25 ≝
+[
+  quadruple … LSR MODE_DIR1 (Byte 〈x3,x4〉) 〈x0,x5〉
+; quadruple … LSR MODE_INHA (Byte 〈x4,x4〉) 〈x0,x1〉
+; quadruple … LSR MODE_INHX (Byte 〈x5,x4〉) 〈x0,x1〉
+; quadruple … LSR MODE_IX1  (Byte 〈x6,x4〉) 〈x0,x5〉
+; quadruple … LSR MODE_IX0  (Byte 〈x7,x4〉) 〈x0,x4〉
+; quadruple … LSR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x4〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_26 ≝
+[
+  quadruple … MOV MODE_DIR1_to_DIR1 (Byte 〈x4,xE〉) 〈x0,x5〉
+; quadruple … MOV MODE_DIR1_to_IX0p (Byte 〈x5,xE〉) 〈x0,x5〉
+; quadruple … MOV MODE_IMM1_to_DIR1 (Byte 〈x6,xE〉) 〈x0,x4〉
+; quadruple … MOV MODE_IX0p_to_DIR1 (Byte 〈x7,xE〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HCS08_27 ≝
+[
+  quadruple … NEG MODE_DIR1 (Byte 〈x3,x0〉) 〈x0,x5〉
+; quadruple … NEG MODE_INHA (Byte 〈x4,x0〉) 〈x0,x1〉
+; quadruple … NEG MODE_INHX (Byte 〈x5,x0〉) 〈x0,x1〉
+; quadruple … NEG MODE_IX1  (Byte 〈x6,x0〉) 〈x0,x5〉
+; quadruple … NEG MODE_IX0  (Byte 〈x7,x0〉) 〈x0,x4〉
+; quadruple … NEG MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x0〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_28 ≝
+[
+  quadruple … ORA MODE_IMM1 (Byte 〈xA,xA〉) 〈x0,x2〉
+; quadruple … ORA MODE_DIR1 (Byte 〈xB,xA〉) 〈x0,x3〉
+; quadruple … ORA MODE_DIR2 (Byte 〈xC,xA〉) 〈x0,x4〉
+; quadruple … ORA MODE_IX2  (Byte 〈xD,xA〉) 〈x0,x4〉
+; quadruple … ORA MODE_IX1  (Byte 〈xE,xA〉) 〈x0,x3〉
+; quadruple … ORA MODE_IX0  (Byte 〈xF,xA〉) 〈x0,x3〉
+; quadruple … ORA MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xA〉〉) 〈x0,x5〉
+; quadruple … ORA MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xA〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_29 ≝
+[
+  quadruple … ROL MODE_DIR1 (Byte 〈x3,x9〉) 〈x0,x5〉
+; quadruple … ROL MODE_INHA (Byte 〈x4,x9〉) 〈x0,x1〉
+; quadruple … ROL MODE_INHX (Byte 〈x5,x9〉) 〈x0,x1〉
+; quadruple … ROL MODE_IX1  (Byte 〈x6,x9〉) 〈x0,x5〉
+; quadruple … ROL MODE_IX0  (Byte 〈x7,x9〉) 〈x0,x4〉
+; quadruple … ROL MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x9〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_30 ≝
+[
+  quadruple … ROR MODE_DIR1 (Byte 〈x3,x6〉) 〈x0,x5〉
+; quadruple … ROR MODE_INHA (Byte 〈x4,x6〉) 〈x0,x1〉
+; quadruple … ROR MODE_INHX (Byte 〈x5,x6〉) 〈x0,x1〉
+; quadruple … ROR MODE_IX1  (Byte 〈x6,x6〉) 〈x0,x5〉
+; quadruple … ROR MODE_IX0  (Byte 〈x7,x6〉) 〈x0,x4〉
+; quadruple … ROR MODE_SP1  (Word 〈〈x9,xE〉:〈x6,x6〉〉) 〈x0,x6〉
+].
+
+ndefinition opcode_table_HCS08_31 ≝
+[
+  quadruple … SBC MODE_IMM1 (Byte 〈xA,x2〉) 〈x0,x2〉
+; quadruple … SBC MODE_DIR1 (Byte 〈xB,x2〉) 〈x0,x3〉
+; quadruple … SBC MODE_DIR2 (Byte 〈xC,x2〉) 〈x0,x4〉
+; quadruple … SBC MODE_IX2  (Byte 〈xD,x2〉) 〈x0,x4〉
+; quadruple … SBC MODE_IX1  (Byte 〈xE,x2〉) 〈x0,x3〉
+; quadruple … SBC MODE_IX0  (Byte 〈xF,x2〉) 〈x0,x3〉
+; quadruple … SBC MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x2〉〉) 〈x0,x5〉
+; quadruple … SBC MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x2〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_32 ≝
+[
+  quadruple … STA MODE_DIR1 (Byte 〈xB,x7〉) 〈x0,x3〉
+; quadruple … STA MODE_DIR2 (Byte 〈xC,x7〉) 〈x0,x4〉
+; quadruple … STA MODE_IX2  (Byte 〈xD,x7〉) 〈x0,x4〉
+; quadruple … STA MODE_IX1  (Byte 〈xE,x7〉) 〈x0,x3〉
+; quadruple … STA MODE_IX0  (Byte 〈xF,x7〉) 〈x0,x2〉
+; quadruple … STA MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x7〉〉) 〈x0,x5〉
+; quadruple … STA MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x7〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_33 ≝
+[
+  quadruple … STX MODE_DIR1 (Byte 〈xB,xF〉) 〈x0,x3〉
+; quadruple … STX MODE_DIR2 (Byte 〈xC,xF〉) 〈x0,x4〉
+; quadruple … STX MODE_IX2  (Byte 〈xD,xF〉) 〈x0,x4〉
+; quadruple … STX MODE_IX1  (Byte 〈xE,xF〉) 〈x0,x3〉
+; quadruple … STX MODE_IX0  (Byte 〈xF,xF〉) 〈x0,x2〉
+; quadruple … STX MODE_SP2  (Word 〈〈x9,xE〉:〈xD,xF〉〉) 〈x0,x5〉
+; quadruple … STX MODE_SP1  (Word 〈〈x9,xE〉:〈xE,xF〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_34 ≝
+[
+  quadruple … SUB MODE_IMM1 (Byte 〈xA,x0〉) 〈x0,x2〉
+; quadruple … SUB MODE_DIR1 (Byte 〈xB,x0〉) 〈x0,x3〉
+; quadruple … SUB MODE_DIR2 (Byte 〈xC,x0〉) 〈x0,x4〉
+; quadruple … SUB MODE_IX2  (Byte 〈xD,x0〉) 〈x0,x4〉
+; quadruple … SUB MODE_IX1  (Byte 〈xE,x0〉) 〈x0,x3〉
+; quadruple … SUB MODE_IX0  (Byte 〈xF,x0〉) 〈x0,x3〉
+; quadruple … SUB MODE_SP2  (Word 〈〈x9,xE〉:〈xD,x0〉〉) 〈x0,x5〉
+; quadruple … SUB MODE_SP1  (Word 〈〈x9,xE〉:〈xE,x0〉〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_HCS08_35 ≝
+[
+  quadruple … TST MODE_DIR1 (Byte 〈x3,xD〉) 〈x0,x4〉
+; quadruple … TST MODE_INHA (Byte 〈x4,xD〉) 〈x0,x1〉
+; quadruple … TST MODE_INHX (Byte 〈x5,xD〉) 〈x0,x1〉
+; quadruple … TST MODE_IX1  (Byte 〈x6,xD〉) 〈x0,x4〉
+; quadruple … TST MODE_IX0  (Byte 〈x7,xD〉) 〈x0,x3〉
+; quadruple … TST MODE_SP1  (Word 〈〈x9,xE〉:〈x6,xD〉〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_HCS08 ≝
+opcode_table_HCS08_1  @ opcode_table_HCS08_2  @ opcode_table_HCS08_3  @ opcode_table_HCS08_4  @
+opcode_table_HCS08_5  @ opcode_table_HCS08_6  @ opcode_table_HCS08_7  @ opcode_table_HCS08_8  @
+opcode_table_HCS08_9  @ opcode_table_HCS08_10 @ opcode_table_HCS08_11 @ opcode_table_HCS08_12 @
+opcode_table_HCS08_13 @ opcode_table_HCS08_14 @ opcode_table_HCS08_15 @ opcode_table_HCS08_16 @
+opcode_table_HCS08_17 @ opcode_table_HCS08_18 @ opcode_table_HCS08_19 @ opcode_table_HCS08_20 @
+opcode_table_HCS08_21 @ opcode_table_HCS08_22 @ opcode_table_HCS08_23 @ opcode_table_HCS08_24 @
+opcode_table_HCS08_25 @ opcode_table_HCS08_26 @ opcode_table_HCS08_27 @ opcode_table_HCS08_28 @
+opcode_table_HCS08_29 @ opcode_table_HCS08_30 @ opcode_table_HCS08_31 @ opcode_table_HCS08_32 @
+opcode_table_HCS08_33 @ opcode_table_HCS08_34 @ opcode_table_HCS08_35.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_table_tests.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/HCS08_table_tests.ma
new file mode 100755 (executable)
index 0000000..60a40cb
--- /dev/null
@@ -0,0 +1,102 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/opcode.ma".
+include "emulator/opcodes/HCS08_table.ma".
+
+(* ****************** *)
+(* TABELLA DELL'HCS08 *)
+(* ****************** *)
+
+(* HCS08: opcode non implementati come da manuale (byte) *)
+ndefinition HCS08_not_impl_byte ≝
+ [〈x8,xD〉
+ ;〈x9,xE〉
+ ;〈xA,xC〉
+ ].
+
+(* test bytecode non implementati *)
+nlemma ok_byte_table_HCS08 : forall_b8 (λb.
+ (test_not_impl_byte b HCS08_not_impl_byte     ⊙ eq_w16 (get_byte_count HCS08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HCS08) 〈〈x0,x0〉:〈x0,x1〉〉) ⊗
+ (⊖ (test_not_impl_byte b HCS08_not_impl_byte) ⊙ eq_w16 (get_byte_count HCS08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HCS08) 〈〈x0,x0〉:〈x0,x0〉〉))
+ = true.
+ napply refl_eq.
+nqed.
+
+(* HCS08: opcode non implementati come da manuale (0x9E+byte) *)
+ndefinition HCS08_not_impl_word ≝
+ [〈x0,x0〉;〈x0,x1〉;〈x0,x2〉;〈x0,x3〉;〈x0,x4〉;〈x0,x5〉;〈x0,x6〉;〈x0,x7〉
+ ;〈x0,x8〉;〈x0,x9〉;〈x0,xA〉;〈x0,xB〉;〈x0,xC〉;〈x0,xD〉;〈x0,xE〉;〈x0,xF〉
+ ;〈x1,x0〉;〈x1,x1〉;〈x1,x2〉;〈x1,x3〉;〈x1,x4〉;〈x1,x5〉;〈x1,x6〉;〈x1,x7〉
+ ;〈x1,x8〉;〈x1,x9〉;〈x1,xA〉;〈x1,xB〉;〈x1,xC〉;〈x1,xD〉;〈x1,xE〉;〈x1,xF〉
+ ;〈x2,x0〉;〈x2,x1〉;〈x2,x2〉;〈x2,x3〉;〈x2,x4〉;〈x2,x5〉;〈x2,x6〉;〈x2,x7〉
+ ;〈x2,x8〉;〈x2,x9〉;〈x2,xA〉;〈x2,xB〉;〈x2,xC〉;〈x2,xD〉;〈x2,xE〉;〈x2,xF〉
+ ;〈x3,x0〉;〈x3,x1〉;〈x3,x2〉;〈x3,x3〉;〈x3,x4〉;〈x3,x5〉;〈x3,x6〉;〈x3,x7〉
+ ;〈x3,x8〉;〈x3,x9〉;〈x3,xA〉;〈x3,xB〉;〈x3,xC〉;〈x3,xD〉;〈x3,xE〉;〈x3,xF〉
+ ;〈x4,x0〉;〈x4,x1〉;〈x4,x2〉;〈x4,x3〉;〈x4,x4〉;〈x4,x5〉;〈x4,x6〉;〈x4,x7〉
+ ;〈x4,x8〉;〈x4,x9〉;〈x4,xA〉;〈x4,xB〉;〈x4,xC〉;〈x4,xD〉;〈x4,xE〉;〈x4,xF〉
+ ;〈x5,x0〉;〈x5,x1〉;〈x5,x2〉;〈x5,x3〉;〈x5,x4〉;〈x5,x5〉;〈x5,x6〉;〈x5,x7〉
+ ;〈x5,x8〉;〈x5,x9〉;〈x5,xA〉;〈x5,xB〉;〈x5,xC〉;〈x5,xD〉;〈x5,xE〉;〈x5,xF〉
+ ;〈x6,x2〉;〈x6,x5〉;〈x6,xE〉
+ ;〈x7,x0〉;〈x7,x1〉;〈x7,x2〉;〈x7,x3〉;〈x7,x4〉;〈x7,x5〉;〈x7,x6〉;〈x7,x7〉
+ ;〈x7,x8〉;〈x7,x9〉;〈x7,xA〉;〈x7,xB〉;〈x7,xC〉;〈x7,xD〉;〈x7,xE〉;〈x7,xF〉
+ ;〈x8,x0〉;〈x8,x1〉;〈x8,x2〉;〈x8,x3〉;〈x8,x4〉;〈x8,x5〉;〈x8,x6〉;〈x8,x7〉
+ ;〈x8,x8〉;〈x8,x9〉;〈x8,xA〉;〈x8,xB〉;〈x8,xC〉;〈x8,xD〉;〈x8,xE〉;〈x8,xF〉
+ ;〈x9,x0〉;〈x9,x1〉;〈x9,x2〉;〈x9,x3〉;〈x9,x4〉;〈x9,x5〉;〈x9,x6〉;〈x9,x7〉
+ ;〈x9,x8〉;〈x9,x9〉;〈x9,xA〉;〈x9,xB〉;〈x9,xC〉;〈x9,xD〉;〈x9,xE〉;〈x9,xF〉
+ ;〈xA,x0〉;〈xA,x1〉;〈xA,x2〉;〈xA,x3〉;〈xA,x4〉;〈xA,x5〉;〈xA,x6〉;〈xA,x7〉;〈xA,x8〉;〈xA,x9〉;〈xA,xA〉;〈xA,xB〉;〈xA,xC〉;〈xA,xD〉;〈xA,xF〉
+ ;〈xB,x0〉;〈xB,x1〉;〈xB,x2〉;〈xB,x3〉;〈xB,x4〉;〈xB,x5〉;〈xB,x6〉;〈xB,x7〉;〈xB,x8〉;〈xB,x9〉;〈xB,xA〉;〈xB,xB〉;〈xB,xC〉;〈xB,xD〉;〈xB,xF〉
+ ;〈xC,x0〉;〈xC,x1〉;〈xC,x2〉;〈xC,x3〉;〈xC,x4〉;〈xC,x5〉;〈xC,x6〉;〈xC,x7〉;〈xC,x8〉;〈xC,x9〉;〈xC,xA〉;〈xC,xB〉;〈xC,xC〉;〈xC,xD〉;〈xC,xF〉
+ ;〈xD,xC〉;〈xD,xD〉
+ ;〈xE,xC〉;〈xE,xD〉
+ ;〈xF,x0〉;〈xF,x1〉;〈xF,x2〉;〈xF,x4〉;〈xF,x5〉;〈xF,x6〉;〈xF,x7〉;〈xF,x8〉;〈xF,x9〉;〈xF,xA〉;〈xF,xB〉;〈xF,xC〉;〈xF,xD〉
+ ].
+
+(* test bytecode non implementati *)
+nlemma ok_word_table_HCS08 : forall_b8 (λb.
+ (test_not_impl_byte b HCS08_not_impl_word     ⊙ eq_w16 (get_word_count HCS08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HCS08) 〈〈x0,x0〉:〈x0,x1〉〉) ⊗
+ (⊖ (test_not_impl_byte b HCS08_not_impl_word) ⊙ eq_w16 (get_word_count HCS08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HCS08) 〈〈x0,x0〉:〈x0,x0〉〉))
+ = true.
+ napply refl_eq.
+nqed.
+
+(* tutti op implementati *)
+nlemma ok_pseudo_table_HCS08 :
+ forall_op HCS08 (λo.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_pseudo_count HCS08 o 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HCS08)) = true.
+ napply refl_eq.
+nqed.
+
+(* tutte im implementate *)
+nlemma ok_mode_table_HCS08 :
+ forall_im HCS08 (λi.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_mode_count HCS08 i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HCS08)) = true.
+ napply refl_eq.
+nqed.
+
+(* nessuna ripetizione di combinazione op + imm *)
+nlemma ok_OpIm_table_HCS08 :
+ forall_im HCS08 (λi.
+  forall_op HCS08 (λo.
+   le_w16 (get_OpIm_count HCS08 o i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_HCS08) 〈〈x0,x0〉:〈x0,x1〉〉)) = true.
+ napply refl_eq.
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_instr_mode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_instr_mode.ma
new file mode 100755 (executable)
index 0000000..0d5a311
--- /dev/null
@@ -0,0 +1,102 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle modalita' di indirizzamento = caricamento degli operandi *)
+ninductive RS08_instr_mode: Type ≝
+  (* INHERENT = nessun operando *)
+  MODE_INH  : RS08_instr_mode
+  (* INHERENT = nessun operando (A implicito) *)
+| MODE_INHA : RS08_instr_mode
+
+  (* IMMEDIATE = operando valore immediato byte = 0xbb *)
+| MODE_IMM1 : RS08_instr_mode
+  (* IMMEDIATE = operando valore immediato word = 0xwwww *)
+| MODE_IMM2 : RS08_instr_mode
+  (* DIRECT = operando offset byte = [0x00bb] *)
+| MODE_DIR1 : RS08_instr_mode
+
+  (* DIRECT → DIRECT = carica da diretto/scrive su diretto *)
+| MODE_DIR1_to_DIR1 : RS08_instr_mode
+  (* IMMEDIATE → DIRECT = carica da immediato/scrive su diretto *)
+| MODE_IMM1_to_DIR1 : RS08_instr_mode
+
+  (* INHERENT(A) + IMMEDIATE *)
+| MODE_INHA_and_IMM1 : RS08_instr_mode
+  (* IMMEDIATE + IMMEDIATE *)
+| MODE_IMM1_and_IMM1 : RS08_instr_mode
+  (* DIRECT + IMMEDIATE *)
+| MODE_DIR1_and_IMM1 : RS08_instr_mode
+
+  (* DIRECT(mTNY) = operando offset byte(maschera scrittura implicita 3 bit) *)
+  (* ex: DIR3 e' carica b, scrivi b con n-simo bit modificato *)
+| MODE_DIRn          : oct → RS08_instr_mode
+  (* DIRECT(mTNY) + IMMEDIATE = operando offset byte(maschera lettura implicita 3 bit) *)
+  (*                            + operando valore immediato byte  *)
+  (* ex: DIR2_and_IMM1 e' carica b, carica imm, restituisci n-simo bit di b + imm *)
+| MODE_DIRn_and_IMM1 : oct → RS08_instr_mode
+  (* TINY = nessun operando (diretto implicito 4bit = [0x00000000:0000iiii]) *)
+| MODE_TNY           : exadecim → RS08_instr_mode
+  (* SHORT = nessun operando (diretto implicito 5bit = [0x00000000:000iiiii]) *)
+| MODE_SRT           : bitrigesim → RS08_instr_mode
+.
+
+ndefinition eq_RS08_im ≝
+λi1,i2:RS08_instr_mode.
+ match i1 with
+  [ MODE_INH ⇒ match i2 with [ MODE_INH ⇒ true | _ ⇒ false ]
+  | MODE_INHA ⇒ match i2 with [ MODE_INHA ⇒ true | _ ⇒ false ]
+  | MODE_IMM1 ⇒ match i2 with [ MODE_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_IMM2 ⇒ match i2 with [ MODE_IMM2 ⇒ true | _ ⇒ false ]
+  | MODE_DIR1 ⇒ match i2 with [ MODE_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_DIR1_to_DIR1 ⇒ match i2 with [ MODE_DIR1_to_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_IMM1_to_DIR1 ⇒ match i2 with [ MODE_IMM1_to_DIR1 ⇒ true | _ ⇒ false ]
+  | MODE_INHA_and_IMM1 ⇒ match i2 with [ MODE_INHA_and_IMM1 ⇒ true | _ ⇒ false ]
+  | MODE_IMM1_and_IMM1 ⇒ match i2 with [ MODE_IMM1_and_IMM1 ⇒ true | _ ⇒ false ]  
+  | MODE_DIR1_and_IMM1 ⇒ match i2 with [ MODE_DIR1_and_IMM1 ⇒ true | _ ⇒ false ]  
+  | MODE_DIRn n1 ⇒ match i2 with [ MODE_DIRn n2 ⇒ eq_oct n1 n2 | _ ⇒ false ]  
+  | MODE_DIRn_and_IMM1 n1 ⇒ match i2 with [ MODE_DIRn_and_IMM1 n2  ⇒ eq_oct n1 n2 | _ ⇒ false ]
+  | MODE_TNY e1 ⇒ match i2 with [ MODE_TNY e2 ⇒ eq_ex e1 e2 | _ ⇒ false ]  
+  | MODE_SRT t1 ⇒ match i2 with [ MODE_SRT t2 ⇒ eq_bit t1 t2 | _ ⇒ false ]  
+  ]. 
+
+(* iteratore sulle modalita' *)
+ndefinition forall_RS08_im ≝ λP:RS08_instr_mode → bool.
+  P MODE_INH
+⊗ P MODE_INHA
+⊗ P MODE_IMM1
+⊗ P MODE_IMM2
+⊗ P MODE_DIR1
+⊗ P MODE_DIR1_to_DIR1
+⊗ P MODE_IMM1_to_DIR1
+⊗ P MODE_INHA_and_IMM1
+⊗ P MODE_IMM1_and_IMM1
+⊗ P MODE_DIR1_and_IMM1
+⊗ forall_oct (λo. P (MODE_DIRn o))
+⊗ forall_oct (λo. P (MODE_DIRn_and_IMM1 o))
+⊗ forall_ex (λe. P (MODE_TNY e))
+⊗ forall_bit (λt. P (MODE_SRT t)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_opcode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_opcode.ma
new file mode 100755 (executable)
index 0000000..9bdb8f4
--- /dev/null
@@ -0,0 +1,108 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle istruzioni *)
+ninductive RS08_opcode: Type ≝
+  ADC    : RS08_opcode (* add with carry *)
+| ADD    : RS08_opcode (* add *)
+| AND    : RS08_opcode (* and *)
+| ASL    : RS08_opcode (* aritmetic shift left *)
+| BCC    : RS08_opcode (* branch if C=0 *)
+| BCLRn  : RS08_opcode (* clear bit n *)
+| BCS    : RS08_opcode (* branch if C=1 *)
+| BEQ    : RS08_opcode (* branch if Z=1 *)
+| BGND   : RS08_opcode (* !!background mode!! *)
+| BNE    : RS08_opcode (* branch if Z=0 *)
+| BRA    : RS08_opcode (* branch always *)
+| BRCLRn : RS08_opcode (* branch if bit n clear *)
+| BRSETn : RS08_opcode (* branch if bit n set *)
+| BSETn  : RS08_opcode (* set bit n *)
+| BSR    : RS08_opcode (* branch to subroutine *)
+| CBEQA  : RS08_opcode (* compare (A) and BEQ *)
+| CLC    : RS08_opcode (* C=0 *)
+| CLR    : RS08_opcode (* operand=0 *)
+| CMP    : RS08_opcode (* flag = sub (compare A) *)
+| COM    : RS08_opcode (* not (1 complement) *)
+| DBNZ   : RS08_opcode (* dec and BNE *)
+| DEC    : RS08_opcode (* operand=operand-1 (decrement) *)
+| EOR    : RS08_opcode (* xor *)
+| INC    : RS08_opcode (* operand=operand+1 (increment) *)
+| JMP    : RS08_opcode (* jmp word [operand] *)
+| JSR    : RS08_opcode (* jmp to subroutine *)
+| LDA    : RS08_opcode (* load in A *)
+| LSR    : RS08_opcode (* logical shift right *)
+| MOV    : RS08_opcode (* move *)
+| NOP    : RS08_opcode (* nop *)
+| ORA    : RS08_opcode (* or *)
+| ROL    : RS08_opcode (* rotate left *)
+| ROR    : RS08_opcode (* rotate right *)
+| RTS    : RS08_opcode (* return from subroutine *)
+| SBC    : RS08_opcode (* sub with carry*)
+| SEC    : RS08_opcode (* C=1 *)
+| SHA    : RS08_opcode (* swap spc_high,A *)
+| SLA    : RS08_opcode (* swap spc_low,A *)
+| STA    : RS08_opcode (* store from A *)
+| STOP   : RS08_opcode (* !!stop mode!! *)
+| SUB    : RS08_opcode (* sub *)
+| WAIT   : RS08_opcode (* !!wait mode!! *)
+.
+
+ndefinition eq_RS08_op ≝
+λop1,op2:RS08_opcode.
+ match op1 with
+  [ ADC ⇒ match op2 with [ ADC ⇒ true | _ ⇒ false ]       | ADD ⇒ match op2 with [ ADD ⇒ true | _ ⇒ false ]
+  | AND ⇒ match op2 with [ AND ⇒ true | _ ⇒ false ]       | ASL ⇒ match op2 with [ ASL ⇒ true | _ ⇒ false ]
+  | BCC ⇒ match op2 with [ BCC ⇒ true | _ ⇒ false ]       | BCLRn ⇒ match op2 with [ BCLRn ⇒ true | _ ⇒ false ]
+  | BCS ⇒ match op2 with [ BCS ⇒ true | _ ⇒ false ]       | BEQ ⇒ match op2 with [ BEQ ⇒ true | _ ⇒ false ] 
+  | BGND ⇒ match op2 with [ BGND ⇒ true | _ ⇒ false ]     | BNE ⇒ match op2 with [ BNE ⇒ true | _ ⇒ false ] 
+  | BRA ⇒ match op2 with [ BRA ⇒ true | _ ⇒ false ]       | BRCLRn ⇒ match op2 with [ BRCLRn ⇒ true | _ ⇒ false ]
+  | BRSETn ⇒ match op2 with [ BRSETn ⇒ true | _ ⇒ false ] | BSETn ⇒ match op2 with [ BSETn ⇒ true | _ ⇒ false ]
+  | BSR ⇒ match op2 with [ BSR ⇒ true | _ ⇒ false ]       | CBEQA ⇒ match op2 with [ CBEQA ⇒ true | _ ⇒ false ] 
+  | CLC ⇒ match op2 with [ CLC ⇒ true | _ ⇒ false ]       | CLR ⇒ match op2 with [ CLR ⇒ true | _ ⇒ false ]
+  | CMP ⇒ match op2 with [ CMP ⇒ true | _ ⇒ false ]       | COM ⇒ match op2 with [ COM ⇒ true | _ ⇒ false ] 
+  | DBNZ ⇒ match op2 with [ DBNZ ⇒ true | _ ⇒ false ]     | DEC ⇒ match op2 with [ DEC ⇒ true | _ ⇒ false ]
+  | EOR ⇒ match op2 with [ EOR ⇒ true | _ ⇒ false ]       | INC ⇒ match op2 with [ INC ⇒ true | _ ⇒ false ]
+  | JMP ⇒ match op2 with [ JMP ⇒ true | _ ⇒ false ]       | JSR ⇒ match op2 with [ JSR ⇒ true | _ ⇒ false ]
+  | LDA ⇒ match op2 with [ LDA ⇒ true | _ ⇒ false ]       | LSR ⇒ match op2 with [ LSR ⇒ true | _ ⇒ false ]
+  | MOV ⇒ match op2 with [ MOV ⇒ true | _ ⇒ false ]       | NOP ⇒ match op2 with [ NOP ⇒ true | _ ⇒ false ] 
+  | ORA ⇒ match op2 with [ ORA ⇒ true | _ ⇒ false ]       | ROL ⇒ match op2 with [ ROL ⇒ true | _ ⇒ false ]
+  | ROR ⇒ match op2 with [ ROR ⇒ true | _ ⇒ false ]       | RTS ⇒ match op2 with [ RTS ⇒ true | _ ⇒ false ]
+  | SBC ⇒ match op2 with [ SBC ⇒ true | _ ⇒ false ]       | SEC ⇒ match op2 with [ SEC ⇒ true | _ ⇒ false ]
+  | SHA ⇒ match op2 with [ SHA ⇒ true | _ ⇒ false ]       | SLA ⇒ match op2 with [ SLA ⇒ true | _ ⇒ false ]
+  | STA ⇒ match op2 with [ STA ⇒ true | _ ⇒ false ]       | STOP ⇒ match op2 with [ STOP ⇒ true | _ ⇒ false ]
+  | SUB ⇒ match op2 with [ SUB ⇒ true | _ ⇒ false ]       | WAIT ⇒ match op2 with [ WAIT ⇒ true | _ ⇒ false ]
+  ].
+
+(* iteratore sugli opcode *)
+ndefinition forall_RS08_op ≝ λP:RS08_opcode → bool.
+ P ADC    ⊗ P ADD    ⊗ P AND    ⊗ P ASL    ⊗ P BCC    ⊗ P BCLRn  ⊗ P BCS    ⊗ P BEQ    ⊗
+ P BGND   ⊗ P BNE    ⊗ P BRA    ⊗ P BRCLRn ⊗ P BRSETn ⊗ P BSETn  ⊗ P BSR    ⊗ P CBEQA  ⊗
+ P CLC    ⊗ P CLR    ⊗ P CMP    ⊗ P COM    ⊗ P DBNZ   ⊗ P DEC    ⊗ P EOR    ⊗ P INC    ⊗
+ P JMP    ⊗ P JSR    ⊗ P LDA    ⊗ P LSR    ⊗ P MOV    ⊗ P NOP    ⊗ P ORA    ⊗ P ROL    ⊗
+ P ROR    ⊗ P RTS    ⊗ P SBC    ⊗ P SEC    ⊗ P SHA    ⊗ P SLA    ⊗ P STA    ⊗ P STOP   ⊗
+ P SUB    ⊗ P WAIT.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_table.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_table.ma
new file mode 100755 (executable)
index 0000000..da3194b
--- /dev/null
@@ -0,0 +1,397 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/RS08_opcode.ma".
+include "emulator/opcodes/RS08_instr_mode.ma".
+include "emulator/opcodes/byte_or_word.ma".
+include "common/list.ma".
+
+(* ***************** *)
+(* TABELLA DELL'RS08 *)
+(* ***************** *)
+
+(* definizione come concatenazione finale di liste per velocizzare il parsing *)
+(* ogni riga e' (any_opcode m) (instr_mode) (opcode esadecimale) (#cicli esecuzione) *)
+(* NB: l'uso di any_opcode m + concatenazione finale tutte liste
+       impedisce di introdurre opcode disomogenei (per mcu) *)
+
+ndefinition opcode_table_RS08_1 ≝
+[ 
+  quadruple … ADC MODE_IMM1 (Byte 〈xA,x9〉) 〈x0,x2〉
+; quadruple … ADC MODE_DIR1 (Byte 〈xB,x9〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_2 ≝
+[ 
+  quadruple … ADD MODE_IMM1     (Byte 〈xA,xB〉) 〈x0,x2〉
+; quadruple … ADD MODE_DIR1     (Byte 〈xB,xB〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x0) (Byte 〈x6,x0〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x1) (Byte 〈x6,x1〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x2) (Byte 〈x6,x2〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x3) (Byte 〈x6,x3〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x4) (Byte 〈x6,x4〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x5) (Byte 〈x6,x5〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x6) (Byte 〈x6,x6〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x7) (Byte 〈x6,x7〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x8) (Byte 〈x6,x8〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY x9) (Byte 〈x6,x9〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY xA) (Byte 〈x6,xA〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY xB) (Byte 〈x6,xB〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY xC) (Byte 〈x6,xC〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY xD) (Byte 〈x6,xD〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY xE) (Byte 〈x6,xE〉) 〈x0,x3〉
+; quadruple … ADD (MODE_TNY xF) (Byte 〈x6,xF〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_3 ≝
+[ 
+  quadruple … AND MODE_IMM1 (Byte 〈xA,x4〉) 〈x0,x2〉
+; quadruple … AND MODE_DIR1 (Byte 〈xB,x4〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_4 ≝
+[
+  quadruple … ASL MODE_INHA (Byte 〈x4,x8〉) 〈x0,x1〉
+].
+
+ndefinition opcode_table_RS08_5 ≝
+[
+  quadruple … BRA MODE_IMM1 (Byte 〈x3,x0〉) 〈x0,x3〉
+; quadruple … BCC MODE_IMM1 (Byte 〈x3,x4〉) 〈x0,x3〉
+; quadruple … BCS MODE_IMM1 (Byte 〈x3,x5〉) 〈x0,x3〉
+; quadruple … BNE MODE_IMM1 (Byte 〈x3,x6〉) 〈x0,x3〉
+; quadruple … BEQ MODE_IMM1 (Byte 〈x3,x7〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_6 ≝
+[
+  quadruple … BSETn (MODE_DIRn o0) (Byte 〈x1,x0〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o0) (Byte 〈x1,x1〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o1) (Byte 〈x1,x2〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o1) (Byte 〈x1,x3〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o2) (Byte 〈x1,x4〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o2) (Byte 〈x1,x5〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o3) (Byte 〈x1,x6〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o3) (Byte 〈x1,x7〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o4) (Byte 〈x1,x8〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o4) (Byte 〈x1,x9〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o5) (Byte 〈x1,xA〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o5) (Byte 〈x1,xB〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o6) (Byte 〈x1,xC〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o6) (Byte 〈x1,xD〉) 〈x0,x5〉
+; quadruple … BSETn (MODE_DIRn o7) (Byte 〈x1,xE〉) 〈x0,x5〉
+; quadruple … BCLRn (MODE_DIRn o7) (Byte 〈x1,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_RS08_7 ≝
+[
+  quadruple … BRSETn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x0〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o0) (Byte 〈x0,x1〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x2〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o1) (Byte 〈x0,x3〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x4〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o2) (Byte 〈x0,x5〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x6〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o3) (Byte 〈x0,x7〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x8〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o4) (Byte 〈x0,x9〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xA〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o5) (Byte 〈x0,xB〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xC〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o6) (Byte 〈x0,xD〉) 〈x0,x5〉
+; quadruple … BRSETn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xE〉) 〈x0,x5〉
+; quadruple … BRCLRn (MODE_DIRn_and_IMM1 o7) (Byte 〈x0,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_RS08_8 ≝
+[
+  quadruple … CLC  MODE_INH (Byte 〈x3,x8〉) 〈x0,x1〉
+; quadruple … SEC  MODE_INH (Byte 〈x3,x9〉) 〈x0,x1〉
+; quadruple … SLA  MODE_INH (Byte 〈x4,x2〉) 〈x0,x1〉
+; quadruple … SHA  MODE_INH (Byte 〈x4,x5〉) 〈x0,x1〉
+; quadruple … NOP  MODE_INH (Byte 〈xA,xC〉) 〈x0,x1〉
+; quadruple … STOP MODE_INH (Byte 〈xA,xE〉) 〈x0,x2〉
+; quadruple … WAIT MODE_INH (Byte 〈xA,xF〉) 〈x0,x2〉
+; quadruple … RTS  MODE_INH (Byte 〈xB,xE〉) 〈x0,x3〉
+; quadruple … BGND MODE_INH (Byte 〈xB,xF〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_RS08_9 ≝
+[
+  quadruple … CBEQA MODE_DIR1_and_IMM1 (Byte 〈x3,x1〉) 〈x0,x5〉
+; quadruple … CBEQA MODE_IMM1_and_IMM1 (Byte 〈x4,x1〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_RS08_10 ≝
+[
+  quadruple … CLR MODE_DIR1      (Byte 〈x3,xF〉) 〈x0,x3〉
+; quadruple … CLR MODE_INHA      (Byte 〈x4,xF〉) 〈x0,x1〉
+; quadruple … CLR (MODE_SRT t00) (Byte 〈x8,x0〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t01) (Byte 〈x8,x1〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t02) (Byte 〈x8,x2〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t03) (Byte 〈x8,x3〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t04) (Byte 〈x8,x4〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t05) (Byte 〈x8,x5〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t06) (Byte 〈x8,x6〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t07) (Byte 〈x8,x7〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t08) (Byte 〈x8,x8〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t09) (Byte 〈x8,x9〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t0A) (Byte 〈x8,xA〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t0B) (Byte 〈x8,xB〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t0C) (Byte 〈x8,xC〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t0D) (Byte 〈x8,xD〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t0E) (Byte 〈x8,xE〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t0F) (Byte 〈x8,xF〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t10) (Byte 〈x9,x0〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t11) (Byte 〈x9,x1〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t12) (Byte 〈x9,x2〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t13) (Byte 〈x9,x3〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t14) (Byte 〈x9,x4〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t15) (Byte 〈x9,x5〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t16) (Byte 〈x9,x6〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t17) (Byte 〈x9,x7〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t18) (Byte 〈x9,x8〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t19) (Byte 〈x9,x9〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t1A) (Byte 〈x9,xA〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t1B) (Byte 〈x9,xB〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t1C) (Byte 〈x9,xC〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t1D) (Byte 〈x9,xD〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t1E) (Byte 〈x9,xE〉) 〈x0,x2〉
+; quadruple … CLR (MODE_SRT t1F) (Byte 〈x9,xF〉) 〈x0,x2〉
+].
+
+ndefinition opcode_table_RS08_11 ≝
+[
+  quadruple … CMP MODE_IMM1 (Byte 〈xA,x1〉) 〈x0,x2〉
+; quadruple … CMP MODE_DIR1 (Byte 〈xB,x1〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_12 ≝
+[
+  quadruple … COM MODE_INHA (Byte 〈x4,x3〉) 〈x0,x1〉
+].
+
+ndefinition opcode_table_RS08_13 ≝
+[
+  quadruple … DBNZ MODE_DIR1_and_IMM1 (Byte 〈x3,xB〉) 〈x0,x7〉
+; quadruple … DBNZ MODE_INHA_and_IMM1 (Byte 〈x4,xB〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_RS08_14 ≝
+[
+  quadruple … DEC MODE_DIR1     (Byte 〈x3,xA〉) 〈x0,x5〉
+; quadruple … DEC MODE_INHA     (Byte 〈x4,xA〉) 〈x0,x1〉
+; quadruple … DEC (MODE_TNY x0) (Byte 〈x5,x0〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x1) (Byte 〈x5,x1〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x2) (Byte 〈x5,x2〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x3) (Byte 〈x5,x3〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x4) (Byte 〈x5,x4〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x5) (Byte 〈x5,x5〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x6) (Byte 〈x5,x6〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x7) (Byte 〈x5,x7〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x8) (Byte 〈x5,x8〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY x9) (Byte 〈x5,x9〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY xA) (Byte 〈x5,xA〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY xB) (Byte 〈x5,xB〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY xC) (Byte 〈x5,xC〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY xD) (Byte 〈x5,xD〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY xE) (Byte 〈x5,xE〉) 〈x0,x4〉
+; quadruple … DEC (MODE_TNY xF) (Byte 〈x5,xF〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_RS08_15 ≝
+[ 
+  quadruple … EOR MODE_IMM1 (Byte 〈xA,x8〉) 〈x0,x2〉
+; quadruple … EOR MODE_DIR1 (Byte 〈xB,x8〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_16 ≝
+[
+  quadruple … INC MODE_DIR1     (Byte 〈x3,xC〉) 〈x0,x5〉
+; quadruple … INC MODE_INHA     (Byte 〈x4,xC〉) 〈x0,x1〉
+; quadruple … INC (MODE_TNY x0) (Byte 〈x2,x0〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x1) (Byte 〈x2,x1〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x2) (Byte 〈x2,x2〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x3) (Byte 〈x2,x3〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x4) (Byte 〈x2,x4〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x5) (Byte 〈x2,x5〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x6) (Byte 〈x2,x6〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x7) (Byte 〈x2,x7〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x8) (Byte 〈x2,x8〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY x9) (Byte 〈x2,x9〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY xA) (Byte 〈x2,xA〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY xB) (Byte 〈x2,xB〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY xC) (Byte 〈x2,xC〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY xD) (Byte 〈x2,xD〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY xE) (Byte 〈x2,xE〉) 〈x0,x4〉
+; quadruple … INC (MODE_TNY xF) (Byte 〈x2,xF〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_RS08_17 ≝
+[
+  quadruple … JMP MODE_IMM2 (Byte 〈xB,xC〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_RS08_18 ≝
+[
+  quadruple … BSR MODE_IMM1 (Byte 〈xA,xD〉) 〈x0,x3〉
+; quadruple … JSR MODE_IMM2 (Byte 〈xB,xD〉) 〈x0,x4〉
+].
+
+ndefinition opcode_table_RS08_19 ≝
+[
+  quadruple … LDA MODE_IMM1      (Byte 〈xA,x6〉) 〈x0,x2〉
+; quadruple … LDA MODE_DIR1      (Byte 〈xB,x6〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t00) (Byte 〈xC,x0〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t01) (Byte 〈xC,x1〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t02) (Byte 〈xC,x2〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t03) (Byte 〈xC,x3〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t04) (Byte 〈xC,x4〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t05) (Byte 〈xC,x5〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t06) (Byte 〈xC,x6〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t07) (Byte 〈xC,x7〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t08) (Byte 〈xC,x8〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t09) (Byte 〈xC,x9〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t0A) (Byte 〈xC,xA〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t0B) (Byte 〈xC,xB〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t0C) (Byte 〈xC,xC〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t0D) (Byte 〈xC,xD〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t0E) (Byte 〈xC,xE〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t0F) (Byte 〈xC,xF〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t10) (Byte 〈xD,x0〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t11) (Byte 〈xD,x1〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t12) (Byte 〈xD,x2〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t13) (Byte 〈xD,x3〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t14) (Byte 〈xD,x4〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t15) (Byte 〈xD,x5〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t16) (Byte 〈xD,x6〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t17) (Byte 〈xD,x7〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t18) (Byte 〈xD,x8〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t19) (Byte 〈xD,x9〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t1A) (Byte 〈xD,xA〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t1B) (Byte 〈xD,xB〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t1C) (Byte 〈xD,xC〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t1D) (Byte 〈xD,xD〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t1E) (Byte 〈xD,xE〉) 〈x0,x3〉
+; quadruple … LDA (MODE_SRT t1F) (Byte 〈xD,xF〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_20 ≝
+[
+  quadruple … LSR MODE_INHA (Byte 〈x4,x4〉) 〈x0,x1〉
+].
+
+ndefinition opcode_table_RS08_21 ≝
+[
+  quadruple … MOV MODE_IMM1_to_DIR1 (Byte 〈x3,xE〉) 〈x0,x4〉
+; quadruple … MOV MODE_DIR1_to_DIR1 (Byte 〈x4,xE〉) 〈x0,x5〉
+].
+
+ndefinition opcode_table_RS08_22 ≝
+[ 
+  quadruple … ORA MODE_IMM1 (Byte 〈xA,xA〉) 〈x0,x2〉
+; quadruple … ORA MODE_DIR1 (Byte 〈xB,xA〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_23 ≝
+[
+  quadruple … ROL MODE_INHA (Byte 〈x4,x9〉) 〈x0,x1〉
+].
+
+ndefinition opcode_table_RS08_24 ≝
+[
+  quadruple … ROR MODE_INHA (Byte 〈x4,x6〉) 〈x0,x1〉
+].
+
+ndefinition opcode_table_RS08_25 ≝
+[
+  quadruple … SBC MODE_IMM1 (Byte 〈xA,x2〉) 〈x0,x2〉
+; quadruple … SBC MODE_DIR1 (Byte 〈xB,x2〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08_26 ≝
+[
+  quadruple … STA MODE_DIR1      (Byte 〈xB,x7〉) 〈x0,x3〉
+; quadruple … STA (MODE_SRT t00) (Byte 〈xE,x0〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t01) (Byte 〈xE,x1〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t02) (Byte 〈xE,x2〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t03) (Byte 〈xE,x3〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t04) (Byte 〈xE,x4〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t05) (Byte 〈xE,x5〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t06) (Byte 〈xE,x6〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t07) (Byte 〈xE,x7〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t08) (Byte 〈xE,x8〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t09) (Byte 〈xE,x9〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t0A) (Byte 〈xE,xA〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t0B) (Byte 〈xE,xB〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t0C) (Byte 〈xE,xC〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t0D) (Byte 〈xE,xD〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t0E) (Byte 〈xE,xE〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t0F) (Byte 〈xE,xF〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t10) (Byte 〈xF,x0〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t11) (Byte 〈xF,x1〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t12) (Byte 〈xF,x2〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t13) (Byte 〈xF,x3〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t14) (Byte 〈xF,x4〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t15) (Byte 〈xF,x5〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t16) (Byte 〈xF,x6〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t17) (Byte 〈xF,x7〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t18) (Byte 〈xF,x8〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t19) (Byte 〈xF,x9〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t1A) (Byte 〈xF,xA〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t1B) (Byte 〈xF,xB〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t1C) (Byte 〈xF,xC〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t1D) (Byte 〈xF,xD〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t1E) (Byte 〈xF,xE〉) 〈x0,x2〉
+; quadruple … STA (MODE_SRT t1F) (Byte 〈xF,xF〉) 〈x0,x2〉
+].
+
+ndefinition opcode_table_RS08_27 ≝
+[ 
+  quadruple … SUB MODE_IMM1     (Byte 〈xA,x0〉) 〈x0,x2〉
+; quadruple … SUB MODE_DIR1     (Byte 〈xB,x0〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x0) (Byte 〈x7,x0〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x1) (Byte 〈x7,x1〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x2) (Byte 〈x7,x2〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x3) (Byte 〈x7,x3〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x4) (Byte 〈x7,x4〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x5) (Byte 〈x7,x5〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x6) (Byte 〈x7,x6〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x7) (Byte 〈x7,x7〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x8) (Byte 〈x7,x8〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY x9) (Byte 〈x7,x9〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY xA) (Byte 〈x7,xA〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY xB) (Byte 〈x7,xB〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY xC) (Byte 〈x7,xC〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY xD) (Byte 〈x7,xD〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY xE) (Byte 〈x7,xE〉) 〈x0,x3〉
+; quadruple … SUB (MODE_TNY xF) (Byte 〈x7,xF〉) 〈x0,x3〉
+].
+
+ndefinition opcode_table_RS08 ≝
+opcode_table_RS08_1  @ opcode_table_RS08_2  @ opcode_table_RS08_3  @ opcode_table_RS08_4  @
+opcode_table_RS08_5  @ opcode_table_RS08_6  @ opcode_table_RS08_7  @ opcode_table_RS08_8  @
+opcode_table_RS08_9  @ opcode_table_RS08_10 @ opcode_table_RS08_11 @ opcode_table_RS08_12 @
+opcode_table_RS08_13 @ opcode_table_RS08_14 @ opcode_table_RS08_15 @ opcode_table_RS08_16 @
+opcode_table_RS08_17 @ opcode_table_RS08_18 @ opcode_table_RS08_19 @ opcode_table_RS08_20 @
+opcode_table_RS08_21 @ opcode_table_RS08_22 @ opcode_table_RS08_23 @ opcode_table_RS08_24 @
+opcode_table_RS08_25 @ opcode_table_RS08_26 @ opcode_table_RS08_27.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_table_tests.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/RS08_table_tests.ma
new file mode 100755 (executable)
index 0000000..155c6ab
--- /dev/null
@@ -0,0 +1,66 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/opcode.ma".
+include "emulator/opcodes/RS08_table.ma".
+
+(* ***************** *)
+(* TABELLA DELL'RS08 *)
+(* ***************** *)
+
+(* RS08: opcode non implementati come da manuale *)
+ndefinition RS08_not_impl_byte ≝
+ [〈x3,x2〉;〈x3,x3〉;〈x3,xD〉
+ ;〈x4,x0〉;〈x4,x7〉;〈x4,xD〉
+ ;〈xA,x3〉;〈xA,x5〉;〈xA,x7〉
+ ;〈xB,x3〉;〈xB,x5〉
+ ].
+
+(* test bytecode non implementati *)
+nlemma ok_byte_table_RS08 : forall_b8 (λb.
+ (test_not_impl_byte b RS08_not_impl_byte     ⊙ eq_w16 (get_byte_count RS08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_RS08) 〈〈x0,x0〉:〈x0,x1〉〉) ⊗
+ (⊖ (test_not_impl_byte b RS08_not_impl_byte) ⊙ eq_w16 (get_byte_count RS08 b 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_RS08) 〈〈x0,x0〉:〈x0,x0〉〉))
+ = true.
+ napply refl_eq.
+nqed.
+
+(* tutti op implementati *)
+nlemma ok_pseudo_table_RS08 :
+ forall_op RS08 (λo.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_pseudo_count RS08 o 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_RS08)) = true.
+ napply refl_eq.
+nqed.
+
+(* tutte im implementate *)
+nlemma ok_mode_table_RS08 :
+ forall_im RS08 (λi.
+  le_w16 〈〈x0,x0〉:〈x0,x1〉〉 (get_mode_count RS08 i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_RS08)) = true.
+ napply refl_eq.
+nqed.
+
+(* nessuna ripetizione di combinazione op + imm *)
+nlemma ok_OpIm_table_RS08 :
+ forall_im RS08 (λi.
+  forall_op RS08 (λo.
+   le_w16 (get_OpIm_count RS08 o i 〈〈x0,x0〉:〈x0,x0〉〉 opcode_table_RS08) 〈〈x0,x0〉:〈x0,x1〉〉)) = true.
+ napply refl_eq.
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/byte_or_word.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/byte_or_word.ma
new file mode 100755 (executable)
index 0000000..7c20eb1
--- /dev/null
@@ -0,0 +1,35 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* raggruppamento di byte e word in un tipo unico *)
+ninductive byte8_or_word16 : Type ≝
+  Byte: byte8  → byte8_or_word16
+| Word: word16 → byte8_or_word16.
+
+ndefinition eq_b8w16 ≝
+λbw1,bw2:byte8_or_word16.
+ match bw1 with
+  [ Byte b1 ⇒ match bw2 with [ Byte b2 ⇒ eq_b8 b1 b2 | Word _ ⇒ false ]
+  | Word w1 ⇒ match bw2 with [ Byte _ ⇒ false | Word w2 ⇒ eq_w16 w1 w2 ]
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/opcodes/opcode.ma b/helm/software/matita/contribs/ng_assembly/emulator/opcodes/opcode.ma
new file mode 100755 (executable)
index 0000000..a1b696d
--- /dev/null
@@ -0,0 +1,205 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/HC05_opcode.ma".
+include "emulator/opcodes/HC05_instr_mode.ma".
+include "emulator/opcodes/HC08_opcode.ma".
+include "emulator/opcodes/HC08_instr_mode.ma".
+include "emulator/opcodes/HCS08_opcode.ma".
+include "emulator/opcodes/RS08_opcode.ma".
+include "emulator/opcodes/RS08_instr_mode.ma".
+include "emulator/opcodes/byte_or_word.ma".
+include "common/list.ma".
+
+(* ********************************************** *)
+(* MATTONI BASE PER DEFINIRE LE TABELLE DELLE MCU *)
+(* ********************************************** *)
+
+(* enumerazione delle ALU *)
+ninductive mcu_type: Type ≝
+  HC05  : mcu_type
+| HC08  : mcu_type
+| HCS08 : mcu_type
+| RS08  : mcu_type.
+
+ndefinition eq_mcutype ≝
+λm1,m2:mcu_type.
+ match m1 with
+  [ HC05 ⇒ match m2 with [ HC05 ⇒ true | _ ⇒ false ]
+  | HC08 ⇒ match m2 with [ HC08 ⇒ true | _ ⇒ false ]
+  | HCS08 ⇒ match m2 with [ HCS08 ⇒ true | _ ⇒ false ]
+  | RS08 ⇒ match m2 with [ RS08 ⇒ true | _ ⇒ false ]
+  ].
+
+ndefinition aux_op_type ≝
+λmcu:mcu_type.match mcu with
+ [ HC05 ⇒ HC05_opcode
+ | HC08 ⇒ HC08_opcode
+ | HCS08 ⇒ HCS08_opcode
+ | RS08 ⇒ RS08_opcode
+ ].
+
+ndefinition aux_im_type ≝
+λmcu:mcu_type.match mcu with
+ [ HC05 ⇒ HC05_instr_mode
+ | HC08 ⇒ HC08_instr_mode
+ | HCS08 ⇒ HC08_instr_mode
+ | RS08 ⇒ RS08_instr_mode
+ ].
+
+ndefinition eq_op ≝
+λmcu:mcu_type.
+ match mcu
+  return λm.aux_op_type m → aux_op_type m → bool
+ with
+  [ HC05 ⇒ eq_HC05_op
+  | HC08 ⇒ eq_HC08_op
+  | HCS08 ⇒ eq_HCS08_op
+  | RS08 ⇒ eq_RS08_op
+  ].
+
+ndefinition eq_im ≝
+λmcu:mcu_type.
+ match mcu
+  return λm.aux_im_type m → aux_im_type m → bool
+ with
+  [ HC05 ⇒ eq_HC05_im
+  | HC08 ⇒ eq_HC08_im
+  | HCS08 ⇒ eq_HC08_im
+  | RS08 ⇒ eq_RS08_im
+  ].
+
+ndefinition forall_op ≝
+λmcu:mcu_type.
+ match mcu
+  return λm.(aux_op_type m → bool) → bool
+ with
+  [ HC05 ⇒ forall_HC05_op
+  | HC08 ⇒ forall_HC08_op
+  | HCS08 ⇒ forall_HCS08_op
+  | RS08 ⇒ forall_RS08_op
+  ].
+
+ndefinition forall_im ≝
+λmcu:mcu_type.
+ match mcu
+  return λm.(aux_im_type m → bool) → bool
+ with
+  [ HC05 ⇒ forall_HC05_im
+  | HC08 ⇒ forall_HC08_im
+  | HCS08 ⇒ forall_HC08_im
+  | RS08 ⇒ forall_RS08_im
+  ].
+
+(* ********************************************* *)
+(* STRUMENTI PER LE DIMOSTRAZIONI DI CORRETTEZZA *)
+(* ********************************************* *)
+
+ndefinition aux_table_type ≝ λmcu:mcu_type.Prod4T (aux_op_type mcu) (aux_im_type mcu) byte8_or_word16 byte8.
+
+(* su tutta la lista quante volte compare il byte *)
+nlet rec get_byte_count (m:mcu_type) (b:byte8) (c:word16) (l:list (aux_table_type m)) on l ≝
+ match l with
+  [ nil ⇒ c
+  | cons hd tl ⇒ match thd4T … hd with
+   [ Byte b' ⇒ match eq_b8 b b' with
+    [ true ⇒ get_byte_count m b (succ_w16 c) tl
+    | false ⇒ get_byte_count m b c tl
+    ]
+   | Word _ ⇒ get_byte_count m b c tl
+   ]
+  ].
+
+(* su tutta la lista quante volte compare la word (0x9E+byte) *)
+nlet rec get_word_count (m:mcu_type) (b:byte8) (c:word16) (l:list (aux_table_type m)) on l ≝
+ match l with
+  [ nil ⇒ c
+  | cons hd tl ⇒ match thd4T … hd with
+   [ Byte _ ⇒ get_word_count m b c tl
+   | Word w ⇒ match eq_w16 〈〈x9,xE〉:b〉 w with
+    [ true ⇒ get_word_count m b (succ_w16 c) tl
+    | false ⇒ get_word_count m b c tl
+    ]
+   ]
+  ].
+
+(* su tutta la lista quante volte compare lo pseudocodice *)
+nlet rec get_pseudo_count (m:mcu_type) (o:aux_op_type m) (c:word16) (l:list (aux_table_type m)) on l ≝
+ match l with
+  [ nil ⇒ c
+  | cons hd tl ⇒ match eq_op m o (fst4T … hd) with
+   [ true ⇒ get_pseudo_count m o (succ_w16 c) tl
+   | false ⇒ get_pseudo_count m o c tl
+   ]
+  ].
+
+(* su tutta la lista quante volte compare la modalita' *)
+nlet rec get_mode_count (m:mcu_type) (i:aux_im_type m) (c:word16) (l:list (aux_table_type m)) on l ≝
+ match l with
+  [ nil ⇒ c
+  | cons hd tl ⇒ match eq_im m i (snd4T … hd) with
+   [ true ⇒ get_mode_count m i (succ_w16 c) tl
+   | false ⇒ get_mode_count m i c tl
+   ]
+  ].
+
+(* b e' non implementato? *)
+nlet rec test_not_impl_byte (b:byte8) (l:list byte8) on l ≝
+ match l with
+  [ nil ⇒ false
+  | cons hd tl ⇒ match eq_b8 b hd with
+   [ true ⇒ true
+   | false ⇒ test_not_impl_byte b tl
+   ]
+  ].
+
+(* o e' non implementato? *)
+nlet rec test_not_impl_pseudo (m:mcu_type) (o:aux_op_type m) (l:list (aux_op_type m)) on l ≝
+ match l with
+  [ nil ⇒ false
+  | cons hd tl ⇒ match eq_op m o hd with
+   [ true ⇒ true
+   | false ⇒ test_not_impl_pseudo m o tl
+   ]
+  ].
+
+(* i e' non implementato? *)
+nlet rec test_not_impl_mode (m:mcu_type) (i:aux_im_type m) (l:list (aux_im_type m)) on l ≝
+ match l with
+  [ nil ⇒ false
+  | cons hd tl ⇒ match eq_im m i hd with
+   [ true ⇒ true
+   | false ⇒ test_not_impl_mode m i tl
+   ]
+  ].
+
+(* su tutta la lista quante volte compare la coppia opcode,instr_mode *)
+nlet rec get_OpIm_count (m:mcu_type) (o:aux_op_type m) (i:aux_im_type m) (c:word16) (l:list (aux_table_type m)) on l ≝
+ match l with
+  [ nil ⇒ c
+  | cons hd tl ⇒
+   match (eq_op m o (fst4T … hd)) ⊗
+         (eq_im m i (snd4T … hd)) with
+    [ true ⇒ get_OpIm_count m o i (succ_w16 c) tl
+    | false ⇒ get_OpIm_count m o i c tl
+    ] 
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/status/HC05_status.ma b/helm/software/matita/contribs/ng_assembly/emulator/status/HC05_status.ma
new file mode 100755 (executable)
index 0000000..4e73b57
--- /dev/null
@@ -0,0 +1,90 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* *********************************** *)
+(* STATUS INTERNO DEL PROCESSORE (ALU) *)
+(* *********************************** *)
+
+(* ALU dell'HC05 *)
+nrecord alu_HC05: Type ≝
+ {
+ (* A: registo accumulatore *)
+ acc_low_reg_HC05 : byte8;
+ (* X: registro indice *)
+ indX_low_reg_HC05 : byte8;
+ (* SP: registo stack pointer *)
+ sp_reg_HC05 : word16;
+ (* modificatori di SP: per esempio e' definito come 0000000011xxxxxxb *)
+ (* la logica della sua costruzione e' quindi (SP∧mask)∨fix *)
+ (* totalmente racchiusa nella ALU, bastera' fare get(set(SP)) *)
+ sp_mask_HC05 : word16;
+ sp_fix_HC05 : word16;
+ (* PC: registro program counter *)
+ pc_reg_HC05 : word16;
+ (* modificatore di PC: per esempio e' definito come 00xxxxxxxxxxxxxxb *)
+ (* la logica della sua costruzione e' quindi (PC∧mask) *)
+ (* totalmente racchiusa nella ALU, bastera' fare get(set(PC)) *)
+ pc_mask_HC05 : word16;
+ (* H: flag semi-carry (somma nibble basso) *)
+ h_flag_HC05 : bool;
+ (* I: flag mascheramento degli interrupt mascherabili: 1=mascherati *)
+ i_flag_HC05 : bool;
+ (* N: flag segno/negativita' *)
+ n_flag_HC05 : bool;
+ (* Z: flag zero *)
+ z_flag_HC05 : bool;
+ (* C: flag carry *)
+ c_flag_HC05 : bool;
+ (* IRQ: flag che simula il pin esterno IRQ *)
+ irq_flag_HC05 : bool
+ }.
+
+notation "{hvbox('A_Reg' ≝ acclow ; break 'X_Reg' ≝ indxlow ; break 'Sp_Reg' ≝ sp ; break 'Sp_Mask' ≝ spm ; break 'Sp_Fix' ≝ spf ; break 'Pc_Reg' ≝ pc ; break 'Pc_Mask' ≝ pcm ; break 'H_Flag' ≝ hfl ; break 'I_Flag' ≝ ifl ; break 'N_Flag' ≝ nfl ; break 'Z_Flag' ≝ zfl ; break 'C_Flag' ≝ cfl ; break 'IRQ_Flag' ≝ irqfl)}"
+ non associative with precedence 80 for
+ @{ 'mk_alu_HC05 $acclow $indxlow $sp $spm $spf $pc $pcm $hfl $ifl $nfl $zfl $cfl $irqfl }.
+interpretation "mk_alu_HC05" 'mk_alu_HC05 acclow indxlow sp spm spf pc pcm hfl ifl nfl zfl cfl irqfl =
+ (mk_alu_HC05 acclow indxlow sp spm spf pc pcm hfl ifl nfl zfl cfl irqfl).
+
+(* ***************** *)
+(* CONFRONTO FRA ALU *)
+(* ***************** *)
+
+(* confronto registro per registro dell'HC05 *)
+ndefinition eq_HC05_alu ≝
+λalu1,alu2:alu_HC05.
+ (eq_b8 (acc_low_reg_HC05 alu1) (acc_low_reg_HC05 alu2)) ⊗
+ (eq_b8 (indX_low_reg_HC05 alu1) (indX_low_reg_HC05 alu2)) ⊗
+ (eq_w16 (sp_reg_HC05 alu1) (sp_reg_HC05 alu2)) ⊗
+ (eq_w16 (sp_mask_HC05 alu1) (sp_mask_HC05 alu2)) ⊗
+ (eq_w16 (sp_fix_HC05 alu1) (sp_fix_HC05 alu2)) ⊗
+ (eq_w16 (pc_reg_HC05 alu1) (pc_reg_HC05 alu2)) ⊗
+ (eq_w16 (pc_mask_HC05 alu1) (pc_mask_HC05 alu2)) ⊗
+ (eq_bool (h_flag_HC05 alu1) (h_flag_HC05 alu2)) ⊗
+ (eq_bool (i_flag_HC05 alu1) (i_flag_HC05 alu2)) ⊗
+ (eq_bool (n_flag_HC05 alu1) (n_flag_HC05 alu2)) ⊗
+ (eq_bool (z_flag_HC05 alu1) (z_flag_HC05 alu2)) ⊗
+ (eq_bool (c_flag_HC05 alu1) (c_flag_HC05 alu2)) ⊗
+ (eq_bool (irq_flag_HC05 alu1) (irq_flag_HC05 alu2)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/status/HC08_status.ma b/helm/software/matita/contribs/ng_assembly/emulator/status/HC08_status.ma
new file mode 100755 (executable)
index 0000000..8c6ab8f
--- /dev/null
@@ -0,0 +1,84 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* *********************************** *)
+(* STATUS INTERNO DEL PROCESSORE (ALU) *)
+(* *********************************** *)
+
+(* ALU dell'HC08/HCS08 *) 
+nrecord alu_HC08: Type ≝
+ {
+ (* A: registo accumulatore *)
+ acc_low_reg_HC08 : byte8;
+ (* X: registro indice parte bassa *)
+ indX_low_reg_HC08 : byte8;
+ (* H: registro indice parte alta *)
+ indX_high_reg_HC08 : byte8;
+ (* SP: registo stack pointer *)
+ sp_reg_HC08 : word16;
+ (* PC: registro program counter *)
+ pc_reg_HC08 : word16;
+ (* V: flag overflow *)
+ v_flag_HC08 : bool;
+ (* H: flag semi-carry (somma nibble basso) *)
+ h_flag_HC08 : bool;
+ (* I: flag mascheramento degli interrupt mascherabili: 1=mascherati *)
+ i_flag_HC08 : bool;
+ (* N: flag segno/negativita' *)
+ n_flag_HC08 : bool;
+ (* Z: flag zero *)
+ z_flag_HC08 : bool;
+ (* C: flag carry *)
+ c_flag_HC08 : bool;
+ (* IRQ: flag che simula il pin esterno IRQ *)
+ irq_flag_HC08 : bool
+ }.
+
+notation "{hvbox('A_Reg' ≝ acclow ; break 'X_Reg' ≝ indxlow ; break 'H_Reg' ≝ indxhigh ; break 'Sp_Reg' ≝ sp ; break 'Pc_Reg' ≝ pc ; break 'V_Flag' ≝ vfl ; break 'H_Flag' ≝ hfl ; break 'I_Flag' ≝ ifl ; break 'N_Flag' ≝ nfl ; break 'Z_Flag' ≝ zfl ; break 'C_Flag' ≝ cfl ; break 'IRQ_Flag' ≝ irqfl)}"
+ non associative with precedence 80 for
+ @{ 'mk_alu_HC08 $acclow $indxlow $indxhigh $sp $pc $vfl $hfl $ifl $nfl $zfl $cfl $irqfl }.
+interpretation "mk_alu_HC08" 'mk_alu_HC08 acclow indxlow indxhigh sp pc vfl hfl ifl nfl zfl cfl irqfl =
+ (mk_alu_HC08 acclow indxlow indxhigh sp pc vfl hfl ifl nfl zfl cfl irqfl).
+
+(* ***************** *)
+(* CONFRONTO FRA ALU *)
+(* ***************** *)
+
+(* confronto registro per registro dell'HC08 *)
+ndefinition eq_HC08_alu ≝
+λalu1,alu2:alu_HC08.
+ (eq_b8 (acc_low_reg_HC08 alu1) (acc_low_reg_HC08 alu2)) ⊗
+ (eq_b8 (indX_low_reg_HC08 alu1) (indX_low_reg_HC08 alu2)) ⊗
+ (eq_b8 (indX_high_reg_HC08 alu1) (indX_high_reg_HC08 alu2)) ⊗
+ (eq_w16 (sp_reg_HC08 alu1) (sp_reg_HC08 alu2)) ⊗
+ (eq_w16 (pc_reg_HC08 alu1) (pc_reg_HC08 alu2)) ⊗
+ (eq_bool (v_flag_HC08 alu1) (v_flag_HC08 alu2)) ⊗
+ (eq_bool (h_flag_HC08 alu1) (h_flag_HC08 alu2)) ⊗
+ (eq_bool (i_flag_HC08 alu1) (i_flag_HC08 alu2)) ⊗
+ (eq_bool (n_flag_HC08 alu1) (n_flag_HC08 alu2)) ⊗
+ (eq_bool (z_flag_HC08 alu1) (z_flag_HC08 alu2)) ⊗
+ (eq_bool (c_flag_HC08 alu1) (c_flag_HC08 alu2)) ⊗
+ (eq_bool (irq_flag_HC08 alu1) (irq_flag_HC08 alu2)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/status/RS08_status.ma b/helm/software/matita/contribs/ng_assembly/emulator/status/RS08_status.ma
new file mode 100755 (executable)
index 0000000..a02971f
--- /dev/null
@@ -0,0 +1,85 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* *********************************** *)
+(* STATUS INTERNO DEL PROCESSORE (ALU) *)
+(* *********************************** *)
+
+(* ALU dell'RS08 *)
+nrecord alu_RS08: Type ≝
+ {
+ (* A: registo accumulatore *)
+ acc_low_reg_RS08 : byte8;
+ (* PC: registro program counter *)
+ pc_reg_RS08 : word16;
+ (* modificatore di PC: per esempio e' definito come 00xxxxxxxxxxxxxxb *)
+ (* la logica della sua costruzione e' quindi (PC∧mask) *)
+ (* totalmente racchiusa nella ALU, bastera' fare get(set(PC)) *)
+ pc_mask_RS08 : word16;
+ (* SPC: registro shadow program counter *)
+ (* NB: il suo modificatore e' lo stesso di PC *)
+ spc_reg_RS08 : word16;
+
+ (* X: registro indice parte bassa *)
+ (* NB: in realta' e' mappato in memoria e non risiede nella ALU *)
+ (* la lettura/scrittura avviene tramite la locazione [0x000F] *)
+ (* la funzione memory_filter_read/write si occupera' di intercettare *)
+ (* e deviare sul registro le letture/scritture (modulo load_write) *)
+ x_map_RS08 : byte8;
+ (* PS: registro selezione di pagina *)
+ (* serve a indirizzare la finestra RAM di 64b [0x00C0-0x00FF] *)
+ (* su tutta la memoria installata [0x0000-0x3FFF]: [00pp pppp ppxx xxxx] *)
+ (* NB: in realta' e' mappato in memoria e non risiede nella ALU *)
+ (* la lettura/scrittura avviene tramite la locazione [0x001F] *)
+ (* la funzione memory_filter_read/write si occupera' di intercettare *)
+ (* e deviare sul registro le letture/scritture (modulo load_write) *)
+ ps_map_RS08 : byte8;
+ (* Z: flag zero *)
+ z_flag_RS08 : bool;
+ (* C: flag carry *)
+ c_flag_RS08 : bool
+ }.
+
+notation "{hvbox('A_Reg' ≝ acclow ; break 'Pc_Reg' ≝ pc ; break 'Pc_Mask' ≝ pcm ; break 'Spc_Reg' ≝ spc ; break 'X_Map' ≝ xm ; break 'Ps_Map' ≝ psm ; break 'Z_Flag' ≝ zfl ; break 'C_Flag' ≝ cfl)}"
+ non associative with precedence 80 for
+ @{ 'mk_alu_RS08 $acclow $pc $pcm $spc $xm $psm $zfl $cfl }.
+interpretation "mk_alu_RS08" 'mk_alu_RS08 acclow pc pcm spc xm psm zfl cfl =
+ (mk_alu_RS08 acclow pc pcm spc xm psm zfl cfl).
+
+(* ***************** *)
+(* CONFRONTO FRA ALU *)
+(* ***************** *)
+
+(* confronto registro per registro dell'RS08 *)
+ndefinition eq_RS08_alu ≝
+λalu1,alu2:alu_RS08.
+ (eq_b8 (acc_low_reg_RS08 alu1) (acc_low_reg_RS08 alu2)) ⊗
+ (eq_w16 (pc_reg_RS08 alu1) (pc_reg_RS08 alu2)) ⊗
+ (eq_w16 (pc_mask_RS08 alu1) (pc_mask_RS08 alu2)) ⊗
+ (eq_w16 (spc_reg_RS08 alu1) (spc_reg_RS08 alu2)) ⊗
+ (eq_b8 (x_map_RS08 alu1) (x_map_RS08 alu2)) ⊗
+ (eq_b8 (ps_map_RS08 alu1) (ps_map_RS08 alu2)) ⊗
+ (eq_bool (z_flag_RS08 alu1) (z_flag_RS08 alu2)) ⊗
+ (eq_bool (c_flag_RS08 alu1) (c_flag_RS08 alu2)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/status/status.ma b/helm/software/matita/contribs/ng_assembly/emulator/status/status.ma
new file mode 100755 (executable)
index 0000000..ae5c97c
--- /dev/null
@@ -0,0 +1,113 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/memory/memory_abs.ma".
+include "emulator/status/HC05_status.ma".
+include "emulator/status/HC08_status.ma".
+include "emulator/status/RS08_status.ma".
+include "emulator/opcodes/opcode.ma".
+
+(* *********************************** *)
+(* STATUS INTERNO DEL PROCESSORE (ALU) *)
+(* *********************************** *)
+
+(* descrittore del click = stato di avanzamento dell'esecuzione *)
+(* 1) None = istruzione eseguita, attesa del fetch *)
+(* 2) Some cur_clk,pseudo,mode,clks,cur_pc = fetch eseguito *)
+ndefinition aux_clk_type ≝ λm:mcu_type.Prod5T byte8 (aux_op_type m) (aux_im_type m) byte8 word16.
+
+(* tipo processore dipendente dalla mcu, varia solo la ALU *)
+nrecord any_status (mcu:mcu_type) (t:memory_impl): Type ≝
+ {
+ alu : match mcu with
+  [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ];
+
+ (* descritore della memoria *)
+ mem_desc : aux_mem_type t;
+ (* descrittore del tipo di memoria installata *)
+ chk_desc : aux_chk_type t;
+ (* descrittore del clik *)
+ clk_desc : option (aux_clk_type mcu)
+ }.
+
+(* evitare di mostrare la memoria/descrittore che impalla il visualizzatore *)
+notation > "{hvbox('Alu' ≝ alu ; break 'Clk' ≝ clk)}" non associative with precedence 80 
+ for @{ 'mk_any_status $alu $mem $chk $clk }.
+interpretation "mk_any_status" 'mk_any_status alu mem chk clk =
+ (mk_any_status alu mem chk clk).
+
+(* ******************** *)
+(* CONFRONTO FRA STATUS *)
+(* ******************** *)
+
+ndefinition eq_alu ≝
+λm:mcu_type.
+ match m
+  return λm.
+   match m with
+    [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ] →
+   match m with
+    [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ] →
+   bool
+ with
+  [ HC05 ⇒ eq_HC05_alu
+  | HC08 ⇒ eq_HC08_alu
+  | HCS08 ⇒ eq_HC08_alu
+  | RS08 ⇒ eq_RS08_alu
+  ].
+
+(* confronto di una regione di memoria [addr1 ; ... ; addrn] *)
+nlet rec forall_memory_ranged
+ (t:memory_impl)
+ (chk1:aux_chk_type t) (chk2:aux_chk_type t)
+ (mem1:aux_mem_type t) (mem2:aux_mem_type t)
+ (addrl:list word32) on addrl ≝
+ match addrl return λ_.bool with
+  [ nil ⇒ true
+  | cons hd tl ⇒ (eq_option byte8 (mem_read t mem1 chk1 hd)
+                            (mem_read t mem2 chk2 hd) eq_b8) ⊗
+                 (forall_memory_ranged t chk1 chk2 mem1 mem2 tl)
+  ].
+
+ndefinition eq_clk ≝
+λm:mcu_type.λc1,c2:option (aux_clk_type m).
+ match c1 with
+  [ None ⇒ match c2 with
+   [ None ⇒ true | Some _ ⇒ false ]
+  | Some c1' ⇒ match c2 with
+   [ None ⇒ false | Some c2' ⇒ (eq_b8 (fst5T … c1') (fst5T … c2')) ⊗
+                               (eq_op m (snd5T … c1') (snd5T … c2')) ⊗
+                               (eq_im m (thd5T … c1') (thd5T … c2')) ⊗
+                               (eq_b8 (fth5T … c1') (fth5T … c2')) ⊗
+                               (eq_w16 (fft5T … c1') (fft5T … c2')) ]
+  ].
+
+(* generalizzazione del confronto fra stati *)
+ndefinition eq_anystatus ≝
+λm:mcu_type.λt:memory_impl.λs1,s2:any_status m t.λaddrl:list word32.
+ (* 1) confronto della ALU *)
+ (eq_alu m (alu m t s1) (alu m t s2)) ⊗
+ (* 2) confronto della memoria in [inf,inf+n] *)
+ (forall_memory_ranged t (chk_desc m t s1) (chk_desc m t s2)
+                         (mem_desc m t s1) (mem_desc m t s2) addrl) ⊗
+ (* 3) confronto del clik *)
+ (eq_clk m (clk_desc m t s1) (clk_desc m t s2)).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/status/status_getter.ma b/helm/software/matita/contribs/ng_assembly/emulator/status/status_getter.ma
new file mode 100755 (executable)
index 0000000..75bb46e
--- /dev/null
@@ -0,0 +1,213 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/status/status.ma".
+
+(* **************** *)
+(* GETTER SPECIFICI *)
+(* **************** *)
+
+(* funzione ausiliaria per il tipaggio dei getter *)
+ndefinition aux_get_type ≝ λx:Type.λm:mcu_type.match m with
+ [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ] → x.
+
+(* REGISTRI *)
+
+(* getter di A, esiste sempre *)
+ndefinition get_acc_8_low_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type byte8 with
+ [ HC05 ⇒ acc_low_reg_HC05
+ | HC08 ⇒ acc_low_reg_HC08
+ | HCS08 ⇒ acc_low_reg_HC08
+ | RS08 ⇒ acc_low_reg_RS08 ]
+ (alu m t s).
+
+(* getter di X, non esiste sempre *)
+ndefinition get_indX_8_low_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option byte8) with 
+ [ HC05 ⇒ λalu.Some ? (indX_low_reg_HC05 alu)
+ | HC08 ⇒ λalu.Some ? (indX_low_reg_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (indX_low_reg_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di H, non esiste sempre *)
+ndefinition get_indX_8_high_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option byte8) with 
+ [ HC05 ⇒ λalu.None ?
+ | HC08 ⇒ λalu.Some ? (indX_high_reg_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (indX_high_reg_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di H:X, non esiste sempre *)
+ndefinition get_indX_16_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option word16) with 
+ [ HC05 ⇒ λalu.None ?
+ | HC08 ⇒ λalu.Some ? (mk_word16 (indX_high_reg_HC08 alu) (indX_low_reg_HC08 alu))
+ | HCS08 ⇒ λalu.Some ? (mk_word16 (indX_high_reg_HC08 alu) (indX_low_reg_HC08 alu))
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di SP, non esiste sempre *)
+ndefinition get_sp_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option word16) with 
+ [ HC05 ⇒ λalu.Some ? (sp_reg_HC05 alu)
+ | HC08 ⇒ λalu.Some ? (sp_reg_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (sp_reg_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di PC, esiste sempre *)
+ndefinition get_pc_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type word16 with 
+ [ HC05 ⇒ pc_reg_HC05
+ | HC08 ⇒ pc_reg_HC08
+ | HCS08 ⇒ pc_reg_HC08
+ | RS08 ⇒ pc_reg_RS08 ]
+ (alu m t s).
+
+(* getter di SPC, non esiste sempre *)
+ndefinition get_spc_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option word16) with 
+ [ HC05 ⇒ λalu.None ?
+ | HC08 ⇒ λalu.None ?
+ | HCS08 ⇒ λalu.None ?
+ | RS08 ⇒ λalu.Some ? (spc_reg_RS08 alu) ]
+ (alu m t s).
+
+(* REGISTRI MEMORY MAPPED *)
+
+(* getter di memory mapped X, non esiste sempre *)
+ndefinition get_x_map ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option byte8) with 
+ [ HC05 ⇒ λalu.None ?
+ | HC08 ⇒ λalu.None ?
+ | HCS08 ⇒ λalu.None ?
+ | RS08 ⇒ λalu.Some ? (x_map_RS08 alu) ]
+ (alu m t s).
+
+(* getter di memory mapped PS, non esiste sempre *)
+ndefinition get_ps_map ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option byte8) with 
+ [ HC05 ⇒ λalu.None ?
+ | HC08 ⇒ λalu.None ?
+ | HCS08 ⇒ λalu.None ?
+ | RS08 ⇒ λalu.Some ? (ps_map_RS08 alu) ]
+ (alu m t s).
+
+(* FLAG *)
+
+(* getter di V, non esiste sempre *)
+ndefinition get_v_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option bool) with 
+ [ HC05 ⇒ λalu.None ?
+ | HC08 ⇒ λalu.Some ? (v_flag_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (v_flag_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di H, non esiste sempre *)
+ndefinition get_h_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option bool) with 
+ [ HC05 ⇒ λalu.Some ? (h_flag_HC05 alu)
+ | HC08 ⇒ λalu.Some ? (h_flag_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (h_flag_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di I, non esiste sempre *)
+ndefinition get_i_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option bool) with 
+ [ HC05 ⇒ λalu.Some ? (i_flag_HC05 alu)
+ | HC08 ⇒ λalu.Some ? (i_flag_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (i_flag_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di N, non esiste sempre *)
+ndefinition get_n_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option bool) with 
+ [ HC05 ⇒ λalu.Some ? (n_flag_HC05 alu)
+ | HC08 ⇒ λalu.Some ? (n_flag_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (n_flag_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
+
+(* getter di Z, esiste sempre *)
+ndefinition get_z_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type bool with 
+ [ HC05 ⇒ z_flag_HC05
+ | HC08 ⇒ z_flag_HC08
+ | HCS08 ⇒ z_flag_HC08
+ | RS08 ⇒ z_flag_RS08 ]
+ (alu m t s).
+
+(* getter di C, esiste sempre *)
+ndefinition get_c_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type bool with 
+ [ HC05 ⇒ c_flag_HC05
+ | HC08 ⇒ c_flag_HC08
+ | HCS08 ⇒ c_flag_HC08
+ | RS08 ⇒ c_flag_RS08 ]
+ (alu m t s).
+
+(* getter di IRQ, non esiste sempre *)
+ndefinition get_irq_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+ match m
+  return aux_get_type (option bool) with 
+ [ HC05 ⇒ λalu.Some ? (irq_flag_HC05 alu)
+ | HC08 ⇒ λalu.Some ? (irq_flag_HC08 alu)
+ | HCS08 ⇒ λalu.Some ? (irq_flag_HC08 alu)
+ | RS08 ⇒ λalu.None ? ]
+ (alu m t s).
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/status/status_setter.ma b/helm/software/matita/contribs/ng_assembly/emulator/status/status_setter.ma
new file mode 100755 (executable)
index 0000000..5a89d2f
--- /dev/null
@@ -0,0 +1,822 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/status/status.ma".
+
+(* ***************************** *)
+(* SETTER SPECIFICI FORTI/DEBOLI *)
+(* ***************************** *)
+
+(* funzione ausiliaria per il tipaggio dei setter forti *)
+ndefinition aux_set_type ≝ λx:Type.λm:mcu_type.
+  match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ]
+  → x →
+  match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ].
+
+(* funzione ausiliaria per il tipaggio dei setter deboli *)
+ndefinition aux_set_type_opt ≝ λx:Type.λm:mcu_type.option
+ (match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ]
+  → x →
+  match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ]).
+
+(* DESCRITTORI ESTERNI ALLA ALU *)
+
+(* setter forte della ALU *)
+ndefinition set_alu ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λalu'.
+ mk_any_status m t alu' (mem_desc m t s) (chk_desc m t s) (clk_desc m t s).
+
+(* setter forte della memoria *)
+ndefinition set_mem_desc ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λmem':aux_mem_type t.
+ mk_any_status m t (alu m t s) mem' (chk_desc m t s) (clk_desc m t s).
+
+(* setter forte del descrittore *)
+ndefinition set_chk_desc ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λchk':aux_chk_type t.
+ mk_any_status m t (alu m t s) (mem_desc m t s) chk' (clk_desc m t s).
+
+(* setter forte del clik *)
+ndefinition set_clk_desc ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.
+λclk':option (aux_clk_type m).
+ mk_any_status m t (alu m t s) (mem_desc m t s) (chk_desc m t s) clk'.
+
+(* REGISTRO A *)
+
+(* setter specifico HC05 di A *)
+ndefinition set_acc_8_low_reg_HC05 ≝
+λalu.λacclow':byte8.
+ mk_alu_HC05
+  acclow'
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di A *)
+ndefinition set_acc_8_low_reg_HC08 ≝
+λalu.λacclow':byte8.
+ mk_alu_HC08
+  acclow'
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter specifico RS08 di A *)
+ndefinition set_acc_8_low_reg_RS08 ≝ 
+λalu.λacclow':byte8.
+ mk_alu_RS08
+  acclow'
+  (pc_reg_RS08 alu)
+  (pc_mask_RS08 alu)
+  (spc_reg_RS08 alu)
+  (x_map_RS08 alu)
+  (ps_map_RS08 alu)
+  (z_flag_RS08 alu)
+  (c_flag_RS08 alu).
+
+(* setter forte di A *)
+ndefinition set_acc_8_low_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λacclow':byte8.
+ set_alu m t s 
+ (match m return aux_set_type byte8 with
+  [ HC05 ⇒ set_acc_8_low_reg_HC05
+  | HC08 ⇒ set_acc_8_low_reg_HC08
+  | HCS08 ⇒ set_acc_8_low_reg_HC08
+  | RS08 ⇒ set_acc_8_low_reg_RS08
+  ] (alu m t s) acclow').
+
+(* REGISTRO X *)
+
+(* setter specifico HC05 di X *)
+ndefinition set_indX_8_low_reg_HC05 ≝
+λalu.λindxlow':byte8.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  indxlow'
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di X *)
+ndefinition set_indX_8_low_reg_HC08 ≝
+λalu.λindxlow':byte8.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  indxlow'
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di X *)
+ndefinition set_indX_8_low_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxlow':byte8.
+ opt_map … (match m return aux_set_type_opt byte8 with
+             [ HC05 ⇒ Some ? set_indX_8_low_reg_HC05
+             | HC08 ⇒ Some ? set_indX_8_low_reg_HC08
+             | HCS08 ⇒ Some ? set_indX_8_low_reg_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) indxlow'))).
+
+(* setter debole di X *)
+ndefinition setweak_indX_8_low_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxlow':byte8.
+ match set_indX_8_low_reg m t s indxlow' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* REGISTRO H *)
+
+(* setter specifico HC08/HCS08 di H *)
+ndefinition set_indX_8_high_reg_HC08 ≝
+λalu.λindxhigh':byte8.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  indxhigh'
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di H *)
+ndefinition set_indX_8_high_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxhigh':byte8.
+ opt_map … (match m return aux_set_type_opt byte8 with
+             [ HC05 ⇒ None ?
+             | HC08 ⇒ Some ? set_indX_8_high_reg_HC08
+             | HCS08 ⇒ Some ? set_indX_8_high_reg_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) indxhigh'))).
+
+(* setter debole di H *)
+ndefinition setweak_indX_8_high_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxhigh':byte8.
+ match set_indX_8_high_reg m t s indxhigh' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* REGISTRO H:X *)
+
+(* setter specifico HC08/HCS08 di H:X *)
+ndefinition set_indX_16_reg_HC08 ≝
+λalu.λindx16:word16.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (w16l indx16)
+  (w16h indx16)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di H:X *)
+ndefinition set_indX_16_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λindx16:word16.
+ opt_map … (match m return aux_set_type_opt word16 with
+             [ HC05 ⇒ None ?
+             | HC08 ⇒ Some ? set_indX_16_reg_HC08
+             | HCS08 ⇒ Some ? set_indX_16_reg_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) indx16))).
+
+(* setter debole di H:X *)
+ndefinition setweak_indX_16_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λindx16:word16.
+ match set_indX_16_reg m t s indx16 with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* REGISTRO SP *)
+
+(* setter specifico HC05 di SP, effettua (SP∧mask)∨fix *)
+ndefinition set_sp_reg_HC05 ≝
+λalu.λsp':word16.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (or_w16 (and_w16 sp' (sp_mask_HC05 alu)) (sp_fix_HC05 alu))
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di SP *)
+ndefinition set_sp_reg_HC08 ≝
+λalu.λsp':word16.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  sp'
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di SP *)
+ndefinition set_sp_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λsp':word16.
+ opt_map … (match m return aux_set_type_opt word16 with
+             [ HC05 ⇒ Some ? set_sp_reg_HC05
+             | HC08 ⇒ Some ? set_sp_reg_HC08
+             | HCS08 ⇒ Some ? set_sp_reg_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) sp'))).
+
+(* setter debole di SP *)
+ndefinition setweak_sp_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λsp':word16.
+ match set_sp_reg m t s sp' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* REGISTRO PC *)
+
+(* setter specifico HC05 di PC, effettua PC∧mask *)
+ndefinition set_pc_reg_HC05 ≝
+λalu.λpc':word16.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (and_w16 pc' (pc_mask_HC05 alu))
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di PC *)
+ndefinition set_pc_reg_HC08 ≝
+λalu.λpc':word16.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  pc'
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter specifico RS08 di PC, effettua PC∧mask *)
+ndefinition set_pc_reg_RS08 ≝ 
+λalu.λpc':word16.
+ mk_alu_RS08
+  (acc_low_reg_RS08 alu)
+  (and_w16 pc' (pc_mask_RS08 alu))
+  (pc_mask_RS08 alu)
+  (spc_reg_RS08 alu)
+  (x_map_RS08 alu)
+  (ps_map_RS08 alu)
+  (z_flag_RS08 alu)
+  (c_flag_RS08 alu).
+
+(* setter forte di PC *)
+ndefinition set_pc_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λpc':word16.
+ set_alu m t s 
+ (match m return aux_set_type word16 with
+  [ HC05 ⇒ set_pc_reg_HC05
+  | HC08 ⇒ set_pc_reg_HC08
+  | HCS08 ⇒ set_pc_reg_HC08
+  | RS08 ⇒ set_pc_reg_RS08
+  ] (alu m t s) pc').
+
+(* REGISTRO SPC *)
+
+(* setter specifico RS08 di SPC, effettua SPC∧mask *)
+ndefinition set_spc_reg_RS08 ≝ 
+λalu.λspc':word16.
+ mk_alu_RS08
+  (acc_low_reg_RS08 alu)
+  (pc_reg_RS08 alu)
+  (pc_mask_RS08 alu)
+  (and_w16 spc' (pc_mask_RS08 alu))
+  (x_map_RS08 alu)
+  (ps_map_RS08 alu)
+  (z_flag_RS08 alu)
+  (c_flag_RS08 alu).
+
+(* setter forte di SPC *)
+ndefinition set_spc_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λspc':word16.
+ opt_map … (match m return aux_set_type_opt word16 with
+             [ HC05 ⇒ None ?
+             | HC08 ⇒ None ?
+             | HCS08 ⇒ None ?
+             | RS08 ⇒ Some ? set_spc_reg_RS08 ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) spc'))).
+
+(* setter debole di SPC *)
+ndefinition setweak_spc_reg ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λspc':word16.
+ match set_spc_reg m t s spc' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* REGISTRO MEMORY MAPPED X *)
+
+(* setter specifico RS08 di memory mapped X *)
+ndefinition set_x_map_RS08 ≝ 
+λalu.λxm':byte8.
+ mk_alu_RS08
+  (acc_low_reg_RS08 alu)
+  (pc_reg_RS08 alu)
+  (pc_mask_RS08 alu)
+  (spc_reg_RS08 alu)
+  xm'
+  (ps_map_RS08 alu)
+  (z_flag_RS08 alu)
+  (c_flag_RS08 alu).
+
+(* setter forte di memory mapped X *)
+ndefinition set_x_map ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λxm':byte8.
+ opt_map … (match m return aux_set_type_opt byte8 with
+             [ HC05 ⇒ None ?
+             | HC08 ⇒ None ?
+             | HCS08 ⇒ None ?
+             | RS08 ⇒ Some ? set_x_map_RS08 ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) xm'))).
+
+(* setter debole di memory mapped X *)
+ndefinition setweak_x_map ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λxm':byte8.
+ match set_x_map m t s xm' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* REGISTRO MEMORY MAPPED PS *)
+
+(* setter specifico RS08 di memory mapped PS *)
+ndefinition set_ps_map_RS08 ≝ 
+λalu.λpsm':byte8.
+ mk_alu_RS08
+  (acc_low_reg_RS08 alu)
+  (pc_reg_RS08 alu)
+  (pc_mask_RS08 alu)
+  (spc_reg_RS08 alu)
+  (x_map_RS08 alu)
+  psm'
+  (z_flag_RS08 alu)
+  (c_flag_RS08 alu).
+
+(* setter forte di memory mapped PS *)
+ndefinition set_ps_map ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λpsm':byte8.
+ opt_map … (match m return aux_set_type_opt byte8 with
+             [ HC05 ⇒ None ?
+             | HC08 ⇒ None ?
+             | HCS08 ⇒ None ?
+             | RS08 ⇒ Some ? set_ps_map_RS08 ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) psm'))).
+
+(* setter debole di memory mapped PS *)
+ndefinition setweak_ps_map ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λpsm':byte8.
+ match set_ps_map m t s psm' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* FLAG V *)
+
+(* setter specifico HC08/HCS08 di V *)
+ndefinition set_v_flag_HC08 ≝
+λalu.λvfl':bool.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  vfl'
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di V *)
+ndefinition set_v_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λvfl':bool.
+ opt_map … (match m return aux_set_type_opt bool with
+             [ HC05 ⇒ None ?
+             | HC08 ⇒ Some ? set_v_flag_HC08
+             | HCS08 ⇒ Some ? set_v_flag_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) vfl'))).
+
+(* setter debole  di V *)
+ndefinition setweak_v_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λvfl':bool.
+ match set_v_flag m t s vfl' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* FLAG H *)
+
+(* setter specifico HC05 di H *)
+ndefinition set_h_flag_HC05 ≝
+λalu.λhfl':bool.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  hfl'
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di H *)
+ndefinition set_h_flag_HC08 ≝
+λalu.λhfl':bool.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  hfl'
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di H *)
+ndefinition set_h_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λhfl':bool.
+ opt_map … (match m return aux_set_type_opt bool with
+             [ HC05 ⇒ Some ? set_h_flag_HC05
+             | HC08 ⇒ Some ? set_h_flag_HC08
+             | HCS08 ⇒ Some ? set_h_flag_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) hfl'))).
+
+(* setter debole di H *)
+ndefinition setweak_h_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λhfl':bool.
+ match set_h_flag m t s hfl' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* FLAG I *)
+
+(* setter specifico HC05 di I *)
+ndefinition set_i_flag_HC05 ≝
+λalu.λifl':bool.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  ifl'
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di I *)
+ndefinition set_i_flag_HC08 ≝
+λalu.λifl':bool.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  ifl'
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di I *)
+ndefinition set_i_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λifl':bool.
+ opt_map … (match m return aux_set_type_opt bool with
+             [ HC05 ⇒ Some ? set_i_flag_HC05
+             | HC08 ⇒ Some ? set_i_flag_HC08
+             | HCS08 ⇒ Some ? set_i_flag_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) ifl'))).
+
+(* setter debole di I *)
+ndefinition setweak_i_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λifl':bool.
+ match set_i_flag m t s ifl' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* FLAG N *)
+
+(* setter specifico HC05 di N *)
+ndefinition set_n_flag_HC05 ≝
+λalu.λnfl':bool.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  nfl'
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di N *)
+ndefinition set_n_flag_HC08 ≝
+λalu.λnfl':bool.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  nfl'
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter forte di N *)
+ndefinition set_n_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λnfl':bool.
+ opt_map … (match m return aux_set_type_opt bool with
+             [ HC05 ⇒ Some ? set_n_flag_HC05
+             | HC08 ⇒ Some ? set_n_flag_HC08
+             | HCS08 ⇒ Some ? set_n_flag_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) nfl'))).
+
+(* setter debole di N *)
+ndefinition setweak_n_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λnfl':bool.
+ match set_n_flag m t s nfl' with
+  [ None ⇒ s | Some s' ⇒ s' ].
+
+(* FLAG Z *)
+
+(* setter specifico HC05 di Z *)
+ndefinition set_z_flag_HC05 ≝
+λalu.λzfl':bool.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  zfl'
+  (c_flag_HC05 alu)
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di Z *)
+ndefinition set_z_flag_HC08 ≝
+λalu.λzfl':bool.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  zfl'
+  (c_flag_HC08 alu)
+  (irq_flag_HC08 alu).
+
+(* setter sprcifico RS08 di Z *)
+ndefinition set_z_flag_RS08 ≝ 
+λalu.λzfl':bool.
+ mk_alu_RS08
+  (acc_low_reg_RS08 alu)
+  (pc_reg_RS08 alu)
+  (pc_mask_RS08 alu)
+  (spc_reg_RS08 alu)
+  (x_map_RS08 alu)
+  (ps_map_RS08 alu)
+  zfl'
+  (c_flag_RS08 alu).
+
+(* setter forte di Z *)
+ndefinition set_z_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λzfl':bool.
+ set_alu m t s 
+ (match m return aux_set_type bool with
+  [ HC05 ⇒ set_z_flag_HC05
+  | HC08 ⇒ set_z_flag_HC08
+  | HCS08 ⇒ set_z_flag_HC08
+  | RS08 ⇒ set_z_flag_RS08
+  ] (alu m t s) zfl').
+
+(* FLAG C *)
+
+(* setter specifico HC05 di C *)
+ndefinition set_c_flag_HC05 ≝
+λalu.λcfl':bool.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  cfl'
+  (irq_flag_HC05 alu).
+
+(* setter specifico HC08/HCS08 di C *)
+ndefinition set_c_flag_HC08 ≝
+λalu.λcfl':bool.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  cfl'
+  (irq_flag_HC08 alu).
+
+(* setter specifico RS08 di C *)
+ndefinition set_c_flag_RS08 ≝ 
+λalu.λcfl':bool.
+ mk_alu_RS08
+  (acc_low_reg_RS08 alu)
+  (pc_reg_RS08 alu)
+  (pc_mask_RS08 alu)
+  (spc_reg_RS08 alu)
+  (x_map_RS08 alu)
+  (ps_map_RS08 alu)
+  (z_flag_RS08 alu)
+  cfl'.
+
+(* setter forte di C *)
+ndefinition set_c_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λcfl':bool.
+ set_alu m t s 
+ (match m return aux_set_type bool with
+  [ HC05 ⇒ set_c_flag_HC05
+  | HC08 ⇒ set_c_flag_HC08
+  | HCS08 ⇒ set_c_flag_HC08
+  | RS08 ⇒ set_c_flag_RS08
+  ] (alu m t s) cfl').
+
+(* FLAG IRQ *)
+
+(* setter specifico HC05 di IRQ *)
+ndefinition set_irq_flag_HC05 ≝
+λalu.λirqfl':bool.
+ mk_alu_HC05
+  (acc_low_reg_HC05 alu)
+  (indX_low_reg_HC05 alu)
+  (sp_reg_HC05 alu)
+  (sp_mask_HC05 alu)
+  (sp_fix_HC05 alu)
+  (pc_reg_HC05 alu)
+  (pc_mask_HC05 alu)
+  (h_flag_HC05 alu)
+  (i_flag_HC05 alu)
+  (n_flag_HC05 alu)
+  (z_flag_HC05 alu)
+  (c_flag_HC05 alu)
+  irqfl'.
+
+(* setter specifico HC08/HCS08 di IRQ *)
+ndefinition set_irq_flag_HC08 ≝
+λalu.λirqfl':bool.
+ mk_alu_HC08
+  (acc_low_reg_HC08 alu)
+  (indX_low_reg_HC08 alu)
+  (indX_high_reg_HC08 alu)
+  (sp_reg_HC08 alu)
+  (pc_reg_HC08 alu)
+  (v_flag_HC08 alu)
+  (h_flag_HC08 alu)
+  (i_flag_HC08 alu)
+  (n_flag_HC08 alu)
+  (z_flag_HC08 alu)
+  (c_flag_HC08 alu)
+  irqfl'.
+
+(* setter forte di IRQ *)
+ndefinition set_irq_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λirqfl':bool.
+ opt_map … (match m return aux_set_type_opt bool with
+             [ HC05 ⇒ Some ? set_irq_flag_HC05
+             | HC08 ⇒ Some ? set_irq_flag_HC08
+             | HCS08 ⇒ Some ? set_irq_flag_HC08
+             | RS08 ⇒ None ? ])
+ (λf.Some ? (set_alu m t s (f (alu m t s) irqfl'))).
+
+(* setter debole di IRQ *)
+ndefinition setweak_irq_flag ≝
+λm:mcu_type.λt:memory_impl.λs:any_status m t.λirqfl':bool.
+ match set_irq_flag m t s irqfl' with
+  [ None ⇒ s | Some s' ⇒ s' ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/translation/HC05_translation.ma b/helm/software/matita/contribs/ng_assembly/emulator/translation/HC05_translation.ma
new file mode 100755 (executable)
index 0000000..5ad7e6f
--- /dev/null
@@ -0,0 +1,75 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/translation/translation_base.ma".
+
+(* ******************************************************* *)
+(* TRADUZIONE MCU+OPCODE+MODALITA'+ARGOMENTI → ESADECIMALE *)
+(* ******************************************************* *)
+
+(* introduzione di un tipo dipendente (dalla modalita') per gli argomenti *)
+ninductive HC05_MA_check : HC05_instr_mode → Type ≝
+  maINH              : HC05_MA_check MODE_INH
+| maINHA             : HC05_MA_check MODE_INHA
+| maINHX             : HC05_MA_check MODE_INHX
+| maINHX0ADD         : HC05_MA_check MODE_INHX0ADD
+| maINHX1ADD         : byte8 → HC05_MA_check MODE_INHX1ADD
+| maINHX2ADD         : word16 → HC05_MA_check MODE_INHX2ADD
+| maIMM1             : byte8  → HC05_MA_check MODE_IMM1
+| maIMM1EXT          : byte8  → HC05_MA_check MODE_IMM1EXT
+| maIMM2             : word16 → HC05_MA_check MODE_IMM2
+| maDIR1             : byte8  → HC05_MA_check MODE_DIR1
+| maDIR2             : word16 → HC05_MA_check MODE_DIR2
+| maIX0              : HC05_MA_check MODE_IX0
+| maIX1              : byte8  → HC05_MA_check MODE_IX1
+| maIX2              : word16 → HC05_MA_check MODE_IX2
+| maDIRn             : ∀n.byte8 → HC05_MA_check (MODE_DIRn n)
+| maDIRn_and_IMM1    : ∀n.byte8 → byte8 → HC05_MA_check (MODE_DIRn_and_IMM1 n)
+.
+
+(* picker: trasforma l'argomento necessario in input a bytes_of_pseudo_instr_mode_param:
+   MA_check i → list (t_byte8 m) *)
+ndefinition HC05_args_picker ≝
+λi:aux_im_type HC05.λargs:HC05_MA_check i.
+ match args with
+  (* inherent: legale se nessun operando *) 
+  [ maINH    ⇒ nil ? 
+  | maINHA   ⇒ nil ? 
+  | maINHX   ⇒ nil ? 
+  (* inherent address: legale se nessun operando/1 byte/1 word *)
+  | maINHX0ADD ⇒ nil ?
+  | maINHX1ADD b ⇒ [ TByte HC05 b ]
+  | maINHX2ADD w ⇒ [ TByte HC05 (w16h w); TByte HC05 (w16l w) ]
+  (* _0/1/2: legale se nessun operando/1 byte/1 word *)
+  | maIMM1 b ⇒ [ TByte HC05 b ]
+  | maIMM1EXT b ⇒ [ TByte HC05 b ]
+  | maIMM2 w ⇒ [ TByte HC05 (w16h w); TByte HC05 (w16l w) ]
+  | maDIR1 b ⇒ [ TByte HC05 b ]
+  | maDIR2 w ⇒ [ TByte HC05 (w16h w); TByte HC05 (w16l w) ]
+  | maIX0    ⇒ nil ?
+  | maIX1 b  ⇒ [ TByte HC05 b ]
+  | maIX2 w  ⇒ [ TByte HC05 (w16h w); TByte HC05 (w16l w) ]
+  (* DIRn: legale se 1 operando byte *)
+  | maDIRn _ b ⇒ [ TByte HC05 b]
+  (* DIRn_and_IMM1: legale se 2 operandi byte *)
+  | maDIRn_and_IMM1 _ b1 b2 ⇒ [ TByte HC05 b1 ; TByte HC05 b2 ]
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/translation/HC08_translation.ma b/helm/software/matita/contribs/ng_assembly/emulator/translation/HC08_translation.ma
new file mode 100755 (executable)
index 0000000..0b7b1c4
--- /dev/null
@@ -0,0 +1,109 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/translation/translation_base.ma".
+
+(* ******************************************************* *)
+(* TRADUZIONE MCU+OPCODE+MODALITA'+ARGOMENTI → ESADECIMALE *)
+(* ******************************************************* *)
+
+(* introduzione di un tipo dipendente (dalla modalita') per gli argomenti *)
+ninductive HC08_MA_check : HC08_instr_mode → Type ≝
+  maINH              : HC08_MA_check MODE_INH
+| maINHA             : HC08_MA_check MODE_INHA
+| maINHX             : HC08_MA_check MODE_INHX
+| maINHH             : HC08_MA_check MODE_INHH
+| maINHX0ADD         : HC08_MA_check MODE_INHX0ADD
+| maINHX1ADD         : byte8 → HC08_MA_check MODE_INHX1ADD
+| maINHX2ADD         : word16 → HC08_MA_check MODE_INHX2ADD
+| maIMM1             : byte8  → HC08_MA_check MODE_IMM1
+| maIMM1EXT          : byte8  → HC08_MA_check MODE_IMM1EXT
+| maIMM2             : word16 → HC08_MA_check MODE_IMM2
+| maDIR1             : byte8  → HC08_MA_check MODE_DIR1
+| maDIR2             : word16 → HC08_MA_check MODE_DIR2
+| maIX0              : HC08_MA_check MODE_IX0
+| maIX1              : byte8  → HC08_MA_check MODE_IX1
+| maIX2              : word16 → HC08_MA_check MODE_IX2
+| maSP1              : byte8  → HC08_MA_check MODE_SP1
+| maSP2              : word16 → HC08_MA_check MODE_SP2
+| maDIR1_to_DIR1     : byte8 → byte8 → HC08_MA_check MODE_DIR1_to_DIR1
+| maIMM1_to_DIR1     : byte8 → byte8 → HC08_MA_check MODE_IMM1_to_DIR1
+| maIX0p_to_DIR1     : byte8 → HC08_MA_check MODE_IX0p_to_DIR1
+| maDIR1_to_IX0p     : byte8 → HC08_MA_check MODE_DIR1_to_IX0p
+| maINHA_and_IMM1    : byte8 → HC08_MA_check MODE_INHA_and_IMM1
+| maINHX_and_IMM1    : byte8 → HC08_MA_check MODE_INHX_and_IMM1
+| maIMM1_and_IMM1    : byte8 → byte8 → HC08_MA_check MODE_IMM1_and_IMM1
+| maDIR1_and_IMM1    : byte8 → byte8 → HC08_MA_check MODE_DIR1_and_IMM1
+| maIX0_and_IMM1     : byte8 → HC08_MA_check MODE_IX0_and_IMM1
+| maIX0p_and_IMM1    : byte8 → HC08_MA_check MODE_IX0p_and_IMM1
+| maIX1_and_IMM1     : byte8 → byte8 → HC08_MA_check MODE_IX1_and_IMM1
+| maIX1p_and_IMM1    : byte8 → byte8 → HC08_MA_check MODE_IX1p_and_IMM1
+| maSP1_and_IMM1     : byte8 → byte8 → HC08_MA_check MODE_SP1_and_IMM1
+| maDIRn             : ∀n.byte8 → HC08_MA_check (MODE_DIRn n)
+| maDIRn_and_IMM1    : ∀n.byte8 → byte8 → HC08_MA_check (MODE_DIRn_and_IMM1 n)
+.
+
+(* picker: trasforma l'argomento necessario in input a bytes_of_pseudo_instr_mode_param:
+   MA_check i → list (t_byte8 m) *)
+ndefinition HC08_args_picker ≝
+λi:aux_im_type HC08.λargs:HC08_MA_check i.
+ match args with
+  (* inherent: legale se nessun operando *) 
+  [ maINH    ⇒ nil ? 
+  | maINHA   ⇒ nil ? 
+  | maINHX   ⇒ nil ? 
+  | maINHH   ⇒ nil ?
+  (* inherent address: legale se nessun operando/1 byte/1 word *)
+  | maINHX0ADD ⇒ nil ?
+  | maINHX1ADD b ⇒ [ TByte HC08 b ]
+  | maINHX2ADD w ⇒ [ TByte HC08 (w16h w); TByte HC08 (w16l w) ]    
+  (* _0/1/2: legale se nessun operando/1 byte/1 word *)
+  | maIMM1 b ⇒ [ TByte HC08 b ]
+  | maIMM1EXT b ⇒ [ TByte HC08 b ]
+  | maIMM2 w ⇒ [ TByte HC08 (w16h w); TByte HC08 (w16l w) ]
+  | maDIR1 b ⇒ [ TByte HC08 b ]
+  | maDIR2 w ⇒ [ TByte HC08 (w16h w); TByte HC08 (w16l w) ]
+  | maIX0    ⇒ nil ?
+  | maIX1 b  ⇒ [ TByte HC08 b ]
+  | maIX2 w  ⇒ [ TByte HC08 (w16h w); TByte HC08 (w16l w) ]
+  | maSP1 b  ⇒ [ TByte HC08 b ]
+  | maSP2 w  ⇒ [ TByte HC08 (w16h w); TByte HC08 (w16l w) ]
+  (* movimento: legale se 2 operandi byte *)
+  | maDIR1_to_DIR1 b1 b2  ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  | maIMM1_to_DIR1 b1 b2  ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  | maIX0p_to_DIR1 b      ⇒ [ TByte HC08 b]
+  | maDIR1_to_IX0p b      ⇒ [ TByte HC08 b]
+  (* cbeq/dbnz: legale se 1/2 operandi byte *)
+  | maINHA_and_IMM1 b     ⇒ [ TByte HC08 b]
+  | maINHX_and_IMM1 b     ⇒ [ TByte HC08 b]
+  | maIMM1_and_IMM1 b1 b2 ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  | maDIR1_and_IMM1 b1 b2 ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  | maIX0_and_IMM1  b     ⇒ [ TByte HC08 b]
+  | maIX0p_and_IMM1 b     ⇒ [ TByte HC08 b]
+  | maIX1_and_IMM1  b1 b2 ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  | maIX1p_and_IMM1 b1 b2 ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  | maSP1_and_IMM1  b1 b2 ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  (* DIRn: legale se 1 operando byte *)
+  | maDIRn _ b ⇒ [ TByte HC08 b]
+  (* DIRn_and_IMM1: legale se 2 operandi byte *)
+  | maDIRn_and_IMM1 _ b1 b2 ⇒ [ TByte HC08 b1 ; TByte HC08 b2 ]
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/translation/HCS08_translation.ma b/helm/software/matita/contribs/ng_assembly/emulator/translation/HCS08_translation.ma
new file mode 100755 (executable)
index 0000000..3e55692
--- /dev/null
@@ -0,0 +1,109 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/translation/translation_base.ma".
+
+(* ******************************************************* *)
+(* TRADUZIONE MCU+OPCODE+MODALITA'+ARGOMENTI → ESADECIMALE *)
+(* ******************************************************* *)
+
+(* introduzione di un tipo dipendente (dalla modalita') per gli argomenti *)
+ninductive HCS08_MA_check : HC08_instr_mode → Type ≝
+  maINH              : HCS08_MA_check MODE_INH
+| maINHA             : HCS08_MA_check MODE_INHA
+| maINHX             : HCS08_MA_check MODE_INHX
+| maINHH             : HCS08_MA_check MODE_INHH
+| maINHX0ADD         : HCS08_MA_check MODE_INHX0ADD
+| maINHX1ADD         : byte8 → HCS08_MA_check MODE_INHX1ADD
+| maINHX2ADD         : word16 → HCS08_MA_check MODE_INHX2ADD
+| maIMM1             : byte8  → HCS08_MA_check MODE_IMM1
+| maIMM1EXT          : byte8  → HCS08_MA_check MODE_IMM1EXT
+| maIMM2             : word16 → HCS08_MA_check MODE_IMM2
+| maDIR1             : byte8  → HCS08_MA_check MODE_DIR1
+| maDIR2             : word16 → HCS08_MA_check MODE_DIR2
+| maIX0              : HCS08_MA_check MODE_IX0
+| maIX1              : byte8  → HCS08_MA_check MODE_IX1
+| maIX2              : word16 → HCS08_MA_check MODE_IX2
+| maSP1              : byte8  → HCS08_MA_check MODE_SP1
+| maSP2              : word16 → HCS08_MA_check MODE_SP2
+| maDIR1_to_DIR1     : byte8 → byte8 → HCS08_MA_check MODE_DIR1_to_DIR1
+| maIMM1_to_DIR1     : byte8 → byte8 → HCS08_MA_check MODE_IMM1_to_DIR1
+| maIX0p_to_DIR1     : byte8 → HCS08_MA_check MODE_IX0p_to_DIR1
+| maDIR1_to_IX0p     : byte8 → HCS08_MA_check MODE_DIR1_to_IX0p
+| maINHA_and_IMM1    : byte8 → HCS08_MA_check MODE_INHA_and_IMM1
+| maINHX_and_IMM1    : byte8 → HCS08_MA_check MODE_INHX_and_IMM1
+| maIMM1_and_IMM1    : byte8 → byte8 → HCS08_MA_check MODE_IMM1_and_IMM1
+| maDIR1_and_IMM1    : byte8 → byte8 → HCS08_MA_check MODE_DIR1_and_IMM1
+| maIX0_and_IMM1     : byte8 → HCS08_MA_check MODE_IX0_and_IMM1
+| maIX0p_and_IMM1    : byte8 → HCS08_MA_check MODE_IX0p_and_IMM1
+| maIX1_and_IMM1     : byte8 → byte8 → HCS08_MA_check MODE_IX1_and_IMM1
+| maIX1p_and_IMM1    : byte8 → byte8 → HCS08_MA_check MODE_IX1p_and_IMM1
+| maSP1_and_IMM1     : byte8 → byte8 → HCS08_MA_check MODE_SP1_and_IMM1
+| maDIRn             : ∀n.byte8 → HCS08_MA_check (MODE_DIRn n)
+| maDIRn_and_IMM1    : ∀n.byte8 → byte8 → HCS08_MA_check (MODE_DIRn_and_IMM1 n)
+.
+
+(* picker: trasforma l'argomento necessario in input a bytes_of_pseudo_instr_mode_param:
+   MA_check i → list (t_byte8 m) *)
+ndefinition HCS08_args_picker ≝
+λi:aux_im_type HCS08.λargs:HCS08_MA_check i.
+ match args with
+  (* inherent: legale se nessun operando *) 
+  [ maINH    ⇒ nil ? 
+  | maINHA   ⇒ nil ? 
+  | maINHX   ⇒ nil ? 
+  | maINHH   ⇒ nil ?
+  (* inherent address: legale se nessun operando/1 byte/1 word *)
+  | maINHX0ADD ⇒ nil ?
+  | maINHX1ADD b ⇒ [ TByte HCS08 b ]
+  | maINHX2ADD w ⇒ [ TByte HCS08 (w16h w); TByte HCS08 (w16l w) ]    
+  (* _0/1/2: legale se nessun operando/1 byte/1 word *)
+  | maIMM1 b ⇒ [ TByte HCS08 b ]
+  | maIMM1EXT b ⇒ [ TByte HCS08 b ]
+  | maIMM2 w ⇒ [ TByte HCS08 (w16h w); TByte HCS08 (w16l w) ]
+  | maDIR1 b ⇒ [ TByte HCS08 b ]
+  | maDIR2 w ⇒ [ TByte HCS08 (w16h w); TByte HCS08 (w16l w) ]
+  | maIX0    ⇒ nil ?
+  | maIX1 b  ⇒ [ TByte HCS08 b ]
+  | maIX2 w  ⇒ [ TByte HCS08 (w16h w); TByte HCS08 (w16l w) ]
+  | maSP1 b  ⇒ [ TByte HCS08 b ]
+  | maSP2 w  ⇒ [ TByte HCS08 (w16h w); TByte HCS08 (w16l w) ]
+  (* movimento: legale se 2 operandi byte *)
+  | maDIR1_to_DIR1 b1 b2  ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  | maIMM1_to_DIR1 b1 b2  ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  | maIX0p_to_DIR1 b      ⇒ [ TByte HCS08 b]
+  | maDIR1_to_IX0p b      ⇒ [ TByte HCS08 b]
+  (* cbeq/dbnz: legale se 1/2 operandi byte *)
+  | maINHA_and_IMM1 b     ⇒ [ TByte HCS08 b]
+  | maINHX_and_IMM1 b     ⇒ [ TByte HCS08 b]
+  | maIMM1_and_IMM1 b1 b2 ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  | maDIR1_and_IMM1 b1 b2 ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  | maIX0_and_IMM1  b     ⇒ [ TByte HCS08 b]
+  | maIX0p_and_IMM1 b     ⇒ [ TByte HCS08 b]
+  | maIX1_and_IMM1  b1 b2 ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  | maIX1p_and_IMM1 b1 b2 ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  | maSP1_and_IMM1  b1 b2 ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  (* DIRn: legale se 1 operando byte *)
+  | maDIRn _ b ⇒ [ TByte HCS08 b]
+  (* DIRn_and_IMM1: legale se 2 operandi byte *)
+  | maDIRn_and_IMM1 _ b1 b2 ⇒ [ TByte HCS08 b1 ; TByte HCS08 b2 ]
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/translation/RS08_translation.ma b/helm/software/matita/contribs/ng_assembly/emulator/translation/RS08_translation.ma
new file mode 100755 (executable)
index 0000000..16546a5
--- /dev/null
@@ -0,0 +1,74 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/translation/translation_base.ma".
+
+(* ******************************************************* *)
+(* TRADUZIONE MCU+OPCODE+MODALITA'+ARGOMENTI → ESADECIMALE *)
+(* ******************************************************* *)
+
+(* introduzione di un tipo dipendente (dalla modalita') per gli argomenti *)
+ninductive RS08_MA_check : RS08_instr_mode → Type ≝
+  maINH              : RS08_MA_check MODE_INH
+| maINHA             : RS08_MA_check MODE_INHA
+| maIMM1             : byte8  → RS08_MA_check MODE_IMM1
+| maIMM2             : word16 → RS08_MA_check MODE_IMM2
+| maDIR1             : byte8  → RS08_MA_check MODE_DIR1
+| maDIR1_to_DIR1     : byte8 → byte8 → RS08_MA_check MODE_DIR1_to_DIR1
+| maIMM1_to_DIR1     : byte8 → byte8 → RS08_MA_check MODE_IMM1_to_DIR1
+| maINHA_and_IMM1    : byte8 → RS08_MA_check MODE_INHA_and_IMM1
+| maIMM1_and_IMM1    : byte8 → byte8 → RS08_MA_check MODE_IMM1_and_IMM1
+| maDIR1_and_IMM1    : byte8 → byte8 → RS08_MA_check MODE_DIR1_and_IMM1
+| maDIRn             : ∀n.byte8 → RS08_MA_check (MODE_DIRn n)
+| maDIRn_and_IMM1    : ∀n.byte8 → byte8 → RS08_MA_check (MODE_DIRn_and_IMM1 n)
+| maTNY              : ∀e.RS08_MA_check (MODE_TNY e)
+| maSRT              : ∀t.RS08_MA_check (MODE_SRT t)
+.
+
+(* picker: trasforma l'argomento necessario in input a bytes_of_pseudo_instr_mode_param:
+   MA_check i → list (t_byte8 m) *)
+ndefinition RS08_args_picker ≝
+λi:aux_im_type RS08.λargs:RS08_MA_check i.
+ match args with
+  (* inherent: legale se nessun operando *) 
+  [ maINH    ⇒ nil ? 
+  | maINHA   ⇒ nil ? 
+  (* _0/1/2: legale se nessun operando/1 byte/1 word *)
+  | maIMM1 b ⇒ [ TByte RS08 b ]
+  | maIMM2 w ⇒ [ TByte RS08 (w16h w); TByte RS08 (w16l w) ]
+  | maDIR1 b ⇒ [ TByte RS08 b ]
+  (* movimento: legale se 2 operandi byte *)
+  | maDIR1_to_DIR1 b1 b2  ⇒ [ TByte RS08 b1 ; TByte RS08 b2 ]
+  | maIMM1_to_DIR1 b1 b2  ⇒ [ TByte RS08 b1 ; TByte RS08 b2 ]
+  (* cbeq/dbnz: legale se 1/2 operandi byte *)
+  | maINHA_and_IMM1 b     ⇒ [ TByte RS08 b]
+  | maIMM1_and_IMM1 b1 b2 ⇒ [ TByte RS08 b1 ; TByte RS08 b2 ]
+  | maDIR1_and_IMM1 b1 b2 ⇒ [ TByte RS08 b1 ; TByte RS08 b2 ]
+  (* DIRn: legale se 1 operando byte *)
+  | maDIRn _ b ⇒ [ TByte RS08 b]
+  (* DIRn_and_IMM1: legale se 2 operandi byte *)
+  | maDIRn_and_IMM1 _ b1 b2 ⇒ [ TByte RS08 b1 ; TByte RS08 b2 ]
+  (* TNY: legale se nessun operando *)
+  | maTNY _ ⇒ nil ?
+  (* SRT: legale se nessun operando *)
+  | maSRT _ ⇒ nil ?
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/translation/translation.ma b/helm/software/matita/contribs/ng_assembly/emulator/translation/translation.ma
new file mode 100755 (executable)
index 0000000..64bda08
--- /dev/null
@@ -0,0 +1,131 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/translation/HC05_translation.ma".
+include "emulator/translation/HC08_translation.ma".
+include "emulator/translation/HCS08_translation.ma".
+include "emulator/translation/RS08_translation.ma".
+
+(* ******************************************************* *)
+(* TRADUZIONE MCU+OPCODE+MODALITA'+ARGOMENTI → ESADECIMALE *)
+(* ******************************************************* *)
+
+(* introduzione di un tipo dipendente (dalla modalita') per gli argomenti *)
+ndefinition MA_check ≝
+λmcu:mcu_type.
+ match mcu
+  return λm.(aux_im_type m) → Type
+ with
+  [ HC05 ⇒ HC05_MA_check
+  | HC08 ⇒ HC08_MA_check
+  | HCS08 ⇒ HCS08_MA_check
+  | RS08 ⇒ RS08_MA_check
+  ].
+
+(* picker: trasforma l'argomento necessario in input a bytes_of_pseudo_instr_mode_param:
+   MA_check i → list (t_byte8 m) *)
+ndefinition args_picker ≝
+λmcu:mcu_type.
+ match mcu
+  return λm.Πi:(aux_im_type m).MA_check m i → ?
+ with
+  [ HC05 ⇒ HC05_args_picker
+  | HC08 ⇒ HC08_args_picker
+  | HCS08 ⇒ HCS08_args_picker
+  | RS08 ⇒ RS08_args_picker
+  ].
+
+(* trasformatore finale: mcu+opcode+instr_mode+args → list (t_byte8 m) *)
+nlet rec bytes_of_pseudo_instr_mode_param_aux (m:mcu_type) (o:aux_op_type m) (i:aux_im_type m) (p:MA_check m i)
+                                             (param:list (aux_table_type m)) on param ≝
+ match param with
+ [ nil ⇒ None ? | cons hd tl ⇒
+  match (eq_op m o (fst4T … hd)) ⊗ (eq_im m i (snd4T … hd)) with
+   [ true ⇒ match thd4T … hd with 
+    [ Byte isab ⇒ 
+     Some ? ([ (TByte m isab) ]@(args_picker m i p))
+    | Word isaw ⇒
+     Some ? ([ (TByte m (w16h isaw)) ; (TByte m (w16l isaw)) ]@(args_picker m i p))
+    ]
+   | false ⇒ bytes_of_pseudo_instr_mode_param_aux m o i p tl ]].
+
+ndefinition bytes_of_pseudo_instr_mode_param ≝
+λm:mcu_type.λo:aux_op_type m.λi:aux_im_type m.λp:MA_check m i.
+bytes_of_pseudo_instr_mode_param_aux m o i p (opcode_table m).
+
+(* ****************************** *)
+(* APPROCCIO COMPILAZIONE AL VOLO *)
+(* ****************************** *)
+
+(* ausiliario di compile *)
+ndefinition defined_option ≝
+ λT:Type.λo:option T.
+  match o with
+   [ None ⇒ False
+   | Some _ ⇒ True
+   ].
+
+(* compila solo se l'intera istruzione+modalita'+argomenti ha riscontro nelle tabelle *)
+ndefinition compile ≝
+λmcu:mcu_type.λi:aux_im_type mcu.λop:aux_op_type mcu.λarg:MA_check mcu i.
+ match bytes_of_pseudo_instr_mode_param mcu op i arg
+  return λres:option ?.defined_option ? res → ?
+ with
+  [ None ⇒ λp:defined_option ? (None ?).False_rect_Type0 ? p
+  | Some x ⇒ λp:defined_option ? (Some ? x).x
+  ].
+
+(* detipatore del compilato: (t_byte8 m) → byte8 *)
+nlet rec source_to_byte8_HC05_aux (p1:list (t_byte8 HC05)) (p2:list byte8) ≝
+ match p1 with
+  [ nil ⇒ p2
+  | cons hd tl ⇒ match hd with [ TByte b ⇒ source_to_byte8_HC05_aux tl (p2@[b]) ]
+  ].
+
+nlet rec source_to_byte8_HC08_aux (p1:list (t_byte8 HC08)) (p2:list byte8) ≝
+ match p1 with
+  [ nil ⇒ p2
+  | cons hd tl ⇒ match hd with [ TByte b ⇒ source_to_byte8_HC08_aux tl (p2@[b]) ]
+  ].
+
+nlet rec source_to_byte8_HCS08_aux (p1:list (t_byte8 HCS08)) (p2:list byte8) ≝
+ match p1 with
+  [ nil ⇒ p2
+  | cons hd tl ⇒ match hd with [ TByte b ⇒ source_to_byte8_HCS08_aux tl (p2@[b]) ]
+  ].
+
+nlet rec source_to_byte8_RS08_aux (p1:list (t_byte8 RS08)) (p2:list byte8) ≝
+ match p1 with
+  [ nil ⇒ p2
+  | cons hd tl ⇒ match hd with [ TByte b ⇒ source_to_byte8_RS08_aux tl (p2@[b]) ]
+  ].
+
+ndefinition source_to_byte8 ≝
+λm:mcu_type.
+ match m
+  return λm:mcu_type.list (t_byte8 m) → list byte8
+ with
+  [ HC05 ⇒ λl:list (t_byte8 HC05).source_to_byte8_HC05_aux l []
+  | HC08 ⇒ λl:list (t_byte8 HC08).source_to_byte8_HC08_aux l []
+  | HCS08 ⇒ λl:list (t_byte8 HCS08).source_to_byte8_HCS08_aux l []
+  | RS08 ⇒ λl:list (t_byte8 RS08).source_to_byte8_RS08_aux l []
+  ].
diff --git a/helm/software/matita/contribs/ng_assembly/emulator/translation/translation_base.ma b/helm/software/matita/contribs/ng_assembly/emulator/translation/translation_base.ma
new file mode 100755 (executable)
index 0000000..2df75d8
--- /dev/null
@@ -0,0 +1,79 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "emulator/opcodes/opcode.ma".
+include "common/option.ma".
+include "emulator/opcodes/HC05_table.ma".
+include "emulator/opcodes/HC08_table.ma".
+include "emulator/opcodes/HCS08_table.ma".
+include "emulator/opcodes/RS08_table.ma".
+
+(* ***************************** *)
+(* TRADUZIONE ESADECIMALE → INFO *)
+(* ***************************** *)
+
+(* accesso alla tabella della ALU prescelta *)
+ndefinition opcode_table ≝
+λm:mcu_type.
+ match m
+  return λm:mcu_type.list (aux_table_type m)
+ with
+  [ HC05  ⇒ opcode_table_HC05
+  | HC08  ⇒ opcode_table_HC08
+  | HCS08 ⇒ opcode_table_HCS08
+  | RS08  ⇒ opcode_table_RS08
+ ].
+
+(* traduzione mcu+esadecimale → info *)
+(* NB: la ricerca per byte non matcha con una word con lo stesso byte superiore uguale *)
+(* NB: per matchare una word (precode+code) bisogna passare una word *)
+(* NB: il risultato e' sempre un'opzione, NON esiste un dummy opcode tipo UNKNOWN/ILLEGAL *)
+nlet rec full_info_of_word16_aux (m:mcu_type) (borw:byte8_or_word16) (param:list (aux_table_type m)) on param ≝
+ match param with
+  [ nil ⇒ None ?
+  | cons hd tl ⇒
+   match thd4T … hd with
+    [ Byte b ⇒ match borw with
+     [ Byte borw' ⇒ match eq_b8 borw' b with
+      [ true ⇒ Some ? hd
+      | false ⇒ full_info_of_word16_aux m borw tl ]
+     | Word _ ⇒ full_info_of_word16_aux m borw tl ]
+    | Word w ⇒ match borw with
+     [ Byte _ ⇒ full_info_of_word16_aux m borw tl
+     | Word borw' ⇒ match eq_w16 borw' w with
+      [ true ⇒ Some ? hd
+      | false ⇒ full_info_of_word16_aux m borw tl ]            
+    ]]].
+
+ndefinition full_info_of_word16 ≝
+λm:mcu_type.λborw:byte8_or_word16.
+full_info_of_word16_aux m borw (opcode_table m).
+
+(* introduzione di un tipo byte8 dipendente dall'mcu_type (phantom type) *)
+ninductive t_byte8 (m:mcu_type) : Type ≝
+ TByte : byte8 → t_byte8 m.
+
+ndefinition eq_tbyte8 ≝
+λm.λtb1,tb2:t_byte8 m.
+ match tb1 with
+  [ TByte b1 ⇒ match tb2 with
+   [ TByte b2 ⇒ eq_b8 b1 b2 ]].
diff --git a/helm/software/matita/contribs/ng_assembly/num/bitrigesim.ma b/helm/software/matita/contribs/ng_assembly/num/bitrigesim.ma
new file mode 100755 (executable)
index 0000000..fdfb9fb
--- /dev/null
@@ -0,0 +1,189 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ************* *)
+(* BITRIGESIMALI *)
+(* ************* *)
+
+ninductive bitrigesim : Type ≝
+  t00: bitrigesim
+| t01: bitrigesim
+| t02: bitrigesim
+| t03: bitrigesim
+| t04: bitrigesim
+| t05: bitrigesim
+| t06: bitrigesim
+| t07: bitrigesim
+| t08: bitrigesim
+| t09: bitrigesim
+| t0A: bitrigesim
+| t0B: bitrigesim
+| t0C: bitrigesim
+| t0D: bitrigesim
+| t0E: bitrigesim
+| t0F: bitrigesim
+| t10: bitrigesim
+| t11: bitrigesim
+| t12: bitrigesim
+| t13: bitrigesim
+| t14: bitrigesim
+| t15: bitrigesim
+| t16: bitrigesim
+| t17: bitrigesim
+| t18: bitrigesim
+| t19: bitrigesim
+| t1A: bitrigesim
+| t1B: bitrigesim
+| t1C: bitrigesim
+| t1D: bitrigesim
+| t1E: bitrigesim
+| t1F: bitrigesim.
+
+(* operatore = *)
+ndefinition eq_bit ≝
+λt1,t2:bitrigesim.
+ match t1 with
+  [ t00 ⇒ match t2 with [ t00 ⇒ true | _ ⇒ false ] | t01 ⇒ match t2 with [ t01 ⇒ true | _ ⇒ false ]
+  | t02 ⇒ match t2 with [ t02 ⇒ true | _ ⇒ false ] | t03 ⇒ match t2 with [ t03 ⇒ true | _ ⇒ false ]
+  | t04 ⇒ match t2 with [ t04 ⇒ true | _ ⇒ false ] | t05 ⇒ match t2 with [ t05 ⇒ true | _ ⇒ false ]
+  | t06 ⇒ match t2 with [ t06 ⇒ true | _ ⇒ false ] | t07 ⇒ match t2 with [ t07 ⇒ true | _ ⇒ false ]
+  | t08 ⇒ match t2 with [ t08 ⇒ true | _ ⇒ false ] | t09 ⇒ match t2 with [ t09 ⇒ true | _ ⇒ false ]
+  | t0A ⇒ match t2 with [ t0A ⇒ true | _ ⇒ false ] | t0B ⇒ match t2 with [ t0B ⇒ true | _ ⇒ false ]
+  | t0C ⇒ match t2 with [ t0C ⇒ true | _ ⇒ false ] | t0D ⇒ match t2 with [ t0D ⇒ true | _ ⇒ false ]
+  | t0E ⇒ match t2 with [ t0E ⇒ true | _ ⇒ false ] | t0F ⇒ match t2 with [ t0F ⇒ true | _ ⇒ false ]
+  | t10 ⇒ match t2 with [ t10 ⇒ true | _ ⇒ false ] | t11 ⇒ match t2 with [ t11 ⇒ true | _ ⇒ false ]
+  | t12 ⇒ match t2 with [ t12 ⇒ true | _ ⇒ false ] | t13 ⇒ match t2 with [ t13 ⇒ true | _ ⇒ false ]
+  | t14 ⇒ match t2 with [ t14 ⇒ true | _ ⇒ false ] | t15 ⇒ match t2 with [ t15 ⇒ true | _ ⇒ false ]
+  | t16 ⇒ match t2 with [ t16 ⇒ true | _ ⇒ false ] | t17 ⇒ match t2 with [ t17 ⇒ true | _ ⇒ false ]
+  | t18 ⇒ match t2 with [ t18 ⇒ true | _ ⇒ false ] | t19 ⇒ match t2 with [ t19 ⇒ true | _ ⇒ false ]
+  | t1A ⇒ match t2 with [ t1A ⇒ true | _ ⇒ false ] | t1B ⇒ match t2 with [ t1B ⇒ true | _ ⇒ false ]
+  | t1C ⇒ match t2 with [ t1C ⇒ true | _ ⇒ false ] | t1D ⇒ match t2 with [ t1D ⇒ true | _ ⇒ false ]
+  | t1E ⇒ match t2 with [ t1E ⇒ true | _ ⇒ false ] | t1F ⇒ match t2 with [ t1F ⇒ true | _ ⇒ false ]
+  ].
+
+(* iteratore sui bitrigesimali *)
+ndefinition forall_bit ≝ λP.
+ P t00 ⊗ P t01 ⊗ P t02 ⊗ P t03 ⊗ P t04 ⊗ P t05 ⊗ P t06 ⊗ P t07 ⊗
+ P t08 ⊗ P t09 ⊗ P t0A ⊗ P t0B ⊗ P t0C ⊗ P t0D ⊗ P t0E ⊗ P t0F ⊗
+ P t10 ⊗ P t11 ⊗ P t12 ⊗ P t13 ⊗ P t14 ⊗ P t15 ⊗ P t16 ⊗ P t17 ⊗
+ P t18 ⊗ P t19 ⊗ P t1A ⊗ P t1B ⊗ P t1C ⊗ P t1D ⊗ P t1E ⊗ P t1F.
+
+(* operatore successore *)
+ndefinition succ_bit ≝
+λn.match n with
+ [ t00 ⇒ t01 | t01 ⇒ t02 | t02 ⇒ t03 | t03 ⇒ t04 | t04 ⇒ t05 | t05 ⇒ t06 | t06 ⇒ t07 | t07 ⇒ t08
+ | t08 ⇒ t09 | t09 ⇒ t0A | t0A ⇒ t0B | t0B ⇒ t0C | t0C ⇒ t0D | t0D ⇒ t0E | t0E ⇒ t0F | t0F ⇒ t10
+ | t10 ⇒ t11 | t11 ⇒ t12 | t12 ⇒ t13 | t13 ⇒ t14 | t14 ⇒ t15 | t15 ⇒ t16 | t16 ⇒ t17 | t17 ⇒ t18
+ | t18 ⇒ t19 | t19 ⇒ t1A | t1A ⇒ t1B | t1B ⇒ t1C | t1C ⇒ t1D | t1D ⇒ t1E | t1E ⇒ t1F | t1F ⇒ t00
+ ].
+
+(* bitrigesimali ricorsivi *)
+ninductive rec_bitrigesim : bitrigesim → Type ≝
+  bi_O : rec_bitrigesim t00
+| bi_S : ∀n.rec_bitrigesim n → rec_bitrigesim (succ_bit n).
+
+(* bitrigesimali → bitrigesimali ricorsivi *)
+ndefinition bit_to_recbit ≝
+λn.match n return λx.rec_bitrigesim x with
+ [ t00 ⇒ bi_O
+ | t01 ⇒ bi_S ? bi_O
+ | t02 ⇒ bi_S ? (bi_S ? bi_O)
+ | t03 ⇒ bi_S ? (bi_S ? (bi_S ? bi_O))
+ | t04 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))
+ | t05 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))
+ | t06 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))))
+ | t07 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))))
+ | t08 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+         bi_O)))))))
+ | t09 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? bi_O))))))))
+ | t0A ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? bi_O)))))))))
+ | t0B ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))
+ | t0C ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))))))))))
+ | t0D ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))
+ | t0E ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))))))))))))
+ | t0F ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))))
+ | t10 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+         bi_O)))))))))))))))
+ | t11 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? bi_O))))))))))))))))
+ | t12 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? bi_O)))))))))))))))))
+ | t13 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))))))))
+ | t14 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))))))))))))))))))
+ | t15 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))))))))))
+ | t16 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))))))))))))))))))))
+ | t17 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))))))))))))
+ | t18 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+         bi_O)))))))))))))))))))))))
+ | t19 ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? bi_O))))))))))))))))))))))))
+ | t1A ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? bi_O)))))))))))))))))))))))))
+ | t1B ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))))))))))))))))
+ | t1C ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))))))))))))))))))))))))))
+ | t1D ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))))))))))))))))))
+ | t1E ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O)))))))))))))))))))))))))))))
+ | t1F ⇒ bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ?
+        (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? (bi_S ? bi_O))))))))))))))))))))))))))))))
+ ].
diff --git a/helm/software/matita/contribs/ng_assembly/num/bitrigesim_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/bitrigesim_lemmas.ma
new file mode 100755 (executable)
index 0000000..021563e
--- /dev/null
@@ -0,0 +1,137 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bitrigesim.ma".
+include "num/bool_lemmas.ma".
+
+(* ************* *)
+(* BITRIGESIMALI *)
+(* ************* *)
+
+(*
+ndefinition bitrigesim_destruct_aux ≝
+Πt1,t2:bitrigesim.ΠP:Prop.t1 = t2 →
+ match eq_bit t1 t2 with [ true ⇒ P → P | false ⇒ P ].
+
+ndefinition bitrigesim_destruct : bitrigesim_destruct_aux.
+ #t1; #t2; #P; #H;
+ nrewrite < H;
+ nelim t1;
+ nnormalize;
+ napply (λx.x).
+nqed.
+*)
+
+nlemma eq_to_eqbit : ∀n1,n2.n1 = n2 → eq_bit n1 n2 = true.
+ #n1; #n2; #H;
+ nrewrite > H;
+ nelim n2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma neqbit_to_neq : ∀n1,n2.eq_bit n1 n2 = false → n1 ≠ n2.
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_bit n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqbit n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqbit_to_eq1 : ∀t2.eq_bit t00 t2 = true → t00 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##1: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq2 : ∀t2.eq_bit t01 t2 = true → t01 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##2: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq3 : ∀t2.eq_bit t02 t2 = true → t02 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##3: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq4 : ∀t2.eq_bit t03 t2 = true → t03 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##4: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq5 : ∀t2.eq_bit t04 t2 = true → t04 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##5: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq6 : ∀t2.eq_bit t05 t2 = true → t05 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##6: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq7 : ∀t2.eq_bit t06 t2 = true → t06 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##7: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq8 : ∀t2.eq_bit t07 t2 = true → t07 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##8: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq9 : ∀t2.eq_bit t08 t2 = true → t08 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##9: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq10 : ∀t2.eq_bit t09 t2 = true → t09 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##10: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq11 : ∀t2.eq_bit t0A t2 = true → t0A = t2. #t2; ncases t2; nnormalize; #H; ##[ ##11: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq12 : ∀t2.eq_bit t0B t2 = true → t0B = t2. #t2; ncases t2; nnormalize; #H; ##[ ##12: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq13 : ∀t2.eq_bit t0C t2 = true → t0C = t2. #t2; ncases t2; nnormalize; #H; ##[ ##13: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq14 : ∀t2.eq_bit t0D t2 = true → t0D = t2. #t2; ncases t2; nnormalize; #H; ##[ ##14: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq15 : ∀t2.eq_bit t0E t2 = true → t0E = t2. #t2; ncases t2; nnormalize; #H; ##[ ##15: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq16 : ∀t2.eq_bit t0F t2 = true → t0F = t2. #t2; ncases t2; nnormalize; #H; ##[ ##16: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq17 : ∀t2.eq_bit t10 t2 = true → t10 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##17: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq18 : ∀t2.eq_bit t11 t2 = true → t11 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##18: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq19 : ∀t2.eq_bit t12 t2 = true → t12 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##19: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq20 : ∀t2.eq_bit t13 t2 = true → t13 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##20: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq21 : ∀t2.eq_bit t14 t2 = true → t14 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##21: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq22 : ∀t2.eq_bit t15 t2 = true → t15 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##22: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq23 : ∀t2.eq_bit t16 t2 = true → t16 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##23: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq24 : ∀t2.eq_bit t17 t2 = true → t17 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##24: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq25 : ∀t2.eq_bit t18 t2 = true → t18 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##25: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq26 : ∀t2.eq_bit t19 t2 = true → t19 = t2. #t2; ncases t2; nnormalize; #H; ##[ ##26: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq27 : ∀t2.eq_bit t1A t2 = true → t1A = t2. #t2; ncases t2; nnormalize; #H; ##[ ##27: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq28 : ∀t2.eq_bit t1B t2 = true → t1B = t2. #t2; ncases t2; nnormalize; #H; ##[ ##28: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq29 : ∀t2.eq_bit t1C t2 = true → t1C = t2. #t2; ncases t2; nnormalize; #H; ##[ ##29: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq30 : ∀t2.eq_bit t1D t2 = true → t1D = t2. #t2; ncases t2; nnormalize; #H; ##[ ##30: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq31 : ∀t2.eq_bit t1E t2 = true → t1E = t2. #t2; ncases t2; nnormalize; #H; ##[ ##31: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+nlemma eqbit_to_eq32 : ∀t2.eq_bit t1F t2 = true → t1F = t2. #t2; ncases t2; nnormalize; #H; ##[ ##32: napply refl_eq ##| ##*: ndestruct (*napply (bool_destruct … H)*) ##] nqed.
+
+nlemma eqbit_to_eq : ∀t1,t2.eq_bit t1 t2 = true → t1 = t2.
+ #t1; ncases t1;
+ ##[ ##1: napply eqbit_to_eq1 ##| ##2: napply eqbit_to_eq2
+ ##| ##3: napply eqbit_to_eq3 ##| ##4: napply eqbit_to_eq4
+ ##| ##5: napply eqbit_to_eq5 ##| ##6: napply eqbit_to_eq6
+ ##| ##7: napply eqbit_to_eq7 ##| ##8: napply eqbit_to_eq8
+ ##| ##9: napply eqbit_to_eq9 ##| ##10: napply eqbit_to_eq10
+ ##| ##11: napply eqbit_to_eq11 ##| ##12: napply eqbit_to_eq12
+ ##| ##13: napply eqbit_to_eq13 ##| ##14: napply eqbit_to_eq14
+ ##| ##15: napply eqbit_to_eq15 ##| ##16: napply eqbit_to_eq16
+ ##| ##17: napply eqbit_to_eq17 ##| ##18: napply eqbit_to_eq18
+ ##| ##19: napply eqbit_to_eq19 ##| ##20: napply eqbit_to_eq20
+ ##| ##21: napply eqbit_to_eq21 ##| ##22: napply eqbit_to_eq22
+ ##| ##23: napply eqbit_to_eq23 ##| ##24: napply eqbit_to_eq24
+ ##| ##25: napply eqbit_to_eq25 ##| ##26: napply eqbit_to_eq26
+ ##| ##27: napply eqbit_to_eq27 ##| ##28: napply eqbit_to_eq28
+ ##| ##29: napply eqbit_to_eq29 ##| ##30: napply eqbit_to_eq30
+ ##| ##31: napply eqbit_to_eq31 ##| ##32: napply eqbit_to_eq32
+ ##]
+nqed.
+
+nlemma neq_to_neqbit : ∀n1,n2.n1 ≠ n2 → eq_bit n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_bit n1 n2));
+ napply (not_to_not (eq_bit n1 n2 = true) (n1 = n2) ? H);
+ napply (eqbit_to_eq n1 n2).
+nqed.
+
+nlemma decidable_bit : ∀x,y:bitrigesim.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_bit x y = true) (eq_bit x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqbit_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqbit_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqbit : symmetricT bitrigesim bool eq_bit.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_bit n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqbit n1 n2 H);
+          napply (symmetric_eq ? (eq_bit n2 n1) false);
+          napply (neq_to_neqbit n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/num/bool.ma b/helm/software/matita/contribs/ng_assembly/num/bool.ma
new file mode 100755 (executable)
index 0000000..8092713
--- /dev/null
@@ -0,0 +1,78 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/theory.ma".
+
+(* ******** *)
+(* BOOLEANI *)
+(* ******** *)
+
+ninductive bool : Type ≝ 
+  true : bool
+| false : bool.
+
+(* operatori booleani *)
+
+ndefinition eq_bool ≝
+λb1,b2:bool.match b1 with
+ [ true ⇒ match b2 with [ true ⇒ true | false ⇒ false ]
+ | false ⇒ match b2 with [ true ⇒ false | false ⇒ true ]
+ ].
+
+ndefinition not_bool ≝
+λb:bool.match b with [ true ⇒ false | false ⇒ true ].
+
+ndefinition and_bool ≝
+λb1,b2:bool.match b1 with
+ [ true ⇒ b2 | false ⇒ false ].
+
+ndefinition or_bool ≝
+λb1,b2:bool.match b1 with
+ [ true ⇒ true | false ⇒ b2 ].
+
+ndefinition xor_bool ≝
+λb1,b2:bool.match b1 with
+ [ true ⇒ not_bool b2
+ | false ⇒ b2 ].
+
+(* \ominus *)
+notation "hvbox(⊖ a)" non associative with precedence 36
+ for @{ 'not_bool $a }.
+interpretation "not_bool" 'not_bool x = (not_bool x).
+
+(* \otimes *)
+notation "hvbox(a break ⊗ b)" left associative with precedence 35
+ for @{ 'and_bool $a $b }.
+interpretation "and_bool" 'and_bool x y = (and_bool x y).
+
+(* \oplus *)
+notation "hvbox(a break ⊕ b)" left associative with precedence 34
+ for @{ 'or_bool $a $b }.
+interpretation "or_bool" 'or_bool x y = (or_bool x y).
+
+(* \odot *)
+notation "hvbox(a break ⊙ b)" left associative with precedence 33
+ for @{ 'xor_bool $a $b }.
+interpretation "xor_bool" 'xor_bool x y = (xor_bool x y).
+
+ndefinition boolRelation : Type → Type ≝
+λA:Type.A → A → bool.
diff --git a/helm/software/matita/contribs/ng_assembly/num/bool_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/bool_lemmas.ma
new file mode 100755 (executable)
index 0000000..db5214c
--- /dev/null
@@ -0,0 +1,324 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ******** *)
+(* BOOLEANI *)
+(* ******** *)
+
+(*
+ndefinition bool_destruct_aux ≝
+Πb1,b2:bool.ΠP:Prop.b1 = b2 →
+ match eq_bool b1 b2 with [ true ⇒ P → P | false ⇒ P ].
+
+ndefinition bool_destruct : bool_destruct_aux.
+ #b1; #b2; #P; #H;
+ nrewrite < H;
+ nelim b1;
+ nnormalize;
+ napply (λx.x).
+nqed.
+*)
+
+nlemma symmetric_eqbool : symmetricT bool bool eq_bool.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_andbool : symmetricT bool bool and_bool.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma associative_andbool : ∀b1,b2,b3.((b1 ⊗ b2) ⊗ b3) = (b1 ⊗ (b2 ⊗ b3)).
+ #b1; #b2; #b3;
+ nelim b1;
+ nelim b2;
+ nelim b3;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_orbool : symmetricT bool bool or_bool.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma associative_orbool : ∀b1,b2,b3.((b1 ⊕ b2) ⊕ b3) = (b1 ⊕ (b2 ⊕ b3)).
+ #b1; #b2; #b3;
+ nelim b1;
+ nelim b2;
+ nelim b3;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_xorbool : symmetricT bool bool xor_bool.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma associative_xorbool : ∀b1,b2,b3.((b1 ⊙ b2) ⊙ b3) = (b1 ⊙ (b2 ⊙ b3)).
+ #b1; #b2; #b3;
+ nelim b1;
+ nelim b2;
+ nelim b3;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma eqbool_to_eq : ∀b1,b2:bool.(eq_bool b1 b2 = true) → (b1 = b2).
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##1,4: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma eq_to_eqbool : ∀b1,b2.b1 = b2 → eq_bool b1 b2 = true.
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##1,4: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma decidable_bool : ∀x,y:bool.decidable (x = y).
+ #x; #y;
+ nnormalize;
+ nelim x;
+ nelim y;
+ ##[ ##1,4: napply (or2_intro1 (? = ?) (? ≠ ?) …); napply refl_eq
+ ##| ##*: napply (or2_intro2 (? = ?) (? ≠ ?) …);
+          nnormalize; #H;
+          napply False_ind;
+          ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma decidable_bexpr : ∀x.(x = true) ∨ (x = false).
+ #x; ncases x;
+ ##[ ##1: napply (or2_intro1 (true = true) (true = false) (refl_eq …))
+ ##| ##2: napply (or2_intro2 (false = true) (false = false) (refl_eq …))
+ ##]
+nqed.
+
+nlemma neqbool_to_neq : ∀b1,b2:bool.(eq_bool b1 b2 = false) → (b1 ≠ b2).
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##1,4: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##*: #H; #H1; ndestruct (*napply (bool_destruct … H1)*)
+ ##]
+nqed.
+
+nlemma neq_to_neqbool : ∀b1,b2.b1 ≠ b2 → eq_bool b1 b2 = false.
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##1,4: #H; nelim (H (refl_eq …))
+ ##| ##*: #H; napply refl_eq
+ ##]
+nqed.
+
+nlemma eqfalse_to_neqtrue : ∀x.x = false → x ≠ true.
+ #x; nelim x;
+ ##[ ##1: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##2: #H; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+ ##]
+nqed.
+
+nlemma eqtrue_to_neqfalse : ∀x.x = true → x ≠ false.
+ #x; nelim x;
+ ##[ ##1: #H; nnormalize; #H1; ndestruct (*napply (bool_destruct … H1)*)
+ ##| ##2: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma neqfalse_to_eqtrue : ∀x.x ≠ false → x = true.
+ #x; nelim x;
+ ##[ ##1: #H; napply refl_eq
+ ##| ##2: nnormalize; #H; nelim (H (refl_eq …))
+ ##]
+nqed.
+
+nlemma neqtrue_to_eqfalse : ∀x.x ≠ true → x = false.
+ #x; nelim x;
+ ##[ ##1: nnormalize; #H; nelim (H (refl_eq …))
+ ##| ##2: #H; napply refl_eq
+ ##]
+nqed.
+
+nlemma andb_true_true_l: ∀b1,b2.(b1 ⊗ b2) = true → b1 = true.
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##1,2: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma andb_true_true_r: ∀b1,b2.(b1 ⊗ b2) = true → b2 = true.
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##1,3: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma andb_false2
+ : ∀b1,b2.(b1 ⊗ b2) = false →
+   (b1 = false) ∨ (b2 = false).
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##1: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##2,4: #H; napply (or2_intro2 … H)
+ ##| ##3: #H; napply (or2_intro1 … H)
+ ##]
+nqed.
+
+nlemma andb_false3
+ : ∀b1,b2,b3.(b1 ⊗ b2 ⊗ b3) = false →
+   Or3 (b1 = false) (b2 = false) (b3 = false).
+ #b1; #b2; #b3;
+ ncases b1;
+ ncases b2;
+ ncases b3;
+ nnormalize;
+ ##[ ##1: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##5,6,7,8: #H; napply (or3_intro1 … H)
+ ##| ##2,4: #H; napply (or3_intro3 … H)
+ ##| ##3: #H; napply (or3_intro2 … H)
+ ##]
+nqed.
+
+nlemma andb_false4
+ : ∀b1,b2,b3,b4.(b1 ⊗ b2 ⊗ b3 ⊗ b4) = false →
+   Or4 (b1 = false) (b2 = false) (b3 = false) (b4 = false).
+ #b1; #b2; #b3; #b4;
+ ncases b1;
+ ncases b2;
+ ncases b3;
+ ncases b4;
+ nnormalize;
+ ##[ ##1: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##9,10,11,12,13,14,15,16: #H; napply (or4_intro1 … H)
+ ##| ##5,6,7,8: #H; napply (or4_intro2 … H)
+ ##| ##3,4: #H; napply (or4_intro3 … H)
+ ##| ##2: #H; napply (or4_intro4 … H)
+ ##]
+nqed.
+
+nlemma andb_false5
+ : ∀b1,b2,b3,b4,b5.(b1 ⊗ b2 ⊗ b3 ⊗ b4 ⊗ b5) = false →
+   Or5 (b1 = false) (b2 = false) (b3 = false) (b4 = false) (b5 = false).
+ #b1; #b2; #b3; #b4; #b5;
+ ncases b1;
+ ncases b2;
+ ncases b3;
+ ncases b4;
+ ncases b5;
+ nnormalize;
+ ##[ ##1: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##| ##17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32: #H; napply (or5_intro1 … H)
+ ##| ##9,10,11,12,13,14,15,16: #H; napply (or5_intro2 … H)
+ ##| ##5,6,7,8: #H; napply (or5_intro3 … H)
+ ##| ##3,4: #H; napply (or5_intro4 … H)
+ ##| ##2: #H; napply (or5_intro5 … H)
+ ##]
+nqed.
+
+nlemma andb_false2_1 : ∀b.(false ⊗ b) = false.
+ #b; nnormalize; napply refl_eq. nqed.
+nlemma andb_false2_2 : ∀b.(b ⊗ false) = false.
+ #b; nelim b; nnormalize; napply refl_eq. nqed.
+
+nlemma andb_false3_1 : ∀b1,b2.(false ⊗ b1 ⊗ b2) = false.
+ #b1; #b2; nnormalize; napply refl_eq. nqed.
+nlemma andb_false3_2 : ∀b1,b2.(b1 ⊗ false ⊗ b2) = false.
+ #b1; #b2; nelim b1; nnormalize; napply refl_eq. nqed.
+nlemma andb_false3_3 : ∀b1,b2.(b1 ⊗ b2 ⊗ false) = false.
+ #b1; #b2; nelim b1; nelim b2; nnormalize; napply refl_eq. nqed.
+
+nlemma andb_false4_1 : ∀b1,b2,b3.(false ⊗ b1 ⊗ b2 ⊗ b3) = false.
+ #b1; #b2; #b3; nnormalize; napply refl_eq. nqed.
+nlemma andb_false4_2 : ∀b1,b2,b3.(b1 ⊗ false ⊗ b2 ⊗ b3) = false.
+ #b1; #b2; #b3; nelim b1; nnormalize; napply refl_eq. nqed.
+nlemma andb_false4_3 : ∀b1,b2,b3.(b1 ⊗ b2 ⊗ false ⊗ b3) = false.
+ #b1; #b2; #b3; nelim b1; nelim b2; nnormalize; napply refl_eq. nqed.
+nlemma andb_false4_4 : ∀b1,b2,b3.(b1 ⊗ b2 ⊗ b3 ⊗ false) = false.
+ #b1; #b2; #b3; nelim b1; nelim b2; nelim b3; nnormalize; napply refl_eq. nqed.
+
+nlemma andb_false5_1 : ∀b1,b2,b3,b4.(false ⊗ b1 ⊗ b2 ⊗ b3 ⊗ b4) = false.
+ #b1; #b2; #b3; #b4; nnormalize; napply refl_eq. nqed.
+nlemma andb_false5_2 : ∀b1,b2,b3,b4.(b1 ⊗ false ⊗ b2 ⊗ b3 ⊗ b4) = false.
+ #b1; #b2; #b3; #b4; nelim b1; nnormalize; napply refl_eq. nqed.
+nlemma andb_false5_3 : ∀b1,b2,b3,b4.(b1 ⊗ b2 ⊗ false ⊗ b3 ⊗ b4) = false.
+ #b1; #b2; #b3; #b4; nelim b1; nelim b2; nnormalize; napply refl_eq. nqed.
+nlemma andb_false5_4 : ∀b1,b2,b3,b4.(b1 ⊗ b2 ⊗ b3 ⊗ false ⊗ b4) = false.
+ #b1; #b2; #b3; #b4; nelim b1; nelim b2; nelim b3; nnormalize; napply refl_eq. nqed.
+nlemma andb_false5_5 : ∀b1,b2,b3,b4.(b1 ⊗ b2 ⊗ b3 ⊗ b4 ⊗ false) = false.
+ #b1; #b2; #b3; #b4; nelim b1; nelim b2; nelim b3; nelim b4; nnormalize; napply refl_eq. nqed.
+
+nlemma orb_false_false_l : ∀b1,b2:bool.(b1 ⊕ b2) = false → b1 = false.
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##4: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma orb_false_false_r : ∀b1,b2:bool.(b1 ⊕ b2) = false → b2 = false.
+ #b1; #b2;
+ ncases b1;
+ ncases b2;
+ nnormalize;
+ ##[ ##4: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/num/byte8.ma b/helm/software/matita/contribs/ng_assembly/num/byte8.ma
new file mode 100755 (executable)
index 0000000..d759181
--- /dev/null
@@ -0,0 +1,408 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/exadecim.ma".
+include "num/bitrigesim.ma".
+
+(* **** *)
+(* BYTE *)
+(* **** *)
+
+nrecord byte8 : Type ≝
+ {
+ b8h: exadecim;
+ b8l: exadecim
+ }.
+
+(* \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).
+
+(* operatore = *)
+ndefinition eq_b8 ≝ λb1,b2:byte8.(eq_ex (b8h b1) (b8h b2)) ⊗ (eq_ex (b8l b1) (b8l b2)).
+
+(* operatore < *)
+ndefinition lt_b8 ≝
+λb1,b2:byte8.
+ (lt_ex (b8h b1) (b8h b2)) ⊕
+ ((eq_ex (b8h b1) (b8h b2)) ⊗ (lt_ex (b8l b1) (b8l b2))).
+
+(* operatore ≤ *)
+ndefinition le_b8 ≝
+λb1,b2:byte8.
+ (lt_ex (b8h b1) (b8h b2)) ⊕
+ ((eq_ex (b8h b1) (b8h b2)) ⊗ (le_ex (b8l b1) (b8l b2))).
+
+(* operatore > *)
+ndefinition gt_b8 ≝
+λb1,b2:byte8.
+ (gt_ex (b8h b1) (b8h b2)) ⊕
+ ((eq_ex (b8h b1) (b8h b2)) ⊗ (gt_ex (b8l b1) (b8l b2))).
+
+(* operatore ≥ *)
+ndefinition ge_b8 ≝
+λb1,b2:byte8.
+ (gt_ex (b8h b1) (b8h b2)) ⊕
+ ((eq_ex (b8h b1) (b8h b2)) ⊗ (ge_ex (b8l b1) (b8l b2))).
+
+(* operatore and *)
+ndefinition and_b8 ≝
+λb1,b2:byte8.mk_byte8 (and_ex (b8h b1) (b8h b2)) (and_ex (b8l b1) (b8l b2)).
+
+(* operatore or *)
+ndefinition or_b8 ≝
+λb1,b2:byte8.mk_byte8 (or_ex (b8h b1) (b8h b2)) (or_ex (b8l b1) (b8l b2)).
+
+(* operatore xor *)
+ndefinition xor_b8 ≝
+λb1,b2:byte8.mk_byte8 (xor_ex (b8h b1) (b8h b2)) (xor_ex (b8l b1) (b8l b2)).
+
+(* 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'' ]]. 
+
+(* 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'' ]].
+
+(* 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' ].
+
+(* 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'' ]]. 
+
+(* 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'' ]].
+
+(* 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' ].
+
+(* operatore not/complemento a 1 *)
+ndefinition not_b8 ≝
+λb:byte8.mk_byte8 (not_ex (b8h b)) (not_ex (b8l b)).
+
+(* 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' ]].
+
+(* 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〉 ].
+
+(* 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).
+
+(* 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' ]].
+
+(* 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〉 ].
+
+(* 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)).
+
+(* 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)) ]. 
+
+(* 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)) ]. 
+
+(* operatore neg/complemento a 2 *)
+ndefinition compl_b8 ≝
+λb:byte8.match MSB_b8 b with
+ [ true ⇒ succ_b8 (not_b8 b)
+ | false ⇒ not_b8 (pred_b8 b) ].
+
+(* operatore moltiplicazione senza segno: e*e=[0x00,0xE1] *)
+ndefinition mul_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 ⇒ 〈x0,x8〉   | x9 ⇒ 〈x0,x9〉   | xA ⇒ 〈x0,xA〉   | xB ⇒ 〈x0,xB〉
+  | xC ⇒ 〈x0,xC〉   | xD ⇒ 〈x0,xD〉   | xE ⇒ 〈x0,xE〉   | xF ⇒ 〈x0,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 ⇒ 〈x1,x0〉   | x9 ⇒ 〈x1,x2〉   | xA ⇒ 〈x1,x4〉   | xB ⇒ 〈x1,x6〉
+  | xC ⇒ 〈x1,x8〉   | xD ⇒ 〈x1,xA〉   | xE ⇒ 〈x1,xC〉   | xF ⇒ 〈x1,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 ⇒ 〈x1,x8〉   | x9 ⇒ 〈x1,xB〉   | xA ⇒ 〈x1,xE〉   | xB ⇒ 〈x2,x1〉
+  | xC ⇒ 〈x2,x4〉   | xD ⇒ 〈x2,x7〉   | xE ⇒ 〈x2,xA〉   | xF ⇒ 〈x2,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 ⇒ 〈x2,x0〉   | x9 ⇒ 〈x2,x4〉   | xA ⇒ 〈x2,x8〉   | xB ⇒ 〈x2,xC〉
+  | xC ⇒ 〈x3,x0〉   | xD ⇒ 〈x3,x4〉   | xE ⇒ 〈x3,x8〉   | xF ⇒ 〈x3,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 ⇒ 〈x2,x8〉   | x9 ⇒ 〈x2,xD〉   | xA ⇒ 〈x3,x2〉   | xB ⇒ 〈x3,x7〉
+  | xC ⇒ 〈x3,xC〉   | xD ⇒ 〈x4,x1〉   | xE ⇒ 〈x4,x6〉   | xF ⇒ 〈x4,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 ⇒ 〈x3,x0〉   | x9 ⇒ 〈x3,x6〉   | xA ⇒ 〈x3,xC〉   | xB ⇒ 〈x4,x2〉
+  | xC ⇒ 〈x4,x8〉   | xD ⇒ 〈x4,xE〉   | xE ⇒ 〈x5,x4〉   | xF ⇒ 〈x5,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 ⇒ 〈x3,x8〉   | x9 ⇒ 〈x3,xF〉   | xA ⇒ 〈x4,x6〉   | xB ⇒ 〈x4,xD〉
+  | xC ⇒ 〈x5,x4〉   | xD ⇒ 〈x5,xB〉   | xE ⇒ 〈x6,x2〉   | xF ⇒ 〈x6,x9〉 ]
+ | x8 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,x8〉   | x2 ⇒ 〈x1,x0〉   | x3 ⇒ 〈x1,x8〉
+  | x4 ⇒ 〈x2,x0〉   | x5 ⇒ 〈x2,x8〉   | x6 ⇒ 〈x3,x0〉   | x7 ⇒ 〈x3,x8〉
+  | x8 ⇒ 〈x4,x0〉   | x9 ⇒ 〈x4,x8〉   | xA ⇒ 〈x5,x0〉   | xB ⇒ 〈x5,x8〉
+  | xC ⇒ 〈x6,x0〉   | xD ⇒ 〈x6,x8〉   | xE ⇒ 〈x7,x0〉   | xF ⇒ 〈x7,x8〉 ]
+ | x9 ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,x9〉   | x2 ⇒ 〈x1,x2〉   | x3 ⇒ 〈x1,xB〉
+  | x4 ⇒ 〈x2,x4〉   | x5 ⇒ 〈x2,xD〉   | x6 ⇒ 〈x3,x6〉   | x7 ⇒ 〈x3,xF〉
+  | x8 ⇒ 〈x4,x8〉   | x9 ⇒ 〈x5,x1〉   | xA ⇒ 〈x5,xA〉   | xB ⇒ 〈x6,x3〉
+  | xC ⇒ 〈x6,xC〉   | xD ⇒ 〈x7,x5〉   | xE ⇒ 〈x7,xE〉   | xF ⇒ 〈x8,x7〉 ]
+ | xA ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,xA〉   | x2 ⇒ 〈x1,x4〉   | x3 ⇒ 〈x1,xE〉
+  | x4 ⇒ 〈x2,x8〉   | x5 ⇒ 〈x3,x2〉   | x6 ⇒ 〈x3,xC〉   | x7 ⇒ 〈x4,x6〉
+  | x8 ⇒ 〈x5,x0〉   | x9 ⇒ 〈x5,xA〉   | xA ⇒ 〈x6,x4〉   | xB ⇒ 〈x6,xE〉
+  | xC ⇒ 〈x7,x8〉   | xD ⇒ 〈x8,x2〉   | xE ⇒ 〈x8,xC〉   | xF ⇒ 〈x9,x6〉 ]
+ | xB ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,xB〉   | x2 ⇒ 〈x1,x6〉   | x3 ⇒ 〈x2,x1〉
+  | x4 ⇒ 〈x2,xC〉   | x5 ⇒ 〈x3,x7〉   | x6 ⇒ 〈x4,x2〉   | x7 ⇒ 〈x4,xD〉
+  | x8 ⇒ 〈x5,x8〉   | x9 ⇒ 〈x6,x3〉   | xA ⇒ 〈x6,xE〉   | xB ⇒ 〈x7,x9〉
+  | xC ⇒ 〈x8,x4〉   | xD ⇒ 〈x8,xF〉   | xE ⇒ 〈x9,xA〉   | xF ⇒ 〈xA,x5〉 ]
+ | xC ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,xC〉   | x2 ⇒ 〈x1,x8〉   | x3 ⇒ 〈x2,x4〉
+  | x4 ⇒ 〈x3,x0〉   | x5 ⇒ 〈x3,xC〉   | x6 ⇒ 〈x4,x8〉   | x7 ⇒ 〈x5,x4〉
+  | x8 ⇒ 〈x6,x0〉   | x9 ⇒ 〈x6,xC〉   | xA ⇒ 〈x7,x8〉   | xB ⇒ 〈x8,x4〉
+  | xC ⇒ 〈x9,x0〉   | xD ⇒ 〈x9,xC〉   | xE ⇒ 〈xA,x8〉   | xF ⇒ 〈xB,x4〉 ]
+ | xD ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,xD〉   | x2 ⇒ 〈x1,xA〉   | x3 ⇒ 〈x2,x7〉
+  | x4 ⇒ 〈x3,x4〉   | x5 ⇒ 〈x4,x1〉   | x6 ⇒ 〈x4,xE〉   | x7 ⇒ 〈x5,xB〉
+  | x8 ⇒ 〈x6,x8〉   | x9 ⇒ 〈x7,x5〉   | xA ⇒ 〈x8,x2〉   | xB ⇒ 〈x8,xF〉
+  | xC ⇒ 〈x9,xC〉   | xD ⇒ 〈xA,x9〉   | xE ⇒ 〈xB,x6〉   | xF ⇒ 〈xC,x3〉 ]
+ | xE ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,xE〉   | x2 ⇒ 〈x1,xC〉   | x3 ⇒ 〈x2,xA〉
+  | x4 ⇒ 〈x3,x8〉   | x5 ⇒ 〈x4,x6〉   | x6 ⇒ 〈x5,x4〉   | x7 ⇒ 〈x6,x2〉
+  | x8 ⇒ 〈x7,x0〉   | x9 ⇒ 〈x7,xE〉   | xA ⇒ 〈x8,xC〉   | xB ⇒ 〈x9,xA〉
+  | xC ⇒ 〈xA,x8〉   | xD ⇒ 〈xB,x6〉   | xE ⇒ 〈xC,x4〉   | xF ⇒ 〈xD,x2〉 ]
+ | xF ⇒ match e2 with
+  [ x0 ⇒ 〈x0,x0〉   | x1 ⇒ 〈x0,xF〉   | x2 ⇒ 〈x1,xE〉   | x3 ⇒ 〈x2,xD〉
+  | x4 ⇒ 〈x3,xC〉   | x5 ⇒ 〈x4,xB〉   | x6 ⇒ 〈x5,xA〉   | x7 ⇒ 〈x6,x9〉
+  | x8 ⇒ 〈x7,x8〉   | x9 ⇒ 〈x8,x7〉   | xA ⇒ 〈x9,x6〉   | xB ⇒ 〈xA,x5〉
+  | xC ⇒ 〈xB,x4〉   | xD ⇒ 〈xC,x3〉   | xE ⇒ 〈xD,x2〉   | xF ⇒ 〈xE,x1〉 ]
+ ].
+
+(* correzione per somma su BCD *)
+(* input: halfcarry,carry,X(BCD+BCD) *)
+(* output: X',carry' *)
+ndefinition daa_b8 ≝
+λh,c:bool.λX:byte8.
+ match lt_b8 X 〈x9,xA〉 with
+  (* [X:0x00-0x99] *)
+  (* c' = c *)
+  (* 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
+    [ 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
+  (* [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
+    [ true ⇒ X
+    | false ⇒ plus_b8_d_d X 〈x0,x6〉 ] in
+   let X'' ≝ plus_b8_d_d X' 〈x6,x0〉 in
+   pair … X'' true
+  ].
+
+(* 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).
+
+(* 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〉
+| b8_S : ∀n.rec_byte8 n → rec_byte8 (succ_b8 n).
+
+(* 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 〈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 ≝
+ match r return λx.λy:rec_exadecim x.rec_byte8 〈x,x0〉 with
+  [ ex_O ⇒ b8_O
+  | ex_S t n' ⇒ b8_to_recb8_aux1 ? (b8_to_recb8_aux2 t n')
+  ].
+
+(* ... cifra esadecimale inferiore *)
+ndefinition b8_to_recb8_aux3 : Πn1,n2.rec_byte8 〈n1,x0〉 → rec_byte8 〈n1,n2〉 ≝
+λn1,n2.λrecb:rec_byte8 〈n1,x0〉.
+ match n2 return λx.rec_byte8 〈n1,x〉 with
+  [ x0 ⇒ 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))))))))))))))
+  ].
+
+(*
+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_byte8 h l ⇒ b8_to_recb8_aux3 h l (b8_to_recb8_aux2 h (ex_to_recex h)) ].
+
+(* ottali → esadecimali *)
+ndefinition b8_of_bit ≝
+λn.match n with
+ [ t00 ⇒ 〈x0,x0〉 | t01 ⇒ 〈x0,x1〉 | t02 ⇒ 〈x0,x2〉 | t03 ⇒ 〈x0,x3〉
+ | t04 ⇒ 〈x0,x4〉 | t05 ⇒ 〈x0,x5〉 | t06 ⇒ 〈x0,x6〉 | t07 ⇒ 〈x0,x7〉
+ | t08 ⇒ 〈x0,x8〉 | t09 ⇒ 〈x0,x9〉 | t0A ⇒ 〈x0,xA〉 | t0B ⇒ 〈x0,xB〉
+ | t0C ⇒ 〈x0,xC〉 | t0D ⇒ 〈x0,xD〉 | t0E ⇒ 〈x0,xE〉 | t0F ⇒ 〈x0,xF〉
+ | t10 ⇒ 〈x1,x0〉 | t11 ⇒ 〈x1,x1〉 | t12 ⇒ 〈x1,x2〉 | t13 ⇒ 〈x1,x3〉
+ | t14 ⇒ 〈x1,x4〉 | t15 ⇒ 〈x1,x5〉 | t16 ⇒ 〈x1,x6〉 | t17 ⇒ 〈x1,x7〉
+ | t18 ⇒ 〈x1,x8〉 | t19 ⇒ 〈x1,x9〉 | t1A ⇒ 〈x1,xA〉 | t1B ⇒ 〈x1,xB〉
+ | t1C ⇒ 〈x1,xC〉 | t1D ⇒ 〈x1,xD〉 | t1E ⇒ 〈x1,xE〉 | t1F ⇒ 〈x1,xF〉
+ ].
diff --git a/helm/software/matita/contribs/ng_assembly/num/byte8_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/byte8_lemmas.ma
new file mode 100755 (executable)
index 0000000..10a1009
--- /dev/null
@@ -0,0 +1,338 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/byte8.ma".
+include "num/exadecim_lemmas.ma".
+
+(* **** *)
+(* BYTE *)
+(* **** *)
+
+nlemma byte8_destruct_1 :
+∀x1,x2,y1,y2.
+ mk_byte8 x1 y1 = mk_byte8 x2 y2 → x1 = x2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_byte8 x2 y2 with [ mk_byte8 a _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma byte8_destruct_2 :
+∀x1,x2,y1,y2.
+ mk_byte8 x1 y1 = mk_byte8 x2 y2 → y1 = y2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_byte8 x2 y2 with [ mk_byte8 _ b ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqb8 : symmetricT byte8 bool eq_b8.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ #e1; #e2; #e3; #e4;
+ nchange with (((eq_ex e3 e1)⊗(eq_ex e4 e2)) = ((eq_ex e1 e3)⊗(eq_ex e2 e4)));
+ nrewrite > (symmetric_eqex e1 e3);
+ nrewrite > (symmetric_eqex e2 e4);
+ napply refl_eq.
+nqed. 
+
+nlemma symmetric_andb8 : symmetricT byte8 byte8 and_b8.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ #e1; #e2; #e3; #e4;
+ nchange with ((mk_byte8 (and_ex e3 e1) (and_ex e4 e2)) = (mk_byte8 (and_ex e1 e3) (and_ex e2 e4)));
+ nrewrite > (symmetric_andex e1 e3);
+ nrewrite > (symmetric_andex e2 e4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_andb8 : ∀b1,b2,b3.(and_b8 (and_b8 b1 b2) b3) = (and_b8 b1 (and_b8 b2 b3)).
+ #b1; #b2; #b3;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nelim b3;
+ #e5; #e6;
+ nchange with (mk_byte8 (and_ex (and_ex e1 e3) e5) (and_ex (and_ex e2 e4) e6) =
+  mk_byte8 (and_ex e1 (and_ex e3 e5)) (and_ex e2 (and_ex e4 e6)));
+ nrewrite < (associative_andex e1 e3 e5);
+ nrewrite < (associative_andex e2 e4 e6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_orb8 : symmetricT byte8 byte8 or_b8.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ #e1; #e2; #e3; #e4;
+ nchange with ((mk_byte8 (or_ex e3 e1) (or_ex e4 e2)) = (mk_byte8 (or_ex e1 e3) (or_ex e2 e4)));
+ nrewrite > (symmetric_orex e1 e3);
+ nrewrite > (symmetric_orex e2 e4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_orb8 : ∀b1,b2,b3.(or_b8 (or_b8 b1 b2) b3) = (or_b8 b1 (or_b8 b2 b3)).
+ #b1; #b2; #b3;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nelim b3;
+ #e5; #e6;
+ nchange with (mk_byte8 (or_ex (or_ex e1 e3) e5) (or_ex (or_ex e2 e4) e6) =
+  mk_byte8 (or_ex e1 (or_ex e3 e5)) (or_ex e2 (or_ex e4 e6)));
+ nrewrite < (associative_orex e1 e3 e5);
+ nrewrite < (associative_orex e2 e4 e6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_xorb8 : symmetricT byte8 byte8 xor_b8.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ #e1; #e2; #e3; #e4;
+ nchange with ((mk_byte8 (xor_ex e3 e1) (xor_ex e4 e2)) = (mk_byte8 (xor_ex e1 e3) (xor_ex e2 e4)));
+ nrewrite > (symmetric_xorex e1 e3);
+ nrewrite > (symmetric_xorex e2 e4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_xorb8 : ∀b1,b2,b3.(xor_b8 (xor_b8 b1 b2) b3) = (xor_b8 b1 (xor_b8 b2 b3)).
+ #b1; #b2; #b3;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nelim b3;
+ #e5; #e6;
+ nchange with (mk_byte8 (xor_ex (xor_ex e1 e3) e5) (xor_ex (xor_ex e2 e4) e6) =
+  mk_byte8 (xor_ex e1 (xor_ex e3 e5)) (xor_ex e2 (xor_ex e4 e6)));
+ nrewrite < (associative_xorex e1 e3 e5);
+ nrewrite < (associative_xorex e2 e4 e6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusb8_dc_dc : ∀b1,b2,c.plus_b8_dc_dc b1 b2 c = plus_b8_dc_dc b2 b1 c.
+ #b1; #b2; #c;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nchange with (
+  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' ]] =
+  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' ]]);
+ nrewrite > (symmetric_plusex_dc_dc e4 e2 c);
+ ncases (plus_ex_dc_dc e2 e4 c);
+ #e5; #c1;
+ nchange with (
+  match plus_ex_dc_dc e1 e3 c1 with [ pair h c' ⇒ pair … 〈h,e5〉 c' ] =
+  match plus_ex_dc_dc e3 e1 c1 with [ pair h c' ⇒ pair … 〈h,e5〉 c' ]);
+ nrewrite > (symmetric_plusex_dc_dc e1 e3 c1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusb8_dc_d : ∀b1,b2,c.plus_b8_dc_d b1 b2 c = plus_b8_dc_d b2 b1 c.
+ #b1; #b2; #c;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nchange with (
+  match plus_ex_dc_dc e2 e4 c with [ pair l c ⇒ 〈plus_ex_dc_d e1 e3 c,l〉 ] =
+  match plus_ex_dc_dc e4 e2 c with [ pair l c ⇒ 〈plus_ex_dc_d e3 e1 c,l〉 ]);
+ nrewrite > (symmetric_plusex_dc_dc e4 e2 c);
+ ncases (plus_ex_dc_dc e2 e4 c);
+ #e5; #c1;
+ nchange with (〈plus_ex_dc_d e1 e3 c1,e5〉 = 〈plus_ex_dc_d e3 e1 c1,e5〉);
+ nrewrite > (symmetric_plusex_dc_d e1 e3 c1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusb8_dc_c : ∀b1,b2,c.plus_b8_dc_c b1 b2 c = plus_b8_dc_c b2 b1 c.
+ #b1; #b2; #c;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nchange with (
+  plus_ex_dc_c e1 e3 (plus_ex_dc_c e2 e4 c) =
+  plus_ex_dc_c e3 e1 (plus_ex_dc_c e4 e2 c));
+ nrewrite > (symmetric_plusex_dc_c e4 e2 c);
+ nrewrite > (symmetric_plusex_dc_c e3 e1 (plus_ex_dc_c e2 e4 c));
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusb8_d_dc : ∀b1,b2.plus_b8_d_dc b1 b2 = plus_b8_d_dc b2 b1.
+ #b1; #b2;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nchange with (
+  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' ]] =
+  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' ]]);
+ nrewrite > (symmetric_plusex_d_dc e4 e2);
+ ncases (plus_ex_d_dc e2 e4);
+ #e5; #c;
+ nchange with (
+  match plus_ex_dc_dc e1 e3 c with [ pair h c' ⇒ pair … 〈h,e5〉 c' ] =
+  match plus_ex_dc_dc e3 e1 c with [ pair h c' ⇒ pair … 〈h,e5〉 c' ]);
+ nrewrite > (symmetric_plusex_dc_dc e1 e3 c);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusb8_d_d : ∀b1,b2.plus_b8_d_d b1 b2 = plus_b8_d_d b2 b1.
+ #b1; #b2;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nchange with (
+  match plus_ex_d_dc e2 e4 with [ pair l c ⇒ 〈plus_ex_dc_d e1 e3 c,l〉 ] =
+  match plus_ex_d_dc e4 e2 with [ pair l c ⇒ 〈plus_ex_dc_d e3 e1 c,l〉 ]);
+ nrewrite > (symmetric_plusex_d_dc e4 e2);
+ ncases (plus_ex_d_dc e2 e4);
+ #e5; #c;
+ nchange with (〈plus_ex_dc_d e1 e3 c,e5〉 = 〈plus_ex_dc_d e3 e1 c,e5〉);
+ nrewrite > (symmetric_plusex_dc_d e1 e3 c);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusb8_d_c : ∀b1,b2.plus_b8_d_c b1 b2 = plus_b8_d_c b2 b1.
+ #b1; #b2;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nchange with (
+  plus_ex_dc_c e1 e3 (plus_ex_d_c e2 e4) =
+  plus_ex_dc_c e3 e1 (plus_ex_d_c e4 e2));
+ nrewrite > (symmetric_plusex_d_c e4 e2);
+ nrewrite > (symmetric_plusex_dc_c e3 e1 (plus_ex_d_c e2 e4));
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_mulex : symmetricT exadecim byte8 mul_ex.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma eqb8_to_eq : ∀b1,b2:byte8.(eq_b8 b1 b2 = true) → (b1 = b2).
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ #e1; #e2; #e3; #e4;
+ nchange in ⊢ (% → ?) with (((eq_ex e3 e1)⊗(eq_ex e4 e2)) = true);
+ #H;
+ nrewrite < (eqex_to_eq … (andb_true_true_l … H));
+ nrewrite < (eqex_to_eq … (andb_true_true_r … H));
+ napply refl_eq.
+nqed. 
+
+nlemma eq_to_eqb8 : ∀b1,b2.b1 = b2 → eq_b8 b1 b2 = true.
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ #e1; #e2; #e3; #e4;
+ #H;
+ nrewrite < (byte8_destruct_1 … H);
+ nrewrite < (byte8_destruct_2 … H);
+ nchange with (((eq_ex e3 e3)⊗(eq_ex e4 e4)) = true);
+ nrewrite > (eq_to_eqex e3 e3 (refl_eq …));
+ nrewrite > (eq_to_eqex e4 e4 (refl_eq …)); 
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma decidable_b8_aux1 : ∀e1,e2,e3,e4.e1 ≠ e3 → 〈e1,e2〉 ≠ 〈e3,e4〉.
+ #e1; #e2; #e3; #e4;
+ nnormalize; #H; #H1;
+ napply (H (byte8_destruct_1 … H1)).
+nqed.
+
+nlemma decidable_b8_aux2 : ∀e1,e2,e3,e4.e2 ≠ e4 → 〈e1,e2〉 ≠ 〈e3,e4〉.
+ #e1; #e2; #e3; #e4;
+ nnormalize; #H; #H1;
+ napply (H (byte8_destruct_2 … H1)).
+nqed.
+
+nlemma decidable_b8 : ∀x,y:byte8.decidable (x = y).
+ #x; nelim x; #e1; #e2;
+ #y; nelim y; #e3; #e4;
+ nnormalize;
+ napply (or2_elim (e1 = e3) (e1 ≠ e3) ? (decidable_ex e1 e3) …);
+ ##[ ##2: #H; napply (or2_intro2 … (decidable_b8_aux1 e1 e2 e3 e4 H))
+ ##| ##1: #H; napply (or2_elim (e2 = e4) (e2 ≠ e4) ? (decidable_ex e2 e4) …);
+          ##[ ##2: #H1; napply (or2_intro2 … (decidable_b8_aux2 e1 e2 e3 e4 H1))
+          ##| ##1: #H1; nrewrite > H; nrewrite > H1;
+                        napply (or2_intro1 … (refl_eq ? 〈e3,e4〉))
+          ##]
+ ##]
+nqed.
+
+nlemma neqb8_to_neq : ∀b1,b2:byte8.(eq_b8 b1 b2 = false) → (b1 ≠ b2).
+ #b1; #b2;
+ nelim b1;
+ nelim b2;
+ #e1; #e2; #e3; #e4;
+ nchange with ((((eq_ex e3 e1) ⊗ (eq_ex e4 e2)) = false) → ?);
+ #H;
+ napply (or2_elim ((eq_ex e3 e1) = false) ((eq_ex e4 e2) = false) ? (andb_false2 … H) …);
+ ##[ ##1: #H1; napply (decidable_b8_aux1 … (neqex_to_neq … H1))
+ ##| ##2: #H1; napply (decidable_b8_aux2 … (neqex_to_neq … H1))
+ ##]
+nqed.
+
+nlemma byte8_destruct : ∀e1,e2,e3,e4.〈e1,e2〉 ≠ 〈e3,e4〉 → e1 ≠ e3 ∨ e2 ≠ e4.
+ #e1; #e2; #e3; #e4;
+ nnormalize; #H;
+ napply (or2_elim (e1 = e3) (e1 ≠ e3) ? (decidable_ex e1 e3) …);
+ ##[ ##2: #H1; napply (or2_intro1 … H1)
+ ##| ##1: #H1; napply (or2_elim (e2 = e4) (e2 ≠ e4) ? (decidable_ex e2 e4) …);
+          ##[ ##2: #H2; napply (or2_intro2 … H2)
+          ##| ##1: #H2; nrewrite > H1 in H:(%);
+                   nrewrite > H2;
+                   #H; nelim (H (refl_eq …))
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqb8 : ∀b1,b2.b1 ≠ b2 → eq_b8 b1 b2 = false.
+ #b1; #b2;
+ nelim b1; #e1; #e2;
+ nelim b2; #e3; #e4;
+ #H; nchange with (((eq_ex e1 e3) ⊗ (eq_ex e2 e4)) = false);
+ napply (or2_elim (e1 ≠ e3) (e2 ≠ e4) ? (byte8_destruct … H) …);
+ ##[ ##1: #H1; nrewrite > (neq_to_neqex … H1); nnormalize; napply refl_eq
+ ##| ##2: #H1; nrewrite > (neq_to_neqex … H1);
+          nrewrite > (symmetric_andbool (eq_ex e1 e3) false);
+          nnormalize; napply refl_eq
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/num/exadecim.ma b/helm/software/matita/contribs/ng_assembly/num/exadecim.ma
new file mode 100755 (executable)
index 0000000..e75c80b
--- /dev/null
@@ -0,0 +1,1427 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+include "num/quatern.ma".
+include "num/oct.ma".
+include "common/prod.ma".
+include "common/nat.ma".
+
+(* *********** *)
+(* ESADECIMALI *)
+(* *********** *)
+
+ninductive exadecim : Type ≝
+  x0: exadecim
+| x1: exadecim
+| x2: exadecim
+| x3: exadecim
+| x4: exadecim
+| x5: exadecim
+| x6: exadecim
+| x7: exadecim
+| x8: exadecim
+| x9: exadecim
+| xA: exadecim
+| xB: exadecim
+| xC: exadecim
+| xD: exadecim
+| xE: exadecim
+| xF: exadecim.
+
+(* operatore = *)
+ndefinition eq_ex ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with [ x0 ⇒ true  | _ ⇒ false ]
+  | x1 ⇒ match e2 with [ x1 ⇒ true  | _ ⇒ false ]
+  | x2 ⇒ match e2 with [ x2 ⇒ true  | _ ⇒ false ]
+  | x3 ⇒ match e2 with [ x3 ⇒ true  | _ ⇒ false ]
+  | x4 ⇒ match e2 with [ x4 ⇒ true  | _ ⇒ false ]
+  | x5 ⇒ match e2 with [ x5 ⇒ true  | _ ⇒ false ]
+  | x6 ⇒ match e2 with [ x6 ⇒ true  | _ ⇒ false ]
+  | x7 ⇒ match e2 with [ x7 ⇒ true  | _ ⇒ false ]
+  | x8 ⇒ match e2 with [ x8 ⇒ true  | _ ⇒ false ]
+  | x9 ⇒ match e2 with [ x9 ⇒ true  | _ ⇒ false ]
+  | xA ⇒ match e2 with [ xA ⇒ true  | _ ⇒ false ]
+  | xB ⇒ match e2 with [ xB ⇒ true  | _ ⇒ false ]
+  | xC ⇒ match e2 with [ xC ⇒ true  | _ ⇒ false ]
+  | xD ⇒ match e2 with [ xD ⇒ true  | _ ⇒ false ]
+  | xE ⇒ match e2 with [ xE ⇒ true  | _ ⇒ false ]
+  | xF ⇒ match e2 with [ xF ⇒ true  | _ ⇒ false ]
+  ].
+
+(* operatore < *)
+ndefinition lt_ex ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ true | x2 ⇒ true | x3 ⇒ true
+   | x4 ⇒ true  | x5 ⇒ true | x6 ⇒ true | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true | xA ⇒ true | xB ⇒ true
+   | xC ⇒ true  | xD ⇒ true | xE ⇒ true | xF ⇒ true ] 
+  | x1 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ true | x3 ⇒ true
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true | xB ⇒ true
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true | xF ⇒ true ] 
+  | x2 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ true
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x3 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x4 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+   | x4 ⇒ false | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x5 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x6 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x7 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false 
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x8 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x9 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xA ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ true
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xB ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xC ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xD ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ true  | xF ⇒ true ] 
+  | xE ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ true ] 
+  | xF ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  ].
+
+(* operatore ≤ *)
+ndefinition le_ex ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with
+   [ x0 ⇒ true | x1 ⇒ true | x2 ⇒ true | x3 ⇒ true 
+   | x4 ⇒ true | x5 ⇒ true | x6 ⇒ true | x7 ⇒ true
+   | x8 ⇒ true | x9 ⇒ true | xA ⇒ true | xB ⇒ true 
+   | xC ⇒ true | xD ⇒ true | xE ⇒ true | xF ⇒ true ] 
+  | x1 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ true | x2 ⇒ true | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true | x6 ⇒ true | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true | xA ⇒ true | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true | xE ⇒ true | xF ⇒ true ] 
+  | x2 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ true | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true | xF ⇒ true ] 
+  | x3 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x4 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x5 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x6 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x7 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ true 
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x8 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | x9 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xA ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xB ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xC ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xD ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ] 
+  | xE ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ true  | xF ⇒ true ] 
+  | xF ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ true ]
+  ].
+
+(* operatore > *)
+ndefinition gt_ex ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x1 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x2 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x3 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x4 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x5 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x6 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x7 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | x8 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | x9 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xA ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xB ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xC ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xD ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xE ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ false | xF ⇒ false ]
+  | xF ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ false ]
+  ].
+
+(* operatore ≥ *)
+ndefinition ge_ex ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x1 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ false | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x2 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ false 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x3 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x4 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x5 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x6 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x7 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | x8 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ false | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | x9 ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ false | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xA ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ false 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xB ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xC ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ false | xE ⇒ false | xF ⇒ false ]
+  | xD ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ false | xF ⇒ false ]
+  | xE ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ false ]
+  | xF ⇒ match e2 with
+   [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true 
+   | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true 
+   | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ]
+  ].
+
+(* operatore and *)
+ndefinition and_ex ≝
+λe1,e2:exadecim.match e1 with
+ [ x0 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x0 | x3 ⇒ x0 
+  | x4 ⇒ x0 | x5 ⇒ x0 | x6 ⇒ x0 | x7 ⇒ x0
+  | x8 ⇒ x0 | x9 ⇒ x0 | xA ⇒ x0 | xB ⇒ x0 
+  | xC ⇒ x0 | xD ⇒ x0 | xE ⇒ x0 | xF ⇒ x0 ]
+ | x1 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x0 | x3 ⇒ x1 
+  | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x0 | x7 ⇒ x1
+  | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x0 | xB ⇒ x1 
+  | xC ⇒ x0 | xD ⇒ x1 | xE ⇒ x0 | xF ⇒ x1 ]
+ | x2 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x2 | x3 ⇒ x2 
+  | x4 ⇒ x0 | x5 ⇒ x0 | x6 ⇒ x2 | x7 ⇒ x2
+  | x8 ⇒ x0 | x9 ⇒ x0 | xA ⇒ x2 | xB ⇒ x2 
+  | xC ⇒ x0 | xD ⇒ x0 | xE ⇒ x2 | xF ⇒ x2 ]
+ | x3 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 
+  | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x2 | x7 ⇒ x3
+  | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x2 | xB ⇒ x3 
+  | xC ⇒ x0 | xD ⇒ x1 | xE ⇒ x2 | xF ⇒ x3 ]
+ | x4 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x0 | x3 ⇒ x0 
+  | x4 ⇒ x4 | x5 ⇒ x4 | x6 ⇒ x4 | x7 ⇒ x4
+  | x8 ⇒ x0 | x9 ⇒ x0 | xA ⇒ x0 | xB ⇒ x0 
+  | xC ⇒ x4 | xD ⇒ x4 | xE ⇒ x4 | xF ⇒ x4 ]
+ | x5 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x0 | x3 ⇒ x1 
+  | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x4 | x7 ⇒ x5
+  | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x0 | xB ⇒ x1 
+  | xC ⇒ x4 | xD ⇒ x5 | xE ⇒ x4 | xF ⇒ x5 ]
+ | x6 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x2 | x3 ⇒ x2 
+  | x4 ⇒ x4 | x5 ⇒ x4 | x6 ⇒ x6 | x7 ⇒ x6
+  | x8 ⇒ x0 | x9 ⇒ x0 | xA ⇒ x2 | xB ⇒ x2 
+  | xC ⇒ x4 | xD ⇒ x4 | xE ⇒ x6 | xF ⇒ x6 ]
+ | x7 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 
+  | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+  | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x2 | xB ⇒ x3 
+  | xC ⇒ x4 | xD ⇒ x5 | xE ⇒ x6 | xF ⇒ x7 ]
+ | x8 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x0 | x3 ⇒ x0 
+  | x4 ⇒ x0 | x5 ⇒ x0 | x6 ⇒ x0 | x7 ⇒ x0
+  | x8 ⇒ x8 | x9 ⇒ x8 | xA ⇒ x8 | xB ⇒ x8 
+  | xC ⇒ x8 | xD ⇒ x8 | xE ⇒ x8 | xF ⇒ x8 ]
+ | x9 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x0 | x3 ⇒ x1 
+  | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x0 | x7 ⇒ x1
+  | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ x8 | xB ⇒ x9 
+  | xC ⇒ x8 | xD ⇒ x9 | xE ⇒ x8 | xF ⇒ x9 ]
+ | xA ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x2 | x3 ⇒ x2 
+  | x4 ⇒ x0 | x5 ⇒ x0 | x6 ⇒ x2 | x7 ⇒ x2
+  | x8 ⇒ x8 | x9 ⇒ x8 | xA ⇒ xA | xB ⇒ xA 
+  | xC ⇒ x8 | xD ⇒ x8 | xE ⇒ xA | xF ⇒ xA ]
+ | xB ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 
+  | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x2 | x7 ⇒ x3
+  | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB 
+  | xC ⇒ x8 | xD ⇒ x9 | xE ⇒ xA | xF ⇒ xB ]
+ | xC ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x0 | x3 ⇒ x0 
+  | x4 ⇒ x4 | x5 ⇒ x4 | x6 ⇒ x4 | x7 ⇒ x4
+  | x8 ⇒ x8 | x9 ⇒ x8 | xA ⇒ x8 | xB ⇒ x8 
+  | xC ⇒ xC | xD ⇒ xC | xE ⇒ xC | xF ⇒ xC ] 
+ | xD ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x0 | x3 ⇒ x1 
+  | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x4 | x7 ⇒ x5
+  | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ x8 | xB ⇒ x9 
+  | xC ⇒ xC | xD ⇒ xD | xE ⇒ xC | xF ⇒ xD ] 
+ | xE ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x0 | x2 ⇒ x2 | x3 ⇒ x2 
+  | x4 ⇒ x4 | x5 ⇒ x4 | x6 ⇒ x6 | x7 ⇒ x6
+  | x8 ⇒ x8 | x9 ⇒ x8 | xA ⇒ xA | xB ⇒ xA 
+  | xC ⇒ xC | xD ⇒ xC | xE ⇒ xE | xF ⇒ xE ] 
+ | xF ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 
+  | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+  | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB 
+  | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ]
+ ]. 
+
+(* operatore or *)
+ndefinition or_ex ≝
+λe1,e2:exadecim.match e1 with
+ [ x0 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 
+  | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+  | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB 
+  | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ]
+ | x1 ⇒ match e2 with
+  [ x0 ⇒ x1 | x1 ⇒ x1 | x2 ⇒ x3 | x3 ⇒ x3 
+  | x4 ⇒ x5 | x5 ⇒ x5 | x6 ⇒ x7 | x7 ⇒ x7
+  | x8 ⇒ x9 | x9 ⇒ x9 | xA ⇒ xB | xB ⇒ xB 
+  | xC ⇒ xD | xD ⇒ xD | xE ⇒ xF | xF ⇒ xF ]
+ | x2 ⇒ match e2 with
+  [ x0 ⇒ x2 | x1 ⇒ x3 | x2 ⇒ x2 | x3 ⇒ x3 
+  | x4 ⇒ x6 | x5 ⇒ x7 | x6 ⇒ x6 | x7 ⇒ x7
+  | x8 ⇒ xA | x9 ⇒ xB | xA ⇒ xA | xB ⇒ xB 
+  | xC ⇒ xE | xD ⇒ xF | xE ⇒ xE | xF ⇒ xF ]
+ | x3 ⇒ match e2 with
+  [ x0 ⇒ x3 | x1 ⇒ x3 | x2 ⇒ x3 | x3 ⇒ x3 
+  | x4 ⇒ x7 | x5 ⇒ x7 | x6 ⇒ x7 | x7 ⇒ x7
+  | x8 ⇒ xB | x9 ⇒ xB | xA ⇒ xB | xB ⇒ xB 
+  | xC ⇒ xF | xD ⇒ xF | xE ⇒ xF | xF ⇒ xF ]
+ | x4 ⇒ match e2 with
+  [ x0 ⇒ x4 | x1 ⇒ x5 | x2 ⇒ x6 | x3 ⇒ x7 
+  | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+  | x8 ⇒ xC | x9 ⇒ xD | xA ⇒ xE | xB ⇒ xF 
+  | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ]
+ | x5 ⇒ match e2 with
+  [ x0 ⇒ x5 | x1 ⇒ x5 | x2 ⇒ x7 | x3 ⇒ x7 
+  | x4 ⇒ x5 | x5 ⇒ x5 | x6 ⇒ x7 | x7 ⇒ x7
+  | x8 ⇒ xD | x9 ⇒ xD | xA ⇒ xF | xB ⇒ xF 
+  | xC ⇒ xD | xD ⇒ xD | xE ⇒ xF | xF ⇒ xF ]
+ | x6 ⇒ match e2 with
+  [ x0 ⇒ x6 | x1 ⇒ x7 | x2 ⇒ x6 | x3 ⇒ x7 
+  | x4 ⇒ x6 | x5 ⇒ x7 | x6 ⇒ x6 | x7 ⇒ x7
+  | x8 ⇒ xE | x9 ⇒ xF | xA ⇒ xE | xB ⇒ xF 
+  | xC ⇒ xE | xD ⇒ xF | xE ⇒ xE | xF ⇒ xF ]
+ | x7 ⇒ match e2 with
+  [ x0 ⇒ x7 | x1 ⇒ x7 | x2 ⇒ x7 | x3 ⇒ x7 
+  | x4 ⇒ x7 | x5 ⇒ x7 | x6 ⇒ x7 | x7 ⇒ x7
+  | x8 ⇒ xF | x9 ⇒ xF | xA ⇒ xF | xB ⇒ xF 
+  | xC ⇒ xF | xD ⇒ xF | xE ⇒ xF | xF ⇒ xF ]
+ | x8 ⇒ match e2 with
+  [ x0 ⇒ x8 | x1 ⇒ x9 | x2 ⇒ xA | x3 ⇒ xB 
+  | x4 ⇒ xC | x5 ⇒ xD | x6 ⇒ xE | x7 ⇒ xF
+  | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB 
+  | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ]
+ | x9 ⇒ match e2 with
+  [ x0 ⇒ x9 | x1 ⇒ x9 | x2 ⇒ xB | x3 ⇒ xB 
+  | x4 ⇒ xD | x5 ⇒ xD | x6 ⇒ xF | x7 ⇒ xF
+  | x8 ⇒ x9 | x9 ⇒ x9 | xA ⇒ xB | xB ⇒ xB 
+  | xC ⇒ xD | xD ⇒ xD | xE ⇒ xF | xF ⇒ xF ]
+ | xA ⇒ match e2 with
+  [ x0 ⇒ xA | x1 ⇒ xB | x2 ⇒ xA | x3 ⇒ xB 
+  | x4 ⇒ xE | x5 ⇒ xF | x6 ⇒ xE | x7 ⇒ xF
+  | x8 ⇒ xA | x9 ⇒ xB | xA ⇒ xA | xB ⇒ xB 
+  | xC ⇒ xE | xD ⇒ xF | xE ⇒ xE | xF ⇒ xF ]
+ | xB ⇒ match e2 with
+  [ x0 ⇒ xB | x1 ⇒ xB | x2 ⇒ xB | x3 ⇒ xB 
+  | x4 ⇒ xF | x5 ⇒ xF | x6 ⇒ xF | x7 ⇒ xF
+  | x8 ⇒ xB | x9 ⇒ xB | xA ⇒ xB | xB ⇒ xB 
+  | xC ⇒ xF | xD ⇒ xF | xE ⇒ xF | xF ⇒ xF ]
+ | xC ⇒ match e2 with
+  [ x0 ⇒ xC | x1 ⇒ xD | x2 ⇒ xE | x3 ⇒ xF 
+  | x4 ⇒ xC | x5 ⇒ xD | x6 ⇒ xE | x7 ⇒ xF
+  | x8 ⇒ xC | x9 ⇒ xD | xA ⇒ xE | xB ⇒ xF 
+  | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ]
+ | xD ⇒ match e2 with
+  [ x0 ⇒ xD | x1 ⇒ xD | x2 ⇒ xF | x3 ⇒ xF 
+  | x4 ⇒ xD | x5 ⇒ xD | x6 ⇒ xF | x7 ⇒ xF
+  | x8 ⇒ xD | x9 ⇒ xD | xA ⇒ xF | xB ⇒ xF 
+  | xC ⇒ xD | xD ⇒ xD | xE ⇒ xF | xF ⇒ xF ]
+ | xE ⇒ match e2 with
+  [ x0 ⇒ xE | x1 ⇒ xF | x2 ⇒ xE | x3 ⇒ xF 
+  | x4 ⇒ xE | x5 ⇒ xF | x6 ⇒ xE | x7 ⇒ xF
+  | x8 ⇒ xE | x9 ⇒ xF | xA ⇒ xE | xB ⇒ xF 
+  | xC ⇒ xE | xD ⇒ xF | xE ⇒ xE | xF ⇒ xF ]
+ | xF ⇒ match e2 with
+  [ x0 ⇒ xF | x1 ⇒ xF | x2 ⇒ xF | x3 ⇒ xF 
+  | x4 ⇒ xF | x5 ⇒ xF | x6 ⇒ xF | x7 ⇒ xF
+  | x8 ⇒ xF | x9 ⇒ xF | xA ⇒ xF | xB ⇒ xF 
+  | xC ⇒ xF | xD ⇒ xF | xE ⇒ xF | xF ⇒ xF ]
+ ].
+
+(* operatore xor *)
+ndefinition xor_ex ≝
+λe1,e2:exadecim.match e1 with
+ [ x0 ⇒ match e2 with
+  [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 
+  | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+  | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB 
+  | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ] 
+ | x1 ⇒ match e2 with
+  [ x0 ⇒ x1 | x1 ⇒ x0 | x2 ⇒ x3 | x3 ⇒ x2 
+  | x4 ⇒ x5 | x5 ⇒ x4 | x6 ⇒ x7 | x7 ⇒ x6
+  | x8 ⇒ x9 | x9 ⇒ x8 | xA ⇒ xB | xB ⇒ xA 
+  | xC ⇒ xD | xD ⇒ xC | xE ⇒ xF | xF ⇒ xE ] 
+ | x2 ⇒ match e2 with
+  [ x0 ⇒ x2 | x1 ⇒ x3 | x2 ⇒ x0 | x3 ⇒ x1 
+  | x4 ⇒ x6 | x5 ⇒ x7 | x6 ⇒ x4 | x7 ⇒ x5
+  | x8 ⇒ xA | x9 ⇒ xB | xA ⇒ x8 | xB ⇒ x9 
+  | xC ⇒ xE | xD ⇒ xF | xE ⇒ xC | xF ⇒ xD ] 
+ | x3 ⇒ match e2 with
+  [ x0 ⇒ x3 | x1 ⇒ x2 | x2 ⇒ x1 | x3 ⇒ x0 
+  | x4 ⇒ x7 | x5 ⇒ x6 | x6 ⇒ x5 | x7 ⇒ x4
+  | x8 ⇒ xB | x9 ⇒ xA | xA ⇒ x9 | xB ⇒ x8 
+  | xC ⇒ xF | xD ⇒ xE | xE ⇒ xD | xF ⇒ xC ] 
+ | x4 ⇒ match e2 with
+  [ x0 ⇒ x4 | x1 ⇒ x5 | x2 ⇒ x6 | x3 ⇒ x7 
+  | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x2 | x7 ⇒ x3
+  | x8 ⇒ xC | x9 ⇒ xD | xA ⇒ xE | xB ⇒ xF 
+  | xC ⇒ x8 | xD ⇒ x9 | xE ⇒ xA | xF ⇒ xB ] 
+ | x5 ⇒ match e2 with
+  [ x0 ⇒ x5 | x1 ⇒ x4 | x2 ⇒ x7 | x3 ⇒ x6 
+  | x4 ⇒ x1 | x5 ⇒ x0 | x6 ⇒ x3 | x7 ⇒ x2
+  | x8 ⇒ xD | x9 ⇒ xC | xA ⇒ xF | xB ⇒ xE 
+  | xC ⇒ x9 | xD ⇒ x8 | xE ⇒ xB | xF ⇒ xA ] 
+ | x6 ⇒ match e2 with
+  [ x0 ⇒ x6 | x1 ⇒ x7 | x2 ⇒ x4 | x3 ⇒ x5 
+  | x4 ⇒ x2 | x5 ⇒ x3 | x6 ⇒ x0 | x7 ⇒ x1
+  | x8 ⇒ xE | x9 ⇒ xF | xA ⇒ xC | xB ⇒ xD 
+  | xC ⇒ xA | xD ⇒ xB | xE ⇒ x8 | xF ⇒ x9 ] 
+ | x7 ⇒ match e2 with
+  [ x0 ⇒ x7 | x1 ⇒ x6 | x2 ⇒ x5 | x3 ⇒ x4 
+  | x4 ⇒ x3 | x5 ⇒ x2 | x6 ⇒ x1 | x7 ⇒ x0
+  | x8 ⇒ xF | x9 ⇒ xE | xA ⇒ xD | xB ⇒ xC 
+  | xC ⇒ xB | xD ⇒ xA | xE ⇒ x9 | xF ⇒ x8 ] 
+ | x8 ⇒ match e2 with
+  [ x0 ⇒ x8 | x1 ⇒ x9 | x2 ⇒ xA | x3 ⇒ xB 
+  | x4 ⇒ xC | x5 ⇒ xD | x6 ⇒ xE | x7 ⇒ xF
+  | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x2 | xB ⇒ x3 
+  | xC ⇒ x4 | xD ⇒ x5 | xE ⇒ x6 | xF ⇒ x7 ] 
+ | x9 ⇒ match e2 with
+  [ x0 ⇒ x9 | x1 ⇒ x8 | x2 ⇒ xB | x3 ⇒ xA 
+  | x4 ⇒ xD | x5 ⇒ xC | x6 ⇒ xF | x7 ⇒ xE
+  | x8 ⇒ x1 | x9 ⇒ x0 | xA ⇒ x3 | xB ⇒ x2 
+  | xC ⇒ x5 | xD ⇒ x4 | xE ⇒ x7 | xF ⇒ x6 ] 
+ | xA ⇒ match e2 with
+  [ x0 ⇒ xA | x1 ⇒ xB | x2 ⇒ x8 | x3 ⇒ x9 
+  | x4 ⇒ xE | x5 ⇒ xF | x6 ⇒ xC | x7 ⇒ xD
+  | x8 ⇒ x2 | x9 ⇒ x3 | xA ⇒ x0 | xB ⇒ x1 
+  | xC ⇒ x6 | xD ⇒ x7 | xE ⇒ x4 | xF ⇒ x5 ] 
+ | xB ⇒ match e2 with
+  [ x0 ⇒ xB | x1 ⇒ xA | x2 ⇒ x9 | x3 ⇒ x8 
+  | x4 ⇒ xF | x5 ⇒ xE | x6 ⇒ xD | x7 ⇒ xC
+  | x8 ⇒ x3 | x9 ⇒ x2 | xA ⇒ x1 | xB ⇒ x0 
+  | xC ⇒ x7 | xD ⇒ x6 | xE ⇒ x5 | xF ⇒ x4 ]
+ | xC ⇒ match e2 with
+  [ x0 ⇒ xC | x1 ⇒ xD | x2 ⇒ xE | x3 ⇒ xF 
+  | x4 ⇒ x8 | x5 ⇒ x9 | x6 ⇒ xA | x7 ⇒ xB
+  | x8 ⇒ x4 | x9 ⇒ x5 | xA ⇒ x6 | xB ⇒ x7 
+  | xC ⇒ x0 | xD ⇒ x1 | xE ⇒ x2 | xF ⇒ x3 ] 
+ | xD ⇒ match e2 with
+  [ x0 ⇒ xD | x1 ⇒ xC | x2 ⇒ xF | x3 ⇒ xE 
+  | x4 ⇒ x9 | x5 ⇒ x8 | x6 ⇒ xB | x7 ⇒ xA
+  | x8 ⇒ x5 | x9 ⇒ x4 | xA ⇒ x7 | xB ⇒ x6 
+  | xC ⇒ x1 | xD ⇒ x0 | xE ⇒ x3 | xF ⇒ x2 ]
+ | xE ⇒ match e2 with
+  [ x0 ⇒ xE | x1 ⇒ xF | x2 ⇒ xC | x3 ⇒ xD 
+  | x4 ⇒ xA | x5 ⇒ xB | x6 ⇒ x8 | x7 ⇒ x9
+  | x8 ⇒ x6 | x9 ⇒ x7 | xA ⇒ x4 | xB ⇒ x5 
+  | xC ⇒ x2 | xD ⇒ x3 | xE ⇒ x0 | xF ⇒ x1 ] 
+ | xF ⇒ match e2 with
+  [ x0 ⇒ xF | x1 ⇒ xE | x2 ⇒ xD | x3 ⇒ xC 
+  | x4 ⇒ xB | x5 ⇒ xA | x6 ⇒ x9 | x7 ⇒ x8
+  | x8 ⇒ x7 | x9 ⇒ x6 | xA ⇒ x5 | xB ⇒ x4 
+  | xC ⇒ x3 | xD ⇒ x2 | xE ⇒ x1 | xF ⇒ x0 ] 
+ ].
+
+(* operatore rotazione destra con carry *)
+ndefinition rcr_ex ≝
+λe:exadecim.λc:bool.match c with
+ [ true ⇒ match e with
+  [ x0 ⇒ pair exadecim bool x8 false | x1 ⇒ pair exadecim bool x8 true
+  | x2 ⇒ pair exadecim bool x9 false | x3 ⇒ pair exadecim bool x9 true
+  | x4 ⇒ pair exadecim bool xA false | x5 ⇒ pair exadecim bool xA true
+  | x6 ⇒ pair exadecim bool xB false | x7 ⇒ pair exadecim bool xB true
+  | x8 ⇒ pair exadecim bool xC false | x9 ⇒ pair exadecim bool xC true
+  | xA ⇒ pair exadecim bool xD false | xB ⇒ pair exadecim bool xD true
+  | xC ⇒ pair exadecim bool xE false | xD ⇒ pair exadecim bool xE true
+  | xE ⇒ pair exadecim bool xF false | xF ⇒ pair exadecim bool xF true ]
+ | false ⇒ match e with 
+  [ x0 ⇒ pair exadecim bool x0 false | x1 ⇒ pair exadecim bool x0 true
+  | x2 ⇒ pair exadecim bool x1 false | x3 ⇒ pair exadecim bool x1 true
+  | x4 ⇒ pair exadecim bool x2 false | x5 ⇒ pair exadecim bool x2 true
+  | x6 ⇒ pair exadecim bool x3 false | x7 ⇒ pair exadecim bool x3 true
+  | x8 ⇒ pair exadecim bool x4 false | x9 ⇒ pair exadecim bool x4 true
+  | xA ⇒ pair exadecim bool x5 false | xB ⇒ pair exadecim bool x5 true
+  | xC ⇒ pair exadecim bool x6 false | xD ⇒ pair exadecim bool x6 true
+  | xE ⇒ pair exadecim bool x7 false | xF ⇒ pair exadecim bool x7 true ]
+ ].
+
+(* operatore shift destro *)
+ndefinition shr_ex ≝
+λe:exadecim.match e with 
+ [ x0 ⇒ pair exadecim bool x0 false | x1 ⇒ pair exadecim bool x0 true
+ | x2 ⇒ pair exadecim bool x1 false | x3 ⇒ pair exadecim bool x1 true
+ | x4 ⇒ pair exadecim bool x2 false | x5 ⇒ pair exadecim bool x2 true
+ | x6 ⇒ pair exadecim bool x3 false | x7 ⇒ pair exadecim bool x3 true
+ | x8 ⇒ pair exadecim bool x4 false | x9 ⇒ pair exadecim bool x4 true
+ | xA ⇒ pair exadecim bool x5 false | xB ⇒ pair exadecim bool x5 true
+ | xC ⇒ pair exadecim bool x6 false | xD ⇒ pair exadecim bool x6 true
+ | xE ⇒ pair exadecim bool x7 false | xF ⇒ pair exadecim bool x7 true ].
+
+(* operatore rotazione destra *)
+ndefinition ror_ex ≝
+λe:exadecim.match e with 
+ [ x0 ⇒ x0 | x1 ⇒ x8 | x2 ⇒ x1 | x3 ⇒ x9
+ | x4 ⇒ x2 | x5 ⇒ xA | x6 ⇒ x3 | x7 ⇒ xB 
+ | x8 ⇒ x4 | x9 ⇒ xC | xA ⇒ x5 | xB ⇒ xD 
+ | xC ⇒ x6 | xD ⇒ xE | xE ⇒ x7 | xF ⇒ xF ].
+
+(* operatore rotazione destra n-volte *)
+nlet rec ror_ex_n (e:exadecim) (n:nat) on n ≝
+ match n with
+  [ O ⇒ e
+  | S n' ⇒ ror_ex_n (ror_ex e) n' ].
+
+(* operatore rotazione sinistra con carry *)
+ndefinition rcl_ex ≝
+λe:exadecim.λc:bool.match c with
+ [ true ⇒ match e with
+  [ x0 ⇒ pair exadecim bool x1 false | x1 ⇒ pair exadecim bool x3 false
+  | x2 ⇒ pair exadecim bool x5 false | x3 ⇒ pair exadecim bool x7 false
+  | x4 ⇒ pair exadecim bool x9 false | x5 ⇒ pair exadecim bool xB false
+  | x6 ⇒ pair exadecim bool xD false | x7 ⇒ pair exadecim bool xF false
+  | x8 ⇒ pair exadecim bool x1 true  | x9 ⇒ pair exadecim bool x3 true
+  | xA ⇒ pair exadecim bool x5 true  | xB ⇒ pair exadecim bool x7 true
+  | xC ⇒ pair exadecim bool x9 true  | xD ⇒ pair exadecim bool xB true
+  | xE ⇒ pair exadecim bool xD true  | xF ⇒ pair exadecim bool xF true ]
+ | false ⇒ match e with
+  [ x0 ⇒ pair exadecim bool x0 false | x1 ⇒ pair exadecim bool x2 false
+  | x2 ⇒ pair exadecim bool x4 false | x3 ⇒ pair exadecim bool x6 false
+  | x4 ⇒ pair exadecim bool x8 false | x5 ⇒ pair exadecim bool xA false
+  | x6 ⇒ pair exadecim bool xC false | x7 ⇒ pair exadecim bool xE false
+  | x8 ⇒ pair exadecim bool x0 true  | x9 ⇒ pair exadecim bool x2 true
+  | xA ⇒ pair exadecim bool x4 true  | xB ⇒ pair exadecim bool x6 true
+  | xC ⇒ pair exadecim bool x8 true  | xD ⇒ pair exadecim bool xA true
+  | xE ⇒ pair exadecim bool xC true  | xF ⇒ pair exadecim bool xE true ]
+ ].
+
+(* operatore shift sinistro *)
+ndefinition shl_ex ≝
+λe:exadecim.match e with
+ [ x0 ⇒ pair exadecim bool x0 false | x1 ⇒ pair exadecim bool x2 false
+ | x2 ⇒ pair exadecim bool x4 false | x3 ⇒ pair exadecim bool x6 false
+ | x4 ⇒ pair exadecim bool x8 false | x5 ⇒ pair exadecim bool xA false
+ | x6 ⇒ pair exadecim bool xC false | x7 ⇒ pair exadecim bool xE false
+ | x8 ⇒ pair exadecim bool x0 true  | x9 ⇒ pair exadecim bool x2 true
+ | xA ⇒ pair exadecim bool x4 true  | xB ⇒ pair exadecim bool x6 true
+ | xC ⇒ pair exadecim bool x8 true  | xD ⇒ pair exadecim bool xA true
+ | xE ⇒ pair exadecim bool xC true  | xF ⇒ pair exadecim bool xE true ].
+
+(* operatore rotazione sinistra *)
+ndefinition rol_ex ≝
+λe:exadecim.match e with
+ [ x0 ⇒ x0 | x1 ⇒ x2 | x2 ⇒ x4 | x3 ⇒ x6
+ | x4 ⇒ x8 | x5 ⇒ xA | x6 ⇒ xC | x7 ⇒ xE
+ | x8 ⇒ x1 | x9 ⇒ x3 | xA ⇒ x5 | xB ⇒ x7
+ | xC ⇒ x9 | xD ⇒ xB | xE ⇒ xD | xF ⇒ xF ].
+
+(* operatore rotazione sinistra n-volte *)
+nlet rec rol_ex_n (e:exadecim) (n:nat) on n ≝
+ match n with
+  [ O ⇒ e
+  | S n' ⇒ rol_ex_n (rol_ex e) n' ].
+
+(* operatore not/complemento a 1 *)
+ndefinition not_ex ≝
+λe:exadecim.match e with
+ [ x0 ⇒ xF | x1 ⇒ xE | x2 ⇒ xD | x3 ⇒ xC
+ | x4 ⇒ xB | x5 ⇒ xA | x6 ⇒ x9 | x7 ⇒ x8
+ | x8 ⇒ x7 | x9 ⇒ x6 | xA ⇒ x5 | xB ⇒ x4
+ | xC ⇒ x3 | xD ⇒ x2 | xE ⇒ x1 | xF ⇒ x0 ].
+
+(* operatore somma con data+carry → data+carry *)
+ndefinition plus_ex_dc_dc ≝
+λe1,e2:exadecim.λc:bool.
+ match c with
+  [ true ⇒ match e1 with
+   [ x0 ⇒ match e2 with
+    [ x0 ⇒ pair … x1 false | x1 ⇒ pair … x2 false | x2 ⇒ pair … x3 false | x3 ⇒ pair … x4 false
+    | x4 ⇒ pair … x5 false | x5 ⇒ pair … x6 false | x6 ⇒ pair … x7 false | x7 ⇒ pair … x8 false
+    | x8 ⇒ pair … x9 false | x9 ⇒ pair … xA false | xA ⇒ pair … xB false | xB ⇒ pair … xC false
+    | xC ⇒ pair … xD false | xD ⇒ pair … xE false | xE ⇒ pair … xF false | xF ⇒ pair … x0 true ] 
+   | x1 ⇒ match e2 with
+    [ x0 ⇒ pair … x2 false | x1 ⇒ pair … x3 false | x2 ⇒ pair … x4 false | x3 ⇒ pair … x5 false
+    | x4 ⇒ pair … x6 false | x5 ⇒ pair … x7 false | x6 ⇒ pair … x8 false | x7 ⇒ pair … x9 false
+    | x8 ⇒ pair … xA false | x9 ⇒ pair … xB false | xA ⇒ pair … xC false | xB ⇒ pair … xD false
+    | xC ⇒ pair … xE false | xD ⇒ pair … xF false | xE ⇒ pair … x0 true  | xF ⇒ pair … x1 true ] 
+   | x2 ⇒ match e2 with
+    [ x0 ⇒ pair … x3 false | x1 ⇒ pair … x4 false | x2 ⇒ pair … x5 false | x3 ⇒ pair … x6 false
+    | x4 ⇒ pair … x7 false | x5 ⇒ pair … x8 false | x6 ⇒ pair … x9 false | x7 ⇒ pair … xA false
+    | x8 ⇒ pair … xB false | x9 ⇒ pair … xC false | xA ⇒ pair … xD false | xB ⇒ pair … xE false
+    | xC ⇒ pair … xF false | xD ⇒ pair … x0 true  | xE ⇒ pair … x1 true  | xF ⇒ pair … x2 true ] 
+   | x3 ⇒ match e2 with
+    [ x0 ⇒ pair … x4 false | x1 ⇒ pair … x5 false | x2 ⇒ pair … x6 false | x3 ⇒ pair … x7 false
+    | x4 ⇒ pair … x8 false | x5 ⇒ pair … x9 false | x6 ⇒ pair … xA false | x7 ⇒ pair … xB false
+    | x8 ⇒ pair … xC false | x9 ⇒ pair … xD false | xA ⇒ pair … xE false | xB ⇒ pair … xF false
+    | xC ⇒ pair … x0 true  | xD ⇒ pair … x1 true  | xE ⇒ pair … x2 true  | xF ⇒ pair … x3 true ] 
+   | x4 ⇒ match e2 with
+    [ x0 ⇒ pair … x5 false | x1 ⇒ pair … x6 false | x2 ⇒ pair … x7 false | x3 ⇒ pair … x8 false
+    | x4 ⇒ pair … x9 false | x5 ⇒ pair … xA false | x6 ⇒ pair … xB false | x7 ⇒ pair … xC false
+    | x8 ⇒ pair … xD false | x9 ⇒ pair … xE false | xA ⇒ pair … xF false | xB ⇒ pair … x0 true
+    | xC ⇒ pair … x1 true  | xD ⇒ pair … x2 true  | xE ⇒ pair … x3 true  | xF ⇒ pair … x4 true ] 
+   | x5 ⇒ match e2 with
+    [ x0 ⇒ pair … x6 false | x1 ⇒ pair … x7 false | x2 ⇒ pair … x8 false | x3 ⇒ pair … x9 false
+    | x4 ⇒ pair … xA false | x5 ⇒ pair … xB false | x6 ⇒ pair … xC false | x7 ⇒ pair … xD false
+    | x8 ⇒ pair … xE false | x9 ⇒ pair … xF false | xA ⇒ pair … x0 true  | xB ⇒ pair … x1 true
+    | xC ⇒ pair … x2 true  | xD ⇒ pair … x3 true  | xE ⇒ pair … x4 true  | xF ⇒ pair … x5 true ] 
+   | x6 ⇒ match e2 with
+    [ x0 ⇒ pair … x7 false | x1 ⇒ pair … x8 false | x2 ⇒ pair … x9 false | x3 ⇒ pair … xA false
+    | x4 ⇒ pair … xB false | x5 ⇒ pair … xC false | x6 ⇒ pair … xD false | x7 ⇒ pair … xE false
+    | x8 ⇒ pair … xF false | x9 ⇒ pair … x0 true  | xA ⇒ pair … x1 true  | xB ⇒ pair … x2 true
+    | xC ⇒ pair … x3 true  | xD ⇒ pair … x4 true  | xE ⇒ pair … x5 true  | xF ⇒ pair … x6 true ] 
+   | x7 ⇒ match e2 with
+    [ x0 ⇒ pair … x8 false | x1 ⇒ pair … x9 false | x2 ⇒ pair … xA false | x3 ⇒ pair … xB false
+    | x4 ⇒ pair … xC false | x5 ⇒ pair … xD false | x6 ⇒ pair … xE false | x7 ⇒ pair … xF false
+    | x8 ⇒ pair … x0 true  | x9 ⇒ pair … x1 true  | xA ⇒ pair … x2 true  | xB ⇒ pair … x3 true
+    | xC ⇒ pair … x4 true  | xD ⇒ pair … x5 true  | xE ⇒ pair … x6 true  | xF ⇒ pair … x7 true ] 
+   | x8 ⇒ match e2 with
+    [ x0 ⇒ pair … x9 false | x1 ⇒ pair … xA false | x2 ⇒ pair … xB false | x3 ⇒ pair … xC false
+    | x4 ⇒ pair … xD false | x5 ⇒ pair … xE false | x6 ⇒ pair … xF false | x7 ⇒ pair … x0 true
+    | x8 ⇒ pair … x1 true  | x9 ⇒ pair … x2 true  | xA ⇒ pair … x3 true  | xB ⇒ pair … x4 true
+    | xC ⇒ pair … x5 true  | xD ⇒ pair … x6 true  | xE ⇒ pair … x7 true  | xF ⇒ pair … x8 true ] 
+   | x9 ⇒ match e2 with
+    [ x0 ⇒ pair … xA false | x1 ⇒ pair … xB false | x2 ⇒ pair … xC false | x3 ⇒ pair … xD false
+    | x4 ⇒ pair … xE false | x5 ⇒ pair … xF false | x6 ⇒ pair … x0 true  | x7 ⇒ pair … x1 true
+    | x8 ⇒ pair … x2 true  | x9 ⇒ pair … x3 true  | xA ⇒ pair … x4 true  | xB ⇒ pair … x5 true
+    | xC ⇒ pair … x6 true  | xD ⇒ pair … x7 true  | xE ⇒ pair … x8 true  | xF ⇒ pair … x9 true ] 
+   | xA ⇒ match e2 with
+    [ x0 ⇒ pair … xB false | x1 ⇒ pair … xC false | x2 ⇒ pair … xD false | x3 ⇒ pair … xE false
+    | x4 ⇒ pair … xF false | x5 ⇒ pair … x0 true  | x6 ⇒ pair … x1 true  | x7 ⇒ pair … x2 true
+    | x8 ⇒ pair … x3 true  | x9 ⇒ pair … x4 true  | xA ⇒ pair … x5 true  | xB ⇒ pair … x6 true
+    | xC ⇒ pair … x7 true  | xD ⇒ pair … x8 true  | xE ⇒ pair … x9 true  | xF ⇒ pair … xA true ] 
+   | xB ⇒ match e2 with
+    [ x0 ⇒ pair … xC false | x1 ⇒ pair … xD false | x2 ⇒ pair … xE false | x3 ⇒ pair … xF false
+    | x4 ⇒ pair … x0 true  | x5 ⇒ pair … x1 true  | x6 ⇒ pair … x2 true  | x7 ⇒ pair … x3 true
+    | x8 ⇒ pair … x4 true  | x9 ⇒ pair … x5 true  | xA ⇒ pair … x6 true  | xB ⇒ pair … x7 true
+    | xC ⇒ pair … x8 true  | xD ⇒ pair … x9 true  | xE ⇒ pair … xA true  | xF ⇒ pair … xB true ] 
+   | xC ⇒ match e2 with
+    [ x0 ⇒ pair … xD false | x1 ⇒ pair … xE false | x2 ⇒ pair … xF false | x3 ⇒ pair … x0 true
+    | x4 ⇒ pair … x1 true  | x5 ⇒ pair … x2 true  | x6 ⇒ pair … x3 true  | x7 ⇒ pair … x4 true
+    | x8 ⇒ pair … x5 true  | x9 ⇒ pair … x6 true  | xA ⇒ pair … x7 true  | xB ⇒ pair … x8 true
+    | xC ⇒ pair … x9 true  | xD ⇒ pair … xA true  | xE ⇒ pair … xB true  | xF ⇒ pair … xC true ] 
+   | xD ⇒ match e2 with
+    [ x0 ⇒ pair … xE false | x1 ⇒ pair … xF false | x2 ⇒ pair … x0 true  | x3 ⇒ pair … x1 true
+    | x4 ⇒ pair … x2 true  | x5 ⇒ pair … x3 true  | x6 ⇒ pair … x4 true  | x7 ⇒ pair … x5 true
+    | x8 ⇒ pair … x6 true  | x9 ⇒ pair … x7 true  | xA ⇒ pair … x8 true  | xB ⇒ pair … x9 true
+    | xC ⇒ pair … xA true  | xD ⇒ pair … xB true  | xE ⇒ pair … xC true  | xF ⇒ pair … xD true ] 
+   | xE ⇒ match e2 with
+    [ x0 ⇒ pair … xF false | x1 ⇒ pair … x0 true  | x2 ⇒ pair … x1 true  | x3 ⇒ pair … x2 true
+    | x4 ⇒ pair … x3 true  | x5 ⇒ pair … x4 true  | x6 ⇒ pair … x5 true  | x7 ⇒ pair … x6 true
+    | x8 ⇒ pair … x7 true  | x9 ⇒ pair … x8 true  | xA ⇒ pair … x9 true  | xB ⇒ pair … xA true
+    | xC ⇒ pair … xB true  | xD ⇒ pair … xC true  | xE ⇒ pair … xD true  | xF ⇒ pair … xE true ]
+   | xF ⇒ match e2 with
+    [ x0 ⇒ pair … x0 true  | x1 ⇒ pair … x1 true  | x2 ⇒ pair … x2 true  | x3 ⇒ pair … x3 true
+    | x4 ⇒ pair … x4 true  | x5 ⇒ pair … x5 true  | x6 ⇒ pair … x6 true  | x7 ⇒ pair … x7 true
+    | x8 ⇒ pair … x8 true  | x9 ⇒ pair … x9 true  | xA ⇒ pair … xA true  | xB ⇒ pair … xB true
+    | xC ⇒ pair … xC true  | xD ⇒ pair … xD true  | xE ⇒ pair … xE true  | xF ⇒ pair … xF true ] 
+   ]
+  | false ⇒ match e1 with
+   [ x0 ⇒ match e2 with
+    [ x0 ⇒ pair … x0 false | x1 ⇒ pair … x1 false | x2 ⇒ pair … x2 false | x3 ⇒ pair … x3 false
+    | x4 ⇒ pair … x4 false | x5 ⇒ pair … x5 false | x6 ⇒ pair … x6 false | x7 ⇒ pair … x7 false
+    | x8 ⇒ pair … x8 false | x9 ⇒ pair … x9 false | xA ⇒ pair … xA false | xB ⇒ pair … xB false
+    | xC ⇒ pair … xC false | xD ⇒ pair … xD false | xE ⇒ pair … xE false | xF ⇒ pair … xF false ] 
+   | x1 ⇒ match e2 with
+    [ x0 ⇒ pair … x1 false | x1 ⇒ pair … x2 false | x2 ⇒ pair … x3 false | x3 ⇒ pair … x4 false
+    | x4 ⇒ pair … x5 false | x5 ⇒ pair … x6 false | x6 ⇒ pair … x7 false | x7 ⇒ pair … x8 false
+    | x8 ⇒ pair … x9 false | x9 ⇒ pair … xA false | xA ⇒ pair … xB false | xB ⇒ pair … xC false
+    | xC ⇒ pair … xD false | xD ⇒ pair … xE false | xE ⇒ pair … xF false | xF ⇒ pair … x0 true ] 
+   | x2 ⇒ match e2 with
+    [ x0 ⇒ pair … x2 false | x1 ⇒ pair … x3 false | x2 ⇒ pair … x4 false | x3 ⇒ pair … x5 false
+    | x4 ⇒ pair … x6 false | x5 ⇒ pair … x7 false | x6 ⇒ pair … x8 false | x7 ⇒ pair … x9 false
+    | x8 ⇒ pair … xA false | x9 ⇒ pair … xB false | xA ⇒ pair … xC false | xB ⇒ pair … xD false
+    | xC ⇒ pair … xE false | xD ⇒ pair … xF false | xE ⇒ pair … x0 true  | xF ⇒ pair … x1 true ] 
+   | x3 ⇒ match e2 with
+    [ x0 ⇒ pair … x3 false | x1 ⇒ pair … x4 false | x2 ⇒ pair … x5 false | x3 ⇒ pair … x6 false
+    | x4 ⇒ pair … x7 false | x5 ⇒ pair … x8 false | x6 ⇒ pair … x9 false | x7 ⇒ pair … xA false
+    | x8 ⇒ pair … xB false | x9 ⇒ pair … xC false | xA ⇒ pair … xD false | xB ⇒ pair … xE false
+    | xC ⇒ pair … xF false | xD ⇒ pair … x0 true  | xE ⇒ pair … x1 true  | xF ⇒ pair … x2 true ] 
+   | x4 ⇒ match e2 with
+    [ x0 ⇒ pair … x4 false | x1 ⇒ pair … x5 false | x2 ⇒ pair … x6 false | x3 ⇒ pair … x7 false
+    | x4 ⇒ pair … x8 false | x5 ⇒ pair … x9 false | x6 ⇒ pair … xA false | x7 ⇒ pair … xB false
+    | x8 ⇒ pair … xC false | x9 ⇒ pair … xD false | xA ⇒ pair … xE false | xB ⇒ pair … xF false
+    | xC ⇒ pair … x0 true  | xD ⇒ pair … x1 true  | xE ⇒ pair … x2 true  | xF ⇒ pair … x3 true ] 
+   | x5 ⇒ match e2 with
+    [ x0 ⇒ pair … x5 false | x1 ⇒ pair … x6 false | x2 ⇒ pair … x7 false | x3 ⇒ pair … x8 false
+    | x4 ⇒ pair … x9 false | x5 ⇒ pair … xA false | x6 ⇒ pair … xB false | x7 ⇒ pair … xC false
+    | x8 ⇒ pair … xD false | x9 ⇒ pair … xE false | xA ⇒ pair … xF false | xB ⇒ pair … x0 true
+    | xC ⇒ pair … x1 true  | xD ⇒ pair … x2 true  | xE ⇒ pair … x3 true  | xF ⇒ pair … x4 true ] 
+   | x6 ⇒ match e2 with
+    [ x0 ⇒ pair … x6 false | x1 ⇒ pair … x7 false | x2 ⇒ pair … x8 false | x3 ⇒ pair … x9 false
+    | x4 ⇒ pair … xA false | x5 ⇒ pair … xB false | x6 ⇒ pair … xC false | x7 ⇒ pair … xD false
+    | x8 ⇒ pair … xE false | x9 ⇒ pair … xF false | xA ⇒ pair … x0 true  | xB ⇒ pair … x1 true
+    | xC ⇒ pair … x2 true  | xD ⇒ pair … x3 true  | xE ⇒ pair … x4 true  | xF ⇒ pair … x5 true ] 
+   | x7 ⇒ match e2 with
+    [ x0 ⇒ pair … x7 false | x1 ⇒ pair … x8 false | x2 ⇒ pair … x9 false | x3 ⇒ pair … xA false
+    | x4 ⇒ pair … xB false | x5 ⇒ pair … xC false | x6 ⇒ pair … xD false | x7 ⇒ pair … xE false
+    | x8 ⇒ pair … xF false | x9 ⇒ pair … x0 true  | xA ⇒ pair … x1 true  | xB ⇒ pair … x2 true
+    | xC ⇒ pair … x3 true  | xD ⇒ pair … x4 true  | xE ⇒ pair … x5 true  | xF ⇒ pair … x6 true ] 
+   | x8 ⇒ match e2 with
+    [ x0 ⇒ pair … x8 false | x1 ⇒ pair … x9 false | x2 ⇒ pair … xA false | x3 ⇒ pair … xB false
+    | x4 ⇒ pair … xC false | x5 ⇒ pair … xD false | x6 ⇒ pair … xE false | x7 ⇒ pair … xF false
+    | x8 ⇒ pair … x0 true  | x9 ⇒ pair … x1 true  | xA ⇒ pair … x2 true  | xB ⇒ pair … x3 true
+    | xC ⇒ pair … x4 true  | xD ⇒ pair … x5 true  | xE ⇒ pair … x6 true  | xF ⇒ pair … x7 true ] 
+   | x9 ⇒ match e2 with
+    [ x0 ⇒ pair … x9 false | x1 ⇒ pair … xA false | x2 ⇒ pair … xB false | x3 ⇒ pair … xC false
+    | x4 ⇒ pair … xD false | x5 ⇒ pair … xE false | x6 ⇒ pair … xF false | x7 ⇒ pair … x0 true
+    | x8 ⇒ pair … x1 true  | x9 ⇒ pair … x2 true  | xA ⇒ pair … x3 true  | xB ⇒ pair … x4 true
+    | xC ⇒ pair … x5 true  | xD ⇒ pair … x6 true  | xE ⇒ pair … x7 true  | xF ⇒ pair … x8 true ] 
+   | xA ⇒ match e2 with
+    [ x0 ⇒ pair … xA false | x1 ⇒ pair … xB false | x2 ⇒ pair … xC false | x3 ⇒ pair … xD false
+    | x4 ⇒ pair … xE false | x5 ⇒ pair … xF false | x6 ⇒ pair … x0 true  | x7 ⇒ pair … x1 true
+    | x8 ⇒ pair … x2 true  | x9 ⇒ pair … x3 true  | xA ⇒ pair … x4 true  | xB ⇒ pair … x5 true
+    | xC ⇒ pair … x6 true  | xD ⇒ pair … x7 true  | xE ⇒ pair … x8 true  | xF ⇒ pair … x9 true ] 
+   | xB ⇒ match e2 with
+    [ x0 ⇒ pair … xB false | x1 ⇒ pair … xC false | x2 ⇒ pair … xD false | x3 ⇒ pair … xE false
+    | x4 ⇒ pair … xF false | x5 ⇒ pair … x0 true  | x6 ⇒ pair … x1 true  | x7 ⇒ pair … x2 true
+    | x8 ⇒ pair … x3 true  | x9 ⇒ pair … x4 true  | xA ⇒ pair … x5 true  | xB ⇒ pair … x6 true
+    | xC ⇒ pair … x7 true  | xD ⇒ pair … x8 true  | xE ⇒ pair … x9 true  | xF ⇒ pair … xA true ] 
+   | xC ⇒ match e2 with
+    [ x0 ⇒ pair … xC false | x1 ⇒ pair … xD false | x2 ⇒ pair … xE false | x3 ⇒ pair … xF false
+    | x4 ⇒ pair … x0 true  | x5 ⇒ pair … x1 true  | x6 ⇒ pair … x2 true  | x7 ⇒ pair … x3 true
+    | x8 ⇒ pair … x4 true  | x9 ⇒ pair … x5 true  | xA ⇒ pair … x6 true  | xB ⇒ pair … x7 true
+    | xC ⇒ pair … x8 true  | xD ⇒ pair … x9 true  | xE ⇒ pair … xA true  | xF ⇒ pair … xB true ] 
+   | xD ⇒ match e2 with
+    [ x0 ⇒ pair … xD false | x1 ⇒ pair … xE false | x2 ⇒ pair … xF false | x3 ⇒ pair … x0 true
+    | x4 ⇒ pair … x1 true  | x5 ⇒ pair … x2 true  | x6 ⇒ pair … x3 true  | x7 ⇒ pair … x4 true
+    | x8 ⇒ pair … x5 true  | x9 ⇒ pair … x6 true  | xA ⇒ pair … x7 true  | xB ⇒ pair … x8 true
+    | xC ⇒ pair … x9 true  | xD ⇒ pair … xA true  | xE ⇒ pair … xB true  | xF ⇒ pair … xC true ] 
+   | xE ⇒ match e2 with
+    [ x0 ⇒ pair … xE false | x1 ⇒ pair … xF false | x2 ⇒ pair … x0 true  | x3 ⇒ pair … x1 true
+    | x4 ⇒ pair … x2 true  | x5 ⇒ pair … x3 true  | x6 ⇒ pair … x4 true  | x7 ⇒ pair … x5 true
+    | x8 ⇒ pair … x6 true  | x9 ⇒ pair … x7 true  | xA ⇒ pair … x8 true  | xB ⇒ pair … x9 true
+    | xC ⇒ pair … xA true  | xD ⇒ pair … xB true  | xE ⇒ pair … xC true  | xF ⇒ pair … xD true ] 
+   | xF ⇒ match e2 with
+    [ x0 ⇒ pair … xF false | x1 ⇒ pair … x0 true  | x2 ⇒ pair … x1 true  | x3 ⇒ pair … x2 true
+    | x4 ⇒ pair … x3 true  | x5 ⇒ pair … x4 true  | x6 ⇒ pair … x5 true  | x7 ⇒ pair … x6 true
+    | x8 ⇒ pair … x7 true  | x9 ⇒ pair … x8 true  | xA ⇒ pair … x9 true  | xB ⇒ pair … xA true
+    | xC ⇒ pair … xB true  | xD ⇒ pair … xC true  | xE ⇒ pair … xD true  | xF ⇒ pair … xE true ]
+   ]].
+
+(* operatore somma con data → data+carry *)
+ndefinition plus_ex_d_dc ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with
+   [ x0 ⇒ pair … x0 false | x1 ⇒ pair … x1 false | x2 ⇒ pair … x2 false | x3 ⇒ pair … x3 false
+   | x4 ⇒ pair … x4 false | x5 ⇒ pair … x5 false | x6 ⇒ pair … x6 false | x7 ⇒ pair … x7 false
+   | x8 ⇒ pair … x8 false | x9 ⇒ pair … x9 false | xA ⇒ pair … xA false | xB ⇒ pair … xB false
+   | xC ⇒ pair … xC false | xD ⇒ pair … xD false | xE ⇒ pair … xE false | xF ⇒ pair … xF false ]  
+  | x1 ⇒ match e2 with
+   [ x0 ⇒ pair … x1 false | x1 ⇒ pair … x2 false | x2 ⇒ pair … x3 false | x3 ⇒ pair … x4 false
+   | x4 ⇒ pair … x5 false | x5 ⇒ pair … x6 false | x6 ⇒ pair … x7 false | x7 ⇒ pair … x8 false
+   | x8 ⇒ pair … x9 false | x9 ⇒ pair … xA false | xA ⇒ pair … xB false | xB ⇒ pair … xC false
+   | xC ⇒ pair … xD false | xD ⇒ pair … xE false | xE ⇒ pair … xF false | xF ⇒ pair … x0 true ] 
+  | x2 ⇒ match e2 with
+   [ x0 ⇒ pair … x2 false | x1 ⇒ pair … x3 false | x2 ⇒ pair … x4 false | x3 ⇒ pair … x5 false
+   | x4 ⇒ pair … x6 false | x5 ⇒ pair … x7 false | x6 ⇒ pair … x8 false | x7 ⇒ pair … x9 false
+   | x8 ⇒ pair … xA false | x9 ⇒ pair … xB false | xA ⇒ pair … xC false | xB ⇒ pair … xD false
+   | xC ⇒ pair … xE false | xD ⇒ pair … xF false | xE ⇒ pair … x0 true  | xF ⇒ pair … x1 true ] 
+  | x3 ⇒ match e2 with
+   [ x0 ⇒ pair … x3 false | x1 ⇒ pair … x4 false | x2 ⇒ pair … x5 false | x3 ⇒ pair … x6 false
+   | x4 ⇒ pair … x7 false | x5 ⇒ pair … x8 false | x6 ⇒ pair … x9 false | x7 ⇒ pair … xA false
+   | x8 ⇒ pair … xB false | x9 ⇒ pair … xC false | xA ⇒ pair … xD false | xB ⇒ pair … xE false
+   | xC ⇒ pair … xF false | xD ⇒ pair … x0 true  | xE ⇒ pair … x1 true  | xF ⇒ pair … x2 true ] 
+  | x4 ⇒ match e2 with
+   [ x0 ⇒ pair … x4 false | x1 ⇒ pair … x5 false | x2 ⇒ pair … x6 false | x3 ⇒ pair … x7 false
+   | x4 ⇒ pair … x8 false | x5 ⇒ pair … x9 false | x6 ⇒ pair … xA false | x7 ⇒ pair … xB false
+   | x8 ⇒ pair … xC false | x9 ⇒ pair … xD false | xA ⇒ pair … xE false | xB ⇒ pair … xF false
+   | xC ⇒ pair … x0 true  | xD ⇒ pair … x1 true  | xE ⇒ pair … x2 true  | xF ⇒ pair … x3 true ] 
+  | x5 ⇒ match e2 with
+   [ x0 ⇒ pair … x5 false | x1 ⇒ pair … x6 false | x2 ⇒ pair … x7 false | x3 ⇒ pair … x8 false
+   | x4 ⇒ pair … x9 false | x5 ⇒ pair … xA false | x6 ⇒ pair … xB false | x7 ⇒ pair … xC false
+   | x8 ⇒ pair … xD false | x9 ⇒ pair … xE false | xA ⇒ pair … xF false | xB ⇒ pair … x0 true
+   | xC ⇒ pair … x1 true  | xD ⇒ pair … x2 true  | xE ⇒ pair … x3 true  | xF ⇒ pair … x4 true ] 
+  | x6 ⇒ match e2 with
+   [ x0 ⇒ pair … x6 false | x1 ⇒ pair … x7 false | x2 ⇒ pair … x8 false | x3 ⇒ pair … x9 false
+   | x4 ⇒ pair … xA false | x5 ⇒ pair … xB false | x6 ⇒ pair … xC false | x7 ⇒ pair … xD false
+   | x8 ⇒ pair … xE false | x9 ⇒ pair … xF false | xA ⇒ pair … x0 true  | xB ⇒ pair … x1 true
+   | xC ⇒ pair … x2 true  | xD ⇒ pair … x3 true  | xE ⇒ pair … x4 true  | xF ⇒ pair … x5 true ] 
+  | x7 ⇒ match e2 with
+   [ x0 ⇒ pair … x7 false | x1 ⇒ pair … x8 false | x2 ⇒ pair … x9 false | x3 ⇒ pair … xA false
+   | x4 ⇒ pair … xB false | x5 ⇒ pair … xC false | x6 ⇒ pair … xD false | x7 ⇒ pair … xE false
+   | x8 ⇒ pair … xF false | x9 ⇒ pair … x0 true  | xA ⇒ pair … x1 true  | xB ⇒ pair … x2 true
+   | xC ⇒ pair … x3 true  | xD ⇒ pair … x4 true  | xE ⇒ pair … x5 true  | xF ⇒ pair … x6 true ] 
+  | x8 ⇒ match e2 with
+   [ x0 ⇒ pair … x8 false | x1 ⇒ pair … x9 false | x2 ⇒ pair … xA false | x3 ⇒ pair … xB false
+   | x4 ⇒ pair … xC false | x5 ⇒ pair … xD false | x6 ⇒ pair … xE false | x7 ⇒ pair … xF false
+   | x8 ⇒ pair … x0 true  | x9 ⇒ pair … x1 true  | xA ⇒ pair … x2 true  | xB ⇒ pair … x3 true
+   | xC ⇒ pair … x4 true  | xD ⇒ pair … x5 true  | xE ⇒ pair … x6 true  | xF ⇒ pair … x7 true ] 
+  | x9 ⇒ match e2 with
+   [ x0 ⇒ pair … x9 false | x1 ⇒ pair … xA false | x2 ⇒ pair … xB false | x3 ⇒ pair … xC false
+   | x4 ⇒ pair … xD false | x5 ⇒ pair … xE false | x6 ⇒ pair … xF false | x7 ⇒ pair … x0 true
+   | x8 ⇒ pair … x1 true  | x9 ⇒ pair … x2 true  | xA ⇒ pair … x3 true  | xB ⇒ pair … x4 true
+   | xC ⇒ pair … x5 true  | xD ⇒ pair … x6 true  | xE ⇒ pair … x7 true  | xF ⇒ pair … x8 true ] 
+  | xA ⇒ match e2 with
+   [ x0 ⇒ pair … xA false | x1 ⇒ pair … xB false | x2 ⇒ pair … xC false | x3 ⇒ pair … xD false
+   | x4 ⇒ pair … xE false | x5 ⇒ pair … xF false | x6 ⇒ pair … x0 true  | x7 ⇒ pair … x1 true
+   | x8 ⇒ pair … x2 true  | x9 ⇒ pair … x3 true  | xA ⇒ pair … x4 true  | xB ⇒ pair … x5 true
+   | xC ⇒ pair … x6 true  | xD ⇒ pair … x7 true  | xE ⇒ pair … x8 true  | xF ⇒ pair … x9 true ] 
+  | xB ⇒ match e2 with
+   [ x0 ⇒ pair … xB false | x1 ⇒ pair … xC false | x2 ⇒ pair … xD false | x3 ⇒ pair … xE false
+   | x4 ⇒ pair … xF false | x5 ⇒ pair … x0 true  | x6 ⇒ pair … x1 true  | x7 ⇒ pair … x2 true
+   | x8 ⇒ pair … x3 true  | x9 ⇒ pair … x4 true  | xA ⇒ pair … x5 true  | xB ⇒ pair … x6 true
+   | xC ⇒ pair … x7 true  | xD ⇒ pair … x8 true  | xE ⇒ pair … x9 true  | xF ⇒ pair … xA true ] 
+  | xC ⇒ match e2 with
+   [ x0 ⇒ pair … xC false | x1 ⇒ pair … xD false | x2 ⇒ pair … xE false | x3 ⇒ pair … xF false
+   | x4 ⇒ pair … x0 true  | x5 ⇒ pair … x1 true  | x6 ⇒ pair … x2 true  | x7 ⇒ pair … x3 true
+   | x8 ⇒ pair … x4 true  | x9 ⇒ pair … x5 true  | xA ⇒ pair … x6 true  | xB ⇒ pair … x7 true
+   | xC ⇒ pair … x8 true  | xD ⇒ pair … x9 true  | xE ⇒ pair … xA true  | xF ⇒ pair … xB true ] 
+  | xD ⇒ match e2 with
+   [ x0 ⇒ pair … xD false | x1 ⇒ pair … xE false | x2 ⇒ pair … xF false | x3 ⇒ pair … x0 true
+   | x4 ⇒ pair … x1 true  | x5 ⇒ pair … x2 true  | x6 ⇒ pair … x3 true  | x7 ⇒ pair … x4 true
+   | x8 ⇒ pair … x5 true  | x9 ⇒ pair … x6 true  | xA ⇒ pair … x7 true  | xB ⇒ pair … x8 true
+   | xC ⇒ pair … x9 true  | xD ⇒ pair … xA true  | xE ⇒ pair … xB true  | xF ⇒ pair … xC true ] 
+  | xE ⇒ match e2 with
+   [ x0 ⇒ pair … xE false | x1 ⇒ pair … xF false | x2 ⇒ pair … x0 true  | x3 ⇒ pair … x1 true
+   | x4 ⇒ pair … x2 true  | x5 ⇒ pair … x3 true  | x6 ⇒ pair … x4 true  | x7 ⇒ pair … x5 true
+   | x8 ⇒ pair … x6 true  | x9 ⇒ pair … x7 true  | xA ⇒ pair … x8 true  | xB ⇒ pair … x9 true
+   | xC ⇒ pair … xA true  | xD ⇒ pair … xB true  | xE ⇒ pair … xC true  | xF ⇒ pair … xD true ] 
+  | xF ⇒ match e2 with
+   [ x0 ⇒ pair … xF false | x1 ⇒ pair … x0 true  | x2 ⇒ pair … x1 true  | x3 ⇒ pair … x2 true
+   | x4 ⇒ pair … x3 true  | x5 ⇒ pair … x4 true  | x6 ⇒ pair … x5 true  | x7 ⇒ pair … x6 true
+   | x8 ⇒ pair … x7 true  | x9 ⇒ pair … x8 true  | xA ⇒ pair … x9 true  | xB ⇒ pair … xA true
+   | xC ⇒ pair … xB true  | xD ⇒ pair … xC true  | xE ⇒ pair … xD true  | xF ⇒ pair … xE true ]
+  ].
+
+(* operatore somma con data+carry → data *)
+ndefinition plus_ex_dc_d ≝
+λe1,e2:exadecim.λc:bool.
+ match c with
+  [ true ⇒ match e1 with
+   [ x0 ⇒ match e2 with
+    [ x0 ⇒ x1 | x1 ⇒ x2 | x2 ⇒ x3 | x3 ⇒ x4 | x4 ⇒ x5 | x5 ⇒ x6 | x6 ⇒ x7 | x7 ⇒ x8
+    | x8 ⇒ x9 | x9 ⇒ xA | xA ⇒ xB | xB ⇒ xC | xC ⇒ xD | xD ⇒ xE | xE ⇒ xF | xF ⇒ x0 ] 
+   | x1 ⇒ match e2 with
+    [ x0 ⇒ x2 | x1 ⇒ x3 | x2 ⇒ x4 | x3 ⇒ x5 | x4 ⇒ x6 | x5 ⇒ x7 | x6 ⇒ x8 | x7 ⇒ x9
+    | x8 ⇒ xA | x9 ⇒ xB | xA ⇒ xC | xB ⇒ xD | xC ⇒ xE | xD ⇒ xF | xE ⇒ x0 | xF ⇒ x1 ] 
+   | x2 ⇒ match e2 with
+    [ x0 ⇒ x3 | x1 ⇒ x4 | x2 ⇒ x5 | x3 ⇒ x6 | x4 ⇒ x7 | x5 ⇒ x8 | x6 ⇒ x9 | x7 ⇒ xA
+    | x8 ⇒ xB | x9 ⇒ xC | xA ⇒ xD | xB ⇒ xE | xC ⇒ xF | xD ⇒ x0 | xE ⇒ x1 | xF ⇒ x2 ]
+   | x3 ⇒ match e2 with
+    [ x0 ⇒ x4 | x1 ⇒ x5 | x2 ⇒ x6 | x3 ⇒ x7 | x4 ⇒ x8 | x5 ⇒ x9 | x6 ⇒ xA | x7 ⇒ xB
+    | x8 ⇒ xC | x9 ⇒ xD | xA ⇒ xE | xB ⇒ xF | xC ⇒ x0 | xD ⇒ x1 | xE ⇒ x2 | xF ⇒ x3 ]
+   | x4 ⇒ match e2 with
+    [ x0 ⇒ x5 | x1 ⇒ x6 | x2 ⇒ x7 | x3 ⇒ x8 | x4 ⇒ x9 | x5 ⇒ xA | x6 ⇒ xB | x7 ⇒ xC
+    | x8 ⇒ xD | x9 ⇒ xE | xA ⇒ xF | xB ⇒ x0 | xC ⇒ x1 | xD ⇒ x2 | xE ⇒ x3 | xF ⇒ x4 ]
+   | x5 ⇒ match e2 with
+    [ x0 ⇒ x6 | x1 ⇒ x7 | x2 ⇒ x8 | x3 ⇒ x9 | x4 ⇒ xA | x5 ⇒ xB | x6 ⇒ xC | x7 ⇒ xD
+    | x8 ⇒ xE | x9 ⇒ xF | xA ⇒ x0 | xB ⇒ x1 | xC ⇒ x2 | xD ⇒ x3 | xE ⇒ x4 | xF ⇒ x5 ]
+   | x6 ⇒ match e2 with
+    [ x0 ⇒ x7 | x1 ⇒ x8 | x2 ⇒ x9 | x3 ⇒ xA | x4 ⇒ xB | x5 ⇒ xC | x6 ⇒ xD | x7 ⇒ xE
+    | x8 ⇒ xF | x9 ⇒ x0 | xA ⇒ x1 | xB ⇒ x2 | xC ⇒ x3 | xD ⇒ x4 | xE ⇒ x5 | xF ⇒ x6 ]
+   | x7 ⇒ match e2 with
+    [ x0 ⇒ x8 | x1 ⇒ x9 | x2 ⇒ xA | x3 ⇒ xB | x4 ⇒ xC | x5 ⇒ xD | x6 ⇒ xE | x7 ⇒ xF
+    | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x2 | xB ⇒ x3 | xC ⇒ x4 | xD ⇒ x5 | xE ⇒ x6 | xF ⇒ x7 ]
+   | x8 ⇒ match e2 with
+    [ x0 ⇒ x9 | x1 ⇒ xA | x2 ⇒ xB | x3 ⇒ xC | x4 ⇒ xD | x5 ⇒ xE | x6 ⇒ xF | x7 ⇒ x0
+    | x8 ⇒ x1 | x9 ⇒ x2 | xA ⇒ x3 | xB ⇒ x4 | xC ⇒ x5 | xD ⇒ x6 | xE ⇒ x7 | xF ⇒ x8 ]
+   | x9 ⇒ match e2 with
+    [ x0 ⇒ xA | x1 ⇒ xB | x2 ⇒ xC | x3 ⇒ xD | x4 ⇒ xE | x5 ⇒ xF | x6 ⇒ x0 | x7 ⇒ x1
+    | x8 ⇒ x2 | x9 ⇒ x3 | xA ⇒ x4 | xB ⇒ x5 | xC ⇒ x6 | xD ⇒ x7 | xE ⇒ x8 | xF ⇒ x9 ]
+   | xA ⇒ match e2 with
+    [ x0 ⇒ xB | x1 ⇒ xC | x2 ⇒ xD | x3 ⇒ xE | x4 ⇒ xF | x5 ⇒ x0 | x6 ⇒ x1 | x7 ⇒ x2
+    | x8 ⇒ x3 | x9 ⇒ x4 | xA ⇒ x5 | xB ⇒ x6 | xC ⇒ x7 | xD ⇒ x8 | xE ⇒ x9 | xF ⇒ xA ]
+   | xB ⇒ match e2 with
+    [ x0 ⇒ xC | x1 ⇒ xD | x2 ⇒ xE | x3 ⇒ xF | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x2 | x7 ⇒ x3
+    | x8 ⇒ x4 | x9 ⇒ x5 | xA ⇒ x6 | xB ⇒ x7 | xC ⇒ x8 | xD ⇒ x9 | xE ⇒ xA | xF ⇒ xB ]
+   | xC ⇒ match e2 with
+     [ x0 ⇒ xD | x1 ⇒ xE | x2 ⇒ xF | x3 ⇒ x0 | x4 ⇒ x1 | x5 ⇒ x2 | x6 ⇒ x3 | x7 ⇒ x4
+    | x8 ⇒ x5 | x9 ⇒ x6 | xA ⇒ x7 | xB ⇒ x8 | xC ⇒ x9 | xD ⇒ xA | xE ⇒ xB | xF ⇒ xC ]
+   | xD ⇒ match e2 with
+    [ x0 ⇒ xE | x1 ⇒ xF | x2 ⇒ x0 | x3 ⇒ x1 | x4 ⇒ x2 | x5 ⇒ x3 | x6 ⇒ x4 | x7 ⇒ x5
+    | x8 ⇒ x6 | x9 ⇒ x7 | xA ⇒ x8 | xB ⇒ x9 | xC ⇒ xA | xD ⇒ xB | xE ⇒ xC | xF ⇒ xD ]
+   | xE ⇒ match e2 with
+    [ x0 ⇒ xF | x1 ⇒ x0 | x2 ⇒ x1 | x3 ⇒ x2 | x4 ⇒ x3 | x5 ⇒ x4 | x6 ⇒ x5 | x7 ⇒ x6
+    | x8 ⇒ x7 | x9 ⇒ x8 | xA ⇒ x9 | xB ⇒ xA | xC ⇒ xB | xD ⇒ xC | xE ⇒ xD | xF ⇒ xE ]
+   | xF ⇒ match e2 with
+    [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+    | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ]
+   ]
+  | false ⇒ match e1 with
+   [ x0 ⇒ match e2 with
+    [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+    | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ] 
+   | x1 ⇒ match e2 with
+    [ x0 ⇒ x1 | x1 ⇒ x2 | x2 ⇒ x3 | x3 ⇒ x4 | x4 ⇒ x5 | x5 ⇒ x6 | x6 ⇒ x7 | x7 ⇒ x8
+    | x8 ⇒ x9 | x9 ⇒ xA | xA ⇒ xB | xB ⇒ xC | xC ⇒ xD | xD ⇒ xE | xE ⇒ xF | xF ⇒ x0 ] 
+   | x2 ⇒ match e2 with
+    [ x0 ⇒ x2 | x1 ⇒ x3 | x2 ⇒ x4 | x3 ⇒ x5 | x4 ⇒ x6 | x5 ⇒ x7 | x6 ⇒ x8 | x7 ⇒ x9
+    | x8 ⇒ xA | x9 ⇒ xB | xA ⇒ xC | xB ⇒ xD | xC ⇒ xE | xD ⇒ xF | xE ⇒ x0 | xF ⇒ x1 ] 
+   | x3 ⇒ match e2 with
+    [ x0 ⇒ x3 | x1 ⇒ x4 | x2 ⇒ x5 | x3 ⇒ x6 | x4 ⇒ x7 | x5 ⇒ x8 | x6 ⇒ x9 | x7 ⇒ xA
+    | x8 ⇒ xB | x9 ⇒ xC | xA ⇒ xD | xB ⇒ xE | xC ⇒ xF | xD ⇒ x0 | xE ⇒ x1 | xF ⇒ x2 ]
+   | x4 ⇒ match e2 with
+    [ x0 ⇒ x4 | x1 ⇒ x5 | x2 ⇒ x6 | x3 ⇒ x7 | x4 ⇒ x8 | x5 ⇒ x9 | x6 ⇒ xA | x7 ⇒ xB
+    | x8 ⇒ xC | x9 ⇒ xD | xA ⇒ xE | xB ⇒ xF | xC ⇒ x0 | xD ⇒ x1 | xE ⇒ x2 | xF ⇒ x3 ]
+   | x5 ⇒ match e2 with
+    [ x0 ⇒ x5 | x1 ⇒ x6 | x2 ⇒ x7 | x3 ⇒ x8 | x4 ⇒ x9 | x5 ⇒ xA | x6 ⇒ xB | x7 ⇒ xC
+    | x8 ⇒ xD | x9 ⇒ xE | xA ⇒ xF | xB ⇒ x0 | xC ⇒ x1 | xD ⇒ x2 | xE ⇒ x3 | xF ⇒ x4 ]
+   | x6 ⇒ match e2 with
+    [ x0 ⇒ x6 | x1 ⇒ x7 | x2 ⇒ x8 | x3 ⇒ x9 | x4 ⇒ xA | x5 ⇒ xB | x6 ⇒ xC | x7 ⇒ xD
+    | x8 ⇒ xE | x9 ⇒ xF | xA ⇒ x0 | xB ⇒ x1 | xC ⇒ x2 | xD ⇒ x3 | xE ⇒ x4 | xF ⇒ x5 ]
+   | x7 ⇒ match e2 with
+    [ x0 ⇒ x7 | x1 ⇒ x8 | x2 ⇒ x9 | x3 ⇒ xA | x4 ⇒ xB | x5 ⇒ xC | x6 ⇒ xD | x7 ⇒ xE
+    | x8 ⇒ xF | x9 ⇒ x0 | xA ⇒ x1 | xB ⇒ x2 | xC ⇒ x3 | xD ⇒ x4 | xE ⇒ x5 | xF ⇒ x6 ]
+   | x8 ⇒ match e2 with
+    [ x0 ⇒ x8 | x1 ⇒ x9 | x2 ⇒ xA | x3 ⇒ xB | x4 ⇒ xC | x5 ⇒ xD | x6 ⇒ xE | x7 ⇒ xF
+    | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x2 | xB ⇒ x3 | xC ⇒ x4 | xD ⇒ x5 | xE ⇒ x6 | xF ⇒ x7 ]
+   | x9 ⇒ match e2 with
+    [ x0 ⇒ x9 | x1 ⇒ xA | x2 ⇒ xB | x3 ⇒ xC | x4 ⇒ xD | x5 ⇒ xE | x6 ⇒ xF | x7 ⇒ x0
+    | x8 ⇒ x1 | x9 ⇒ x2 | xA ⇒ x3 | xB ⇒ x4 | xC ⇒ x5 | xD ⇒ x6 | xE ⇒ x7 | xF ⇒ x8 ]
+   | xA ⇒ match e2 with
+    [ x0 ⇒ xA | x1 ⇒ xB | x2 ⇒ xC | x3 ⇒ xD | x4 ⇒ xE | x5 ⇒ xF | x6 ⇒ x0 | x7 ⇒ x1
+    | x8 ⇒ x2 | x9 ⇒ x3 | xA ⇒ x4 | xB ⇒ x5 | xC ⇒ x6 | xD ⇒ x7 | xE ⇒ x8 | xF ⇒ x9 ]
+   | xB ⇒ match e2 with
+    [ x0 ⇒ xB | x1 ⇒ xC | x2 ⇒ xD | x3 ⇒ xE | x4 ⇒ xF | x5 ⇒ x0 | x6 ⇒ x1 | x7 ⇒ x2
+    | x8 ⇒ x3 | x9 ⇒ x4 | xA ⇒ x5 | xB ⇒ x6 | xC ⇒ x7 | xD ⇒ x8 | xE ⇒ x9 | xF ⇒ xA ]
+   | xC ⇒ match e2 with
+    [ x0 ⇒ xC | x1 ⇒ xD | x2 ⇒ xE | x3 ⇒ xF | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x2 | x7 ⇒ x3
+    | x8 ⇒ x4 | x9 ⇒ x5 | xA ⇒ x6 | xB ⇒ x7 | xC ⇒ x8 | xD ⇒ x9 | xE ⇒ xA | xF ⇒ xB ]
+   | xD ⇒ match e2 with
+     [ x0 ⇒ xD | x1 ⇒ xE | x2 ⇒ xF | x3 ⇒ x0 | x4 ⇒ x1 | x5 ⇒ x2 | x6 ⇒ x3 | x7 ⇒ x4
+    | x8 ⇒ x5 | x9 ⇒ x6 | xA ⇒ x7 | xB ⇒ x8 | xC ⇒ x9 | xD ⇒ xA | xE ⇒ xB | xF ⇒ xC ]
+   | xE ⇒ match e2 with
+    [ x0 ⇒ xE | x1 ⇒ xF | x2 ⇒ x0 | x3 ⇒ x1 | x4 ⇒ x2 | x5 ⇒ x3 | x6 ⇒ x4 | x7 ⇒ x5
+    | x8 ⇒ x6 | x9 ⇒ x7 | xA ⇒ x8 | xB ⇒ x9 | xC ⇒ xA | xD ⇒ xB | xE ⇒ xC | xF ⇒ xD ]
+   | xF ⇒ match e2 with
+    [ x0 ⇒ xF | x1 ⇒ x0 | x2 ⇒ x1 | x3 ⇒ x2 | x4 ⇒ x3 | x5 ⇒ x4 | x6 ⇒ x5 | x7 ⇒ x6
+    | x8 ⇒ x7 | x9 ⇒ x8 | xA ⇒ x9 | xB ⇒ xA | xC ⇒ xB | xD ⇒ xC | xE ⇒ xD | xF ⇒ xE ]
+   ]].
+
+(* operatore somma con data → data *)
+ndefinition plus_ex_d_d ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with
+   [ x0 ⇒ x0 | x1 ⇒ x1 | x2 ⇒ x2 | x3 ⇒ x3 | x4 ⇒ x4 | x5 ⇒ x5 | x6 ⇒ x6 | x7 ⇒ x7
+   | x8 ⇒ x8 | x9 ⇒ x9 | xA ⇒ xA | xB ⇒ xB | xC ⇒ xC | xD ⇒ xD | xE ⇒ xE | xF ⇒ xF ] 
+  | x1 ⇒ match e2 with
+   [ x0 ⇒ x1 | x1 ⇒ x2 | x2 ⇒ x3 | x3 ⇒ x4 | x4 ⇒ x5 | x5 ⇒ x6 | x6 ⇒ x7 | x7 ⇒ x8
+   | x8 ⇒ x9 | x9 ⇒ xA | xA ⇒ xB | xB ⇒ xC | xC ⇒ xD | xD ⇒ xE | xE ⇒ xF | xF ⇒ x0 ] 
+  | x2 ⇒ match e2 with
+   [ x0 ⇒ x2 | x1 ⇒ x3 | x2 ⇒ x4 | x3 ⇒ x5 | x4 ⇒ x6 | x5 ⇒ x7 | x6 ⇒ x8 | x7 ⇒ x9
+   | x8 ⇒ xA | x9 ⇒ xB | xA ⇒ xC | xB ⇒ xD | xC ⇒ xE | xD ⇒ xF | xE ⇒ x0 | xF ⇒ x1 ] 
+  | x3 ⇒ match e2 with
+   [ x0 ⇒ x3 | x1 ⇒ x4 | x2 ⇒ x5 | x3 ⇒ x6 | x4 ⇒ x7 | x5 ⇒ x8 | x6 ⇒ x9 | x7 ⇒ xA
+   | x8 ⇒ xB | x9 ⇒ xC | xA ⇒ xD | xB ⇒ xE | xC ⇒ xF | xD ⇒ x0 | xE ⇒ x1 | xF ⇒ x2 ]
+  | x4 ⇒ match e2 with
+   [ x0 ⇒ x4 | x1 ⇒ x5 | x2 ⇒ x6 | x3 ⇒ x7 | x4 ⇒ x8 | x5 ⇒ x9 | x6 ⇒ xA | x7 ⇒ xB
+   | x8 ⇒ xC | x9 ⇒ xD | xA ⇒ xE | xB ⇒ xF | xC ⇒ x0 | xD ⇒ x1 | xE ⇒ x2 | xF ⇒ x3 ]
+  | x5 ⇒ match e2 with
+   [ x0 ⇒ x5 | x1 ⇒ x6 | x2 ⇒ x7 | x3 ⇒ x8 | x4 ⇒ x9 | x5 ⇒ xA | x6 ⇒ xB | x7 ⇒ xC
+   | x8 ⇒ xD | x9 ⇒ xE | xA ⇒ xF | xB ⇒ x0 | xC ⇒ x1 | xD ⇒ x2 | xE ⇒ x3 | xF ⇒ x4 ]
+  | x6 ⇒ match e2 with
+   [ x0 ⇒ x6 | x1 ⇒ x7 | x2 ⇒ x8 | x3 ⇒ x9 | x4 ⇒ xA | x5 ⇒ xB | x6 ⇒ xC | x7 ⇒ xD
+   | x8 ⇒ xE | x9 ⇒ xF | xA ⇒ x0 | xB ⇒ x1 | xC ⇒ x2 | xD ⇒ x3 | xE ⇒ x4 | xF ⇒ x5 ]
+  | x7 ⇒ match e2 with
+   [ x0 ⇒ x7 | x1 ⇒ x8 | x2 ⇒ x9 | x3 ⇒ xA | x4 ⇒ xB | x5 ⇒ xC | x6 ⇒ xD | x7 ⇒ xE
+   | x8 ⇒ xF | x9 ⇒ x0 | xA ⇒ x1 | xB ⇒ x2 | xC ⇒ x3 | xD ⇒ x4 | xE ⇒ x5 | xF ⇒ x6 ]
+  | x8 ⇒ match e2 with
+   [ x0 ⇒ x8 | x1 ⇒ x9 | x2 ⇒ xA | x3 ⇒ xB | x4 ⇒ xC | x5 ⇒ xD | x6 ⇒ xE | x7 ⇒ xF
+   | x8 ⇒ x0 | x9 ⇒ x1 | xA ⇒ x2 | xB ⇒ x3 | xC ⇒ x4 | xD ⇒ x5 | xE ⇒ x6 | xF ⇒ x7 ]
+  | x9 ⇒ match e2 with
+   [ x0 ⇒ x9 | x1 ⇒ xA | x2 ⇒ xB | x3 ⇒ xC | x4 ⇒ xD | x5 ⇒ xE | x6 ⇒ xF | x7 ⇒ x0
+   | x8 ⇒ x1 | x9 ⇒ x2 | xA ⇒ x3 | xB ⇒ x4 | xC ⇒ x5 | xD ⇒ x6 | xE ⇒ x7 | xF ⇒ x8 ]
+  | xA ⇒ match e2 with
+   [ x0 ⇒ xA | x1 ⇒ xB | x2 ⇒ xC | x3 ⇒ xD | x4 ⇒ xE | x5 ⇒ xF | x6 ⇒ x0 | x7 ⇒ x1
+   | x8 ⇒ x2 | x9 ⇒ x3 | xA ⇒ x4 | xB ⇒ x5 | xC ⇒ x6 | xD ⇒ x7 | xE ⇒ x8 | xF ⇒ x9 ]
+  | xB ⇒ match e2 with
+   [ x0 ⇒ xB | x1 ⇒ xC | x2 ⇒ xD | x3 ⇒ xE | x4 ⇒ xF | x5 ⇒ x0 | x6 ⇒ x1 | x7 ⇒ x2
+   | x8 ⇒ x3 | x9 ⇒ x4 | xA ⇒ x5 | xB ⇒ x6 | xC ⇒ x7 | xD ⇒ x8 | xE ⇒ x9 | xF ⇒ xA ]
+  | xC ⇒ match e2 with
+   [ x0 ⇒ xC | x1 ⇒ xD | x2 ⇒ xE | x3 ⇒ xF | x4 ⇒ x0 | x5 ⇒ x1 | x6 ⇒ x2 | x7 ⇒ x3
+   | x8 ⇒ x4 | x9 ⇒ x5 | xA ⇒ x6 | xB ⇒ x7 | xC ⇒ x8 | xD ⇒ x9 | xE ⇒ xA | xF ⇒ xB ]
+  | xD ⇒ match e2 with
+   [ x0 ⇒ xD | x1 ⇒ xE | x2 ⇒ xF | x3 ⇒ x0 | x4 ⇒ x1 | x5 ⇒ x2 | x6 ⇒ x3 | x7 ⇒ x4
+   | x8 ⇒ x5 | x9 ⇒ x6 | xA ⇒ x7 | xB ⇒ x8 | xC ⇒ x9 | xD ⇒ xA | xE ⇒ xB | xF ⇒ xC ]
+  | xE ⇒ match e2 with
+   [ x0 ⇒ xE | x1 ⇒ xF | x2 ⇒ x0 | x3 ⇒ x1 | x4 ⇒ x2 | x5 ⇒ x3 | x6 ⇒ x4 | x7 ⇒ x5
+   | x8 ⇒ x6 | x9 ⇒ x7 | xA ⇒ x8 | xB ⇒ x9 | xC ⇒ xA | xD ⇒ xB | xE ⇒ xC | xF ⇒ xD ]
+  | xF ⇒ match e2 with
+   [ x0 ⇒ xF | x1 ⇒ x0 | x2 ⇒ x1 | x3 ⇒ x2 | x4 ⇒ x3 | x5 ⇒ x4 | x6 ⇒ x5 | x7 ⇒ x6
+   | x8 ⇒ x7 | x9 ⇒ x8 | xA ⇒ x9 | xB ⇒ xA | xC ⇒ xB | xD ⇒ xC | xE ⇒ xD | xF ⇒ xE ]
+  ].
+
+(* operatore somma con data+carry → carry *)
+ndefinition plus_ex_dc_c ≝
+λe1,e2:exadecim.λc:bool.
+ match c with
+  [ true ⇒ match e1 with
+   [ x0 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ true  ] 
+   | x1 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ true  | xF ⇒ true  ] 
+   | x2 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x3 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x4 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x5 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x6 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x7 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x8 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x9 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xA ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xB ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xC ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xD ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ true  | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xE ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ]
+   | xF ⇒ match e2 with
+    [ x0 ⇒ true  | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ]  
+   ]
+  | false ⇒ match e1 with
+   [ x0 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+   | x1 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ true  ] 
+   | x2 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ true  | xF ⇒ true  ] 
+   | x3 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x4 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x5 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x6 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ false | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x7 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ false | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x8 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | x9 ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xA ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xB ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xC ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xD ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xE ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ true  | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   | xF ⇒ match e2 with
+    [ x0 ⇒ false | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+    | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+   ]].
+
+(* operatore somma con data → carry *)
+ndefinition plus_ex_d_c ≝
+λe1,e2:exadecim.
+ match e1 with
+  [ x0 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ false ] 
+  | x1 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ false | xF ⇒ true  ] 
+  | x2 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ false | xE ⇒ true  | xF ⇒ true  ] 
+  | x3 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ false | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | x4 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ false | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | x5 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ false | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | x6 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ false | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | x7 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ false | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | x8 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | x9 ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | xA ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ false | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | xB ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ false | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | xC ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | xD ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | xE ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ true  | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  | xF ⇒ match e2 with
+   [ x0 ⇒ false | x1 ⇒ true  | x2 ⇒ true  | x3 ⇒ true  | x4 ⇒ true  | x5 ⇒ true  | x6 ⇒ true  | x7 ⇒ true
+   | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true  | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true  ] 
+  ].
+
+(* operatore Most Significant Bit *)
+ndefinition MSB_ex ≝
+λe:exadecim.match e with
+ [ x0 ⇒ false | x1 ⇒ false | x2 ⇒ false | x3 ⇒ false
+ | x4 ⇒ false | x5 ⇒ false | x6 ⇒ false | x7 ⇒ false
+ | x8 ⇒ true  | x9 ⇒ true  | xA ⇒ true  | xB ⇒ true
+ | xC ⇒ true  | xD ⇒ true  | xE ⇒ true  | xF ⇒ true ].
+
+(* operatore predecessore *)
+ndefinition pred_ex ≝
+λe:exadecim.
+ match e with
+  [ x0 ⇒ xF | x1 ⇒ x0 | x2 ⇒ x1 | x3 ⇒ x2 | x4 ⇒ x3 | x5 ⇒ x4 | x6 ⇒ x5 | x7 ⇒ x6
+  | x8 ⇒ x7 | x9 ⇒ x8 | xA ⇒ x9 | xB ⇒ xA | xC ⇒ xB | xD ⇒ xC | xE ⇒ xD | xF ⇒ xE ].
+
+(* operatore successore *)
+ndefinition succ_ex ≝
+λe:exadecim.
+ match e with
+  [ x0 ⇒ x1 | x1 ⇒ x2 | x2 ⇒ x3 | x3 ⇒ x4 | x4 ⇒ x5 | x5 ⇒ x6 | x6 ⇒ x7 | x7 ⇒ x8
+  | x8 ⇒ x9 | x9 ⇒ xA | xA ⇒ xB | xB ⇒ xC | xC ⇒ xD | xD ⇒ xE | xE ⇒ xF | xF ⇒ x0 ].
+
+(* operatore neg/complemento a 2 *)
+ndefinition compl_ex ≝
+λe:exadecim.match e with
+ [ x0 ⇒ x0 | x1 ⇒ xF | x2 ⇒ xE | x3 ⇒ xD
+ | x4 ⇒ xC | x5 ⇒ xB | x6 ⇒ xA | x7 ⇒ x9
+ | x8 ⇒ x8 | x9 ⇒ x7 | xA ⇒ x6 | xB ⇒ x5
+ | xC ⇒ x4 | xD ⇒ x3 | xE ⇒ x2 | xF ⇒ x1 ].
+
+(* operatore x in [inf,sup] o in sup],[inf *)
+ndefinition inrange_ex ≝
+λx,inf,sup:exadecim.
+ match le_ex inf sup with
+  [ true ⇒ and_bool | false ⇒ or_bool ]
+ (le_ex inf x) (le_ex x sup).
+
+(* iteratore sugli esadecimali *)
+ndefinition forall_ex ≝ λP.
+ P x0 ⊗ P x1 ⊗ P x2 ⊗ P x3 ⊗ P x4 ⊗ P x5 ⊗ P x6 ⊗ P x7 ⊗
+ P x8 ⊗ P x9 ⊗ P xA ⊗ P xB ⊗ P xC ⊗ P xD ⊗ P xE ⊗ P xF.
+
+(* esadecimali ricorsivi *)
+ninductive rec_exadecim : exadecim → Type ≝
+  ex_O : rec_exadecim x0
+| ex_S : ∀n.rec_exadecim n → rec_exadecim (succ_ex n).
+
+(* esadecimali → esadecimali ricorsivi *)
+ndefinition ex_to_recex ≝
+λn.match n return λx.rec_exadecim x with
+ [ x0 ⇒ ex_O
+ | x1 ⇒ ex_S ? ex_O
+ | x2 ⇒ ex_S ? (ex_S ? ex_O)
+ | x3 ⇒ ex_S ? (ex_S ? (ex_S ? ex_O))
+ | x4 ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O)))
+ | x5 ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O))))
+ | x6 ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O)))))
+ | x7 ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O))))))
+ | x8 ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O)))))))
+ | x9 ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O))))))))
+ | xA ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O)))))))))
+ | xB ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O))))))))))
+ | xC ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O)))))))))))
+ | xD ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O))))))))))))
+ | xE ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O)))))))))))))
+ | xF ⇒ ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? (ex_S ? ex_O))))))))))))))
+ ].
+
+(* quaternari → esadecimali *)
+ndefinition ex_of_qu ≝
+λn.match n with
+ [ q0 ⇒ x0 | q1 ⇒ x1 | q2 ⇒ x2 | q3 ⇒ x3 ].
+
+(* ottali → esadecimali *)
+ndefinition ex_of_oct ≝
+λn.match n with
+ [ o0 ⇒ x0 | o1 ⇒ x1 | o2 ⇒ x2 | o3 ⇒ x3 | o4 ⇒ x4 | o5 ⇒ x5 | o6 ⇒ x6 | o7 ⇒ x7 ].
diff --git a/helm/software/matita/contribs/ng_assembly/num/exadecim_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/exadecim_lemmas.ma
new file mode 100755 (executable)
index 0000000..c6e09d5
--- /dev/null
@@ -0,0 +1,346 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/exadecim.ma".
+include "num/bool_lemmas.ma".
+
+(* *********** *)
+(* ESADECIMALI *)
+(* *********** *)
+
+(*
+ndefinition exadecim_destruct_aux ≝
+Πe1,e2.ΠP:Prop.ΠH:e1 = e2.
+ match eq_ex e1 e2 with [ true ⇒ P → P | false ⇒ P ].
+
+ndefinition exadecim_destruct : exadecim_destruct_aux.
+ #e1; #e2; #P; #H;
+ nrewrite < H;
+ nelim e1;
+ nnormalize;
+ napply (λx.x).
+nqed.
+*)
+
+nlemma symmetric_andex : symmetricT exadecim exadecim and_ex.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma associative_andex1 : ∀e2,e3.(and_ex (and_ex x0 e2) e3) = (and_ex x0 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex2 : ∀e2,e3.(and_ex (and_ex x1 e2) e3) = (and_ex x1 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex3 : ∀e2,e3.(and_ex (and_ex x2 e2) e3) = (and_ex x2 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex4 : ∀e2,e3.(and_ex (and_ex x3 e2) e3) = (and_ex x3 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex5 : ∀e2,e3.(and_ex (and_ex x4 e2) e3) = (and_ex x4 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex6 : ∀e2,e3.(and_ex (and_ex x5 e2) e3) = (and_ex x5 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex7 : ∀e2,e3.(and_ex (and_ex x6 e2) e3) = (and_ex x6 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex8 : ∀e2,e3.(and_ex (and_ex x7 e2) e3) = (and_ex x7 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex9 : ∀e2,e3.(and_ex (and_ex x8 e2) e3) = (and_ex x8 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex10 : ∀e2,e3.(and_ex (and_ex x9 e2) e3) = (and_ex x9 (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex11 : ∀e2,e3.(and_ex (and_ex xA e2) e3) = (and_ex xA (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex12 : ∀e2,e3.(and_ex (and_ex xB e2) e3) = (and_ex xB (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex13 : ∀e2,e3.(and_ex (and_ex xC e2) e3) = (and_ex xC (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex14 : ∀e2,e3.(and_ex (and_ex xD e2) e3) = (and_ex xD (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex15 : ∀e2,e3.(and_ex (and_ex xE e2) e3) = (and_ex xE (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+nlemma associative_andex16 : ∀e2,e3.(and_ex (and_ex xF e2) e3) = (and_ex xF (and_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed. 
+
+nlemma associative_andex : ∀e1,e2,e3.(and_ex (and_ex e1 e2) e3) = (and_ex e1 (and_ex e2 e3)).
+ #e1; nelim e1;
+ ##[ ##1: napply  associative_andex1 ##| ##2: napply  associative_andex2
+ ##| ##3: napply  associative_andex3 ##| ##4: napply  associative_andex4
+ ##| ##5: napply  associative_andex5 ##| ##6: napply  associative_andex6
+ ##| ##7: napply  associative_andex7 ##| ##8: napply  associative_andex8
+ ##| ##9: napply  associative_andex9 ##| ##10: napply  associative_andex10
+ ##| ##11: napply  associative_andex11 ##| ##12: napply  associative_andex12
+ ##| ##13: napply  associative_andex13 ##| ##14: napply  associative_andex14
+ ##| ##15: napply  associative_andex15 ##| ##16: napply  associative_andex16
+ ##]
+nqed.
+
+nlemma symmetric_orex : symmetricT exadecim exadecim or_ex.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma associative_orex1 : ∀e2,e3.(or_ex (or_ex x0 e2) e3) = (or_ex x0 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex2 : ∀e2,e3.(or_ex (or_ex x1 e2) e3) = (or_ex x1 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex3 : ∀e2,e3.(or_ex (or_ex x2 e2) e3) = (or_ex x2 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex4 : ∀e2,e3.(or_ex (or_ex x3 e2) e3) = (or_ex x3 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex5 : ∀e2,e3.(or_ex (or_ex x4 e2) e3) = (or_ex x4 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex6 : ∀e2,e3.(or_ex (or_ex x5 e2) e3) = (or_ex x5 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex7 : ∀e2,e3.(or_ex (or_ex x6 e2) e3) = (or_ex x6 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex8 : ∀e2,e3.(or_ex (or_ex x7 e2) e3) = (or_ex x7 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex9 : ∀e2,e3.(or_ex (or_ex x8 e2) e3) = (or_ex x8 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex10 : ∀e2,e3.(or_ex (or_ex x9 e2) e3) = (or_ex x9 (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex11 : ∀e2,e3.(or_ex (or_ex xA e2) e3) = (or_ex xA (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex12 : ∀e2,e3.(or_ex (or_ex xB e2) e3) = (or_ex xB (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex13 : ∀e2,e3.(or_ex (or_ex xC e2) e3) = (or_ex xC (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex14 : ∀e2,e3.(or_ex (or_ex xD e2) e3) = (or_ex xD (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex15 : ∀e2,e3.(or_ex (or_ex xE e2) e3) = (or_ex xE (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_orex16 : ∀e2,e3.(or_ex (or_ex xF e2) e3) = (or_ex xF (or_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+
+nlemma associative_orex : ∀e1,e2,e3.(or_ex (or_ex e1 e2) e3) = (or_ex e1 (or_ex e2 e3)).
+ #e1; nelim e1;
+ ##[ ##1: napply associative_orex1 ##| ##2: napply associative_orex2
+ ##| ##3: napply associative_orex3 ##| ##4: napply associative_orex4
+ ##| ##5: napply associative_orex5 ##| ##6: napply associative_orex6
+ ##| ##7: napply associative_orex7 ##| ##8: napply associative_orex8
+ ##| ##9: napply associative_orex9 ##| ##10: napply associative_orex10
+ ##| ##11: napply associative_orex11 ##| ##12: napply associative_orex12
+ ##| ##13: napply associative_orex13 ##| ##14: napply associative_orex14
+ ##| ##15: napply associative_orex15 ##| ##16: napply associative_orex16
+ ##]
+nqed.
+
+nlemma symmetric_xorex : symmetricT exadecim exadecim xor_ex.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma associative_xorex1 : ∀e2,e3.(xor_ex (xor_ex x0 e2) e3) = (xor_ex x0 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex2 : ∀e2,e3.(xor_ex (xor_ex x1 e2) e3) = (xor_ex x1 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex3 : ∀e2,e3.(xor_ex (xor_ex x2 e2) e3) = (xor_ex x2 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex4 : ∀e2,e3.(xor_ex (xor_ex x3 e2) e3) = (xor_ex x3 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex5 : ∀e2,e3.(xor_ex (xor_ex x4 e2) e3) = (xor_ex x4 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex6 : ∀e2,e3.(xor_ex (xor_ex x5 e2) e3) = (xor_ex x5 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex7 : ∀e2,e3.(xor_ex (xor_ex x6 e2) e3) = (xor_ex x6 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex8 : ∀e2,e3.(xor_ex (xor_ex x7 e2) e3) = (xor_ex x7 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex9 : ∀e2,e3.(xor_ex (xor_ex x8 e2) e3) = (xor_ex x8 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex10 : ∀e2,e3.(xor_ex (xor_ex x9 e2) e3) = (xor_ex x9 (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex11 : ∀e2,e3.(xor_ex (xor_ex xA e2) e3) = (xor_ex xA (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex12 : ∀e2,e3.(xor_ex (xor_ex xB e2) e3) = (xor_ex xB (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex13 : ∀e2,e3.(xor_ex (xor_ex xC e2) e3) = (xor_ex xC (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex14 : ∀e2,e3.(xor_ex (xor_ex xD e2) e3) = (xor_ex xD (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex15 : ∀e2,e3.(xor_ex (xor_ex xE e2) e3) = (xor_ex xE (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_xorex16 : ∀e2,e3.(xor_ex (xor_ex xF e2) e3) = (xor_ex xF (xor_ex e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+
+nlemma associative_xorex : ∀e1,e2,e3.(xor_ex (xor_ex e1 e2) e3) = (xor_ex e1 (xor_ex e2 e3)).
+ #e1; nelim e1;
+ ##[ ##1: napply associative_xorex1 ##| ##2: napply associative_xorex2
+ ##| ##3: napply associative_xorex3 ##| ##4: napply associative_xorex4
+ ##| ##5: napply associative_xorex5 ##| ##6: napply associative_xorex6
+ ##| ##7: napply associative_xorex7 ##| ##8: napply associative_xorex8
+ ##| ##9: napply associative_xorex9 ##| ##10: napply associative_xorex10
+ ##| ##11: napply associative_xorex11 ##| ##12: napply associative_xorex12
+ ##| ##13: napply associative_xorex13 ##| ##14: napply associative_xorex14
+ ##| ##15: napply associative_xorex15 ##| ##16: napply associative_xorex16
+ ##]
+nqed.
+
+nlemma symmetric_plusex_dc_dc : ∀e1,e2,c.plus_ex_dc_dc e1 e2 c = plus_ex_dc_dc e2 e1 c.
+ #e1; #e2; #c;
+ nelim e1;
+ nelim e2;
+ nelim c;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma plusex_dc_dc_to_dc_d : ∀e1,e2,c.fst … (plus_ex_dc_dc e1 e2 c) = plus_ex_dc_d e1 e2 c.
+ #e1; #e2; #c;
+ nelim e1;
+ nelim e2;
+ nelim c;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma plusex_dc_dc_to_dc_c : ∀e1,e2,c.snd … (plus_ex_dc_dc e1 e2 c) = plus_ex_dc_c e1 e2 c.
+ #e1; #e2; #c;
+ nelim e1;
+ nelim e2;
+ nelim c;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma plusex_dc_dc_to_d_dc : ∀e1,e2.plus_ex_dc_dc e1 e2 false = plus_ex_d_dc e1 e2.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma plusex_dc_dc_to_d_d : ∀e1,e2.fst … (plus_ex_dc_dc e1 e2 false) = plus_ex_d_d e1 e2.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma plusex_dc_dc_to_d_c : ∀e1,e2.snd … (plus_ex_dc_dc e1 e2 false) = plus_ex_d_c e1 e2.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusex_dc_d : ∀e1,e2,c.plus_ex_dc_d e1 e2 c = plus_ex_dc_d e2 e1 c.
+ #e1; #e2; #c;
+ nelim e1;
+ nelim e2;
+ nelim c;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusex_dc_c : ∀e1,e2,c.plus_ex_dc_c e1 e2 c = plus_ex_dc_c e2 e1 c.
+ #e1; #e2; #c;
+ nelim e1;
+ nelim e2;
+ nelim c;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusex_d_dc : ∀e1,e2.plus_ex_d_dc e1 e2 = plus_ex_d_dc e2 e1.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma plusex_d_dc_to_d_d : ∀e1,e2.fst … (plus_ex_d_dc e1 e2) = plus_ex_d_d e1 e2.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma plusex_d_dc_to_d_c : ∀e1,e2.snd … (plus_ex_d_dc e1 e2) = plus_ex_d_c e1 e2.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusex_d_d : ∀e1,e2.plus_ex_d_d e1 e2 = plus_ex_d_d e2 e1.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma associative_plusex_d_d1 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x0 e2) e3) = (plus_ex_d_d x0 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d2 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x1 e2) e3) = (plus_ex_d_d x1 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d3 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x2 e2) e3) = (plus_ex_d_d x2 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d4 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x3 e2) e3) = (plus_ex_d_d x3 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d5 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x4 e2) e3) = (plus_ex_d_d x4 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d6 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x5 e2) e3) = (plus_ex_d_d x5 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d7 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x6 e2) e3) = (plus_ex_d_d x6 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d8 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x7 e2) e3) = (plus_ex_d_d x7 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d9 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x8 e2) e3) = (plus_ex_d_d x8 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d10 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d x9 e2) e3) = (plus_ex_d_d x9 (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d11 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d xA e2) e3) = (plus_ex_d_d xA (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d12 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d xB e2) e3) = (plus_ex_d_d xB (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d13 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d xC e2) e3) = (plus_ex_d_d xC (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d14 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d xD e2) e3) = (plus_ex_d_d xD (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d15 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d xE e2) e3) = (plus_ex_d_d xE (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+nlemma associative_plusex_d_d16 : ∀e2,e3.(plus_ex_d_d (plus_ex_d_d xF e2) e3) = (plus_ex_d_d xF (plus_ex_d_d e2 e3)). #e2; #e3; nelim e2; nelim e3; nnormalize; napply refl_eq. nqed.
+
+nlemma associative_plusex_d_d : ∀e1,e2,e3.(plus_ex_d_d (plus_ex_d_d e1 e2) e3) = (plus_ex_d_d e1 (plus_ex_d_d e2 e3)).
+ #e1; nelim e1;
+ ##[ ##1: napply associative_plusex_d_d1 ##| ##2: napply associative_plusex_d_d2
+ ##| ##3: napply associative_plusex_d_d3 ##| ##4: napply associative_plusex_d_d4
+ ##| ##5: napply associative_plusex_d_d5 ##| ##6: napply associative_plusex_d_d6
+ ##| ##7: napply associative_plusex_d_d7 ##| ##8: napply associative_plusex_d_d8
+ ##| ##9: napply associative_plusex_d_d9 ##| ##10: napply associative_plusex_d_d10
+ ##| ##11: napply associative_plusex_d_d11 ##| ##12: napply associative_plusex_d_d12
+ ##| ##13: napply associative_plusex_d_d13 ##| ##14: napply associative_plusex_d_d14
+ ##| ##15: napply associative_plusex_d_d15 ##| ##16: napply associative_plusex_d_d16
+ ##]
+nqed.
+
+nlemma symmetric_plusex_d_c : ∀e1,e2.plus_ex_d_c e1 e2 = plus_ex_d_c e2 e1.
+ #e1; #e2;
+ nelim e1;
+ nelim e2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma eq_to_eqex : ∀n1,n2.n1 = n2 → eq_ex n1 n2 = true.
+ #n1; #n2; #H;
+ nrewrite > H;
+ nelim n2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma neqex_to_neq : ∀n1,n2.eq_ex n1 n2 = false → n1 ≠ n2.
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_ex n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqex n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqex_to_eq : ∀n1,n2.eq_ex n1 n2 = true → n1 = n2.
+ #n1; #n2;
+ ncases n1;
+ ncases n2;
+ nnormalize;
+ ##[ ##1,18,35,52,69,86,103,120,137,154,171,188,205,222,239,256: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma neq_to_neqex : ∀n1,n2.n1 ≠ n2 → eq_ex n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_ex n1 n2));
+ napply (not_to_not (eq_ex n1 n2 = true) (n1 = n2) ? H);
+ napply (eqex_to_eq n1 n2).
+nqed.
+
+nlemma decidable_ex : ∀x,y:exadecim.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_ex x y = true) (eq_ex x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqex_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqex_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqex : symmetricT exadecim bool eq_ex.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_ex n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqex n1 n2 H);
+          napply (symmetric_eq ? (eq_ex n2 n1) false);
+          napply (neq_to_neqex n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/num/oct.ma b/helm/software/matita/contribs/ng_assembly/num/oct.ma
new file mode 100755 (executable)
index 0000000..fbdbacd
--- /dev/null
@@ -0,0 +1,78 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ****** *)
+(* OTTALI *)
+(* ****** *)
+
+ninductive oct : Type ≝
+  o0: oct
+| o1: oct
+| o2: oct
+| o3: oct
+| o4: oct
+| o5: oct
+| o6: oct
+| o7: oct.
+
+(* operatore = *)
+ndefinition eq_oct ≝
+λn1,n2:oct.
+ match n1 with
+  [ o0 ⇒ match n2 with [ o0 ⇒ true  | _ ⇒ false ]
+  | o1 ⇒ match n2 with [ o1 ⇒ true  | _ ⇒ false ] 
+  | o2 ⇒ match n2 with [ o2 ⇒ true  | _ ⇒ false ]
+  | o3 ⇒ match n2 with [ o3 ⇒ true  | _ ⇒ false ] 
+  | o4 ⇒ match n2 with [ o4 ⇒ true  | _ ⇒ false ]  
+  | o5 ⇒ match n2 with [ o5 ⇒ true  | _ ⇒ false ] 
+  | o6 ⇒ match n2 with [ o6 ⇒ true  | _ ⇒ false ]  
+  | o7 ⇒ match n2 with [ o7 ⇒ true  | _ ⇒ false ] 
+  ].
+
+(* iteratore sugli ottali *)
+ndefinition forall_oct ≝ λP.
+ P o0 ⊗ P o1 ⊗ P o2 ⊗ P o3 ⊗ P o4 ⊗ P o5 ⊗ P o6 ⊗ P o7.
+
+(* operatore successore *)
+ndefinition succ_oct ≝
+λn.match n with
+ [ o0 ⇒ o1 | o1 ⇒ o2 | o2 ⇒ o3 | o3 ⇒ o4 | o4 ⇒ o5 | o5 ⇒ o6 | o6 ⇒ o7 | o7 ⇒ o0 ].
+
+(* ottali ricorsivi *)
+ninductive rec_oct : oct → Type ≝
+  oc_O : rec_oct o0
+| oc_S : ∀n.rec_oct n → rec_oct (succ_oct n).
+
+(* ottali → ottali ricorsivi *)
+ndefinition oct_to_recoct ≝
+λn.match n return λx.rec_oct x with
+ [ o0 ⇒ oc_O
+ | o1 ⇒ oc_S ? oc_O
+ | o2 ⇒ oc_S ? (oc_S ? oc_O)
+ | o3 ⇒ oc_S ? (oc_S ? (oc_S ? oc_O))
+ | o4 ⇒ oc_S ? (oc_S ? (oc_S ? (oc_S ? oc_O)))
+ | o5 ⇒ oc_S ? (oc_S ? (oc_S ? (oc_S ? (oc_S ? oc_O))))
+ | o6 ⇒ oc_S ? (oc_S ? (oc_S ? (oc_S ? (oc_S ? (oc_S ? oc_O)))))
+ | o7 ⇒ oc_S ? (oc_S ? (oc_S ? (oc_S ? (oc_S ? (oc_S ? (oc_S ? oc_O))))))
+ ].
diff --git a/helm/software/matita/contribs/ng_assembly/num/oct_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/oct_lemmas.ma
new file mode 100755 (executable)
index 0000000..3a29cc1
--- /dev/null
@@ -0,0 +1,93 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/oct.ma".
+include "num/bool_lemmas.ma".
+
+(* ****** *)
+(* OTTALI *)
+(* ****** *)
+
+(*
+ndefinition oct_destruct_aux ≝
+Πn1,n2:oct.ΠP:Prop.n1 = n2 →
+ match eq_oct n1 n2 with [ true ⇒ P → P | false ⇒ P ].
+
+ndefinition oct_destruct : oct_destruct_aux.
+ #n1; #n2; #P; #H;
+ nrewrite < H;
+ nelim n1;
+ nnormalize;
+ napply (λx.x).
+nqed.
+*)
+
+nlemma eq_to_eqoct : ∀n1,n2.n1 = n2 → eq_oct n1 n2 = true.
+ #n1; #n2; #H;
+ nrewrite > H;
+ nelim n2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma neqoct_to_neq : ∀n1,n2.eq_oct n1 n2 = false → n1 ≠ n2.
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_oct n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqoct n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqoct_to_eq : ∀n1,n2.eq_oct n1 n2 = true → n1 = n2.
+ #n1; #n2;
+ ncases n1;
+ ncases n2;
+ nnormalize;
+ ##[ ##1,10,19,28,37,46,55,64: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma neq_to_neqoct : ∀n1,n2.n1 ≠ n2 → eq_oct n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_oct n1 n2));
+ napply (not_to_not (eq_oct n1 n2 = true) (n1 = n2) ? H);
+ napply (eqoct_to_eq n1 n2).
+nqed.
+
+nlemma decidable_oct : ∀x,y:oct.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_oct x y = true) (eq_oct x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqoct_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqoct_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqoct : symmetricT oct bool eq_oct.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_oct n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqoct n1 n2 H);
+          napply (symmetric_eq ? (eq_oct n2 n1) false);
+          napply (neq_to_neqoct n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/num/quatern.ma b/helm/software/matita/contribs/ng_assembly/num/quatern.ma
new file mode 100755 (executable)
index 0000000..a6bc134
--- /dev/null
@@ -0,0 +1,66 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/bool.ma".
+
+(* ********** *)
+(* QUATERNARI *)
+(* ********** *)
+
+ninductive quatern : Type ≝
+  q0 : quatern
+| q1 : quatern
+| q2 : quatern
+| q3 : quatern.
+
+(* operatore = *)
+ndefinition eq_qu ≝
+λn1,n2:quatern.
+ match n1 with
+  [ q0 ⇒ match n2 with [ q0 ⇒ true | _ ⇒ false ]
+  | q1 ⇒ match n2 with [ q1 ⇒ true | _ ⇒ false ]
+  | q2 ⇒ match n2 with [ q2 ⇒ true | _ ⇒ false ]
+  | q3 ⇒ match n2 with [ q3 ⇒ true | _ ⇒ false ]
+  ].
+
+(* iteratore sui quaternari *)
+ndefinition forall_qu ≝ λP.
+ P q0 ⊗ P q1 ⊗ P q2 ⊗ P q3.
+
+(* operatore successorre *)
+ndefinition succ_qu ≝
+λn.match n with
+ [ q0 ⇒ q1 | q1 ⇒ q2 | q2 ⇒ q3 | q3 ⇒ q0 ].
+
+(* quaternari ricorsivi *)
+ninductive rec_quatern : quatern → Type ≝
+  qu_O : rec_quatern q0
+| qu_S : ∀n.rec_quatern n → rec_quatern (succ_qu n).
+
+(* quaternari → quaternari ricorsivi *)
+ndefinition qu_to_recqu ≝
+λn.match n return λx.rec_quatern x with
+ [ q0 ⇒ qu_O
+ | q1 ⇒ qu_S ? qu_O
+ | q2 ⇒ qu_S ? (qu_S ? qu_O)
+ | q3 ⇒ qu_S ? (qu_S ? (qu_S ? qu_O))
+ ].
diff --git a/helm/software/matita/contribs/ng_assembly/num/quatern_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/quatern_lemmas.ma
new file mode 100755 (executable)
index 0000000..a3ff945
--- /dev/null
@@ -0,0 +1,93 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/quatern.ma".
+include "num/bool_lemmas.ma".
+
+(* ********** *)
+(* QUATERNARI *)
+(* ********** *)
+
+(*
+ndefinition quatern_destruct_aux ≝
+Πn1,n2:quatern.ΠP:Prop.n1 = n2 →
+ match eq_qu n1 n2 with [ true ⇒ P → P | false ⇒ P ].
+
+ndefinition quatern_destruct : quatern_destruct_aux.
+ #n1; #n2; #P; #H;
+ nrewrite < H;
+ nelim n1;
+ nnormalize;
+ napply (λx.x).
+nqed.
+*)
+
+nlemma eq_to_eqqu : ∀n1,n2.n1 = n2 → eq_qu n1 n2 = true.
+ #n1; #n2; #H;
+ nrewrite > H;
+ nelim n2;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma neqqu_to_neq : ∀n1,n2.eq_qu n1 n2 = false → n1 ≠ n2.
+ #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_qu n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqqu n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+nlemma eqqu_to_eq : ∀n1,n2.eq_qu n1 n2 = true → n1 = n2.
+ #n1; #n2;
+ ncases n1;
+ ncases n2;
+ nnormalize;
+ ##[ ##1,6,11,16: #H; napply refl_eq
+ ##| ##*: #H; ndestruct (*napply (bool_destruct … H)*)
+ ##]
+nqed.
+
+nlemma neq_to_neqqu : ∀n1,n2.n1 ≠ n2 → eq_qu n1 n2 = false.
+ #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_qu n1 n2));
+ napply (not_to_not (eq_qu n1 n2 = true) (n1 = n2) ? H);
+ napply (eqqu_to_eq n1 n2).
+nqed.
+
+nlemma decidable_qu : ∀x,y:quatern.decidable (x = y).
+ #x; #y; nnormalize;
+ napply (or2_elim (eq_qu x y = true) (eq_qu x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqqu_to_eq … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqqu_to_neq … H))
+ ##]
+nqed.
+
+nlemma symmetric_eqqu : symmetricT quatern bool eq_qu.
+ #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_qu n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqqu n1 n2 H);
+          napply (symmetric_eq ? (eq_qu n2 n1) false);
+          napply (neq_to_neqqu n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/num/word16.ma b/helm/software/matita/contribs/ng_assembly/num/word16.ma
new file mode 100755 (executable)
index 0000000..e89e64f
--- /dev/null
@@ -0,0 +1,763 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/byte8.ma".
+
+(* **** *)
+(* WORD *)
+(* **** *)
+
+nrecord word16 : Type ≝
+ {
+ w16h: byte8;
+ w16l: byte8
+ }.
+
+(* \langle \rangle *)
+notation "〈x:y〉" non associative with precedence 80
+ for @{ 'mk_word16 $x $y }.
+interpretation "mk_word16" 'mk_word16 x y = (mk_word16 x y).
+
+(* operatore = *)
+ndefinition eq_w16 ≝ λw1,w2.(eq_b8 (w16h w1) (w16h w2)) ⊗ (eq_b8 (w16l w1) (w16l w2)).
+
+(* operatore < *)
+ndefinition lt_w16 ≝
+λw1,w2:word16.
+ (lt_b8 (w16h w1) (w16h w2)) ⊕
+ ((eq_b8 (w16h w1) (w16h w2)) ⊗ (lt_b8 (w16l w1) (w16l w2))).
+
+(* operatore ≤ *)
+ndefinition le_w16 ≝
+λw1,w2:word16.
+ (lt_b8 (w16h w1) (w16h w2)) ⊕
+ ((eq_b8 (w16h w1) (w16h w2)) ⊗ (le_b8 (w16l w1) (w16l w2))).
+
+(* operatore > *)
+ndefinition gt_w16 ≝
+λw1,w2:word16.
+ (gt_b8 (w16h w1) (w16h w2)) ⊕
+ ((eq_b8 (w16h w1) (w16h w2)) ⊗ (gt_b8 (w16l w1) (w16l w2))).
+
+(* operatore ≥ *)
+ndefinition ge_w16 ≝
+λw1,w2:word16.
+ (gt_b8 (w16h w1) (w16h w2)) ⊕
+ ((eq_b8 (w16h w1) (w16h w2)) ⊗ (ge_b8 (w16l w1) (w16l w2))).
+
+(* operatore and *)
+ndefinition and_w16 ≝
+λw1,w2:word16.mk_word16 (and_b8 (w16h w1) (w16h w2)) (and_b8 (w16l w1) (w16l w2)).
+
+(* operatore or *)
+ndefinition or_w16 ≝
+λw1,w2:word16.mk_word16 (or_b8 (w16h w1) (w16h w2)) (or_b8 (w16l w1) (w16l w2)).
+
+(* operatore xor *)
+ndefinition xor_w16 ≝
+λw1,w2:word16.mk_word16 (xor_b8 (w16h w1) (w16h w2)) (xor_b8 (w16l w1) (w16l w2)).
+
+(* operatore rotazione destra con carry *)
+ndefinition rcr_w16 ≝
+λw:word16.λc:bool.match rcr_b8 (w16h w) c with
+ [ pair wh' c' ⇒ match rcr_b8 (w16l w) c' with
+  [ pair wl' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]]. 
+
+(* operatore shift destro *)
+ndefinition shr_w16 ≝
+λw:word16.match rcr_b8 (w16h w) false with
+ [ pair wh' c' ⇒ match rcr_b8 (w16l w) c' with
+  [ pair wl' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]].
+
+(* operatore rotazione destra *)
+ndefinition ror_w16 ≝
+λw:word16.match rcr_b8 (w16h w) false with
+ [ pair wh' c' ⇒ match rcr_b8 (w16l w) c' with
+  [ pair wl' c'' ⇒ match c'' with
+   [ true ⇒ mk_word16 (or_b8 (mk_byte8 x8 x0) wh') wl'
+   | false ⇒ mk_word16 wh' wl' ]]].
+
+(* operatore rotazione destra n-volte *)
+nlet rec ror_w16_n (w:word16) (n:nat) on n ≝
+ match n with
+  [ O ⇒ w
+  | S n' ⇒ ror_w16_n (ror_w16 w) n' ].
+
+(* operatore rotazione sinistra con carry *)
+ndefinition rcl_w16 ≝
+λw:word16.λc:bool.match rcl_b8 (w16l w) c with
+ [ pair wl' c' ⇒ match rcl_b8 (w16h w) c' with
+  [ pair wh' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]]. 
+
+(* operatore shift sinistro *)
+ndefinition shl_w16 ≝
+λw:word16.match rcl_b8 (w16l w) false with
+ [ pair wl' c' ⇒ match rcl_b8 (w16h w) c' with
+  [ pair wh' c'' ⇒ pair … (mk_word16 wh' wl') c'' ]].
+
+(* operatore rotazione sinistra *)
+ndefinition rol_w16 ≝
+λw:word16.match rcl_b8 (w16l w) false with
+ [ pair wl' c' ⇒ match rcl_b8 (w16h w) c' with
+  [ pair wh' c'' ⇒ match c'' with
+   [ true ⇒ mk_word16 wh' (or_b8 (mk_byte8 x0 x1) wl')
+   | false ⇒ mk_word16 wh' wl' ]]].
+
+(* operatore rotazione sinistra n-volte *)
+nlet rec rol_w16_n (w:word16) (n:nat) on n ≝
+ match n with
+  [ O ⇒ w
+  | S n' ⇒ rol_w16_n (rol_w16 w) n' ].
+
+(* operatore not/complemento a 1 *)
+ndefinition not_w16 ≝
+λw:word16.mk_word16 (not_b8 (w16h w)) (not_b8 (w16l w)).
+
+(* operatore somma con data+carry → data+carry *)
+ndefinition plus_w16_dc_dc ≝
+λw1,w2:word16.λc:bool.
+ match plus_b8_dc_dc (w16l w1) (w16l w2) c with
+  [ pair l c ⇒ match plus_b8_dc_dc (w16h w1) (w16h w2) c with
+   [ pair h c' ⇒ pair … 〈h:l〉 c' ]].
+
+(* operatore somma con data+carry → data *)
+ndefinition plus_w16_dc_d ≝
+λw1,w2:word16.λc:bool.
+ match plus_b8_dc_dc (w16l w1) (w16l w2) c with
+  [ pair l c ⇒ 〈plus_b8_dc_d (w16h w1) (w16h w2) c:l〉 ].
+
+(* operatore somma con data+carry → c *)
+ndefinition plus_w16_dc_c ≝
+λw1,w2:word16.λc:bool.
+ plus_b8_dc_c (w16h w1) (w16h w2) (plus_b8_dc_c (w16l w1) (w16l w2) c).
+
+(* operatore somma con data → data+carry *)
+ndefinition plus_w16_d_dc ≝
+λw1,w2:word16.
+ match plus_b8_d_dc (w16l w1) (w16l w2) with
+  [ pair l c ⇒ match plus_b8_dc_dc (w16h w1) (w16h w2) c with
+   [ pair h c' ⇒ pair … 〈h:l〉 c' ]].
+
+(* operatore somma con data → data *)
+ndefinition plus_w16_d_d ≝
+λw1,w2:word16.
+ match plus_b8_d_dc (w16l w1) (w16l w2) with
+  [ pair l c ⇒ 〈plus_b8_dc_d (w16h w1) (w16h w2) c:l〉 ].
+
+(* operatore somma con data → c *)
+ndefinition plus_w16_d_c ≝
+λw1,w2:word16.
+ plus_b8_dc_c (w16h w1) (w16h w2) (plus_b8_d_c (w16l w1) (w16l w2)).
+
+(* operatore Most Significant Bit *)
+ndefinition MSB_w16 ≝ λw:word16.eq_ex x8 (and_ex x8 (b8h (w16h w))).
+
+(* operatore predecessore *)
+ndefinition pred_w16 ≝
+λw:word16.match eq_b8 (w16l w) (mk_byte8 x0 x0) with
+ [ true ⇒ mk_word16 (pred_b8 (w16h w)) (pred_b8 (w16l w))
+ | false ⇒ mk_word16 (w16h w) (pred_b8 (w16l w)) ].
+
+(* operatore successore *)
+ndefinition succ_w16 ≝
+λw:word16.match eq_b8 (w16l w) (mk_byte8 xF xF) with
+ [ true ⇒ mk_word16 (succ_b8 (w16h w)) (succ_b8 (w16l w))
+ | false ⇒ mk_word16 (w16h w) (succ_b8 (w16l w)) ].
+
+(* operatore neg/complemento a 2 *)
+ndefinition compl_w16 ≝
+λw:word16.match MSB_w16 w with
+ [ true ⇒ succ_w16 (not_w16 w)
+ | false ⇒ not_w16 (pred_w16 w) ].
+
+(* 
+   operatore moltiplicazione senza segno: b*b=[0x0000,0xFE01]
+   ... in pratica (〈a,b〉*〈c,d〉) = (a*c)<<8+(a*d)<<4+(b*c)<<4+(b*d)
+*)
+ndefinition mul_b8 ≝
+λb1,b2:byte8.match b1 with
+[ mk_byte8 b1h b1l ⇒ match b2 with
+[ mk_byte8 b2h b2l ⇒ match mul_ex b1l b2l with
+[ mk_byte8 t1_h t1_l ⇒ match mul_ex b1h b2l with
+[ mk_byte8 t2_h t2_l ⇒ match mul_ex b2h b1l with
+[ mk_byte8 t3_h t3_l ⇒ match mul_ex b1h b2h with
+[ mk_byte8 t4_h t4_l ⇒
+ plus_w16_d_d
+  (plus_w16_d_d
+   (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〉〉
+]]]]]].
+
+(* divisione senza segno (secondo la logica delle ALU): (quoziente resto) overflow *)
+nlet rec div_b8_aux (divd:word16) (divs:word16) (molt:byte8) (q:byte8) (c:nat) on c ≝
+ let w' ≝ plus_w16_d_d divd (compl_w16 divs) in
+  match c with
+  [ O ⇒ match le_w16 divs divd with
+   [ true ⇒ triple … (or_b8 molt q) (w16l w') (⊖ (eq_b8 (w16h w') 〈x0,x0〉))
+   | false ⇒ triple … q (w16l divd) (⊖ (eq_b8 (w16h divd) 〈x0,x0〉)) ]
+  | S c' ⇒ match le_w16 divs divd with
+   [ true ⇒ div_b8_aux w' (ror_w16 divs) (ror_b8 molt) (or_b8 molt q) c'
+   | false ⇒ div_b8_aux divd (ror_w16 divs) (ror_b8 molt) q c' ]].
+
+ndefinition div_b8 ≝
+λw:word16.λb:byte8.match eq_b8 b 〈x0,x0〉 with
+(* 
+   la combinazione n/0 e' illegale, segnala solo overflow senza dare risultato
+*)
+ [ true ⇒ triple … 〈xF,xF〉 (w16l w) true
+ | false ⇒ match eq_w16 w 〈〈x0,x0〉:〈x0,x0〉〉 with
+(* 0 diviso qualsiasi cosa diverso da 0 da' q=0 r=0 o=false *)
+  [ true ⇒ triple … 〈x0,x0〉 〈x0,x0〉 false
+(* 1) e' una divisione sensata che produrra' overflow/risultato *)
+(* 2) parametri: dividendo, divisore, moltiplicatore, quoziente, contatore *)
+(* 3) ad ogni ciclo il divisore e il moltiplicatore vengono scalati di 1 a dx *)
+(* 4) il moltiplicatore e' la quantita' aggiunta al quoziente se il divisore *)
+(*    puo' essere sottratto al dividendo *) 
+  | false ⇒ div_b8_aux w (rol_w16_n 〈〈x0,x0〉:b〉 nat7) 〈x8,x0〉 〈x0,x0〉 nat7 ]].
+
+(* operatore x in [inf,sup] o in sup],[inf *)
+ndefinition inrange_w16 ≝
+λx,inf,sup:word16.
+ match le_w16 inf sup with
+  [ true ⇒ and_bool | false ⇒ or_bool ]
+ (le_w16 inf x) (le_w16 x sup).
+
+(* iteratore sulle word *)
+ndefinition forall_w16 ≝
+ λP.
+  forall_b8 (λbh.
+  forall_b8 (λbl.
+   P (mk_word16 bh bl ))).
+
+(* word16 ricorsive *)
+ninductive rec_word16 : word16 → Type ≝
+  w16_O : rec_word16 〈〈x0,x0〉:〈x0,x0〉〉
+| w16_S : ∀n.rec_word16 n → rec_word16 (succ_w16 n).
+
+(* word16 → word16 ricorsive *)
+
+(* EX: ancora problema di tempi ???
+ndefinition w16_to_recw16_aux1_1 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x1,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (
+ w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? (w16_S ? recw
+ ))))))))))))))).
+*)
+
+ndefinition w16_to_recw16_aux1_1 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x1,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x0,xF〉〉 (w16_S 〈n:〈x0,xE〉〉 (w16_S 〈n:〈x0,xD〉〉 (w16_S 〈n:〈x0,xC〉〉 (
+ w16_S 〈n:〈x0,xB〉〉 (w16_S 〈n:〈x0,xA〉〉 (w16_S 〈n:〈x0,x9〉〉 (w16_S 〈n:〈x0,x8〉〉 (
+ w16_S 〈n:〈x0,x7〉〉 (w16_S 〈n:〈x0,x6〉〉 (w16_S 〈n:〈x0,x5〉〉 (w16_S 〈n:〈x0,x4〉〉 (
+ w16_S 〈n:〈x0,x3〉〉 (w16_S 〈n:〈x0,x2〉〉 (w16_S 〈n:〈x0,x1〉〉 (w16_S 〈n:〈x0,x0〉〉 recw
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_2 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x2,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x1,xF〉〉 (w16_S 〈n:〈x1,xE〉〉 (w16_S 〈n:〈x1,xD〉〉 (w16_S 〈n:〈x1,xC〉〉 (
+ w16_S 〈n:〈x1,xB〉〉 (w16_S 〈n:〈x1,xA〉〉 (w16_S 〈n:〈x1,x9〉〉 (w16_S 〈n:〈x1,x8〉〉 (
+ w16_S 〈n:〈x1,x7〉〉 (w16_S 〈n:〈x1,x6〉〉 (w16_S 〈n:〈x1,x5〉〉 (w16_S 〈n:〈x1,x4〉〉 (
+ w16_S 〈n:〈x1,x3〉〉 (w16_S 〈n:〈x1,x2〉〉 (w16_S 〈n:〈x1,x1〉〉 (w16_S 〈n:〈x1,x0〉〉 (w16_to_recw16_aux1_1 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_3 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x3,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x2,xF〉〉 (w16_S 〈n:〈x2,xE〉〉 (w16_S 〈n:〈x2,xD〉〉 (w16_S 〈n:〈x2,xC〉〉 (
+ w16_S 〈n:〈x2,xB〉〉 (w16_S 〈n:〈x2,xA〉〉 (w16_S 〈n:〈x2,x9〉〉 (w16_S 〈n:〈x2,x8〉〉 (
+ w16_S 〈n:〈x2,x7〉〉 (w16_S 〈n:〈x2,x6〉〉 (w16_S 〈n:〈x2,x5〉〉 (w16_S 〈n:〈x2,x4〉〉 (
+ w16_S 〈n:〈x2,x3〉〉 (w16_S 〈n:〈x2,x2〉〉 (w16_S 〈n:〈x2,x1〉〉 (w16_S 〈n:〈x2,x0〉〉 (w16_to_recw16_aux1_2 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_4 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x4,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x3,xF〉〉 (w16_S 〈n:〈x3,xE〉〉 (w16_S 〈n:〈x3,xD〉〉 (w16_S 〈n:〈x3,xC〉〉 (
+ w16_S 〈n:〈x3,xB〉〉 (w16_S 〈n:〈x3,xA〉〉 (w16_S 〈n:〈x3,x9〉〉 (w16_S 〈n:〈x3,x8〉〉 (
+ w16_S 〈n:〈x3,x7〉〉 (w16_S 〈n:〈x3,x6〉〉 (w16_S 〈n:〈x3,x5〉〉 (w16_S 〈n:〈x3,x4〉〉 (
+ w16_S 〈n:〈x3,x3〉〉 (w16_S 〈n:〈x3,x2〉〉 (w16_S 〈n:〈x3,x1〉〉 (w16_S 〈n:〈x3,x0〉〉 (w16_to_recw16_aux1_3 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_5 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x5,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x4,xF〉〉 (w16_S 〈n:〈x4,xE〉〉 (w16_S 〈n:〈x4,xD〉〉 (w16_S 〈n:〈x4,xC〉〉 (
+ w16_S 〈n:〈x4,xB〉〉 (w16_S 〈n:〈x4,xA〉〉 (w16_S 〈n:〈x4,x9〉〉 (w16_S 〈n:〈x4,x8〉〉 (
+ w16_S 〈n:〈x4,x7〉〉 (w16_S 〈n:〈x4,x6〉〉 (w16_S 〈n:〈x4,x5〉〉 (w16_S 〈n:〈x4,x4〉〉 (
+ w16_S 〈n:〈x4,x3〉〉 (w16_S 〈n:〈x4,x2〉〉 (w16_S 〈n:〈x4,x1〉〉 (w16_S 〈n:〈x4,x0〉〉 (w16_to_recw16_aux1_4 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_6 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x6,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x5,xF〉〉 (w16_S 〈n:〈x5,xE〉〉 (w16_S 〈n:〈x5,xD〉〉 (w16_S 〈n:〈x5,xC〉〉 (
+ w16_S 〈n:〈x5,xB〉〉 (w16_S 〈n:〈x5,xA〉〉 (w16_S 〈n:〈x5,x9〉〉 (w16_S 〈n:〈x5,x8〉〉 (
+ w16_S 〈n:〈x5,x7〉〉 (w16_S 〈n:〈x5,x6〉〉 (w16_S 〈n:〈x5,x5〉〉 (w16_S 〈n:〈x5,x4〉〉 (
+ w16_S 〈n:〈x5,x3〉〉 (w16_S 〈n:〈x5,x2〉〉 (w16_S 〈n:〈x5,x1〉〉 (w16_S 〈n:〈x5,x0〉〉 (w16_to_recw16_aux1_5 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_7 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x7,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x6,xF〉〉 (w16_S 〈n:〈x6,xE〉〉 (w16_S 〈n:〈x6,xD〉〉 (w16_S 〈n:〈x6,xC〉〉 (
+ w16_S 〈n:〈x6,xB〉〉 (w16_S 〈n:〈x6,xA〉〉 (w16_S 〈n:〈x6,x9〉〉 (w16_S 〈n:〈x6,x8〉〉 (
+ w16_S 〈n:〈x6,x7〉〉 (w16_S 〈n:〈x6,x6〉〉 (w16_S 〈n:〈x6,x5〉〉 (w16_S 〈n:〈x6,x4〉〉 (
+ w16_S 〈n:〈x6,x3〉〉 (w16_S 〈n:〈x6,x2〉〉 (w16_S 〈n:〈x6,x1〉〉 (w16_S 〈n:〈x6,x0〉〉 (w16_to_recw16_aux1_6 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_8 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x8,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x7,xF〉〉 (w16_S 〈n:〈x7,xE〉〉 (w16_S 〈n:〈x7,xD〉〉 (w16_S 〈n:〈x7,xC〉〉 (
+ w16_S 〈n:〈x7,xB〉〉 (w16_S 〈n:〈x7,xA〉〉 (w16_S 〈n:〈x7,x9〉〉 (w16_S 〈n:〈x7,x8〉〉 (
+ w16_S 〈n:〈x7,x7〉〉 (w16_S 〈n:〈x7,x6〉〉 (w16_S 〈n:〈x7,x5〉〉 (w16_S 〈n:〈x7,x4〉〉 (
+ w16_S 〈n:〈x7,x3〉〉 (w16_S 〈n:〈x7,x2〉〉 (w16_S 〈n:〈x7,x1〉〉 (w16_S 〈n:〈x7,x0〉〉 (w16_to_recw16_aux1_7 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_9 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈x9,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x8,xF〉〉 (w16_S 〈n:〈x8,xE〉〉 (w16_S 〈n:〈x8,xD〉〉 (w16_S 〈n:〈x8,xC〉〉 (
+ w16_S 〈n:〈x8,xB〉〉 (w16_S 〈n:〈x8,xA〉〉 (w16_S 〈n:〈x8,x9〉〉 (w16_S 〈n:〈x8,x8〉〉 (
+ w16_S 〈n:〈x8,x7〉〉 (w16_S 〈n:〈x8,x6〉〉 (w16_S 〈n:〈x8,x5〉〉 (w16_S 〈n:〈x8,x4〉〉 (
+ w16_S 〈n:〈x8,x3〉〉 (w16_S 〈n:〈x8,x2〉〉 (w16_S 〈n:〈x8,x1〉〉 (w16_S 〈n:〈x8,x0〉〉 (w16_to_recw16_aux1_8 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_10 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xA,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈x9,xF〉〉 (w16_S 〈n:〈x9,xE〉〉 (w16_S 〈n:〈x9,xD〉〉 (w16_S 〈n:〈x9,xC〉〉 (
+ w16_S 〈n:〈x9,xB〉〉 (w16_S 〈n:〈x9,xA〉〉 (w16_S 〈n:〈x9,x9〉〉 (w16_S 〈n:〈x9,x8〉〉 (
+ w16_S 〈n:〈x9,x7〉〉 (w16_S 〈n:〈x9,x6〉〉 (w16_S 〈n:〈x9,x5〉〉 (w16_S 〈n:〈x9,x4〉〉 (
+ w16_S 〈n:〈x9,x3〉〉 (w16_S 〈n:〈x9,x2〉〉 (w16_S 〈n:〈x9,x1〉〉 (w16_S 〈n:〈x9,x0〉〉 (w16_to_recw16_aux1_9 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_11 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xB,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈xA,xF〉〉 (w16_S 〈n:〈xA,xE〉〉 (w16_S 〈n:〈xA,xD〉〉 (w16_S 〈n:〈xA,xC〉〉 (
+ w16_S 〈n:〈xA,xB〉〉 (w16_S 〈n:〈xA,xA〉〉 (w16_S 〈n:〈xA,x9〉〉 (w16_S 〈n:〈xA,x8〉〉 (
+ w16_S 〈n:〈xA,x7〉〉 (w16_S 〈n:〈xA,x6〉〉 (w16_S 〈n:〈xA,x5〉〉 (w16_S 〈n:〈xA,x4〉〉 (
+ w16_S 〈n:〈xA,x3〉〉 (w16_S 〈n:〈xA,x2〉〉 (w16_S 〈n:〈xA,x1〉〉 (w16_S 〈n:〈xA,x0〉〉 (w16_to_recw16_aux1_10 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_12 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xC,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈xB,xF〉〉 (w16_S 〈n:〈xB,xE〉〉 (w16_S 〈n:〈xB,xD〉〉 (w16_S 〈n:〈xB,xC〉〉 (
+ w16_S 〈n:〈xB,xB〉〉 (w16_S 〈n:〈xB,xA〉〉 (w16_S 〈n:〈xB,x9〉〉 (w16_S 〈n:〈xB,x8〉〉 (
+ w16_S 〈n:〈xB,x7〉〉 (w16_S 〈n:〈xB,x6〉〉 (w16_S 〈n:〈xB,x5〉〉 (w16_S 〈n:〈xB,x4〉〉 (
+ w16_S 〈n:〈xB,x3〉〉 (w16_S 〈n:〈xB,x2〉〉 (w16_S 〈n:〈xB,x1〉〉 (w16_S 〈n:〈xB,x0〉〉 (w16_to_recw16_aux1_11 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_13 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xD,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈xC,xF〉〉 (w16_S 〈n:〈xC,xE〉〉 (w16_S 〈n:〈xC,xD〉〉 (w16_S 〈n:〈xC,xC〉〉 (
+ w16_S 〈n:〈xC,xB〉〉 (w16_S 〈n:〈xC,xA〉〉 (w16_S 〈n:〈xC,x9〉〉 (w16_S 〈n:〈xC,x8〉〉 (
+ w16_S 〈n:〈xC,x7〉〉 (w16_S 〈n:〈xC,x6〉〉 (w16_S 〈n:〈xC,x5〉〉 (w16_S 〈n:〈xC,x4〉〉 (
+ w16_S 〈n:〈xC,x3〉〉 (w16_S 〈n:〈xC,x2〉〉 (w16_S 〈n:〈xC,x1〉〉 (w16_S 〈n:〈xC,x0〉〉 (w16_to_recw16_aux1_12 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_14 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xE,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈xD,xF〉〉 (w16_S 〈n:〈xD,xE〉〉 (w16_S 〈n:〈xD,xD〉〉 (w16_S 〈n:〈xD,xC〉〉 (
+ w16_S 〈n:〈xD,xB〉〉 (w16_S 〈n:〈xD,xA〉〉 (w16_S 〈n:〈xD,x9〉〉 (w16_S 〈n:〈xD,x8〉〉 (
+ w16_S 〈n:〈xD,x7〉〉 (w16_S 〈n:〈xD,x6〉〉 (w16_S 〈n:〈xD,x5〉〉 (w16_S 〈n:〈xD,x4〉〉 (
+ w16_S 〈n:〈xD,x3〉〉 (w16_S 〈n:〈xD,x2〉〉 (w16_S 〈n:〈xD,x1〉〉 (w16_S 〈n:〈xD,x0〉〉 (w16_to_recw16_aux1_13 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1_15 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈n:〈xF,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈xE,xF〉〉 (w16_S 〈n:〈xE,xE〉〉 (w16_S 〈n:〈xE,xD〉〉 (w16_S 〈n:〈xE,xC〉〉 (
+ w16_S 〈n:〈xE,xB〉〉 (w16_S 〈n:〈xE,xA〉〉 (w16_S 〈n:〈xE,x9〉〉 (w16_S 〈n:〈xE,x8〉〉 (
+ w16_S 〈n:〈xE,x7〉〉 (w16_S 〈n:〈xE,x6〉〉 (w16_S 〈n:〈xE,x5〉〉 (w16_S 〈n:〈xE,x4〉〉 (
+ w16_S 〈n:〈xE,x3〉〉 (w16_S 〈n:〈xE,x2〉〉 (w16_S 〈n:〈xE,x1〉〉 (w16_S 〈n:〈xE,x0〉〉 (w16_to_recw16_aux1_14 ? recw)
+ ))))))))))))))).
+
+ndefinition w16_to_recw16_aux1 : Πn.rec_word16 〈n:〈x0,x0〉〉 → rec_word16 〈(succ_b8 n):〈x0,x0〉〉 ≝
+λn.λrecw:rec_word16 〈n:〈x0,x0〉〉.
+ w16_S 〈n:〈xF,xF〉〉 (w16_S 〈n:〈xF,xE〉〉 (w16_S 〈n:〈xF,xD〉〉 (w16_S 〈n:〈xF,xC〉〉 (
+ w16_S 〈n:〈xF,xB〉〉 (w16_S 〈n:〈xF,xA〉〉 (w16_S 〈n:〈xF,x9〉〉 (w16_S 〈n:〈xF,x8〉〉 (
+ w16_S 〈n:〈xF,x7〉〉 (w16_S 〈n:〈xF,x6〉〉 (w16_S 〈n:〈xF,x5〉〉 (w16_S 〈n:〈xF,x4〉〉 (
+ w16_S 〈n:〈xF,x3〉〉 (w16_S 〈n:〈xF,x2〉〉 (w16_S 〈n:〈xF,x1〉〉 (w16_S 〈n:〈xF,x0〉〉 (w16_to_recw16_aux1_15 ? recw)
+ ))))))))))))))).
+
+(* ... cifra byte superiore *)
+nlet rec w16_to_recw16_aux2 (n:byte8) (r:rec_byte8 n) on r ≝
+ match r return λx.λy:rec_byte8 x.rec_word16 〈x:〈x0,x0〉〉 with
+  [ b8_O ⇒ w16_O
+  | b8_S t n' ⇒ w16_to_recw16_aux1 ? (w16_to_recw16_aux2 t n')
+  ].
+
+(* ... cifra esadecimale n.2 *)
+ndefinition w16_to_recw16_aux3 ≝
+λb,n.λrecw:rec_word16 〈b:〈x0,x0〉〉.
+ match n return λx.rec_word16 〈b:〈x,x0〉〉 with
+ [ x0 ⇒ recw
+ | x1 ⇒ w16_to_recw16_aux1_1 ? recw
+ | x2 ⇒ w16_to_recw16_aux1_2 ? recw
+ | x3 ⇒ w16_to_recw16_aux1_3 ? recw
+ | x4 ⇒ w16_to_recw16_aux1_4 ? recw
+ | x5 ⇒ w16_to_recw16_aux1_5 ? recw
+ | x6 ⇒ w16_to_recw16_aux1_6 ? recw
+ | x7 ⇒ w16_to_recw16_aux1_7 ? recw
+ | x8 ⇒ w16_to_recw16_aux1_8 ? recw
+ | x9 ⇒ w16_to_recw16_aux1_9 ? recw
+ | xA ⇒ w16_to_recw16_aux1_10 ? recw
+ | xB ⇒ w16_to_recw16_aux1_11 ? recw
+ | xC ⇒ w16_to_recw16_aux1_12 ? recw
+ | xD ⇒ w16_to_recw16_aux1_13 ? recw
+ | xE ⇒ w16_to_recw16_aux1_14 ? recw
+ | xF ⇒ w16_to_recw16_aux1_15 ? recw
+ ].
+
+ndefinition w16_to_recw16_aux4_1 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x1〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x1〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? recw
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? recw
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? recw
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? recw
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? recw
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? recw
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? recw
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? recw
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? recw
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? recw
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? recw
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? recw
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? recw
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? recw
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? recw
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? recw
+  ].
+
+ndefinition w16_to_recw16_aux4_2 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x2〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x2〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_1 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_3 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x3〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x3〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_2 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_4 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x4〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x4〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_3 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_5 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x5〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x5〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_4 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_6 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x6〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x6〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_5 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_7 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x7〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x7〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_6 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_8 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x8〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x8〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_7 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_9 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,x9〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,x9〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_8 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_10 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xA〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,xA〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_9 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_11 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xB〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,xB〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_10 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_12 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xC〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,xC〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_11 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_13 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xD〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,xD〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_12 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_14 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xE〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,xE〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_13 … recw)
+  ].
+
+ndefinition w16_to_recw16_aux4_15 : Πn,e.rec_word16 〈n:〈e,x0〉〉 → rec_word16 〈n:〈e,xF〉〉 ≝
+λn,e.
+ match e return λx.rec_word16 〈n:〈x,x0〉〉 → rec_word16 〈n:〈x,xF〉〉 with
+  [ x0 ⇒ λrecw:rec_word16 〈n:〈x0,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x1 ⇒ λrecw:rec_word16 〈n:〈x1,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x2 ⇒ λrecw:rec_word16 〈n:〈x2,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x3 ⇒ λrecw:rec_word16 〈n:〈x3,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x4 ⇒ λrecw:rec_word16 〈n:〈x4,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x5 ⇒ λrecw:rec_word16 〈n:〈x5,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x6 ⇒ λrecw:rec_word16 〈n:〈x6,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x7 ⇒ λrecw:rec_word16 〈n:〈x7,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x8 ⇒ λrecw:rec_word16 〈n:〈x8,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | x9 ⇒ λrecw:rec_word16 〈n:〈x9,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | xA ⇒ λrecw:rec_word16 〈n:〈xA,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | xB ⇒ λrecw:rec_word16 〈n:〈xB,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | xC ⇒ λrecw:rec_word16 〈n:〈xC,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | xD ⇒ λrecw:rec_word16 〈n:〈xD,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | xE ⇒ λrecw:rec_word16 〈n:〈xE,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  | xF ⇒ λrecw:rec_word16 〈n:〈xF,x0〉〉.w16_S ? (w16_to_recw16_aux4_14 … recw)
+  ].
+
+(* ... cifra esadecimale n.1 *)
+ndefinition w16_to_recw16_aux4 ≝
+λb,e,n.λrecw:rec_word16 〈b:〈e,x0〉〉.
+ match n return λx.rec_word16 〈b:〈e,x〉〉 with
+ [ x0 ⇒ recw
+ | x1 ⇒ w16_to_recw16_aux4_1 … recw
+ | x2 ⇒ w16_to_recw16_aux4_2 … recw
+ | x3 ⇒ w16_to_recw16_aux4_3 … recw
+ | x4 ⇒ w16_to_recw16_aux4_4 … recw
+ | x5 ⇒ w16_to_recw16_aux4_5 … recw
+ | x6 ⇒ w16_to_recw16_aux4_6 … recw
+ | x7 ⇒ w16_to_recw16_aux4_7 … recw
+ | x8 ⇒ w16_to_recw16_aux4_8 … recw
+ | x9 ⇒ w16_to_recw16_aux4_9 … recw
+ | xA ⇒ w16_to_recw16_aux4_10 … recw
+ | xB ⇒ w16_to_recw16_aux4_11 … recw
+ | xC ⇒ w16_to_recw16_aux4_12 … recw
+ | xD ⇒ w16_to_recw16_aux4_13 … recw
+ | xE ⇒ w16_to_recw16_aux4_14 … recw
+ | xF ⇒ w16_to_recw16_aux4_15 … recw
+ ].
+
+ndefinition w16_to_recw16 : Πw.rec_word16 w ≝
+λw.
+ match w with [ mk_word16 h l ⇒
+ match l with [ mk_byte8 lh ll ⇒
+  w16_to_recw16_aux4 h lh ll (w16_to_recw16_aux3 h lh (w16_to_recw16_aux2 h (b8_to_recb8 h))) ]].
diff --git a/helm/software/matita/contribs/ng_assembly/num/word16_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/word16_lemmas.ma
new file mode 100755 (executable)
index 0000000..2e38a06
--- /dev/null
@@ -0,0 +1,377 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+include "num/byte8_lemmas.ma".
+
+(* **** *)
+(* WORD *)
+(* **** *)
+
+nlemma word16_destruct_1 :
+∀x1,x2,y1,y2.
+ mk_word16 x1 y1 = mk_word16 x2 y2 → x1 = x2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_word16 x2 y2 with [ mk_word16 a _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma word16_destruct_2 :
+∀x1,x2,y1,y2.
+ mk_word16 x1 y1 = mk_word16 x2 y2 → y1 = y2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_word16 x2 y2 with [ mk_word16 _ b ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqw16 : symmetricT word16 bool eq_w16.
+ #w1; #w2;
+ nelim w1;
+ nelim w2;
+ #b1; #b2; #b3; #b4;
+ nchange with (((eq_b8 b3 b1)⊗(eq_b8 b4 b2)) = ((eq_b8 b1 b3)⊗(eq_b8 b2 b4)));
+ nrewrite > (symmetric_eqb8 b1 b3);
+ nrewrite > (symmetric_eqb8 b2 b4);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_andw16 : symmetricT word16 word16 and_w16.
+ #w1; #w2;
+ nelim w1;
+ nelim w2;
+ #b1; #b2; #b3; #b4;
+ nchange with ((mk_word16 (and_b8 b3 b1) (and_b8 b4 b2)) = (mk_word16 (and_b8 b1 b3) (and_b8 b2 b4)));
+ nrewrite > (symmetric_andb8 b1 b3);
+ nrewrite > (symmetric_andb8 b2 b4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_andw16 : ∀w1,w2,w3.(and_w16 (and_w16 w1 w2) w3) = (and_w16 w1 (and_w16 w2 w3)).
+ #w1; #w2; #w3;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nelim w3;
+ #b5; #b6;
+ nchange with (mk_word16 (and_b8 (and_b8 b1 b3) b5) (and_b8 (and_b8 b2 b4) b6) =
+  mk_word16 (and_b8 b1 (and_b8 b3 b5)) (and_b8 b2 (and_b8 b4 b6)));
+ nrewrite < (associative_andb8 b1 b3 b5);
+ nrewrite < (associative_andb8 b2 b4 b6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_orw16 : symmetricT word16 word16 or_w16.
+ #w1; #w2;
+ nelim w1;
+ nelim w2;
+ #b1; #b2; #b3; #b4;
+ nchange with ((mk_word16 (or_b8 b3 b1) (or_b8 b4 b2)) = (mk_word16 (or_b8 b1 b3) (or_b8 b2 b4)));
+ nrewrite > (symmetric_orb8 b1 b3);
+ nrewrite > (symmetric_orb8 b2 b4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_orw16 : ∀w1,w2,w3.(or_w16 (or_w16 w1 w2) w3) = (or_w16 w1 (or_w16 w2 w3)).
+ #w1; #w2; #w3;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nelim w3;
+ #b5; #b6;
+ nchange with (mk_word16 (or_b8 (or_b8 b1 b3) b5) (or_b8 (or_b8 b2 b4) b6) =
+  mk_word16 (or_b8 b1 (or_b8 b3 b5)) (or_b8 b2 (or_b8 b4 b6)));
+ nrewrite < (associative_orb8 b1 b3 b5);
+ nrewrite < (associative_orb8 b2 b4 b6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_xorw16 : symmetricT word16 word16 xor_w16.
+ #w1; #w2;
+ nelim w1;
+ nelim w2;
+ #b1; #b2; #b3; #b4;
+ nchange with ((mk_word16 (xor_b8 b3 b1) (xor_b8 b4 b2)) = (mk_word16 (xor_b8 b1 b3) (xor_b8 b2 b4)));
+ nrewrite > (symmetric_xorb8 b1 b3);
+ nrewrite > (symmetric_xorb8 b2 b4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_xorw16 : ∀w1,w2,w3.(xor_w16 (xor_w16 w1 w2) w3) = (xor_w16 w1 (xor_w16 w2 w3)).
+ #w1; #w2; #w3;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nelim w3;
+ #b5; #b6;
+ nchange with (mk_word16 (xor_b8 (xor_b8 b1 b3) b5) (xor_b8 (xor_b8 b2 b4) b6) =
+  mk_word16 (xor_b8 b1 (xor_b8 b3 b5)) (xor_b8 b2 (xor_b8 b4 b6)));
+ nrewrite < (associative_xorb8 b1 b3 b5);
+ nrewrite < (associative_xorb8 b2 b4 b6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw16_dc_dc : ∀w1,w2,c.plus_w16_dc_dc w1 w2 c = plus_w16_dc_dc w2 w1 c.
+ #w1; #w2; #c;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nchange with (
+  match plus_b8_dc_dc b2 b4 c with [ pair l c ⇒ match plus_b8_dc_dc b1 b3 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]] =
+  match plus_b8_dc_dc b4 b2 c with [ pair l c ⇒ match plus_b8_dc_dc b3 b1 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]]);
+ nrewrite > (symmetric_plusb8_dc_dc b4 b2 c);
+ ncases (plus_b8_dc_dc b2 b4 c);
+ #b5; #c1;
+ nchange with (
+  match plus_b8_dc_dc b1 b3 c1 with [ pair h c' ⇒ pair … 〈h:b5〉 c' ] =
+  match plus_b8_dc_dc b3 b1 c1 with [ pair h c' ⇒ pair … 〈h:b5〉 c' ]);
+ nrewrite > (symmetric_plusb8_dc_dc b1 b3 c1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw16_dc_d : ∀w1,w2,c.plus_w16_dc_d w1 w2 c = plus_w16_dc_d w2 w1 c.
+ #w1; #w2; #c;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nchange with (
+  match plus_b8_dc_dc b2 b4 c with [ pair l c ⇒ 〈plus_b8_dc_d b1 b3 c:l〉 ] =
+  match plus_b8_dc_dc b4 b2 c with [ pair l c ⇒ 〈plus_b8_dc_d b3 b1 c:l〉 ]);
+ nrewrite > (symmetric_plusb8_dc_dc b4 b2 c);
+ ncases (plus_b8_dc_dc b2 b4 c);
+ #b5; #c1;
+ nchange with (〈plus_b8_dc_d b1 b3 c1:b5〉 = 〈plus_b8_dc_d b3 b1 c1:b5〉);
+ nrewrite > (symmetric_plusb8_dc_d b1 b3 c1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw16_dc_c : ∀w1,w2,c.plus_w16_dc_c w1 w2 c = plus_w16_dc_c w2 w1 c.
+ #w1; #w2; #c;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nchange with (
+  plus_b8_dc_c b1 b3 (plus_b8_dc_c b2 b4 c) =
+  plus_b8_dc_c b3 b1 (plus_b8_dc_c b4 b2 c));
+ nrewrite > (symmetric_plusb8_dc_c b4 b2 c);
+ nrewrite > (symmetric_plusb8_dc_c b3 b1 (plus_b8_dc_c b2 b4 c));
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw16_d_dc : ∀w1,w2.plus_w16_d_dc w1 w2 = plus_w16_d_dc w2 w1.
+ #w1; #w2;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nchange with (
+  match plus_b8_d_dc b2 b4 with [ pair l c ⇒ match plus_b8_dc_dc b1 b3 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]] =
+  match plus_b8_d_dc b4 b2 with [ pair l c ⇒ match plus_b8_dc_dc b3 b1 c with [ pair h c' ⇒ pair … 〈h:l〉 c' ]]);
+ nrewrite > (symmetric_plusb8_d_dc b4 b2);
+ ncases (plus_b8_d_dc b2 b4);
+ #b5; #c;
+ nchange with (
+  match plus_b8_dc_dc b1 b3 c with [ pair h c' ⇒ pair … 〈h:b5〉 c' ] =
+  match plus_b8_dc_dc b3 b1 c with [ pair h c' ⇒ pair … 〈h:b5〉 c' ]);
+ nrewrite > (symmetric_plusb8_dc_dc b1 b3 c);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw16_d_d : ∀w1,w2.plus_w16_d_d w1 w2 = plus_w16_d_d w2 w1.
+ #w1; #w2;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nchange with (
+  match plus_b8_d_dc b2 b4 with [ pair l c ⇒ 〈plus_b8_dc_d b1 b3 c:l〉 ] =
+  match plus_b8_d_dc b4 b2 with [ pair l c ⇒ 〈plus_b8_dc_d b3 b1 c:l〉 ]);
+ nrewrite > (symmetric_plusb8_d_dc b4 b2);
+ ncases (plus_b8_d_dc b2 b4);
+ #b5; #c;
+ nchange with (〈plus_b8_dc_d b1 b3 c:b5〉 = 〈plus_b8_dc_d b3 b1 c:b5〉);
+ nrewrite > (symmetric_plusb8_dc_d b1 b3 c);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw16_d_c : ∀w1,w2.plus_w16_d_c w1 w2 = plus_w16_d_c w2 w1.
+ #w1; #w2;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nchange with (
+  plus_b8_dc_c b1 b3 (plus_b8_d_c b2 b4) =
+  plus_b8_dc_c b3 b1 (plus_b8_d_c b4 b2));
+ nrewrite > (symmetric_plusb8_d_c b4 b2);
+ nrewrite > (symmetric_plusb8_dc_c b3 b1 (plus_b8_d_c b2 b4));
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_mulb8 : symmetricT byte8 word16 mul_b8.
+ #b1; #b2;
+ nelim b1;
+ #e1; #e2;
+ nelim b2;
+ #e3; #e4;
+ nchange with (match mul_ex e2 e4 with
+ [ mk_byte8 t1_h t1_l ⇒ match mul_ex e1 e4 with
+ [ mk_byte8 t2_h t2_l ⇒ match mul_ex e3 e2 with
+ [ mk_byte8 t3_h t3_l ⇒ match mul_ex e1 e3 with
+ [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (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〉〉
+ ]]]] = match mul_ex e4 e2 with
+ [ mk_byte8 t1_h t1_l ⇒ match mul_ex e3 e2 with
+ [ mk_byte8 t2_h t2_l ⇒ match mul_ex e1 e4 with
+ [ mk_byte8 t3_h t3_l ⇒ match mul_ex e3 e1 with
+ [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (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〉〉
+ ]]]]);
+ nrewrite < (symmetric_mulex e2 e4);
+ ncases (mul_ex e2 e4);
+ #e5; #e6;
+ nchange with (match mul_ex e1 e4 with
+ [ mk_byte8 t2_h t2_l ⇒ match mul_ex e3 e2 with
+ [ mk_byte8 t3_h t3_l ⇒ match mul_ex e1 e3 with
+ [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,t3_h〉:〈t3_l,x0〉〉 〈〈x0,t2_h〉:〈t2_l,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
+ ]]] = match mul_ex e3 e2 with
+ [ mk_byte8 t2_h t2_l ⇒ match mul_ex e1 e4 with
+ [ mk_byte8 t3_h t3_l ⇒ match mul_ex e3 e1 with
+ [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,t3_h〉:〈t3_l,x0〉〉 〈〈x0,t2_h〉:〈t2_l,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
+ ]]]);
+ ncases (mul_ex e3 e2);
+ #e7; #e8;
+ ncases (mul_ex e1 e4);
+ #e9; #e10;
+ nchange with (match mul_ex e1 e3 with
+ [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e7〉:〈e8,x0〉〉 〈〈x0,e9〉:〈e10,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
+ ] = match mul_ex e3 e1 with
+ [ mk_byte8 t4_h t4_l ⇒ plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e9〉:〈e10,x0〉〉 〈〈x0,e7〉:〈e8,x0〉〉) 〈〈t4_h,t4_l〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉
+ ]);
+ nrewrite < (symmetric_mulex e1 e3);
+ ncases (mul_ex e1 e3);
+ #e11; #e12;
+ nchange with ((plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e7〉:〈e8,x0〉〉 〈〈x0,e9〉:〈e10,x0〉〉) 〈〈e11,e12〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉) =
+  (plus_w16_d_d (plus_w16_d_d (plus_w16_d_d 〈〈x0,e9〉:〈e10,x0〉〉 〈〈x0,e7〉:〈e8,x0〉〉) 〈〈e11,e12〉:〈x0,x0〉〉)〈〈x0,x0〉:〈e5,e6〉〉));
+ nrewrite > (symmetric_plusw16_d_d 〈〈x0,e7〉:〈e8,x0〉〉 〈〈x0,e9〉:〈e10,x0〉〉);
+ napply refl_eq.
+nqed.
+
+nlemma eqw16_to_eq : ∀w1,w2:word16.(eq_w16 w1 w2 = true) → (w1 = w2).
+ #w1; #w2;
+ nelim w1;
+ nelim w2;
+ #b1; #b2; #b3; #b4;
+ nchange in ⊢ (% → ?) with (((eq_b8 b3 b1)⊗(eq_b8 b4 b2)) = true);
+ #H;
+ nrewrite < (eqb8_to_eq … (andb_true_true_l … H));
+ nrewrite < (eqb8_to_eq … (andb_true_true_r … H));
+ napply refl_eq.
+nqed.
+
+nlemma eq_to_eqw16 : ∀w1,w2.w1 = w2 → eq_w16 w1 w2 = true.
+ #w1; #w2;
+ nelim w1;
+ nelim w2;
+ #b1; #b2; #b3; #b4;
+ #H;
+ nrewrite < (word16_destruct_1 … H);
+ nrewrite < (word16_destruct_2 … H);
+ nchange with (((eq_b8 b3 b3)⊗(eq_b8 b4 b4)) = true);
+ nrewrite > (eq_to_eqb8 b3 b3 (refl_eq …));
+ nrewrite > (eq_to_eqb8 b4 b4 (refl_eq …)); 
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma decidable_w16_aux1 : ∀b1,b2,b3,b4.b1 ≠ b3 → 〈b1:b2〉 ≠ 〈b3:b4〉.
+ #b1; #b2; #b3; #b4;
+ nnormalize; #H; #H1;
+ napply (H (word16_destruct_1 … H1)).
+nqed.
+
+nlemma decidable_w16_aux2 : ∀b1,b2,b3,b4.b2 ≠ b4 → 〈b1:b2〉 ≠ 〈b3:b4〉.
+ #b1; #b2; #b3; #b4;
+ nnormalize; #H; #H1;
+ napply (H (word16_destruct_2 … H1)).
+nqed.
+
+nlemma decidable_w16 : ∀x,y:word16.decidable (x = y).
+ #x; nelim x; #b1; #b2;
+ #y; nelim y; #b3; #b4;
+ nnormalize;
+ napply (or2_elim (b1 = b3) (b1 ≠ b3) ? (decidable_b8 b1 b3) …);
+ ##[ ##2: #H; napply (or2_intro2 … (decidable_w16_aux1 b1 b2 b3 b4 H))
+ ##| ##1: #H; napply (or2_elim (b2 = b4) (b2 ≠ b4) ? (decidable_b8 b2 b4) …);
+          ##[ ##2: #H1; napply (or2_intro2 … (decidable_w16_aux2 b1 b2 b3 b4 H1))
+          ##| ##1: #H1; nrewrite > H; nrewrite > H1;
+                        napply (or2_intro1 … (refl_eq ? 〈b3:b4〉))
+          ##]
+ ##]
+nqed.
+
+nlemma neqw16_to_neq : ∀w1,w2:word16.(eq_w16 w1 w2 = false) → (w1 ≠ w2).
+ #w1; #w2;
+ nelim w1;
+ nelim w2;
+ #b1; #b2; #b3; #b4;
+ nchange with ((((eq_b8 b3 b1) ⊗ (eq_b8 b4 b2)) = false) → ?);
+ #H;
+ napply (or2_elim ((eq_b8 b3 b1) = false) ((eq_b8 b4 b2) = false) ? (andb_false2 … H) …);
+ ##[ ##1: #H1; napply (decidable_w16_aux1 … (neqb8_to_neq … H1))
+ ##| ##2: #H1; napply (decidable_w16_aux2 … (neqb8_to_neq … H1))
+ ##]
+nqed.
+
+nlemma word16_destruct : ∀b1,b2,b3,b4.〈b1:b2〉 ≠ 〈b3:b4〉 → b1 ≠ b3 ∨ b2 ≠ b4.
+ #b1; #b2; #b3; #b4;
+ nnormalize; #H;
+ napply (or2_elim (b1 = b3) (b1 ≠ b3) ? (decidable_b8 b1 b3) …);
+ ##[ ##2: #H1; napply (or2_intro1 … H1)
+ ##| ##1: #H1; napply (or2_elim (b2 = b4) (b2 ≠ b4) ? (decidable_b8 b2 b4) …);
+          ##[ ##2: #H2; napply (or2_intro2 … H2)
+          ##| ##1: #H2; nrewrite > H1 in H:(%);
+                   nrewrite > H2;
+                   #H; nelim (H (refl_eq …))
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqw16 : ∀w1,w2.w1 ≠ w2 → eq_w16 w1 w2 = false.
+ #w1; #w2;
+ nelim w1; #b1; #b2;
+ nelim w2; #b3; #b4;
+ #H; nchange with (((eq_b8 b1 b3) ⊗ (eq_b8 b2 b4)) = false);
+ napply (or2_elim (b1 ≠ b3) (b2 ≠ b4) ? (word16_destruct … H) …);
+ ##[ ##1: #H1; nrewrite > (neq_to_neqb8 … H1); nnormalize; napply refl_eq
+ ##| ##2: #H1; nrewrite > (neq_to_neqb8 … H1);
+          nrewrite > (symmetric_andbool (eq_b8 b1 b3) false);
+          nnormalize; napply refl_eq
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/num/word32.ma b/helm/software/matita/contribs/ng_assembly/num/word32.ma
new file mode 100755 (executable)
index 0000000..bc81cac
--- /dev/null
@@ -0,0 +1,248 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word16.ma".
+
+(* ***** *)
+(* DWORD *)
+(* ***** *)
+
+nrecord word32 : Type ≝
+ {
+ w32h: word16;
+ w32l: word16
+ }.
+
+(* \langle \rangle *)
+notation "〈x.y〉" non associative with precedence 80
+ for @{ 'mk_word32 $x $y }.
+interpretation "mk_word32" 'mk_word32 x y = (mk_word32 x y).
+
+(* operatore = *)
+ndefinition eq_w32 ≝ λdw1,dw2.(eq_w16 (w32h dw1) (w32h dw2)) ⊗ (eq_w16 (w32l dw1) (w32l dw2)).
+
+(* operatore < *)
+ndefinition lt_w32 ≝
+λdw1,dw2:word32.
+ (lt_w16 (w32h dw1) (w32h dw2)) ⊕
+ ((eq_w16 (w32h dw1) (w32h dw2)) ⊗ (lt_w16 (w32l dw1) (w32l dw2))).
+
+(* operatore ≤ *)
+ndefinition le_w32 ≝
+λdw1,dw2:word32.
+ (lt_w16 (w32h dw1) (w32h dw2)) ⊕
+ ((eq_w16 (w32h dw1) (w32h dw2)) ⊗ (le_w16 (w32l dw1) (w32l dw2))).
+
+(* operatore > *)
+ndefinition gt_w32 ≝
+λdw1,dw2:word32.
+ (gt_w16 (w32h dw1) (w32h dw2)) ⊕
+ ((eq_w16 (w32h dw1) (w32h dw2)) ⊗ (gt_w16 (w32l dw1) (w32l dw2))).
+
+(* operatore ≥ *)
+ndefinition ge_w32 ≝
+λdw1,dw2:word32.
+ (gt_w16 (w32h dw1) (w32h dw2)) ⊕
+ ((eq_w16 (w32h dw1) (w32h dw2)) ⊗ (ge_w16 (w32l dw1) (w32l dw2))).
+
+(* operatore and *)
+ndefinition and_w32 ≝
+λdw1,dw2:word32.mk_word32 (and_w16 (w32h dw1) (w32h dw2)) (and_w16 (w32l dw1) (w32l dw2)).
+
+(* operatore or *)
+ndefinition or_w32 ≝
+λdw1,dw2:word32.mk_word32 (or_w16 (w32h dw1) (w32h dw2)) (or_w16 (w32l dw1) (w32l dw2)).
+
+(* operatore xor *)
+ndefinition xor_w32 ≝
+λdw1,dw2:word32.mk_word32 (xor_w16 (w32h dw1) (w32h dw2)) (xor_w16 (w32l dw1) (w32l dw2)).
+
+(* operatore rotazione destra con carry *)
+ndefinition rcr_w32 ≝
+λdw:word32.λc:bool.match rcr_w16 (w32h dw) c with
+ [ pair wh' c' ⇒ match rcr_w16 (w32l dw) c' with
+  [ pair wl' c'' ⇒ pair … (mk_word32 wh' wl') c'' ]]. 
+
+(* operatore shift destro *)
+ndefinition shr_w32 ≝
+λdw:word32.match rcr_w16 (w32h dw) false with
+ [ pair wh' c' ⇒ match rcr_w16 (w32l dw) c' with
+  [ pair wl' c'' ⇒ pair … (mk_word32 wh' wl') c'' ]].
+
+(* operatore rotazione destra *)
+ndefinition ror_w32 ≝
+λdw:word32.match rcr_w16 (w32h dw) false with
+ [ pair wh' c' ⇒ match rcr_w16 (w32l dw) c' with
+  [ pair wl' c'' ⇒ match c'' with
+   [ true ⇒ mk_word32 (or_w16 (mk_word16 (mk_byte8 x8 x0) (mk_byte8 x0 x0)) wh') wl'
+   | false ⇒ mk_word32 wh' wl' ]]].
+
+(* operatore rotazione destra n-volte *)
+nlet rec ror_w32_n (dw:word32) (n:nat) on n ≝
+ match n with
+  [ O ⇒ dw
+  | S n' ⇒ ror_w32_n (ror_w32 dw) n' ].
+
+(* operatore rotazione sinistra con carry *)
+ndefinition rcl_w32 ≝
+λdw:word32.λc:bool.match rcl_w16 (w32l dw) c with
+ [ pair wl' c' ⇒ match rcl_w16 (w32h dw) c' with
+  [ pair wh' c'' ⇒ pair … (mk_word32 wh' wl') c'' ]]. 
+
+(* operatore shift sinistro *)
+ndefinition shl_w32 ≝
+λdw:word32.match rcl_w16 (w32l dw) false with
+ [ pair wl' c' ⇒ match rcl_w16 (w32h dw) c' with
+  [ pair wh' c'' ⇒ pair … (mk_word32 wh' wl') c'' ]].
+
+(* operatore rotazione sinistra *)
+ndefinition rol_w32 ≝
+λdw:word32.match rcl_w16 (w32l dw) false with
+ [ pair wl' c' ⇒ match rcl_w16 (w32h dw) c' with
+  [ pair wh' c'' ⇒ match c'' with
+   [ true ⇒ mk_word32 wh' (or_w16 (mk_word16 (mk_byte8 x0 x0) (mk_byte8 x0 x1)) wl')
+   | false ⇒ mk_word32 wh' wl' ]]].
+
+(* operatore rotazione sinistra n-volte *)
+nlet rec rol_w32_n (dw:word32) (n:nat) on n ≝
+ match n with
+  [ O ⇒ dw
+  | S n' ⇒ rol_w32_n (rol_w32 dw) n' ].
+
+(* operatore not/complemento a 1 *)
+ndefinition not_w32 ≝
+λdw:word32.mk_word32 (not_w16 (w32h dw)) (not_w16 (w32l dw)).
+
+(* operatore somma con data+carry → data+carry *)
+ndefinition plus_w32_dc_dc ≝
+λdw1,dw2:word32.λc:bool.
+ match plus_w16_dc_dc (w32l dw1) (w32l dw2) c with
+  [ pair l c ⇒ match plus_w16_dc_dc (w32h dw1) (w32h dw2) c with
+   [ pair h c' ⇒ pair … 〈h.l〉 c' ]].
+
+(* operatore somma con data+carry → data *)
+ndefinition plus_w32_dc_d ≝
+λdw1,dw2:word32.λc:bool.
+ match plus_w16_dc_dc (w32l dw1) (w32l dw2) c with
+  [ pair l c ⇒ 〈plus_w16_dc_d (w32h dw1) (w32h dw2) c.l〉 ].
+
+(* operatore somma con data+carry → c *)
+ndefinition plus_w32_dc_c ≝
+λdw1,dw2:word32.λc:bool.
+ plus_w16_dc_c (w32h dw1) (w32h dw2) (plus_w16_dc_c (w32l dw1) (w32l dw2) c).
+
+(* operatore somma con data → data+carry *)
+ndefinition plus_w32_d_dc ≝
+λdw1,dw2:word32.
+ match plus_w16_d_dc (w32l dw1) (w32l dw2) with
+  [ pair l c ⇒ match plus_w16_dc_dc (w32h dw1) (w32h dw2) c with
+   [ pair h c' ⇒ pair … 〈h.l〉 c' ]].
+
+(* operatore somma con data → data *)
+ndefinition plus_w32_d_d ≝
+λdw1,dw2:word32.
+ match plus_w16_d_dc (w32l dw1) (w32l dw2) with
+  [ pair l c ⇒ 〈plus_w16_dc_d (w32h dw1) (w32h dw2) c.l〉 ].
+
+(* operatore somma con data → c *)
+ndefinition plus_w32_d_c ≝
+λdw1,dw2:word32.
+ plus_w16_dc_c (w32h dw1) (w32h dw2) (plus_w16_d_c (w32l dw1) (w32l dw2)).
+
+(* operatore Most Significant Bit *)
+ndefinition MSB_w32 ≝ λdw:word32.eq_ex x8 (and_ex x8 (b8h (w16h (w32h dw)))).
+
+(* operatore predecessore *)
+ndefinition pred_w32 ≝
+λdw:word32.match eq_w16 (w32l dw) (mk_word16 (mk_byte8 x0 x0) (mk_byte8 x0 x0)) with
+ [ true ⇒ mk_word32 (pred_w16 (w32h dw)) (pred_w16 (w32l dw))
+ | false ⇒ mk_word32 (w32h dw) (pred_w16 (w32l dw)) ].
+
+(* operatore successore *)
+ndefinition succ_w32 ≝
+λdw:word32.match eq_w16 (w32l dw) (mk_word16 (mk_byte8 xF xF) (mk_byte8 xF xF)) with
+ [ true ⇒ mk_word32 (succ_w16 (w32h dw)) (succ_w16 (w32l dw))
+ | false ⇒ mk_word32 (w32h dw) (succ_w16 (w32l dw)) ].
+
+(* operatore neg/complemento a 2 *)
+ndefinition compl_w32 ≝
+λdw:word32.match MSB_w32 dw with
+ [ true ⇒ succ_w32 (not_w32 dw)
+ | false ⇒ not_w32 (pred_w32 dw) ].
+
+(* 
+   operatore moltiplicazione senza segno: b*b=[0x00000000,0xFFFE0001]
+   ... in pratica (〈a:b〉*〈c:d〉) = (a*c)<<16+(a*d)<<8+(b*c)<<8+(b*d)
+*)
+ndefinition mul_w16 ≝
+λw1,w2:word16.match w1 with
+[ mk_word16 b1h b1l ⇒ match w2 with
+[ mk_word16 b2h b2l ⇒ match mul_b8 b1l b2l with
+[ mk_word16 t1_h t1_l ⇒ match mul_b8 b1h b2l with
+[ mk_word16 t2_h t2_l ⇒ match mul_b8 b2h b1l with
+[ mk_word16 t3_h t3_l ⇒ match mul_b8 b1h b2h with
+[ mk_word16 t4_h t4_l ⇒
+ plus_w32_d_d
+  (plus_w32_d_d
+   (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈t1_h:t1_l〉〉
+]]]]]].
+
+(* divisione senza segno (secondo la logica delle ALU): (quoziente resto) overflow *)
+nlet rec div_w16_aux (divd:word32) (divs:word32) (molt:word16) (q:word16) (c:nat) on c ≝
+  let w' ≝ plus_w32_d_d divd (compl_w32 divs) in
+   match c with
+   [ O ⇒ match le_w32 divs divd with
+    [ true ⇒ triple … (or_w16 molt q) (w32l w') (⊖ (eq_w16 (w32h w') 〈〈x0,x0〉:〈x0,x0〉〉))
+    | false ⇒ triple … q (w32l divd) (⊖ (eq_w16 (w32h divd) 〈〈x0,x0〉:〈x0,x0〉〉)) ]
+   | S c' ⇒ match le_w32 divs divd with
+    [ true ⇒ div_w16_aux w' (ror_w32 divs) (ror_w16 molt) (or_w16 molt q) c'
+    | false ⇒ div_w16_aux divd (ror_w32 divs) (ror_w16 molt) q c' ]].
+
+ndefinition div_w16 ≝
+λw:word32.λb:word16.match eq_w16 b 〈〈x0,x0〉:〈x0,x0〉〉 with
+(* 
+   la combinazione n/0 e' illegale, segnala solo overflow senza dare risultato
+*)
+ [ true ⇒ triple … 〈〈xF,xF〉:〈xF,xF〉〉 (w32l w) true
+ | false ⇒ match eq_w32 w 〈〈〈x0,x0〉:〈x0,x0〉〉.〈〈x0,x0〉:〈x0,x0〉〉〉 with
+(* 0 diviso qualsiasi cosa diverso da 0 da' q=0 r=0 o=false *)
+  [ true ⇒ triple … 〈〈x0,x0〉:〈x0,x0〉〉 〈〈x0,x0〉:〈x0,x0〉〉 false
+(* 1) e' una divisione sensata che produrra' overflow/risultato *)
+(* 2) parametri: dividendo, divisore, moltiplicatore, quoziente, contatore *)
+(* 3) ad ogni ciclo il divisore e il moltiplicatore vengono scalati di 1 a dx *)
+(* 4) il moltiplicatore e' la quantita' aggiunta al quoziente se il divisore *)
+(*    puo' essere sottratto al dividendo *) 
+  | false ⇒ div_w16_aux w (rol_w32_n 〈〈〈x0,x0〉:〈x0,x0〉〉.b〉 nat15) 〈〈x8,x0〉:〈x0,x0〉〉 〈〈x0,x0〉:〈x0,x0〉〉 nat15 ]].
+
+(* operatore x in [inf,sup] o in sup],[inf *)
+ndefinition inrange_w32 ≝
+λx,inf,sup:word32.
+ match le_w32 inf sup with
+  [ true ⇒ and_bool | false ⇒ or_bool ]
+ (le_w32 inf x) (le_w32 x sup).
+
+(* iteratore sulle word *)
+ndefinition forall_w32 ≝
+ λP.
+  forall_w16 (λbh.
+  forall_w16 (λbl.
+   P (mk_word32 bh bl ))).
diff --git a/helm/software/matita/contribs/ng_assembly/num/word32_lemmas.ma b/helm/software/matita/contribs/ng_assembly/num/word32_lemmas.ma
new file mode 100755 (executable)
index 0000000..026086d
--- /dev/null
@@ -0,0 +1,377 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "num/word32.ma".
+include "num/word16_lemmas.ma".
+
+(* ***** *)
+(* DWORD *)
+(* ***** *)
+
+nlemma word32_destruct_1 :
+∀x1,x2,y1,y2.
+ mk_word32 x1 y1 = mk_word32 x2 y2 → x1 = x2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_word32 x2 y2 with [ mk_word32 a _ ⇒ x1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma word32_destruct_2 :
+∀x1,x2,y1,y2.
+ mk_word32 x1 y1 = mk_word32 x2 y2 → y1 = y2.
+ #x1; #x2; #y1; #y2; #H;
+ nchange with (match mk_word32 x2 y2 with [ mk_word32 _ b ⇒ y1 = b ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_eqw32 : symmetricT word32 bool eq_w32.
+ #dw1; #dw2;
+ nelim dw1;
+ nelim dw2;
+ #w1; #w2; #w3; #w4;
+ nchange with (((eq_w16 w3 w1)⊗(eq_w16 w4 w2)) = ((eq_w16 w1 w3)⊗(eq_w16 w2 w4)));
+ nrewrite > (symmetric_eqw16 w1 w3);
+ nrewrite > (symmetric_eqw16 w2 w4);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_andw32 : symmetricT word32 word32 and_w32.
+ #dw1; #dw2;
+ nelim dw1;
+ nelim dw2;
+ #w1; #w2; #w3; #w4;
+ nchange with ((mk_word32 (and_w16 w3 w1) (and_w16 w4 w2)) = (mk_word32 (and_w16 w1 w3) (and_w16 w2 w4)));
+ nrewrite > (symmetric_andw16 w1 w3);
+ nrewrite > (symmetric_andw16 w2 w4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_andw32 : ∀dw1,dw2,dw3.(and_w32 (and_w32 dw1 dw2) dw3) = (and_w32 dw1 (and_w32 dw2 dw3)).
+ #dw1; #dw2; #dw3;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nelim dw3;
+ #w5; #w6;
+ nchange with (mk_word32 (and_w16 (and_w16 w1 w3) w5) (and_w16 (and_w16 w2 w4) w6) =
+  mk_word32 (and_w16 w1 (and_w16 w3 w5)) (and_w16 w2 (and_w16 w4 w6)));
+ nrewrite < (associative_andw16 w1 w3 w5);
+ nrewrite < (associative_andw16 w2 w4 w6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_orw32 : symmetricT word32 word32 or_w32.
+ #dw1; #dw2;
+ nelim dw1;
+ nelim dw2;
+ #w1; #w2; #w3; #w4;
+ nchange with ((mk_word32 (or_w16 w3 w1) (or_w16 w4 w2)) = (mk_word32 (or_w16 w1 w3) (or_w16 w2 w4)));
+ nrewrite > (symmetric_orw16 w1 w3);
+ nrewrite > (symmetric_orw16 w2 w4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_orw32 : ∀dw1,dw2,dw3.(or_w32 (or_w32 dw1 dw2) dw3) = (or_w32 dw1 (or_w32 dw2 dw3)).
+ #dw1; #dw2; #dw3;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nelim dw3;
+ #w5; #w6;
+ nchange with (mk_word32 (or_w16 (or_w16 w1 w3) w5) (or_w16 (or_w16 w2 w4) w6) =
+  mk_word32 (or_w16 w1 (or_w16 w3 w5)) (or_w16 w2 (or_w16 w4 w6)));
+ nrewrite < (associative_orw16 w1 w3 w5);
+ nrewrite < (associative_orw16 w2 w4 w6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_xorw32 : symmetricT word32 word32 xor_w32.
+ #dw1; #dw2;
+ nelim dw1;
+ nelim dw2;
+ #w1; #w2; #w3; #w4;
+ nchange with ((mk_word32 (xor_w16 w3 w1) (xor_w16 w4 w2)) = (mk_word32 (xor_w16 w1 w3) (xor_w16 w2 w4)));
+ nrewrite > (symmetric_xorw16 w1 w3);
+ nrewrite > (symmetric_xorw16 w2 w4);
+ napply refl_eq.
+nqed.
+
+nlemma associative_xorw32 : ∀dw1,dw2,dw3.(xor_w32 (xor_w32 dw1 dw2) dw3) = (xor_w32 dw1 (xor_w32 dw2 dw3)).
+ #dw1; #dw2; #dw3;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nelim dw3;
+ #w5; #w6;
+ nchange with (mk_word32 (xor_w16 (xor_w16 w1 w3) w5) (xor_w16 (xor_w16 w2 w4) w6) =
+  mk_word32 (xor_w16 w1 (xor_w16 w3 w5)) (xor_w16 w2 (xor_w16 w4 w6)));
+ nrewrite < (associative_xorw16 w1 w3 w5);
+ nrewrite < (associative_xorw16 w2 w4 w6);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw32_dc_dc : ∀dw1,dw2,c.plus_w32_dc_dc dw1 dw2 c = plus_w32_dc_dc dw2 dw1 c.
+ #dw1; #dw2; #c;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nchange with (
+  match plus_w16_dc_dc w2 w4 c with [ pair l c ⇒ match plus_w16_dc_dc w1 w3 c with [ pair h c' ⇒ pair … 〈h.l〉 c' ]] =
+  match plus_w16_dc_dc w4 w2 c with [ pair l c ⇒ match plus_w16_dc_dc w3 w1 c with [ pair h c' ⇒ pair … 〈h.l〉 c' ]]);
+ nrewrite > (symmetric_plusw16_dc_dc w4 w2 c);
+ ncases (plus_w16_dc_dc w2 w4 c);
+ #w5; #c1;
+ nchange with (
+  match plus_w16_dc_dc w1 w3 c1 with [ pair h c' ⇒ pair … 〈h.w5〉 c' ] =
+  match plus_w16_dc_dc w3 w1 c1 with [ pair h c' ⇒ pair … 〈h.w5〉 c' ]);
+ nrewrite > (symmetric_plusw16_dc_dc w1 w3 c1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw32_dc_d : ∀dw1,dw2,c.plus_w32_dc_d dw1 dw2 c = plus_w32_dc_d dw2 dw1 c.
+ #dw1; #dw2; #c;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nchange with (
+  match plus_w16_dc_dc w2 w4 c with [ pair l c ⇒ 〈plus_w16_dc_d w1 w3 c.l〉 ] =
+  match plus_w16_dc_dc w4 w2 c with [ pair l c ⇒ 〈plus_w16_dc_d w3 w1 c.l〉 ]);
+ nrewrite > (symmetric_plusw16_dc_dc w4 w2 c);
+ ncases (plus_w16_dc_dc w2 w4 c);
+ #w5; #c1;
+ nchange with (〈plus_w16_dc_d w1 w3 c1.w5〉 = 〈plus_w16_dc_d w3 w1 c1.w5〉);
+ nrewrite > (symmetric_plusw16_dc_d w1 w3 c1);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw32_dc_c : ∀dw1,dw2,c.plus_w32_dc_c dw1 dw2 c = plus_w32_dc_c dw2 dw1 c.
+ #dw1; #dw2; #c;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nchange with (
+  plus_w16_dc_c w1 w3 (plus_w16_dc_c w2 w4 c) =
+  plus_w16_dc_c w3 w1 (plus_w16_dc_c w4 w2 c));
+ nrewrite > (symmetric_plusw16_dc_c w4 w2 c);
+ nrewrite > (symmetric_plusw16_dc_c w3 w1 (plus_w16_dc_c w2 w4 c));
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw32_d_dc : ∀dw1,dw2.plus_w32_d_dc dw1 dw2 = plus_w32_d_dc dw2 dw1.
+ #dw1; #dw2;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nchange with (
+  match plus_w16_d_dc w2 w4 with [ pair l c ⇒ match plus_w16_dc_dc w1 w3 c with [ pair h c' ⇒ pair … 〈h.l〉 c' ]] =
+  match plus_w16_d_dc w4 w2 with [ pair l c ⇒ match plus_w16_dc_dc w3 w1 c with [ pair h c' ⇒ pair … 〈h.l〉 c' ]]);
+ nrewrite > (symmetric_plusw16_d_dc w4 w2);
+ ncases (plus_w16_d_dc w2 w4);
+ #w5; #c;
+ nchange with (
+  match plus_w16_dc_dc w1 w3 c with [ pair h c' ⇒ pair … 〈h.w5〉 c' ] =
+  match plus_w16_dc_dc w3 w1 c with [ pair h c' ⇒ pair … 〈h.w5〉 c' ]);
+ nrewrite > (symmetric_plusw16_dc_dc w1 w3 c);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw32_d_d : ∀dw1,dw2.plus_w32_d_d dw1 dw2 = plus_w32_d_d dw2 dw1.
+ #dw1; #dw2;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nchange with (
+  match plus_w16_d_dc w2 w4 with [ pair l c ⇒ 〈plus_w16_dc_d w1 w3 c.l〉 ] =
+  match plus_w16_d_dc w4 w2 with [ pair l c ⇒ 〈plus_w16_dc_d w3 w1 c.l〉 ]);
+ nrewrite > (symmetric_plusw16_d_dc w4 w2);
+ ncases (plus_w16_d_dc w2 w4);
+ #w5; #c;
+ nchange with (〈plus_w16_dc_d w1 w3 c.w5〉 = 〈plus_w16_dc_d w3 w1 c.w5〉);
+ nrewrite > (symmetric_plusw16_dc_d w1 w3 c);
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_plusw32_d_c : ∀dw1,dw2.plus_w32_d_c dw1 dw2 = plus_w32_d_c dw2 dw1.
+ #dw1; #dw2;
+ nelim dw1;
+ #w1; #w2;
+ nelim dw2;
+ #w3; #w4;
+ nchange with (
+  plus_w16_dc_c w1 w3 (plus_w16_d_c w2 w4) =
+  plus_w16_dc_c w3 w1 (plus_w16_d_c w4 w2));
+ nrewrite > (symmetric_plusw16_d_c w4 w2);
+ nrewrite > (symmetric_plusw16_dc_c w3 w1 (plus_w16_d_c w2 w4));
+ napply refl_eq.
+nqed.
+
+nlemma symmetric_mulw16 : symmetricT word16 word32 mul_w16.
+ #w1; #w2;
+ nelim w1;
+ #b1; #b2;
+ nelim w2;
+ #b3; #b4;
+ nchange with (match mul_b8 b2 b4 with
+ [ mk_word16 t1_h t1_l ⇒ match mul_b8 b1 b4 with
+ [ mk_word16 t2_h t2_l ⇒ match mul_b8 b3 b2 with
+ [ mk_word16 t3_h t3_l ⇒ match mul_b8 b1 b3 with
+ [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈t1_h:t1_l〉〉 
+ ]]]] = match mul_b8 b4 b2 with
+ [ mk_word16 t1_h t1_l ⇒ match mul_b8 b3 b2 with
+ [ mk_word16 t2_h t2_l ⇒ match mul_b8 b1 b4 with
+ [ mk_word16 t3_h t3_l ⇒ match mul_b8 b3 b1 with
+ [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈t1_h:t1_l〉〉 
+ ]]]]);
+ nrewrite < (symmetric_mulb8 b2 b4);
+ ncases (mul_b8 b2 b4);
+ #b5; #b6;
+ nchange with (match mul_b8 b1 b4 with
+ [ mk_word16 t2_h t2_l ⇒ match mul_b8 b3 b2 with
+ [ mk_word16 t3_h t3_l ⇒ match mul_b8 b1 b3 with
+ [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉 
+ ]]] = match mul_b8 b3 b2 with
+ [ mk_word16 t2_h t2_l ⇒ match mul_b8 b1 b4 with
+ [ mk_word16 t3_h t3_l ⇒ match mul_b8 b3 b1 with
+ [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉 
+ ]]]);
+ ncases (mul_b8 b3 b2);
+ #b7; #b8;
+ ncases (mul_b8 b1 b4);
+ #b9; #b10;
+ nchange with (match mul_b8 b1 b3 with
+ [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉 
+ ] = match mul_b8 b3 b1 with
+ [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉 
+ ]);
+ nrewrite < (symmetric_mulb8 b1 b3);
+ ncases (mul_b8 b1 b3);
+ #b11; #b12;
+ nchange with ((plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉) 〈〈b11:b12〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉) =
+  (plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉) 〈〈b11:b12〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉));
+ nrewrite > (symmetric_plusw32_d_d 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉);
+ napply refl_eq.
+nqed.
+
+nlemma eqw32_to_eq : ∀dw1,dw2:word32.(eq_w32 dw1 dw2 = true) → (dw1 = dw2).
+ #dw1; #dw2;
+ nelim dw1;
+ nelim dw2;
+ #w1; #w2; #w3; #w4;
+ nchange in ⊢ (% → ?) with (((eq_w16 w3 w1)⊗(eq_w16 w4 w2)) = true);
+ #H;
+ nrewrite < (eqw16_to_eq … (andb_true_true_l … H));
+ nrewrite < (eqw16_to_eq … (andb_true_true_r … H));
+ napply refl_eq.
+nqed.
+
+nlemma eq_to_eqw32 : ∀dw1,dw2.dw1 = dw2 → eq_w32 dw1 dw2 = true.
+ #dw1; #dw2;
+ nelim dw1;
+ nelim dw2;
+ #w1; #w2; #w3; #w4;
+ #H;
+ nrewrite < (word32_destruct_1 … H);
+ nrewrite < (word32_destruct_2 … H);
+ nchange with (((eq_w16 w3 w3)⊗(eq_w16 w4 w4)) = true);
+ nrewrite > (eq_to_eqw16 w3 w3 (refl_eq …));
+ nrewrite > (eq_to_eqw16 w4 w4 (refl_eq …)); 
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+nlemma decidable_w32_aux1 : ∀w1,w2,w3,w4.w1 ≠ w3 → 〈w1.w2〉 ≠ 〈w3.w4〉.
+ #w1; #w2; #w3; #w4;
+ nnormalize; #H; #H1;
+ napply (H (word32_destruct_1 … H1)).
+nqed.
+
+nlemma decidable_w32_aux2 : ∀w1,w2,w3,w4.w2 ≠ w4 → 〈w1.w2〉 ≠ 〈w3.w4〉.
+ #w1; #w2; #w3; #w4;
+ nnormalize; #H; #H1;
+ napply (H (word32_destruct_2 … H1)).
+nqed.
+
+nlemma decidable_w32 : ∀x,y:word32.decidable (x = y).
+ #x; nelim x; #w1; #w2;
+ #y; nelim y; #w3; #w4;
+ nnormalize;
+ napply (or2_elim (w1 = w3) (w1 ≠ w3) ? (decidable_w16 w1 w3) …);
+ ##[ ##2: #H; napply (or2_intro2 … (decidable_w32_aux1 w1 w2 w3 w4 H))
+ ##| ##1: #H; napply (or2_elim (w2 = w4) (w2 ≠ w4) ? (decidable_w16 w2 w4) …);
+          ##[ ##2: #H1; napply (or2_intro2 … (decidable_w32_aux2 w1 w2 w3 w4 H1))
+          ##| ##1: #H1; nrewrite > H; nrewrite > H1;
+                        napply (or2_intro1 … (refl_eq ? 〈w3.w4〉))
+          ##]
+ ##]
+nqed.
+
+nlemma neqw32_to_neq : ∀dw1,dw2:word32.(eq_w32 dw1 dw2 = false) → (dw1 ≠ dw2).
+ #dw1; #dw2;
+ nelim dw1;
+ nelim dw2;
+ #w1; #w2; #w3; #w4;
+ nchange with ((((eq_w16 w3 w1) ⊗ (eq_w16 w4 w2)) = false) → ?);
+ #H;
+ napply (or2_elim ((eq_w16 w3 w1) = false) ((eq_w16 w4 w2) = false) ? (andb_false2 … H) …);
+ ##[ ##1: #H1; napply (decidable_w32_aux1 … (neqw16_to_neq … H1))
+ ##| ##2: #H1; napply (decidable_w32_aux2 … (neqw16_to_neq … H1))
+ ##]
+nqed.
+
+nlemma word32_destruct : ∀w1,w2,w3,w4.〈w1.w2〉 ≠ 〈w3.w4〉 → w1 ≠ w3 ∨ w2 ≠ w4.
+ #w1; #w2; #w3; #w4;
+ nnormalize; #H;
+ napply (or2_elim (w1 = w3) (w1 ≠ w3) ? (decidable_w16 w1 w3) …);
+ ##[ ##2: #H1; napply (or2_intro1 … H1)
+ ##| ##1: #H1; napply (or2_elim (w2 = w4) (w2 ≠ w4) ? (decidable_w16 w2 w4) …);
+          ##[ ##2: #H2; napply (or2_intro2 … H2)
+          ##| ##1: #H2; nrewrite > H1 in H:(%);
+                   nrewrite > H2;
+                   #H; nelim (H (refl_eq …))
+          ##]
+ ##]
+nqed.
+
+nlemma neq_to_neqw32 : ∀dw1,dw2.dw1 ≠ dw2 → eq_w32 dw1 dw2 = false.
+ #dw1; #dw2;
+ nelim dw1; #w1; #w2;
+ nelim dw2; #w3; #w4;
+ #H; nchange with (((eq_w16 w1 w3) ⊗ (eq_w16 w2 w4)) = false);
+ napply (or2_elim (w1 ≠ w3) (w2 ≠ w4) ? (word32_destruct … H) …);
+ ##[ ##1: #H1; nrewrite > (neq_to_neqw16 … H1); nnormalize; napply refl_eq
+ ##| ##2: #H1; nrewrite > (neq_to_neqw16 … H1);
+          nrewrite > (symmetric_andbool (eq_w16 w1 w3) false);
+          nnormalize; napply refl_eq
+ ##]
+nqed.
diff --git a/helm/software/matita/contribs/ng_assembly/universe/universe.ma b/helm/software/matita/contribs/ng_assembly/universe/universe.ma
new file mode 100755 (executable)
index 0000000..0db667a
--- /dev/null
@@ -0,0 +1,233 @@
+(**************************************************************************)
+(*       ___                                                              *)
+(*      ||M||                                                             *)
+(*      ||A||       A project by Andrea Asperti                           *)
+(*      ||T||                                                             *)
+(*      ||I||       Developers:                                           *)
+(*      ||T||         The HELM team.                                      *)
+(*      ||A||         http://helm.cs.unibo.it                             *)
+(*      \   /                                                             *)
+(*       \ /        This file is distributed under the terms of the       *)
+(*        v         GNU General Public License Version 2                  *)
+(*                                                                        *)
+(**************************************************************************)
+
+(* ********************************************************************** *)
+(*                          Progetto FreeScale                            *)
+(*                                                                        *)
+(*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
+(*   Sviluppo: 2008-2010                                                  *)
+(*                                                                        *)
+(* ********************************************************************** *)
+
+include "common/list.ma".
+include "common/nat_lemmas.ma".
+include "common/prod.ma".
+
+nlet rec nmember_natList (elem:nat) (l:ne_list nat) on l ≝
+ match l with
+  [ ne_nil h ⇒ ⊖(eq_nat elem h)
+  | ne_cons h t ⇒ match eq_nat elem h with
+   [ true ⇒ false | false ⇒ nmember_natList elem t ]
+  ].
+
+(* elem presente una ed una sola volta in l *)
+nlet rec member_natList (elem:nat) (l:ne_list nat) on l ≝
+ match l with
+  [ ne_nil h ⇒ eq_nat elem h
+  | ne_cons h t ⇒ match eq_nat elem h with
+    [ true ⇒ nmember_natList elem t | false ⇒ member_natList elem t ]
+  ].
+
+(* costruttore di un sottouniverso:
+   S_EL cioe' uno qualsiasi degli elementi del sottouniverso
+*)
+ninductive S_UN (l:ne_list nat) : Type ≝
+ S_EL : Πx:nat.((member_natList x l) = true) → S_UN l.
+
+ndefinition getelem : ∀l.∀e:S_UN l.nat.
+ #l; #s; nelim s;
+ #u; #dim;
+ napply u.
+nqed.
+
+ndefinition eq_SUN ≝ λl.λx,y:S_UN l.eq_nat (getelem ? x) (getelem ? y).
+
+ndefinition getdim : ∀l.∀e:S_UN l.member_natList (getelem ? e) l = true.
+ #l; #s; nelim s;
+ #u; #dim;
+ napply dim.
+nqed.
+
+nlemma SUN_destruct_1
+ : ∀l.∀e1,e2.∀dim1,dim2.S_EL l e1 dim1 = S_EL l e2 dim2 → e1 = e2.
+ #l; #e1; #e2; #dim1; #dim2; #H;
+ nchange with (match S_EL l e2 dim2 with [ S_EL a _ ⇒ e1 = a ]);
+ nrewrite < H;
+ nnormalize;
+ napply refl_eq.
+nqed.
+
+(* destruct universale *)
+ndefinition SUN_destruct : ∀l.∀x,y:S_UN l.∀P:Prop.x = y → match eq_SUN l x y with [ true ⇒ P → P | false ⇒ P ].
+ #l; #x; nelim x;
+ #u1; #dim1;
+ #y; nelim y;
+ #u2; #dim2;
+ #P;
+ nchange with (? → (match eq_nat u1 u2 with [ true ⇒ P → P | false ⇒ P ]));
+ #H;
+ nrewrite > (SUN_destruct_1 l … H);
+ nrewrite > (eq_to_eqnat u2 u2 (refl_eq …));
+ nnormalize;
+ napply (λx.x).
+nqed.
+
+(* eq_to_eqxx universale *)
+nlemma eq_to_eqSUN : ∀l.∀x,y:S_UN l.x = y → eq_SUN l x y = true.
+ #l; #x; nelim x;
+ #u1; #dim1;
+ #y; nelim y;
+ #u2; #dim2;
+ nchange with (? → eq_nat u1 u2 = true);
+ #H; napply (eq_to_eqnat u1 u2);
+ napply (SUN_destruct_1 l … H).
+nqed.
+
+(* neqxx_to_neq universale *)
+nlemma neqSUN_to_neq : ∀l.∀x,y:S_UN l.eq_SUN l x y = false → x ≠ y.
+ #l; #n1; #n2; #H;
+ napply (not_to_not (n1 = n2) (eq_SUN l n1 n2 = true) …);
+ ##[ ##1: napply (eq_to_eqSUN l n1 n2)
+ ##| ##2: napply (eqfalse_to_neqtrue … H)
+ ##]
+nqed.
+
+(* eqxx_to_eq universale *)
+(* !!! evidente ma come si fa? *)
+naxiom eqSUN_to_eq_aux : ∀l,x,y.((getelem l x) = (getelem l y)) → x = y.
+
+nlemma eqSUN_to_eq : ∀l.∀x,y:S_UN l.eq_SUN l x y = true → x = y.
+ #l; #x; #y;
+ nchange with ((eq_nat (getelem ? x) (getelem ? y) = true) → x = y);
+ #H; napply (eqSUN_to_eq_aux l x y (eqnat_to_eq … H)).
+nqed.
+
+(* neq_to_neqxx universale *)
+nlemma neq_to_neqSUN : ∀l.∀x,y:S_UN l.x ≠ y → eq_SUN l x y = false.
+ #l; #n1; #n2; #H;
+ napply (neqtrue_to_eqfalse (eq_SUN l n1 n2));
+ napply (not_to_not (eq_SUN l n1 n2 = true) (n1 = n2) ? H);
+ napply (eqSUN_to_eq l n1 n2).
+nqed.
+
+(* decidibilita' universale *)
+nlemma decidable_SUN : ∀l.∀x,y:S_UN l.decidable (x = y).
+ #l; #x; #y; nnormalize;
+ napply (or2_elim (eq_SUN l x y = true) (eq_SUN l x y = false) ? (decidable_bexpr ?));
+ ##[ ##1: #H; napply (or2_intro1 (x = y) (x ≠ y) (eqSUN_to_eq l … H))
+ ##| ##2: #H; napply (or2_intro2 (x = y) (x ≠ y) (neqSUN_to_neq l … H))
+ ##]
+nqed.
+
+(* simmetria di uguaglianza universale *)
+nlemma symmetric_eqSUN : ∀l.symmetricT (S_UN l) bool (eq_SUN l).
+ #l; #n1; #n2;
+ napply (or2_elim (n1 = n2) (n1 ≠ n2) ? (decidable_SUN l n1 n2));
+ ##[ ##1: #H; nrewrite > H; napply refl_eq
+ ##| ##2: #H; nrewrite > (neq_to_neqSUN l n1 n2 H);
+          napply (symmetric_eq ? (eq_SUN l n2 n1) false);
+          napply (neq_to_neqSUN l n2 n1 (symmetric_neq ? n1 n2 H))
+ ##]
+nqed.
+
+(* scheletro di funzione generica ad 1 argomento *)
+nlet rec farg1_auxT (T:Type) (l:ne_list nat) on l ≝
+ match l with
+  [ ne_nil _ ⇒ T
+  | ne_cons _ t ⇒ ProdT T (farg1_auxT T t)
+  ].
+
+nlemma farg1_auxDim : ∀h,t,x.eq_nat x h = false → member_natList x (h§§t) = true → member_natList x t = true.
+ #h; #t; #x; #H; #H1;
+ nnormalize in H1:(%);
+ nrewrite > H in H1:(%);
+ nnormalize;
+ napply (λx.x).
+nqed.
+
+nlet rec farg1 (T:Type) (l:ne_list nat) on l ≝
+ match l with
+  [ ne_nil h ⇒ λarg:farg1_auxT T «£h».λx:S_UN «£h».arg
+  | ne_cons h t ⇒ λarg:farg1_auxT T (h§§t).λx:S_UN (h§§t).
+   match eq_nat (getelem ? x) h
+    return λy.eq_nat (getelem ? x) h = y → ?
+   with
+    [ true ⇒ λp:(eq_nat (getelem ? x) h = true).fst … arg
+    | false ⇒ λp:(eq_nat (getelem ? x) h = false).
+     farg1 T t
+      (snd … arg)
+      (S_EL t (getelem ? x) (farg1_auxDim h t (getelem ? x) p (getdim ? x)))
+    ] (refl_eq ? (eq_nat (getelem ? x) h))
+  ].
+
+(* scheletro di funzione generica a 2 argomenti *)
+nlet rec farg2 (T:Type) (l,lfix:ne_list nat) on l ≝
+ match l with
+  [ ne_nil h ⇒ λarg:farg1_auxT (farg1_auxT T lfix) «£h».λx:S_UN «£h».farg1 T lfix arg
+  | ne_cons h t ⇒ λarg:farg1_auxT (farg1_auxT T lfix) (h§§t).λx:S_UN (h§§t).
+   match eq_nat (getelem ? x) h
+    return λy.eq_nat (getelem ? x) h = y → ?
+   with
+    [ true ⇒ λp:(eq_nat (getelem ? x) h = true).farg1 T lfix (fst … arg)
+    | false ⇒ λp:(eq_nat (getelem ? x) h = false).
+     farg2 T t lfix
+      (snd … arg)
+      (S_EL t (getelem ? x) (farg1_auxDim h t (getelem ? x) p (getdim ? x)))
+    ] (refl_eq ? (eq_nat (getelem ? x) h))
+  ].
+
+(* esempio0: universo ottale *)
+ndefinition oct0 ≝ O.
+ndefinition oct1 ≝ nat1.
+ndefinition oct2 ≝ nat2.
+ndefinition oct3 ≝ nat3.
+ndefinition oct4 ≝ nat4.
+ndefinition oct5 ≝ nat5.
+ndefinition oct6 ≝ nat6.
+ndefinition oct7 ≝ nat7.
+
+ndefinition oct_UN ≝ « oct0 ; oct1 ; oct2 ; oct3 ; oct4 ; oct5 ; oct6 £ oct7 ».
+
+ndefinition uoct0 ≝ S_EL oct_UN oct0 (refl_eq …).
+ndefinition uoct1 ≝ S_EL oct_UN oct1 (refl_eq …).
+ndefinition uoct2 ≝ S_EL oct_UN oct2 (refl_eq …).
+ndefinition uoct3 ≝ S_EL oct_UN oct3 (refl_eq …).
+ndefinition uoct4 ≝ S_EL oct_UN oct4 (refl_eq …).
+ndefinition uoct5 ≝ S_EL oct_UN oct5 (refl_eq …).
+ndefinition uoct6 ≝ S_EL oct_UN oct6 (refl_eq …).
+ndefinition uoct7 ≝ S_EL oct_UN oct7 (refl_eq …).
+
+(* esempio1: NOT ottale *)
+ndefinition octNOT ≝
+ farg1 (S_UN oct_UN) oct_UN
+  (pair … uoct7 (pair … uoct6 (pair … uoct5 (pair … uoct4 (pair … uoct3 (pair … uoct2 (pair … uoct1 uoct0))))))). 
+
+(* esempio2: AND ottale *)
+ndefinition octAND0 ≝ pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 uoct0)))))).
+ndefinition octAND1 ≝ pair … uoct0 (pair … uoct1 (pair … uoct0 (pair … uoct1 (pair … uoct0 (pair … uoct1 (pair … uoct0 uoct1)))))).
+ndefinition octAND2 ≝ pair … uoct0 (pair … uoct0 (pair … uoct2 (pair … uoct2 (pair … uoct0 (pair … uoct0 (pair … uoct2 uoct2)))))).
+ndefinition octAND3 ≝ pair … uoct0 (pair … uoct1 (pair … uoct2 (pair … uoct3 (pair … uoct0 (pair … uoct1 (pair … uoct2 uoct3)))))).
+ndefinition octAND4 ≝ pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct0 (pair … uoct4 (pair … uoct4 (pair … uoct4 uoct4)))))).
+ndefinition octAND5 ≝ pair … uoct0 (pair … uoct1 (pair … uoct0 (pair … uoct1 (pair … uoct4 (pair … uoct5 (pair … uoct4 uoct5)))))).
+ndefinition octAND6 ≝ pair … uoct0 (pair … uoct0 (pair … uoct2 (pair … uoct2 (pair … uoct4 (pair … uoct4 (pair … uoct6 uoct6)))))).
+ndefinition octAND7 ≝ pair … uoct0 (pair … uoct1 (pair … uoct2 (pair … uoct3 (pair … uoct4 (pair … uoct5 (pair … uoct6 uoct7)))))).
+
+ndefinition octAND ≝
+ farg2 (S_UN oct_UN) oct_UN oct_UN
+  (pair … octAND0 (pair … octAND1 (pair … octAND2 (pair … octAND3 (pair … octAND4 (pair … octAND5 (pair … octAND6 octAND7))))))).
+
+(* ora e' possibile fare
+   octNOT uoctX
+   octAND uoctX uoctY
+*)