# Can graphs in GAP be obtained as a visual output

In GAP when we draw a cayley graph of a group using "CayleyGraph" command we get a list. Is there a way to visualize that cayley graph like a figure?

Or else is there any other software that has the ability to visualize?

• There is a graphical package called XGAP. I am not sure that there is a specific comment for drawing a Cayley graph. Oct 2, 2018 at 8:24
• xgap (nor Gap.app) doesn't draw Cayley graphs "out of the box". An interested person with some programming experience could probably add such functionality (perhaps using Alexander's code to get started) without too much trouble. Oct 4, 2018 at 20:55

A standard tool for visualizing graphs is the graphviz software. The following GAP program

# usage: PrintCayleyGraph(filename,group[,generatornames]);
PrintCayleyGraph:=function(arg)
local f,g,gens,ngens,epi,r,nams,nnams,vert,kind,p,i,j,e,ed;
f:=arg[1];
g:=arg[2];
gens:=GeneratorsOfGroup(g);
r:=Length(gens);
if Length(arg)>2 then
nams:=arg[3];
else
nams:=List([1..r],x->CHARS_LALPHA{[x]});
fi;
ngens:=[];
nnams:=[];
kind:=[]; # what kind of arrow
for i in [1..r] do
if Order(gens[i])=2 then
kind[i]:=2;
else
p:=Position(gens,gens[i]^-1);
if p<i then
kind[i]:=-p;
else
kind[i]:=1;
fi;
fi;
od;
gens:=ngens;
g:=GroupWithGenerators(gens);
epi:=EpimorphismFromFreeGroup(g:names:=nnams);
PrintTo(f,"digraph cayley {\nsize = \"6,6\";\n");
e:=Elements(g);
e:=ShallowCopy(e);
if IsPermGroup(g) then
SortBy(e,x->1^x);
fi;
vert:=List([1..Length(e)],x->Concatenation("\"v",String(x),"\""));
for i in [1..Length(e)] do
if IsOne(e[i]) then
p:="1";
else
p:=String(Factorization(g,e[i]));
fi;
AppendTo(f,vert[i]," [label=\"",i,":",p,"\"\];\n");
od;
ed:=[];
for i in [1..Length(e)] do
for j in [1..Length(gens)] do
p:=Position(e,e[i]*gens[j]);
if kind[j]=1 then
elif kind[j]=2 and p>i then
fi;
od;
od;
Sort(ed); # to try to get same shape
for i in ed do
AppendTo(f,"  ",vert[i[2]]," -> ",vert[i[3]],i[4]);
od;

AppendTo(f,"}\n");
end;


takes a group, and prints out its cayley graph in this format. For example,

gap> g:=Group((1,2,3,4),(1,3));;
gap> PrintCayleyGraph("d8cay.dot",g,["a","b"]);


produces a file d8cay.dot that when read processed by graphviz produces a picture like (here I used the program OmniGraffle (Mac only) to rearrange vertices and add shadow) the following.

I'm working on a GAP package to do just what you're talking about in the context of Jupyter notebooks. The package is in its early phases, but it can already produce a bunch of different kinds of visualizations. Repository:

https://github.com/nathancarter/jupyter-viz

• Please use @username to ping me (see meta.stackexchange.com/questions/43019/…) - otherwise I will see this only if I will revisit the question, and that's not guaranteed. GAP works on all recent macOS (except that we haven't heard yet from most recent macOC mojave released a couple of weeks ago, but I expect that even if there will be any problems, they will be resolved). It works on all post popular Linux distributions - Ubuntu, Debian, etc. - choose one who which you have a better support locally. Oct 14, 2018 at 13:29