• Top
    • Documentation
    • Books
    • 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
          • Istrpos
          • Strrpos
          • Strpos
          • Collect-syms-with-isubstr
          • Istrprefixp
            • Collect-strs-with-isubstr
            • Iprefixp
            • Strsuffixp
            • Firstn-chars
            • Strprefixp
            • Isubstrp
            • Substrp
          • Strtok
          • Equivalences
          • Url-encoding
          • Lines
          • Explode-implode-equalities
          • Ordering
          • Numbers
          • Pad-trim
          • Coercion
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/osets
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Substrings

    Istrprefixp

    Case-insensitive string prefix test.

    (istrprefixp x y) determines if the string x is a case-insensitive prefix of the string y.

    Logically, this is identical to

    (iprefixp (explode x) (explode y))

    But we use a more efficient implementation which avoids coercing the strings to lists.

    Definitions and Theorems

    Function: istrprefixp-impl

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

    (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: istrprefixp-impl-elim

    (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: istreqv-implies-equal-istrprefixp-1

    (defthm istreqv-implies-equal-istrprefixp-1
      (implies (istreqv x x-equiv)
               (equal (istrprefixp x y)
                      (istrprefixp x-equiv y)))
      :rule-classes (:congruence))

    Theorem: istreqv-implies-equal-istrprefixp-2

    (defthm istreqv-implies-equal-istrprefixp-2
      (implies (istreqv y y-equiv)
               (equal (istrprefixp x y)
                      (istrprefixp x y-equiv)))
      :rule-classes (:congruence))