• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • 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
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
          • Process-syntheto-toplevel-fn
          • Translation
          • Language
            • Static-semantics
              • Check-expression-fns
              • Subtypep
              • Match-type
              • Check-product-update-expression
              • Get-builtin-function-in/out/pre-post
              • Check-sum-update-expression
              • Check-sum-field-expression
              • Check-strict-binary-expression
              • Check-lt/le/gt/ge-expression
              • Check-eq/ne-expression
              • Check-div/rem-expression
              • Check-add/sub/mul-expression
              • Align-let-vars-values
              • Check-iff-expression
              • Check-function-definition-top/nontop
              • Check-sum-construct-expression
              • Check-rem-expression
              • Check-mul-expression
              • Check-sub-expression
              • Check-div-expression
              • Check-add-expression
              • Check-ne-expression
              • Check-lt-expression
              • Check-le-expression
              • Check-gt-expression
              • Check-ge-expression
              • Check-eq-expression
              • Check-function-specifier
              • Type-result
              • Check-product-construct-expression
              • Supremum-type
              • Check-call-expression
              • Check-product-field-expression
              • Check-function-definer
              • Make-subproof-obligations
              • Get-function-in/out/pre/post
              • Check-sum-test-expression
              • Match-field
                • Decompose-expression
                • Match-to-target
                • Check-unary-expression
                • Max-supertype
                • Match-type-list
                • Check-minus-expression
                • Check-type-definition
                • Check-not-expression
                • Check-type-product
                • Match-field-list
                • Check-type-subset
                • Check-type-definition-in-recursion
                • Align-let-vars-values-aux
                • Non-trivial-proof-obligation
                • Check-type-recursion
                • Check-function-specification
                • Check-toplevel
                • Supremum-type-list
                • Check-component-expression
                • Check-branch-list
                • Check-function-recursion
                • Check-function-definition
                • Binding
                • Check-function-header
                • Check-function-definition-list
                • Check-type-definition-list-in-recursion
                • Check-theorem
                • Check-nonstrict-binary-expression
                • Context-add-variables
                • Decompose-expression-aux
                • Check-alternative
                • Check-multi-expression
                • Check-type-sum
                • Check-type
                • Check-alternative-list
                • Context-add-condition
                • Check-type-definer
                • Check-transform
                • Check-variable
                • Check-transform-args
                • Check-toplevel-list
                • Context-add-condition-list
                • Check-if/when/unless-expression
                • Initializers-to-variable-substitution
                • Context-add-binding
                • Check-function-header-list
                • Context-add-toplevel
                • Ensure-single-type
                • Max-supertypes
                • Check-bind-expression
                • Check-type-list
                • Check-literal
                • Literal-type
                • Check-expression-list
                • Variable-context
                • Check-cond-expression
                • Check-branch
                • Args-without-defaults
                • Check-expression
                • *builtin-function-names*
                • Function-called-in
              • Abstract-syntax
              • Outcome
              • Abstract-syntax-operations
              • Outcome-list
              • Outcomes
            • Process-syntheto-toplevel
            • Shallow-embedding
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Static-semantics

    Match-field

    Match a source field to some target field.

    Signature
    (match-field init source targets ctxt) 
      → 
    (mv yes/no obligs rest-targets)
    Arguments
    init — Guard (initializerp init).
    source — Guard (typep source).
    targets — Guard (field-listp targets).
    ctxt — Guard (contextp ctxt).
    Returns
    yes/no — Type (booleanp yes/no).
    obligs — Type (proof-obligation-listp obligs).
    rest-targets — Type (field-listp rest-targets).

    This is used when checking the static semantics of initializers in product/sum constructions and updates: each initializer in such expressions (the init input) with its own calculated type (the type input), must correspond to a field in the product or sum type (one in the targets input). Thus, we look for a field, with the same name as the initializer, in the target fields; if it is not found, it is an error; if it is found, we match the types and remove the target field from further consideration, by returning a list of the remaining fields. This function is called repeatedly by match-field-list.

    Definitions and Theorems

    Function: match-field

    (defun match-field (init source targets ctxt)
      (declare (xargs :guard (and (initializerp init)
                                  (typep source)
                                  (field-listp targets)
                                  (contextp ctxt))))
      (let ((__function__ 'match-field))
        (declare (ignorable __function__))
        (b* (((when (endp targets)) (mv nil nil nil))
             (target (field-fix (car targets)))
             ((when (not (equal (field->name target)
                                (initializer->field init))))
              (b* (((mv okp obligs rest-targets)
                    (match-field init source (cdr targets)
                                 ctxt))
                   ((when (not okp)) (mv nil nil nil)))
                (mv t obligs (cons target rest-targets))))
             ((mv okp obligs)
              (match-type (initializer->value init)
                          source (field->type target)
                          ctxt))
             ((when (not okp)) (mv nil nil nil)))
          (mv t obligs
              (field-list-fix (cdr targets))))))

    Theorem: booleanp-of-match-field.yes/no

    (defthm booleanp-of-match-field.yes/no
      (b* (((mv ?yes/no ?obligs ?rest-targets)
            (match-field init source targets ctxt)))
        (booleanp yes/no))
      :rule-classes :rewrite)

    Theorem: proof-obligation-listp-of-match-field.obligs

    (defthm proof-obligation-listp-of-match-field.obligs
      (b* (((mv ?yes/no ?obligs ?rest-targets)
            (match-field init source targets ctxt)))
        (proof-obligation-listp obligs))
      :rule-classes :rewrite)

    Theorem: field-listp-of-match-field.rest-targets

    (defthm field-listp-of-match-field.rest-targets
      (b* (((mv ?yes/no ?obligs ?rest-targets)
            (match-field init source targets ctxt)))
        (field-listp rest-targets))
      :rule-classes :rewrite)

    Theorem: match-field-of-initializer-fix-init

    (defthm match-field-of-initializer-fix-init
      (equal (match-field (initializer-fix init)
                          source targets ctxt)
             (match-field init source targets ctxt)))

    Theorem: match-field-initializer-equiv-congruence-on-init

    (defthm match-field-initializer-equiv-congruence-on-init
      (implies (initializer-equiv init init-equiv)
               (equal (match-field init source targets ctxt)
                      (match-field init-equiv source targets ctxt)))
      :rule-classes :congruence)

    Theorem: match-field-of-type-fix-source

    (defthm match-field-of-type-fix-source
      (equal (match-field init (type-fix source)
                          targets ctxt)
             (match-field init source targets ctxt)))

    Theorem: match-field-type-equiv-congruence-on-source

    (defthm match-field-type-equiv-congruence-on-source
      (implies (type-equiv source source-equiv)
               (equal (match-field init source targets ctxt)
                      (match-field init source-equiv targets ctxt)))
      :rule-classes :congruence)

    Theorem: match-field-of-field-list-fix-targets

    (defthm match-field-of-field-list-fix-targets
      (equal (match-field init source (field-list-fix targets)
                          ctxt)
             (match-field init source targets ctxt)))

    Theorem: match-field-field-list-equiv-congruence-on-targets

    (defthm match-field-field-list-equiv-congruence-on-targets
      (implies (field-list-equiv targets targets-equiv)
               (equal (match-field init source targets ctxt)
                      (match-field init source targets-equiv ctxt)))
      :rule-classes :congruence)

    Theorem: match-field-of-context-fix-ctxt

    (defthm match-field-of-context-fix-ctxt
      (equal (match-field init source targets (context-fix ctxt))
             (match-field init source targets ctxt)))

    Theorem: match-field-context-equiv-congruence-on-ctxt

    (defthm match-field-context-equiv-congruence-on-ctxt
      (implies (context-equiv ctxt ctxt-equiv)
               (equal (match-field init source targets ctxt)
                      (match-field init source targets ctxt-equiv)))
      :rule-classes :congruence)