Proof with auto with real.
rewrite expand_sumOver_ijs.
simpl snd.
simpl @fst.
apply Rle_trans with (RsumOver (nats 0 n) (fun _ => 2 * INR (S (log2ceil n)))).
apply RsumOver_le.
intros.
change (fun i => _) with (compose (fun i => 2 / INR (S i)) (minus x)).
rewrite RsumOver_minus...
rewrite plus_0_r.
rewrite <- minus_n_n...
apply Rle_trans with (RsumOver (nats 1 x) (fun i => 2 / INR i)).
apply RsumOver_le.
intros.
unfold Rdiv.
apply Rmult_le_compat_l...
destruct (In_nats_inv _ _ _ H0).
apply RIneq.Rle_Rinv...
rewrite <- (RsumOver_mult_constant (fun i => / INR i) 2).
apply Rmult_le_compat_l...
apply Rle_trans with (RsumOver (nats 1 n) (Rinv ∘ INR)).
apply RsumOver_nats_le.
destruct (In_nats_inv _ _ _ H)...
intros.
unfold Rdiv.
destruct q.
inversion H0.
unfold compose.
apply O_le_inv_INR_S.
apply harmonic.upper_bound.
fold (compose (Rmult 2) (fun _: nat => INR (S (log2ceil n)))).
rewrite <- RsumOver_mult_constant.
rewrite Rmult_assoc.
unfold RsumOver.
rewrite Rsum_constant with (INR (S (log2ceil n))) (map (fun _ => INR (S (log2ceil n))) (nats 0 n)).
rewrite map_length.
rewrite nats_length...
intros.
destruct (In_map_inv H).
destruct H0...
Qed.
Require U.
Require list_length_expec.
Require qs_definitions.
Require qs_parts.
Require qs_sound_cmps.
Require qs_cmp_prob.
Require qs_CM_U_expec_cost_eq.
Arguments length {A}.
Section contents.
Variables (ee: E) (ol: list ee).

Theorem Umonoid_expec_qs_bounded_by_sumOver_ijs l: IndexSeq 0 l ->
@monoid_expec U.monoid length _ (qs (@U.cmp ee ol) U.pick l) <=
RsumOver (ijs (length l)) (fun ij => 2 / INR (S (snd ij - fst ij))).