• 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

    Check-function-specifier

    Check if a function specifier is statically well-formed.

    Signature
    (check-function-specifier spec inputs/outputs ctxt) 
      → 
    (mv err? obligs)
    Arguments
    spec — Guard (function-specifierp spec).
    inputs/outputs — Guard (typed-variable-listp inputs/outputs).
    ctxt — Guard (contextp ctxt).
    Returns
    obligs — Type (proof-obligation-listp obligs).

    When checking a function specifier, the context has no types being defined, no variables in scope, and no obligation variable and hypotheses, but there may be function headers: Ttese all come from the function specification that this specifier is contained in.

    The inputs/outputs parameter of this ACL2 function is non-nil only when the specifier is an input/output one: it consists of the inputs and output of the function header (there must be exactly one) of the enclosing function specification.

    A specification is a predicate, so the body must be always boolean-valued.

    For a regular function specifier, we simply check the body and ensure it is a boolean. The use of this kind of function specifier seems quite limited, because there are no ordinary (not function) variables in scope: it points to the fact that we'll need to extend Syntheto with more general second-order functions (still representable in ACL2's first-order logic, e.g. via SOFT).

    For a quantifier function specifier, we augment the context with the bound variables and we check the matrix ensuring it is a boolean.

    For an input/output function specifier, we augment the context with the input/output variables and we check the relation ensuring it is a boolean.

    Definitions and Theorems

    Function: check-function-specifier

    (defun check-function-specifier (spec inputs/outputs ctxt)
     (declare (xargs :guard (and (function-specifierp spec)
                                 (typed-variable-listp inputs/outputs)
                                 (contextp ctxt))))
     (declare
          (xargs :guard (and (null (context->types ctxt))
                             (omap::emptyp (context->variables ctxt))
                             (null (context->obligation-vars ctxt))
                             (null (context->obligation-hyps ctxt)))))
     (let ((__function__ 'check-function-specifier))
      (declare (ignorable __function__))
      (function-specifier-case
       spec :regular
       (b* ((result (check-expression spec.body ctxt)))
        (type-result-case
             result :err (mv result.info nil)
             :ok
             (if (type-list-equiv result.types (list (type-boolean)))
                 (mv nil result.obligations)
               (mv (list :non-boolean-function-specifier-body spec.body)
                   nil))))
       :quantified
       (b* ((bound-var-ctxt
                 (typed-variables-to-variable-context spec.variables))
            (ctxt (context-add-variables bound-var-ctxt ctxt))
            (result (check-expression spec.matrix ctxt)))
        (type-result-case
         result :err (mv result.info nil)
         :ok
         (if (type-list-equiv result.types (list (type-boolean)))
             (mv nil result.obligations)
           (mv (list :non-boolean-function-specifier-matrix spec.matrix)
               nil))))
       :input-output
       (b* ((io-var-ctxt
                 (typed-variables-to-variable-context inputs/outputs))
            (ctxt (context-add-variables io-var-ctxt ctxt))
            (ctxt (change-context ctxt
                                  :obligation-vars inputs/outputs))
            (result (check-expression spec.relation ctxt)))
        (type-result-case
         result :err (mv result.info nil)
         :ok
         (if (type-list-equiv result.types (list (type-boolean)))
             (mv nil result.obligations)
          (mv
           (list :non-boolean-function-specifier-relation spec.relation)
           nil)))))))

    Theorem: proof-obligation-listp-of-check-function-specifier.obligs

    (defthm proof-obligation-listp-of-check-function-specifier.obligs
      (b* (((mv ?err? ?obligs)
            (check-function-specifier spec inputs/outputs ctxt)))
        (proof-obligation-listp obligs))
      :rule-classes :rewrite)

    Theorem: check-function-specifier-of-function-specifier-fix-spec

    (defthm check-function-specifier-of-function-specifier-fix-spec
      (equal (check-function-specifier (function-specifier-fix spec)
                                       inputs/outputs ctxt)
             (check-function-specifier spec inputs/outputs ctxt)))

    Theorem: check-function-specifier-function-specifier-equiv-congruence-on-spec

    (defthm
     check-function-specifier-function-specifier-equiv-congruence-on-spec
     (implies
      (function-specifier-equiv spec spec-equiv)
      (equal (check-function-specifier spec inputs/outputs ctxt)
             (check-function-specifier spec-equiv inputs/outputs ctxt)))
     :rule-classes :congruence)

    Theorem: check-function-specifier-of-typed-variable-list-fix-inputs/outputs

    (defthm
     check-function-specifier-of-typed-variable-list-fix-inputs/outputs
     (equal
      (check-function-specifier spec
                                (typed-variable-list-fix inputs/outputs)
                                ctxt)
      (check-function-specifier spec inputs/outputs ctxt)))

    Theorem: check-function-specifier-typed-variable-list-equiv-congruence-on-inputs/outputs

    (defthm
     check-function-specifier-typed-variable-list-equiv-congruence-on-inputs/outputs
     (implies
      (typed-variable-list-equiv inputs/outputs inputs/outputs-equiv)
      (equal (check-function-specifier spec inputs/outputs ctxt)
             (check-function-specifier spec inputs/outputs-equiv ctxt)))
     :rule-classes :congruence)

    Theorem: check-function-specifier-of-context-fix-ctxt

    (defthm check-function-specifier-of-context-fix-ctxt
     (equal
       (check-function-specifier spec inputs/outputs (context-fix ctxt))
       (check-function-specifier spec inputs/outputs ctxt)))

    Theorem: check-function-specifier-context-equiv-congruence-on-ctxt

    (defthm check-function-specifier-context-equiv-congruence-on-ctxt
     (implies
      (context-equiv ctxt ctxt-equiv)
      (equal (check-function-specifier spec inputs/outputs ctxt)
             (check-function-specifier spec inputs/outputs ctxt-equiv)))
     :rule-classes :congruence)