• 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

    Bitscan-fwd

    (bitscan-fwd src) returns the bit position of the least significant bit in src that is set, or 0 when src is zero (and hence has no such bit).

    Signature
    (bitscan-fwd src) → position
    Arguments
    src — Guard (natp src).
    Returns
    position — Type (natp position).

    Examples:

    (bitscan-fwd #b1001) = 0
    (bitscan-fwd #b1010) = 1
    (bitscan-fwd #b1100) = 2
    (bitscan-fwd #b1000) = 3

    Definitions and Theorems

    Function: bitscan-fwd

    (defun bitscan-fwd (src)
      (declare (xargs :guard (natp src)))
      (let ((__function__ 'bitscan-fwd))
        (declare (ignorable __function__))
        (cond ((zp src) 0)
              ((logbitp 0 src) 0)
              (t (+ 1 (bitscan-fwd (ash src -1)))))))

    Theorem: natp-of-bitscan-fwd

    (defthm acl2::natp-of-bitscan-fwd
      (b* ((position (bitscan-fwd src)))
        (natp position))
      :rule-classes :type-prescription)

    Theorem: nat-equiv-implies-equal-bitscan-fwd-1

    (defthm nat-equiv-implies-equal-bitscan-fwd-1
      (implies (nat-equiv src src-equiv)
               (equal (bitscan-fwd src)
                      (bitscan-fwd src-equiv)))
      :rule-classes (:congruence))