Function:
(defun carry-out (width cin x y) (declare (xargs :guard (and (posp width) (bitp cin) (integerp x) (integerp y)))) (let ((__function__ 'carry-out)) (declare (ignorable __function__)) (b* ((width (lposfix width)) (sum (sum-with-cin cin (loghead width x) (loghead width y)))) (logtail (lposfix width) sum))))
Theorem:
(defthm carry-out-bit-is-carry-out (implies (and (posp width) (equal xbit (bool->bit (logbitp (+ -1 width) x))) (equal ybit (bool->bit (logbitp (+ -1 width) y)))) (equal (carry-out-bit xbit ybit (bool->bit (logbitp (+ -1 width) (sum-with-cin cin x y)))) (carry-out width cin x y))))
Theorem:
(defthm bitp-of-carry-out (bitp (carry-out width cin x y)) :rule-classes :type-prescription)
Theorem:
(defthm carry-out-correct (implies (posp width) (equal (logapp width (sum-with-cin cin x1 y1) (sum-with-cin (carry-out width cin x1 y1) x2 y2)) (sum-with-cin cin (logapp width x1 x2) (logapp width y1 y2)))))
Theorem:
(defthm carry-out-of-carry-out (equal (carry-out w2 (carry-out w1 cin x1 y1) x2 y2) (carry-out (+ (pos-fix w1) (pos-fix w2)) cin (logapp (pos-fix w1) x1 x2) (logapp (pos-fix w1) y1 y2))))
Theorem:
(defthm carry-out-of-sum (implies (posp width) (equal (logtail width (sum-with-cin cin x y)) (sum-with-cin (carry-out width cin x y) (logtail width x) (logtail width y)))))
Theorem:
(defthm carry-out-simplify-loghead-1 (implies (and (equal ww (pos-fix width)) (equal xx (loghead ww x)) (bind-free (case-match xx (('acl2::loghead$inline w xxx) (if (equal w ww) (if (equal xxx x) nil (cons (cons 'xxx xxx) 'nil)) (and (not (equal xx x)) (cons (cons 'xxx xx) 'nil)))) (& (and (not (equal xx x)) (cons (cons 'xxx xx) 'nil))))) (equal (loghead ww xxx) (loghead ww xx))) (equal (carry-out width cin x y) (carry-out width cin xxx y))))
Theorem:
(defthm carry-out-simplify-loghead-2 (implies (and (equal ww (pos-fix width)) (equal xx (loghead ww x)) (bind-free (case-match xx (('acl2::loghead$inline w xxx) (if (equal w ww) (if (equal xxx x) nil (cons (cons 'xxx xxx) 'nil)) (and (not (equal xx x)) (cons (cons 'xxx xx) 'nil)))) (& (and (not (equal xx x)) (cons (cons 'xxx xx) 'nil))))) (equal (loghead ww xxx) (loghead ww xx))) (equal (carry-out width cin y x) (carry-out width cin y xxx))))
Theorem:
(defthm carry-out-of-pos-fix-width (equal (carry-out (pos-fix width) cin x y) (carry-out width cin x y)))
Theorem:
(defthm carry-out-pos-equiv-congruence-on-width (implies (pos-equiv width width-equiv) (equal (carry-out width cin x y) (carry-out width-equiv cin x y))) :rule-classes :congruence)
Theorem:
(defthm carry-out-of-bfix-cin (equal (carry-out width (bfix cin) x y) (carry-out width cin x y)))
Theorem:
(defthm carry-out-bit-equiv-congruence-on-cin (implies (bit-equiv cin cin-equiv) (equal (carry-out width cin x y) (carry-out width cin-equiv x y))) :rule-classes :congruence)
Theorem:
(defthm carry-out-of-ifix-x (equal (carry-out width cin (ifix x) y) (carry-out width cin x y)))
Theorem:
(defthm carry-out-int-equiv-congruence-on-x (implies (int-equiv x x-equiv) (equal (carry-out width cin x y) (carry-out width cin x-equiv y))) :rule-classes :congruence)
Theorem:
(defthm carry-out-of-ifix-y (equal (carry-out width cin x (ifix y)) (carry-out width cin x y)))
Theorem:
(defthm carry-out-int-equiv-congruence-on-y (implies (int-equiv y y-equiv) (equal (carry-out width cin x y) (carry-out width cin x y-equiv))) :rule-classes :congruence)