• 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

    Sparseint$-height

    Signature
    (sparseint$-height x) → height
    Arguments
    x — Guard (sparseint$-p x).
    Returns
    height — Type (natp height).

    Definitions and Theorems

    Function: sparseint$-height

    (defun sparseint$-height (x)
     (declare (xargs :guard (sparseint$-p x)))
     (declare (xargs :guard (sparseint$-height-correctp x)))
     (let ((__function__ 'sparseint$-height))
      (declare (ignorable __function__))
      (sparseint$-case
       x
       :leaf 0
       :concat
       (mbe :logic (+ 1
                      (max (sparseint$-height x.lsbs)
                           (sparseint$-height x.msbs)))
            :exec (cond (x.lsbs-taller (+ 2 (sparseint$-height x.msbs)))
                        (x.msbs-taller (+ 2 (sparseint$-height x.lsbs)))
                        (t (+ 1 (sparseint$-height x.lsbs))))))))

    Theorem: natp-of-sparseint$-height

    (defthm natp-of-sparseint$-height
      (b* ((height (sparseint$-height x)))
        (natp height))
      :rule-classes :type-prescription)

    Theorem: sparseint$-real-height-equals-sparseint$-height

    (defthm sparseint$-real-height-equals-sparseint$-height
      (b* ((?height (sparseint$-height x)))
        (equal (sparseint$-real-height x)
               height)))

    Theorem: sparseint$-height-equal-0

    (defthm sparseint$-height-equal-0
      (b* ((?height (sparseint$-height x)))
        (equal (equal height 0)
               (sparseint$-case x :leaf))))

    Theorem: sparseint$-height-when-concat

    (defthm sparseint$-height-when-concat
      (implies (sparseint$-case x :concat)
               (equal (sparseint$-height x)
                      (b* (((sparseint$-concat x)))
                        (+ 1
                           (max (sparseint$-height x.lsbs)
                                (sparseint$-height x.msbs)))))))

    Theorem: sparseint$-height-of-concat

    (defthm sparseint$-height-of-concat
      (equal (sparseint$-height
                  (make-sparseint$-concat :width width
                                          :lsbs lsbs
                                          :msbs msbs
                                          :lsbs-taller lsbs-taller
                                          :msbs-taller msbs-taller))
             (+ 1
                (max (sparseint$-height lsbs)
                     (sparseint$-height msbs)))))

    Theorem: sparseint$-height-when-leaf

    (defthm sparseint$-height-when-leaf
      (implies (sparseint$-case x :leaf)
               (equal (sparseint$-height x) 0))
      :rule-classes (:rewrite :forward-chaining))

    Theorem: sparseint$-height-posp-when-concat

    (defthm sparseint$-height-posp-when-concat
      (b* ((?height (sparseint$-height x)))
        (iff (posp height)
             (equal (sparseint$-kind x) :concat)))
      :rule-classes
      ((:forward-chaining
            :trigger-terms ((sparseint$-height x))
            :corollary (implies (posp (sparseint$-height x))
                                (equal (sparseint$-kind x) :concat)))
       (:forward-chaining
            :trigger-terms ((equal (sparseint$-kind x) :concat))
            :corollary (implies (equal (sparseint$-kind x) :concat)
                                (posp (sparseint$-height x))))))

    Theorem: sparseint$-height-gt-0-implies-concat

    (defthm sparseint$-height-gt-0-implies-concat
      (b* ((?height (sparseint$-height x)))
        (implies (< 0 height)
                 (equal (sparseint$-kind x) :concat)))
      :rule-classes
      ((:forward-chaining :trigger-terms ((sparseint$-height x)))))

    Theorem: sparseint$-height-of-lsbs-upper-bound

    (defthm sparseint$-height-of-lsbs-upper-bound
      (implies (sparseint$-case x :concat)
               (<= (sparseint$-height (sparseint$-concat->lsbs x))
                   (+ -1 (sparseint$-height x))))
      :rule-classes :linear)

    Theorem: sparseint$-height-of-msbs-upper-bound

    (defthm sparseint$-height-of-msbs-upper-bound
      (implies (sparseint$-case x :concat)
               (<= (sparseint$-height (sparseint$-concat->msbs x))
                   (+ -1 (sparseint$-height x))))
      :rule-classes :linear)

    Theorem: sparseint$-height-of-sparseint$-fix-x

    (defthm sparseint$-height-of-sparseint$-fix-x
      (equal (sparseint$-height (sparseint$-fix x))
             (sparseint$-height x)))

    Theorem: sparseint$-height-sparseint$-equiv-congruence-on-x

    (defthm sparseint$-height-sparseint$-equiv-congruence-on-x
      (implies (sparseint$-equiv x x-equiv)
               (equal (sparseint$-height x)
                      (sparseint$-height x-equiv)))
      :rule-classes :congruence)