Repository: digraphs/Digraphs
Pull request #403: Add `PancakeGraph`
Author: login: james-d-mitchell
Labels: name: new-feature
description: A label for new features.
name: gap-days-brussels-2025
description: Label for things we might work on in Brussels
Created: 2021-02-10T16:06:09Z | Merged: 2025-04-08T07:31:51Z



Diff:
diff --git a/doc/examples.xml b/doc/examples.xml
index a2bc87912..f2f5251cb 100644
--- a/doc/examples.xml
+++ b/doc/examples.xml
@@ -367,6 +367,82 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i - 1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
+    
+    If the optional first argument <A>filt</A> is not present, then <Ref
+    Filt="IsImmutableDigraph"/> is used by default.<P/>
+
+    See <URL>https://en.wikipedia.org/wiki/Pancake_graph</URL> for further
+    details. 
+
+<Example><![CDATA[
+gap> D := PancakeGraph(5);
+<immutable Hamiltonian connected symmetric digraph with 120 vertices, \
+480 edges>
+gap> DigraphUndirectedGirth(D);
+6
+gap> ChromaticNumber(D);
+3
+gap> IsHamiltonianDigraph(D);
+true
+gap> IsCayleyDigraph(D);
+true
+gap> IsVertexTransitive(D);
+true]]></Example>
+  </Description>
+</ManSection>
+<#/GAPDoc>
+
+<#GAPDoc Label="BurntPancakeGraph">
+<ManSection>
+  <Oper Name="BurntPancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>burnt pancake graph</E> with <M>n!</M> vertices and <M>n2^{n}n!</M>
+    directed edges. The <M>n</M>th burnt pancake graph is the Cayley graph of the
+    hyperoctahedral group acting on <C>[<A>-n</A> .. -1, 1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>, which are defined in exactly
+    the same way as in  <Ref Oper="PancakeGraph"/>. The hyperoctahedral group consists of
+    permutations <M>p</M> acting on <C>[<A>-n</A> .. -1, 1 .. <A>n</A>]</C>, where the image
+    of every point <M>i</M> in <C>[<A>-n</A> .. -1, 1 .. <A>n</A>]</C> is equal to the
+    negative of the image of <M>-i</M> under <M>p</M>.
+    GAP only works with permutations of positive integers and so <C>BurntPancakeGraph</C> returns
+    the Cayley graph of the hyperoctahedral group acting on <C>[1 .. <A>2n</A>]</C> instead of
+    <C>[<A>-n</A> .. -1, 1 .. <A>n</A>]</C>.
+    If the optional first argument <A>filt</A> is not present, then <Ref
+    Filt="IsImmutableDigraph"/> is used by default.<P/>
+
+    See <URL>https://en.wikipedia.org/wiki/Pancake_graph</URL> for further
+    details. 
+
+<Example><![CDATA[
+gap> BurntPancakeGraph(3);
+<immutable symmetric digraph with 48 vertices, 144 edges>
+gap> BurntPancakeGraph(4);
+<immutable symmetric digraph with 384 vertices, 1536 edges>
+gap> BurntPancakeGraph(5);
+<immutable symmetric digraph with 3840 vertices, 19200 edges>
+gap> BurntPancakeGraph(IsMutableDigraph, 1);
+<mutable digraph with 1 vertex, 1 edge>
+]]></Example>
+  </Description>
+</ManSection>
+<#/GAPDoc>
+
 <#GAPDoc Label="StarGraph">
 <ManSection>
   <Oper Name="StarGraph" Arg="[filt, ]k"/>
diff --git a/doc/grape.xml b/doc/grape.xml
index 7cc5e6df3..cc971a07e 100644
--- a/doc/grape.xml
+++ b/doc/grape.xml
@@ -46,18 +46,24 @@ true]]></Example>
 
 <#GAPDoc Label="CayleyDigraph">
 <ManSection>
-  <Oper Name="CayleyDigraph" Arg="G[, gens]"/>
-  <Returns>An immutable digraph.</Returns>
+  <Oper Name="CayleyDigraph" Arg="[filt,] G[, gens]"/>
+  <Returns>A digraph.</Returns>
   <Description>
     Let <A>G</A> be any group and let <A>gens</A> be a list of elements of
-    <A>G</A>. This operation returns an immutable digraph that corresponds to
-    the Cayley graph of <A>G</A> with respect to <A>gens</A>. <P/>
+    <A>G</A>. This operation returns a digraph that corresponds to the Cayley
+    graph of <A>G</A> with respect to <A>gens</A>. If the optional argument
+    <A>filt</A> is present, then it determines mutability of the returned
+    digraph. In other words, if <A>filt</A> is <C>IsMutable</C> or
+    <C>IsMutableDigraph</C>, then the returned digraph is mutable, and if
+    <A>filt</A> is <C>IsImmutableDigraph</C>, then the returned digraph is
+    immutable. 
+    <P/>
 
-    The vertices of the digraph correspond to the elements of <A>G</A>,
-    in the order given by <C>AsList(<A>G</A>)</C>.
-    There exists an edge from vertex <C>u</C> to vertex <C>v</C>
-    if and only if there exists a generator <C>g</C> in <A>gens</A>
-    such that <C>AsList(<A>G</A>)[u] * g = AsList(<A>G</A>)[v]</C>. <P/>
+    The vertices of the digraph correspond to the elements of <A>G</A>, in the
+    order given by <C>Set(<A>G</A>)</C>. There exists an edge from vertex
+    <C>u</C> to vertex <C>v</C> if and only if there exists a generator
+    <C>g</C> in <A>gens</A> such that <C>Set(<A>G</A>)[u] * g =
+    Set(<A>G</A>)[v]</C>. <P/>
       
     The labels of the vertices <C>u</C>, <C>v</C>, and the edge <C>[u, v]</C>
     are the corresponding elements <C>AsList(<A>G</A>)[u]</C>,
@@ -73,8 +79,6 @@ true]]></Example>
     digraph using <Ref Attr="GroupOfCayleyDigraph"/>, and the generators
     <A>gens</A> can be obtained using <Ref Attr="GeneratorsOfCayleyDigraph"/>.<P/>
 
