Function:
(defun svstack-merge-branches (cond then-st else-st) (declare (xargs :guard (and (svex-p cond) (svstack-p then-st) (svstack-p else-st)))) (let ((__function__ 'svstack-merge-branches)) (declare (ignorable __function__)) (b* (((when (or (atom then-st) (atom else-st))) nil) (then-alist (car then-st)) (else-alist (car else-st)) (first (b* (((with-fast then-alist else-alist)) (first nil) (first (svex-alist-merge-branches then-alist cond then-alist else-alist first)) (first (svex-alist-merge-branches else-alist cond then-alist else-alist first))) first))) (cons first (svstack-merge-branches cond (cdr then-st) (cdr else-st))))))
Theorem:
(defthm svstack-p-of-svstack-merge-branches (b* ((merged-st (svstack-merge-branches cond then-st else-st))) (svstack-p merged-st)) :rule-classes :rewrite)
Theorem:
(defthm svstack-merge-branches-lookup-under-iff (implies (double-rewrite (svstacks-compatible then-st else-st)) (iff (svex-lookup k (svstack-to-svex-alist (svstack-merge-branches cond then-st else-st))) (or (svex-lookup k (svstack-to-svex-alist then-st)) (svex-lookup k (svstack-to-svex-alist else-st))))))
Theorem:
(defthm svstack-merge-branches-when-cond-true-lookup (implies (and (equal (4vec-reduction-or (svex-eval cond env)) -1) (svstacks-compatible then-st else-st)) (equal (svex-eval (svex-lookup k (svstack-to-svex-alist (svstack-merge-branches cond then-st else-st))) env) (if (svex-lookup k (svstack-to-svex-alist then-st)) (svex-eval (svex-lookup k (svstack-to-svex-alist then-st)) env) (if (svex-lookup k (svstack-to-svex-alist else-st)) (svex-env-lookup k env) (4vec-x))))))
Theorem:
(defthm svstack-merge-branches-when-cond-false-lookup (implies (and (equal (4vec-reduction-or (svex-eval cond env)) 0) (svstacks-compatible then-st else-st)) (equal (svex-eval (svex-lookup k (svstack-to-svex-alist (svstack-merge-branches cond then-st else-st))) env) (if (svex-lookup k (svstack-to-svex-alist else-st)) (svex-eval (svex-lookup k (svstack-to-svex-alist else-st)) env) (if (svex-lookup k (svstack-to-svex-alist then-st)) (svex-env-lookup k env) (4vec-x))))))
Theorem:
(defthm keys-of-svstack-merge-branches (implies (and (not (member v (svex-alist-keys (svstack-to-svex-alist then-st)))) (not (member v (svex-alist-keys (svstack-to-svex-alist else-st))))) (not (member v (svex-alist-keys (svstack-to-svex-alist (svstack-merge-branches cond then-st else-st)))))))
Theorem:
(defthm svex-lookup-of-svstack-merge-branches (implies (and (not (member v (svex-alist-keys (svstack-to-svex-alist then-st)))) (not (member v (svex-alist-keys (svstack-to-svex-alist else-st)))) (svar-p v)) (not (svex-lookup v (svstack-to-svex-alist (svstack-merge-branches cond then-st else-st))))))
Theorem:
(defthm vars-of-svstack-merge-branches (implies (and (not (member v (svex-vars cond))) (not (member v (svex-alist-vars (svstack-to-svex-alist then-st)))) (not (member v (svex-alist-vars (svstack-to-svex-alist else-st)))) (not (member v (svex-alist-keys (svstack-to-svex-alist then-st)))) (not (member v (svex-alist-keys (svstack-to-svex-alist else-st)))) (double-rewrite (svstacks-compatible then-st else-st))) (not (member v (svex-alist-vars (svstack-to-svex-alist (svstack-merge-branches cond then-st else-st)))))))
Theorem:
(defthm svstack-merge-branches-compatible (b* ((?merged-st (svstack-merge-branches cond then-st else-st))) (implies (double-rewrite (svstacks-compatible then-st else-st)) (svstacks-compatible merged-st (double-rewrite then-st)))))
Theorem:
(defthm svstack-merge-branches-consp (b* ((?merged-st (svstack-merge-branches cond then-st else-st))) (implies (and (consp then-st) (consp else-st)) (consp merged-st))))
Theorem:
(defthm svstack-merge-branches-len (b* ((?merged-st (svstack-merge-branches cond then-st else-st))) (equal (len merged-st) (min (len then-st) (len else-st)))))
Theorem:
(defthm svstack-merge-branches-of-svex-fix-cond (equal (svstack-merge-branches (svex-fix cond) then-st else-st) (svstack-merge-branches cond then-st else-st)))
Theorem:
(defthm svstack-merge-branches-svex-equiv-congruence-on-cond (implies (svex-equiv cond cond-equiv) (equal (svstack-merge-branches cond then-st else-st) (svstack-merge-branches cond-equiv then-st else-st))) :rule-classes :congruence)
Theorem:
(defthm svstack-merge-branches-of-svstack-fix-then-st (equal (svstack-merge-branches cond (svstack-fix then-st) else-st) (svstack-merge-branches cond then-st else-st)))
Theorem:
(defthm svstack-merge-branches-svstack-equiv-congruence-on-then-st (implies (svstack-equiv then-st then-st-equiv) (equal (svstack-merge-branches cond then-st else-st) (svstack-merge-branches cond then-st-equiv else-st))) :rule-classes :congruence)
Theorem:
(defthm svstack-merge-branches-of-svstack-fix-else-st (equal (svstack-merge-branches cond then-st (svstack-fix else-st)) (svstack-merge-branches cond then-st else-st)))
Theorem:
(defthm svstack-merge-branches-svstack-equiv-congruence-on-else-st (implies (svstack-equiv else-st else-st-equiv) (equal (svstack-merge-branches cond then-st else-st) (svstack-merge-branches cond then-st else-st-equiv))) :rule-classes :congruence)