Sum a list of natural numbers.
(sum-nats x) → *
Function:
(defun tr-sum-nats (x acc) (declare (xargs :guard (and (nat-listp x) (natp acc))) (type integer acc)) (if (consp x) (tr-sum-nats (cdr x) (the integer (+ (car x) acc))) acc))
Function:
(defun sum-nats (x) (declare (xargs :guard (nat-listp x))) (let ((__function__ 'sum-nats)) (declare (ignorable __function__)) (mbe :logic (if (consp x) (+ (nfix (car x)) (sum-nats (cdr x))) 0) :exec (tr-sum-nats x 0))))
Theorem:
(defthm sum-nats-when-atom (implies (atom x) (equal (sum-nats x) 0)))
Theorem:
(defthm sum-nats-of-cons (equal (sum-nats (cons a x)) (+ (nfix a) (sum-nats x))))
Theorem:
(defthm sum-nats-of-list-fix (equal (sum-nats (list-fix x)) (sum-nats x)))
Theorem:
(defthm sum-nats-of-append (equal (sum-nats (append x y)) (+ (sum-nats x) (sum-nats y))))
Theorem:
(defthm sum-nats-of-rev (equal (sum-nats (rev x)) (sum-nats x)))
Theorem:
(defthm sum-nats-of-revappend (equal (sum-nats (revappend x y)) (+ (sum-nats x) (sum-nats y))))
Theorem:
(defthm sum-nats-of-reverse (implies (true-listp x) (equal (sum-nats (reverse x)) (sum-nats x))))
Theorem:
(defthm sum-nats-when-all-equalp (implies (all-equalp n x) (equal (sum-nats x) (* (nfix n) (len x)))))
Theorem:
(defthm sum-nats-when-all-equalp-1 (implies (all-equalp 1 x) (equal (sum-nats x) (len x))))