Fast implementation of strsubst.
Function:
(defun strsubst-aux (old new x n xl oldl acc) (declare (type string old new x) (type (integer 0 *) n xl oldl) (xargs :guard (and (stringp old) (stringp new) (stringp x) (natp n) (natp xl) (posp oldl) (= oldl (length old)) (= xl (length x))))) (cond ((mbe :logic (zp oldl) :exec nil) acc) ((mbe :logic (zp (- (nfix xl) (nfix n))) :exec (>= n xl)) acc) ((strprefixp-impl old x 0 n oldl xl) (let ((acc (revappend-chars new acc))) (strsubst-aux old new x (the (integer 0 *) (+ oldl (the (integer 0 *) (lnfix n)))) xl oldl acc))) (t (let ((acc (cons (char x n) acc))) (strsubst-aux old new x (the (integer 0 *) (+ 1 (the (integer 0 *) (lnfix n)))) xl oldl acc)))))
Theorem:
(defthm character-listp-of-strsubst-aux (implies (and (stringp old) (stringp new) (stringp x) (natp n) (posp oldl) (= oldl (length old)) (= xl (length x)) (character-listp acc)) (character-listp (strsubst-aux old new x n xl oldl acc))))