Fast implementation of strrpos.
Function:
(defun strrpos-fast (x y n xl yl) (declare (type string x y) (type (integer 0 *) n xl yl) (xargs :guard (and (stringp x) (stringp y) (natp xl) (natp yl) (natp n) (<= n (length y)) (= xl (length x)) (= yl (length y))))) (cond ((mbe :logic (prefixp (explode x) (nthcdr n (explode y))) :exec (strprefixp-impl (the string x) (the string y) (the integer 0) (the (integer 0 *) n) (the (integer 0 *) xl) (the (integer 0 *) yl))) (lnfix n)) ((zp n) nil) (t (strrpos-fast (the string x) (the string y) (the (integer 0 *) (+ -1 (lnfix n))) (the (integer 0 *) xl) (the (integer 0 *) yl)))))
Theorem:
(defthm strrpos-fast-type (or (and (integerp (strrpos-fast x y n xl yl)) (<= 0 (strrpos-fast x y n xl yl))) (not (strrpos-fast x y n xl yl))) :rule-classes :type-prescription)
Theorem:
(defthm strrpos-fast-upper-bound (implies (force (natp n)) (<= (strrpos-fast x y n xl yl) n)) :rule-classes :linear)
Theorem:
(defthm strrpos-fast-when-empty (implies (and (not (consp (explode x))) (equal xl (length x)) (equal yl (length y)) (natp n)) (equal (strrpos-fast x y n xl yl) n)))