test_coset_table.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. from sympy.combinatorics.fp_groups import FpGroup
  2. from sympy.combinatorics.coset_table import (CosetTable,
  3. coset_enumeration_r, coset_enumeration_c)
  4. from sympy.combinatorics.coset_table import modified_coset_enumeration_r
  5. from sympy.combinatorics.free_groups import free_group
  6. from sympy.testing.pytest import slow
  7. """
  8. References
  9. ==========
  10. [1] Holt, D., Eick, B., O'Brien, E.
  11. "Handbook of Computational Group Theory"
  12. [2] John J. Cannon; Lucien A. Dimino; George Havas; Jane M. Watson
  13. Mathematics of Computation, Vol. 27, No. 123. (Jul., 1973), pp. 463-490.
  14. "Implementation and Analysis of the Todd-Coxeter Algorithm"
  15. """
  16. def test_scan_1():
  17. # Example 5.1 from [1]
  18. F, x, y = free_group("x, y")
  19. f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y])
  20. c = CosetTable(f, [x])
  21. c.scan_and_fill(0, x)
  22. assert c.table == [[0, 0, None, None]]
  23. assert c.p == [0]
  24. assert c.n == 1
  25. assert c.omega == [0]
  26. c.scan_and_fill(0, x**3)
  27. assert c.table == [[0, 0, None, None]]
  28. assert c.p == [0]
  29. assert c.n == 1
  30. assert c.omega == [0]
  31. c.scan_and_fill(0, y**3)
  32. assert c.table == [[0, 0, 1, 2], [None, None, 2, 0], [None, None, 0, 1]]
  33. assert c.p == [0, 1, 2]
  34. assert c.n == 3
  35. assert c.omega == [0, 1, 2]
  36. c.scan_and_fill(0, x**-1*y**-1*x*y)
  37. assert c.table == [[0, 0, 1, 2], [None, None, 2, 0], [2, 2, 0, 1]]
  38. assert c.p == [0, 1, 2]
  39. assert c.n == 3
  40. assert c.omega == [0, 1, 2]
  41. c.scan_and_fill(1, x**3)
  42. assert c.table == [[0, 0, 1, 2], [3, 4, 2, 0], [2, 2, 0, 1], \
  43. [4, 1, None, None], [1, 3, None, None]]
  44. assert c.p == [0, 1, 2, 3, 4]
  45. assert c.n == 5
  46. assert c.omega == [0, 1, 2, 3, 4]
  47. c.scan_and_fill(1, y**3)
  48. assert c.table == [[0, 0, 1, 2], [3, 4, 2, 0], [2, 2, 0, 1], \
  49. [4, 1, None, None], [1, 3, None, None]]
  50. assert c.p == [0, 1, 2, 3, 4]
  51. assert c.n == 5
  52. assert c.omega == [0, 1, 2, 3, 4]
  53. c.scan_and_fill(1, x**-1*y**-1*x*y)
  54. assert c.table == [[0, 0, 1, 2], [1, 1, 2, 0], [2, 2, 0, 1], \
  55. [None, 1, None, None], [1, 3, None, None]]
  56. assert c.p == [0, 1, 2, 1, 1]
  57. assert c.n == 3
  58. assert c.omega == [0, 1, 2]
  59. # Example 5.2 from [1]
  60. f = FpGroup(F, [x**2, y**3, (x*y)**3])
  61. c = CosetTable(f, [x*y])
  62. c.scan_and_fill(0, x*y)
  63. assert c.table == [[1, None, None, 1], [None, 0, 0, None]]
  64. assert c.p == [0, 1]
  65. assert c.n == 2
  66. assert c.omega == [0, 1]
  67. c.scan_and_fill(0, x**2)
  68. assert c.table == [[1, 1, None, 1], [0, 0, 0, None]]
  69. assert c.p == [0, 1]
  70. assert c.n == 2
  71. assert c.omega == [0, 1]
  72. c.scan_and_fill(0, y**3)
  73. assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]]
  74. assert c.p == [0, 1, 2]
  75. assert c.n == 3
  76. assert c.omega == [0, 1, 2]
  77. c.scan_and_fill(0, (x*y)**3)
  78. assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]]
  79. assert c.p == [0, 1, 2]
  80. assert c.n == 3
  81. assert c.omega == [0, 1, 2]
  82. c.scan_and_fill(1, x**2)
  83. assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]]
  84. assert c.p == [0, 1, 2]
  85. assert c.n == 3
  86. assert c.omega == [0, 1, 2]
  87. c.scan_and_fill(1, y**3)
  88. assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [None, None, 1, 0]]
  89. assert c.p == [0, 1, 2]
  90. assert c.n == 3
  91. assert c.omega == [0, 1, 2]
  92. c.scan_and_fill(1, (x*y)**3)
  93. assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [3, 4, 1, 0], [None, 2, 4, None], [2, None, None, 3]]
  94. assert c.p == [0, 1, 2, 3, 4]
  95. assert c.n == 5
  96. assert c.omega == [0, 1, 2, 3, 4]
  97. c.scan_and_fill(2, x**2)
  98. assert c.table == [[1, 1, 2, 1], [0, 0, 0, 2], [3, 3, 1, 0], [2, 2, 3, 3], [2, None, None, 3]]
  99. assert c.p == [0, 1, 2, 3, 3]
  100. assert c.n == 4
  101. assert c.omega == [0, 1, 2, 3]
  102. @slow
  103. def test_coset_enumeration():
  104. # this test function contains the combined tests for the two strategies
  105. # i.e. HLT and Felsch strategies.
  106. # Example 5.1 from [1]
  107. F, x, y = free_group("x, y")
  108. f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y])
  109. C_r = coset_enumeration_r(f, [x])
  110. C_r.compress(); C_r.standardize()
  111. C_c = coset_enumeration_c(f, [x])
  112. C_c.compress(); C_c.standardize()
  113. table1 = [[0, 0, 1, 2], [1, 1, 2, 0], [2, 2, 0, 1]]
  114. assert C_r.table == table1
  115. assert C_c.table == table1
  116. # E1 from [2] Pg. 474
  117. F, r, s, t = free_group("r, s, t")
  118. E1 = FpGroup(F, [t**-1*r*t*r**-2, r**-1*s*r*s**-2, s**-1*t*s*t**-2])
  119. C_r = coset_enumeration_r(E1, [])
  120. C_r.compress()
  121. C_c = coset_enumeration_c(E1, [])
  122. C_c.compress()
  123. table2 = [[0, 0, 0, 0, 0, 0]]
  124. assert C_r.table == table2
  125. # test for issue #11449
  126. assert C_c.table == table2
  127. # Cox group from [2] Pg. 474
  128. F, a, b = free_group("a, b")
  129. Cox = FpGroup(F, [a**6, b**6, (a*b)**2, (a**2*b**2)**2, (a**3*b**3)**5])
  130. C_r = coset_enumeration_r(Cox, [a])
  131. C_r.compress(); C_r.standardize()
  132. C_c = coset_enumeration_c(Cox, [a])
  133. C_c.compress(); C_c.standardize()
  134. table3 = [[0, 0, 1, 2],
  135. [2, 3, 4, 0],
  136. [5, 1, 0, 6],
  137. [1, 7, 8, 9],
  138. [9, 10, 11, 1],
  139. [12, 2, 9, 13],
  140. [14, 9, 2, 11],
  141. [3, 12, 15, 16],
  142. [16, 17, 18, 3],
  143. [6, 4, 3, 5],
  144. [4, 19, 20, 21],
  145. [21, 22, 6, 4],
  146. [7, 5, 23, 24],
  147. [25, 23, 5, 18],
  148. [19, 6, 22, 26],
  149. [24, 27, 28, 7],
  150. [29, 8, 7, 30],
  151. [8, 31, 32, 33],
  152. [33, 34, 13, 8],
  153. [10, 14, 35, 35],
  154. [35, 36, 37, 10],
  155. [30, 11, 10, 29],
  156. [11, 38, 39, 14],
  157. [13, 39, 38, 12],
  158. [40, 15, 12, 41],
  159. [42, 13, 34, 43],
  160. [44, 35, 14, 45],
  161. [15, 46, 47, 34],
  162. [34, 48, 49, 15],
  163. [50, 16, 21, 51],
  164. [52, 21, 16, 49],
  165. [17, 50, 53, 54],
  166. [54, 55, 56, 17],
  167. [41, 18, 17, 40],
  168. [18, 28, 27, 25],
  169. [26, 20, 19, 19],
  170. [20, 57, 58, 59],
  171. [59, 60, 51, 20],
  172. [22, 52, 61, 23],
  173. [23, 62, 63, 22],
  174. [64, 24, 33, 65],
  175. [48, 33, 24, 61],
  176. [62, 25, 54, 66],
  177. [67, 54, 25, 68],
  178. [57, 26, 59, 69],
  179. [70, 59, 26, 63],
  180. [27, 64, 71, 72],
  181. [72, 73, 68, 27],
  182. [28, 41, 74, 75],
  183. [75, 76, 30, 28],
  184. [31, 29, 77, 78],
  185. [79, 77, 29, 37],
  186. [38, 30, 76, 80],
  187. [78, 81, 82, 31],
  188. [43, 32, 31, 42],
  189. [32, 83, 84, 85],
  190. [85, 86, 65, 32],
  191. [36, 44, 87, 88],
  192. [88, 89, 90, 36],
  193. [45, 37, 36, 44],
  194. [37, 82, 81, 79],
  195. [80, 74, 41, 38],
  196. [39, 42, 91, 92],
  197. [92, 93, 45, 39],
  198. [46, 40, 94, 95],
  199. [96, 94, 40, 56],
  200. [97, 91, 42, 82],
  201. [83, 43, 98, 99],
  202. [100, 98, 43, 47],
  203. [101, 87, 44, 90],
  204. [82, 45, 93, 97],
  205. [95, 102, 103, 46],
  206. [104, 47, 46, 105],
  207. [47, 106, 107, 100],
  208. [61, 108, 109, 48],
  209. [105, 49, 48, 104],
  210. [49, 110, 111, 52],
  211. [51, 111, 110, 50],
  212. [112, 53, 50, 113],
  213. [114, 51, 60, 115],
  214. [116, 61, 52, 117],
  215. [53, 118, 119, 60],
  216. [60, 70, 66, 53],
  217. [55, 67, 120, 121],
  218. [121, 122, 123, 55],
  219. [113, 56, 55, 112],
  220. [56, 103, 102, 96],
  221. [69, 124, 125, 57],
  222. [115, 58, 57, 114],
  223. [58, 126, 127, 128],
  224. [128, 128, 69, 58],
  225. [66, 129, 130, 62],
  226. [117, 63, 62, 116],
  227. [63, 125, 124, 70],
  228. [65, 109, 108, 64],
  229. [131, 71, 64, 132],
  230. [133, 65, 86, 134],
  231. [135, 66, 70, 136],
  232. [68, 130, 129, 67],
  233. [137, 120, 67, 138],
  234. [132, 68, 73, 131],
  235. [139, 69, 128, 140],
  236. [71, 141, 142, 86],
  237. [86, 143, 144, 71],
  238. [145, 72, 75, 146],
  239. [147, 75, 72, 144],
  240. [73, 145, 148, 120],
  241. [120, 149, 150, 73],
  242. [74, 151, 152, 94],
  243. [94, 153, 146, 74],
  244. [76, 147, 154, 77],
  245. [77, 155, 156, 76],
  246. [157, 78, 85, 158],
  247. [143, 85, 78, 154],
  248. [155, 79, 88, 159],
  249. [160, 88, 79, 161],
  250. [151, 80, 92, 162],
  251. [163, 92, 80, 156],
  252. [81, 157, 164, 165],
  253. [165, 166, 161, 81],
  254. [99, 107, 106, 83],
  255. [134, 84, 83, 133],
  256. [84, 167, 168, 169],
  257. [169, 170, 158, 84],
  258. [87, 171, 172, 93],
  259. [93, 163, 159, 87],
  260. [89, 160, 173, 174],
  261. [174, 175, 176, 89],
  262. [90, 90, 89, 101],
  263. [91, 177, 178, 98],
  264. [98, 179, 162, 91],
  265. [180, 95, 100, 181],
  266. [179, 100, 95, 152],
  267. [153, 96, 121, 148],
  268. [182, 121, 96, 183],
  269. [177, 97, 165, 184],
  270. [185, 165, 97, 172],
  271. [186, 99, 169, 187],
  272. [188, 169, 99, 178],
  273. [171, 101, 174, 189],
  274. [190, 174, 101, 176],
  275. [102, 180, 191, 192],
  276. [192, 193, 183, 102],
  277. [103, 113, 194, 195],
  278. [195, 196, 105, 103],
  279. [106, 104, 197, 198],
  280. [199, 197, 104, 109],
  281. [110, 105, 196, 200],
  282. [198, 201, 133, 106],
  283. [107, 186, 202, 203],
  284. [203, 204, 181, 107],
  285. [108, 116, 205, 206],
  286. [206, 207, 132, 108],
  287. [109, 133, 201, 199],
  288. [200, 194, 113, 110],
  289. [111, 114, 208, 209],
  290. [209, 210, 117, 111],
  291. [118, 112, 211, 212],
  292. [213, 211, 112, 123],
  293. [214, 208, 114, 125],
  294. [126, 115, 215, 216],
  295. [217, 215, 115, 119],
  296. [218, 205, 116, 130],
  297. [125, 117, 210, 214],
  298. [212, 219, 220, 118],
  299. [136, 119, 118, 135],
  300. [119, 221, 222, 217],
  301. [122, 182, 223, 224],
  302. [224, 225, 226, 122],
  303. [138, 123, 122, 137],
  304. [123, 220, 219, 213],
  305. [124, 139, 227, 228],
  306. [228, 229, 136, 124],
  307. [216, 222, 221, 126],
  308. [140, 127, 126, 139],
  309. [127, 230, 231, 232],
  310. [232, 233, 140, 127],
  311. [129, 135, 234, 235],
  312. [235, 236, 138, 129],
  313. [130, 132, 207, 218],
  314. [141, 131, 237, 238],
  315. [239, 237, 131, 150],
  316. [167, 134, 240, 241],
  317. [242, 240, 134, 142],
  318. [243, 234, 135, 220],
  319. [221, 136, 229, 244],
  320. [149, 137, 245, 246],
  321. [247, 245, 137, 226],
  322. [220, 138, 236, 243],
  323. [244, 227, 139, 221],
  324. [230, 140, 233, 248],
  325. [238, 249, 250, 141],
  326. [251, 142, 141, 252],
  327. [142, 253, 254, 242],
  328. [154, 255, 256, 143],
  329. [252, 144, 143, 251],
  330. [144, 257, 258, 147],
  331. [146, 258, 257, 145],
  332. [259, 148, 145, 260],
  333. [261, 146, 153, 262],
  334. [263, 154, 147, 264],
  335. [148, 265, 266, 153],
  336. [246, 267, 268, 149],
  337. [260, 150, 149, 259],
  338. [150, 250, 249, 239],
  339. [162, 269, 270, 151],
  340. [262, 152, 151, 261],
  341. [152, 271, 272, 179],
  342. [159, 273, 274, 155],
  343. [264, 156, 155, 263],
  344. [156, 270, 269, 163],
  345. [158, 256, 255, 157],
  346. [275, 164, 157, 276],
  347. [277, 158, 170, 278],
  348. [279, 159, 163, 280],
  349. [161, 274, 273, 160],
  350. [281, 173, 160, 282],
  351. [276, 161, 166, 275],
  352. [283, 162, 179, 284],
  353. [164, 285, 286, 170],
  354. [170, 188, 184, 164],
  355. [166, 185, 189, 173],
  356. [173, 287, 288, 166],
  357. [241, 254, 253, 167],
  358. [278, 168, 167, 277],
  359. [168, 289, 290, 291],
  360. [291, 292, 187, 168],
  361. [189, 293, 294, 171],
  362. [280, 172, 171, 279],
  363. [172, 295, 296, 185],
  364. [175, 190, 297, 297],
  365. [297, 298, 299, 175],
  366. [282, 176, 175, 281],
  367. [176, 294, 293, 190],
  368. [184, 296, 295, 177],
  369. [284, 178, 177, 283],
  370. [178, 300, 301, 188],
  371. [181, 272, 271, 180],
  372. [302, 191, 180, 303],
  373. [304, 181, 204, 305],
  374. [183, 266, 265, 182],
  375. [306, 223, 182, 307],
  376. [303, 183, 193, 302],
  377. [308, 184, 188, 309],
  378. [310, 189, 185, 311],
  379. [187, 301, 300, 186],
  380. [305, 202, 186, 304],
  381. [312, 187, 292, 313],
  382. [314, 297, 190, 315],
  383. [191, 316, 317, 204],
  384. [204, 318, 319, 191],
  385. [320, 192, 195, 321],
  386. [322, 195, 192, 319],
  387. [193, 320, 323, 223],
  388. [223, 324, 325, 193],
  389. [194, 326, 327, 211],
  390. [211, 328, 321, 194],
  391. [196, 322, 329, 197],
  392. [197, 330, 331, 196],
  393. [332, 198, 203, 333],
  394. [318, 203, 198, 329],
  395. [330, 199, 206, 334],
  396. [335, 206, 199, 336],
  397. [326, 200, 209, 337],
  398. [338, 209, 200, 331],
  399. [201, 332, 339, 240],
  400. [240, 340, 336, 201],
  401. [202, 341, 342, 292],
  402. [292, 343, 333, 202],
  403. [205, 344, 345, 210],
  404. [210, 338, 334, 205],
  405. [207, 335, 346, 237],
  406. [237, 347, 348, 207],
  407. [208, 349, 350, 215],
  408. [215, 351, 337, 208],
  409. [352, 212, 217, 353],
  410. [351, 217, 212, 327],
  411. [328, 213, 224, 323],
  412. [354, 224, 213, 355],
  413. [349, 214, 228, 356],
  414. [357, 228, 214, 345],
  415. [358, 216, 232, 359],
  416. [360, 232, 216, 350],
  417. [344, 218, 235, 361],
  418. [362, 235, 218, 348],
  419. [219, 352, 363, 364],
  420. [364, 365, 355, 219],
  421. [222, 358, 366, 367],
  422. [367, 368, 353, 222],
  423. [225, 354, 369, 370],
  424. [370, 371, 372, 225],
  425. [307, 226, 225, 306],
  426. [226, 268, 267, 247],
  427. [227, 373, 374, 233],
  428. [233, 360, 356, 227],
  429. [229, 357, 361, 234],
  430. [234, 375, 376, 229],
  431. [248, 231, 230, 230],
  432. [231, 377, 378, 379],
  433. [379, 380, 359, 231],
  434. [236, 362, 381, 245],
  435. [245, 382, 383, 236],
  436. [384, 238, 242, 385],
  437. [340, 242, 238, 346],
  438. [347, 239, 246, 381],
  439. [386, 246, 239, 387],
  440. [388, 241, 291, 389],
  441. [343, 291, 241, 339],
  442. [375, 243, 364, 390],
  443. [391, 364, 243, 383],
  444. [373, 244, 367, 392],
  445. [393, 367, 244, 376],
  446. [382, 247, 370, 394],
  447. [395, 370, 247, 396],
  448. [377, 248, 379, 397],
  449. [398, 379, 248, 374],
  450. [249, 384, 399, 400],
  451. [400, 401, 387, 249],
  452. [250, 260, 402, 403],
  453. [403, 404, 252, 250],
  454. [253, 251, 405, 406],
  455. [407, 405, 251, 256],
  456. [257, 252, 404, 408],
  457. [406, 409, 277, 253],
  458. [254, 388, 410, 411],
  459. [411, 412, 385, 254],
  460. [255, 263, 413, 414],
  461. [414, 415, 276, 255],
  462. [256, 277, 409, 407],
  463. [408, 402, 260, 257],
  464. [258, 261, 416, 417],
  465. [417, 418, 264, 258],
  466. [265, 259, 419, 420],
  467. [421, 419, 259, 268],
  468. [422, 416, 261, 270],
  469. [271, 262, 423, 424],
  470. [425, 423, 262, 266],
  471. [426, 413, 263, 274],
  472. [270, 264, 418, 422],
  473. [420, 427, 307, 265],
  474. [266, 303, 428, 425],
  475. [267, 386, 429, 430],
  476. [430, 431, 396, 267],
  477. [268, 307, 427, 421],
  478. [269, 283, 432, 433],
  479. [433, 434, 280, 269],
  480. [424, 428, 303, 271],
  481. [272, 304, 435, 436],
  482. [436, 437, 284, 272],
  483. [273, 279, 438, 439],
  484. [439, 440, 282, 273],
  485. [274, 276, 415, 426],
  486. [285, 275, 441, 442],
  487. [443, 441, 275, 288],
  488. [289, 278, 444, 445],
  489. [446, 444, 278, 286],
  490. [447, 438, 279, 294],
  491. [295, 280, 434, 448],
  492. [287, 281, 449, 450],
  493. [451, 449, 281, 299],
  494. [294, 282, 440, 447],
  495. [448, 432, 283, 295],
  496. [300, 284, 437, 452],
  497. [442, 453, 454, 285],
  498. [309, 286, 285, 308],
  499. [286, 455, 456, 446],
  500. [450, 457, 458, 287],
  501. [311, 288, 287, 310],
  502. [288, 454, 453, 443],
  503. [445, 456, 455, 289],
  504. [313, 290, 289, 312],
  505. [290, 459, 460, 461],
  506. [461, 462, 389, 290],
  507. [293, 310, 463, 464],
  508. [464, 465, 315, 293],
  509. [296, 308, 466, 467],
  510. [467, 468, 311, 296],
  511. [298, 314, 469, 470],
  512. [470, 471, 472, 298],
  513. [315, 299, 298, 314],
  514. [299, 458, 457, 451],
  515. [452, 435, 304, 300],
  516. [301, 312, 473, 474],
  517. [474, 475, 309, 301],
  518. [316, 302, 476, 477],
  519. [478, 476, 302, 325],
  520. [341, 305, 479, 480],
  521. [481, 479, 305, 317],
  522. [324, 306, 482, 483],
  523. [484, 482, 306, 372],
  524. [485, 466, 308, 454],
  525. [455, 309, 475, 486],
  526. [487, 463, 310, 458],
  527. [454, 311, 468, 485],
  528. [486, 473, 312, 455],
  529. [459, 313, 488, 489],
  530. [490, 488, 313, 342],
  531. [491, 469, 314, 472],
  532. [458, 315, 465, 487],
  533. [477, 492, 485, 316],
  534. [463, 317, 316, 468],
  535. [317, 487, 493, 481],
  536. [329, 447, 464, 318],
  537. [468, 319, 318, 463],
  538. [319, 467, 448, 322],
  539. [321, 448, 467, 320],
  540. [475, 323, 320, 466],
  541. [432, 321, 328, 437],
  542. [438, 329, 322, 434],
  543. [323, 474, 452, 328],
  544. [483, 494, 486, 324],
  545. [466, 325, 324, 475],
  546. [325, 485, 492, 478],
  547. [337, 422, 433, 326],
  548. [437, 327, 326, 432],
  549. [327, 436, 424, 351],
  550. [334, 426, 439, 330],
  551. [434, 331, 330, 438],
  552. [331, 433, 422, 338],
  553. [333, 464, 447, 332],
  554. [449, 339, 332, 440],
  555. [465, 333, 343, 469],
  556. [413, 334, 338, 418],
  557. [336, 439, 426, 335],
  558. [441, 346, 335, 415],
  559. [440, 336, 340, 449],
  560. [416, 337, 351, 423],
  561. [339, 451, 470, 343],
  562. [346, 443, 450, 340],
  563. [480, 493, 487, 341],
  564. [469, 342, 341, 465],
  565. [342, 491, 495, 490],
  566. [361, 407, 414, 344],
  567. [418, 345, 344, 413],
  568. [345, 417, 408, 357],
  569. [381, 446, 442, 347],
  570. [415, 348, 347, 441],
  571. [348, 414, 407, 362],
  572. [356, 408, 417, 349],
  573. [423, 350, 349, 416],
  574. [350, 425, 420, 360],
  575. [353, 424, 436, 352],
  576. [479, 363, 352, 435],
  577. [428, 353, 368, 476],
  578. [355, 452, 474, 354],
  579. [488, 369, 354, 473],
  580. [435, 355, 365, 479],
  581. [402, 356, 360, 419],
  582. [405, 361, 357, 404],
  583. [359, 420, 425, 358],
  584. [476, 366, 358, 428],
  585. [427, 359, 380, 482],
  586. [444, 381, 362, 409],
  587. [363, 481, 477, 368],
  588. [368, 393, 390, 363],
  589. [365, 391, 394, 369],
  590. [369, 490, 480, 365],
  591. [366, 478, 483, 380],
  592. [380, 398, 392, 366],
  593. [371, 395, 496, 497],
  594. [497, 498, 489, 371],
  595. [473, 372, 371, 488],
  596. [372, 486, 494, 484],
  597. [392, 400, 403, 373],
  598. [419, 374, 373, 402],
  599. [374, 421, 430, 398],
  600. [390, 411, 406, 375],
  601. [404, 376, 375, 405],
  602. [376, 403, 400, 393],
  603. [397, 430, 421, 377],
  604. [482, 378, 377, 427],
  605. [378, 484, 497, 499],
  606. [499, 499, 397, 378],
  607. [394, 461, 445, 382],
  608. [409, 383, 382, 444],
  609. [383, 406, 411, 391],
  610. [385, 450, 443, 384],
  611. [492, 399, 384, 453],
  612. [457, 385, 412, 493],
  613. [387, 442, 446, 386],
  614. [494, 429, 386, 456],
  615. [453, 387, 401, 492],
  616. [389, 470, 451, 388],
  617. [493, 410, 388, 457],
  618. [471, 389, 462, 495],
  619. [412, 390, 393, 399],
  620. [462, 394, 391, 410],
  621. [401, 392, 398, 429],
  622. [396, 445, 461, 395],
  623. [498, 496, 395, 460],
  624. [456, 396, 431, 494],
  625. [431, 397, 499, 496],
  626. [399, 477, 481, 412],
  627. [429, 483, 478, 401],
  628. [410, 480, 490, 462],
  629. [496, 497, 484, 431],
  630. [489, 495, 491, 459],
  631. [495, 460, 459, 471],
  632. [460, 489, 498, 498],
  633. [472, 472, 471, 491]]
  634. assert C_r.table == table3
  635. assert C_c.table == table3
  636. # Group denoted by B2,4 from [2] Pg. 474
  637. F, a, b = free_group("a, b")
  638. B_2_4 = FpGroup(F, [a**4, b**4, (a*b)**4, (a**-1*b)**4, (a**2*b)**4, \
  639. (a*b**2)**4, (a**2*b**2)**4, (a**-1*b*a*b)**4, (a*b**-1*a*b)**4])
  640. C_r = coset_enumeration_r(B_2_4, [a])
  641. C_c = coset_enumeration_c(B_2_4, [a])
  642. index_r = 0
  643. for i in range(len(C_r.p)):
  644. if C_r.p[i] == i:
  645. index_r += 1
  646. assert index_r == 1024
  647. index_c = 0
  648. for i in range(len(C_c.p)):
  649. if C_c.p[i] == i:
  650. index_c += 1
  651. assert index_c == 1024
  652. # trivial Macdonald group G(2,2) from [2] Pg. 480
  653. M = FpGroup(F, [b**-1*a**-1*b*a*b**-1*a*b*a**-2, a**-1*b**-1*a*b*a**-1*b*a*b**-2])
  654. C_r = coset_enumeration_r(M, [a])
  655. C_r.compress(); C_r.standardize()
  656. C_c = coset_enumeration_c(M, [a])
  657. C_c.compress(); C_c.standardize()
  658. table4 = [[0, 0, 0, 0]]
  659. assert C_r.table == table4
  660. assert C_c.table == table4
  661. def test_look_ahead():
  662. # Section 3.2 [Test Example] Example (d) from [2]
  663. F, a, b, c = free_group("a, b, c")
  664. f = FpGroup(F, [a**11, b**5, c**4, (a*c)**3, b**2*c**-1*b**-1*c, a**4*b**-1*a**-1*b])
  665. H = [c, b, c**2]
  666. table0 = [[1, 2, 0, 0, 0, 0],
  667. [3, 0, 4, 5, 6, 7],
  668. [0, 8, 9, 10, 11, 12],
  669. [5, 1, 10, 13, 14, 15],
  670. [16, 5, 16, 1, 17, 18],
  671. [4, 3, 1, 8, 19, 20],
  672. [12, 21, 22, 23, 24, 1],
  673. [25, 26, 27, 28, 1, 24],
  674. [2, 10, 5, 16, 22, 28],
  675. [10, 13, 13, 2, 29, 30]]
  676. CosetTable.max_stack_size = 10
  677. C_c = coset_enumeration_c(f, H)
  678. C_c.compress(); C_c.standardize()
  679. assert C_c.table[: 10] == table0
  680. def test_modified_methods():
  681. '''
  682. Tests for modified coset table methods.
  683. Example 5.7 from [1] Holt, D., Eick, B., O'Brien
  684. "Handbook of Computational Group Theory".
  685. '''
  686. F, x, y = free_group("x, y")
  687. f = FpGroup(F, [x**3, y**5, (x*y)**2])
  688. H = [x*y, x**-1*y**-1*x*y*x]
  689. C = CosetTable(f, H)
  690. C.modified_define(0, x)
  691. identity = C._grp.identity
  692. a_0 = C._grp.generators[0]
  693. a_1 = C._grp.generators[1]
  694. assert C.P == [[identity, None, None, None],
  695. [None, identity, None, None]]
  696. assert C.table == [[1, None, None, None],
  697. [None, 0, None, None]]
  698. C.modified_define(1, x)
  699. assert C.table == [[1, None, None, None],
  700. [2, 0, None, None],
  701. [None, 1, None, None]]
  702. assert C.P == [[identity, None, None, None],
  703. [identity, identity, None, None],
  704. [None, identity, None, None]]
  705. C.modified_scan(0, x**3, C._grp.identity, fill=False)
  706. assert C.P == [[identity, identity, None, None],
  707. [identity, identity, None, None],
  708. [identity, identity, None, None]]
  709. assert C.table == [[1, 2, None, None],
  710. [2, 0, None, None],
  711. [0, 1, None, None]]
  712. C.modified_scan(0, x*y, C._grp.generators[0], fill=False)
  713. assert C.P == [[identity, identity, None, a_0**-1],
  714. [identity, identity, a_0, None],
  715. [identity, identity, None, None]]
  716. assert C.table == [[1, 2, None, 1],
  717. [2, 0, 0, None],
  718. [0, 1, None, None]]
  719. C.modified_define(2, y**-1)
  720. assert C.table == [[1, 2, None, 1],
  721. [2, 0, 0, None],
  722. [0, 1, None, 3],
  723. [None, None, 2, None]]
  724. assert C.P == [[identity, identity, None, a_0**-1],
  725. [identity, identity, a_0, None],
  726. [identity, identity, None, identity],
  727. [None, None, identity, None]]
  728. C.modified_scan(0, x**-1*y**-1*x*y*x, C._grp.generators[1])
  729. assert C.table == [[1, 2, None, 1],
  730. [2, 0, 0, None],
  731. [0, 1, None, 3],
  732. [3, 3, 2, None]]
  733. assert C.P == [[identity, identity, None, a_0**-1],
  734. [identity, identity, a_0, None],
  735. [identity, identity, None, identity],
  736. [a_1, a_1**-1, identity, None]]
  737. C.modified_scan(2, (x*y)**2, C._grp.identity)
  738. assert C.table == [[1, 2, 3, 1],
  739. [2, 0, 0, None],
  740. [0, 1, None, 3],
  741. [3, 3, 2, 0]]
  742. assert C.P == [[identity, identity, a_1**-1, a_0**-1],
  743. [identity, identity, a_0, None],
  744. [identity, identity, None, identity],
  745. [a_1, a_1**-1, identity, a_1]]
  746. C.modified_define(2, y)
  747. assert C.table == [[1, 2, 3, 1],
  748. [2, 0, 0, None],
  749. [0, 1, 4, 3],
  750. [3, 3, 2, 0],
  751. [None, None, None, 2]]
  752. assert C.P == [[identity, identity, a_1**-1, a_0**-1],
  753. [identity, identity, a_0, None],
  754. [identity, identity, identity, identity],
  755. [a_1, a_1**-1, identity, a_1],
  756. [None, None, None, identity]]
  757. C.modified_scan(0, y**5, C._grp.identity)
  758. assert C.table == [[1, 2, 3, 1], [2, 0, 0, 4], [0, 1, 4, 3], [3, 3, 2, 0], [None, None, 1, 2]]
  759. assert C.P == [[identity, identity, a_1**-1, a_0**-1],
  760. [identity, identity, a_0, a_0*a_1**-1],
  761. [identity, identity, identity, identity],
  762. [a_1, a_1**-1, identity, a_1],
  763. [None, None, a_1*a_0**-1, identity]]
  764. C.modified_scan(1, (x*y)**2, C._grp.identity)
  765. assert C.table == [[1, 2, 3, 1],
  766. [2, 0, 0, 4],
  767. [0, 1, 4, 3],
  768. [3, 3, 2, 0],
  769. [4, 4, 1, 2]]
  770. assert C.P == [[identity, identity, a_1**-1, a_0**-1],
  771. [identity, identity, a_0, a_0*a_1**-1],
  772. [identity, identity, identity, identity],
  773. [a_1, a_1**-1, identity, a_1],
  774. [a_0*a_1**-1, a_1*a_0**-1, a_1*a_0**-1, identity]]
  775. # Modified coset enumeration test
  776. f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y])
  777. C = coset_enumeration_r(f, [x])
  778. C_m = modified_coset_enumeration_r(f, [x])
  779. assert C_m.table == C.table