(alist-keys x) collects all keys bound in an alist.
This is a "modern" equivalent of strip-cars, which properly respects the non-alist convention; see std/alists for discussion of this convention.
Note that the list of keys returned by
A key is a among the
Theorem:
(defthm alist-keys-member-hons-assoc-equal (iff (member-equal x (alist-keys a)) (hons-assoc-equal x a)))
However, sometimes the
Theorem:
(defthm hons-assoc-equal-iff-member-alist-keys (iff (hons-assoc-equal x a) (member-equal x (alist-keys a))))
Obviously these two rules loop, so a theory-invariant insists that you choose one or the other. For greater compatibility between books, please do not non-locally switch the normal form.
Function:
(defun alist-keys (x) (declare (xargs :guard t)) (cond ((atom x) nil) ((atom (car x)) (alist-keys (cdr x))) (t (cons (caar x) (alist-keys (cdr x))))))
Theorem:
(defthm alist-keys-when-atom (implies (atom x) (equal (alist-keys x) nil)))
Theorem:
(defthm alist-keys-of-cons (equal (alist-keys (cons a x)) (if (atom a) (alist-keys x) (cons (car a) (alist-keys x)))))
Theorem:
(defthm list-equiv-implies-equal-alist-keys-1 (implies (list-equiv x x-equiv) (equal (alist-keys x) (alist-keys x-equiv))) :rule-classes (:congruence))
Theorem:
(defthm true-listp-of-alist-keys (true-listp (alist-keys x)) :rule-classes :type-prescription)
Theorem:
(defthm alist-keys-of-hons-acons (equal (alist-keys (hons-acons key val x)) (cons key (alist-keys x))))
Theorem:
(defthm alist-keys-of-pairlis$ (equal (alist-keys (pairlis$ keys vals)) (list-fix keys)))
Theorem:
(defthm alist-keys-member-hons-assoc-equal (iff (member-equal x (alist-keys a)) (hons-assoc-equal x a)))
Theorem:
(defthm hons-assoc-equal-iff-member-alist-keys (iff (hons-assoc-equal x a) (member-equal x (alist-keys a))))
Theorem:
(defthm hons-assoc-equal-when-not-member-alist-keys (implies (not (member-equal x (alist-keys a))) (equal (hons-assoc-equal x a) nil)))
Theorem:
(defthm alist-keys-of-append (equal (alist-keys (append x y)) (append (alist-keys x) (alist-keys y))))
Theorem:
(defthm alist-keys-of-rev (equal (alist-keys (rev x)) (rev (alist-keys x))))
Theorem:
(defthm alist-keys-of-revappend (equal (alist-keys (revappend x y)) (revappend (alist-keys x) (alist-keys y))))