permute.old 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. (FILECREATED " 2-JAN-83 14:20:01" {DSK}PERMUTE.LSP;4 9267
  2. changes to: (FNS HISTO-CREATE HISTO-PEAKS HISTO-ADD)
  3. (VARS PERMUTECOMS)
  4. previous date: "28-DEC-82 11:32:40" {DSK}PERMUTE.LSP;1)
  5. (PRETTYCOMPRINT PERMUTECOMS)
  6. (RPAQQ PERMUTECOMS ((GLISPOBJECTS HISTOGRAM PERMUTATION)
  7. (VARS PERM3S FOLD3S PERM4S FOLD4S)
  8. (FNS ALLPERMS BINLIST BITSHUFFLE COMPOSEBITSHUFFLES DOBITSHUFFLE GENPERMS HISTO-ADD
  9. HISTO-CREATE HISTO-PEAKS IDPERM LISTOFC LOG2 NEGINPPERM OUTPERMS PERM-INVERSE)
  10. (PROP GLRESULTTYPE BITSHUFFLE DOBITSHUFFLE)))
  11. [GLISPOBJECTS
  12. (HISTOGRAM
  13. (LISTOBJECT (MIN INTEGER)
  14. (MAX INTEGER)
  15. (TOTAL INTEGER)
  16. (COUNTS (LISTOF INTEGER)))
  17. PROP ((PEAKS HISTO-PEAKS))
  18. MSG ((CREATE HISTO-CREATE)
  19. (+ HISTO-ADD)) )
  20. (PERMUTATION
  21. (LISTOF INTEGER)
  22. PROP ((LENGTH LENGTH)
  23. (INVERSE PERM-INVERSE RESULT PERMUTATION))
  24. MSG ((* COMPOSEBITSHUFFLES RESULT PERMUTATION)) )
  25. ]
  26. (RPAQQ PERM3S ((7 3 5 1 6 2 4 0)
  27. (7 5 3 1 6 4 2 0)
  28. (7 3 6 2 5 1 4 0)
  29. (7 5 6 4 3 1 2 0)
  30. (7 6 3 2 5 4 1 0)))
  31. (RPAQQ FOLD3S ((3 2 1 0 7 6 5 4)
  32. (5 4 7 6 1 0 3 2)
  33. (6 7 4 5 2 3 0 1)))
  34. (RPAQQ PERM4S ((15 7 11 3 13 5 9 1 14 6 10 2 12 4 8 0)
  35. (15 11 7 3 13 9 5 1 14 10 6 2 12 8 4 0)
  36. (15 7 13 5 11 3 9 1 14 6 12 4 10 2 8 0)
  37. (15 11 13 9 7 3 5 1 14 10 12 8 6 2 4 0)
  38. (15 13 7 5 11 9 3 1 14 12 6 4 10 8 2 0)
  39. (15 13 11 9 7 5 3 1 14 12 10 8 6 4 2 0)
  40. (15 7 11 3 14 6 10 2 13 5 9 1 12 4 8 0)
  41. (15 11 7 3 14 10 6 2 13 9 5 1 12 8 4 0)
  42. (15 7 13 5 14 6 12 4 11 3 9 1 10 2 8 0)
  43. (15 11 13 9 14 10 12 8 7 3 5 1 6 2 4 0)
  44. (15 13 7 5 14 12 6 4 11 9 3 1 10 8 2 0)
  45. (15 13 11 9 14 12 10 8 7 5 3 1 6 4 2 0)
  46. (15 7 14 6 11 3 10 2 13 5 12 4 9 1 8 0)
  47. (15 11 14 10 7 3 6 2 13 9 12 8 5 1 4 0)
  48. (15 7 14 6 13 5 12 4 11 3 10 2 9 1 8 0)
  49. (15 11 14 10 13 9 12 8 7 3 6 2 5 1 4 0)
  50. (15 13 14 12 7 5 6 4 11 9 10 8 3 1 2 0)
  51. (15 13 14 12 11 9 10 8 7 5 6 4 3 1 2 0)
  52. (15 14 7 6 11 10 3 2 13 12 5 4 9 8 1 0)
  53. (15 14 11 10 7 6 3 2 13 12 9 8 5 4 1 0)
  54. (15 14 7 6 13 12 5 4 11 10 3 2 9 8 1 0)
  55. (15 14 11 10 13 12 9 8 7 6 3 2 5 4 1 0)
  56. (15 14 13 12 7 6 5 4 11 10 9 8 3 2 1 0)))
  57. (RPAQQ FOLD4S ((7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8)
  58. (11 10 9 8 15 14 13 12 3 2 1 0 7 6 5 4)
  59. (13 12 15 14 9 8 11 10 5 4 7 6 1 0 3 2)
  60. (14 15 12 13 10 11 8 9 6 7 4 5 2 3 0 1)))
  61. (DEFINEQ
  62. (ALLPERMS
  63. (GLAMBDA (N:INTEGER) (* edited: "27-DEC-82 15:36")
  64. (* Generate a list of all permutations of length N.
  65. The identity permutation is always the first member of
  66. the list.)
  67. (RESULT (LISTOF PERMUTATION))
  68. (DECLARE (SPECVARS LST))
  69. (PROG (LST)
  70. (IF N>5 (ERROR "TOO MANY PERMUTATIONS!"))
  71. (GENPERMS NIL (IDPERM N))
  72. (RETURN LST))))
  73. (BINLIST
  74. (GLAMBDA (N,NBITS:INTEGER) (* edited: "28-DEC-82 11:26")
  75. (* Convert N to a list of bit values.)
  76. (RESULT (LISTOF INTEGER))
  77. (PROG (L I BIT)
  78. (I_0)
  79. (BIT_1)
  80. (WHILE I<NBITS DO (L+_(IF (LOGAND N BIT)=0
  81. THEN 0
  82. ELSE 1))
  83. (I_+1)
  84. (BIT_+BIT))
  85. (RETURN L))))
  86. (BITSHUFFLE
  87. [LAMBDA (INPUT LST) (* edited: " 6-MAY-82 16:33")
  88. (* Compute a bit-shuffle of the input according to the specification list LST. LST gives, for each output bit in
  89. order, the input bit from which it comes.)
  90. (PROG (RES)
  91. (SETQ RES 0)
  92. [MAPC LST (FUNCTION (LAMBDA (X)
  93. (SETQ RES (IPLUS (IPLUS RES RES)
  94. (COND
  95. ((NULL X)
  96. 0)
  97. ((NOT (NUMBERP X))
  98. 1)
  99. ((ZEROP (LOGAND INPUT (BITPICK X)))
  100. 0)
  101. (T 1]
  102. (RETURN RES])
  103. (COMPOSEBITSHUFFLES
  104. [LAMBDA (FIRST SECOND) (* edited: "23-JUN-82 15:17")
  105. (* Compose two bitshuffles to produce a single
  106. bitshuffle which is equivalent.)
  107. (PROG (L)
  108. (COND
  109. ((NOT (EQUAL (SETQ L (LENGTH FIRST))
  110. (LENGTH SECOND)))
  111. (ERROR)))
  112. (RETURN (MAPCAR SECOND (FUNCTION (LAMBDA (X)
  113. (COND
  114. [(FIXP X)
  115. (CAR (NTH FIRST (IDIFFERENCE L X]
  116. (T X])
  117. (DOBITSHUFFLE
  118. [LAMBDA (INT PERM) (* edited: "27-DEC-82 15:44")
  119. (BITSHUFFLE INT PERM])
  120. (GENPERMS
  121. [GLAMBDA (PREV,L:(LISTOF INTEGER)) (* edited: "27-DEC-82 15:38")
  122. (* Generate all permutations consisting of the list PREV followed by all permutations of the list L.
  123. The permutations which are generated are added to the global LST. Called by ALLPERMS.)
  124. (GLOBAL LST:(LISTOF PERMUTATION))
  125. (PROG (I TMP N)
  126. (IF ~L
  127. THEN LST+_PREV
  128. (RETURN))
  129. (N_(LENGTH L))
  130. (I_0)
  131. (WHILE (I_+1)
  132. <=N DO (TMP_(CAR (NTH L I)))
  133. (GENPERMS (PREV+TMP)
  134. (L - TMP])
  135. (HISTO-ADD
  136. (GLAMBDA (H:HISTOGRAM N:INTEGER) (* edited: "30-DEC-82 13:26")
  137. (IF N>MAX OR N<MIN
  138. THEN (ERROR)
  139. ELSE TOTAL_+1
  140. (CAR (NTH COUNTS (N - MIN + 1)))_+1)
  141. H))
  142. (HISTO-CREATE
  143. (GLAMBDA (H:HISTOGRAM) (* edited: " 2-JAN-83 14:14")
  144. (RESULT HISTOGRAM) (* Initialize a histogram.)
  145. (TOTAL_0)
  146. (COUNTS_(LISTOFC 0 (MAX - MIN + 1)))
  147. H))
  148. (HISTO-PEAKS
  149. [GLAMBDA (H:HISTOGRAM) (* edited: " 2-JAN-83 14:10")
  150. (PROG (THRESH L MX N)
  151. (MX_0)
  152. (FOR X IN COUNTS (IF X>MX MX_X))
  153. (THRESH_MX/2)
  154. (N_MIN)
  155. (FOR X IN COUNTS DO (IF X>=THRESH L+_N)
  156. N_+1)
  157. (RETURN (DREVERSE L])
  158. (IDPERM
  159. (GLAMBDA (N:INTEGER) (* edited: "28-DEC-82 11:23")
  160. (* Produce an identity permutation of length N.)
  161. (RESULT PERMUTATION)
  162. (PROG (L (I 0))
  163. (WHILE I<N L+_I
  164. I_+1)
  165. (RETURN L))))
  166. (LISTOFC
  167. (GLAMBDA (C N:INTEGER) (* edited: "28-DEC-82 11:23")
  168. (* Make a list of N copies of the constant C.)
  169. (RESULT (LISTOF ATOM))
  170. (PROG (I L)
  171. (I_0)
  172. (WHILE (I_+1)
  173. <=N DO L+_C)
  174. (RETURN L))))
  175. (LOG2
  176. (GLAMBDA (N:INTEGER) (* edited: "28-DEC-82 11:07")
  177. (* Log to the base 2 of an integer, rounded up.)
  178. (RESULT INTEGER)
  179. (PROG ((I 0)
  180. (M 1))
  181. (WHILE M<N DO I_+1
  182. M_+M)
  183. (RETURN I))))
  184. (NEGINPPERM
  185. (GLAMBDA (N,M:INTEGER) (* edited: "28-DEC-82 11:03")
  186. (* Compute the permutation to be applied to the output
  187. of a boolean function of N inputs to account for
  188. negating the Mth input.)
  189. (RESULT PERMUTATION)
  190. (PROG (TWON TWOM (I 0)
  191. L)
  192. (TWON_2^N)
  193. (TWOM_2^M)
  194. (WHILE I<TWON L+_(IF (LOGAND I TWOM)
  195. ~=0
  196. THEN I - TWOM
  197. ELSE I+TWOM)
  198. I_+1)
  199. (RETURN L))))
  200. (OUTPERMS
  201. (GLAMBDA (N:INTEGER) (* edited: "28-DEC-82 11:02")
  202. (* Create the set of permutations of the set of 2^N outputs corresponding to isomorphisms, i.e., renamings of the
  203. N inputs of a boolean function. The identity isomorphism is omitted.)
  204. (RESULT (LISTOF PERMUTATION))
  205. (PROG (I TMP RES TWON)
  206. (TWON_2^N)
  207. (FOR X IN (CDR (ALLPERMS N)) DO (I_0)
  208. (TMP_NIL)
  209. (WHILE I<TWON DO (TMP+_(DOBITSHUFFLE I X))
  210. (I_+1))
  211. (RES+_TMP))
  212. (RETURN RES))))
  213. (PERM-INVERSE
  214. (GLAMBDA (P:PERMUTATION) (* edited: " 2-SEP-82 10:47")
  215. (RESULT PERMUTATION) (* edited: " 2-SEP-82 10:44")
  216. (* Compute the inverse of a permutation.)
  217. (PROG (LST N M (I 0)
  218. J PP TMP)
  219. (N_P:LENGTH)
  220. (WHILE I<N DO (J _ N - 1)
  221. (PP_P)
  222. [WHILE PP DO (IF (CAR PP)=I
  223. THEN LST+_J
  224. PP_NIL
  225. ELSE TMP-_PP
  226. J_-1
  227. (IF ~PP (ERROR]
  228. (I_+1))
  229. (RETURN LST))))
  230. )
  231. (PUTPROPS BITSHUFFLE GLRESULTTYPE INTEGER)
  232. (PUTPROPS DOBITSHUFFLE GLRESULTTYPE INTEGER)
  233. (DECLARE: DONTCOPY
  234. (FILEMAP (NIL (2528 9147 (ALLPERMS 2538 . 3071) (BINLIST 3073 . 3528) (BITSHUFFLE 3530 . 4122) (
  235. COMPOSEBITSHUFFLES 4124 . 4654) (DOBITSHUFFLE 4656 . 4799) (GENPERMS 4801 . 5395) (HISTO-ADD 5397 .
  236. 5635) (HISTO-CREATE 5637 . 5902) (HISTO-PEAKS 5904 . 6268) (IDPERM 6270 . 6598) (LISTOFC 6600 . 6950)
  237. (LOG2 6952 . 7296) (NEGINPPERM 7298 . 7897) (OUTPERMS 7899 . 8504) (PERM-INVERSE 8506 . 9145)))))
  238. STOP