Count how many characters at the start of a list are members of a particular character set.
(count-leading-charset x set) → num
Function:
(defun count-leading-charset (x set) (declare (xargs :guard (and (character-listp x) (charset-p set)))) (let ((acl2::__function__ 'count-leading-charset)) (declare (ignorable acl2::__function__)) (cond ((atom x) 0) ((char-in-charset-p (car x) set) (+ 1 (count-leading-charset (cdr x) set))) (t 0))))
Theorem:
(defthm natp-of-count-leading-charset (b* ((num (count-leading-charset x set))) (natp num)) :rule-classes :type-prescription)
Theorem:
(defthm upper-bound-of-count-leading-charset (<= (count-leading-charset x set) (len x)) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm count-leading-charset-len (equal (equal (len x) (count-leading-charset x set)) (chars-in-charset-p x set)) :rule-classes ((:rewrite) (:rewrite :corollary (equal (< (count-leading-charset x set) (len x)) (not (chars-in-charset-p x set)))) (:linear :corollary (implies (not (chars-in-charset-p x set)) (< (count-leading-charset x set) (len x))))))
Theorem:
(defthm count-leading-charset-zero (equal (equal 0 (count-leading-charset x set)) (not (char-in-charset-p (car x) set))) :rule-classes ((:rewrite) (:rewrite :corollary (equal (< 0 (count-leading-charset x set)) (char-in-charset-p (car x) set))) (:linear :corollary (implies (char-in-charset-p (car x) set) (< 0 (count-leading-charset x set))))))
Theorem:
(defthm count-leading-charset-sound (let ((n (count-leading-charset x set))) (chars-in-charset-p (take n x) set)))
Theorem:
(defthm count-leading-charset-complete (b* ((n (count-leading-charset x set)) (next-char (nth n x))) (not (char-in-charset-p next-char set))))