diff --git a/doc/oper.xml b/doc/oper.xml
index c7cf5d218..8710f6e68 100644
--- a/doc/oper.xml
+++ b/doc/oper.xml
@@ -1053,6 +1053,51 @@ gap> QuotientDigraph(EmptyDigraph(0), []);
<#/GAPDoc>
+<#GAPDoc Label="DigraphHalfSquare">
+
+
+
+ A digraph or a list of digraphs.
+
+ If digraph is a bipartite digraph D, and list is a list
+ of vertices U as one of the two sides of D (see
+ , ), then
+ DigraphHalfSquare returns the bipartite half or half-square of
+ digraph with respect to list. If digraph is not
+ bipartite, or list is not a side of digraph, then an
+ error is raised.
+
+ The half-square of D with respect to U is a digraph whose
+ vertices are the elements of U, with an edge from u_1 to
+ u_2 if and only if there exists a directed path u_1 \to x \to
+ u_2 in D. The vertices are 1, \ldots, |U|,
+ where the vertex i corresponds to the i-th smallest element of
+ U.
+
+ DigraphHalfSquares returns a list containing two digraphs, the
+ half square of digraph with respect to list, and the half
+ square with respect to the vertices of digraph not in list,
+ i.e. the half squares of both sides of the bipartition.
+ D := ChainDigraph(5);;
+gap> DigraphBicomponents(D);
+[ [ 1, 3, 5 ], [ 2, 4 ] ]
+gap> D1 := DigraphHalfSquare(D, [1, 3, 5]);;
+gap> OutNeighbours(D1);
+[ [ 2 ], [ 3 ], [ ] ]
+gap> D := DigraphSymmetricClosure(ChainDigraph(5));;
+gap> OutNeighbours(DigraphHalfSquare(D, [1, 3, 5]));
+[ [ 2 ], [ 1, 3 ], [ 2 ] ]
+gap> D := DigraphHalfSquares(CompleteBipartiteDigraph(2, 4), [1, 2]);;
+gap> IsIsomorphicDigraph(D[1], CompleteDigraph(2));
+true
+gap> IsIsomorphicDigraph(D[2], CompleteDigraph(4));
+true
+]]>
+
+
+<#/GAPDoc>
+
<#GAPDoc Label="IsDigraphEdge">
<#Include Label="DigraphShortestPathSpanningTree">
<#Include Label="QuotientDigraph">
+ <#Include Label="DigraphHalfSquare">
<#Include Label="DigraphReverse">
<#Include Label="DigraphDual">
<#Include Label="DigraphSymmetricClosure">
diff --git a/gap/oper.gd b/gap/oper.gd
index ce77dc770..f69694db1 100644
--- a/gap/oper.gd
+++ b/gap/oper.gd
@@ -76,6 +76,9 @@ DeclareOperation("OnMultiDigraphs", [IsDigraph, IsPerm, IsPerm]);
# 5. Substructures and quotients . . .
DeclareOperation("QuotientDigraph", [IsDigraph, IsList]);
DeclareOperation("InducedSubdigraph", [IsDigraph, IsList]);
+DeclareOperation("DigraphHalfSquareNC", [IsDigraph, IsList]);
+DeclareOperation("DigraphHalfSquare", [IsDigraph, IsList]);
+DeclareOperation("DigraphHalfSquares", [IsDigraph, IsList]);
# 6. In and out degrees, neighbours, and edges of vertices . . .
DeclareOperation("InDegreeOfVertex", [IsDigraph, IsPosInt]);
diff --git a/gap/oper.gi b/gap/oper.gi
index 638bf5331..dd01c73b2 100644
--- a/gap/oper.gi
+++ b/gap/oper.gi
@@ -1272,6 +1272,70 @@ InstallMethod(QuotientDigraph,
{D, partition} ->
MakeImmutable(QuotientDigraph(DigraphMutableCopy(D), partition)));
+InstallMethod(DigraphHalfSquareNC, "for a digraph and a list",
+[IsDigraph, IsList],
+function(D, U)
+ local pos, i, u, w, x, sharecommon, outnbs;
+
+ # for vertex re-numbering from D to U
+ pos := ListWithIdenticalEntries(DigraphNrVertices(D), 0);
+ for i in [1 .. Length(U)] do
+ pos[U[i]] := i;
+ od;
+
+ # two vertices u, x are joined if they share a common neighbour w in
+ # the other side of the bipartition, i.e. there exists a path u -> w -> x
+ outnbs := [];
+ for i in [1 .. Length(U)] do
+ u := U[i];
+ sharecommon := [];
+ for w in OutNeighboursOfVertex(D, u) do
+ for x in OutNeighboursOfVertex(D, w) do
+ if x <> u then
+ Add(sharecommon, pos[x]);
+ fi;
+ od;
+ od;
+ Add(outnbs, Set(sharecommon));
+ od;
+
+ return Digraph(outnbs);
+end);
+
+InstallMethod(DigraphHalfSquare, "for a digraph and a list",
+[IsDigraph, IsList],
+function(D, U)
+ local nU;
+
+ if not IsBipartiteDigraph(D) then
+ ErrorNoReturn("the 1st argument must be a bipartite digraph");
+ fi;
+
+ nU := Set(U);
+ if not IsSubset(DigraphVertices(D), nU) then
+ ErrorNoReturn("the 2nd argument must be a list of vertices of ");
+ fi;
+
+ # check if the set U and its complement D \ U are bicomponents, i.e. no edges
+ # between vertices in the same set
+ # can't do 'U in DigraphBicomponents(D)' because the partition isn't unique
+ if not (IsIndependentSet(D, nU) and
+ IsIndependentSet(D, Difference(DigraphVertices(D), nU))) then
+ ErrorNoReturn("the digraph is not bipartite with respect to the vertex",
+ " set ");
+ fi;
+
+ return DigraphHalfSquareNC(D, nU);
+end);
+
+InstallMethod(DigraphHalfSquares, "for a digraph and a list",
+[IsDigraph, IsList],
+function(D, U)
+ local complement;
+ complement := Difference(DigraphVertices(D), U);
+ return [DigraphHalfSquare(D, U), DigraphHalfSquare(D, complement)];
+end);
+
#############################################################################
# 6. In and out degrees, neighbours, and edges of vertices
#############################################################################
diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst
index 1c3872fc6..5b7014386 100644
--- a/tst/standard/oper.tst
+++ b/tst/standard/oper.tst
@@ -10,7 +10,7 @@
##
#@local C, D, D1, D2, D3, D3_edges, DD
-#@local G, G1, L, TestPartialOrderDigraph
+#@local G, G1, L, L1, TestPartialOrderDigraph
#@local TestPartialOrderDigraph2, TestUnion, a, adj, b, comps, copy, d, e
#@local edges, edges2, func, g, gr, gr1, gr2, gr3, gr4, gri, grrt, grt, h, i
#@local i1, i2, id, idom, in1, in2, in3, iter, j1, j2, m, m1, m2, mat, n, nbs
@@ -491,6 +491,40 @@ gap> qr := QuotientDigraph(gr, [[1], [2, 3, 5, 7], [4, 6, 8]]);
gap> OutNeighbours(qr);
[ [ 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ]
+# DigraphHalfSquare[s]
+gap> D := Digraph([[2], [3], [1]]);;
+gap> DigraphHalfSquare(D, [1]);
+Error, the 1st argument must be a bipartite digraph
+gap> DigraphHalfSquares(D, [1]);
+Error, the 1st argument must be a bipartite digraph
+gap> D := ChainDigraph(5);;
+gap> DigraphBicomponents(D);
+[ [ 1, 3, 5 ], [ 2, 4 ] ]
+gap> DigraphHalfSquare(D, [6]);
+Error, the 2nd argument must be a list of vertices of
+gap> DigraphHalfSquare(D, [1, 3]);
+Error, the digraph is not bipartite with respect to the vertex set
+gap> OutNeighbours(DigraphHalfSquare(D, [1, 3, 5]));
+[ [ 2 ], [ 3 ], [ ] ]
+gap> OutNeighbours(DigraphHalfSquare(D, [2, 4]));
+[ [ 2 ], [ ] ]
+gap> D := DigraphSymmetricClosure(ChainDigraph(5));;
+gap> OutNeighbours(DigraphHalfSquare(D, [1, 3, 5]));
+[ [ 2 ], [ 1, 3 ], [ 2 ] ]
+gap> D := CompleteBipartiteDigraph(3, 3);;
+gap> D1 := DigraphHalfSquare(D, DigraphBicomponents(D)[1]);;
+gap> IsIsomorphicDigraph(D1, CompleteDigraph(3));
+true
+gap> D := CompleteBipartiteDigraph(2, 4);;
+gap> L := DigraphHalfSquares(D, DigraphBicomponents(D)[1]);;
+gap> IsIsomorphicDigraph(L[1], CompleteDigraph(2));
+true
+gap> IsIsomorphicDigraph(L[2], CompleteDigraph(4));
+true
+gap> L1 := DigraphHalfSquares(D, DigraphBicomponents(D)[2]);;
+gap> L = Reversed(L1);
+true
+
# DigraphInEdges and DigraphOutEdges: for a vertex
gap> gr := Digraph([[2, 2, 2, 2, 2], [1, 1, 1, 1], [1], [3, 2]]);