Robert Smith committed 0846526

Add PERM-FIXPOINTS for computing the fixed points of a permutation.

Comments (0)

Files changed (3)

 perm-transpose-indexes : swap two indexes, keeping the entries fixed
 perm-transpose-entries : swap two entries, keeping the indexes fixed
 perm-inverse : invert a permutation
+perm-fixpoints : compute the fixed points of a permutation
 permute : permute an array according to a permutation
+   #:perm-fixpoints
           :do (setf (aref perm*-spec (perm-eval perm i)) i)
           :finally (return (%make-perm :spec perm*-spec)))))
+;;; This can be a bit more optimized.
+(defun perm-fixpoints (perm &optional (n (perm-size perm)))
+  "Return a list of the fixed points in PERM less than or equal to N,
+  which is the perm's size by default.."
+  (check-type n (integer 1))
+  (loop :for i :from 1 :to n
+        :when (= i (perm-eval* perm i))
+          :collect i))
 (defun permute (perm a)
   "Permute the array A according to PERM."
   (assert (<= (perm-size perm)