Optimized alternative to parity.
This is faster than parity because it computes up to 32 bits of parity at a time using parity32.
Function:
(defun fast-parity (n x) (declare (xargs :guard (and (natp n) (integerp x)))) (let ((__function__ 'fast-parity)) (declare (ignorable __function__)) (mbe :logic (parity n x) :exec (if (<= n 32) (parity32 (logand (logmask n) x)) (logxor (parity32 (logand 4294967295 x)) (fast-parity (- n 32) (ash x -32)))))))
Theorem:
(defthm acl2::bitp-of-fast-parity (b* ((p (fast-parity n x))) (bitp p)) :rule-classes :type-prescription)