• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Hons-and-memoization
      • Events
      • History
      • Parallelism
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Memoize
        • Mbe
        • Io
        • Apply$
        • Defpkg
        • Mutual-recursion
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Loop$-primer
        • Fast-alists
        • Defmacro
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Irrelevant-formals
        • Efficiency
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
        • Program-wrapper
        • Get-internal-time
        • Basics
        • Packages
        • Defmacro-untouchable
        • Primitive
        • <<
        • Revert-world
        • Set-duplicate-keys-action
        • Unmemoize
        • Symbols
        • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Defopen
          • Sleep
        • Start-here
        • Real
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Programming

    Def-list-constructor

    Define function that constructs a list, just by giving the length and how to compute the Nth element in terms of the formals and index.

    This takes many of the same arguments as defiteration, and in fact it uses defiteration. But instead of giving the step function for the iteration, you give the value of the Nth element of the list. You must also provide the keyword :last, giving the length of the list.

    What you end up with is your top-level function, definition disabled, and four rules:

    • nth-of-fnname tells what the Nth element is, for N in bounds
    • nth-of-fnname-split (disabled), tells what the Nth element is, causing a case-split on whether it's in bounds or not
    • len-of-fnname: gives the length of the list
    • true-listp-of-fnname shows that the list is true-listp.

    See centaur/misc/equal-by-nths for a strategy that proves equivalences between lists based on length and Nth value.

    Syntax:

    (def-list-constructor foo (x y)
      "optional doc string"
      (declare (xargs ...))   ;; optional declare forms
      (+ idx-var x y)         ;; value of the IDX-VARth element
      :length  (bar x y)      ;; final index
      :index idx-var          ;; counter variable, default N
      ... defiteration args ...)