• 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
        • Bitops
          • Bitops/merge
          • Bitops-compatibility
          • Bitops-books
          • Logbitp-reasoning
          • Bitops/signed-byte-p
          • Fast-part-select
          • Bitops/integer-length
          • Bitops/extra-defs
            • Abs-diff
              • Nth-slice512
              • Nth-slice128
              • Nth-slice8
              • Nth-slice64
              • Nth-slice4
              • Nth-slice32
              • Nth-slice256
              • Nth-slice2
              • Nth-slice16
              • Negate-slice8
              • Copybit
              • Negate-slice32
              • Negate-slice16
              • Negate-slice64
              • Bitscan-rev
              • Bitscan-fwd
              • Setbit
              • Notbit
              • Clearbit
            • Install-bit
            • Trailing-0-count
            • Bitops/defaults
            • Logbitp-mismatch
            • Trailing-1-count
            • Bitops/rotate
            • Bitops/equal-by-logbitp
            • Bitops/ash-bounds
            • Bitops/fast-logrev
            • Limited-shifts
            • Bitops/part-select
            • Bitops/parity
            • Bitops/saturate
            • Bitops/part-install
            • Bitops/logbitp-bounds
            • Bitops/ihsext-basics
            • Bitops/fast-rotate
            • Bitops/fast-logext
            • Bitops/ihs-extensions
          • Bv
          • Ihs
          • Rtl
        • Algebra
      • Testing-utilities
    • Bitops/extra-defs

    Abs-diff

    (abs-diff a b) is just (abs (- (ifix a) (ifix b))), but optimized for ACL2::gl.

    Signature
    (abs-diff a b) → ans
    Arguments
    a — Guard (integerp a).
    b — Guard (integerp b).
    Returns
    ans — Type (natp ans).

    abs-diff is similar to (abs (- a b)) but has better performance for symbolic simulations with GL: it decides whether the subtraction will be necessary by looking at the arguments, which tend to be simple and perhaps nicely interleaved, instead of by looking at the result, which tend to be complex since they are the combined arguments.

    For an aig-cert-mode proof of the 64-bit PSADBW instruction, using abs-diff instead of (abs (- a b)) reduced the proof time from 56.2 seconds to 37.44 seconds.

    We disable this function, but we leave enabled the following theorem:

    Theorem: abs-diff-correct

    (defthm abs-diff-correct
      (equal (abs-diff a b)
             (abs (- (ifix a) (ifix b)))))

    We therefore would not expect to ever need to reason about abs-diff directly.

    Definitions and Theorems

    Function: abs-diff

    (defun abs-diff (a b)
      (declare (xargs :guard (and (integerp a) (integerp b))))
      (let ((__function__ 'abs-diff))
        (declare (ignorable __function__))
        (mbe :logic
             (let ((a (ifix a)) (b (ifix b)))
               (if (<= b a) (- a b) (- b a)))
             :exec (if (<= b a) (- a b) (- b a)))))

    Theorem: natp-of-abs-diff

    (defthm acl2::natp-of-abs-diff
      (b* ((ans (abs-diff a b))) (natp ans))
      :rule-classes :type-prescription)

    Theorem: abs-diff-correct

    (defthm abs-diff-correct
      (equal (abs-diff a b)
             (abs (- (ifix a) (ifix b)))))