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.

Theorem compLoop_spec :
forall (A B : Set){e1 : EqDec A}{e2 : EqDec B}(P : A -> B -> Prop)(c1 : A -> Comp A)(c2 : B -> Comp B) n a b,
(forall x y, P x y -> comp_spec P (c1 x) (c2 y)) ->
P a b ->
comp_spec P (compLoop e1 c1 n a) (compLoop e2 c2 n b).