Skip to content

Commit 92c09bd

Browse files
kernel: clarify the images argument for HomomorphismDigraphsFinder
This commit adds some comments to the kernel code, an info warning, and some doc to clarify the meaning of the <image> argument to HomomorphismDigraphsFinder. See the discussion at: #697 for details.
1 parent d02b521 commit 92c09bd

File tree

8 files changed

+80
-7
lines changed

8 files changed

+80
-7
lines changed

doc/grahom.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,20 @@
9595
This argument should be a subset of the vertices of the graph <A>D2</A>.
9696
<C>HomomorphismDigraphsFinder</C> only finds homomorphisms from
9797
<A>D1</A> to the subgraph of <A>D2</A> induced by the vertices
98-
<A>image</A>.
98+
<A>image</A>.<P/>
99+
100+
The returned homomorphisms (if any) are still "up to the action" of the
101+
group specified by <A>aut_grp</A> (which is the entire automorphism
102+
group by default). This might generate unexpected results. For example,
103+
if <A>D1</A> has automorphism group where one orbit consists of, say,
104+
<C>1</C> and <C>2</C>, then <C>HomomorphismDigraphsFinder</C> will only
105+
attempt to find homomorphisms mapping <C>1</C> to <C>1</C>, and if
106+
there are no such homomorphisms with image set equal to <A>image</A>,
107+
then no homomorphisms will be returned (even if there is a homomorphism
108+
from <A>D1</A> to <A>D2</A> mapping <C>1</C> to <C>2</C>). To ensure that
109+
that <B>all</B> homomorphisms with image set equal to <A>image</A> are
110+
considered it is necessary for the last argument <A>aut_grp</A> to be
111+
the trivial permutation group.
99112
</Item>
100113

101114
<Mark><A>partial_map</A></Mark>
@@ -133,6 +146,7 @@
133146
idea for this to be the <Ref Attr="DigraphWelshPowellOrder"/>, i.e.
134147
vertices ordered from highest to lowest degree.
135148
</Item>
149+
<Mark><A>aut_grp</A></Mark>
136150
<Item>
137151
The optional argument <A>aut_grp</A> should be a subgroup of the
138152
automorphism group of <A>D2</A>. This function returns unique
@@ -149,6 +163,10 @@ gap> D := DigraphSymmetricClosure(D);
149163
<immutable symmetric digraph with 10 vertices, 18 edges>
150164
gap> HomomorphismDigraphsFinder(D, D, fail, [], infinity, 2, 0,
151165
> [3, 4], [], fail, fail);
166+
#I WARNING you are trying to find homomorphisms by specifying a subset
167+
of the vertices of the target digraph. This might lead to unexpected
168+
results! If this happens, try passing Group(()) as the last argument.
169+
Please see the documentation of HomomorphismDigraphsFinder for details.
152170
[ Transformation( [ 3, 4, 3, 4, 3, 4, 3, 4, 3, 4 ] ),
153171
Transformation( [ 4, 3, 4, 3, 4, 3, 4, 3, 4, 3 ] ) ]
154172
gap> D2 := CompleteDigraph(6);;

src/bitarray.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
////////////////////////////////////////////////////////////////////////
3434

3535
bool LOOKUPS_INITIALISED = false;
36-
size_t* NR_BLOCKS_LOOKUP = NULL;
36+
size_t* NR_BLOCKS_LOOKUP = NULL;
3737
size_t* QUOTIENT_LOOKUP = NULL;
3838
size_t* REMAINDER_LOOKUP = NULL;
3939
Block* MASK_LOOKUP = NULL;
@@ -113,7 +113,7 @@ BitArray* new_bit_array(uint16_t const nr_bits) {
113113
bit_array->nr_bits = nr_bits;
114114
bit_array->nr_blocks =
115115
((nr_bits % NR_BITS_PER_BLOCK) == 0 ? nr_bits / NR_BITS_PER_BLOCK
116-
: nr_bits / NR_BITS_PER_BLOCK + 1);
116+
: nr_bits / NR_BITS_PER_BLOCK + 1);
117117
bit_array->blocks = safe_calloc(bit_array->nr_blocks, NR_BITS_PER_BLOCK);
118118

