Set Implicit Arguments.
Require vec.
Definition numbers := 3 :: 2 :: 5 :: 9 :: 7 :: 6 :: 1 :: 0 :: 4 :: 8 :: nil.
Require Vector.
Hint Constructors vec.sorted.
Instance insert_perm_mor: Proper (eq ==> Permutation ==> Permutation) insert.
Proof with eauto.
repeat intro.
induction H0; subst; simpl...
destruct (le y x0)...
destruct (le y y0); destruct (le y x0)...
Qed.
Hypotheses
(le_yippee: forall x y, le x y = false -> le y x = true)
(preorder_R: preorder _ R).
Proof with auto.
induction l.
simpl.
intros.
apply vec.sorted_one.
intros.
pose proof (vec.sorted_tail H).
apply IHl in H0.
simpl.
case_eq (le x a); intro.
simpl.
apply vec.sorted_more...
simpl.
apply vec.sorted_cons'...
pose proof (le_yippee H1).
intros.
rewrite vec.list_round_trip in H3.
unfold R.
destruct (Permutation_in _ (insert_perm x l) H3).
subst...
simpl in H.
apply (vec.sorted_cons_inv' preorder_R H).
rewrite vec.list_round_trip...
Qed.
Definition isort: list T -> list T := fold_right insert nil.

Lemma isort_permutes l: Permutation (isort l) l.