• Top
    • Documentation
    • Books
    • Boolean-reasoning
      • Ipasir
      • Aignet
      • Aig
      • Satlink
      • Truth
        • Index-permute-shrink
        • Permute-stretch
        • Permute-shrink
        • Env-mismatch-aux
        • Env-permute-shrink
        • Permute-polarity
        • Env-permute-polarity
        • Permute-var-down
        • Env-permute-stretch
        • Swap-vars-aux
        • Swap-vars
        • Permute-var-up
        • Truth-perm-rev
        • Negative-cofactor
        • Index-permute-stretch
        • Env-mismatch
        • Swap-polarity
          • Positive-cofactor
          • Truth-perm
          • Index-perm-rev
          • Nth-set-bit-pos
          • Env-perm-rev
          • Is-xor-with-var
          • Index-swap
          • Index-perm
          • Env-move-var-down
          • Truth-eval
          • Env-swap-vars
          • Env-perm
          • Depends-on-witness
          • Var
          • Index-move-down
          • Env-update
          • Env-swap-polarity
          • Var-repetitions
          • Env-move-var-up
          • Depends-on
          • Index-move-up
          • Truth-norm
          • Index-listp
          • Env-diff-index
          • Env-lookup
          • True
          • False
        • Ubdds
        • Bdd
        • Faig
        • Bed
        • 4v
      • Projects
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Truth

    Swap-polarity

    Signature
    (swap-polarity n truth numvars) → new-truth
    Arguments
    n — Guard (natp n).
    truth — Guard (integerp truth).
    numvars — Guard (natp numvars).
    Returns
    new-truth — Type (integerp new-truth).

    Definitions and Theorems

    Function: swap-polarity

    (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: integerp-of-swap-polarity

    (defthm integerp-of-swap-polarity
      (b* ((new-truth (swap-polarity n truth numvars)))
        (integerp new-truth))
      :rule-classes :type-prescription)

    Theorem: swap-polarity-correct

    (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: size-of-logand-by-size-of-loghead-2

    (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: size-of-logand-with-loghead

    (defthm size-of-logand-with-loghead
      (implies (unsigned-byte-p n (loghead m b))
               (unsigned-byte-p n (logand b (loghead m a)))))

    Theorem: swap-polarity-size-basic

    (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: swap-polarity-size

    (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: swap-polarity-of-truth-norm

    (defthm swap-polarity-of-truth-norm
      (equal (swap-polarity n (truth-norm truth numvars)
                            numvars)
             (swap-polarity n truth numvars)))

    Theorem: swap-polarity-of-nfix-n

    (defthm swap-polarity-of-nfix-n
      (equal (swap-polarity (nfix n) truth numvars)
             (swap-polarity n truth numvars)))

    Theorem: swap-polarity-nat-equiv-congruence-on-n

    (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: swap-polarity-of-ifix-truth

    (defthm swap-polarity-of-ifix-truth
      (equal (swap-polarity n (ifix truth) numvars)
             (swap-polarity n truth numvars)))

    Theorem: swap-polarity-int-equiv-congruence-on-truth

    (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: swap-polarity-of-nfix-numvars

    (defthm swap-polarity-of-nfix-numvars
      (equal (swap-polarity n truth (nfix numvars))
             (swap-polarity n truth numvars)))

    Theorem: swap-polarity-nat-equiv-congruence-on-numvars

    (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)