Definition upd {A} (m : nat -> A) x e :=
fun y => if eq_nat_dec x y then e else m y.
Definition updatemap (m : map) (x e : nat) : option map :=
match m x with Some _ => Some (upd m x (Some (inl e))) | None => None end.
Definition assertmap (m : map) (x : nat) : Prop :=
match m x with Some (inl (S _)) => True | _ => False end.
(*+ Join relation on resources and resource maps *)
Definition joincell (a b : option val) : option (option val) :=
match a, b with
| None, None => Some None
| Some a, None | None, Some a => Some (Some a)
| Some _, Some _ => None
end.
Definition join (m n o : map) : Prop := forall x, joincell (m x) (n x) = Some (o x).
Definition joins (m n : map) : Prop := exists o, join m n o.
Add Parametric Morphism : join with signature eqmap ==> eqmap ==> eqmap ==> iff as join_morphism.

Lemma join_eqmap_l {m m' n o}  : join m n o -> join m' n o -> eqmap m m'.
Definition joincell_split {a b ab c abc} :
joincell a b = Some ab -> joincell ab c = Some abc ->
{ bc | joincell b c = Some bc /\ joincell a bc = Some abc }.