(* 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 _).

(* Being in the restriction is enough evidence to be in the set *)
Lemma restrict_in_set {A} : forall (m : M.t A) s k v,
M.find k (restrict m s) = Some v ->
S.In k s.