(repeat n x) creates a list of
Function:
(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:
(defthm repeat-when-zp (implies (zp n) (equal (repeat n a) nil)))
Theorem:
(defthm |(repeat 0 x)| (equal (repeat 0 x) nil))
Theorem:
(defthm repeat-under-iff (iff (repeat n x) (not (zp n))))
Theorem:
(defthm consp-of-repeat (equal (consp (repeat n a)) (not (zp n))))
Theorem:
(defthm repeat-1 (equal (repeat 1 a) (list a)))
Theorem:
(defthm take-when-atom (implies (atom x) (equal (take n x) (repeat n nil))))
Theorem:
(defthm len-of-repeat (equal (len (repeat n x)) (nfix n)))
Theorem:
(defthm repeat-of-nfix (equal (repeat (nfix n) x) (repeat n x)))
Theorem:
(defthm car-of-repeat-increment (implies (natp n) (equal (car (repeat (+ 1 n) x)) x)))
Theorem:
(defthm cdr-of-repeat-increment (implies (natp n) (equal (cdr (repeat (+ 1 n) x)) (repeat n x))))
Theorem:
(defthm member-of-repeat (equal (member a (repeat n b)) (if (equal a b) (repeat n b) nil)))
Theorem:
(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:
(defthm nthcdr-of-repeat (equal (nthcdr n (repeat k a)) (if (<= (nfix n) (nfix k)) (repeat (- (nfix k) (nfix n)) a) nil)))
Theorem:
(defthm append-of-repeat-to-cons-of-same (equal (append (repeat n a) (cons a x)) (cons a (append (repeat n a) x))))
Theorem:
(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:
(defthm rev-of-repeat (equal (rev (repeat n a)) (repeat n a)))
Theorem:
(defthm subsetp-of-repeat (iff (subsetp-equal (repeat n x) y) (or (zp n) (member-equal x y))))
Theorem:
(defthm element-list-p-of-repeat (iff (element-list-p (repeat n x)) (or (element-p x) (zp n))) :rule-classes :rewrite)