• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
        • Std/lists/abstract
        • Rev
        • Defsort
        • List-fix
        • Std/lists/nth
        • Hons-remove-duplicates
        • Std/lists/update-nth
        • Set-equiv
        • Duplicity
        • Prefixp
        • Std/lists/take
        • Std/lists/intersection$
        • Nats-equiv
        • Repeat
        • Index-of
        • All-equalp
        • Sublistp
        • Std/lists/nthcdr
        • Listpos
        • List-equiv
        • Final-cdr
        • Std/lists/append
        • Std/lists/remove
        • Subseq-list
        • Rcons
        • Std/lists/revappend
        • Std/lists/remove-duplicates-equal
        • Std/lists/reverse
        • Std/lists/last
        • Std/lists/resize-list
        • Flatten
        • Suffixp
        • Std/lists/butlast
        • Std/lists/set-difference
        • Std/lists/len
        • Std/lists/intersectp
        • Std/lists/true-listp
        • Intersectp-witness
        • Subsetp-witness
        • Std/lists/remove1-equal
        • Rest-n
        • First-n
          • Std/lists/union
          • Std/lists/add-to-set
          • Append-without-guard
          • Std/lists/subsetp
          • Std/lists/member
        • Std/alists
        • Obags
        • Std/util
        • Std/strings
        • Std/osets
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Std/lists
    • Take

    First-n

    (first-n n x) is logically identical to (take n x), but its guard does not require (true-listp x).

    Reasoning Note. We leave first-n enabled, so it will just get rewritten into take. You should typically never write a theorem about first-n: write theorems about take instead.

    Definitions and Theorems

    Function: first-n

    (defun first-n (n x)
      (declare (xargs :guard (natp n)))
      (mbe :logic (take n x)
           :exec (cond ((zp n) nil)
                       ((atom x) (make-list n))
                       (t (cons (car x)
                                (first-n (- n 1) (cdr x)))))))