Section CompLoop.
Variable A : Set.
Hypothesis eqd : EqDec A.
Variable c : A -> Comp A.
Hypothesis c_wf : forall a, well_formed_comp (c a).
Definition compLoop n (a : A) : Comp A :=
compFold _ (fun a n => c a) a (allNatsLt n).
intuition.
eapply compFold_wf; intuition.
Qed.
End CompLoop.
intuition.
Qed.
induction n; intuition.
unfold compLoop, allNatsLt.
rewrite app_nil_l.
unfold compFold.
intuition.
unfold compLoop, allNatsLt.
fold allNatsLt.
eapply eqRat_trans.
rewrite compFold_app.
eapply evalDist_seq_eq.
intros.
eapply IHn.
intros.
eapply eqRat_refl.
dist_inline_first.
comp_skip.
unfold compLoop.
eapply eqRat_trans.
symmetry.
eapply compFold_app.
eapply comp_spec_eq_impl_eq.
eapply (@compFold_eq _ _ (fun x y => True)).
eapply list_pred_I.
repeat rewrite app_length.
simpl; intuition.
intuition.
Qed.
induction n; intuition.
unfold compLoop.
simpl.
eapply comp_spec_ret; intuition.
unfold compLoop in *.
simpl.
(* eapply comp_spec_eq_trans. eapply eq_impl_comp_spec_eq. intros. eapply compFold_app. eapply comp_spec_eq_trans_r. Focus 2. eapply comp_spec_eq_symm. eapply eq_impl_comp_spec_eq. intros. eapply compFold_app. eapply comp_spec_seq; intuition. simpl. eapply comp_spec_seq; intuition. eapply comp_spec_ret; intuition. *)
Admitted.

Theorem compLoop_eq :
forall (A : Set){e1 e2 : EqDec A}(c1 c2 : A -> Comp A) n a x,
(forall x y, evalDist (c1 x) y == evalDist (c2 x) y) ->
evalDist (compLoop e1 c1 n a) x == evalDist (compLoop e2 c2 n a) x.