Organize a list of symbols by their names.
(organize-symbols-by-name syms) → syms-by-name
The result is an alist from symbol names (strings) to the non-empty lists of the symbols that have the respective names.
The alist has unique keys, and each of its values has no duplicates.
Function:
(defun organize-symbols-by-name-aux (syms acc) (declare (xargs :guard (and (symbol-listp syms) (string-symbollist-alistp acc)))) (let ((__function__ 'organize-symbols-by-name-aux)) (declare (ignorable __function__)) (b* (((when (endp syms)) acc) (sym (car syms)) (name (symbol-name sym)) (prev-syms-for-name (cdr (assoc-equal name acc)))) (organize-symbols-by-name-aux (cdr syms) (put-assoc-equal name (add-to-set-eq sym prev-syms-for-name) acc)))))
Theorem:
(defthm string-symbollist-alistp-of-organize-symbols-by-name-aux (implies (and (symbol-listp syms) (string-symbollist-alistp acc)) (b* ((syms-by-name (organize-symbols-by-name-aux syms acc))) (string-symbollist-alistp syms-by-name))) :rule-classes :rewrite)
Function:
(defun organize-symbols-by-name (syms) (declare (xargs :guard (symbol-listp syms))) (let ((__function__ 'organize-symbols-by-name)) (declare (ignorable __function__)) (organize-symbols-by-name-aux syms nil)))
Theorem:
(defthm string-symbollist-alistp-of-organize-symbols-by-name (implies (and (symbol-listp syms)) (b* ((syms-by-name (organize-symbols-by-name syms))) (string-symbollist-alistp syms-by-name))) :rule-classes :rewrite)