intuition.
simpl in *.
rewrite (sumList_partition e).
eapply ratAdd_eqRat_compat.
rewrite (sumList_body_eq _ _ (fun b => ((evalDist c b) * (if (e b) then 1 else 0)) * v1)).
rewrite sumList_factor_constant_r.
eapply ratMult_eqRat_compat; intuition.
rewrite <- H0.
eapply sumList_body_eq; intuition.
destruct (EqDec_dec bool_EqDec (e a0) true).
rewrite e0.
intuition.
destruct (e a0); try congruence.
intuition.
intuition.
case_eq (e a0); intuition.
repeat rewrite ratMult_1_r.
eapply ratMult_eqRat_compat; intuition.
repeat rewrite ratMult_0_r.
rewrite ratMult_0_l.
intuition.
rewrite (sumList_body_eq _ _ (fun b => ((evalDist c b) * (if (e b) then 0 else 1)) * v2)).
rewrite sumList_factor_constant_r.
eapply ratMult_eqRat_compat; intuition.
rewrite <- H0.
rewrite <- (@evalDist_lossless _ c).
rewrite (sumList_partition e _ (evalDist c)).
rewrite ratAdd_comm.
rewrite ratSubtract_ratAdd_assoc.
rewrite ratSubtract_0.
rewrite <- ratAdd_0_r.
intuition.
eapply eqRat_impl_leRat.
eapply sumList_body_eq; intuition.
destruct (EqDec_dec bool_EqDec (e a0) true).
rewrite e0.
intuition.
destruct (e a0); try congruence.
intuition.
eapply eqRat_impl_leRat.
eapply sumList_body_eq; intuition.
destruct (EqDec_dec bool_EqDec (e a0) true).
rewrite e0.
intuition.
destruct (e a0); try congruence.
intuition.
trivial.
intuition.
case_eq (e a0); intuition.
repeat rewrite ratMult_0_r.
rewrite ratMult_0_l.
intuition.
repeat rewrite ratMult_1_r.
eapply ratMult_eqRat_compat; intuition.
Qed.

(* Specifications: *)
Theorem evalDist_bind_distance : forall (A B : Set)(c1 c2 : Comp B)(c3 c4 : B -> Comp A) d,
well_formed_comp c2 ->
(forall b, evalDist c1 b == evalDist c2 b) ->
(forall b a, In b (getSupport c1) -> | evalDist (c3 b) a - evalDist (c4 b) a | <= d) ->
(forall a, | evalDist (Bind c1 c3) a - evalDist (Bind c2 c4) a | <= d).