diff --git a/gap/grahom.gd b/gap/grahom.gd index 7bfd16d20..d0aa6d5a7 100644 --- a/gap/grahom.gd +++ b/gap/grahom.gd @@ -87,3 +87,5 @@ DeclareOperation("IsDigraphEmbedding", DeclareOperation("IsDigraphColouring", [IsDigraph, IsList]); DeclareOperation("IsDigraphColouring", [IsDigraph, IsTransformation]); + +DeclareGlobalFunction("DIGRAPHS_RespectsColouring"); diff --git a/gap/grahom.gi b/gap/grahom.gi index 3d2fbdacd..eea35c204 100644 --- a/gap/grahom.gi +++ b/gap/grahom.gi @@ -451,6 +451,50 @@ end); # IsDigraph{Homo/Epi/...}morphism ######################################################################## +# Given a non-negative integer and a homogeneous list , +# this global function tests whether is a valid partition +# of the list [1 .. n]. A valid partition of [1 .. n] is either: +# +# 1. A list of length consisting of a numbers, such that the set of these +# numbers is [1 .. m] for some m <= n. +# 2. A list of non-empty disjoint lists whose union is [1 .. n]. +# +# If is a valid partition of [1 .. n] then this global function +# returns the partition, in form 1 (converting it to this form if necessary). +# If is invalid, then the function returns . + +# Given: +# +# 1) two digraphs and , +# 2) a transformation or permutation mapping the vertices of to +# , and +# 3) two lists and of positive integers defining vertex +# colourings of and , +# +# this global function tests whether respects the colouring, i.e. whether +# for all vertices i in , cols[i] = cols[i ^ x]. + +InstallGlobalFunction(DIGRAPHS_RespectsColouring, +function(src, ran, x, cols1, cols2) + + if not IsDigraph(src) then + ErrorNoReturn("the first argument must be a digraph,"); + elif not IsDigraph(ran) then + ErrorNoReturn("the second argument must be a digraph,"); + elif not (IsPerm(x) or IsTransformation(x)) then + ErrorNoReturn("the third argument must be a transformation or ", + "a permutation,"); + elif Maximum(OnTuples(DigraphVertices(src), x)) > DigraphNrVertices(ran) then + ErrorNoReturn("the third argument must map the vertices of the first ", + "argument into the vertices of the second argument ", + ","); + fi; + DIGRAPHS_ValidateVertexColouring(DigraphNrVertices(src), cols1); + DIGRAPHS_ValidateVertexColouring(DigraphNrVertices(ran), cols2); + + return ForAll(DigraphVertices(src), i -> cols1[i] = cols2[i ^ x]); +end); + InstallMethod(IsDigraphHomomorphism, "for a digraph by out-neighbours, a digraph, and a perm", [IsDigraphByOutNeighboursRep, IsDigraph, IsPerm], @@ -492,15 +536,9 @@ end); InstallMethod(IsDigraphHomomorphism, "for a digraph by out-neighbours, a digraph, a transformation, and two lists", [IsDigraphByOutNeighboursRep, IsDigraph, IsTransformation, IsList, IsList], -function(src, ran, x, colours1, colours2) - if not IsDigraphHomomorphism(src, ran, x) then - return false; - fi; - - DIGRAPHS_ValidateVertexColouring(DigraphNrVertices(src), colours1); - DIGRAPHS_ValidateVertexColouring(DigraphNrVertices(ran), colours2); - - return ForAll(DigraphVertices(src), i -> colours1[i] = colours2[i ^ x]); +function(src, ran, x, cols1, cols2) + return IsDigraphHomomorphism(src, ran, x) and + DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphEndomorphism, "for a digraph and a transformation", @@ -521,9 +559,9 @@ end); InstallMethod(IsDigraphEpimorphism, "for digraph, digraph, and transformation", [IsDigraph, IsDigraph, IsTransformation, IsList, IsList], -function(src, ran, x, c1, c2) - return IsDigraphHomomorphism(src, ran, x, c1, c2) - and OnSets(DigraphVertices(src), x) = DigraphVertices(ran); +function(src, ran, x, cols1, cols2) + return IsDigraphEpimorphism(src, ran, x) and + DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphEpimorphism, "for digraph, digraph, and perm", @@ -536,9 +574,9 @@ end); InstallMethod(IsDigraphEpimorphism, "for digraph, digraph, perm, list, and list", [IsDigraph, IsDigraph, IsPerm, IsList, IsList], -function(src, ran, x, c1, c2) - return IsDigraphHomomorphism(src, ran, x, c1, c2) - and OnSets(DigraphVertices(src), x) = DigraphVertices(ran); +function(src, ran, x, cols1, cols2) + return IsDigraphEpimorphism(src, ran, x) + and DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphMonomorphism, @@ -552,38 +590,19 @@ end); InstallMethod(IsDigraphMonomorphism, "for digraph, digraph, transformation, list, list", [IsDigraph, IsDigraph, IsTransformation, IsList, IsList], -function(src, ran, x, c1, c2) - return IsDigraphHomomorphism(src, ran, x, c1, c2) - and IsInjectiveListTrans(DigraphVertices(src), x); +function(src, ran, x, cols1, cols2) + return IsDigraphMonomorphism(src, ran, x) + and DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphMonomorphism, "for digraph, digraph, and perm", [IsDigraph, IsDigraph, IsPerm], IsDigraphHomomorphism); InstallMethod(IsDigraphMonomorphism, "for digraph, digraph, perm, list, list", -[IsDigraph, IsDigraph, IsPerm, IsList, IsList], IsDigraphHomomorphism); - -InstallMethod(IsDigraphEmbedding, -"for digraph, digraph by out-neighbours, transformation, list, and list", -[IsDigraph, IsDigraphByOutNeighboursRep, IsTransformation, IsList, IsList], -function(src, ran, x, c1, c2) - local y, induced, i, j; - if not IsDigraphMonomorphism(src, ran, x, c1, c2) then - return false; - fi; - y := MappingPermListList(OnTuples(DigraphVertices(src), x), - DigraphVertices(src)); - induced := BlistList(DigraphVertices(ran), OnSets(DigraphVertices(src), x)); - for i in DigraphVertices(ran) do - if induced[i] then - for j in OutNeighbours(ran)[i] do - if induced[j] and not IsDigraphEdge(src, i ^ y, j ^ y) then - return false; - fi; - od; - fi; - od; - return true; +[IsDigraph, IsDigraph, IsPerm, IsList, IsList], +function(src, ran, x, cols1, cols2) + return IsDigraphMonomorphism(src, ran, x) + and DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphEmbedding, @@ -609,6 +628,14 @@ function(src, ran, x) return true; end); +InstallMethod(IsDigraphEmbedding, +"for digraph, digraph by out-neighbours, transformation, list, and list", +[IsDigraph, IsDigraphByOutNeighboursRep, IsTransformation, IsList, IsList], +function(src, ran, x, cols1, cols2) + return IsDigraphEmbedding(src, ran, x) + and DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); +end); + InstallMethod(IsDigraphEmbedding, "for a digraph, a digraph by out-neighbours, and a perm", [IsDigraph, IsDigraphByOutNeighboursRep, IsPerm], @@ -634,23 +661,9 @@ end); InstallMethod(IsDigraphEmbedding, "for a digraph, a digraph by out-neighbours, a perm, a list, and a list", [IsDigraph, IsDigraphByOutNeighboursRep, IsPerm, IsList, IsList], -function(src, ran, x, c1, c2) - local y, induced, i, j; - if not IsDigraphHomomorphism(src, ran, x, c1, c2) then - return false; - fi; - y := x ^ -1; - induced := BlistList(DigraphVertices(ran), OnSets(DigraphVertices(src), x)); - for i in DigraphVertices(ran) do - if induced[i] then - for j in OutNeighbours(ran)[i] do - if induced[j] and not IsDigraphEdge(src, i ^ y, j ^ y) then - return false; - fi; - od; - fi; - od; - return true; +function(src, ran, x, cols1, cols2) + return IsDigraphEmbedding(src, ran, x) + and DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphColouring, "for a digraph by out-neighbours and a list", diff --git a/gap/isomorph.gi b/gap/isomorph.gi index bc817e1a0..ee4fb69c6 100644 --- a/gap/isomorph.gi +++ b/gap/isomorph.gi @@ -721,13 +721,9 @@ end); InstallMethod(IsDigraphIsomorphism, "for digraph, digraph, permutation, list, and list", [IsDigraph, IsDigraph, IsPerm, IsList, IsList], -function(src, ran, x, c1, c2) - if IsMultiDigraph(src) or IsMultiDigraph(ran) then - ErrorNoReturn("the 1st and 2nd arguments and must not have ", - "multiple edges,"); - fi; - return IsDigraphHomomorphism(src, ran, x, c1, c2) - and IsDigraphHomomorphism(ran, src, x ^ -1, c1, c2); +function(src, ran, x, cols1, cols2) + return IsDigraphIsomorphism(src, ran, x) + and DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphAutomorphism, "for a digraph and a permutation", @@ -753,13 +749,9 @@ end); InstallMethod(IsDigraphIsomorphism, "for digraph, digraph, transformation, list, and list", [IsDigraph, IsDigraph, IsTransformation, IsList, IsList], -function(src, ran, x, c1, c2) - local y; - y := AsPermutation(RestrictedTransformation(x, DigraphVertices(src))); - if y = fail then - return false; - fi; - return IsDigraphIsomorphism(src, ran, y, c1, c2); +function(src, ran, x, cols1, cols2) + return IsDigraphIsomorphism(src, ran, x) + and DIGRAPHS_RespectsColouring(src, ran, x, cols1, cols2); end); InstallMethod(IsDigraphAutomorphism, "for a digraph and a transformation",