(* Copyright 2012-2015 by Adam Petcher.				* * Use of this source code is governed by the license described	* * in the LICENSE file at the root of the source tree.		*)
Set Implicit Arguments.
Local Open Scope list_scope.
Notation "'query' v" := (OC_Query  _ v) (at level 79) : comp_scope.
Fixpoint oc_compMap(A B C D : Set)(eqdb : EqDec B)(c : A -> OracleComp C D B)(ls : list A) : OracleComp C D (list B) :=
match ls with
| nil => $ (ret nil)
| a :: ls' =>
b <--$ c a;
lsb' <--$ oc_compMap _ c ls';
$ (ret (b :: lsb'))
end.
induction ls1; inversion 1; subst; intuition; simpl in *.
comp_simp.
eapply comp_spec_ret; simpl; econstructor.
simpl.
comp_skip.
comp_simp.
comp_skip.
comp_simp.
eapply comp_spec_ret; intuition.
simpl.
econstructor; eauto.
Qed.
induction ls; intuition; simpl in *.
comp_simp.
eapply comp_spec_eq_refl.
comp_skip.
comp_skip.
comp_simp.
eapply comp_spec_eq_refl.
Qed.

Theorem compMap_randomFunc_NoDup :
forall (A B C: Set){eqda : EqDec A}{eqdb : EqDec B}{eqdc : EqDec C}(ls : list A)(f : A -> B -> Comp C)(rndB : Comp B)(lsf : list (A * B)),
NoDup ls ->
(forall a, In a ls -> arrayLookup _ lsf a = None) ->
comp_spec (fun a b => fst a = fst b)
((oc_compMap _ (fun x => y <--$ query x; $ f x y) ls) _ _ (@randomFunc A B rndB _) lsf)
((oc_compMap _ (fun x => y <--$ query x; $ f x y) ls) _ _ (fun s a => b <-$ rndB; ret (b, s)) tt).