Logically simple alternative to reverse for lists.
This function is nicer to reason about than ACL2's built-in reverse function because it is more limited:
Despite its simple append-based logical definition,
Function:
(defun rev (x) (declare (xargs :guard t)) (mbe :logic (if (consp x) (append (rev (cdr x)) (list (car x))) nil) :exec (revappend-without-guard x nil)))
Theorem:
(defthm rev-when-not-consp (implies (not (consp x)) (equal (rev x) nil)))
Theorem:
(defthm rev-of-cons (equal (rev (cons a x)) (append (rev x) (list a))))
Theorem:
(defthm rev-of-append (equal (rev (append x y)) (append (rev y) (rev x))))
Theorem:
(defthm rev-of-list-fix (equal (rev (list-fix x)) (rev x)))
Theorem:
(defthm len-of-rev (equal (len (rev x)) (len x)))
Theorem:
(defthm rev-of-rev (equal (rev (rev x)) (list-fix x)))
Theorem:
(defthm consp-of-rev (equal (consp (rev x)) (consp x)))
Theorem:
(defthm rev-under-iff (iff (rev x) (consp x)))
Theorem:
(defthm revappend-removal (equal (revappend x y) (append (rev x) y)))
Theorem:
(defthm reverse-removal (implies (true-listp x) (equal (reverse x) (rev x))))
Theorem:
(defthm equal-of-rev-and-rev (equal (equal (rev x) (rev y)) (equal (list-fix x) (list-fix y))))
Theorem:
(defthm make-character-list-of-rev (equal (make-character-list (rev x)) (rev (make-character-list x))))
Theorem:
(defthm list-equiv-of-rev-and-rev (equal (list-equiv (rev x) (rev y)) (list-equiv x y)))
Theorem:
(defthm element-list-p-of-rev (equal (element-list-p (rev x)) (element-list-p (list-fix x))) :rule-classes :rewrite)
Theorem:
(defthm element-list-fix-of-rev (equal (element-list-fix (rev x)) (rev (element-list-fix x))) :rule-classes :rewrite)
Theorem:
(defthm elementlist-projection-of-rev (equal (elementlist-projection (rev x)) (rev (elementlist-projection x))) :rule-classes :rewrite)