(prefixp x y) determines if the list
Function:
(defun prefixp (x y) (declare (xargs :guard t)) (if (consp x) (and (consp y) (equal (car x) (car y)) (prefixp (cdr x) (cdr y))) t))
Theorem:
(defthm prefixp-when-not-consp-left (implies (not (consp x)) (prefixp x y)))
Theorem:
(defthm prefixp-of-cons-left (equal (prefixp (cons a x) y) (and (consp y) (equal a (car y)) (prefixp x (cdr y)))))
Theorem:
(defthm prefixp-when-not-consp-right (implies (not (consp y)) (equal (prefixp x y) (not (consp x)))))
Theorem:
(defthm prefixp-of-cons-right (equal (prefixp x (cons a y)) (if (consp x) (and (equal (car x) a) (prefixp (cdr x) y)) t)))
Theorem:
(defthm prefixp-of-list-fix-left (equal (prefixp (list-fix x) y) (prefixp x y)))
Theorem:
(defthm prefixp-of-list-fix-right (equal (prefixp x (list-fix y)) (prefixp x y)))
Theorem:
(defthm list-equiv-implies-equal-prefixp-1 (implies (list-equiv x x-equiv) (equal (prefixp x y) (prefixp x-equiv y))) :rule-classes (:congruence))
Theorem:
(defthm list-equiv-implies-equal-prefixp-2 (implies (list-equiv y y-equiv) (equal (prefixp x y) (prefixp x y-equiv))) :rule-classes (:congruence))
Theorem:
(defthm len-when-prefixp (implies (prefixp x y) (equal (< (len y) (len x)) nil)) :rule-classes ((:rewrite) (:linear :corollary (implies (prefixp x y) (<= (len x) (len y))))))
Theorem:
(defthm take-when-prefixp (implies (prefixp x y) (equal (take (len x) y) (list-fix x))))
Theorem:
(defthm prefixp-of-take (equal (prefixp (take n x) x) (<= (nfix n) (len x))))
Theorem:
(defthm prefixp-reflexive (prefixp x x))
Theorem:
(defthm prefixp-of-append-arg2 (equal (prefixp x (append y z)) (or (prefixp x y) (and (equal (true-list-fix y) (take (len y) x)) (prefixp (nthcdr (len y) x) z)))))
Theorem:
(defthm prefixp-when-equal-lengths (implies (>= (len x) (len y)) (equal (prefixp x y) (list-equiv x y))))
Theorem:
(defthm prefixp-transitive (implies (and (prefixp x y) (prefixp y z)) (prefixp x z)) :rule-classes (:rewrite (:rewrite :corollary (implies (and (prefixp y z) (prefixp x y)) (prefixp x z)))))
Theorem:
(defthm prefixp-append-append (equal (prefixp (append x1 x2) (append x1 y)) (prefixp x2 y)))
Theorem:
(defthm prefixp-nthcdr-nthcdr (implies (and (>= (len l2) n) (equal (take n l1) (take n l2))) (equal (prefixp (nthcdr n l1) (nthcdr n l2)) (prefixp l1 l2))))
Theorem:
(defthm prefixp-one-way-or-another (implies (and (prefixp x z) (prefixp y z) (not (prefixp x y))) (prefixp y x)) :rule-classes (:rewrite (:rewrite :corollary (implies (and (prefixp y z) (prefixp x z) (not (prefixp x y))) (prefixp y x)))))
Theorem:
(defthm nth-when-prefixp (implies (and (prefixp x y) (< (nfix n) (len x))) (equal (nth n y) (nth n x))) :rule-classes ((:rewrite :corollary (implies (and (prefixp x y) (not (list-equiv x y)) (< (nfix n) (len x))) (equal (nth n y) (nth n x))))))
Theorem:
(defthm append-when-prefixp (implies (prefixp x y) (equal (append x (nthcdr (len x) y)) y)))
Theorem:
(defthm subsetp-when-prefixp (implies (prefixp x y) (subsetp-equal x y)))
Theorem:
(defthm prefixp-of-append-arg1 (equal (prefixp (append x y) z) (and (<= (+ (len x) (len y)) (len z)) (equal (true-list-fix x) (take (len x) z)) (prefixp y (nthcdr (len x) z)))))
Theorem:
(defthm prefixp-when-prefixp (implies (prefixp y x) (equal (prefixp x y) (list-equiv x y))))