Ltac prog_assoc_r :=
    eapply comp_spec_eq_trans_r; [ idtac | eapply comp_spec_assoc].(* A bounded repeat based on fold. *)
Definition repeatMax(A : Set)(eqd : EqDec A)(c : Comp A)(P : A -> bool) def (n : nat):=
  compFold _ (fun a' i => if (P a') then (ret a') else c) def (allNatsLt n).

Theorem compFold_repeat_spec : forall (C D: Set)(ls1 : list C)(ls2 : list D)(pre : C -> D -> Prop), list_pred pre ls1 ls2 -> forall (A B : Set)(eqda : EqDec A)(eqdb : EqDec B)(post : A -> B -> Prop)(c1 : C -> Comp A)(P1 : A -> bool)(c2 : D -> Comp B)(P2 : B -> bool) a b, post a b -> (forall a b, pre a b -> comp_spec post (c1 a) (c2 b)) -> (forall a b, post a b -> (P1 a = true <-> P2 b = true)) -> comp_spec post (compFold _ (fun acc v => if (P1 acc) then (ret acc) else (c1 v)) a ls1) (compFold _ (fun acc v => if (P2 acc) then (ret acc) else (c2 v)) b ls2).