Proof with auto with arith.
intros s.
induction s.
intros.
inversion i.
intros i j.
rewrite (nb1 i).
rewrite (nb1 j).
simpl.
intro.
elimtype False.
apply (Xlt_irrefl H).
intro i. pattern i. apply natBelow_S_inv'; [idtac | intro m]; intro j; pattern j; apply natBelow_S_inv'.
rewrite nth_0.
intros.
elimtype False.
apply (Xlt_irrefl H0).
intro.
rewrite val_nb0.
rewrite val_Snb...
rewrite nth_S.
rewrite nth_0.
intros.
elimtype False.
apply (Xle_nlt H).
apply Xle_lt_trans with (nth (Vector.cons b t) m)...
apply (sorted_le_indices_le_values s (nb0 _) m)...
intro.
do 2 rewrite nth_S.
do 2 rewrite val_Snb...
Qed.
(* insertion sort *)
Variable XleDec: forall x y, { Xle x y } + { Xle y x }.
Fixpoint insert_ordered (x: X) n: Vector.t X n -> Vector.t X (S n) :=
match n return Vector.t X n -> Vector.t X (S n) with
| 0 => fun _ => Vector.cons x Vector.nil
| S n' => fun v => if XleDec x (head v)
then Vector.cons x v
else Vector.cons (head v) (insert_ordered x (tail v))
end.
Hint Immediate perm_refl.

(* Specifications: *)
Lemma insert_ordered_permutes x n (v: Vector.t X n): Permutation (insert_ordered x v) (Vector.cons x v).
Proof with auto.