]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/freescale/nat.ma
Setoids, setoids1, sets, and the like. The mess begins.
[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 eq_nat (n1,n2:nat) on n1 ≝
41  match n1 with
42   [ O ⇒ match n2 with [ O ⇒ true | S _ ⇒ false ]
43   | S n1' ⇒ match n2 with [ O ⇒ false | S n2' ⇒ eq_nat n1' n2' ]
44   ].
45
46 nlet rec le_nat n m ≝ 
47  match n with 
48   [ O ⇒ true
49   | (S p) ⇒ match m with 
50    [ O ⇒ false | (S q) ⇒ le_nat p q ]
51   ].
52
53 nlet rec plus (n1,n2:nat) on n1 ≝ 
54  match n1 with
55   [ O ⇒ n2
56   | (S n1') ⇒ S (plus n1' n2) ].
57
58 interpretation "natural plus" 'plus x y = (plus x y).
59
60 nlet rec times (n1,n2:nat) on n1 ≝ 
61  match n1 with 
62   [ O ⇒ O
63   | (S n1') ⇒ n2 + (times n1' n2) ].
64
65 interpretation "natural times" 'times x y = (times x y).
66
67 nlet rec minus n m ≝ 
68  match n with 
69  [ O ⇒ O
70  | (S p) ⇒ 
71         match m with
72         [O ⇒ (S p)
73   | (S q) ⇒ minus p q ]].
74
75 interpretation "natural minus" 'minus x y = (minus x y).
76
77 nlet rec div_aux p m n : nat ≝
78 match (le_nat m n) with
79 [ true ⇒ O
80 | false ⇒
81   match p with
82   [ O ⇒ O
83   | (S q) ⇒ S (div_aux q (m-(S n)) n)]].
84
85 ndefinition div : nat → nat → nat ≝
86 λn,m.match m with 
87  [ O ⇒ S n
88  | (S p) ⇒ div_aux n n p]. 
89
90 interpretation "natural divide" 'divide x y = (div x y).