(* Restrict a map by a set of keys *)
(* Fold over the set we are restricting with for better induction. *)
Definition restrict {A} (m : M.t A) s :=
S.fold (fun k m' => match M.find k m with
| Some v => M.add k v m'
| None => m'
end) s (@M.empty _).

(* extensive use of hammer *)
Lemma restrict_full {A} :
forall s (f : M.t A) (v i : M.key),
S.In i s ->
M.In i f ->
S.Subset (Mdomain (restrict f s)) (Mdomain f) ->
S.In i (Mdomain (restrict f s)).