Skip to content

Instantly share code, notes, and snippets.

@GeoffChurch
Last active January 19, 2022 16:30
Show Gist options
  • Select an option

  • Save GeoffChurch/4d82198cdca8e7903e972346f254de1d to your computer and use it in GitHub Desktop.

Select an option

Save GeoffChurch/4d82198cdca8e7903e972346f254de1d to your computer and use it in GitHub Desktop.
Plot subgroup lattice with short labels and normal subgroups highlighted. Works with Sage 9.2, Python 3.9.5
def relabel(xs, f):
clazz = type(xs[0])
new_clazz = type(f"{clazz}_relabeled", (clazz,), {"__str__" : f})
for x in xs:
x.__class__ = new_clazz
def norms_abnorms(subgroups, G):
norms = []
abnorms = []
for s in subgroups:
if s.is_normal(G):
norms.append(s)
else:
abnorms.append(s)
return norms, abnorms
def SubgroupLatticePlot(G, only_normal_subgroups=False):
subgroups = G.normal_subgroups() if only_normal_subgroups else G.subgroups()
clazz = type(subgroups[0])
relabel(subgroups, clazz.structure_description)
norms, abnorms = norms_abnorms(subgroups, G)
subs_poset = Poset((subgroups, clazz.is_subgroup))
graph = subs_poset.hasse_diagram()
return graph.plot(
vertex_colors = {"red": norms, "white": abnorms},
vertex_size=2000,
layout='acyclic',
figsize=20
)
# Example usage:
# G = DihedralGroup(8)
# SubgroupLatticePlot(G, False).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment