(listpos x y) returns the starting position of the first occurrence
of the sublist
See also sublistp, which is closely related.
Function:
(defun listpos (x y) (declare (xargs :guard t)) (cond ((prefixp x y) 0) ((atom y) nil) (t (let ((pos-in-cdr (listpos x (cdr y)))) (and pos-in-cdr (+ 1 pos-in-cdr))))))
Theorem:
(defthm listpos-when-atom-left (implies (atom x) (equal (listpos x y) 0)))
Theorem:
(defthm listpos-when-atom-right (implies (atom y) (equal (listpos x y) (if (atom x) 0 nil))))
Theorem:
(defthm listpos-of-list-fix-left (equal (listpos (list-fix x) y) (listpos x y)))
Theorem:
(defthm listpos-of-list-fix-right (equal (listpos x (list-fix y)) (listpos x y)))
Theorem:
(defthm list-equiv-implies-equal-listpos-1 (implies (list-equiv x x-equiv) (equal (listpos x y) (listpos x-equiv y))) :rule-classes (:congruence))
Theorem:
(defthm list-equiv-implies-equal-listpos-2 (implies (list-equiv y y-equiv) (equal (listpos x y) (listpos x y-equiv))) :rule-classes (:congruence))
Theorem:
(defthm listpos-under-iff (iff (listpos x y) (sublistp x y)))
Theorem:
(defthm natp-of-listpos (equal (natp (listpos x y)) (sublistp x y)))
Theorem:
(defthm integerp-of-listpos (equal (integerp (listpos x y)) (sublistp x y)))
Theorem:
(defthm rationalp-of-listpos (equal (rationalp (listpos x y)) (sublistp x y)))
Theorem:
(defthm acl2-numberp-of-listpos (equal (acl2-numberp (listpos x y)) (sublistp x y)))
Theorem:
(defthm listpos-lower-bound-weak (<= 0 (listpos x y)) :rule-classes (:linear))
Theorem:
(defthm listpos-upper-bound-weak (<= (listpos x y) (len y)) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm listpos-upper-bound-strong-1 (equal (< (listpos x y) (len y)) (consp y)) :rule-classes ((:rewrite) (:linear :corollary (implies (consp y) (< (listpos x y) (len y))))))
Theorem:
(defthm listpos-upper-bound-strong-2 (implies (sublistp x y) (<= (listpos x y) (- (len y) (len x)))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm listpos-complete (implies (prefixp x (nthcdr n y)) (and (listpos x y) (<= (listpos x y) (nfix n)))) :rule-classes ((:rewrite) (:linear :corollary (implies (prefixp x (nthcdr n y)) (<= (listpos x y) (nfix n))))))