1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(*i $Id: Peano.v 11735 2009-01-02 17:22:31Z herbelin $ i*)
11
(** The type [nat] of Peano natural numbers (built from [O] and [S])
12
is defined in [Datatypes.v] *)
14
(** This module defines the following operations on natural numbers :
17
- multiplication [mult]
18
- less or equal order [le]
20
- greater or equal [ge]
23
It states various lemmas and theorems about natural numbers,
24
including Peano's axioms of arithmetic (in Coq, these are provable).
25
Case analysis on [nat] and induction on [nat * nat] are provided too
28
Require Import Notations.
29
Require Import Datatypes.
31
Unset Boxed Definitions.
35
Definition eq_S := f_equal S.
37
Hint Resolve (f_equal S): v62.
38
Hint Resolve (f_equal (A:=nat)): core.
40
(** The predecessor function *)
42
Definition pred (n:nat) : nat := match n with
46
Hint Resolve (f_equal pred): v62.
48
Theorem pred_Sn : forall n:nat, n = pred (S n).
53
(** Injectivity of successor *)
55
Theorem eq_add_S : forall n m:nat, S n = S m -> n = m.
58
replace (n=m) with (pred (S n) = pred (S m)) by auto using pred_Sn.
59
rewrite Sn_eq_Sm; trivial.
62
Hint Immediate eq_add_S: core.
64
Theorem not_eq_S : forall n m:nat, n <> m -> S n <> S m.
68
Hint Resolve not_eq_S: core.
70
Definition IsSucc (n:nat) : Prop :=
76
(** Zero is not the successor of a number *)
78
Theorem O_S : forall n:nat, 0 <> S n.
80
unfold not; intros n H.
83
Hint Resolve O_S: core.
85
Theorem n_Sn : forall n:nat, n <> S n.
89
Hint Resolve n_Sn: core.
93
Fixpoint plus (n m:nat) {struct n} : nat :=
99
where "n + m" := (plus n m) : nat_scope.
101
Hint Resolve (f_equal2 plus): v62.
102
Hint Resolve (f_equal2 (A1:=nat) (A2:=nat)): core.
104
Lemma plus_n_O : forall n:nat, n = n + 0.
106
induction n; simpl in |- *; auto.
108
Hint Resolve plus_n_O: core.
110
Lemma plus_O_n : forall n:nat, 0 + n = n.
115
Lemma plus_n_Sm : forall n m:nat, S (n + m) = n + S m.
117
intros n m; induction n; simpl in |- *; auto.
119
Hint Resolve plus_n_Sm: core.
121
Lemma plus_Sn_m : forall n m:nat, S n + m = S (n + m).
126
(** Standard associated names *)
128
Notation plus_0_r_reverse := plus_n_O (only parsing).
129
Notation plus_succ_r_reverse := plus_n_Sm (only parsing).
131
(** Multiplication *)
133
Fixpoint mult (n m:nat) {struct n} : nat :=
139
where "n * m" := (mult n m) : nat_scope.
141
Hint Resolve (f_equal2 mult): core.
143
Lemma mult_n_O : forall n:nat, 0 = n * 0.
145
induction n; simpl in |- *; auto.
147
Hint Resolve mult_n_O: core.
149
Lemma mult_n_Sm : forall n m:nat, n * m + n = n * S m.
151
intros; induction n as [| p H]; simpl in |- *; auto.
152
destruct H; rewrite <- plus_n_Sm; apply (f_equal S).
153
pattern m at 1 3 in |- *; elim m; simpl in |- *; auto.
155
Hint Resolve mult_n_Sm: core.
157
(** Standard associated names *)
159
Notation mult_0_r_reverse := mult_n_O (only parsing).
160
Notation mult_succ_r_reverse := mult_n_Sm (only parsing).
162
(** Truncated subtraction: [m-n] is [0] if [n>=m] *)
164
Fixpoint minus (n m:nat) {struct n} : nat :=
171
where "n - m" := (minus n m) : nat_scope.
173
(** Definition of the usual orders, the basic properties of [le] and [lt]
174
can be found in files Le and Lt *)
176
Inductive le (n:nat) : nat -> Prop :=
178
| le_S : forall m:nat, n <= m -> n <= S m
180
where "n <= m" := (le n m) : nat_scope.
182
Hint Constructors le: core.
183
(*i equivalent to : "Hints Resolve le_n le_S : core." i*)
185
Definition lt (n m:nat) := S n <= m.
186
Hint Unfold lt: core.
188
Infix "<" := lt : nat_scope.
190
Definition ge (n m:nat) := m <= n.
191
Hint Unfold ge: core.
193
Infix ">=" := ge : nat_scope.
195
Definition gt (n m:nat) := m < n.
196
Hint Unfold gt: core.
198
Infix ">" := gt : nat_scope.
200
Notation "x <= y <= z" := (x <= y /\ y <= z) : nat_scope.
201
Notation "x <= y < z" := (x <= y /\ y < z) : nat_scope.
202
Notation "x < y < z" := (x < y /\ y < z) : nat_scope.
203
Notation "x < y <= z" := (x < y /\ y <= z) : nat_scope.
208
forall (n:nat) (P:nat -> Prop), P 0 -> (forall m:nat, P (S m)) -> P n.
213
(** Principle of double induction *)
215
Theorem nat_double_ind :
216
forall R:nat -> nat -> Prop,
217
(forall n:nat, R 0 n) ->
218
(forall n:nat, R (S n) 0) ->
219
(forall n m:nat, R n m -> R (S n) (S m)) -> forall n m:nat, R n m.
222
destruct m as [| n0]; auto.