• 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
      • 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
        • Aleobft
          • Aleobft-static
            • Correctness
            • Definition
              • Transitions
              • Operations
                • Operations-author-round-pairs
                • Operations-faults-and-quora
                • Operations-leaders
                  • Leader-index
                  • Nth-address
                    • Leader-at-round
                  • Operations-previous-certificates
                  • Operations-dags
                  • Operations-blockchain
                  • Operations-voting
                  • Operations-message-creation
                • States
                • Initialization
                • Events
            • Aleobft-dynamic
            • Aleobft-arxiv
            • Aleobft-stake
            • Aleobft-proposals
            • Library-extensions
          • Leo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Operations-leaders

    Nth-address

    The address at a given index in a set of addresses.

    Signature
    (nth-address index addrs) → addr
    Arguments
    index — Guard (natp index).
    addrs — Guard (address-setp addrs).
    Returns
    addr — Type (addressp addr).

    ACL2 osets are ordered sets, according to ACL2's total order on values, and so they can be treated as lists (without repetitions); in fact, that is exactly how they are represented. In particular, it makes sense to retrieve the element of a set that occupies a given position in the sequential order. As in lists, we index the positions starting from 0.

    This could be a more general operation on sets. Another option could be simply to use nth, since osets are lists.

    Definitions and Theorems

    Function: nth-address

    (defun nth-address (index addrs)
      (declare (xargs :guard (and (natp index)
                                  (address-setp addrs))))
      (declare (xargs :guard (< index (cardinality addrs))))
      (let ((__function__ 'nth-address))
        (declare (ignorable __function__))
        (cond ((emptyp addrs)
               (prog2$ (impossible)
                       (address :irrelevant)))
              ((zp index) (address-fix (head addrs)))
              (t (nth-address (1- index)
                              (tail addrs))))))

    Theorem: addressp-of-nth-address

    (defthm addressp-of-nth-address
      (b* ((addr (nth-address index addrs)))
        (addressp addr))
      :rule-classes :rewrite)