Section EagerSampling.
Variable v_firstn : forall n1 n2, Bvector (n1 + n2)%nat -> Bvector n1.
Variable v_skipn : forall n1 n2, Bvector (n1 + n2)%nat -> Bvector n2.
Hypothesis v_firstn_correct : forall n1 n2 v1 v2,  (v_firstn n1 n2 (VectorDef.append v1 v2)) = v1.
Hypothesis v_skipn_correct : forall n1 n2 v1 v2,  (v_skipn n1 n2 (VectorDef.append v1 v2)) = v2.
Hypothesis firstn_skipn_correct : forall n1 n2 (v : Bvector (n1 + n2)), v = (VectorDef.append (v_firstn n1 n2 v) (v_skipn n1 n2 v)).
intuition.
eapply det_eq_impl_dist_sem_eq;
wftac.
unfold DetSem.evalDet_equiv.
intuition.
Admitted.
Admitted.
induction 1; intuition.
exists O.
exists (fun v => a).
intuition.
eapply leRat_trans.
eapply eqRat_impl_leRat.
rewrite <- ratIdentityIndiscernables.
eapply evalDist_Bind_1; intuition; wftac.
simpl.
destruct (EqDec_dec eqd a a0); destruct (pf a a0); subst; intuition.
eapply rat0_le_all.
assert (nz (length (getSupport c1))).
econstructor.
eapply getSupport_length_nz.
trivial.
destruct (IHwell_formed_comp (comp_EqDec c1) (d * (1 / (length (getSupport c1))) * (1/3))).
destruct H3.
intuition.
assert (forall (d : Rat) (b : B),
In b (getSupport c1) ->
exists (t : nat) (f : Bvector t -> A),
(forall a : A,
| evalDist (v <- { 0 , 1 }^t; ret f v) a - evalDist (c2 b) a | <= d) /\
(forall a : A,
In a (getSupport (v <- { 0 , 1 }^t; ret f v)) ->
In a (getSupport (c2 b)))).
intuition.
clear H1.
specialize (H3 (d * (1 / (length (getSupport c1))) * (1/3))).
(* assert (forall b : B, In b (getSupport c1) -> exists (t : nat), forall t', t' >= t -> exists (f : Bvector t' -> A), forall a : A, evalDist (v <- { 0 , 1 }^t'; ret f v) a == evalDist (c2 b) a). intuition.    Lemma maxWitness : forall (A : Set)(P_A : A -> Prop)(P : A -> nat -> Prop), (forall (a : A), P_A a -> exists (b : nat), forall b', b' >= b -> P a b') -> exists max, forall a, P_A a -> P a max. Admitted.  *)
assert (exists t, forall b, In b (getSupport c1) -> exists (f : Bvector t -> A),
(forall a, | evalDist (v <- {0, 1} ^ t; ret f v) a - evalDist (c2 b) a | <= (d * (1 / (length (getSupport c1))) * (1/3))) /\
(forall a : A,
In a (getSupport (v <- { 0 , 1 }^t; ret f v)) ->
In a (getSupport (c2 b)))).
(* find max over all b in support of c1 *)
admit.
clear H3.
destruct H1.
exists (x + x1)%nat.

Lemma witnessMap : forall (A B : Set)(P_a : A -> Prop)(P_b : A -> B -> Prop),
(forall (a : A), P_a a -> exists (b : B), P_b a b) ->
exists (f : A -> B),
forall a, P_a a -> P_b a (f a).