]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/nat/nat.ma
9fce4df76a8b3dfbd7071582202ea648676d884b
[helm.git] / helm / software / matita / library / nat / nat.ma
1 (**************************************************************************)
2 (*       ___                                                                  *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
8 (*      ||A||       E.Tassi, S.Zacchiroli                                 *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU Lesser General Public License Version 2.1         *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "higher_order_defs/functions.ma".
16
17 inductive nat : Set \def
18   | O : nat
19   | S : nat \to nat.
20
21 definition pred: nat \to nat \def
22  \lambda n:nat. match n with
23  [ O \Rightarrow  O
24  | (S p) \Rightarrow p ].
25
26 theorem pred_Sn : \forall n:nat.n=(pred (S n)).
27  intros. simplify. reflexivity.
28 qed.
29
30 theorem injective_S : injective nat nat S.
31  unfold injective.
32  intros.
33  rewrite > pred_Sn.
34  rewrite > (pred_Sn y).
35  apply eq_f. assumption.
36 qed.
37
38 theorem inj_S : \forall n,m:nat.(S n)=(S m) \to n=m \def
39  injective_S.
40
41 theorem not_eq_S  : \forall n,m:nat. 
42  \lnot n=m \to S n \neq S m.
43  intros. unfold Not. intros.
44  apply H. apply injective_S. assumption.
45 qed.
46
47 definition not_zero : nat \to Prop \def
48  \lambda n: nat.
49   match n with
50   [ O \Rightarrow False
51   | (S p) \Rightarrow True ].
52
53 theorem not_eq_O_S : \forall n:nat. O \neq S n.
54  intros. unfold Not. intros.
55  cut (not_zero O).
56  exact Hcut.
57  rewrite > H.exact I.
58 qed.
59
60 theorem not_eq_n_Sn : \forall n:nat. n \neq S n.
61  intros.elim n.
62  apply not_eq_O_S.
63  apply not_eq_S.assumption.
64 qed.
65
66 theorem nat_case:
67  \forall n:nat.\forall P:nat \to Prop. 
68   P O \to  (\forall m:nat. P (S m)) \to P n.
69 intros.elim n
70   [ assumption
71   | apply H1 ]
72 qed.
73
74 theorem nat_case1:
75  \forall n:nat.\forall P:nat \to Prop. 
76   (n=O \to P O) \to  (\forall m:nat. (n=(S m) \to P (S m))) \to P n.
77 intros 2; elim n
78   [ apply H;reflexivity
79   | apply H2;reflexivity ]
80 qed.
81
82 theorem nat_elim2 :
83  \forall R:nat \to nat \to Prop.
84   (\forall n:nat. R O n) 
85   \to (\forall n:nat. R (S n) O) 
86   \to (\forall n,m:nat. R n m \to R (S n) (S m))
87   \to \forall n,m:nat. R n m.
88 intros 5;elim n 
89   [ apply H
90   | apply (nat_case m)
91     [ apply H1
92     | intro; apply H2; apply H3 ] ]
93 qed.
94
95 theorem decidable_eq_nat : \forall n,m:nat.decidable (n=m).
96  intros.unfold decidable.
97  apply (nat_elim2 (\lambda n,m.(Or (n=m) ((n=m) \to False))))
98  [ intro; elim n1
99    [ left; reflexivity
100    | right; apply not_eq_O_S ]
101  | intro; right; intro; apply (not_eq_O_S n1); apply sym_eq; assumption
102  | intros; elim H
103    [ left; apply eq_f; assumption
104    | right; intro; apply H1; apply inj_S; assumption ] ]
105 qed.