• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
        • Std/lists/abstract
        • Rev
        • Defsort
        • List-fix
        • Std/lists/nth
        • Hons-remove-duplicates
        • Std/lists/update-nth
        • Set-equiv
        • Duplicity
        • Prefixp
        • Std/lists/take
        • Std/lists/intersection$
        • Nats-equiv
        • Repeat
        • Index-of
        • All-equalp
        • Sublistp
        • Std/lists/nthcdr
        • Listpos
        • List-equiv
        • Final-cdr
        • Std/lists/append
        • Std/lists/remove
        • Subseq-list
        • Rcons
        • Std/lists/revappend
        • Std/lists/remove-duplicates-equal
        • Std/lists/reverse
        • Std/lists/last
        • Std/lists/resize-list
        • Flatten
        • Suffixp
          • Std/lists/butlast
          • Std/lists/set-difference
          • Std/lists/len
          • Std/lists/intersectp
          • Std/lists/true-listp
          • Intersectp-witness
          • Subsetp-witness
          • Std/lists/remove1-equal
          • Rest-n
          • First-n
          • Std/lists/union
          • Append-without-guard
          • Std/lists/subsetp
          • Std/lists/member
        • Std/alists
        • Obags
        • Std/util
        • Std/strings
        • Std/io
        • Std/osets
        • Std/system
        • Std/basic
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Std/lists

    Suffixp

    (suffixp x y) determines if the list x occurs at the end of the list y.

    For example:

    (suffixp '(3 4 5) '(1 2 3 4 5)) == t
    (suffixp '(a b c) '(1 2 3 4 5)) == nil

    Note that the check is carried out using equal, so the final cdr of the list is considered relevant. That is,

    (suffixp '(3 4 5 . 6) '(1 2 3 4 5 . 6)) = t
    (suffixp '(3 4 5)     '(1 2 3 4 5 . 6)) = nil

    Definitions and Theorems

    Function: suffixp

    (defun suffixp (x y)
      (declare (xargs :guard t))
      (or (equal x y)
          (and (consp y) (suffixp x (cdr y)))))

    Theorem: suffixp-of-cons-right

    (defthm suffixp-of-cons-right
      (equal (suffixp a (cons c b))
             (or (equal a (cons c b))
                 (suffixp a b))))

    Theorem: not-suffixp-of-cons-left

    (defthm not-suffixp-of-cons-left
      (implies (not (suffixp a b))
               (not (suffixp (cons c a) b))))

    Theorem: suffixp-of-self

    (defthm suffixp-of-self (suffixp x x))

    Theorem: suffixp-transitive

    (defthm suffixp-transitive
      (implies (and (suffixp b c) (suffixp a b))
               (suffixp a c)))

    Note that the following is disabled by default:

    Theorem: suffixp-equals-nthcdr

    (defthm suffixp-equals-nthcdr
      (equal (suffixp x y)
             (equal x (nthcdr (- (len y) (len x)) y))))