Case-insensitive string equivalence test.
(istreqv x y) → bool
(istreqv x y) determines if
Logically this is identical to
(icharlisteqv (explode x) (explode y))
But we use a more efficient implementation which avoids coercing the strings into lists.
NOTE: for reasoning, we leave this function enabled and prefer to work with icharlisteqv of the coerces as our normal form.
Function:
(defun istreqv-aux (x y n l) (declare (type string x) (type string y) (type (integer 0 *) n) (type (integer 0 *) l) (xargs :guard (and (natp n) (natp l) (equal (length x) l) (equal (length y) l) (<= n l)))) (mbe :logic (if (zp (- (nfix l) (nfix n))) t (and (ichareqv (char x n) (char y n)) (istreqv-aux x y (+ (nfix n) 1) l))) :exec (if (eql n l) t (and (ichareqv (the character (char x n)) (the character (char y n))) (istreqv-aux x y (the (integer 0 *) (+ 1 n)) l)))))
Theorem:
(defthm istreqv-aux-removal (implies (and (stringp x) (stringp y) (natp n) (<= n l) (= l (length x)) (= l (length y))) (equal (istreqv-aux x y n l) (icharlisteqv (nthcdr n (explode x)) (nthcdr n (explode y))))))
Function:
(defun istreqv$inline (x y) (declare (type string x) (type string y)) (let ((acl2::__function__ 'istreqv)) (declare (ignorable acl2::__function__)) (mbe :logic (icharlisteqv (explode x) (explode y)) :exec (b* (((the (integer 0 *) xl) (length x)) ((the (integer 0 *) yl) (length y))) (and (eql xl yl) (istreqv-aux x y 0 xl))))))
Theorem:
(defthm istreqv-is-an-equivalence (and (booleanp (istreqv x y)) (istreqv x x) (implies (istreqv x y) (istreqv y x)) (implies (and (istreqv x y) (istreqv y z)) (istreqv x z))) :rule-classes (:equivalence))
Theorem:
(defthm streqv-refines-istreqv (implies (streqv x y) (istreqv x y)) :rule-classes (:refinement))
Theorem:
(defthm istreqv-implies-ichareqv-char-1 (implies (istreqv x x-equiv) (ichareqv (char x n) (char x-equiv n))) :rule-classes (:congruence))
Theorem:
(defthm istreqv-implies-icharlisteqv-explode-1 (implies (istreqv x x-equiv) (icharlisteqv (explode x) (explode x-equiv))) :rule-classes (:congruence))
Theorem:
(defthm istreqv-implies-istreqv-string-append-1 (implies (istreqv x x-equiv) (istreqv (string-append x y) (string-append x-equiv y))) :rule-classes (:congruence))
Theorem:
(defthm istreqv-implies-istreqv-string-append-2 (implies (istreqv y y-equiv) (istreqv (string-append x y) (string-append x y-equiv))) :rule-classes (:congruence))