• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defconst
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
          • Member
          • Append
          • List
          • Nth
          • Len
          • True-listp
          • String-listp
          • Nat-listp
          • Character-listp
          • Symbol-listp
          • True-list-listp
          • Length
          • Search
          • Intersection$
          • Union$
          • Remove-duplicates
          • Position
          • Update-nth
          • Take
          • Set-difference$
          • Nthcdr
          • Subsetp
          • No-duplicatesp
          • Concatenate
          • Remove
          • Remove1
          • Intersectp
          • Endp
          • Keyword-value-listp
          • Integer-listp
          • Reverse
          • Add-to-set
          • List-utilities
          • Set-size
          • Revappend
          • Subseq
          • Make-list
            • Repeat
              • Take-of-too-many
              • Make-list-ac-removal
              • Replicate
            • Make-list-ac-removal
            • Hons-make-list
          • Lists-light
          • Boolean-listp
          • Butlast
          • Pairlis$
          • Substitute
          • Count
          • Keyword-listp
          • List*
          • Last
          • Eqlable-listp
          • Pos-listp
          • Integer-range-listp
          • Rational-listp
          • Evens
          • Atom-listp
          • ACL2-number-listp
          • Typed-list-utilities
          • Odds
          • List$
          • Listp
          • 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
        • Oracle-eval
        • Defmacro-untouchable
        • <<
        • Primitive
        • Revert-world
        • Unmemoize
        • Set-duplicate-keys-action
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Fake-oracle-eval
        • Defopen
        • Sleep
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Std/lists
  • Make-list

Repeat

(repeat n x) creates a list of xes with length n; it is a simpler alternative to make-list.

Definitions and Theorems

Function: repeat

(defun repeat (n x)
  (declare (xargs :guard (natp n)))
  (mbe :logic
       (if (zp n)
           nil
         (cons x (repeat (- n 1) x)))
       :exec (make-list n :initial-element x)))

Theorem: repeat-when-zp

(defthm repeat-when-zp
  (implies (zp n)
           (equal (repeat n a) nil)))

Theorem: (repeat 0 x)

(defthm |(repeat 0 x)|
  (equal (repeat 0 x) nil))

Theorem: repeat-under-iff

(defthm repeat-under-iff
  (iff (repeat n x) (not (zp n))))

Theorem: consp-of-repeat

(defthm consp-of-repeat
  (equal (consp (repeat n a))
         (not (zp n))))

Theorem: repeat-1

(defthm repeat-1
  (equal (repeat 1 a) (list a)))

Theorem: take-when-atom

(defthm take-when-atom
  (implies (atom x)
           (equal (take n x) (repeat n nil))))

Theorem: len-of-repeat

(defthm len-of-repeat
  (equal (len (repeat n x)) (nfix n)))

Theorem: repeat-of-nfix

(defthm repeat-of-nfix
  (equal (repeat (nfix n) x)
         (repeat n x)))

Theorem: car-of-repeat-increment

(defthm car-of-repeat-increment
  (implies (natp n)
           (equal (car (repeat (+ 1 n) x)) x)))

Theorem: cdr-of-repeat-increment

(defthm cdr-of-repeat-increment
  (implies (natp n)
           (equal (cdr (repeat (+ 1 n) x))
                  (repeat n x))))

Theorem: member-of-repeat

(defthm member-of-repeat
  (equal (member a (repeat n b))
         (if (equal a b) (repeat n b) nil)))

Theorem: take-of-repeat

(defthm take-of-repeat
  (equal (take n (repeat k a))
         (if (<= (nfix n) (nfix k))
             (repeat n a)
           (append (repeat k a)
                   (repeat (- (nfix n) (nfix k)) nil)))))

Theorem: nthcdr-of-repeat

(defthm nthcdr-of-repeat
  (equal (nthcdr n (repeat k a))
         (if (<= (nfix n) (nfix k))
             (repeat (- (nfix k) (nfix n)) a)
           nil)))

Theorem: append-of-repeat-to-cons-of-same

(defthm append-of-repeat-to-cons-of-same
  (equal (append (repeat n a) (cons a x))
         (cons a (append (repeat n a) x))))

Theorem: equal-of-append-repeat

(defthm equal-of-append-repeat
  (implies (case-split (<= n (len y)))
           (equal (equal (append (repeat n a) x) y)
                  (and (equal (repeat n a) (take n y))
                       (equal x (nthcdr n y))))))

Theorem: rev-of-repeat

(defthm rev-of-repeat
  (equal (rev (repeat n a)) (repeat n a)))

Theorem: subsetp-of-repeat

(defthm subsetp-of-repeat
  (iff (subsetp-equal (repeat n x) y)
       (or (zp n) (member-equal x y))))

Theorem: element-list-p-of-repeat

(defthm element-list-p-of-repeat
  (iff (element-list-p (repeat n x))
       (or (element-p x) (zp n)))
  :rule-classes :rewrite)

Subtopics

Take-of-too-many
Rewrite (take n x) when n is more than (len x).
Make-list-ac-removal
Rewrite rule that eliminates make-list-ac (and hence make-list) in favor of repeat.
Replicate
Alias for repeat.