intuition.
specialize (@fundamental_lemma_h B eqdb (a <-$ c1; ret (proj a, badness a)) (a <-$ c2; ret (proj a, badness a)) ); intuition.
assert ( | evalDist (x <-$ (a0 <-$ c1; ret (proj a0, badness a0)); ret fst x) x -
evalDist (x <-$ (a0 <-$ c2; ret (proj a0, badness a0)); ret fst x) x | ==
| evalDist (a <-$ c1; ret proj a) x - evalDist (a <-$ c2; ret proj a) x |).
eapply ratDistance_eqRat_compat.
eapply eqRat_trans.
eapply evalDist_assoc_eq.
cbv beta.
eapply eqRat_trans.
eapply evalDist_seq_eq.
intuition.
eapply eqRat_refl.
intuition.
eapply eqRat_trans.
eapply evalDist_left_ident_eq.
eapply eqRat_refl.
cbv beta.
unfold fst.
intuition.
eapply eqRat_trans.
eapply evalDist_assoc_eq.
cbv beta.
eapply evalDist_seq_eq; intuition.
eapply evalDist_left_ident_eq.
rewrite <- H2.
rewrite H1.
eapply leRat_trans.
eapply eqRat_impl_leRat.
eapply eqRat_trans.
eapply evalDist_assoc_eq.
cbv beta.
eapply evalDist_seq_eq; intuition.
eapply eqRat_refl.
eapply eqRat_trans.
eapply evalDist_left_ident_eq.
cbv beta.
eapply eqRat_refl.
cbv beta.
unfold snd.
intuition.
eapply eqRat_trans.
eapply evalDist_assoc_eq.
eapply eqRat_trans.
eapply evalDist_seq_eq; intuition.
eapply eqRat_refl.
eapply eqRat_trans.
eapply evalDist_left_ident_eq.
cbv beta.
eapply eqRat_refl.
rewrite H.
symmetry.
eapply eqRat_trans.
eapply evalDist_assoc_eq.
eapply eqRat_trans.
eapply evalDist_seq_eq; intuition.
eapply eqRat_refl.
eapply eqRat_trans.
eapply evalDist_left_ident_eq.
eapply eqRat_refl.
cbv beta.
simpl.
intuition.
intuition.
Qed.

(* Specifications: *)
Theorem repeat_unroll_eq: forall (A : Set)(eqd : EqDec A)(c : Comp A)(P : A -> bool) v,
well_formed_comp c ->
(exists a, In a (filter P (getSupport c))) ->
evalDist (Repeat c P) v == evalDist (x <-$ c; if (P x) then ret x else (Repeat c P)) v.