• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
        • Strtok!
        • Cases
        • Concatenation
        • Html-encoding
        • Character-kinds
        • Substrings
        • Strtok
        • Equivalences
          • Charlisteqv
          • Icharlisteqv
          • Istreqv
            • Ichareqv
            • Streqv
            • Chareqv
            • Char-fix
            • Str-fix
          • Url-encoding
          • Lines
          • Ordering
          • Numbers
          • Pad-trim
          • Coercion
          • Std/strings-extensions
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/io
        • Std/osets
        • Std/system
        • Std/basic
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Equivalences
    • Cases

    Istreqv

    Case-insensitive string equivalence test.

    Signature
    (istreqv x y) → bool

    (istreqv x y) determines if x and y are case-insensitively equivalent strings. That is, x and y must have the same length and their elements must be ichareqv to one another.

    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.

    Definitions and Theorems

    Function: istreqv-aux

    (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: istreqv-aux-removal

    (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: istreqv$inline

    (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: istreqv-is-an-equivalence

    (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: streqv-refines-istreqv

    (defthm streqv-refines-istreqv
            (implies (streqv x y) (istreqv x y))
            :rule-classes (:refinement))

    Theorem: istreqv-implies-ichareqv-char-1

    (defthm istreqv-implies-ichareqv-char-1
            (implies (istreqv x x-equiv)
                     (ichareqv (char x n) (char x-equiv n)))
            :rule-classes (:congruence))

    Theorem: istreqv-implies-icharlisteqv-explode-1

    (defthm istreqv-implies-icharlisteqv-explode-1
            (implies (istreqv x x-equiv)
                     (icharlisteqv (explode x)
                                   (explode x-equiv)))
            :rule-classes (:congruence))

    Theorem: istreqv-implies-istreqv-string-append-1

    (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: istreqv-implies-istreqv-string-append-2

    (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))