-    Note that this function can only return an immutable digraph.
-
     <Example><![CDATA[
 gap> G := DihedralGroup(8);
 <pc group of size 8 with 3 generators>
@@ -89,7 +93,10 @@ gap> digraph := CayleyDigraph(G, [()]);
 gap> GroupOfCayleyDigraph(digraph) = G;
 true
 gap> GeneratorsOfCayleyDigraph(digraph);
-[ () ]]]></Example>
+[ () ]
+gap> digraph := CayleyDigraph(IsMutable, G, [()]);
+<mutable digraph with 8 vertices, 8 edges>
+]]></Example>
   </Description>
 </ManSection>
 <#/GAPDoc>
diff --git a/doc/z-chap2.xml b/doc/z-chap2.xml
index 897f56399..5c6b4066a 100644
--- a/doc/z-chap2.xml
+++ b/doc/z-chap2.xml
@@ -92,6 +92,8 @@
     <#Include Label="BishopsGraph">
     <#Include Label="BondyGraph">
     <#Include Label="BookGraph">
+    <#Include Label="BurntPancakeGraph">
+    <#Include Label="PancakeGraph">
     <#Include Label="StackedBookGraph">
     <#Include Label="ChainDigraph">
     <#Include Label="CirculantGraph">
diff --git a/gap/examples.gd b/gap/examples.gd
index cec75fff3..a3623fc69 100644
--- a/gap/examples.gd
+++ b/gap/examples.gd
@@ -215,3 +215,11 @@ DeclareOperation("WheelGraph", [IsFunction, IsPosInt]);
 DeclareConstructor("WindmillGraphCons", [IsDigraph, IsPosInt, IsPosInt]);
 DeclareOperation("WindmillGraph", [IsPosInt, IsPosInt]);
 DeclareOperation("WindmillGraph", [IsFunction, IsPosInt, IsPosInt]);
+
+DeclareConstructor("PancakeGraphCons", [IsDigraph, IsPosInt]);
+DeclareOperation("PancakeGraph", [IsPosInt]);
+DeclareOperation("PancakeGraph", [IsFunction, IsPosInt]);
+
+DeclareConstructor("BurntPancakeGraphCons", [IsDigraph, IsPosInt]);
+DeclareOperation("BurntPancakeGraph", [IsPosInt]);
+DeclareOperation("BurntPancakeGraph", [IsFunction, IsPosInt]);
diff --git a/gap/examples.gi b/gap/examples.gi
index b542fa6fe..c01cc178a 100644
--- a/gap/examples.gi
+++ b/gap/examples.gi
@@ -1898,3 +1898,63 @@ InstallMethod(WindmillGraph, "for two integers", [IsPosInt, IsPosInt],
 
 InstallMethod(WindmillGraph, "for a function and two integers",
 [IsFunction, IsPosInt, IsPosInt], WindmillGraphCons);
+
+BindGlobal("DIGRAPHS_PrefixReversalGroup",
+n -> Group(List([2 .. n], i -> PermList([i, i - 1 .. 1])), ()));
+
+InstallMethod(PancakeGraphCons, "for IsMutableDigraph and pos int",
+[IsMutableDigraph, IsPosInt],
+{filt, n} -> CayleyDigraph(IsMutableDigraph, DIGRAPHS_PrefixReversalGroup(n)));
+
+InstallMethod(PancakeGraphCons, "for IsImmutableDigraph and pos int",
+[IsImmutableDigraph, IsPosInt],
+function(_, n)
+  local D;
+  D := CayleyDigraph(IsImmutableDigraph, DIGRAPHS_PrefixReversalGroup(n));
+  SetIsMultiDigraph(D, false);
+  SetIsSymmetricDigraph(D, true);
+  SetIsHamiltonianDigraph(D, true);
+  return D;
+end);
+
+InstallMethod(PancakeGraph, "for a function and pos int",
+[IsFunction, IsPosInt], PancakeGraphCons);
+
+InstallMethod(PancakeGraph, "for a pos int",
+[IsPosInt], n -> PancakeGraphCons(IsImmutableDigraph, n));
+
+BindGlobal("DIGRAPHS_HyperoctahedralGroup",
+function(n)
+  local id, A, i;
+  if n = 1 then
+    return Group(());
+  fi;
+  id := [1 .. 2 * n];
+  A := [];
+  for i in [1 .. n] do
+    id{[1 .. i]} := [i + n, i - 1 + n .. 1 + n];
+    id{[n + 1 .. n + i]} := [i, i - 1 .. 1];
+    Add(A, PermList(id));
+  od;
+  return Group(A);
+end);
+
+InstallMethod(BurntPancakeGraphCons, "for IsMutableDigraph and pos int",
+[IsMutableDigraph, IsPosInt],
+{filt, n} -> CayleyDigraph(IsMutableDigraph, DIGRAPHS_HyperoctahedralGroup(n)));
+
+InstallMethod(BurntPancakeGraphCons, "for IsImmutableDigraph and pos int",
+[IsImmutableDigraph, IsPosInt],
+function(_, n)
+  local D;
+  D := CayleyDigraph(IsImmutableDigraph, DIGRAPHS_HyperoctahedralGroup(n));
+  SetIsMultiDigraph(D, false);
+  SetIsSymmetricDigraph(D, true);
+  return D;
+end);
+
+InstallMethod(BurntPancakeGraph, "for a function and pos int",
+[IsFunction, IsPosInt], BurntPancakeGraphCons);
+
+InstallMethod(BurntPancakeGraph, "for a pos int",
+[IsPosInt], n -> BurntPancakeGraphCons(IsImmutableDigraph, n));
diff --git a/gap/grape.gd b/gap/grape.gd
index 9eab49d94..205a931c0 100644
--- a/gap/grape.gd
+++ b/gap/grape.gd
@@ -11,8 +11,13 @@
 DeclareOperation("Graph", [IsDigraph]);
 
 #  Cayley digraphs
+DeclareConstructor("CayleyDigraphCons", [IsDigraph, IsGroup, IsList]);
+
 DeclareOperation("CayleyDigraph", [IsGroup]);
 DeclareOperation("CayleyDigraph", [IsGroup, IsList]);
+DeclareOperation("CayleyDigraph", [IsFunction, IsGroup]);
+DeclareOperation("CayleyDigraph", [IsFunction, IsGroup, IsList]);
+
 DeclareAttribute("GroupOfCayleyDigraph", IsCayleyDigraph);
 DeclareAttribute("SemigroupOfCayleyDigraph", IsCayleyDigraph);
 DeclareAttribute("GeneratorsOfCayleyDigraph", IsCayleyDigraph);
diff --git a/gap/grape.gi b/gap/grape.gi
index 6b1f158fc..af0c067d8 100644
--- a/gap/grape.gi
+++ b/gap/grape.gi
@@ -89,37 +89,74 @@ function(imm, G, obj, act, adj)
   return D;
 end);
 
