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 ((empty 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-empty (implies (set::empty keys) (equal (restrict keys map) nil)) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm restrict-when-right-empty (implies (empty map) (equal (restrict keys map) nil)) :rule-classes (:rewrite :type-prescription))