(** Assuming safety of cooperative VST.concurrency*)
Section Safety.
Variables (f : val) (arg : list val).
Variable init_coarse_safe:
forall sched tpc mem' n,
tpc_init sched init_mem (sched, [::], tpc) mem' f arg ->
HybridCoarseMachine.csafe (sched,[::],tpc) mem' n.
(** [init_mach] and [init_mem] are related by [mem_compatible]*)
(* Lemma init_compatible: *)
(*   forall pmap tp m m', *)
(*     @init_mach DryHybridMachine.dryResources _ _ _ pmap m tp m' f arg -> *)
(*     mem_compatible tp m'. *)
(* Proof. *)
(*   intros. *)
(*   destruct init_perm as [pmap|] eqn:Hinit_perm; *)
(*     [| eapply init_mach_none in H0; now exfalso]. *)
(*   unfold init_perm in Hinit_perm. *)
(*   rewrite H in Hinit_perm. *)
(*   inversion Hinit_perm; subst. *)
(*   constructor. *)
(*   - intros j cntj. *)
(*     pose proof (init_thread H0 cntj); subst. *)
(*     erewrite getThreadR_init by eauto. *)
(*     simpl. *)
(*     split; [intros ? ?; now apply getCur_Max |now apply empty_LT]. *)
(*   - intros. *)
(*     erewrite init_lockRes_empty in H1 by eauto. *)
(*     discriminate. *)
(*   - intros. *)
(*     erewrite init_lockRes_empty in H1 by eauto. *)
(*     discriminate. *)
(* Qed. *)

(* Specifications: *)
(** Simulation relation with id renaming for initial memory*)
Lemma init_mem_obs_eq :
forall pmap m' tp i (cnti : containsThread tp i)
(Hcomp: mem_compatible tp m')
(HcompF: mem_compatible tp (@diluteMem FineDilMem m'))
(ARGS:valid_val_list (id_ren init_mem) arg),
@init_mach DryHybridMachine.dryResources _ _ _ pmap init_mem tp m' f arg ->
mem_obs_eq (id_ren m') (restrPermMap (compat_th _ _ Hcomp cnti).1)
(restrPermMap (HcompF _ cnti).1) /\
mem_obs_eq (id_ren m') (restrPermMap (Hcomp _ cnti).2)
(restrPermMap (HcompF _ cnti).2).
(** The [strong_tsim] relation is reflexive under the identity renaming*)
Lemma strong_tsim_refl:
forall pmap tp m' i (cnti: containsThread tp i)
(Hcomp: mem_compatible tp m')
(HcompF: mem_compatible tp (@diluteMem FineDilMem m'))
(ARGS:valid_val_list (id_ren init_mem) arg),
@init_mach DryHybridMachine.dryResources _ _ _ pmap init_mem tp m' f arg ->
SimDefs.strong_tsim (id_ren m') cnti cnti Hcomp HcompF.
Lemma setMaxPerm_inv:
forall m, SimDefs.max_inv (@diluteMem FineDilMem m).
(** Establishing the simulation relation for the initial state*)
Lemma init_sim:
forall sched tpc tpf m' n (ARG:valid_val_list (id_ren init_mem) arg),
tpc_init sched init_mem (sched, [::], tpc) m' f arg ->
tpf_init sched init_mem (sched, [::], tpf) m' f arg ->
SimDefs.sim tpc [::] m' tpf [::] (@diluteMem FineDilMem m') nil (id_ren m')
(id_ren init_mem) (fun i cnti => id_ren m') n.