• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • 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
        • Defpkg
        • Apply$
        • 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
          • Member
          • Append
          • Nth
          • List
          • Len
          • True-listp
            • True-list-listp
            • List-fix
            • True-list-fix
              • The-true-list
              • Std/lists/true-listp
            • Symbol-listp
            • String-listp
            • Nat-listp
            • Character-listp
            • True-list-listp
            • Length
            • Search
            • Intersection$
            • Union$
            • Remove-duplicates
            • Position
            • Take
            • Update-nth
            • Set-difference$
            • Subsetp
            • No-duplicatesp
            • Concatenate
            • Remove
            • Nthcdr
            • Remove1
            • Intersectp
            • Endp
            • Keyword-value-listp
            • Reverse
            • List-utilities
            • Add-to-set
            • Set-size
            • Integer-listp
            • Revappend
            • Subseq
            • Make-list
            • Lists-light
            • Butlast
            • Pairlis$
            • Substitute
            • Count
            • Boolean-listp
            • List*
            • Keyword-listp
            • Eqlable-listp
            • Last
            • Integer-range-listp
            • Pos-listp
            • Rational-listp
            • Evens
            • Atom-listp
            • ACL2-number-listp
            • Good-atom-listp
            • Typed-list-utilities
            • Listp
            • Odds
            • Standard-char-listp
            • Last-cdr
            • Pairlis
            • Proper-consp
            • Improper-consp
            • Pairlis-x2
            • Pairlis-x1
            • Merge-sort-lexorder
            • Fix-true-list
            • Real-listp
          • 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
    • True-listp
    • ACL2-built-ins

    True-list-fix

    Coerce to a true list

    Many functions that process lists follows the true-list-fix convention: whenever f is given some non-true-listp x where it expected a list, that is, some x with a non-nil final-cdr, it will act as though it had been given (true-list-fix x) instead. As a few examples, logically,

    • (endp x) ignores the final cdr of x
    • (len x) ignores the final cdr of x
    • (append x y) ignores the final cdr of x (but not y)
    • (member a x) ignores the final cdr of x

    True-list-fix is often useful when writing theorems about how list-processing functions behave. For example, it allows us to write strong, hypothesis-free theorems such as:

    (equal (character-listp (append x y))
           (and (character-listp (true-list-fix x))
                (character-listp y)))

    Indeed, true-list-fix is the basis for list-equiv, an extremely common equivalence relation.

    Efficiency note. In practice, most lists are nil-terminated. As an optimization, true-list-fix tries to avoid any consing by first checking whether its argument is a true-listp, and, in that case, it simply returns its argument unchanged.

    For a logically equivalent utility that returns its argument unchanged (with no checking) during normal evaluation, see the-true-list.

    Function: true-list-fix-exec

    (defun true-list-fix-exec (x)
           (declare (xargs :guard t))
           (if (consp x)
               (cons (car x)
                     (true-list-fix-exec (cdr x)))
               nil))

    Function: true-list-fix

    (defun true-list-fix (x)
           (declare (xargs :guard t))
           (mbe :logic (if (consp x)
                           (cons (car x) (true-list-fix (cdr x)))
                           nil)
                :exec (if (true-listp x)
                          x (true-list-fix-exec x))))