119119
return bit_array;
@@ -141,6 +141,7 @@ void set_bit_array_from_gap_list(BitArray* const bit_array, Obj list_obj) {
141141
return;
142142
}
143143
init_bit_array(bit_array, false, bit_array->nr_bits);
144+
// TODO assert that bit_array->nr_bits > LEN_LIST(list_obj)?
144145
for (int i = 1; i <= LEN_LIST(list_obj); i++) {
145146
if (ISB_LIST(list_obj, i)) {
146147
set_bit_array_from_gap_int(bit_array, ELM_LIST(list_obj, i));

src/bitarray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,5 @@ void set_bit_array_from_gap_int(BitArray* const bit_array, Obj o);
195195
//! plain or dense).
196196
void set_bit_array_from_gap_list(BitArray* const bit_array, Obj list_obj);
197197

198+
// void print_bit_array(BitArray const* const bit_array);
198199
#endif // DIGRAPHS_SRC_BITARRAY_H_

src/digraphs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Obj IsSubset;
5757
Obj OnTuples;
5858
Obj Group;
5959
Obj ClosureGroup;
60+
Obj InfoWarning;
6061

6162
static inline bool IsAttributeStoringRep(Obj o) {
6263
return (CALL_1ARGS(IsAttributeStoringRepObj, o) == True ? true : false);
@@ -2253,6 +2254,7 @@ static Int InitKernel(StructInitInfo* module) {
22532254
ImportGVarFromLibrary("OnTuples", &OnTuples);
22542255
ImportGVarFromLibrary("Group", &Group);
22552256
ImportGVarFromLibrary("ClosureGroup", &ClosureGroup);
2257+
ImportGVarFromLibrary("InfoWarning", &InfoWarning);
22562258
/* return success */
22572259
return 0;
22582260
}

src/digraphs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ extern Obj GeneratorsOfGroup;
3535
extern Obj IsDigraph;
3636
extern Obj IsMultiDigraph;
3737
extern Obj IsDigraphEdge;
38+
extern Obj InfoWarning;
3839

3940
#endif // DIGRAPHS_SRC_DIGRAPHS_H_

src/homos.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
// 1. Try other bit hacks for iterating through set bits
2626

2727
#include "homos.h"
28+
2829
// C headers
2930
#include <setjmp.h> // for longjmp, setjmp, jmp_buf
3031
#include <stdbool.h> // for true, false, bool
3132
#include <stddef.h> // for NULL
3233
#include <stdint.h> // for uint16_t, uint64_t
3334
#include <stdlib.h> // for malloc, NULL
34-
#ifdef DIGRAPHS_ENABLE_STATS
35-
#include <time.h> // for time
36-
#endif
3735

3836
// GAP headers
3937
#include "gap-includes.h"
@@ -50,6 +48,12 @@
5048
#include "safemalloc.h" // for safe_mallov
5149
#include "schreier-sims.h" // for PermColl, . . .
5250

51+
#ifdef DIGRAPHS_ENABLE_STATS
52+
// This include has to come after digraphs-config.h since that's where
53+
// DIGRAPHS_ENABLE_STATS is defined
54+
#include <time.h> // for time
55+
#endif
56+
5357
////////////////////////////////////////////////////////////////////////////////
5458
// 1. Macros
5559
////////////////////////////////////////////////////////////////////////////////
@@ -135,6 +139,7 @@ extern Obj AutomorphismGroup;
135139
extern Obj IsPermGroup;
136140
extern Obj IsDigraphAutomorphism;
137141
extern Obj LargestMovedPointPerms;
142+
extern Obj InfoWarning;
138143

139144
////////////////////////////////////////////////////////////////////////////////
140145
// 3. Global variables
@@ -147,7 +152,6 @@ static Obj (*HOOK)(void*, // HOOK function applied to every homo found
147152
const uint16_t*);
148153
static void* USER_PARAM; // a USER_PARAM for the hook
149154

150-
// Values in MAP are restricted to those positions in IMAGE_RESTRICT
151155
static jmp_buf OUTOFHERE; // so we can jump out of the deepest
152156

153157
static bool ORDERED; // true if the vertices of the domain/source digraph
@@ -680,6 +684,7 @@ static void find_graph_homos(uint16_t depth,
680684
}
681685
}
682686
DIGRAPHS_ASSERT(get_bit_array(MAP_UNDEFINED[depth], next));
687+
DIGRAPHS_ASSERT(next < GRAPH1->nr_vertices);
683688

684689
if (rank < hint) {
685690
copy_bit_array(
@@ -2186,6 +2191,30 @@ Obj FuncHomomorphismDigraphsFinder(Obj self, Obj args) {
21862191
}
21872192
}
21882193

2194+
if (image_obj != Fail
2195+
&& LEN_LIST(image_obj) != DigraphNrVertices(digraph2_obj)) {
2196+
bool warn = false;
2197+
if (aut_grp_obj == Fail) {
2198+
warn = true;
2199+
} else {
2200+
Obj gens = CALL_1ARGS(GeneratorsOfGroup, aut_grp_obj);
2201+
Int lmp = INT_INTOBJ(CALL_1ARGS(LargestMovedPointPerms, gens));
2202+
warn = lmp > 0;
2203+
}
2204+
if (warn) {
2205+
Obj msg = MakeImmString(
2206+
"WARNING you are trying to find homomorphisms by specifying a "
2207+
"subset of the vertices of the target digraph. This might lead "
2208+
"to unexpect results! If this happens, try passing Group(()) as the "
2209+
"last argument. Please see the documentation of "
2210+
"HomomorphismDigraphsFinder for details.");
2211+
Obj info_args = NEW_PLIST(T_PLIST, 1);
2212+
SET_ELM_PLIST(info_args, 1, msg);
2213+
SET_LEN_PLIST(info_args, 1);
2214+
InfoDoPrint(InfoWarning, INTOBJ_INT(0), info_args);
2215+
}
2216+
}
2217+
21892218
// Some conditions that immediately rule out there being any homomorphisms.
21902219
if (((INT_INTOBJ(injective_obj) == 1 || INT_INTOBJ(injective_obj) == 2)
21912220
&& ((hint_obj != Fail

tst/extreme/grahom.tst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ gap> Size(Semigroup(gens));
2929
105120
3030
gap> HomomorphismDigraphsFinder(gr, gr, fail, [], infinity, fail, 0,
3131
> [1, 14, 28, 39, 42], [], fail, fail);;
32+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
3233
gap> str := HomomorphismDigraphsFinder(gr, gr, fail, [], infinity, fail, 0,
3334
> [1, 14, 28, 39, 42], [], fail, fail);;
35+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
3436
gap> Length(str);
3537
192
3638

@@ -424,12 +426,14 @@ gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 25, 0, [1 .. 40],
424426
37, 38 ] ) ]
425427
gap> t := HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 23, 0,
426428
> [4 .. 37], [], fail, fail, DigraphWelshPowellOrder(gr1))[1];
429+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
427430
Transformation( [ 15, 11, 4, 7, 4, 9, 6, 17, 11, 31, 10, 7, 25, 9, 26, 22, 29,
428431
8, 21, 27, 25, 25, 30, 19, 18, 13, 16, 8, 5, 32, 31, 32 ] )
429432
gap> ForAll(DigraphEdges(gr1), e -> IsDigraphEdge(gr2, [e[1] ^ t, e[2] ^ t]));
430433
true
431434
gap> t := HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 23, 0,
432435
> [6 .. 37], [], fail, fail, DigraphWelshPowellOrder(gr1))[1];
436+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
433437
Transformation( [ 13, 20, 6, 30, 25, 24, 6, 23, 17, 30, 14, 9, 29, 11, 19, 28,
434438
13, 34, 32, 7, 9, 10, 18, 15, 12, 21, 7, 11, 37, 19, 31, 32, 33, 34, 35, 36,
435439
37 ] )

tst/standard/grahom.tst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 1, 1, [],
7979
Error, the 9th argument <partial_map> is too long, must be at most 2, found 4,
8080
gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 1, 1, [1], [1],
8181
> fail, fail);
82+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
8283
[ ]
8384
gap> HomomorphismDigraphsFinder(CompleteDigraph(2),
8485
> CompleteDigraph(3),
@@ -91,24 +92,30 @@ gap> HomomorphismDigraphsFinder(CompleteDigraph(2),
9192
> [1], # 1 -> 1
9293
> fail, # no colours
9394
> fail); # no colours
95+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
9496
[ IdentityTransformation ]
9597
gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 3, 0, [1, 2], [1],
9698
> fail, fail);
99+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
97100
[ ]
98101
gap> HomomorphismDigraphsFinder(gr2, gr1, fail, [], 1, 3, 0, [1, 2], [1],
99102
> fail, fail);
100103
[ ]
101104
gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 1, 0, [], [], fail,
102105
> fail);
106+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
103107
[ ]
104108
gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 1, 0, [1, 2], [],
105109
> fail, fail);
110+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
106111
[ ]
107112
gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 1, 0, [1, 2], [],
108113
> fail, fail);
114+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
109115
[ ]
110116
gap> HomomorphismDigraphsFinder(gr1, gr2, fail, [], 1, 2, 0, [1], [], fail,
111117
> fail);
118+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
112119
[ ]
113120
gap> HomomorphismDigraphsFinder(gr1, gr1, fail, [], 1, 2, 0, [1, 2], [],
114121
> fail, fail);
@@ -708,6 +715,7 @@ gap> gr := Digraph([[2, 3], [], [], [5], [], []]);
708715
<immutable digraph with 6 vertices, 3 edges>
709716
gap> HomomorphismDigraphsFinder(gr, gr, fail, [], infinity, fail, 0,
710717
> [1 .. 5], [], fail, fail);
718+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
711719
[ Transformation( [ 1, 2, 3, 4, 5, 1 ] ),
712720
Transformation( [ 1, 2, 3, 4, 5, 2 ] ),
713721
Transformation( [ 1, 2, 3, 4, 5, 3 ] ),
@@ -1129,6 +1137,7 @@ gap> gr := DigraphFromDigraph6String(Concatenation(
11291137
<immutable digraph with 22 vertices, 198 edges>
11301138
gap> t := HomomorphismDigraphsFinder(gr, gr, fail, [], 1, fail, 0,
11311139
> [2, 6, 7, 11, 12, 13, 14, 15, 19, 20, 21], [], fail, fail)[1];
1140+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
11321141
Transformation( [ 2, 13, 20, 19, 21, 19, 14, 13, 15, 14, 20, 6, 15, 21, 11,
11331142
12, 6, 7, 7, 12, 2, 11 ] )
11341143
gap> ForAll(DigraphEdges(gr), e -> IsDigraphEdge(gr, e[1] ^ t, e[2] ^ t));
@@ -1569,6 +1578,7 @@ gap> HomomorphismDigraphsFinder(D,
15691578
> [], # map
15701579
> [1, 2, 3], # colours1
15711580
> [1, 3, 2]); # colours2
1581+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
15721582
[ ]
15731583
gap> EmbeddingsDigraphsRepresentatives(NullDigraph(2),
15741584
> Digraph([[2, 3], [], []]));
@@ -1593,10 +1603,12 @@ gap> D := DigraphFromDigraph6String(Concatenation(
15931603
> "HBSatQlC[TIC{iSBlo_VrO@u[_Eyk?]YS?"));;
15941604
gap> HomomorphismDigraphsFinder(D, D, fail, [], 1, fail, 1,
15951605
> [2, 6, 7, 11, 12, 13, 14, 15, 19, 20, 21], [], fail, fail);
1606+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
15961607
[ ]
15971608
gap> D := Digraph([[2], []]);;
15981609
gap> HomomorphismDigraphsFinder(D, D, fail, [], 1, fail, 1,
15991610
> [1], [], fail, fail);
1611+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
16001612
[ ]
16011613

16021614
# Test monomorphisms for graphs
@@ -1804,6 +1816,7 @@ gap> HomomorphismDigraphsFinder(D,
18041816
> [, 3], # map
18051817
> fail, # colours1
18061818
> fail); # colours2
1819+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
18071820
[ ]
18081821
gap> D := DigraphAddAllLoops(Digraph([[2, 3], [1], [1], [], [5]]));;
18091822
gap> EmbeddingsDigraphsRepresentatives(NullDigraph(2), D);
@@ -2790,6 +2803,7 @@ on 1 of the group generators,
27902803
gap> HomomorphismDigraphsFinder(NullDigraph(3), NullDigraph(510), fail, [], 1,
27912804
> fail, true, [1, 2, 3], [1], fail, fail,
27922805
> Group((511, 512)));
2806+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
27932807
[ IdentityTransformation ]
27942808

27952809
# Issue 697
@@ -2815,6 +2829,7 @@ gap> HomomorphismDigraphsFinder(H,
28152829
> [], # partial_map
28162830
> fail, # colors1
28172831
> fail);
2832+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
28182833
[ ]
28192834

28202835
# With partial map, no hint
@@ -2829,6 +2844,7 @@ gap> HomomorphismDigraphsFinder(H,
28292844
> [8], # partial_map
28302845
> fail, # colors1
28312846
> fail);
2847+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
28322848
[ Transformation( [ 8, 1, 5, 7, 3, 4, 6, 8 ] ) ]
28332849

28342850
# With group, no hint
@@ -2859,6 +2875,7 @@ gap> HomomorphismDigraphsFinder(H,
28592875
> [8], # partial_map
28602876
> fail, # colors1
28612877
> fail);
2878+
#I WARNING you are trying to find homomorphisms by specifying a subset of the vertices of the target digraph. This might lead to unexpected results! If this happens, try passing Group(()) as the last argument. Please see the documentation of HomomorphismDigraphsFinder for details.
28622879
[ Transformation( [ 8, 1, 5, 7, 3, 4, 6, 8 ] ) ]
28632880

28642881
# With group, with hint

0 commit comments

Comments
 (0)