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

    Strrpos-fast

    Fast implementation of strrpos.

    Definitions and Theorems

    Function: strrpos-fast

    (defun strrpos-fast (x y n xl yl)
      (declare (type string x y)
               (type (integer 0 *) n xl 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 0 *) n)
                                         (the (integer 0 *) xl)
                                         (the (integer 0 *) yl)))
             (lnfix n))
            ((zp n) nil)
            (t (strrpos-fast (the string x)
                             (the string y)
                             (the (integer 0 *) (+ -1 (lnfix n)))
                             (the (integer 0 *) xl)
                             (the (integer 0 *) yl)))))

    Theorem: strrpos-fast-type

    (defthm strrpos-fast-type
      (or (and (integerp (strrpos-fast x y n xl yl))
               (<= 0 (strrpos-fast x y n xl yl)))
          (not (strrpos-fast x y n xl yl)))
      :rule-classes :type-prescription)

    Theorem: strrpos-fast-upper-bound

    (defthm strrpos-fast-upper-bound
      (implies (force (natp n))
               (<= (strrpos-fast x y n xl yl) n))
      :rule-classes :linear)

    Theorem: strrpos-fast-when-empty

    (defthm strrpos-fast-when-empty
      (implies (and (not (consp (explode x)))
                    (equal xl (length x))
                    (equal yl (length y))
                    (natp n))
               (equal (strrpos-fast x y n xl yl) n)))