(* Lemma mem_compatible_locks_lt: forall {tp m}, mem_compatible tp m -> forall i cnti, permMapLt (perm_of_res_lock (@getThreadR i tp cnti)) (getMaxPerm m ).  Lemma compat_lt_m: forall m js, mem_compatible js m -> forall b ofs, Mem.perm_order'' ((getMaxPerm m) !! b ofs) ((lockSet js) !! b ofs).  (** There is no inteference in the thread pool *)
(* Per-thread disjointness definition*)
Definition disjoint_threads tp :=
forall i j (cnti : containsThread tp i)
(cntj: containsThread tp j) (Hneq: i <> j),
joins (getThreadR(resources:=LockInvsAndResources) cnti)
(getThreadR cntj).
(* Per-lock disjointness definition*)
Definition disjoint_locks tp :=
forall loc1 loc2 R1 R2 r1 r2,
lockRes tp loc1 = Some (R1, Some r1) ->
lockRes tp loc2 = Some (R2, Some r2) ->
joins r1 r2.
(* lock-thread disjointness definition*)
Definition disjoint_lock_thread tp :=
forall i loc R r (cnti : containsThread tp i),
lockRes tp loc = Some (R, Some r) ->
joins (getThreadR cnti) r.
Variant invariant' (tp:t) := True. (* The invariant has been absorbed my mem_compat*)
Definition invariant := invariant'.
(*Lemmas to retrive the ex-invariant properties from the mem-compat*)
(** Steps*)
(* What follows is the lemmas needed to construct a "personal" memory That is a memory with the juice and Cur of a particular thread. *)
Definition mapmap {A B} (def:B) (f:positive -> A -> B) (m:PMap.t A): PMap.t B:=
(def, PTree.map f m#2).
(* You need the memory, to make a finite tree. *)
Definition juice2Perm (phi:rmap)(m:mem): access_map:=
mapmap (fun _ => None) (fun block _ => fun ofs => perm_of_res (phi @ (block, ofs)) ) (getMaxPerm m).
Definition juice2Perm_locks (phi:rmap)(m:mem): access_map:=
mapmap (fun _ => None) (fun block _ => fun ofs => perm_of_res_lock (phi @ (block, ofs)) ) (getMaxPerm m).

(* Specifications: *)
Lemma juice2Perm_canon: forall phi m, isCanonical (juice2Perm phi m).
Lemma juice2Perm_locks_nogrow: forall phi m b ofs,
Mem.perm_order'' (perm_of_res_lock (phi @ (b, ofs)))
((juice2Perm_locks phi m) !! b ofs).
Lemma juice2Perm_cohere: forall phi m,
access_cohere' m phi ->
permMapLt (juice2Perm phi m) (getMaxPerm m).
Lemma juice2Perm_locks_cohere: forall phi m,
max_access_cohere m phi ->
permMapLt (juice2Perm_locks phi m) (getMaxPerm m).
Lemma Mem_canonical_useful: forall m loc k,
(Mem.mem_access m)#1 loc k = None.
Lemma juic2Perm_locks_correct:
forall r m b ofs,
max_access_cohere m r ->
perm_of_res_lock (r @ (b,ofs)) = (juice2Perm_locks r m) !! b ofs.
Lemma juic2Perm_correct:
forall r m b ofs,
access_cohere' m r ->
perm_of_res (r @ (b,ofs)) = (juice2Perm r m) !! b ofs.