unfold TrueRepeat_G1, TrueRepeat_G2.
repeat (inline_first; comp_skip).
destruct (hd_error (filter P x0)).
comp_simp.
dist_compute.
rewrite e in n0.
simpl in *.
intuition.
eapply rat0_le_all.
comp_simp.
dist_compute.
rewrite e in n0.
simpl in *.
intuition.
eapply rat0_le_all.
Qed.
Definition TrueRepeat_G3 :=
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 (fold_left (fun b x => b || (f x)) bs false, if b_opt then false else true).

Theorem TrueRepeat_G2_G3_equiv :
Pr[x <-$ TrueRepeat_G2; ret (fst x || snd x)] <=
Pr[x <-$ TrueRepeat_G3; ret (fst x || snd x)].