Library nats
Natural numbers
The inductive definition of nat is outside of the capabilities
of first-order logic: it has a number of implicit consequences shown
next.
Note here the use of inversion on equalities between constructors
of the inductive type nat.
Goal forall x:nat, O <> S x.
Proof.
intros x H.
inversion H.
Qed.
Goal forall x y : nat, S x = S y -> x = y.
Proof.
intros x y H.
inversion H.
reflexivity.
Qed.
We can use destruct to perform case analysis over a natural number.
Goal forall x:nat, x = O \/ exists y:nat, x = S y.
Proof.
intro x. destruct x.
+ left. reflexivity.
+ right. exists x. reflexivity.
Qed.
An induction principle is also derived from the inductive definition,
which is implicitly used through the induction tactic.
Note that the induction principle is a higher-order formula,
quantifying over Prop.
Check nat_ind.
Lemma Sx_x : forall x:nat, S x <> x.
Proof.
intros x H.
induction x.
+ inversion H.
+ inversion H. apply IHx. exact H1.
Qed.
Addition
Print plus.
In the next proof we use simpl to compute 1+1.
Note that the proof script works without this explicit
simplification step.
Goal 2 = 1+1.
Proof.
simpl.
reflexivity.
Qed.
Goal forall x y : nat, S x + y = S (x+y).
Proof.
intros. reflexivity.
Qed.
Lemma plus_S : forall x y : nat, x + S y = S (x + y).
Proof.
admit.
Qed.
Lemma plus_O : forall x:nat, x + O = x.
Proof.
admit.
Qed.
Lemma commutativity : forall x y : nat, x + y = y + x.
Proof.
admit.
Qed.
Order
If x <= y holds it must have been obtained through one of the
two constructors: the corresponding case analysis rule is given
by the inversion tactic.
Goal forall x y : nat, x <= y -> x = y \/ x <= pred y.
Proof.
intros x y H. inversion H.
+ left. reflexivity.
+ right.
simpl. exact H0.
Qed.
Theorem le_O : forall x:nat, O <= x.
Proof.
admit.
Qed.
Theorem le_S_S : forall x:nat, forall y:nat,
S x <= S y -> x <= y.
Proof.
admit.
Qed.
x<y is a notation for lt x y which is itself defined
in terms of le.
Print lt.
Theorem le_lt : forall x:nat, forall y:nat, x < S y -> x <= y.
Proof.
admit.
Qed.
Theorem lt_S_case : forall x:nat, forall y:nat,
x < S y -> x = y \/ x < y.
Proof.
admit.
Qed.