• 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
            • Strpos-fast
            • 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
    • Strpos

    Strpos-fast

    Fast implementation of strpos.

    Definitions and Theorems

    Function: strpos-fast

    (defun strpos-fast (x y n xl yl)
      (declare (type string x)
               (type string y)
               (type integer n)
               (type integer xl)
               (type integer yl)
               (xargs :guard (and (stringp x)
                                  (stringp y)
                                  (natp xl)
                                  (natp yl)
                                  (natp n)
                                  (<= n (length y))
                                  (= xl (length x))
                                  (= yl (length y)))))
      (cond ((mbe :logic (prefixp (explode x)
                                  (nthcdr n (explode y)))
                  :exec (strprefixp-impl (the string x)
                                         (the string y)
                                         (the integer 0)
                                         (the integer n)
                                         (the integer xl)
                                         (the integer yl)))
             (lnfix n))
            ((mbe :logic (zp (- (nfix yl) (nfix n)))
                  :exec (int= n yl))
             nil)
            (t (strpos-fast (the string x)
                            (the string y)
                            (+ 1 (lnfix n))
                            (the integer xl)
                            (the integer yl)))))

    Theorem: strpos-fast-removal

    (defthm strpos-fast-removal
      (implies (and (force (stringp x))
                    (force (stringp y))
                    (force (natp n))
                    (force (equal xl (length x)))
                    (force (equal yl (length y))))
               (equal (strpos-fast x y n xl yl)
                      (let ((idx (listpos (explode x)
                                          (nthcdr n (explode y)))))
                        (and idx (+ n idx))))))