Restrict an omap to a set of keys.
This drops all the keys of the omap that are not in the given set of keys.
Function:
(defun restrict (keys map) (declare (xargs :guard (and (setp keys) (mapp map)))) (let ((__function__ 'restrict)) (declare (ignorable __function__)) (cond ((emptyp map) nil) (t (mv-let (key val) (head map) (if (set::in key keys) (update key val (restrict keys (tail map))) (restrict keys (tail map))))))))
Theorem:
(defthm mapp-of-restrict (b* ((map1 (restrict keys map))) (mapp map1)) :rule-classes :rewrite)
Theorem:
(defthm restrict-when-left-emptyp (implies (set::emptyp keys) (equal (restrict keys map) nil)) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm restrict-when-right-emptyp (implies (emptyp map) (equal (restrict keys map) nil)) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm assoc-of-restrict (equal (assoc key (restrict keys map)) (and (set::in key keys) (assoc key map))))
Theorem:
(defthm assoc-of-restrict-when-in-keys (implies (set::in key keys) (equal (assoc key (restrict keys map)) (assoc key map))))