]> matita.cs.unibo.it Git - helm.git/blob - matita/library/nat/nat.ma
matita 0.5.1 tagged
[helm.git] / 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 theorem esempio: \forall A,B,C:Prop.(A \to B \to C) \to (A \to B)
18 \to A \to C.
19
20
21
22 inductive nat : Set \def
23   | O : nat
24   | S : nat \to nat.
25
26 definition pred: nat \to nat \def
27  \lambda n:nat. match n with
28  [ O \Rightarrow  O
29  | (S p) \Rightarrow p ].
30
31 theorem pred_Sn : \forall n:nat.n=(pred (S n)).
32  intros. simplify. reflexivity.
33 qed.
34
35 theorem injective_S : injective nat nat S.
36  unfold injective.
37  intros.
38  rewrite > pred_Sn.
39  rewrite > (pred_Sn y).
40  apply eq_f. assumption.
41 qed.
42
43 theorem inj_S : \forall n,m:nat.(S n)=(S m) \to n=m \def
44  injective_S.
45
46 theorem not_eq_S  : \forall n,m:nat. 
47  \lnot n=m \to S n \neq S m.
48  intros. unfold Not. intros.
49  apply H. apply injective_S. assumption.
50 qed.
51
52 definition not_zero : nat \to Prop \def
53  \lambda n: nat.
54   match n with
55   [ O \Rightarrow False
56   | (S p) \Rightarrow True ].
57
58 theorem not_eq_O_S : \forall n:nat. O \neq S n.
59  intros. unfold Not. intros.
60  cut (not_zero O).
61  exact Hcut.
62  rewrite > H.exact I.
63 qed.
64
65 theorem not_eq_n_Sn : \forall n:nat. n \neq S n.
66  intros.elim n.
67  apply not_eq_O_S.
68  apply not_eq_S.assumption.
69 qed.
70
71 theorem nat_case:
72  \forall n:nat.\forall P:nat \to Prop. 
73   P O \to  (\forall m:nat. P (S m)) \to P n.
74 intros.elim n
75   [ assumption
76   | apply H1 ]
77 qed.
78
79 theorem nat_case1:
80  \forall n:nat.\forall P:nat \to Prop. 
81   (n=O \to P O) \to  (\forall m:nat. (n=(S m) \to P (S m))) \to P n.
82 intros 2; elim n
83   [ apply H;reflexivity
84   | apply H2;reflexivity ]
85 qed.
86
87 theorem nat_elim2 :
88  \forall R:nat \to nat \to Prop.
89   (\forall n:nat. R O n) 
90   \to (\forall n:nat. R (S n) O) 
91   \to (\forall n,m:nat. R n m \to R (S n) (S m))
92   \to \forall n,m:nat. R n m.
93 intros 5;elim n 
94   [ apply H
95   | apply (nat_case m)
96     [ apply H1
97     | intro; apply H2; apply H3 ] ]
98 qed.
99
100 theorem decidable_eq_nat : \forall n,m:nat.decidable (n=m).
101  intros.unfold decidable.
102  apply (nat_elim2 (\lambda n,m.(Or (n=m) ((n=m) \to False))))
103  [ intro; elim n1
104    [ left; reflexivity
105    | right; apply not_eq_O_S ]
106  | intro; right; intro; apply (not_eq_O_S n1); apply sym_eq; assumption
107  | intros; elim H
108    [ left; apply eq_f; assumption
109    | right; intro; apply H1; apply inj_S; assumption ] ]
110 qed.