galois.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. r"""
  2. Construct transitive subgroups of symmetric groups, useful in Galois theory.
  3. Besides constructing instances of the :py:class:`~.PermutationGroup` class to
  4. represent the transitive subgroups of $S_n$ for small $n$, this module provides
  5. *names* for these groups.
  6. In some applications, it may be preferable to know the name of a group,
  7. rather than receive an instance of the :py:class:`~.PermutationGroup`
  8. class, and then have to do extra work to determine which group it is, by
  9. checking various properties.
  10. Names are instances of ``Enum`` classes defined in this module. With a name in
  11. hand, the name's ``get_perm_group`` method can then be used to retrieve a
  12. :py:class:`~.PermutationGroup`.
  13. The names used for groups in this module are taken from [1].
  14. References
  15. ==========
  16. .. [1] Cohen, H. *A Course in Computational Algebraic Number Theory*.
  17. """
  18. from collections import defaultdict
  19. from enum import Enum
  20. import itertools
  21. from sympy.combinatorics.named_groups import (
  22. SymmetricGroup, AlternatingGroup, CyclicGroup, DihedralGroup,
  23. set_symmetric_group_properties, set_alternating_group_properties,
  24. )
  25. from sympy.combinatorics.perm_groups import PermutationGroup
  26. from sympy.combinatorics.permutations import Permutation
  27. class S1TransitiveSubgroups(Enum):
  28. """
  29. Names for the transitive subgroups of S1.
  30. """
  31. S1 = "S1"
  32. def get_perm_group(self):
  33. return SymmetricGroup(1)
  34. class S2TransitiveSubgroups(Enum):
  35. """
  36. Names for the transitive subgroups of S2.
  37. """
  38. S2 = "S2"
  39. def get_perm_group(self):
  40. return SymmetricGroup(2)
  41. class S3TransitiveSubgroups(Enum):
  42. """
  43. Names for the transitive subgroups of S3.
  44. """
  45. A3 = "A3"
  46. S3 = "S3"
  47. def get_perm_group(self):
  48. if self == S3TransitiveSubgroups.A3:
  49. return AlternatingGroup(3)
  50. elif self == S3TransitiveSubgroups.S3:
  51. return SymmetricGroup(3)
  52. class S4TransitiveSubgroups(Enum):
  53. """
  54. Names for the transitive subgroups of S4.
  55. """
  56. C4 = "C4"
  57. V = "V"
  58. D4 = "D4"
  59. A4 = "A4"
  60. S4 = "S4"
  61. def get_perm_group(self):
  62. if self == S4TransitiveSubgroups.C4:
  63. return CyclicGroup(4)
  64. elif self == S4TransitiveSubgroups.V:
  65. return four_group()
  66. elif self == S4TransitiveSubgroups.D4:
  67. return DihedralGroup(4)
  68. elif self == S4TransitiveSubgroups.A4:
  69. return AlternatingGroup(4)
  70. elif self == S4TransitiveSubgroups.S4:
  71. return SymmetricGroup(4)
  72. class S5TransitiveSubgroups(Enum):
  73. """
  74. Names for the transitive subgroups of S5.
  75. """
  76. C5 = "C5"
  77. D5 = "D5"
  78. M20 = "M20"
  79. A5 = "A5"
  80. S5 = "S5"
  81. def get_perm_group(self):
  82. if self == S5TransitiveSubgroups.C5:
  83. return CyclicGroup(5)
  84. elif self == S5TransitiveSubgroups.D5:
  85. return DihedralGroup(5)
  86. elif self == S5TransitiveSubgroups.M20:
  87. return M20()
  88. elif self == S5TransitiveSubgroups.A5:
  89. return AlternatingGroup(5)
  90. elif self == S5TransitiveSubgroups.S5:
  91. return SymmetricGroup(5)
  92. class S6TransitiveSubgroups(Enum):
  93. """
  94. Names for the transitive subgroups of S6.
  95. """
  96. C6 = "C6"
  97. S3 = "S3"
  98. D6 = "D6"
  99. A4 = "A4"
  100. G18 = "G18"
  101. A4xC2 = "A4 x C2"
  102. S4m = "S4-"
  103. S4p = "S4+"
  104. G36m = "G36-"
  105. G36p = "G36+"
  106. S4xC2 = "S4 x C2"
  107. PSL2F5 = "PSL2(F5)"
  108. G72 = "G72"
  109. PGL2F5 = "PGL2(F5)"
  110. A6 = "A6"
  111. S6 = "S6"
  112. def get_perm_group(self):
  113. if self == S6TransitiveSubgroups.C6:
  114. return CyclicGroup(6)
  115. elif self == S6TransitiveSubgroups.S3:
  116. return S3_in_S6()
  117. elif self == S6TransitiveSubgroups.D6:
  118. return DihedralGroup(6)
  119. elif self == S6TransitiveSubgroups.A4:
  120. return A4_in_S6()
  121. elif self == S6TransitiveSubgroups.G18:
  122. return G18()
  123. elif self == S6TransitiveSubgroups.A4xC2:
  124. return A4xC2()
  125. elif self == S6TransitiveSubgroups.S4m:
  126. return S4m()
  127. elif self == S6TransitiveSubgroups.S4p:
  128. return S4p()
  129. elif self == S6TransitiveSubgroups.G36m:
  130. return G36m()
  131. elif self == S6TransitiveSubgroups.G36p:
  132. return G36p()
  133. elif self == S6TransitiveSubgroups.S4xC2:
  134. return S4xC2()
  135. elif self == S6TransitiveSubgroups.PSL2F5:
  136. return PSL2F5()
  137. elif self == S6TransitiveSubgroups.G72:
  138. return G72()
  139. elif self == S6TransitiveSubgroups.PGL2F5:
  140. return PGL2F5()
  141. elif self == S6TransitiveSubgroups.A6:
  142. return AlternatingGroup(6)
  143. elif self == S6TransitiveSubgroups.S6:
  144. return SymmetricGroup(6)
  145. def four_group():
  146. """
  147. Return a representation of the Klein four-group as a transitive subgroup
  148. of S4.
  149. """
  150. return PermutationGroup(
  151. Permutation(0, 1)(2, 3),
  152. Permutation(0, 2)(1, 3)
  153. )
  154. def M20():
  155. """
  156. Return a representation of the metacyclic group M20, a transitive subgroup
  157. of S5 that is one of the possible Galois groups for polys of degree 5.
  158. Notes
  159. =====
  160. See [1], Page 323.
  161. """
  162. G = PermutationGroup(Permutation(0, 1, 2, 3, 4), Permutation(1, 2, 4, 3))
  163. G._degree = 5
  164. G._order = 20
  165. G._is_transitive = True
  166. G._is_sym = False
  167. G._is_alt = False
  168. G._is_cyclic = False
  169. G._is_dihedral = False
  170. return G
  171. def S3_in_S6():
  172. """
  173. Return a representation of S3 as a transitive subgroup of S6.
  174. Notes
  175. =====
  176. The representation is found by viewing the group as the symmetries of a
  177. triangular prism.
  178. """
  179. G = PermutationGroup(Permutation(0, 1, 2)(3, 4, 5), Permutation(0, 3)(2, 4)(1, 5))
  180. set_symmetric_group_properties(G, 3, 6)
  181. return G
  182. def A4_in_S6():
  183. """
  184. Return a representation of A4 as a transitive subgroup of S6.
  185. Notes
  186. =====
  187. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  188. """
  189. G = PermutationGroup(Permutation(0, 4, 5)(1, 3, 2), Permutation(0, 1, 2)(3, 5, 4))
  190. set_alternating_group_properties(G, 4, 6)
  191. return G
  192. def S4m():
  193. """
  194. Return a representation of the S4- transitive subgroup of S6.
  195. Notes
  196. =====
  197. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  198. """
  199. G = PermutationGroup(Permutation(1, 4, 5, 3), Permutation(0, 4)(1, 5)(2, 3))
  200. set_symmetric_group_properties(G, 4, 6)
  201. return G
  202. def S4p():
  203. """
  204. Return a representation of the S4+ transitive subgroup of S6.
  205. Notes
  206. =====
  207. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  208. """
  209. G = PermutationGroup(Permutation(0, 2, 4, 1)(3, 5), Permutation(0, 3)(4, 5))
  210. set_symmetric_group_properties(G, 4, 6)
  211. return G
  212. def A4xC2():
  213. """
  214. Return a representation of the (A4 x C2) transitive subgroup of S6.
  215. Notes
  216. =====
  217. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  218. """
  219. return PermutationGroup(
  220. Permutation(0, 4, 5)(1, 3, 2), Permutation(0, 1, 2)(3, 5, 4),
  221. Permutation(5)(2, 4))
  222. def S4xC2():
  223. """
  224. Return a representation of the (S4 x C2) transitive subgroup of S6.
  225. Notes
  226. =====
  227. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  228. """
  229. return PermutationGroup(
  230. Permutation(1, 4, 5, 3), Permutation(0, 4)(1, 5)(2, 3),
  231. Permutation(1, 4)(3, 5))
  232. def G18():
  233. """
  234. Return a representation of the group G18, a transitive subgroup of S6
  235. isomorphic to the semidirect product of C3^2 with C2.
  236. Notes
  237. =====
  238. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  239. """
  240. return PermutationGroup(
  241. Permutation(5)(0, 1, 2), Permutation(3, 4, 5),
  242. Permutation(0, 4)(1, 5)(2, 3))
  243. def G36m():
  244. """
  245. Return a representation of the group G36-, a transitive subgroup of S6
  246. isomorphic to the semidirect product of C3^2 with C2^2.
  247. Notes
  248. =====
  249. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  250. """
  251. return PermutationGroup(
  252. Permutation(5)(0, 1, 2), Permutation(3, 4, 5),
  253. Permutation(1, 2)(3, 5), Permutation(0, 4)(1, 5)(2, 3))
  254. def G36p():
  255. """
  256. Return a representation of the group G36+, a transitive subgroup of S6
  257. isomorphic to the semidirect product of C3^2 with C4.
  258. Notes
  259. =====
  260. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  261. """
  262. return PermutationGroup(
  263. Permutation(5)(0, 1, 2), Permutation(3, 4, 5),
  264. Permutation(0, 5, 2, 3)(1, 4))
  265. def G72():
  266. """
  267. Return a representation of the group G72, a transitive subgroup of S6
  268. isomorphic to the semidirect product of C3^2 with D4.
  269. Notes
  270. =====
  271. See [1], Page 325.
  272. """
  273. return PermutationGroup(
  274. Permutation(5)(0, 1, 2),
  275. Permutation(0, 4, 1, 3)(2, 5), Permutation(0, 3)(1, 4)(2, 5))
  276. def PSL2F5():
  277. r"""
  278. Return a representation of the group $PSL_2(\mathbb{F}_5)$, as a transitive
  279. subgroup of S6, isomorphic to $A_5$.
  280. Notes
  281. =====
  282. This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.
  283. """
  284. G = PermutationGroup(
  285. Permutation(0, 4, 5)(1, 3, 2), Permutation(0, 4, 3, 1, 5))
  286. set_alternating_group_properties(G, 5, 6)
  287. return G
  288. def PGL2F5():
  289. r"""
  290. Return a representation of the group $PGL_2(\mathbb{F}_5)$, as a transitive
  291. subgroup of S6, isomorphic to $S_5$.
  292. Notes
  293. =====
  294. See [1], Page 325.
  295. """
  296. G = PermutationGroup(
  297. Permutation(0, 1, 2, 3, 4), Permutation(0, 5)(1, 2)(3, 4))
  298. set_symmetric_group_properties(G, 5, 6)
  299. return G
  300. def find_transitive_subgroups_of_S6(*targets, print_report=False):
  301. r"""
  302. Search for certain transitive subgroups of $S_6$.
  303. The symmetric group $S_6$ has 16 different transitive subgroups, up to
  304. conjugacy. Some are more easily constructed than others. For example, the
  305. dihedral group $D_6$ is immediately found, but it is not at all obvious how
  306. to realize $S_4$ or $S_5$ *transitively* within $S_6$.
  307. In some cases there are well-known constructions that can be used. For
  308. example, $S_5$ is isomorphic to $PGL_2(\mathbb{F}_5)$, which acts in a
  309. natural way on the projective line $P^1(\mathbb{F}_5)$, a set of order 6.
  310. In absence of such special constructions however, we can simply search for
  311. generators. For example, transitive instances of $A_4$ and $S_4$ can be
  312. found within $S_6$ in this way.
  313. Once we are engaged in such searches, it may then be easier (if less
  314. elegant) to find even those groups like $S_5$ that do have special
  315. constructions, by mere search.
  316. This function locates generators for transitive instances in $S_6$ of the
  317. following subgroups:
  318. * $A_4$
  319. * $S_4^-$ ($S_4$ not contained within $A_6$)
  320. * $S_4^+$ ($S_4$ contained within $A_6$)
  321. * $A_4 \times C_2$
  322. * $S_4 \times C_2$
  323. * $G_{18} = C_3^2 \rtimes C_2$
  324. * $G_{36}^- = C_3^2 \rtimes C_2^2$
  325. * $G_{36}^+ = C_3^2 \rtimes C_4$
  326. * $G_{72} = C_3^2 \rtimes D_4$
  327. * $A_5$
  328. * $S_5$
  329. Note: Each of these groups also has a dedicated function in this module
  330. that returns the group immediately, using generators that were found by
  331. this search procedure.
  332. The search procedure serves as a record of how these generators were
  333. found. Also, due to randomness in the generation of the elements of
  334. permutation groups, it can be called again, in order to (probably) get
  335. different generators for the same groups.
  336. Parameters
  337. ==========
  338. targets : list of :py:class:`~.S6TransitiveSubgroups` values
  339. The groups you want to find.
  340. print_report : bool (default False)
  341. If True, print to stdout the generators found for each group.
  342. Returns
  343. =======
  344. dict
  345. mapping each name in *targets* to the :py:class:`~.PermutationGroup`
  346. that was found
  347. References
  348. ==========
  349. .. [2] https://en.wikipedia.org/wiki/Projective_linear_group#Exceptional_isomorphisms
  350. .. [3] https://en.wikipedia.org/wiki/Automorphisms_of_the_symmetric_and_alternating_groups#PGL(2,5)
  351. """
  352. def elts_by_order(G):
  353. """Sort the elements of a group by their order. """
  354. elts = defaultdict(list)
  355. for g in G.elements:
  356. elts[g.order()].append(g)
  357. return elts
  358. def order_profile(G, name=None):
  359. """Determine how many elements a group has, of each order. """
  360. elts = elts_by_order(G)
  361. profile = {o:len(e) for o, e in elts.items()}
  362. if name:
  363. print(f'{name}: ' + ' '.join(f'{len(profile[r])}@{r}' for r in sorted(profile.keys())))
  364. return profile
  365. S6 = SymmetricGroup(6)
  366. A6 = AlternatingGroup(6)
  367. S6_by_order = elts_by_order(S6)
  368. def search(existing_gens, needed_gen_orders, order, alt=None, profile=None, anti_profile=None):
  369. """
  370. Find a transitive subgroup of S6.
  371. Parameters
  372. ==========
  373. existing_gens : list of Permutation
  374. Optionally empty list of generators that must be in the group.
  375. needed_gen_orders : list of positive int
  376. Nonempty list of the orders of the additional generators that are
  377. to be found.
  378. order: int
  379. The order of the group being sought.
  380. alt: bool, None
  381. If True, require the group to be contained in A6.
  382. If False, require the group not to be contained in A6.
  383. profile : dict
  384. If given, the group's order profile must equal this.
  385. anti_profile : dict
  386. If given, the group's order profile must *not* equal this.
  387. """
  388. for gens in itertools.product(*[S6_by_order[n] for n in needed_gen_orders]):
  389. if len(set(gens)) < len(gens):
  390. continue
  391. G = PermutationGroup(existing_gens + list(gens))
  392. if G.order() == order and G.is_transitive():
  393. if alt is not None and G.is_subgroup(A6) != alt:
  394. continue
  395. if profile and order_profile(G) != profile:
  396. continue
  397. if anti_profile and order_profile(G) == anti_profile:
  398. continue
  399. return G
  400. def match_known_group(G, alt=None):
  401. needed = [g.order() for g in G.generators]
  402. return search([], needed, G.order(), alt=alt, profile=order_profile(G))
  403. found = {}
  404. def finish_up(name, G):
  405. found[name] = G
  406. if print_report:
  407. print("=" * 40)
  408. print(f"{name}:")
  409. print(G.generators)
  410. if S6TransitiveSubgroups.A4 in targets or S6TransitiveSubgroups.A4xC2 in targets:
  411. A4_in_S6 = match_known_group(AlternatingGroup(4))
  412. finish_up(S6TransitiveSubgroups.A4, A4_in_S6)
  413. if S6TransitiveSubgroups.S4m in targets or S6TransitiveSubgroups.S4xC2 in targets:
  414. S4m_in_S6 = match_known_group(SymmetricGroup(4), alt=False)
  415. finish_up(S6TransitiveSubgroups.S4m, S4m_in_S6)
  416. if S6TransitiveSubgroups.S4p in targets:
  417. S4p_in_S6 = match_known_group(SymmetricGroup(4), alt=True)
  418. finish_up(S6TransitiveSubgroups.S4p, S4p_in_S6)
  419. if S6TransitiveSubgroups.A4xC2 in targets:
  420. A4xC2_in_S6 = search(A4_in_S6.generators, [2], 24, anti_profile=order_profile(SymmetricGroup(4)))
  421. finish_up(S6TransitiveSubgroups.A4xC2, A4xC2_in_S6)
  422. if S6TransitiveSubgroups.S4xC2 in targets:
  423. S4xC2_in_S6 = search(S4m_in_S6.generators, [2], 48)
  424. finish_up(S6TransitiveSubgroups.S4xC2, S4xC2_in_S6)
  425. # For the normal factor N = C3^2 in any of the G_n subgroups, we take one
  426. # obvious instance of C3^2 in S6:
  427. N_gens = [Permutation(5)(0, 1, 2), Permutation(5)(3, 4, 5)]
  428. if S6TransitiveSubgroups.G18 in targets:
  429. G18_in_S6 = search(N_gens, [2], 18)
  430. finish_up(S6TransitiveSubgroups.G18, G18_in_S6)
  431. if S6TransitiveSubgroups.G36m in targets:
  432. G36m_in_S6 = search(N_gens, [2, 2], 36, alt=False)
  433. finish_up(S6TransitiveSubgroups.G36m, G36m_in_S6)
  434. if S6TransitiveSubgroups.G36p in targets:
  435. G36p_in_S6 = search(N_gens, [4], 36, alt=True)
  436. finish_up(S6TransitiveSubgroups.G36p, G36p_in_S6)
  437. if S6TransitiveSubgroups.G72 in targets:
  438. G72_in_S6 = search(N_gens, [4, 2], 72)
  439. finish_up(S6TransitiveSubgroups.G72, G72_in_S6)
  440. # The PSL2(F5) and PGL2(F5) subgroups are isomorphic to A5 and S5, resp.
  441. if S6TransitiveSubgroups.PSL2F5 in targets:
  442. PSL2F5_in_S6 = match_known_group(AlternatingGroup(5))
  443. finish_up(S6TransitiveSubgroups.PSL2F5, PSL2F5_in_S6)
  444. if S6TransitiveSubgroups.PGL2F5 in targets:
  445. PGL2F5_in_S6 = match_known_group(SymmetricGroup(5))
  446. finish_up(S6TransitiveSubgroups.PGL2F5, PGL2F5_in_S6)
  447. # There is little need to "search" for any of the groups C6, S3, D6, A6,
  448. # or S6, since they all have obvious realizations within S6. However, we
  449. # support them here just in case a random representation is desired.
  450. if S6TransitiveSubgroups.C6 in targets:
  451. C6 = match_known_group(CyclicGroup(6))
  452. finish_up(S6TransitiveSubgroups.C6, C6)
  453. if S6TransitiveSubgroups.S3 in targets:
  454. S3 = match_known_group(SymmetricGroup(3))
  455. finish_up(S6TransitiveSubgroups.S3, S3)
  456. if S6TransitiveSubgroups.D6 in targets:
  457. D6 = match_known_group(DihedralGroup(6))
  458. finish_up(S6TransitiveSubgroups.D6, D6)
  459. if S6TransitiveSubgroups.A6 in targets:
  460. A6 = match_known_group(A6)
  461. finish_up(S6TransitiveSubgroups.A6, A6)
  462. if S6TransitiveSubgroups.S6 in targets:
  463. S6 = match_known_group(S6)
  464. finish_up(S6TransitiveSubgroups.S6, S6)
  465. return found