• 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
          • Syntax-for-tools
          • Atc
          • Language
            • Abstract-syntax
            • Integer-ranges
            • Implementation-environments
            • Dynamic-semantics
            • Static-semantics
            • Grammar
            • Integer-formats
            • Types
            • Portable-ascii-identifiers
            • Values
            • Integer-operations
            • Computation-states
            • Object-designators
            • Operations
            • Errors
            • Tag-environments
            • Function-environments
            • Character-sets
            • Flexible-array-member-removal
            • Arithmetic-operations
            • Pointer-operations
            • Bytes
            • Keywords
            • Real-operations
            • Array-operations
              • Value-array-write
              • Value-array-read
                • Value-array->length
              • Scalar-operations
              • Structure-operations
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Array-operations

    Value-array-read

    Read an element from an array.

    Signature
    (value-array-read index array) → elem
    Arguments
    index — Guard (natp index).
    array — Guard (valuep array).
    Returns
    elem — Type (value-resultp elem).

    If the index is too large, it is an error.

    Definitions and Theorems

    Function: value-array-read

    (defun value-array-read (index array)
      (declare (xargs :guard (and (natp index) (valuep array))))
      (declare (xargs :guard (value-case array :array)))
      (let ((__function__ 'value-array-read))
        (declare (ignorable __function__))
        (b* ((index (nfix index))
             ((unless (< index (value-array->length array)))
              (error (list :array-read-index
                           index (value-fix array)))))
          (nth index (value-array->elements array)))))

    Theorem: value-resultp-of-value-array-read

    (defthm value-resultp-of-value-array-read
      (b* ((elem (value-array-read index array)))
        (value-resultp elem))
      :rule-classes :rewrite)

    Theorem: value-array-read-of-nfix-index

    (defthm value-array-read-of-nfix-index
      (equal (value-array-read (nfix index) array)
             (value-array-read index array)))

    Theorem: value-array-read-nat-equiv-congruence-on-index

    (defthm value-array-read-nat-equiv-congruence-on-index
      (implies (acl2::nat-equiv index index-equiv)
               (equal (value-array-read index array)
                      (value-array-read index-equiv array)))
      :rule-classes :congruence)

    Theorem: value-array-read-of-value-fix-array

    (defthm value-array-read-of-value-fix-array
      (equal (value-array-read index (value-fix array))
             (value-array-read index array)))

    Theorem: value-array-read-value-equiv-congruence-on-array

    (defthm value-array-read-value-equiv-congruence-on-array
      (implies (value-equiv array array-equiv)
               (equal (value-array-read index array)
                      (value-array-read index array-equiv)))
      :rule-classes :congruence)