• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
      • Std/osets
      • Std/io
      • Std/basic
      • Std/system
        • Fresh-logical-name-with-$s-suffix
        • Irrelevant-formals-info
        • Std/system/function-queries
        • Std/system/term-queries
        • Std/system/term-transformations
          • Make-mv-let-call
          • Mvify
          • Remove-trivial-vars
            • Remove-equal-formals-actuals
            • Remove-trivial-vars-lst
          • Remove-unused-vars
          • Fsublis-fn-rec
          • Close-lambdas
          • Fsublis-var
          • Remove-mbe-logic/exec
          • Untranslate$
          • Remove-dead-if-branches
          • Remove-progn
          • Make-mv-nth-calls
          • Apply-fn-into-ifs
          • Conjoin-equalities
          • Fapply-unary-to-terms
          • Apply-unary-to-terms
          • Apply-terms-same-args
          • Apply-term
          • Fsublis-fn-lst-simple
          • Fsublis-fn
          • Fapply-terms-same-args
          • Fsublis-fn-simple
          • Fapply-term
          • Remove-mbe-logic
          • Remove-mbe-exec
          • Quote-term
          • Quote-term-list
          • Apply-term*
          • Std/system/fsubcor-var
          • Std/system/conjoin
          • Std/system/flatten-ands-in-lit
          • Fapply-term*
          • Std/system/dumb-negate-lit
        • Std/system/enhanced-utilities
        • Install-not-normalized-event
        • Install-not-normalized-event-lst
        • Std/system/term-function-recognizers
        • Genvar$
        • Std/system/event-name-queries
        • Pseudo-tests-and-call-listp
        • Maybe-pseudo-event-formp
        • Add-suffix-to-fn-or-const
        • Chk-irrelevant-formals-ok
        • Table-alist+
        • Pseudo-tests-and-callp
        • Add-suffix-to-fn-or-const-lst
        • Known-packages+
        • Add-suffix-to-fn-lst
        • Unquote-term
        • Event-landmark-names
        • Add-suffix-lst
        • Std/system/theorem-queries
        • Unquote-term-list
        • Std/system/macro-queries
        • Pseudo-command-landmark-listp
        • Install-not-normalized$
        • Pseudo-event-landmark-listp
        • Known-packages
        • Std/system/partition-rest-and-keyword-args
        • Rune-enabledp
        • Rune-disabledp
        • Included-books
        • Std/system/pseudo-event-formp
        • Std/system/plist-worldp-with-formals
        • Std/system/w
        • Std/system/geprops
        • Std/system/arglistp
        • Std/system/constant-queries
      • Std/typed-lists
      • Std/bitsets
      • Std/testing
      • Std/typed-alists
      • Std/stobjs
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Std/system/term-transformations

Remove-trivial-vars

Remove the trivial lambda-bound variables.

Signature
(remove-trivial-vars term) → new-term
Arguments
term — Guard (pseudo-termp term).
Returns
new-term — Type (pseudo-termp new-term), given (pseudo-termp term).

ACL2 lambda expressions in translated terms are always closed, which means that they often include formal parameters that are replaced by themselves (i.e. by the same symbols) when the lambda expression is applied. For instance, the untranslated term (let ((x 3)) (+ x y)) is ((lambda (x y) (binary-+ x y)) '3 y) in translated form: the lambda expression includes the extra formal parameter y which is not bound by the let, applied to y itself, making the lambda expression closed.

This function removes the formal parameters of lambda expressions that are ``trivial'' in the sense that they are replaced by identical actual parameters. These are ``artificial'' variables, not let variables. We also remove the corresponding actual parameters, of course, so that beta reduction still makes sense, and the number of actual parameters still matches the number of formal parameters. Applying this function to the example above yields ((lambda (x) (binary-+ x y)) '3).

If all the formal parameters are trivial, we replace the lambda expression with its body. A lambda expression with all trivial formal parameters may not result from hand-written code, but could result from generated code.

We obtain terms whose lambda expressions may not be closed. These do not satisfy termp, but they still satisfy pseudo-termp. Furthermore, it is easy to close any open lambda expressions, by adding formal parameters, and corresponding actual parameters, for the free variables in the lambda expression.

For certain term transformations, it may be more convenient to work with the possibly open lamba expressions produced by this function. This way, every lambda expression corresponds to a let without any trivial bindings. In other languages, let expressions are normally not closed.

Theorem: return-type-of-remove-trivial-vars.new-term

(defthm return-type-of-remove-trivial-vars.new-term
  (implies (pseudo-termp term)
           (b* ((?new-term (remove-trivial-vars term)))
             (pseudo-termp new-term)))
  :rule-classes :rewrite)

Theorem: return-type-of-remove-trivial-vars-lst.new-terms

(defthm return-type-of-remove-trivial-vars-lst.new-terms
  (implies (pseudo-term-listp terms)
           (b* ((?new-terms (remove-trivial-vars-lst terms)))
             (and (pseudo-term-listp new-terms)
                  (equal (len new-terms) (len terms)))))
  :rule-classes :rewrite)

Subtopics

Remove-equal-formals-actuals
Remove equal formals and actuals from two lists of the same length.
Remove-trivial-vars-lst