• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • 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
            • String-listp
            • Stringp
            • Length
            • Search
            • Remove-duplicates
            • Position
            • Coerce
            • Concatenate
            • Reverse
            • String
            • Subseq
            • Substitute
            • String-upcase
            • String-downcase
            • Count
            • Char
            • String<
            • String-equal
            • String-utilities
            • String-append
            • String>=
            • String<=
            • String>
            • Hex-digit-char-theorems
            • String-downcase-gen
            • String-upcase-gen
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • 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))))))