Find the pair in the omap with a given key.
If the key is present, return the cons pair with the key.
Otherwise, return
This is similar to common-lisp::assoc for alists.
Function:
(defun assoc (key map) (declare (xargs :guard (mapp map))) (let ((__function__ 'assoc)) (declare (ignorable __function__)) (cond ((emptyp map) nil) (t (mv-let (key0 val0) (head map) (cond ((equal key key0) (cons key0 val0)) (t (assoc key (tail map)))))))))
Theorem:
(defthm listp-of-assoc (b* ((pair? (assoc key map))) (listp pair?)) :rule-classes :rewrite)
Theorem:
(defthm assoc-of-mfix (equal (assoc key (mfix map)) (assoc key map)))
Theorem:
(defthm assoc-when-emptyp (implies (emptyp map) (equal (assoc key map) nil)) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm assoc-of-head (iff (assoc (mv-nth 0 (head map)) map) (not (emptyp map))))
Theorem:
(defthm assoc-when-assoc-tail (implies (assoc key (tail map)) (assoc key map)))
Theorem:
(defthm acl2-count-assoc-<-map (implies (not (emptyp map)) (< (acl2-count (assoc key map)) (acl2-count map))))
Theorem:
(defthm assoc-of-update (equal (assoc key1 (update key val map)) (if (equal key1 key) (cons key val) (assoc key1 map))))
Theorem:
(defthm assoc-of-update* (equal (assoc key (update* map1 map2)) (or (assoc key map1) (assoc key map2))))
Theorem:
(defthm consp-of-assoc-of-update* (equal (consp (assoc key (update* map1 map2))) (or (consp (assoc key map1)) (consp (assoc key map2)))))
Theorem:
(defthm update-of-cdr-of-assoc-when-assoc (implies (assoc k m) (equal (update k (cdr (assoc k m)) m) m)))
Theorem:
(defthm consp-of-assoc-iff-assoc (iff (consp (assoc key map)) (assoc key map)))
Theorem:
(defthm head-key-minimal (implies (<< key (mv-nth 0 (head map))) (not (assoc key map))))
Theorem:
(defthm head-key-not-assoc-tail (not (assoc (mv-nth 0 (head map)) (tail map))))
Theorem:
(defthm assoc-of-tail-when-assoc-of-tail (implies (assoc key (tail map)) (equal (assoc key (tail map)) (assoc key map))))
Theorem:
(defthm assoc-of-tail-when-not-head (implies (not (equal key (mv-nth 0 (head map)))) (equal (assoc key (tail map)) (assoc key map))))