Count the 1 bits in a sparseint if positive, 0 bits if negative.
(sparseint-bitcount x) → count
Function:
(defun sparseint-bitcount (x) (declare (xargs :guard (sparseint-p x))) (let ((__function__ 'sparseint-bitcount)) (declare (ignorable __function__)) (sparseint$-bitcount-rec 0 (bool->bit (sparseint-< x 0)) (sparseint-fix x))))
Theorem:
(defthm natp-of-sparseint-bitcount (b* ((count (sparseint-bitcount x))) (natp count)) :rule-classes :type-prescription)
Theorem:
(defthm sparseint-bitcount-correct (b* ((common-lisp::?count (sparseint-bitcount x))) (equal count (logcount (sparseint-val x)))))
Theorem:
(defthm sparseint-bitcount-of-sparseint-fix-x (equal (sparseint-bitcount (sparseint-fix x)) (sparseint-bitcount x)))
Theorem:
(defthm sparseint-bitcount-sparseint-equiv-congruence-on-x (implies (sparseint-equiv x x-equiv) (equal (sparseint-bitcount x) (sparseint-bitcount x-equiv))) :rule-classes :congruence)