• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
      • Std/io
      • Std/osets
      • Std/system
      • Std/basic
      • Std/typed-lists
      • Std/bitsets
        • Bitsets
          • Bitset-members
          • Bitset-insert
            • Bitset-delete
            • Bitset-intersectp
            • Bitset-intersect
            • Bitset-difference
            • Bitset-subsetp
            • Bitset-memberp
            • Bitset-union
            • Bitset-singleton
            • Bitset-list
            • Bitset-cardinality
            • Bitset-list*
            • Utilities
          • Sbitsets
          • Reasoning
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Bitsets

    Bitset-insert

    (bitset-insert a x) constructs the set X U {a}.

    Signature
    (bitset-insert a x) → bitset
    Arguments
    a — Guard (natp a).
    x — Guard (natp x).
    Returns
    bitset — Type (natp bitset).

    This looks pretty efficient, but keep in mind that it still has to construct a new set and hence is linear in the size of the set. You should probably avoid calling this in a loop if possible; instead consider functions like bitset-union.

    Definitions and Theorems

    Function: bitset-insert$inline

    (defun acl2::bitset-insert$inline (a x)
           (declare (type unsigned-byte a)
                    (type unsigned-byte x))
           (declare (xargs :guard (and (natp a) (natp x))))
           (declare (xargs :split-types t))
           (let ((__function__ 'bitset-insert))
                (declare (ignorable __function__))
                (the unsigned-byte
                     (logior (the unsigned-byte (ash 1 (lnfix a)))
                             (the unsigned-byte (lnfix x))))))

    Theorem: natp-of-bitset-insert

    (defthm acl2::natp-of-bitset-insert
            (b* ((bitset (acl2::bitset-insert$inline a x)))
                (natp bitset))
            :rule-classes :type-prescription)

    Theorem: bitset-insert-when-not-natp-left

    (defthm bitset-insert-when-not-natp-left
            (implies (not (natp a))
                     (equal (bitset-insert a x)
                            (bitset-insert 0 x))))

    Theorem: bitset-insert-when-not-natp-right

    (defthm bitset-insert-when-not-natp-right
            (implies (not (natp x))
                     (equal (bitset-insert a x)
                            (bitset-singleton a))))

    Theorem: bitset-insert-of-nfix-left

    (defthm bitset-insert-of-nfix-left
            (equal (bitset-insert (nfix a) x)
                   (bitset-insert a x)))

    Theorem: bitset-insert-of-nfix-right

    (defthm bitset-insert-of-nfix-right
            (equal (bitset-insert a (nfix x))
                   (bitset-insert a x)))

    Theorem: bitset-members-of-bitset-insert

    (defthm set::bitset-members-of-bitset-insert
            (equal (bitset-members (bitset-insert a x))
                   (insert (nfix a) (bitset-members x))))