(bitset-insert a x) constructs the set
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.
Function:
(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:
(defthm acl2::natp-of-bitset-insert (b* ((bitset (acl2::bitset-insert$inline a x))) (natp bitset)) :rule-classes :type-prescription)
Theorem:
(defthm bitset-insert-when-not-natp-left (implies (not (natp a)) (equal (bitset-insert a x) (bitset-insert 0 x))))
Theorem:
(defthm bitset-insert-when-not-natp-right (implies (not (natp x)) (equal (bitset-insert a x) (bitset-singleton a))))
Theorem:
(defthm bitset-insert-of-nfix-left (equal (bitset-insert (nfix a) x) (bitset-insert a x)))
Theorem:
(defthm bitset-insert-of-nfix-right (equal (bitset-insert a (nfix x)) (bitset-insert a x)))
Theorem:
(defthm set::bitset-members-of-bitset-insert (equal (bitset-members (bitset-insert a x)) (insert (nfix a) (bitset-members x))))