Commits

Robert Smith committed 798eabf

* add SIGN and IOTA-VECTOR to utilities
* use IOTA-VECTOR to generate PERM-IDENTITY

Comments (0)

Files changed (2)

 
 (defun perm-identity (n)
   "The identity permutation of size N."
-  (%make-perm :spec (coerce (iota (1+ n)) 'vector)))
+  (%make-perm :spec (iota-vector (1+ n))))
 
 (defun perm-identity-p (perm)
   "Is the permutation PERM an identity permutation?"
   "Generate a list of numbers between 0 and N-1."
   (loop :for i :below n :collect i))
 
+(defun iota-vector (n)
+  "Generate the equivalent of (COERCE (IOTA N) 'VECTOR)."
+  (loop :with a := (make-array n :initial-element 0)
+        :for i :below n
+        :do (setf (aref a i) i)
+        :finally (return a)))
+
 (defun iota+1 (n)
   "Generate a list of numbers between 1 and N."
   (loop :for i :from 1 :to n :collect i))
 function KEY."
   (reduce '* list :key key :initial-value 1))
 
+(defun sign (x)
+  "Return the sign of X."
+  (cond
+    ((plusp x)  1)
+    ((zerop x)  0)
+    (t         -1)))
+
 (defun hash-table-key-exists-p (hash-table key)
   "Check of KEY exists in HASH-TABLE."
   (multiple-value-bind (val existsp) (gethash key hash-table)