Set a key to a value in an omap.
If the key is not already in the map, it is added, with the value. If the key is already in the map, the new value overrides the old value.
This is similar to insert for osets.
Function:
(defun update (key val map) (declare (xargs :guard (mapp map))) (let ((__function__ 'update)) (declare (ignorable __function__)) (cond ((emptyp map) (list (cons key val))) (t (mv-let (key0 val0) (head map) (cond ((equal key key0) (cons (cons key val) (tail map))) ((<< key key0) (cons (cons key val) map)) (t (cons (cons key0 val0) (update key val (tail map))))))))))
Theorem:
(defthm mapp-of-update (b* ((map1 (update key val map))) (mapp map1)) :rule-classes :rewrite)
Theorem:
(defthm update-of-head-and-tail (implies (not (emptyp map)) (equal (update (mv-nth 0 (head map)) (mv-nth 1 (head map)) (tail map)) map)) :rule-classes :elim)
Theorem:
(defthm update-not-emptyp (not (emptyp (update key val map))))
Theorem:
(defthm update-same (equal (update key val1 (update key val2 map)) (update key val1 map)))
Theorem:
(defthm update-different (implies (not (equal key1 key2)) (equal (update key1 val1 (update key2 val2 map)) (update key2 val2 (update key1 val1 map)))))
Theorem:
(defthm update-when-emptyp (implies (and (syntaxp (not (equal map ''nil))) (emptyp map)) (equal (update key val map) (update key val nil))))
Theorem:
(defthm head-key-of-update-of-nil (equal (mv-nth 0 (head (update key val nil))) key))
Theorem:
(defthm head-value-of-update-of-nil (equal (mv-nth 1 (head (update key val nil))) val))
Theorem:
(defthm tail-of-update-of-nil (equal (tail (update key val nil)) nil))
Theorem:
(defthm head-of-update (equal (head (update key val map)) (cond ((emptyp map) (mv key val)) ((<< (mv-nth 0 (head map)) key) (head map)) (t (mv key val)))))
Theorem:
(defthm head-key-of-update (equal (mv-nth 0 (head (update key val map))) (cond ((emptyp map) key) ((<< (mv-nth 0 (head map)) key) (mv-nth 0 (head map))) (t key))))
Theorem:
(defthm head-value-of-update (equal (mv-nth 1 (head (update key val map))) (cond ((emptyp map) val) ((<< (mv-nth 0 (head map)) key) (mv-nth 1 (head map))) (t val))))
Theorem:
(defthm tail-of-update (equal (tail (update key val map)) (cond ((emptyp map) nil) ((<< key (mv-nth 0 (head map))) map) ((equal key (mv-nth 0 (head map))) (tail map)) (t (update key val (tail map))))))
Theorem:
(defthm head-value-of-update-emptyp (implies (emptyp map) (equal (mv-nth 1 (head (update key val map))) val)))
Theorem:
(defthm head-value-of-update-key-<< (implies (and (not (emptyp map)) (or (<< key (mv-nth 0 (head map))) (equal key (mv-nth 0 (head map))))) (equal (mv-nth 1 (head (update key val map))) val)))
Theorem:
(defthm head-value-of-update-when-head-key-equal (implies (equal (mv-nth 0 (head (update key val x))) key) (equal (mv-nth 1 (head (update key val x))) val)))
Theorem:
(defthm head-value-of-update-not-<< (implies (and (not (emptyp map)) (<< (mv-nth 0 (head map)) key)) (equal (mv-nth 1 (head (update key val map))) (mv-nth 1 (head map)))))
Theorem:
(defthm tail-of-update-emptyp (implies (emptyp map) (equal (tail (update key val map)) nil)))
Theorem:
(defthm tail-of-update-<< (implies (and (not (emptyp map)) (<< key (mv-nth 0 (head map)))) (equal (tail (update key val map)) map)))
Theorem:
(defthm tail-of-update-equal (implies (and (not (emptyp map)) (equal key (mv-nth 0 (head map)))) (equal (tail (update key val map)) (tail map))))
Theorem:
(defthm tail-of-update-<<-rev (implies (and (not (emptyp map)) (<< (mv-nth 0 (head map)) key)) (equal (tail (update key val map)) (update key val (tail map)))))