• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • C
      • Proof-checker-array
      • Soft
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Ethereum
      • Leftist-trees
      • Java
      • Riscv
      • Taspi
      • Bitcoin
      • Zcash
      • Des
      • X86isa
      • Sha-2
      • Yul
      • Proof-checker-itp13
      • Regex
      • ACL2-programming-language
      • Json
      • Jfkr
      • Equational
      • Cryptography
      • Axe
      • Poseidon
      • Where-do-i-place-my-book
      • Aleo
        • Aleobft
        • Aleovm
        • Leo
          • Grammar
          • Early-version
            • Json2ast
            • Testing
            • Definition
              • Flattening
              • Abstract-syntax
              • Dynamic-semantics
                • Execution
                  • Exec-expressions/statements
                  • Init-for-loop
                  • Exec-file-main
                  • Update-variable-value-in-scope-list
                  • Step-for-loop
                  • Update-variable-value-in-scope
                    • Expr-value-to-value
                    • Exec-binary
                    • Exec-expression
                    • Init-vcscope-dinfo-call
                    • Value?+denv
                    • Exec-statement
                    • End-of-for-loop-p
                    • Expr-value
                    • Evalue+denv
                    • Write-location
                    • Read-location
                    • Exec-for-loop-iterations
                    • Update-variable-value
                    • Exec-unary
                    • Values+denv
                    • Init-vcscope-dinfo-loop
                    • Extend-denv-with-structdecl
                    • Exec-var/const
                    • Valuemap+denv
                    • Namevalue+denv
                    • Extend-denv-with-fundecl
                    • Ensure-boolean
                    • Int+denv
                    • Push-vcscope-dinfo
                    • Extend-denv-with-topdecl-list
                    • Exec-literal
                    • Build-denv-from-file
                    • Namevalue+denv-result
                    • Extend-denv-with-topdecl
                    • Evalue+denv-result
                    • Value?+denv-result
                    • Values+denv-result
                    • Valuemap+denv-result
                    • Int+denv-result
                    • Push-call-dinfo
                    • Exec-print
                    • Pop-vcscope-dinfo
                    • Exec-if
                    • Exec-function
                    • Pop-call-dinfo
                    • Exec-statement-list
                    • Exec-block
                    • Exec-struct-init-list
                    • Exec-struct-init
                    • Exec-expression-list
                  • Values
                  • Dynamic-environments
                  • Arithmetic-operations
                  • Curve-parameterization
                  • Shift-operations
                  • Errors
                  • Value-expressions
                  • Locations
                  • Input-execution
                  • Edwards-bls12-generator
                  • Equality-operations
                  • Logical-operations
                  • Program-execution
                  • Ordering-operations
                  • Bitwise-operations
                  • Literal-evaluation
                  • Type-maps-for-struct-components
                  • Output-execution
                  • Tuple-operations
                  • Struct-operations
                • Compilation
                • Static-semantics
                • Concrete-syntax
        • Bigmems
        • Builtins
        • Execloader
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Community
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Execution

    Update-variable-value-in-scope

    Update the value in a variable in a scope.

    Signature
    (update-variable-value-in-scope var val scope) → new-scope
    Arguments
    var — Guard (identifierp var).
    val — Guard (valuep val).
    scope — Guard (vcscope-dinfop scope).
    Returns
    new-scope — Type (vcscope-dinfo-option-resultp new-scope).

    If a variable with the given name is in the scope and the new value has the same type as the old value, we overwrite the value and return the scope. If the types differ, we return an error. If a constant with the given name (instead of a variable) is in the scope, we return an error. If no variable or constant in the scope has the given name, we return no scope, but not an error: this just means that we must look in another scope.

    Definitions and Theorems

    Function: update-variable-value-in-scope

    (defun update-variable-value-in-scope (var val scope)
     (declare (xargs :guard (and (identifierp var)
                                 (valuep val)
                                 (vcscope-dinfop scope))))
     (let ((__function__ 'update-variable-value-in-scope))
      (declare (ignorable __function__))
      (b*
       ((info (get-var/const-dinfo-from-scope var scope))
        ((unless info)
         (vcscope-dinfo-option-none))
        ((var/const-dinfo info) info)
        ((when info.constp)
         (reserrf (list :update-constant-attempt (identifier-fix var))))
        ((unless (equal (type-of-value info.value)
                        (type-of-value val)))
         (reserrf (list :mismatch-value-update
                        (identifier-fix var)
                        info.value (value-fix val))))
        (new-info (change-var/const-dinfo info
                                          :value (value-fix val)))
        (new-scope (omap::update (identifier-fix var)
                                 new-info (vcscope-dinfo-fix scope))))
       (vcscope-dinfo-option-some new-scope))))

    Theorem: vcscope-dinfo-option-resultp-of-update-variable-value-in-scope

    (defthm
         vcscope-dinfo-option-resultp-of-update-variable-value-in-scope
      (b* ((new-scope (update-variable-value-in-scope var val scope)))
        (vcscope-dinfo-option-resultp new-scope))
      :rule-classes :rewrite)

    Theorem: update-variable-value-in-scope-of-identifier-fix-var

    (defthm update-variable-value-in-scope-of-identifier-fix-var
      (equal (update-variable-value-in-scope (identifier-fix var)
                                             val scope)
             (update-variable-value-in-scope var val scope)))

    Theorem: update-variable-value-in-scope-identifier-equiv-congruence-on-var

    (defthm
      update-variable-value-in-scope-identifier-equiv-congruence-on-var
      (implies
           (identifier-equiv var var-equiv)
           (equal (update-variable-value-in-scope var val scope)
                  (update-variable-value-in-scope var-equiv val scope)))
      :rule-classes :congruence)

    Theorem: update-variable-value-in-scope-of-value-fix-val

    (defthm update-variable-value-in-scope-of-value-fix-val
      (equal (update-variable-value-in-scope var (value-fix val)
                                             scope)
             (update-variable-value-in-scope var val scope)))

    Theorem: update-variable-value-in-scope-value-equiv-congruence-on-val

    (defthm update-variable-value-in-scope-value-equiv-congruence-on-val
      (implies
           (value-equiv val val-equiv)
           (equal (update-variable-value-in-scope var val scope)
                  (update-variable-value-in-scope var val-equiv scope)))
      :rule-classes :congruence)

    Theorem: update-variable-value-in-scope-of-vcscope-dinfo-fix-scope

    (defthm update-variable-value-in-scope-of-vcscope-dinfo-fix-scope
     (equal
      (update-variable-value-in-scope var val (vcscope-dinfo-fix scope))
      (update-variable-value-in-scope var val scope)))

    Theorem: update-variable-value-in-scope-vcscope-dinfo-equiv-congruence-on-scope

    (defthm
     update-variable-value-in-scope-vcscope-dinfo-equiv-congruence-on-scope
     (implies
          (vcscope-dinfo-equiv scope scope-equiv)
          (equal (update-variable-value-in-scope var val scope)
                 (update-variable-value-in-scope var val scope-equiv)))
     :rule-classes :congruence)