• 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
      • Projects
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Truth

    Swap-vars

    Signature
    (swap-vars n m truth numvars) → swapped-truth
    Arguments
    n — Guard (natp n).
    m — Guard (natp m).
    truth — Guard (integerp truth).
    numvars — Guard (natp numvars).
    Returns
    swapped-truth — Type (integerp swapped-truth).

    Definitions and Theorems

    Function: swap-vars

    (defun swap-vars (n m truth numvars)
           (declare (xargs :guard (and (natp n)
                                       (natp m)
                                       (integerp truth)
                                       (natp numvars))))
           (declare (xargs :guard (and (< n numvars) (< m numvars))))
           (let ((__function__ 'swap-vars))
                (declare (ignorable __function__))
                (cond ((< (lnfix n) (lnfix m))
                       (swap-vars-aux m n truth numvars))
                      ((< (lnfix m) (lnfix n))
                       (swap-vars-aux n m truth numvars))
                      (t (truth-norm truth numvars)))))

    Theorem: integerp-of-swap-vars

    (defthm integerp-of-swap-vars
            (b* ((swapped-truth (swap-vars n m truth numvars)))
                (integerp swapped-truth))
            :rule-classes :type-prescription)

    Theorem: swap-vars-commute

    (defthm swap-vars-commute
            (b* nil
                (equal (swap-vars m n truth numvars)
                       (swap-vars n m truth numvars)))
            :rule-classes ((:rewrite :loop-stopper ((n m)))))

    Theorem: eval-of-swap-vars

    (defthm
         eval-of-swap-vars
         (b* ((?swapped-truth (swap-vars n m truth numvars)))
             (implies (and (< (nfix n) (nfix numvars))
                           (< (nfix m) (nfix numvars)))
                      (equal (truth-eval swapped-truth env numvars)
                             (truth-eval truth (env-swap-vars n m env)
                                         numvars)))))

    Theorem: size-of-swap-vars

    (defthm size-of-swap-vars
            (b* ((?swapped-truth (swap-vars n m truth numvars)))
                (implies (and (< (nfix n) (nfix numvars))
                              (< (nfix m) (nfix numvars))
                              (natp size)
                              (<= (ash 1 numvars) size))
                         (unsigned-byte-p size swapped-truth))))

    Theorem: swap-vars-self

    (defthm swap-vars-self
            (b* nil
                (equal (swap-vars n n truth numvars)
                       (truth-norm truth numvars))))

    Theorem: truth-norm-of-swap-vars

    (defthm truth-norm-of-swap-vars
            (b* ((?swapped-truth (swap-vars n m truth numvars)))
                (implies (and (< (nfix n) (nfix numvars))
                              (< (nfix m) (nfix numvars)))
                         (equal (truth-norm swapped-truth numvars)
                                swapped-truth))))

    Theorem: swap-vars-of-truth-norm

    (defthm swap-vars-of-truth-norm
            (equal (swap-vars n m (truth-norm truth numvars)
                              numvars)
                   (swap-vars n m truth numvars)))

    Theorem: swap-vars-of-nfix-n

    (defthm swap-vars-of-nfix-n
            (equal (swap-vars (nfix n) m truth numvars)
                   (swap-vars n m truth numvars)))

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

    (defthm swap-vars-nat-equiv-congruence-on-n
            (implies (nat-equiv n n-equiv)
                     (equal (swap-vars n m truth numvars)
                            (swap-vars n-equiv m truth numvars)))
            :rule-classes :congruence)

    Theorem: swap-vars-of-nfix-m

    (defthm swap-vars-of-nfix-m
            (equal (swap-vars n (nfix m) truth numvars)
                   (swap-vars n m truth numvars)))

    Theorem: swap-vars-nat-equiv-congruence-on-m

    (defthm swap-vars-nat-equiv-congruence-on-m
            (implies (nat-equiv m m-equiv)
                     (equal (swap-vars n m truth numvars)
                            (swap-vars n m-equiv truth numvars)))
            :rule-classes :congruence)

    Theorem: swap-vars-of-ifix-truth

    (defthm swap-vars-of-ifix-truth
            (equal (swap-vars n m (ifix truth) numvars)
                   (swap-vars n m truth numvars)))

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

    (defthm swap-vars-int-equiv-congruence-on-truth
            (implies (int-equiv truth truth-equiv)
                     (equal (swap-vars n m truth numvars)
                            (swap-vars n m truth-equiv numvars)))
            :rule-classes :congruence)

    Theorem: swap-vars-of-nfix-numvars

    (defthm swap-vars-of-nfix-numvars
            (equal (swap-vars n m truth (nfix numvars))
                   (swap-vars n m truth numvars)))

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

    (defthm swap-vars-nat-equiv-congruence-on-numvars
            (implies (nat-equiv numvars numvars-equiv)
                     (equal (swap-vars n m truth numvars)
                            (swap-vars n m truth numvars-equiv)))
            :rule-classes :congruence)