Section contents.
Variables (ee: E) (ol: list ee).
Proof with auto with real.
unfold RsumOver.
intros.
assert (NoDup l).
apply IndexSeq_NoDup with 0%nat...
unfold monoid_expec.
rewrite <- (expec_map (@fst U.monoid (list (Index ee ol))) length).
apply (list_length_expec.exp_list_sum_le U.UcmpDec).
intros.
rewrite expec_map.
destruct i.
simpl expec.
simpl snd.
simpl @fst.
cset qs_cmp_prob.qs_comp_prob.
unfold monoid_expec in H2.
unfold U.ijcount in H2.
unfold list_length_expec.beq_X.
unfold U.UcmpCmp in H2.
destruct (In_ijs_inv _ _ _ H1).
assert (lt n (length l)).
apply lt_trans with n0...
destruct (In_map_inv (H _ (le_O_n _) H5)).
destruct (In_map_inv (H _ (le_O_n _) H4)).
destruct H6. destruct H7.
unfold compose in H2.
unfold compose.
unfold U.monoid in H2.
simpl monoid_type in H2.
assert (lt x x0).
rewrite H6.
rewrite H7...
cset (H2 ee ol x x0 H10 l 0%nat H).
rewrite H6 in H11.
rewrite H7 in H11...
intros.
rewrite expec_map.
replace 0 with (INR 0)...
apply expec_constant.
intros.
unfold compose.
apply count_0.
intros.
destruct x0.
destruct (qs_sound_cmps.qs_sound_cmps_2 l H2 n n0 H3).
cset (qs_sound_cmps.qs_sound_cmps H2 H0 n n0 H3).
unfold list_length_expec.beq_X.
destruct (U.UcmpDec i (n, n0))...
elimtype False.
apply H1. clear H1.
subst.
apply In_ijs...
destruct (In_map_inv H5).
destruct H1.
destruct (IndexSeq_inv H x0 H7).
subst...
Qed.
Require NDP.

Theorem qs_expec_cost:
expec cost (NDP.qs ee ol) <= 2 * INR (length ol) * INR (S (log2ceil (length ol))).