• 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
              • 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
    • Substrings

    Strsuffixp

    Case-sensitive string suffix test.

    (strsuffixp x y) determines if the string x is a suffix of the string y, in a case-sensitive manner.

    Logically, we ask whether |x| < |y|, and whether

    (equal (nthcdr (- |y| |x|) (explode x))
           (explode y))

    But we use a more efficient implementation that avoids coercing the strings into lists; basically we ask if the last |x| characters of y are equal to x.

    Corner case: we regard the empty string as a suffix of every other string. That is, (strsuffixp "" x) is always true.

    Definitions and Theorems

    Function: strsuffixp$inline

    (defun strsuffixp$inline (x y)
      (declare (type string x y))
      (mbe :logic
           (let* ((xchars (explode x))
                  (ychars (explode y))
                  (xlen (len xchars))
                  (ylen (len ychars)))
             (and (<= xlen ylen)
                  (equal (nthcdr (- ylen xlen) (explode y))
                         (explode x))))
           :exec
           (let* ((xlen (length x)) (ylen (length y)))
             (and (<= xlen ylen)
                  (strprefixp-impl x y 0 (- ylen xlen)
                                   xlen ylen)))))

    Theorem: strsuffixp-of-empty

    (defthm strsuffixp-of-empty
      (strsuffixp "" y))

    Theorem: streqv-implies-equal-strsuffixp-1

    (defthm streqv-implies-equal-strsuffixp-1
      (implies (streqv x x-equiv)
               (equal (strsuffixp x y)
                      (strsuffixp x-equiv y)))
      :rule-classes (:congruence))

    Theorem: streqv-implies-equal-strsuffixp-2

    (defthm streqv-implies-equal-strsuffixp-2
      (implies (streqv y y-equiv)
               (equal (strsuffixp x y)
                      (strsuffixp x y-equiv)))
      :rule-classes (:congruence))