• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
        • Soft
        • Bv
        • Imp-language
        • Ethereum
        • Event-macros
        • Java
          • Atj
            • Atj-implementation
              • Atj-types
              • Atj-java-primitive-array-model
              • Atj-java-abstract-syntax
              • Atj-input-processing
              • Atj-java-pretty-printer
              • Atj-code-generation
                • Atj-gen-test-method
                • Atj-shallow-code-generation
                  • Atj-gen-shallow-term-fns
                  • String-jmethodlist-alistp
                  • Atj-gen-shallow-fndef-method
                  • String-jfieldlist-alistp
                  • Atj-gen-shallow-test-code
                  • Atj-adapt-expr-to-type
                  • Atj-gen-shallow-fn-call
                  • Atj-check-marked-annotated-mv-let-call
                    • Atj-gen-shallow-main-class
                    • Atj-gen-shallow-fnnative-method
                    • Atj-gen-shallow-synonym-method
                    • Atj-gen-shallow-if-call
                    • Atj-gen-shallow-and-call
                    • Atj-gen-shallow-pkg-methods
                    • Atj-convert-expr-to-jprim
                    • Atj-gen-shallow-or-call
                    • Atj-convert-expr-from-jprimarr-method
                    • Atj-adapt-expr-to-types
                    • Atj-gen-shallow-all-pkg-methods
                    • Atj-convert-expr-to-jprimarr-method
                    • Atj-gen-shallow-fndef-all-methods
                    • Atj-convert-expr-from-jprim
                    • Atj-gen-shallow-mv-class
                    • Atj-gen-shallow-main-cunit
                    • Atj-gen-shallow-fndef-methods
                    • Atj-gen-shallow-mv-class-name
                    • Atj-shallow-fns-that-may-throw
                    • Atj-gen-shallow-term
                    • Atj-gen-shallow-let-bindings
                    • Atj-gen-shallow-fn-methods
                    • Atj-gen-shallow-jprimarr-new-init-call
                    • Atj-gen-shallow-fnname
                    • Atj-gen-shallow-all-fn-methods
                    • Atj-gen-shallow-not-call
                    • Atj-fnnative-method-name
                    • Atj-gen-shallow-mv-let
                    • Atj-gen-shallow-jprim-constr-call
                    • Atj-gen-shallow-jprimarr-write-call
                    • Atj-gen-shallow-fnnative-all-methods
                    • Atj-gen-shallow-pkg-class
                    • Atj-gen-shallow-jprimarr-length-call
                    • Atj-gen-shallow-pkg-fields
                    • Atj-all-mv-output-types
                    • Atj-gen-shallow-mv-call
                    • Atj-gen-shallow-jprim-binop-call
                    • Atj-gen-shallow-jprim-conv-call
                    • Atj-gen-shallow-primarray-write-method
                    • Atj-gen-shallow-mv-fields
                    • Atj-gen-shallow-jprimarr-read-call
                    • Atj-gen-shallow-jprimarr-new-len-call
                    • Atj-gen-shallow-jprimarr-conv-tolist-call
                    • Atj-gen-shallow-jprimarr-conv-fromlist-call
                    • Atj-gen-shallow-synonym-all-methods
                    • Atj-gen-shallow-jprim-deconstr-call
                    • Atj-gen-shallow-all-pkg-fields
                    • Atj-gen-shallow-test-code-asgs
                    • Atj-gen-shallow-lambda
                    • Atj-gen-shallow-jprim-unop-call
                    • Atj-jprim-binop-fn-to-jbinop
                    • Atj-gen-shallow-mv-asgs
                    • Atj-gen-shallow-env-class
                    • Atj-gen-shallow-mv-params
                    • Atj-gen-shallow-fnnative-methods
                    • Atj-gen-shallow-pkg-classes
                    • Atj-gen-shallow-env-cunit
                    • Atj-gen-shallow-all-synonym-methods
                    • Atj-convert-expr-to-jprimarr
                    • Atj-convert-expr-from-jprimarr
                    • Atj-jprim-constr-fn-of-qconst-to-expr
                    • Atj-gen-shallow-test-code-mv-asgs
                    • Atj-gen-shallow-synonym-methods
                    • Atj-gen-shallow-synonym-method-params
                    • Atj-convert-expr-to-jprimarr-method-name
                    • Atj-convert-expr-from-jprimarr-method-name
                    • Atj-jexpr-list-to-3-jexprs
                    • Atj-jblock-list-to-3-jblocks
                    • Atj-gen-shallow-test-code-comps
                    • Atj-jprim-conv-fn-to-jtype
                    • Atj-gen-shallow-terms
                    • Atj-gen-shallow-mv-field-name
                    • Atj-adapt-exprs-to-types
                    • Atj-jblock-list-to-2-jblocks
                    • Atj-gen-shallow-primarray-write-methods
                    • Atj-gen-shallow-mv-classes
                    • Atj-gen-shallow-jtype
                    • Atj-gen-shallow-build-method
                    • Atj-jexpr-list-to-2-jexprs
                    • Atj-jprimarr-write-to-method-name
                    • Atj-gen-shallow-all-jprimarr-conv-methods
                    • Atj-jprimarr-new-len-fn-to-comp-jtype
                    • Atj-jprimarr-new-init-fn-to-comp-jtype
                    • Atj-jprim-unop-fn-to-junop
                    • *atj-gen-cond-exprs*
                    • Atj-primarray-write-method-name
                    • Atj-gen-shallow-jprimarr-fromlist-methods
                    • Atj-gen-shallow-jprimarr-tolist-methods
                    • Atj-gen-shallow-mv-classes-guard
                    • *atj-mv-singleton-field-name*
                    • *atj-mv-factory-method-name*
                  • Atj-common-code-generation
                  • Atj-shallow-quoted-constant-generation
                  • Atj-pre-translation
                  • Atj-gen-everything
                  • Atj-name-translation
                  • Atj-gen-test-cunit
                  • Atj-gen-test-class
                  • Atj-gen-main-file
                  • Atj-post-translation
                  • Atj-deep-code-generation
                  • Atj-gen-test-methods
                  • Atj-gen-test-file
                  • Atj-gen-env-file
                  • Atj-gen-output-subdir
                • Atj-java-primitives
                • Atj-java-primitive-arrays
                • Atj-type-macros
                • Atj-java-syntax-operations
                • Atj-fn
                • Atj-library-extensions
                • Atj-java-input-types
                • Atj-test-structures
                • Aij-notions
                • Atj-macro-definition
              • Atj-tutorial
            • Aij
            • Language
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Atj-shallow-code-generation

    Atj-check-marked-annotated-mv-let-call

    Recognize translated mv-lets after pre-translation.

    Signature
    (atj-check-marked-annotated-mv-let-call term) 
      → 
    (mv yes/no mv-var mv-term vars indices body-term)
    Arguments
    term — Guard (pseudo-termp term).
    Returns
    yes/no — Type (booleanp yes/no).
    mv-var — Type (symbolp mv-var).
    mv-term — Type (pseudo-termp mv-term).
    vars — Type (symbol-listp vars).
    indices — Type (nat-listp indices).
    body-term — Type (pseudo-termp body-term).

    The type annotation pre-translation step recognizes mv-lets and transforms them as explained in atj-type-annotate-term. the variable reuse pre-translation step additionally marks the variables, and the variable renaming pre-translation step may change their (unmarked, unannotated) names. So the resulting term should have the form

    ([reqinf>reqinf]
     ((lambda ([m][types]mv)
              ([reqinf>reqinf]
               ((lambda ([m1][type1]var1 ... [mn][typen]varn)
                        ([...>reqinf] body-term))
                ([AV>type1] (mv-nth ([AI>AI] '0)
                                    ([types>types] [m][types]mv)))
                ...
                ([AV>typen] (mv-nth ([AI>AI] 'n-1)
                                    ([types>types] [m][types]mv))))))
      ([types>types] mv-term)))

    where [m], [m1], ..., [mn] are new/old markings, and where mv may not be the symbol `mv' but some other symbol. Because of the pre-translation steps that removes unused variables, the formals and arguments of the inner lambda may be fewer than the elements of types; i.e. some mv-nth indices may be skipped.

    This code recognizes terms of the form above, returning some of the constituents if successful. The mv-var result is [m][types]mv, i.e. the marked and annotated multi-value variable. The mv-term result is ([types>types] mv-term), i.e. the wrapped multi-value term. The vars result is ([m1][type1]var1 ... [mn][typen]varn) (possibly skipping some indices), i.e. the list of formals of the inner lambda expression, all marked and annotated. The indices result is the ordered list of mv-nth indices actually present; these are 0-based. The body-term result is ([...>reqinf] body-term), i.e. the wrapped body of the inner lambda expression. The term and variable results are marked/annotated/wrapped so that they can be treated uniformly by the code generation functions.

    Definitions and Theorems

    Function: atj-check-marked-annotated-mv-let-call-aux

    (defun atj-check-marked-annotated-mv-let-call-aux
           (args vars types mv-var)
     (declare (xargs :guard (and (pseudo-term-listp args)
                                 (symbol-listp vars)
                                 (atj-type-listp types)
                                 (symbolp mv-var))))
     (declare (xargs :guard (and (= (len vars) (len args))
                                 (consp types))))
     (let ((__function__ 'atj-check-marked-annotated-mv-let-call-aux))
      (declare (ignorable __function__))
      (b*
       (((when (endp args)) nil)
        ((mv arg arg-src arg-dst)
         (atj-type-unwrap-term (car args)))
        ((unless (and (not (variablep arg))
                      (not (fquotep arg))
                      (eq (ffn-symb arg) 'mv-nth)
                      (= (len (fargs arg)) 2)
                      (equal (fargn arg 2)
                             (atj-type-wrap-term mv-var types types))))
         (raise "Internal error: malformed term ~x0."
                (car args))
         (repeat (len args) 0))
        ((mv index index-src index-dst)
         (atj-type-unwrap-term (fargn arg 1)))
        ((unless
              (and (quotep index)
                   (equal index-src
                          (list (atj-type-acl2 (atj-atype-integer))))
                   (equal index-dst
                          (list (atj-type-acl2 (atj-atype-integer))))))
         (raise "Internal error: malformed term ~x0."
                (car args))
         (repeat (len args) 0))
        (index (unquote-term index))
        ((unless (integer-range-p 0 (len types) index))
         (raise "Internal error: malformed term ~x0."
                (car args))
         (repeat (len args) 0))
        ((unless (and (equal arg-src
                             (list (atj-type-acl2 (atj-atype-value))))
                      (equal arg-dst (list (nth index types)))))
         (raise "Internal error: malformed term ~x0."
                (car args))
         (repeat (len args) 0))
        ((mv var &) (atj-unmark-var (car vars)))
        ((mv & var-types)
         (atj-type-unannotate-var var))
        ((unless (equal var-types (list (nth index types))))
         (raise "Internal error: malformed term ~x0."
                (car args))
         (repeat (len args) 0)))
       (cons
           index
           (atj-check-marked-annotated-mv-let-call-aux (cdr args)
                                                       (cdr vars)
                                                       types mv-var)))))

    Theorem: nat-listp-of-atj-check-marked-annotated-mv-let-call-aux

    (defthm nat-listp-of-atj-check-marked-annotated-mv-let-call-aux
      (b* ((indices (atj-check-marked-annotated-mv-let-call-aux
                         args vars types mv-var)))
        (nat-listp indices))
      :rule-classes :rewrite)

    Theorem: len-of-atj-check-marked-annotated-mv-let-call-aux

    (defthm len-of-atj-check-marked-annotated-mv-let-call-aux
      (b* ((?indices (atj-check-marked-annotated-mv-let-call-aux
                          args vars types mv-var)))
        (equal (len indices) (len args))))

    Function: atj-check-marked-annotated-mv-let-call

    (defun atj-check-marked-annotated-mv-let-call (term)
      (declare (xargs :guard (pseudo-termp term)))
      (let ((__function__ 'atj-check-marked-annotated-mv-let-call))
        (declare (ignorable __function__))
        (b* (((mv outer-lambda-call reqinf reqinf2)
              (atj-type-unwrap-term term))
             ((unless (equal reqinf reqinf2))
              (mv nil nil nil nil nil nil))
             ((mv okp mv-var
                  wrapped-inner-lambda-call mv-term)
              (check-unary-lambda-call outer-lambda-call))
             ((unless okp)
              (mv nil nil nil nil nil nil))
             ((mv mv-var-unmarked &)
              (atj-unmark-var mv-var))
             ((mv & types)
              (atj-type-unannotate-var mv-var-unmarked))
             ((unless (> (len types) 1))
              (mv nil nil nil nil nil nil))
             ((mv & src-types dst-types)
              (atj-type-unwrap-term mv-term))
             ((unless (and (equal src-types types)
                           (equal dst-types types)))
              (raise "Internal error: malformed term ~x0."
                     term)
              (mv nil nil nil nil nil nil))
             ((mv inner-lambda-call src-types dst-types)
              (atj-type-unwrap-term wrapped-inner-lambda-call))
             ((unless (and (equal src-types reqinf)
                           (equal dst-types reqinf)))
              (mv nil nil nil nil nil nil))
             ((mv okp vars body-term args)
              (check-lambda-call inner-lambda-call))
             ((unless okp)
              (raise "Internal error: malformed term ~x0."
                     term)
              (mv nil nil nil nil nil nil))
             ((mv & & dst-types)
              (atj-type-unwrap-term body-term))
             ((unless (equal dst-types reqinf))
              (raise "Internal error: malformed term ~x0."
                     term)
              (mv nil nil nil nil nil nil))
             (indices (atj-check-marked-annotated-mv-let-call-aux
                           args vars types mv-var)))
          (mv t mv-var
              mv-term vars indices body-term))))

    Theorem: booleanp-of-atj-check-marked-annotated-mv-let-call.yes/no

    (defthm booleanp-of-atj-check-marked-annotated-mv-let-call.yes/no
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (booleanp yes/no))
      :rule-classes :rewrite)

    Theorem: symbolp-of-atj-check-marked-annotated-mv-let-call.mv-var

    (defthm symbolp-of-atj-check-marked-annotated-mv-let-call.mv-var
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (symbolp mv-var))
      :rule-classes :rewrite)

    Theorem: pseudo-termp-of-atj-check-marked-annotated-mv-let-call.mv-term

    (defthm
         pseudo-termp-of-atj-check-marked-annotated-mv-let-call.mv-term
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (pseudo-termp mv-term))
      :rule-classes :rewrite)

    Theorem: symbol-listp-of-atj-check-marked-annotated-mv-let-call.vars

    (defthm symbol-listp-of-atj-check-marked-annotated-mv-let-call.vars
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (symbol-listp vars))
      :rule-classes :rewrite)

    Theorem: nat-listp-of-atj-check-marked-annotated-mv-let-call.indices

    (defthm nat-listp-of-atj-check-marked-annotated-mv-let-call.indices
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (nat-listp indices))
      :rule-classes :rewrite)

    Theorem: pseudo-termp-of-atj-check-marked-annotated-mv-let-call.body-term

    (defthm
       pseudo-termp-of-atj-check-marked-annotated-mv-let-call.body-term
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (pseudo-termp body-term))
      :rule-classes :rewrite)

    Theorem: len-of-atj-check-marked-annotated-mv-let.vars/indices

    (defthm len-of-atj-check-marked-annotated-mv-let.vars/indices
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (equal (len indices) (len vars))))

    Theorem: atj-check-marked-annotated-mv-let-mv-term-smaller

    (defthm atj-check-marked-annotated-mv-let-mv-term-smaller
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (implies yes/no
                 (< (acl2-count mv-term)
                    (acl2-count term))))
      :rule-classes :linear)

    Theorem: atj-check-marked-annotated-mv-let-body-term-smaller

    (defthm atj-check-marked-annotated-mv-let-body-term-smaller
      (b* (((mv ?yes/no ?mv-var
                ?mv-term ?vars ?indices ?body-term)
            (atj-check-marked-annotated-mv-let-call term)))
        (implies yes/no
                 (< (acl2-count body-term)
                    (acl2-count term))))
      :rule-classes :linear)