Section TwoWorldsEquiv_eta.
Variable eta : nat.
Definition StandardDef_G :=
b <-$ {0, 1};
b' <-$ f eta b;
ret (eqb b b').
unfold StandardDef_G.
rewrite rndBool_bind.
assert ( Pr[b' <-$ f eta true; ret eqb true b'] == Pr[f eta true]).
symmetry.
rewrite <- evalDist_right_ident.
comp_skip.
fcf_compute.
rewrite H.
clear H.
assert ( Pr  [b' <-$ f eta false; ret eqb false b' ] == (ratSubtract 1 (Pr[f eta false]))).
assert (Pr  [b' <-$ f eta false; ret eqb false b' ]  == evalDist (f eta false) false).
symmetry.
rewrite <- evalDist_right_ident.
comp_skip.
fcf_compute.
rewrite H.
clear H.
eapply evalDist_bool_complement.
wftac.
rewrite H.
clear H.
rewrite <- ratMult_distrib.
rewrite <- (ratMult_1_r (1/2)) at 2.
rewrite ratMult_ratDistance_factor_l.
eapply ratMult_eqRat_compat; intuition.
assert ((Pr  [f eta false])  + ratSubtract 1 (Pr  [f eta false]) == 1).
rewrite <- ratSubtract_ratAdd_assoc.
eapply ratSubtract_ratAdd_inverse.
eapply evalDist_le_1.
unfold eq_dec.
rewrite <- H at 2.
rewrite ratDistance_add_same_r.
reflexivity.
Grab Existential Variables.
exact _.
exact _.
Qed.
rewrite StandardDef_equiv_2W_h.
rewrite ratDistance_comm.
intuition.
Qed.
End TwoWorldsEquiv_eta.
unfold negligible.
intuition.
destruct (H c).
exists x.
intuition.
eapply H0.
intuition.
rewrite H2.
rewrite Def_equiv_2W.
rewrite ratMult_comm.
eapply ratMult_small_le.
eapply rat_le_1.
simpl.
omega.
Qed.
unfold negligible.
intuition.
edestruct (H (1 + c)%nat).
exists (S x)%nat.
intuition.
eapply H0.
omega.
assert ((RatIntro (S O)
(@natToPosnat (expnat x0 (plus (S O) c))
(@expnat_nz (plus (S O) c) x0 pf_nz))) == (1 / x0) * (1 / (expnat x0 c))).
simpl.
rewrite <- ratMult_denom.
eapply eqRat_terms; intuition.
rewrite H3.
clear H3.
rewrite H2.
eapply leRat_trans.
2:{
eapply eqRat_impl_leRat.
symmetry.
eapply Def_equiv_2W.
}
eapply ratMult_leRat_compat; intuition.
unfold leRat.
eapply leRat_terms; intuition.
unfold natToPosnat, posnatToNat.
omega.
Qed.

Theorem TwoWorlds_equiv :
negligible (fun eta => (| Pr[f eta false] - Pr[f eta true] |)) <->
negligible (fun eta => | Pr[StandardDef_G eta] - 1 / 2 |).