Program Definition nonlockat (l: AV.address): pred rmap :=
fun m => nonlock (m @ l).
Next Obligation.
intros; intro; intros.
unfold resource_share in *.
destruct (a @ l) eqn:?H.
+ rewrite (necR_NO a a' l _ n) in H1 by (constructor; auto).
rewrite H1; assumption.
+ eapply necR_YES in H1; [ | constructor; eassumption].
rewrite H1; assumption.
+ eapply necR_PURE in H1; [ | constructor; eassumption].
rewrite H1; assumption.
Qed.
Program Definition shareat (l: AV.address) (sh: share): pred rmap :=
fun m => resource_share (m @ l) = Some sh.
Next Obligation.
intros; intro; intros.
unfold resource_share in *.
destruct (a @ l) eqn:?H.
+ rewrite (necR_NO a a' l _ n) in H1 by (constructor; auto).
rewrite H1; assumption.
+ eapply necR_YES in H1; [ | constructor; eassumption].
rewrite H1; assumption.
+ inv H0.
Qed.
Program Definition jam {A} {JA: Join A}{PA: Perm_alg A}{agA: ageable A}{AgeA: Age_alg A} {B: Type} {S': B -> Prop} (S: forall l, {S' l}+{~ S' l}) (P Q: B -> pred A) : B -> pred A :=
fun (l: B) m => if S l then P l m else Q l m.
Next Obligation.
intros; intro; intros.
if_tac; try (eapply pred_hereditary; eauto).
Qed.

(* Specifications: *)
(*Lemma allp_noat_emp: allp noat = emp.  Lemma jam_true: forall A JA PA agA AgeA B (S': B -> Prop) S P Q loc, S' loc -> @jam A JA PA agA AgeA B S' S P Q loc = P loc.  Lemma jam_false: forall A JA PA agA AgeA B (S': B -> Prop) S P Q loc, ~ S' loc -> @jam A JA PA agA AgeA B S' S P Q loc = Q loc.  Lemma boxy_jam:  forall (m: modality) A (S': A -> Prop) S P Q, (forall (x: A), boxy m (P x)) -> (forall x, boxy m (Q x)) -> forall x, boxy m (@jam rmap _ _ _ _ A S' S P Q x).  Definition extensible_jam: forall A (S': A -> Prop) S (P Q: A -> pred rmap), (forall (x: A), boxy extendM (P x)) -> (forall x, boxy extendM (Q x)) -> forall x, boxy extendM  (@jam _ _ _ _ _ _ S' S P Q x).  Definition jam_vacuous: forall A JA PA agA AgeA B S S' P Q, (forall x:B, ~ S x) -> @jam A JA PA agA AgeA B S S' P Q = Q. (* Implicit Arguments jam_vacuous. *)
Lemma make_sub_rmap: forall w (P: address -> Prop) (P_DEC: forall l, {P l} + {~ P l}),
(forall l sh k, P l -> res_option (w @ l) = Some (sh, k) -> isVAL k \/ isFUN k) ->
{w' | level w' = level w /\ resource_at w' =
(fun l => if P_DEC l then w @ l else core (w @ l)) /\ ghost_of w' = ghost_of w}.