Section DistMult_impl_RepeatCore.
Variable A B : Set.
Hypothesis B_EqDec : EqDec B.
Variable P : B -> bool.
Variable c1 c2 : A -> Comp B.
Variable A_State : Set.
Variable A1 : Comp (A * A_State).
Variable A2 : A_State -> B -> Comp bool.
Hypothesis A1_wf : well_formed_comp A1.
Hypothesis A2_wf : forall s_A b, well_formed_comp (A2 s_A b).
Hypothesis c1_wf : forall a s_A, In (a, s_A) (getSupport A1) -> well_formed_comp (c1 a).
Hypothesis c1_repeat_wf : forall a s_A, In (a, s_A) (getSupport A1) -> exists b, In b (filter P (getSupport (c1 a))).
Hypothesis c2_wf : forall a s_A, In (a, s_A) (getSupport A1) -> well_formed_comp (c2 a).
Hypothesis c2_repeat_wf : forall a s_A, In (a, s_A) (getSupport A1) -> exists b, In b (filter P (getSupport (c2 a))).
Variable n : nat.
(* Assume A1 can effectively distinguish the cores as in RepeatCore_G, construct an adversary B that can distinguish the entire distributions given multiple samples as in DistMult_G. *)
Definition DM_RC_G1(c : A -> Comp B) :=
[a, s_A] <-$2 A1;
p <-$ Repeat (b <-$ (c a); g <-$ (A2 s_A b); ret (b, g)) (fun p => P (fst p));
ret (snd p).

Theorem DM_RC_G1_equiv :
forall c x,
(forall a s_A, In (a, s_A) (getSupport A1) -> well_formed_comp (c a)) ->
(forall a s_A, In (a, s_A) (getSupport A1) -> exists b, In b (filter P (getSupport (c a)))) ->
evalDist (RepeatCore_G P A1 A2 c) x == evalDist (DM_RC_G1 c) x.