Function:
(defun index-perm (n perm x numvars) (declare (xargs :guard (and (natp n) (nat-listp perm) (natp x) (natp numvars)))) (declare (xargs :guard (and (<= n numvars) (eql (len perm) numvars)))) (let ((__function__ 'index-perm)) (declare (ignorable __function__)) (b* (((when (mbe :logic (zp (- (nfix numvars) (nfix n))) :exec (eql n numvars))) (lnfix x)) (x (index-swap n (nth n perm) x))) (index-perm (1+ (lnfix n)) perm x numvars))))
Theorem:
(defthm natp-of-index-perm (b* ((perm-idx (index-perm n perm x numvars))) (natp perm-idx)) :rule-classes :type-prescription)
Theorem:
(defthm bound-of-index-perm (b* ((?perm-idx (index-perm n perm x numvars))) (implies (and (< (nfix x) (nfix numvars)) (index-listp perm numvars)) (< perm-idx (nfix numvars)))) :rule-classes :linear)
Theorem:
(defthm index-perm-unique (iff (equal (index-perm n perm x numvars) (index-perm n perm y numvars)) (equal (nfix x) (nfix y))))
Theorem:
(defthm index-perm-of-nfix-n (equal (index-perm (nfix n) perm x numvars) (index-perm n perm x numvars)))
Theorem:
(defthm index-perm-nat-equiv-congruence-on-n (implies (nat-equiv n n-equiv) (equal (index-perm n perm x numvars) (index-perm n-equiv perm x numvars))) :rule-classes :congruence)
Theorem:
(defthm index-perm-of-nfix-x (equal (index-perm n perm (nfix x) numvars) (index-perm n perm x numvars)))
Theorem:
(defthm index-perm-nat-equiv-congruence-on-x (implies (nat-equiv x x-equiv) (equal (index-perm n perm x numvars) (index-perm n perm x-equiv numvars))) :rule-classes :congruence)
Theorem:
(defthm index-perm-of-nfix-numvars (equal (index-perm n perm x (nfix numvars)) (index-perm n perm x numvars)))
Theorem:
(defthm index-perm-nat-equiv-congruence-on-numvars (implies (nat-equiv numvars numvars-equiv) (equal (index-perm n perm x numvars) (index-perm n perm x numvars-equiv))) :rule-classes :congruence)