Fast implementation of strpos.
Function:
(defun strpos-fast (x y n xl yl) (declare (type string x) (type string y) (type integer n) (type integer xl) (type integer 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 n) (the integer xl) (the integer yl))) (lnfix n)) ((mbe :logic (zp (- (nfix yl) (nfix n))) :exec (int= n yl)) nil) (t (strpos-fast (the string x) (the string y) (+ 1 (lnfix n)) (the integer xl) (the integer yl)))))
Theorem:
(defthm strpos-fast-removal (implies (and (force (stringp x)) (force (stringp y)) (force (natp n)) (force (equal xl (length x))) (force (equal yl (length y)))) (equal (strpos-fast x y n xl yl) (let ((idx (listpos (explode x) (nthcdr n (explode y))))) (and idx (+ n idx))))))