Definition fixup_trace (trace: AV.address -> option (pshare * AV.kind))
(f: AV.address -> resource) : AV.address -> resource :=
fun x => match trace x, f x with
| None, PURE k pp => PURE k pp
| Some(sh,k), PURE _ pp => YES sh k pp
| Some (sh,k), YES _ _ pp => YES sh k pp
| Some (sh, k), NO => YES sh k NoneP
| None, _ => NO
end.

(* Specifications: *)
Lemma fixup_trace_valid: forall tr f, AV.valid tr -> AV.valid (res_option oo (fixup_trace tr f)).
Lemma fixup_trace_rmap:
forall (tr: sig AV.valid) (f: rmap),
{phi: rmap | level phi = level f /\ resource_at phi = fixup_trace (proj1_sig tr) (resource_at f)}.