• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
      • 100-theorems
      • Arithmetic
      • Bit-vectors
        • Sparseint
          • Sparseint-impl
            • Sparseint$-binary-bitop-width
            • Sparseint$-plus-width
            • Sparseint$-binary-bitop-offset
            • Sparseint$-binary-bitop-int-width
            • Sparseint$-plus-int-width
            • Sum-with-cin
            • Sparseint$-plus-offset
            • Sparseint$-binary-bitop-int
            • Sparseint$-finalize-concat
            • Sparseint$-plus-int
            • Sparseint$-binary-bittest-width
            • Sparseint$-binary-bittest-int-width
            • Sparseint$-trailing-0-count-width
            • Sparseint$-height
            • Int-to-sparseint$-rec
            • Carry-out
              • Sparseint$-compare-width
              • Sparseint$-binary-bittest-offset
              • Sparseint$-equal-width
              • Sparseint$-binary-bittest-int
              • Sparseint$-compare-int-width
              • Sparseint$-bitcount-width
              • Sparseint$-unary-bittest-width
              • Sparseint$-rightshift-rec
              • Sparseint$-equal-int-width
              • Sparseint$-trailing-0-count-rec
              • Sparseint$-unary-bitop
              • Sparseint$-concatenate
              • Sparseint$-length-width-rec
              • Sparseint$-sign-ext
              • Sparseint$-binary-bitop
              • Binary-bitop
              • Sparseint$-compare-offset
              • Sparseint$-unary-bittest-offset
              • Sparseint$-equal-offset
              • Sparseint$-truncate
              • Sparseint$-mergeable-leaves-p
              • Carry-out-bit
              • Sparseint$-truncate-height
              • Sparseint$-compare-int
              • Sparseint$-binary-bittest
              • Sparseint$-equal-int
              • Sparseint$-rightshift
              • Sparseint$-leaves-mergeable-p
              • Sparseint$-plus
              • Unary-bitop
              • Sparseint$-bitcount-rec
              • Within-1
              • Sparseint$
              • Binary-bitop-cofactor2
              • Binary-bitop-cofactor1
              • Sparseint$-compare
              • Sparseint$-unary-bittest
              • Sparseint$-height-correct-exec
              • Sparseint$-equal
              • Sparseint$-bitnot
              • Sparseint$-unary-minus
              • Sparseint$-bit
              • Int-to-sparseint$
              • Binary-bittest
              • Sparseint$-length-rec
              • Sparseint$-val
              • Binary-bitop-swap
              • Compare
              • Sparseint$-real-height
              • Sparseint$-height-correctp
              • Sparseint$-length
            • Sparseint-p
            • Sparseint-binary-bittest
            • Sparseint-concatenate
            • Sparseint-binary-bitop
            • Sparseint-bitite
            • Sparseint-fix
            • Sparseint$-binary-minus
            • Sparseint-trailing-1-count-from
            • Sparseint-trailing-0-count-from
            • Sparseint-equal
            • Sparseint-test-bitorc2
            • Sparseint-test-bitorc1
            • Sparseint-test-bitnand
            • Sparseint-test-bitandc2
            • Sparseint-test-bitandc1
            • Sparseint-test-bitand
            • Sparseint-rightshift
            • Sparseint-bitcount-from
            • Sparseint-test-bitxor
            • Sparseint-test-bitor
            • Sparseint-test-bitnor
            • Sparseint-test-biteqv
            • Sparseint-compare
            • Sparseint-binary-minus
            • Sparseint-sign-ext
            • Sparseint-plus
            • Sparseint-bitandc2
            • Sparseint-bitandc1
            • Sparseint-bitand
            • Sparseint$-leaf-bitlimit
            • Sparseint-bitxor
            • Sparseint-bitorc2
            • Sparseint-bitorc1
            • Sparseint-bitor
            • Sparseint-bitnor
            • Sparseint-bitnand
            • Sparseint-biteqv
            • Sparseint-ash
            • Sparseint-<
            • Sparseint-bit
            • Sparseint-trailing-1-count
            • Sparseint-trailing-0-count
            • Sparseint-unary-minus
            • Sparseint-length
            • Sparseint-bitnot
            • Sparseint-bitcount
            • Int-to-sparseint
            • Sparseint-val
          • Bitops
          • Bv
          • Ihs
          • Rtl
        • Algebra
      • Testing-utilities
    • Sparseint-impl

    Carry-out

    Signature
    (carry-out width cin x y) → *
    Arguments
    width — Guard (posp width).
    cin — Guard (bitp cin).
    x — Guard (integerp x).
    y — Guard (integerp y).

    Definitions and Theorems

    Function: carry-out

    (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: carry-out-bit-is-carry-out

    (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: bitp-of-carry-out

    (defthm bitp-of-carry-out
      (bitp (carry-out width cin x y))
      :rule-classes :type-prescription)

    Theorem: carry-out-correct

    (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: carry-out-of-carry-out

    (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: carry-out-of-sum

    (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: carry-out-simplify-loghead-1

    (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: carry-out-simplify-loghead-2

    (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: carry-out-of-pos-fix-width

    (defthm carry-out-of-pos-fix-width
      (equal (carry-out (pos-fix width) cin x y)
             (carry-out width cin x y)))

    Theorem: carry-out-pos-equiv-congruence-on-width

    (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: carry-out-of-bfix-cin

    (defthm carry-out-of-bfix-cin
      (equal (carry-out width (bfix cin) x y)
             (carry-out width cin x y)))

    Theorem: carry-out-bit-equiv-congruence-on-cin

    (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: carry-out-of-ifix-x

    (defthm carry-out-of-ifix-x
      (equal (carry-out width cin (ifix x) y)
             (carry-out width cin x y)))

    Theorem: carry-out-int-equiv-congruence-on-x

    (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: carry-out-of-ifix-y

    (defthm carry-out-of-ifix-y
      (equal (carry-out width cin x (ifix y))
             (carry-out width cin x y)))

    Theorem: carry-out-int-equiv-congruence-on-y

    (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)