Function:
(defun svstate-merge-branches (cond then-st else-st) (declare (xargs :guard (and (svex-p cond) (svstate-p then-st) (svstate-p else-st)))) (let ((__function__ 'svstate-merge-branches)) (declare (ignorable __function__)) (b* (((svstate then-st) (svstate-fix then-st)) ((svstate else-st) (svstate-fix else-st)) ((when (hons-equal then-st else-st)) then-st) (blkst (svstack-merge-branches cond then-st.blkst else-st.blkst)) (nonblkst nil) (nonblkst (svex-alist-merge-branches then-st.nonblkst cond then-st.nonblkst else-st.nonblkst nonblkst)) (nonblkst (svex-alist-merge-branches else-st.nonblkst cond then-st.nonblkst else-st.nonblkst nonblkst))) (svstate-free then-st) (svstate-free else-st) (make-svstate :blkst blkst :nonblkst nonblkst))))
Theorem:
(defthm svstate-p-of-svstate-merge-branches (b* ((merged-st (svstate-merge-branches cond then-st else-st))) (svstate-p merged-st)) :rule-classes :rewrite)
Theorem:
(defthm svstate-merge-branches-lookup-blkst-when-false (implies (and (equal (4vec-reduction-or (svex-eval cond env)) 0) (svstacks-compatible (svstate->blkst then-st) (svstate->blkst else-st))) (equal (svex-eval (svex-lookup k (svstack-to-svex-alist (svstate->blkst (svstate-merge-branches cond then-st else-st)))) env) (if (svex-lookup k (svstack-to-svex-alist (svstate->blkst else-st))) (svex-eval (svex-lookup k (svstack-to-svex-alist (svstate->blkst else-st))) env) (if (svex-lookup k (svstack-to-svex-alist (svstate->blkst then-st))) (svex-env-lookup k env) (4vec-x))))))
Theorem:
(defthm svstate-merge-branches-lookup-nonblkst-when-false (implies (equal (4vec-reduction-or (svex-eval cond env)) 0) (equal (svex-eval (svex-lookup k (svstate->nonblkst (svstate-merge-branches cond then-st else-st))) env) (if (svex-lookup k (svstate->nonblkst else-st)) (svex-eval (svex-lookup k (svstate->nonblkst else-st)) env) (if (svex-lookup k (svstate->nonblkst then-st)) (svex-env-lookup k env) (4vec-x))))))
Theorem:
(defthm svstate-merge-branches-lookup-blkst-under-iff (implies (double-rewrite (svstacks-compatible (svstate->blkst then-st) (svstate->blkst else-st))) (iff (svex-lookup k (svstack-to-svex-alist (svstate->blkst (svstate-merge-branches cond then-st else-st)))) (or (svex-lookup k (svstack-to-svex-alist (svstate->blkst then-st))) (svex-lookup k (svstack-to-svex-alist (svstate->blkst else-st)))))))
Theorem:
(defthm svstate-merge-branches-lookup-nonblkst-under-iff (iff (svex-lookup k (svstate->nonblkst (svstate-merge-branches cond then-st else-st))) (or (svex-lookup k (svstate->nonblkst then-st)) (svex-lookup k (svstate->nonblkst else-st)))))
Theorem:
(defthm svstate-merge-branches-lookup-blkst-when-true (implies (and (svstacks-compatible (svstate->blkst then-st) (svstate->blkst else-st)) (equal (4vec-reduction-or (svex-eval cond env)) -1)) (equal (svex-eval (svex-lookup k (svstack-to-svex-alist (svstate->blkst (svstate-merge-branches cond then-st else-st)))) env) (if (svex-lookup k (svstack-to-svex-alist (svstate->blkst then-st))) (svex-eval (svex-lookup k (svstack-to-svex-alist (svstate->blkst then-st))) env) (if (svex-lookup k (svstack-to-svex-alist (svstate->blkst else-st))) (svex-env-lookup k env) (4vec-x))))))
Theorem:
(defthm svstate-merge-branches-lookup-nonblkst-when-true (implies (equal (4vec-reduction-or (svex-eval cond env)) -1) (equal (svex-eval (svex-lookup k (svstate->nonblkst (svstate-merge-branches cond then-st else-st))) env) (if (svex-lookup k (svstate->nonblkst then-st)) (svex-eval (svex-lookup k (svstate->nonblkst then-st)) env) (if (svex-lookup k (svstate->nonblkst else-st)) (svex-env-lookup k env) (4vec-x))))))
Theorem:
(defthm svstate-merge-branches-blkst-when-true (implies (and (equal (4vec-reduction-or (svex-eval cond env)) -1) (svstacks-compatible (svstate->blkst then-st) (svstate->blkst else-st))) (svex-envs-similar (append (svex-alist-eval (svstack-to-svex-alist (svstate->blkst (svstate-merge-branches cond then-st else-st))) env) env) (append (svex-alist-eval (svstack-to-svex-alist (svstate->blkst then-st)) env) env))))
Theorem:
(defthm svstate-merge-branches-nonblkst-when-true (implies (equal (4vec-reduction-or (svex-eval cond env)) -1) (svex-envs-similar (append (svex-alist-eval (svstate->nonblkst (svstate-merge-branches cond then-st else-st)) env) env) (append (svex-alist-eval (svstate->nonblkst then-st) env) env))))
Theorem:
(defthm svstate-merge-branches-blkst-when-false (implies (and (equal (4vec-reduction-or (svex-eval cond env)) 0) (svstacks-compatible (svstate->blkst then-st) (svstate->blkst else-st))) (svex-envs-similar (append (svex-alist-eval (svstack-to-svex-alist (svstate->blkst (svstate-merge-branches cond then-st else-st))) env) env) (append (svex-alist-eval (svstack-to-svex-alist (svstate->blkst else-st)) env) env))))
Theorem:
(defthm svstate-merge-branches-nonblkst-when-false (implies (equal (4vec-reduction-or (svex-eval cond env)) 0) (svex-envs-similar (append (svex-alist-eval (svstate->nonblkst (svstate-merge-branches cond then-st else-st)) env) env) (append (svex-alist-eval (svstate->nonblkst else-st) env) env))))
Theorem:
(defthm vars-of-svstate-merge-branches (b* ((?merged-st (svstate-merge-branches cond then-st else-st))) (implies (and (double-rewrite (svstates-compatible then-st else-st)) (not (member v (svex-vars cond))) (not (member v (svstate-vars then-st))) (not (member v (svstate-vars else-st)))) (not (member v (svstate-vars merged-st))))))
Theorem:
(defthm svstate-merge-branches-blkst-compatible (b* ((?merged-st (svstate-merge-branches cond then-st else-st))) (implies (double-rewrite (svstates-compatible then-st else-st)) (svstates-compatible merged-st (double-rewrite then-st)))))
Theorem:
(defthm svstate-merge-branches-preserves-blkst-consp (b* ((?merged-st (svstate-merge-branches cond then-st else-st))) (implies (and (consp (svstate->blkst then-st)) (consp (svstate->blkst else-st))) (consp (svstate->blkst merged-st)))))
Theorem:
(defthm svstate-merge-branches-blkst-len (b* ((?merged-st (svstate-merge-branches cond then-st else-st))) (equal (len (svstate->blkst merged-st)) (min (len (svstate->blkst then-st)) (len (svstate->blkst else-st))))))
Theorem:
(defthm svstate-merge-branches-of-svex-fix-cond (equal (svstate-merge-branches (svex-fix cond) then-st else-st) (svstate-merge-branches cond then-st else-st)))
Theorem:
(defthm svstate-merge-branches-svex-equiv-congruence-on-cond (implies (svex-equiv cond cond-equiv) (equal (svstate-merge-branches cond then-st else-st) (svstate-merge-branches cond-equiv then-st else-st))) :rule-classes :congruence)
Theorem:
(defthm svstate-merge-branches-of-svstate-fix-then-st (equal (svstate-merge-branches cond (svstate-fix then-st) else-st) (svstate-merge-branches cond then-st else-st)))
Theorem:
(defthm svstate-merge-branches-svstate-equiv-congruence-on-then-st (implies (svstate-equiv then-st then-st-equiv) (equal (svstate-merge-branches cond then-st else-st) (svstate-merge-branches cond then-st-equiv else-st))) :rule-classes :congruence)
Theorem:
(defthm svstate-merge-branches-of-svstate-fix-else-st (equal (svstate-merge-branches cond then-st (svstate-fix else-st)) (svstate-merge-branches cond then-st else-st)))
Theorem:
(defthm svstate-merge-branches-svstate-equiv-congruence-on-else-st (implies (svstate-equiv else-st else-st-equiv) (equal (svstate-merge-branches cond then-st else-st) (svstate-merge-branches cond then-st else-st-equiv))) :rule-classes :congruence)