(hons-remove-duplicates l) removes duplicate elements from a list, and is implemented using fast-alists.
This operation is similar to the built-in ACL2 function remove-duplicates-equal, but it has different performance characteristics and the answer it produces is in an oddly different order.
ACL2's remove-duplicates function preserves the order of
non-duplicated elements but has a rather inefficient
In contrast,
Another reasonably efficient way to remove duplicate elements from a list include sorting the elements, e.g., via set::mergesort.
In the special case of removing duplicates from lists of natural numbers, nat-list-remove-duplicates may be offer superior performance.
Even though
Theorem:
(defthm hons-remove-duplicates-under-set-equiv (set-equiv (hons-remove-duplicates x) (remove-duplicates-equal x)))
Function:
(defun hons-remove-duplicates1 (l tab) (declare (xargs :guard t)) (cond ((atom l) (progn$ (fast-alist-free tab) nil)) ((hons-get (car l) tab) (hons-remove-duplicates1 (cdr l) tab)) (t (cons (car l) (hons-remove-duplicates1 (cdr l) (hons-acons (car l) t tab))))))
Function:
(defun hons-remove-duplicates (l) (declare (xargs :guard t)) (mbe :logic (rev (remove-duplicates-equal (rev l))) :exec (hons-remove-duplicates1 l (len l))))
Theorem:
(defthm hons-remove-duplicates-when-atom (implies (atom x) (equal (hons-remove-duplicates x) nil)))
Theorem:
(defthm hons-remove-duplicates-of-list-fix (equal (hons-remove-duplicates (list-fix x)) (hons-remove-duplicates x)))
Theorem:
(defthm list-equiv-implies-equal-hons-remove-duplicates-1 (implies (list-equiv x x-equiv) (equal (hons-remove-duplicates x) (hons-remove-duplicates x-equiv))) :rule-classes (:congruence))
Theorem:
(defthm set-equiv-implies-set-equiv-hons-remove-duplicates-1 (implies (set-equiv x x-equiv) (set-equiv (hons-remove-duplicates x) (hons-remove-duplicates x-equiv))) :rule-classes (:congruence))
Theorem:
(defthm hons-remove-duplicates-under-set-equiv (set-equiv (hons-remove-duplicates x) (remove-duplicates-equal x)))
Theorem:
(defthm no-duplicatesp-equal-of-hons-remove-duplicates (no-duplicatesp-equal (hons-remove-duplicates x)))
Theorem:
(defthm duplicity-in-of-hons-remove-duplicates (equal (duplicity a (hons-remove-duplicates x)) (if (member a x) 1 0)))
Theorem:
(defthm hons-remove-duplicates1-of-nil (equal (hons-remove-duplicates1 x nil) (hons-remove-duplicates x)))
Theorem:
(defthm acl2-count-of-hons-remove-duplicates (<= (acl2-count (hons-remove-duplicates x)) (acl2-count x)) :rule-classes ((:rewrite) (:linear)))