(** *Even length*)
Inductive even : nat -> Prop :=
| EvenO : even 0
| EvenS : forall n, even n -> even (S (S n)).
Function length_of_even (ls:list nat) : option nat :=
match ls with
| nil => Some 0
| cons x1 (cons x2 ls') =>
match length_of_even ls' with
| Some n' => Some ( 2 + n')
| _ => None
end
| cons x nil => None
end.
(** * Perm_of_sh *)
Print perm_of_sh.
(** * Merge *)
Definition double_measure (lss: list nat * list nat):= (length (fst lss) + length (snd lss)).
Function merge (lss: list nat * list nat)
{measure double_measure}:=
match lss with
| (ls1, ls2) =>
match ls1 with
nil => ls2
| cons n ls1' =>
match ls2 with
nil => ls1
| cons m ls2' =>
if n <? m then
cons n (merge (ls1', ls2))
else
cons m (merge (ls1, ls2'))
end
end
end.
- intros; simpl.
unfold double_measure; simpl.
omega.
- intros; simpl.
unfold double_measure; simpl.
omega.
Defined.

Lemma merge_length: forall lss,
length (merge lss) = length (fst lss) + length (snd lss).