Section contents.
Variable X: Set.
Variable Xle: X -> X -> Prop.
Hypothesis XO: preorder X Xle.
Definition Xlt (x y: X): Prop := Xle x y /\ ~ Xle y x.
(* Vsorted *)
Inductive sorted: forall n, Vector.t X n -> Prop := (* Coq.Sorting's definition sucks *)
| sorted_nil: sorted Vector.nil
| sorted_one x: sorted (Vector.cons x Vector.nil)
| sorted_more (a b: X) n (t: Vector.t X n):
Xle a b -> sorted (Vector.cons b t) -> sorted (Vector.cons a (Vector.cons b t)).
Hint Constructors sorted.
Proof with auto.
intros.
rewrite (eq_cons v).
apply sorted_more...
rewrite <- eq_cons...
Qed.
Proof with auto.
induction v; intros.
apply sorted_one.
apply sorted_more...
apply H. left...
Qed.
Proof with auto.
induction v...
intros.
simpl.
apply sorted_cons'.
intros.
clear IHv.
rewrite list_round_trip in H2.
destruct (List.in_app_or v w y H2).
simpl in H.
apply (sorted_cons_inv' H).
rewrite list_round_trip...
apply H1...
left...
apply IHv...
simpl in H.
apply sorted_tail with a...
intros.
apply H1...
simpl...
Qed.

Lemma sorted_le_indices_le_values n (v: Vector.t X n): sorted v ->
forall (i j: natBelow n), i <= j -> Xle (nth v i) (nth v j).