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