Proof with auto with real.
intros.
rewrite partition_0...
Focus 2.
intro.
rewrite H0 in H.
apply (lt_asym _ _ H iltj).
rewrite Rplus_0_l.
rewrite monoid_expec_plus... Focus 2. intros. repeat rewrite monoid_expec_plus...
rewrite monoid_expec_plus...
rewrite monoid_expec_ret...
rewrite Rplus_0_r.
rewrite sound_cmp_expec_0...
Focus 2.
left.
apply not_In_flt...
intro.
apply (lt_asym _ _ H).
symmetry in H0.
apply (IndicesCorrect _ _ H0).
rewrite Rplus_0_l.
case_eq (Ecmp ee (subscript i) (subscript (vec.nth v pi))); intro.
(* i in the Eq part *)
unfold Rdiv.
rewrite sound_cmp_expec_0...
left.
apply not_In_flt...
simpl.
simpl in H0.
rewrite H0. intro. discriminate.
(* in the Lt part, impossible *)
elimtype False.
apply (lt_irrefl i).
apply lt_trans with (vec.nth v pi)...
apply (IndicesCorrect i (vec.nth v pi))...
(* i in the Gt part. recursive sorting of upper part: *)
assert (IndexSeq b (vec.nth v pi :: vec.remove v pi)).
apply IndexSeq_perm with v...
cset (vec.List_Permutation (vec.remove_perm pi v))...
apply (IH _ Gt (@InvIndexSeq_filterGt' ee ol (vec.nth v pi) (vec.remove v pi) b H1))...
Qed.

Lemma case_E: (j < vec.nth v pi)%nat ->
INR (U.ijcount i j (map (fun i0: Index ee ol => U.unordered_nat_pair i0 (vec.nth v pi)) (vec.remove v pi))) +
monoid_expec (U.ijcount i j)
(foo <- @U.qs ee ol (flt pi Lt);
bar <- @U.qs ee ol (flt pi Gt);
ret (foo ++ (vec.nth v pi :: flt pi Eq) ++ bar))
<= 2 * / INR (S (j - i)).