Proof with auto with real.
intros.
rewrite partition_0...
Focus 2.
intro.
cset (natBelow_unique _ _ H0).
subst i.
apply (lt_asym _ _ H iltj).
rewrite Rplus_0_l.
rewrite monoid_expec_plus...
rewrite monoid_expec_plus...
rewrite monoid_expec_ret...
rewrite Rplus_0_r.
rewrite (@sound_cmp_expec_0 ee ol i j (flt pi Gt))...
Focus 2.
right.
apply not_In_flt.
intro.
apply (lt_asym _ _ H).
cset (Ecmp_sym ee (subscript (vec.nth v pi)) (subscript j)).
simpl in H0.
simpl in H1.
rewrite <- H0 in H1.
simpl in H1.
apply (IndicesCorrect _ _ H1).
rewrite Rplus_0_r.
case_eq (Ecmp ee (subscript j) (subscript (vec.nth v pi))); intro.
(* j in the Eq part *)
unfold Rdiv.
rewrite sound_cmp_expec_0...
right.
apply not_In_flt...
simpl.
simpl in H0. simpl.
rewrite H0. intro. discriminate.
Focus 2.
(* in the Gt part, impossible *)
elimtype False.
cset (Ecmp_sym ee (subscript (vec.nth v pi)) (subscript j)).
rewrite H0 in H1.
simpl in H1.
apply (lt_asym _ _ H).
apply (IndicesCorrect _ _ H1)...
(* in the Lt part *)
apply IH with b...
unfold flt.
assert (length (vec.nth v pi :: vec.remove v pi) = S n).
simpl @length. rewrite vec.length...
assert (IndexSeq b (vec.nth v pi :: vec.remove v pi)).
apply IndexSeq_perm with v...
apply (vec.List_Permutation (vec.remove_perm pi v)).
cset (@IndexSeq_filterLt ee ol (vec.nth v pi) (S n) b (vec.nth v pi :: vec.remove v pi) H1 H2).
simpl filter in H3.
rewrite Ecmp_refl in H3...
intros.
repeat rewrite monoid_expec_plus...
Qed.

(* Specifications: *)
Lemma case_C: (i < vec.nth v pi)%nat -> (vec.nth v pi < j)%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))
= 0.