]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/freescale/nat.ma
aacc7b1dd26f3d0d398751ee25ba661ccaa854e7
[helm.git] / helm / software / matita / contribs / ng_assembly / freescale / nat.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: Cosimo Oliboni, oliboni@cs.unibo.it                   *)
19 (*     Cosimo Oliboni, oliboni@cs.unibo.it                                *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "freescale/pts.ma".
24 include "freescale/bool.ma".
25
26 (* ******** *)
27 (* NATURALI *)
28 (* ******** *)
29
30 inductive nat : Type ≝
31   O : nat
32 | S : nat → nat.
33
34 interpretation "Natural numbers" 'N = nat.
35
36 default "natural numbers" cic:/matita/freescale/nat/nat.ind.
37
38 alias num (instance 0) = "natural number".
39
40 nlet rec nat_ind (P:nat → Prop) (p:P O) (f:Πn:nat.P n → P (S n)) (n:nat) on n : P n ≝
41  match n with [ O ⇒ p | S (n1:nat) ⇒ f n1 (nat_ind P p f n1) ].
42
43 nlet rec nat_rec (P:nat → Set) (p:P O) (f:Πn:nat.P n → P (S n)) (n:nat) on n : P n ≝
44  match n with [ O ⇒ p | S (n1:nat) ⇒ f n1 (nat_rec P p f n1) ].
45
46 nlet rec nat_rect (P:nat → Type) (p:P O) (f:Πn:nat.P n → P (S n)) (n:nat) on n : P n ≝
47  match n with [ O ⇒ p | S (n1:nat) ⇒ f n1 (nat_rect P p f n1) ].
48
49 nlet rec eq_nat (n1,n2:nat) on n1 ≝
50  match n1 with
51   [ O ⇒ match n2 with [ O ⇒ true | S _ ⇒ false ]
52   | S n1' ⇒ match n2 with [ O ⇒ false | S n2' ⇒ eq_nat n1' n2' ]
53   ].
54
55 nlet rec le_nat n m ≝ 
56  match n with 
57   [ O ⇒ true
58   | (S p) ⇒ match m with 
59    [ O ⇒ false | (S q) ⇒ le_nat p q ]
60   ].
61
62 nlet rec plus (n1,n2:nat) on n1 ≝ 
63  match n1 with
64   [ O ⇒ n2
65   | (S n1') ⇒ S (plus n1' n2) ].
66
67 interpretation "natural plus" 'plus x y = (plus x y).
68
69 nlet rec times (n1,n2:nat) on n1 ≝ 
70  match n1 with 
71   [ O ⇒ O
72   | (S n1') ⇒ n2 + (times n1' n2) ].
73
74 interpretation "natural times" 'times x y = (times x y).
75
76 nlet rec minus n m ≝ 
77  match n with 
78  [ O ⇒ O
79  | (S p) ⇒ 
80         match m with
81         [O ⇒ (S p)
82   | (S q) ⇒ minus p q ]].
83
84 interpretation "natural minus" 'minus x y = (minus x y).
85
86 nlet rec div_aux p m n : nat ≝
87 match (le_nat m n) with
88 [ true ⇒ O
89 | false ⇒
90   match p with
91   [ O ⇒ O
92   | (S q) ⇒ S (div_aux q (m-(S n)) n)]].
93
94 ndefinition div : nat → nat → nat ≝
95 λn,m.match m with 
96  [ O ⇒ S n
97  | (S p) ⇒ div_aux n n p]. 
98
99 interpretation "natural divide" 'divide x y = (div x y).