• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • 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

    Sparseint$-plus-int

    Signature
    (sparseint$-plus-int offset x x.height y cin) 
      → 
    (mv sum height)
    Arguments
    offset — Guard (natp offset).
    x — Guard (sparseint$-p x).
    x.height — Guard (natp x.height).
    y — Guard (integerp y).
    cin — Guard (bitp cin).
    Returns
    sum — Type (sparseint$-p sum).
    height — Type (equal height (sparseint$-height sum)).

    Definitions and Theorems

    Function: sparseint$-plus-int

    (defun sparseint$-plus-int (offset x x.height y cin)
     (declare (xargs :guard (and (natp offset)
                                 (sparseint$-p x)
                                 (natp x.height)
                                 (integerp y)
                                 (bitp cin))))
     (declare
          (xargs :guard (and (sparseint$-height-correctp x)
                             (equal x.height (sparseint$-height x)))))
     (let ((__function__ 'sparseint$-plus-int))
      (declare (ignorable __function__))
      (b* ((offset (lnfix offset))
           (y (lifix y))
           (cin (lbfix cin))
           (x.height (mbe :logic (sparseint$-height x)
                          :exec x.height)))
       (sparseint$-case
         x :leaf
         (b* ((xval (logtail offset x.val))
              (sum (sum-with-cin cin xval y)))
           (mv (sparseint$-leaf sum) 0))
         :concat
         (b*
          ((x.msbs.height
                (mbe :logic (sparseint$-height x.msbs)
                     :exec (- x.height (if x.lsbs-taller 2 1))))
           ((when (<= x.width offset))
            (sparseint$-plus-int (- offset x.width)
                                 x.msbs x.msbs.height y cin))
           (width1 (- x.width offset))
           (x.lsbs.height
                (mbe :logic (sparseint$-height x.lsbs)
                     :exec (- x.height (if x.msbs-taller 2 1))))
           ((mv lsbs-sum lsbs-sum-height lsbs-cout)
            (sparseint$-plus-int-width
                 width1 offset x.lsbs
                 x.lsbs.height (bignum-logext width1 y)
                 cin))
           ((mv msbs-sum msbs-sum-height)
            (sparseint$-plus-int 0
                                 x.msbs x.msbs.height (logtail width1 y)
                                 lsbs-cout))
           ((mv sum-concat sum-height)
            (sparseint$-concatenate-rebalance
                 width1 lsbs-sum lsbs-sum-height
                 msbs-sum msbs-sum-height)))
          (mv sum-concat sum-height))))))

    Theorem: sparseint$-p-of-sparseint$-plus-int.sum

    (defthm sparseint$-p-of-sparseint$-plus-int.sum
      (b* (((mv ?sum ?height)
            (sparseint$-plus-int offset x x.height y cin)))
        (sparseint$-p sum))
      :rule-classes :rewrite)

    Theorem: return-type-of-sparseint$-plus-int.height

    (defthm return-type-of-sparseint$-plus-int.height
      (b* (((mv ?sum ?height)
            (sparseint$-plus-int offset x x.height y cin)))
        (equal height (sparseint$-height sum)))
      :rule-classes :rewrite)

    Theorem: sparseint$-height-correctp-of-sparseint$-plus-int

    (defthm sparseint$-height-correctp-of-sparseint$-plus-int
      (b* (((mv ?sum ?height)
            (sparseint$-plus-int offset x x.height y cin)))
        (implies (sparseint$-height-correctp x)
                 (sparseint$-height-correctp sum))))

    Theorem: sparseint$-val-of-sparseint$-plus-int

    (defthm sparseint$-val-of-sparseint$-plus-int
      (b* (((mv ?sum ?height)
            (sparseint$-plus-int offset x x.height y cin)))
        (equal (sparseint$-val sum)
               (sum-with-cin cin (logtail offset (sparseint$-val x))
                             y))))

    Theorem: sparseint$-plus-int-of-nfix-offset

    (defthm sparseint$-plus-int-of-nfix-offset
      (equal (sparseint$-plus-int (nfix offset)
                                  x x.height y cin)
             (sparseint$-plus-int offset x x.height y cin)))

    Theorem: sparseint$-plus-int-nat-equiv-congruence-on-offset

    (defthm sparseint$-plus-int-nat-equiv-congruence-on-offset
      (implies
           (nat-equiv offset offset-equiv)
           (equal (sparseint$-plus-int offset x x.height y cin)
                  (sparseint$-plus-int offset-equiv x x.height y cin)))
      :rule-classes :congruence)

    Theorem: sparseint$-plus-int-of-sparseint$-fix-x

    (defthm sparseint$-plus-int-of-sparseint$-fix-x
      (equal (sparseint$-plus-int offset (sparseint$-fix x)
                                  x.height y cin)
             (sparseint$-plus-int offset x x.height y cin)))

    Theorem: sparseint$-plus-int-sparseint$-equiv-congruence-on-x

    (defthm sparseint$-plus-int-sparseint$-equiv-congruence-on-x
      (implies
           (sparseint$-equiv x x-equiv)
           (equal (sparseint$-plus-int offset x x.height y cin)
                  (sparseint$-plus-int offset x-equiv x.height y cin)))
      :rule-classes :congruence)

    Theorem: sparseint$-plus-int-of-nfix-x.height

    (defthm sparseint$-plus-int-of-nfix-x.height
      (equal (sparseint$-plus-int offset x (nfix x.height)
                                  y cin)
             (sparseint$-plus-int offset x x.height y cin)))

    Theorem: sparseint$-plus-int-nat-equiv-congruence-on-x.height

    (defthm sparseint$-plus-int-nat-equiv-congruence-on-x.height
      (implies
           (nat-equiv x.height x.height-equiv)
           (equal (sparseint$-plus-int offset x x.height y cin)
                  (sparseint$-plus-int offset x x.height-equiv y cin)))
      :rule-classes :congruence)

    Theorem: sparseint$-plus-int-of-ifix-y

    (defthm sparseint$-plus-int-of-ifix-y
      (equal (sparseint$-plus-int offset x x.height (ifix y)
                                  cin)
             (sparseint$-plus-int offset x x.height y cin)))

    Theorem: sparseint$-plus-int-int-equiv-congruence-on-y

    (defthm sparseint$-plus-int-int-equiv-congruence-on-y
      (implies
           (int-equiv y y-equiv)
           (equal (sparseint$-plus-int offset x x.height y cin)
                  (sparseint$-plus-int offset x x.height y-equiv cin)))
      :rule-classes :congruence)

    Theorem: sparseint$-plus-int-of-bfix-cin

    (defthm sparseint$-plus-int-of-bfix-cin
      (equal (sparseint$-plus-int offset x x.height y (bfix cin))
             (sparseint$-plus-int offset x x.height y cin)))

    Theorem: sparseint$-plus-int-bit-equiv-congruence-on-cin

    (defthm sparseint$-plus-int-bit-equiv-congruence-on-cin
      (implies
           (bit-equiv cin cin-equiv)
           (equal (sparseint$-plus-int offset x x.height y cin)
                  (sparseint$-plus-int offset x x.height y cin-equiv)))
      :rule-classes :congruence)