Section TrueMult_impl_Repeat.
Variable A B : Set.
Hypothesis eqdb : EqDec B.
Variable A1 : Comp A.
Hypothesis A1_wf :
well_formed_comp A1.
Variable c : A -> Comp B.
Variable f P : B -> bool.
Hypothesis c_wf :
forall x, In x (getSupport A1) -> well_formed_comp (c x).
Hypothesis Repeat_c_terminating :
forall x, In x (getSupport A1) ->
exists x1 : B, In x1 (filter P (getSupport (c x))).
Definition TrueRepeat_G :=
a <-$ A1;
b <-$ Repeat (c a) P;
ret (f b).
Variable n : nat.
Variable failProb : Rat.
Hypothesis failProb_correct :
forall (a : A),
In a (getSupport A1) ->
Pr[x <-$ c a; ret negb (P x)] <= failProb.
Definition TrueRepeat_G1 :=
a <-$ A1;
bs <-$ compMap _ (fun _ => c a) (forNats n);
b_opt <- hd_error (filter P bs);
b' <-$ Repeat (c a) P;
b <- match b_opt with
| None => b'
| Some x => x
end;
ret (f b).

Theorem  TrueRepeat_G_G1_equiv :
Pr[ TrueRepeat_G] == Pr[TrueRepeat_G1].