]> matita.cs.unibo.it Git - helm.git/blob - matitaB/matita/contribs/ng_assembly/common/nat_to_num.ma
mod change (-x)
[helm.git] / matitaB / matita / contribs / ng_assembly / common / nat_to_num.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
19 (*   Sviluppo: 2008-2010                                                  *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "common/nat.ma".
24 include "num/word32.ma".
25
26 (* ************************ *)
27 (* NUMERI FINITI → NATURALI *)
28 (* ************************ *)
29
30 nlet rec nat_of_qu_aux n (r:rec_quatern n) on r ≝
31  match r with
32   [ qu_O ⇒ O
33   | qu_S t n' ⇒ S (nat_of_qu_aux t n')
34   ].
35
36 ndefinition nat_of_qu : quatern → nat ≝ λn.nat_of_qu_aux n (qu_to_recqu n).
37
38 nlet rec nat_of_oct_aux n (r:rec_oct n) on r ≝
39  match r with
40   [ oc_O ⇒ O
41   | oc_S t n' ⇒ S (nat_of_oct_aux t n')
42   ].
43
44 ndefinition nat_of_oct : oct → nat ≝ λn.nat_of_oct_aux n (oct_to_recoct n).
45
46 nlet rec nat_of_ex_aux n (r:rec_exadecim n) on r ≝
47  match r with
48   [ ex_O ⇒ O
49   | ex_S t n' ⇒ S (nat_of_ex_aux t n')
50   ].
51
52 ndefinition nat_of_ex : exadecim → nat ≝ λn.nat_of_ex_aux n (ex_to_recex n).
53
54 nlet rec nat_of_bit_aux n (r:rec_bitrigesim n) on r ≝
55  match r with
56   [ bi_O ⇒ O
57   | bi_S t n' ⇒ S (nat_of_bit_aux t n')
58   ].
59
60 ndefinition nat_of_bit : bitrigesim → nat ≝ λn.nat_of_bit_aux n (bit_to_recbit n).
61
62 nlet rec nat_of_b8_aux n (r:rec_byte8 n) on r ≝
63  match r with
64   [ b8_O ⇒ O
65   | b8_S t n' ⇒ S (nat_of_b8_aux t n')
66   ].
67
68 ndefinition nat_of_b8 : byte8 → nat ≝ λn:byte8.nat_of_b8_aux n (b8_to_recb8 n).
69
70 nlet rec nat_of_w16_aux n (r:rec_word16 n) on r : nat ≝
71  match r with
72   [ w16_O ⇒ O
73   | w16_S t n' ⇒ S (nat_of_w16_aux t n')
74   ].
75
76 ndefinition nat_of_w16 : word16 → nat ≝ λn:word16.nat_of_w16_aux n (w16_to_recw16 n).
77
78 ndefinition nat_of_w32 : word32 → nat ≝ λn:word32.(nat65536 * (nat_of_w16 (cnH ? n))) + (nat_of_w16 (cnL ? n)).