Pick the maximum number in a list of natural numbers
Function:
(defun max-nats (x) (declare (xargs :guard (nat-listp x))) (let ((__function__ 'max-nats)) (declare (ignorable __function__)) (cond ((atom x) 0) ((atom (cdr x)) (lnfix (car x))) (t (max (lnfix (car x)) (max-nats (cdr x)))))))
Theorem:
(defthm natp-of-max-nats (implies (and (nat-listp x)) (b* ((max (max-nats x))) (natp max))) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm max-nats-returns-a-member-of-input (implies (and (nat-listp x) (consp x)) (member-equal (max-nats x) x)))
Theorem:
(defthm max-nats-of-list-of-one-element (implies (natp e) (equal (max-nats (list e)) e)))
Theorem:
(defthm max-nats-and-cons (<= (max-nats x) (max-nats (cons e x))) :rule-classes :linear)
Theorem:
(defthm max-nats-is-greater-than-any-other-list-element (implies (and (member-equal e x) (not (equal e (max-nats x))) (nat-listp x)) (< e (max-nats x))) :rule-classes :linear)