Library Coq.Init.Peano
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
The predecessor function
Injectivity of successor
Zero is not the successor of a number
Addition
Standard associated names
Multiplication
Standard associated names
Truncated subtraction: m-n is 0 if n>=m
Fixpoint minus (
n m:
nat) :
nat :=
match n,
m with
|
O,
_ =>
n
|
S k,
O =>
n
|
S k,
S l =>
k - l
end
where "n - m" := (
minus n m) :
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.
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.
Theorem le_pred :
forall n m,
n <= m ->
pred n <= pred m.
Theorem le_S_n :
forall n m,
S n <= S m ->
n <= m.
Case analysis
Principle of double induction
Maximum and minimum : definitions and specifications
Fixpoint max n m :
nat :=
match n,
m with
|
O,
_ =>
m
|
S n´,
O =>
n
|
S n´,
S m´ =>
S (
max n´ m´)
end.
Fixpoint min n m :
nat :=
match n,
m with
|
O,
_ => 0
|
S n´,
O => 0
|
S n´,
S m´ =>
S (
min n´ m´)
end.
Theorem max_l :
forall n m :
nat,
m <= n ->
max n m = n.
Theorem max_r :
forall n m :
nat,
n <= m ->
max n m = m.
Theorem min_l :
forall n m :
nat,
n <= m ->
min n m = n.
Theorem min_r :
forall n m :
nat,
m <= n ->
min n m = m.
nth iteration of the function f
Preservation of invariants : if f : A->A preserves the invariant Inv,
then the iterates of f also preserve it.