-InstallMethod(CayleyDigraph, "for a group with generators",
-[IsGroup, IsHomogeneousList],
-function(G, gens)
-  local elts, adj, D, edge_labels;
-
+InstallMethod(CayleyDigraphCons,
+"for IsMutableDigraph, group, and list of elements",
+[IsMutableDigraph, IsGroup, IsHomogeneousList],
+function(_, G, gens)
   if not IsFinite(G) then
-    ErrorNoReturn("the 1st argument <G> must be a finite group,");
+    ErrorNoReturn("the 2nd argument (a group) must be finite");
   elif not ForAll(gens, x -> x in G) then
-    ErrorNoReturn("the 2nd argument <gens> must consist of elements of the ",
-                  "1st argument,");
+    ErrorNoReturn("the 3rd argument (a homog. list) must consist of ",
+                  "elements of the 2nd argument (a group)");
   fi;
+  return Digraph(IsMutableDigraph,
+                 G,
+                 AsList(G),
+                 OnLeftInverse,
+                 {x, y} -> x ^ -1 * y in gens);
+end);
 
+InstallMethod(CayleyDigraphCons,
+"for IsImmutableDigraph, group, and list of elements",
+[IsImmutableDigraph, IsGroup, IsHomogeneousList],
+function(_, G, gens)
+  local set, D, edge_labels;
+
+  # This method is a duplicate of the one above because the method for Digraph
+  # sets some additional attributes if IsImmutableDigraph is passed as 1st
+  # argument, and so we don't want to make a mutable version of the returned
+  # graph, and then make it immutable, because then those attributes won't be
+  # set.
+
+  if not IsFinite(G) then
+    ErrorNoReturn("the 2nd argument (a group) must be finite");
+  elif not ForAll(gens, x -> x in G) then
+    ErrorNoReturn("the 3rd argument (a homog. list) must consist ",
+                  "of elements of the 2nd argument (a list)");
+  fi;
+  set := AsSet(G);
   # vertex i in the Cayley digraph corresponds to elts[i].
-  elts := AsSet(G);
-  adj := {x, y} -> LeftQuotient(x, y) in gens;
+  D := Digraph(IsImmutableDigraph,
+               G,
+               set,
+               OnLeftInverse,
+               {x, y} -> LeftQuotient(x, y) in gens);
 
-  D := Digraph(IsImmutableDigraph, G, elts, OnLeftInverse, adj);
   SetFilterObj(D, IsCayleyDigraph);
   SetGroupOfCayleyDigraph(D, G);
   SetGeneratorsOfCayleyDigraph(D, gens);
-  SetDigraphVertexLabels(D, elts);
+  SetDigraphVertexLabels(D, AsList(G));
   # Out-neighbours of identity give the correspondence between edges & gens
-  edge_labels := elts{OutNeighboursOfVertex(D, Position(elts, One(G)))};
+  edge_labels := AsList(G){OutNeighboursOfVertex(D,
+                                                 Position(set, One(G)))};
   SetDigraphEdgeLabels(D, ListWithIdenticalEntries(Size(G), edge_labels));
-
   return D;
 end);
 
+InstallMethod(CayleyDigraph, "for a group and list of elements",
+[IsGroup, IsHomogeneousList],
+{G, gens} -> CayleyDigraphCons(IsImmutableDigraph, G, gens));
+
+InstallMethod(CayleyDigraph, "for a filter and group with generators",
+[IsFunction, IsGroup, IsHomogeneousList], CayleyDigraphCons);
+
 InstallMethod(CayleyDigraph, "for a group with generators",
 [IsGroup and HasGeneratorsOfGroup],
-G -> CayleyDigraph(G, GeneratorsOfGroup(G)));
+G -> CayleyDigraphCons(IsImmutableDigraph, G, GeneratorsOfGroup(G)));
+
+InstallMethod(CayleyDigraph, "for a filter and group with generators",
+[IsFunction, IsGroup and HasGeneratorsOfGroup],
+{filt, G} -> CayleyDigraphCons(filt, G, GeneratorsOfGroup(G)));
 
 InstallMethod(Graph, "for a digraph", [IsDigraph],
 function(D)
diff --git a/tst/standard/examples.tst b/tst/standard/examples.tst
index 24f780db9..3306cae5a 100644
--- a/tst/standard/examples.tst
+++ b/tst/standard/examples.tst
@@ -816,7 +816,31 @@ gap> WindmillGraph(-1, 0);
 Error, no method found! For debugging hints type ?Recovery from NoMethodFound
 Error, no 1st choice method found for `WindmillGraph' on 2 arguments
 
-#  DIGRAPHS_UnbindVariables
+# PancakeGraph
+gap> D := PancakeGraph(3);
+<immutable Hamiltonian connected symmetric digraph with 6 vertices, 12 edges>
+gap> ChromaticNumber(D);
+2
+gap> IsVertexTransitive(D);
+true
+gap> DigraphUndirectedGirth(D);
+6
+gap> IsHamiltonianDigraph(D);
+true
+gap> D := PancakeGraph(IsMutableDigraph, 1);
+<mutable empty digraph with 1 vertex>
+
+# BurntPancakeGraph
+gap> BurntPancakeGraph(3);
+<immutable symmetric digraph with 48 vertices, 144 edges>
+gap> BurntPancakeGraph(4);
+<immutable symmetric digraph with 384 vertices, 1536 edges>
+gap> BurntPancakeGraph(5);
+<immutable symmetric digraph with 3840 vertices, 19200 edges>
+gap> BurntPancakeGraph(IsMutableDigraph, 1);
+<mutable digraph with 1 vertex, 1 edge>
+
+# DIGRAPHS_UnbindVariables
 gap> Unbind(D);
 gap> Unbind(G8_3);
 gap> Unbind(gr);
diff --git a/tst/standard/grape.tst b/tst/standard/grape.tst
index 7b5f9e034..cb6460c93 100644
--- a/tst/standard/grape.tst
+++ b/tst/standard/grape.tst
@@ -26,6 +26,13 @@ true
 gap> ForAll(DigraphEdges(digraph), e -> AsList(group)[e[1]]
 > * DigraphEdgeLabel(digraph, e[1], e[2]) = AsList(group)[e[2]]);
 true
+gap> digraph := CayleyDigraph(IsMutableDigraph, group);
+<mutable digraph with 8 vertices, 24 edges>
+gap> digraph := CayleyDigraph(IsMutableDigraph, FreeGroup(1));
+Error, the 2nd argument (a group) must be finite
+gap> digraph := CayleyDigraph(IsMutableDigraph, group, [(2, 3)]);
+Error, the 3rd argument (a homog. list) must consist of elements of the 2nd ar\
+gument (a group)
 gap> group := DihedralGroup(IsPermGroup, 8);
 Group([ (1,2,3,4), (2,4) ])
 gap> digraph := CayleyDigraph(group);
@@ -41,10 +48,11 @@ true
 gap> GeneratorsOfCayleyDigraph(digraph);
 [ () ]
 gap> digraph := CayleyDigraph(group, [(1, 2, 3, 4), (2, 5)]);
-Error, the 2nd argument <gens> must consist of elements of the 1st argument,
+Error, the 3rd argument (a homog. list) must consist of elements of the 2nd ar\
+gument (a list)
 gap> group := FreeGroup(2);;
 gap> digraph := CayleyDigraph(group);
-Error, the 1st argument <G> must be a finite group,
+Error, the 2nd argument (a group) must be finite
 
 #  CayleyDigraph: check edge labels
 #
@@ -270,6 +278,23 @@ gap> Unbind(gr2);
 gap> Unbind(gr3);
 gap> Unbind(group);
 
+#
+gap> Digraph(IsSemigroup, SymmetricGroup(3), [1, 2, 3], OnPoints, 
+> {x, y} -> x <> y);
+Error, <imm> must be IsMutableDigraph or IsImmutableDigraph
+
+# Code coverage
+gap> D := Digraph([[1, 1]]);
+<immutable multidigraph with 1 vertex, 2 edges>
+gap> Graph(D);
+rec( adjacencies := [ [ 1 ] ], group := Group(()), isGraph := true, 
+  names := [ 1 ], order := 1, representatives := [ 1 ], 
+  schreierVector := [ -1 ] )
+gap> D := CompleteDigraph(IsMutableDigraph, 5);;
+gap> HasDigraphGroup(D);
+false
+gap> Graph(D);;
+
 #
 gap> DIGRAPHS_StopTest();
 gap> STOP_TEST("Digraphs package: standard/grape.tst", 0);


Reviews:
user: login: marinaanagno
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2021-02-12T11:59:50Z
user: login: flsmith
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2021-03-03T15:17:15Z
user: login: james-d-mitchell
state: COMMENTED
author_association: MEMBER
submitted_at: 2021-03-03T17:24:42Z
user: login: wilfwilson
body: Nice graph! I have a few comments/suggestions/complaints.

I would much prefer it if this PR consisted of two separate commits: one for the changes to `CayleyDigraph`, and one for the pancake stuff.
state: DISMISSED
author_association: COLLABORATOR
submitted_at: 2021-03-11T15:08:08Z
user: login: james-d-mitchell
state: COMMENTED
author_association: MEMBER
submitted_at: 2021-03-22T09:30:07Z
user: login: wilfwilson
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2021-05-26T10:39:24Z
user: login: LRacine
body: I really enjoyed looking through your code, it was clean and concise. Your documentation was also thorough and readable. There were just a couple of capitalisation errors and I was wondering where I could see the burnt pancake documentation.
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2021-05-26T14:27:00Z
user: login: marinaanagno
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2021-05-26T14:30:29Z
user: login: LRacine
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2021-05-26T14:45:53Z
user: login: marinaanagno
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2021-05-26T14:47:41Z
user: login: reiniscirpons
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-04-07T16:09:56Z
user: login: reiniscirpons
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-07T16:10:55Z
user: login: reiniscirpons
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-07T16:21:59Z

Review comments:
diff_hunk: @@ -309,3 +309,47 @@ gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4);
   </Description>
 </ManSection>
 <#/GAPDoc>
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set has consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i -1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
path: doc/examples.xml
user: login: marinaanagno
body: @james-d-mitchell I'm not entirely sure that we tend to do this when implementing graphs and not operations, but maybe it would be useful to calculate and mention the complexity of the algorithm? :)
created_at: 2021-02-12T11:59:50Z
author_association: CONTRIBUTOR
diff_hunk: @@ -309,3 +309,47 @@ gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4);
   </Description>
 </ManSection>
 <#/GAPDoc>
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set has consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i -1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
path: doc/examples.xml
user: login: flsmith
body: This would be nice but we don't really do it anywhere else. On the other hand, there aren't many other examples like this in the package where the complexity isn't somehow obvious, so it might be a nice precedent to start.
created_at: 2021-03-03T14:47:37Z
author_association: COLLABORATOR
diff_hunk: @@ -91,33 +91,65 @@ function(imm, G, obj, act, adj)
   return D;
 end);
 
-InstallMethod(CayleyDigraph, "for a group with generators",
-[IsGroup, IsHomogeneousList],
-function(G, gens)
-  local adj, D;
-
+InstallMethod(CayleyDigraphCons,
+"for IsMutableDigraph, group, and list of elements",
+[IsMutableDigraph, IsGroup, IsHomogeneousList],
+function(filt, G, gens)
   if not IsFinite(G) then
     ErrorNoReturn("the 1st argument <G> must be a finite group,");
path: gap/grape.gi
user: login: flsmith
body: Here the arguments have the wrong indices if the function is called directly. Of course, this function is undocumented, but this raises the question (which may have already been answered) of whether it should be obscured using `DIGRAPHS_`
created_at: 2021-03-03T15:01:42Z
author_association: COLLABORATOR
diff_hunk: @@ -91,33 +91,65 @@ function(imm, G, obj, act, adj)
   return D;
 end);
 
-InstallMethod(CayleyDigraph, "for a group with generators",
-[IsGroup, IsHomogeneousList],
-function(G, gens)
-  local adj, D;
-
+InstallMethod(CayleyDigraphCons,
+"for IsMutableDigraph, group, and list of elements",
+[IsMutableDigraph, IsGroup, IsHomogeneousList],
+function(filt, G, gens)
   if not IsFinite(G) then
     ErrorNoReturn("the 1st argument <G> must be a finite group,");
path: gap/grape.gi
user: login: flsmith
body: They also have the wrong indices if `CayleyDigraph` is called with the filter as first argument.
created_at: 2021-03-03T15:15:04Z
author_association: COLLABORATOR
diff_hunk: @@ -18,6 +18,12 @@ gap> group := DihedralGroup(8);
 <pc group of size 8 with 3 generators>
 gap> digraph := CayleyDigraph(group);
 <immutable digraph with 8 vertices, 24 edges>
+gap> digraph := CayleyDigraph(IsMutableDigraph, group);
+<mutable digraph with 8 vertices, 24 edges>
+gap> digraph := CayleyDigraph(IsMutableDigraph, FreeGroup(1));
+Error, the 1st argument <G> must be a finite group,
path: tst/standard/grape.tst
user: login: flsmith
body: Example of wrong indices 
created_at: 2021-03-03T15:15:18Z
author_association: COLLABORATOR
diff_hunk: @@ -309,3 +309,47 @@ gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4);
   </Description>
 </ManSection>
 <#/GAPDoc>
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set has consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i -1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
path: doc/examples.xml
user: login: james-d-mitchell
body: I don't actually know the complexity, so maybe it's better to just skip this for now!
created_at: 2021-03-03T17:24:41Z
author_association: MEMBER
diff_hunk: @@ -41,10 +48,11 @@ true
 gap> GeneratorsOfCayleyDigraph(digraph);
 [ () ]
 gap> digraph := CayleyDigraph(group, [(1, 2, 3, 4), (2, 5)]);
-Error, the 2nd argument <gens> must consist of elements of the 1st argument,
+Error, the 3rd argument (a homog. list) must consist of elements of the 2nd ar\
+gument (a list)
 gap> group := FreeGroup(2);;
 gap> digraph := CayleyDigraph(group);
-Error, the 1st argument <G> must be a finite group,
+Error, the 2nd argument (a group) must be finite
path: tst/standard/grape.tst
user: login: wilfwilson
body: But now this error message is less helpful in this case, about the position of arguments! Because `CayleyDigraph` only has one argument here.

Also, I think it's much more useful to actually name the argument `<G>`, as it was before, because this tells the user that at the interactive break loop, they can get access to the misbehaving argument by typing `G` and investigate what it actually is.
created_at: 2021-03-11T14:48:33Z
author_association: COLLABORATOR
diff_hunk: @@ -309,3 +309,47 @@ gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4);
   </Description>
 </ManSection>
 <#/GAPDoc>
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set has consists of the permutations <C>p2</C>, <C>p3</C>, ...,
path: doc/examples.xml
user: login: wilfwilson
body: ```suggestion
    set consists of the permutations <C>p2</C>, <C>p3</C>, ...,
```
created_at: 2021-03-11T14:49:20Z
author_association: COLLABORATOR
diff_hunk: @@ -309,3 +309,47 @@ gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4);
   </Description>
 </ManSection>
 <#/GAPDoc>
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set has consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i -1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
path: doc/examples.xml
user: login: wilfwilson
body: ```suggestion
    of <C>[i, i - 1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
```
Perhaps a clearer way of defining these permutations would be as the permutations that reverse `[1..i]` and fix the other points.
created_at: 2021-03-11T14:49:40Z
author_association: COLLABORATOR
diff_hunk: @@ -48,3 +48,8 @@ DeclareOperation("PetersenGraph", [IsFunction]);
 DeclareConstructor("GeneralisedPetersenGraphCons", [IsDigraph, IsInt, IsInt]);
 DeclareOperation("GeneralisedPetersenGraph", [IsInt, IsInt]);
 DeclareOperation("GeneralisedPetersenGraph", [IsFunction, IsInt, IsInt]);
+
+DeclareConstructor("PancakeGraphCons", [IsDigraph, IsPosInt]);
+DeclareOperation("PancakeGraph", [IsPosInt]);
+DeclareOperation("PancakeGraph", [IsFunction, IsPosInt]);
+
path: gap/examples.gd
user: login: wilfwilson
body: ```suggestion
```
created_at: 2021-03-11T14:50:03Z
author_association: COLLABORATOR
diff_hunk: @@ -370,3 +370,39 @@ GeneralisedPetersenGraphCons);
 
 InstallMethod(GeneralisedPetersenGraph, "for integer, integer", [IsInt, IsInt],
 {n, k} -> GeneralisedPetersenGraphCons(IsImmutableDigraph, n, k));
+
+BindGlobal("DIGRAPHS_PrefixReversalGroup",
+function(n)
+  local id, A, i;
+  if n = 1 then
+    return Group(());
+  fi;
+  id := [1 .. n];
+  A := [];
+  for i in [2 .. n] do
+    id{[1 .. i]} := [i, i - 1 .. 1];
+    Add(A, PermList(id));
+  od;
+  return Group(A);
path: gap/examples.gi
user: login: wilfwilson
body: ```suggestion
  return Group(List([2 .. n], i -> PermList([i, i - 1 .. 1])), ());
```
I don't think you need to special case `n = 1`.  Currently the case `n = 1` for `PancakeGraph` is returning a digraph with one vertex and with a loop at that vertex. This doesn't match the documentation. A better result in my opinion (and what this code would provide) would be an empty digraph with one vertex.
created_at: 2021-03-11T14:56:05Z
author_association: COLLABORATOR
diff_hunk: @@ -226,6 +226,18 @@ Error, the arguments <n> and <k> must be non-negative integers,
 gap> JohnsonDigraph(IsMutableDigraph, 4, 2);
 <mutable digraph with 6 vertices, 24 edges>
 
+# PancakeGraph
+gap> D := PancakeGraph(3);
path: tst/standard/examples.tst
user: login: wilfwilson
body: Please also add a test for `PancakeGraph(1)` once its behaviour is agreed.
created_at: 2021-03-11T15:04:07Z
author_association: COLLABORATOR
diff_hunk: @@ -226,6 +226,18 @@ Error, the arguments <n> and <k> must be non-negative integers,
 gap> JohnsonDigraph(IsMutableDigraph, 4, 2);
 <mutable digraph with 6 vertices, 24 edges>
 
+# PancakeGraph
+gap> D := PancakeGraph(3);
path: tst/standard/examples.tst
user: login: james-d-mitchell
body: Thanks for the comments @wilfwilson !
created_at: 2021-03-22T09:30:07Z
author_association: MEMBER
diff_hunk: @@ -41,10 +48,11 @@ true
 gap> GeneratorsOfCayleyDigraph(digraph);
 [ () ]
 gap> digraph := CayleyDigraph(group, [(1, 2, 3, 4), (2, 5)]);
-Error, the 2nd argument <gens> must consist of elements of the 1st argument,
+Error, the 3rd argument (a homog. list) must consist of elements of the 2nd ar\
+gument (a list)
 gap> group := FreeGroup(2);;
 gap> digraph := CayleyDigraph(group);
-Error, the 1st argument <G> must be a finite group,
+Error, the 2nd argument (a group) must be finite
path: tst/standard/grape.tst
user: login: wilfwilson
body: It's fine though, since in practice you get
```
gap> digraph := CayleyDigraph(group);
Error, the 2nd argument (a group) must be finite at /Users/Wilf/gap/pkg/digraphs/gap/grape.gi:123 called from
CayleyDigraphCons( IsImmutableDigraph, G, GeneratorsOfGroup( G )
 ) at /Users/Wilf/gap/pkg/digraphs/gap/grape.gi:155 called from
```
which tells you that it's called `G`.
created_at: 2021-05-26T10:39:23Z
author_association: COLLABORATOR
diff_hunk: @@ -493,6 +493,46 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
path: doc/examples.xml
user: login: LRacine
body: Looking great! Pancake should be pancake though (inappropriate capitalisation).
created_at: 2021-05-26T14:06:34Z
author_association: CONTRIBUTOR
diff_hunk: @@ -493,6 +493,46 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
path: doc/examples.xml
user: login: LRacine
body: Pancake -> pancake
created_at: 2021-05-26T14:07:32Z
author_association: CONTRIBUTOR
diff_hunk: @@ -493,6 +493,46 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i - 1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
+    
+    If the optional first argument <A>filt</A> is not present, then <Ref
+    Filt="IsImmutableDigraph"/> is used by default.<P/>
+
+    See <URL>https://en.wikipedia.org/wiki/Pancake_graph</URL> for further
+    details. 
+
path: doc/examples.xml
user: login: LRacine
body: Is there documentation for the burnt pancake graph?
created_at: 2021-05-26T14:24:25Z
author_association: CONTRIBUTOR
diff_hunk: @@ -493,6 +493,46 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i - 1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
+    
+    If the optional first argument <A>filt</A> is not present, then <Ref
+    Filt="IsImmutableDigraph"/> is used by default.<P/>
+
+    See <URL>https://en.wikipedia.org/wiki/Pancake_graph</URL> for further
+    details. 
+
path: doc/examples.xml
user: login: marinaanagno
body: @LRacine I have created a pull request on James's branch and if you would like to have a look I'd love to hear your comments :)
https://github.com/james-d-mitchell/Digraphs/pull/14
created_at: 2021-05-26T14:30:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -493,6 +493,46 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i - 1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
+    
+    If the optional first argument <A>filt</A> is not present, then <Ref
+    Filt="IsImmutableDigraph"/> is used by default.<P/>
+
+    See <URL>https://en.wikipedia.org/wiki/Pancake_graph</URL> for further
+    details. 
+
path: doc/examples.xml
user: login: LRacine
body: @marinaanagno Thank you, doing so now
created_at: 2021-05-26T14:45:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -493,6 +493,46 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>Pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th Pancake graph is the Cayley graph of the
path: doc/examples.xml
user: login: marinaanagno
body: fixed in burnt pancake PR :)
created_at: 2021-05-26T14:47:41Z
author_association: CONTRIBUTOR
diff_hunk: @@ -89,37 +89,74 @@ function(imm, G, obj, act, adj)
   return D;
 end);
 
-InstallMethod(CayleyDigraph, "for a group with generators",
-[IsGroup, IsHomogeneousList],
-function(G, gens)
-  local elts, adj, D, edge_labels;
-
+InstallMethod(CayleyDigraphCons,
+"for IsMutableDigraph, group, and list of elements",
+[IsMutableDigraph, IsGroup, IsHomogeneousList],
+function(_, G, gens)
   if not IsFinite(G) then
-    ErrorNoReturn("the 1st argument <G> must be a finite group,");
+    ErrorNoReturn("the 2nd argument (a group) must be finite");
   elif not ForAll(gens, x -> x in G) then
-    ErrorNoReturn("the 2nd argument <gens> must consist of elements of the ",
-                  "1st argument,");
+    ErrorNoReturn("the 3rd argument (a homog. list) must consist of ",
+                  "elements of the 2nd argument (a group)");
   fi;
+  return Digraph(IsMutableDigraph,
+                 G,
+                 AsList(G),
+                 OnLeftInverse,
+                 {x, y} -> x ^ -1 * y in gens);
path: gap/grape.gi
user: login: reiniscirpons
body: This seems like a slightly suboptimal method for `CayleyDigraphCons`.
created_at: 2025-04-07T14:22:02Z
author_association: COLLABORATOR
diff_hunk: @@ -89,37 +89,74 @@ function(imm, G, obj, act, adj)
   return D;
 end);
 
-InstallMethod(CayleyDigraph, "for a group with generators",
-[IsGroup, IsHomogeneousList],
-function(G, gens)
-  local elts, adj, D, edge_labels;
-
+InstallMethod(CayleyDigraphCons,
+"for IsMutableDigraph, group, and list of elements",
+[IsMutableDigraph, IsGroup, IsHomogeneousList],
+function(_, G, gens)
   if not IsFinite(G) then
-    ErrorNoReturn("the 1st argument <G> must be a finite group,");
+    ErrorNoReturn("the 2nd argument (a group) must be finite");
   elif not ForAll(gens, x -> x in G) then
-    ErrorNoReturn("the 2nd argument <gens> must consist of elements of the ",
-                  "1st argument,");
+    ErrorNoReturn("the 3rd argument (a homog. list) must consist of ",
+                  "elements of the 2nd argument (a group)");
   fi;
+  return Digraph(IsMutableDigraph,
+                 G,
+                 AsList(G),
+                 OnLeftInverse,
+                 {x, y} -> x ^ -1 * y in gens);
+end);
 
+InstallMethod(CayleyDigraphCons,
+"for IsImmutableDigraph, group, and list of elements",
+[IsImmutableDigraph, IsGroup, IsHomogeneousList],
+function(_, G, gens)
+  local set, D, edge_labels;
+
+  # This method is a duplicate of the one above because the method for Digraph
+  # sets some additional attributes if IsImmutableDigraph is passed as 1st
+  # argument, and so we don't want to make a mutable version of the returned
+  # graph, and then make it immutable, because then those attributes won't be
+  # set.
+
+  if not IsFinite(G) then
+    ErrorNoReturn("the 2nd argument (a group) must be finite");
+  elif not ForAll(gens, x -> x in G) then
+    ErrorNoReturn("the 3rd argument (a homog. list) must consist ",
+                  "of elements of the 2nd argument (a list)");
+  fi;
+  set := AsSet(G);
   # vertex i in the Cayley digraph corresponds to elts[i].
-  elts := AsSet(G);
-  adj := {x, y} -> LeftQuotient(x, y) in gens;
+  D := Digraph(IsImmutableDigraph,
+               G,
+               set,
+               OnLeftInverse,
+               {x, y} -> LeftQuotient(x, y) in gens);
 
-  D := Digraph(IsImmutableDigraph, G, elts, OnLeftInverse, adj);
   SetFilterObj(D, IsCayleyDigraph);
   SetGroupOfCayleyDigraph(D, G);
   SetGeneratorsOfCayleyDigraph(D, gens);
-  SetDigraphVertexLabels(D, elts);
+  SetDigraphVertexLabels(D, AsList(G));
   # Out-neighbours of identity give the correspondence between edges & gens
-  edge_labels := elts{OutNeighboursOfVertex(D, Position(elts, One(G)))};
+  edge_labels := AsList(G){OutNeighboursOfVertex(D,
+                                                 Position(set, One(G)))};
   SetDigraphEdgeLabels(D, ListWithIdenticalEntries(Size(G), edge_labels));
-
   return D;
 end);
 
+InstallMethod(CayleyDigraph, "for a group and list of elements",
+[IsGroup, IsHomogeneousList],
+{G, gens} -> CayleyDigraphCons(IsImmutableDigraph, G, gens));
+
+InstallMethod(CayleyDigraph, "for a filter and group with generators",
+[IsFunction, IsGroup, IsHomogeneousList], CayleyDigraphCons);
+
 InstallMethod(CayleyDigraph, "for a group with generators",
 [IsGroup and HasGeneratorsOfGroup],
-G -> CayleyDigraph(G, GeneratorsOfGroup(G)));
+G -> CayleyDigraphCons(IsImmutableDigraph, G, GeneratorsOfGroup(G)));
+
+InstallMethod(CayleyDigraph, "for a filter and group with generators",
+[IsFunction, IsGroup and HasGeneratorsOfGroup],
+{filt, G} -> CayleyDigraphCons(filt, G, GeneratorsOfGroup(G)));
path: gap/grape.gi
user: login: reiniscirpons
body: Could you add docs for these new overloads?
created_at: 2025-04-07T16:09:50Z
author_association: COLLABORATOR
diff_hunk: @@ -89,37 +89,74 @@ function(imm, G, obj, act, adj)
   return D;
 end);
 
-InstallMethod(CayleyDigraph, "for a group with generators",
-[IsGroup, IsHomogeneousList],
-function(G, gens)
-  local elts, adj, D, edge_labels;
-
+InstallMethod(CayleyDigraphCons,
+"for IsMutableDigraph, group, and list of elements",
+[IsMutableDigraph, IsGroup, IsHomogeneousList],
+function(_, G, gens)
   if not IsFinite(G) then
-    ErrorNoReturn("the 1st argument <G> must be a finite group,");
+    ErrorNoReturn("the 2nd argument (a group) must be finite");
   elif not ForAll(gens, x -> x in G) then
-    ErrorNoReturn("the 2nd argument <gens> must consist of elements of the ",
-                  "1st argument,");
+    ErrorNoReturn("the 3rd argument (a homog. list) must consist of ",
+                  "elements of the 2nd argument (a group)");
   fi;
+  return Digraph(IsMutableDigraph,
+                 G,
+                 AsList(G),
+                 OnLeftInverse,
+                 {x, y} -> x ^ -1 * y in gens);
path: gap/grape.gi
user: login: reiniscirpons
body: I've made issue #750 for this, as such this no longer needs to be addressed in this PR.
created_at: 2025-04-07T16:10:55Z
author_association: COLLABORATOR
diff_hunk: @@ -367,6 +367,82 @@ gap> TriangularGridGraph(IsMutable, 3, 3);
 </ManSection>
 <#/GAPDoc>
 
+<#GAPDoc Label="PancakeGraph">
+<ManSection>
+  <Oper Name="PancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>pancake graph</E> with <M>n!</M> vertices and <M>n!(n - 1)</M>
+    directed edges. The <M>n</M>th pancake graph is the Cayley graph of the
+    symmetric group acting on <C>[1 .. <A>n</A>]</C> with respect to the
+    generating set consisting of the <Q>prefix reversals</Q>. This generating
+    set consists of the permutations <C>p2</C>, <C>p3</C>, ...,
+    <C>p<A>n</A></C> where <C>ListPerm(pi, <A>n</A>)</C> is the concatenation
+    of <C>[i, i - 1 .. 1]</C> and <C>[i + 1 .. <A>n</A>]</C>. 
+    <P/>
+    
+    If the optional first argument <A>filt</A> is not present, then <Ref
+    Filt="IsImmutableDigraph"/> is used by default.<P/>
+
+    See <URL>https://en.wikipedia.org/wiki/Pancake_graph</URL> for further
+    details. 
+
+<Example><![CDATA[
+gap> D := PancakeGraph(5);
+<immutable Hamiltonian connected symmetric digraph with 120 vertices, \
+480 edges>
+gap> DigraphUndirectedGirth(D);
+6
+gap> ChromaticNumber(D);
+3
+gap> IsHamiltonianDigraph(D);
+true
+gap> IsCayleyDigraph(D);
+true
+gap> IsVertexTransitive(D);
+true]]></Example>
+  </Description>
+</ManSection>
+<#/GAPDoc>
+
+<#GAPDoc Label="BurntPancakeGraph">
+<ManSection>
+  <Oper Name="BurntPancakeGraph" Arg="[filt, ]n"/>
+  <Returns>A digraph.</Returns>
+  <Description>
+    If <A>n</A> is a positive integer, then this operation returns
+    the <E>burnt pancake graph</E> with <M>n!</M> vertices and <M>n2^(n)n!</M>
path: doc/examples.xml
user: login: reiniscirpons
body: ```suggestion
    the <E>burnt pancake graph</E> with <M>n!</M> vertices and <M>n2^{n}n!</M>
```
To make `2^n` display correctly in latex.
created_at: 2025-04-07T16:21:58Z
author_association: COLLABORATOR

PR comments:
user: login: codecov[bot]
created_at: 2021-02-10T16:15:59Z
body: # [Codecov](https://codecov.io/gh/digraphs/Digraphs/pull/403?src=pr&el=h1) Report
> Merging [#403](https://codecov.io/gh/digraphs/Digraphs/pull/403?src=pr&el=desc) (2232361) into [master](https://codecov.io/gh/digraphs/Digraphs/commit/0c909dde98c138085f666b995547690045f1759e?el=desc) (0c909dd) will **increase** coverage by `0.24%`.
> The diff coverage is `98.48%`.


```diff
@@            Coverage Diff             @@
##           master     #403      +/-   ##
==========================================
+ Coverage   97.01%   97.25%   +0.24%     
==========================================
  Files          45       45              
  Lines       12884    12499     -385     
==========================================
- Hits        12499    12156     -343     
+ Misses        385      343      -42     
```


| [Impacted Files](https://codecov.io/gh/digraphs/Digraphs/pull/403?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [gap/examples.gi](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-Z2FwL2V4YW1wbGVzLmdp) | `98.68% <96.29%> (-0.24%)` | :arrow_down: |
| [gap/examples.gd](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-Z2FwL2V4YW1wbGVzLmdk) | `100.00% <100.00%> (ø)` | |
| [gap/grape.gd](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-Z2FwL2dyYXBlLmdk) | `100.00% <100.00%> (ø)` | |
| [gap/grape.gi](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-Z2FwL2dyYXBlLmdp) | `99.50% <100.00%> (+0.62%)` | :arrow_up: |
| [src/bitarray.c](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-c3JjL2JpdGFycmF5LmM=) | `93.33% <0.00%> (-1.91%)` | :arrow_down: |
| [src/planar.c](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-c3JjL3BsYW5hci5j) | `93.75% <0.00%> (-0.37%)` | :arrow_down: |
| [src/perms.c](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-c3JjL3Blcm1zLmM=) | `77.77% <0.00%> (-0.35%)` | :arrow_down: |
| [src/homos-graphs.c](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-c3JjL2hvbW9zLWdyYXBocy5j) | `98.66% <0.00%> (-0.27%)` | :arrow_down: |
| [src/homos.c](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-c3JjL2hvbW9zLmM=) | `99.08% <0.00%> (-0.07%)` | :arrow_down: |
| [src/cliques.c](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree#diff-c3JjL2NsaXF1ZXMuYw==) | `99.26% <0.00%> (-0.04%)` | :arrow_down: |
| ... and [11 more](https://codecov.io/gh/digraphs/Digraphs/pull/403/diff?src=pr&el=tree-more) | |

author_association: NONE
user: login: olexandr-konovalov
created_at: 2021-03-03T14:46:18Z
body: @james-d-mitchell merge conflicts now should be resolved...
author_association: CONTRIBUTOR
user: login: marinaanagno
created_at: 2021-03-11T16:07:10Z
body: Just a reminder, there is a pull request on this branch about the burnt pancake graph (which has to do with signed permutations). I haven't finished documented it yet, but I guess I should do this and @james-d-mitchell should approve before merging this into master, if we still want burnt pancake as a family of graphs in digraphs :)
author_association: CONTRIBUTOR
user: login: reiniscirpons
created_at: 2025-04-07T16:13:00Z
body: A wonderful graph to have in our library, thanks James. Looks good and tests pass on my end, just one documentation improvement and should be good to merge. 
author_association: COLLABORATOR
user: login: james-d-mitchell
created_at: 2025-04-08T06:58:44Z
body: > A wonderful graph to have in our library, thanks James. Looks good and tests pass on my end, just one documentation improvement and should be good to merge.

Done, I'll merge when/if the CI passes.
author_association: MEMBER