(parity n x) computes the parity of the low
This has a simple recursive definition which should be easy to reason about. However, it isn't particularly efficient; see fast-parity for a more efficient, logically identical function.
Function:
(defun parity (n x) (declare (xargs :guard (and (natp n) (integerp x)))) (let ((__function__ 'parity)) (declare (ignorable __function__)) (cond ((zp n) 0) (t (logxor (logand x 1) (parity (1- n) (ash x -1)))))))
Theorem:
(defthm acl2::bitp-of-parity (b* ((p (parity n x))) (bitp p)) :rule-classes :type-prescription)
Theorem:
(defthm acl2::parity-of-nfix-n (equal (parity (nfix n) x) (parity n x)))
Theorem:
(defthm acl2::parity-nat-equiv-congruence-on-n (implies (nat-equiv n acl2::n-equiv) (equal (parity n x) (parity acl2::n-equiv x))) :rule-classes :congruence)
Theorem:
(defthm acl2::parity-of-ifix-x (equal (parity n (ifix x)) (parity n x)))
Theorem:
(defthm acl2::parity-int-equiv-congruence-on-x (implies (int-equiv x acl2::x-equiv) (equal (parity n x) (parity n acl2::x-equiv))) :rule-classes :congruence)
Theorem:
(defthm parity-decomp (equal (logxor (parity m (logtail n x)) (parity n (loghead n x))) (parity (+ (nfix m) (nfix n)) x)))
Theorem:
(defthm parity-of-logxor (equal (parity n (logxor x y)) (logxor (parity n x) (parity n y))))
Theorem:
(defthm parity-of-0 (equal (parity n 0) 0))
Theorem:
(defthm parity-of-loghead-split (equal (parity m (loghead n x)) (parity (min (nfix m) (nfix n)) x)))