Case-insensitive string prefix test.
(istrprefixp x y) determines if the string
Logically, this is identical to
(iprefixp (explode x) (explode y))
But we use a more efficient implementation which avoids coercing the strings to lists.
Function:
(defun istrprefixp-impl (x y xn yn xl yl) (declare (type string x) (type string y) (type integer xn) (type integer yn) (type integer xl) (type integer yl) (xargs :guard (and (stringp x) (stringp y) (natp xn) (natp yn) (natp xl) (natp yl) (= xl (length x)) (= yl (length y)) (<= xn (length x)) (<= yn (length y))))) (cond ((mbe :logic (zp (- (nfix xl) (nfix xn))) :exec (int= xn xl)) t) ((mbe :logic (zp (- (nfix yl) (nfix yn))) :exec (int= yn yl)) nil) ((ichareqv (char x xn) (char y yn)) (istrprefixp-impl x y (+ 1 (lnfix xn)) (+ 1 (lnfix yn)) xl yl)) (t nil)))
Function:
(defun istrprefixp$inline (x y) (declare (type string x) (type string y)) (mbe :logic (iprefixp (explode x) (explode y)) :exec (istrprefixp-impl (the string x) (the string y) (the integer 0) (the integer 0) (the integer (length (the string x))) (the integer (length (the string y))))))
Theorem:
(defthm istrprefixp-impl-elim (implies (and (force (stringp x)) (force (stringp y)) (force (natp xn)) (force (natp yn)) (force (= xl (length x))) (force (= yl (length y)))) (equal (istrprefixp-impl x y xn yn xl yl) (iprefixp (nthcdr xn (coerce x 'list)) (nthcdr yn (coerce y 'list))))))
Theorem:
(defthm istreqv-implies-equal-istrprefixp-1 (implies (istreqv x x-equiv) (equal (istrprefixp x y) (istrprefixp x-equiv y))) :rule-classes (:congruence))
Theorem:
(defthm istreqv-implies-equal-istrprefixp-2 (implies (istreqv y y-equiv) (equal (istrprefixp x y) (istrprefixp x y-equiv))) :rule-classes (:congruence))