4v-sexpr-restrict with inline rewriting.
This is different from sexpr-rewrite-of-restrict because it doesn't apply rewriting to the alist lookups; it basically assumes they've already been rewritten. So while we can't prove that this is equal to sexpr-rewrite of 4v-sexpr-restrict, we can prove that it's sexpr-equivalent to 4v-sexpr-restrict, and contains a subset of its variables.
Careful about memoization here; wouldn't want to use this when you're about to (or just have) done a 4v-sexpr-restrict of a similar sexpression with the same alist, or done a sexpr-rewrite of an sexpression similar to your result. Memoization won't carry over.
Function:
(defun 4v-sexpr-restrict-with-rw (x al) (declare (xargs :guard t)) (if (atom x) (and x (let ((look (hons-get x al))) (if look (cdr look) x))) (b* ((args (4v-sexpr-restrict-with-rw-list (cdr x) al))) (sexpr-rewrite-fncall 100 (car x) args *sexpr-rewrites*))))
Function:
(defun 4v-sexpr-restrict-with-rw-list (x al) (declare (xargs :guard t)) (if (atom x) x (hons (4v-sexpr-restrict-with-rw (car x) al) (4v-sexpr-restrict-with-rw-list (cdr x) al))))
Function:
(defun 4v-sexpr-restrict-with-rw-memoize-condition (x al) (declare (ignorable x al) (xargs :guard 't)) (consp x))
Theorem:
(defthm 4v-sexpr-restrict-with-rw-equiv-to-4v-sexpr-restrict (4v-sexpr-equiv (4v-sexpr-restrict-with-rw x al) (4v-sexpr-restrict x al)))
Theorem:
(defthm 4v-sexpr-restrict-with-rw-list-equiv-to-4v-sexpr-restrict-list (4v-sexpr-list-equiv (4v-sexpr-restrict-with-rw-list x al) (4v-sexpr-restrict-list x al)))
Theorem:
(defthm 4v-sexpr-vars-4v-sexpr-restrict-with-rw (implies (and (not (member-equal k (4v-sexpr-vars-list (alist-vals al)))) (not (and (member-equal k (4v-sexpr-vars x)) (not (member-equal k (alist-keys al)))))) (not (member-equal k (4v-sexpr-vars (4v-sexpr-restrict-with-rw x al))))))
Theorem:
(defthm 4v-sexpr-vars-list-4v-sexpr-restrict-with-rw-list (implies (and (not (member-equal k (4v-sexpr-vars-list (alist-vals al)))) (not (and (member-equal k (4v-sexpr-vars-list x)) (not (member-equal k (alist-keys al)))))) (not (member-equal k (4v-sexpr-vars-list (4v-sexpr-restrict-with-rw-list x al))))))
Function:
(defun 4v-sexpr-restrict-with-rw-alist-exec (x al acc) (declare (xargs :guard t)) (if (atom x) acc (if (atom (car x)) (4v-sexpr-restrict-with-rw-alist-exec (cdr x) al acc) (4v-sexpr-restrict-with-rw-alist-exec (cdr x) al (cons (cons (caar x) (4v-sexpr-restrict-with-rw (cdar x) al)) acc)))))
Function:
(defun 4v-sexpr-restrict-with-rw-alist (x al) (declare (xargs :guard t)) (mbe :logic (if (atom x) nil (if (atom (car x)) (4v-sexpr-restrict-with-rw-alist (cdr x) al) (cons (cons (caar x) (4v-sexpr-restrict-with-rw (cdar x) al)) (4v-sexpr-restrict-with-rw-alist (cdr x) al)))) :exec (reverse (4v-sexpr-restrict-with-rw-alist-exec x al nil))))
Theorem:
(defthm 4v-sexpr-restrict-with-rw-alist-exec-removal (equal (4v-sexpr-restrict-with-rw-alist-exec x al acc) (revappend (4v-sexpr-restrict-with-rw-alist x al) acc)))
Theorem:
(defthm hons-assoc-equal-4v-sexpr-restrict-with-rw-alist (equal (hons-assoc-equal k (4v-sexpr-restrict-with-rw-alist x al)) (and (hons-assoc-equal k x) (cons k (4v-sexpr-restrict-with-rw (cdr (hons-assoc-equal k x)) al)))))
Theorem:
(defthm 4v-sexpr-restrict-with-rw-alist-equiv-to-4v-sexpr-restrict-alist (4v-sexpr-alist-equiv (4v-sexpr-restrict-with-rw-alist x al) (4v-sexpr-restrict-alist x al)))
Theorem:
(defthm sexpr-eval-alist-of-4v-sexpr-restrict-with-rw-alist (equal (4v-sexpr-eval-alist (4v-sexpr-restrict-with-rw-alist x al) env) (4v-sexpr-eval-alist (4v-sexpr-restrict-alist x al) env)))
Theorem:
(defthm alist-keys-4v-sexpr-restrict-with-rw-alist (equal (alist-keys (4v-sexpr-restrict-with-rw-alist al env)) (alist-keys al)))
Theorem:
(defthm 4v-sexpr-restrict-with-rw-alist-append (equal (4v-sexpr-restrict-with-rw-alist (append al1 al2) env) (append (4v-sexpr-restrict-with-rw-alist al1 env) (4v-sexpr-restrict-with-rw-alist al2 env))))
Function:
(defun 4v-sexpr-restrict-with-rw-alists (x al) (declare (xargs :guard t)) (if (atom x) nil (cons (4v-sexpr-restrict-with-rw-alist (car x) al) (4v-sexpr-restrict-with-rw-alists (cdr x) al))))
Function:
(defun 4v-sexpr-restrict-with-rw-list-list (x al) (declare (xargs :guard t)) (if (atom x) nil (cons (4v-sexpr-restrict-with-rw-list (car x) al) (4v-sexpr-restrict-with-rw-list-list (cdr x) al))))