(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
(** The type [nat] of Peano natural numbers (built from [O] and [S]) is defined in [Datatypes.v] *)
(** This module defines the following operations on natural numbers : - predecessor [pred] - addition [plus] - multiplication [mult] - less or equal order [le] - less [lt] - greater or equal [ge] - greater [gt]  It states various lemmas and theorems about natural numbers, including Peano's axioms of arithmetic (in Coq, these are provable). Case analysis on [nat] and induction on [nat * nat] are provided too *)
Require Coq.Init.Nat.
Open Scope nat_scope.
Local Notation "0" := O.
Definition eq_S := f_equal S.
Definition f_equal_nat := f_equal (A:=nat).
Hint Resolve f_equal_nat: core.
(** The predecessor function *)
Notation pred := Nat.pred (only parsing).
Definition f_equal_pred := f_equal pred.
(** Injectivity of successor *)
Definition eq_add_S n m (H: S n = S m): n = m := f_equal pred H.
Hint Immediate eq_add_S: core.
Hint Resolve not_eq_S: core.
Definition IsSucc (n:nat) : Prop :=
match n with
| O => False
| S p => True
end.
(** Zero is not the successor of a number *)
Hint Resolve O_S: core.
Hint Resolve n_Sn: core.
(** Addition *)
Notation plus := Nat.add (only parsing).
Infix "+" := Nat.add : nat_scope.
Definition f_equal2_plus := f_equal2 plus.
Definition f_equal2_nat := f_equal2 (A1:=nat) (A2:=nat).
Hint Resolve f_equal2_nat: core.
Remove Hints eq_refl : core.
Hint Resolve plus_n_O eq_refl: core.  (* We want eq_refl to have higher priority than plus_n_O *)
Hint Resolve plus_n_Sm: core.
(** Standard associated names *)
Notation plus_0_r_reverse := plus_n_O (only parsing).
Notation plus_succ_r_reverse := plus_n_Sm (only parsing).
(** Multiplication *)
Notation mult := Nat.mul (only parsing).
Infix "*" := Nat.mul : nat_scope.
Definition f_equal2_mult := f_equal2 mult.
Hint Resolve f_equal2_mult: core.
Hint Resolve mult_n_O: core.
Hint Resolve mult_n_Sm: core.
(** Standard associated names *)
Notation mult_0_r_reverse := mult_n_O (only parsing).
Notation mult_succ_r_reverse := mult_n_Sm (only parsing).
(** Truncated subtraction: [m-n] is [0] if [n>=m] *)
Notation minus := Nat.sub (only parsing).
Infix "-" := Nat.sub : nat_scope.
(** Definition of the usual orders, the basic properties of [le] and [lt] can be found in files Le and Lt *)
Inductive le (n:nat) : nat -> Prop :=
| le_n : n <= n
| le_S : forall m:nat, n <= m -> n <= S m
where "n <= m" := (le n m) : nat_scope.
Hint Constructors le: core.
(*i equivalent to : "Hints Resolve le_n le_S : core." i*)
Definition lt (n m:nat) := S n <= m.
Hint Unfold lt: core.
Infix "<" := lt : nat_scope.
Definition ge (n m:nat) := m <= n.
Hint Unfold ge: core.
Infix ">=" := ge : nat_scope.
Definition gt (n m:nat) := m < n.
Hint Unfold gt: core.
Infix ">" := gt : nat_scope.
Notation "x <= y <= z" := (x <= y /\ y <= z) : nat_scope.
Notation "x <= y < z" := (x <= y /\ y < z) : nat_scope.
Notation "x < y < z" := (x < y /\ y < z) : nat_scope.
Notation "x < y <= z" := (x < y /\ y <= z) : nat_scope.
Register le as num.nat.le.
Register lt as num.nat.lt.
Register ge as num.nat.ge.
Register gt as num.nat.gt.
(** Case analysis *)
(** Principle of double induction *)
(** Maximum and minimum : definitions and specifications *)
Notation max := Nat.max (only parsing).
Notation min := Nat.min (only parsing).

Theorem nat_rect_plus :
forall (n m:nat) {A} (f:A -> A) (x:A),
nat_rect (fun _ => A) x (fun _ => f) (n + m) =
nat_rect (fun _ => A) (nat_rect (fun _ => A) x (fun _ => f) m) (fun _ => f) n.