Inductive list (X: Type) := nil | cons : X -> list X -> list X.
This declaration introduces three names:
- list : Type -> Type
- nil : forall X:Type, list X
- cons : forall X:Type, X -> list X -> list X.
Implicit Arguments nil [X].
Implicit Arguments cons [X].
Notation "x :: y" := (cons x y) (at level 60, right associativity).
Notation "[ x , .. , y ]" := (cons x .. (cons y nil) ..).
Fixpoint length X (xs: list X) := match xs with
| nil => 0
| x::xr => S(length X xr)
end.
Implicit Arguments length [X].
Fixpoint app X (xs ys: list X) := match xs with
| nil => ys
| x::xr => x::app X xr ys
end.
Implicit Arguments app [X].
Notation "x ++ y" := (app x y) (at level 60, right associativity).
Fixpoint rev X (xs: list X) := match xs with
| nil => nil
| x::xr => rev X xr ++ ([x]: list X)
end.
Implicit Arguments rev [X].
Proposition P1: forall X (xs ys: list X),
length(xs++ys) = length xs + length ys.
Proof. intros. induction xs.
trivial.
simpl. rewrite IHxs. trivial.
Qed.
Proposition P2: forall X (xs: list X),
xs ++ nil = xs.
Proof. induction xs.
trivial.
simpl. rewrite IHxs. trivial.
Qed.
Proposition P3: forall X (xs ys zs: list X),
xs++(ys++zs) = (xs++ys)++zs.
Proof. intros. induction xs.
trivial.
simpl. rewrite IHxs. trivial.
Qed.
Proposition P4: forall X (xs ys: list X),
rev(xs++ys) = rev ys ++ rev xs.
Proof. intros. induction xs.
simpl. rewrite P2. trivial.
simpl. rewrite IHxs. rewrite P3. trivial.
Qed.
Proposition P5 : forall X (xs: list X),
rev (rev xs) = xs.
Proof. induction xs.
trivial.
simpl. rewrite P4. rewrite IHxs. trivial.
Qed.
This page has been generated by coqdoc