• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • 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
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Leftist-trees
        • Java
        • Taspi
        • Bitcoin
        • Riscv
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • 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)