Function:
(defun swap-polarity (n truth numvars) (declare (xargs :guard (and (natp n) (integerp truth) (natp numvars)))) (declare (xargs :guard (< n numvars))) (let ((__function__ 'swap-polarity)) (declare (ignorable __function__)) (b* ((truth (truth-norm truth numvars)) (var (var n numvars)) (shift (ash 1 (lnfix n)))) (logior (ash (logand var truth) (- shift)) (ash (logand (lognot var) (loghead (ash 1 (lnfix numvars)) truth)) shift)))))
Theorem:
(defthm integerp-of-swap-polarity (b* ((new-truth (swap-polarity n truth numvars))) (integerp new-truth)) :rule-classes :type-prescription)
Theorem:
(defthm swap-polarity-correct (b* ((?new-truth (swap-polarity n truth numvars))) (implies (< (nfix n) (nfix numvars)) (equal (truth-eval new-truth env numvars) (truth-eval truth (env-swap-polarity n env) numvars)))))
Theorem:
(defthm size-of-logand-by-size-of-loghead-2 (implies (and (unsigned-byte-p m a) (unsigned-byte-p n (loghead m b))) (unsigned-byte-p n (logand b a))))
Theorem:
(defthm size-of-logand-with-loghead (implies (unsigned-byte-p n (loghead m b)) (unsigned-byte-p n (logand b (loghead m a)))))
Theorem:
(defthm swap-polarity-size-basic (b* ((?new-truth (swap-polarity n truth numvars))) (implies (< (nfix n) (nfix numvars)) (unsigned-byte-p (ash 1 numvars) new-truth))))
Theorem:
(defthm swap-polarity-size (b* ((?new-truth (swap-polarity n truth numvars))) (implies (and (natp size) (<= (ash 1 (nfix numvars)) size) (< (nfix n) (nfix numvars))) (unsigned-byte-p size new-truth))))
Theorem:
(defthm swap-polarity-of-truth-norm (equal (swap-polarity n (truth-norm truth numvars) numvars) (swap-polarity n truth numvars)))
Theorem:
(defthm swap-polarity-of-nfix-n (equal (swap-polarity (nfix n) truth numvars) (swap-polarity n truth numvars)))
Theorem:
(defthm swap-polarity-nat-equiv-congruence-on-n (implies (nat-equiv n n-equiv) (equal (swap-polarity n truth numvars) (swap-polarity n-equiv truth numvars))) :rule-classes :congruence)
Theorem:
(defthm swap-polarity-of-ifix-truth (equal (swap-polarity n (ifix truth) numvars) (swap-polarity n truth numvars)))
Theorem:
(defthm swap-polarity-int-equiv-congruence-on-truth (implies (int-equiv truth truth-equiv) (equal (swap-polarity n truth numvars) (swap-polarity n truth-equiv numvars))) :rule-classes :congruence)
Theorem:
(defthm swap-polarity-of-nfix-numvars (equal (swap-polarity n truth (nfix numvars)) (swap-polarity n truth numvars)))
Theorem:
(defthm swap-polarity-nat-equiv-congruence-on-numvars (implies (nat-equiv numvars numvars-equiv) (equal (swap-polarity n truth numvars) (swap-polarity n truth numvars-equiv))) :rule-classes :congruence)