Homomorphism reconfiguration via homotopy

We consider the following problem for a fixed graph H: given a graph G and two H-colorings of G, i.e. homomorphisms from G to H, can one be transformed (reconfigured) into the other by changing one color at a time, maintaining an H-coloring throughout. This is the same as finding a path in the Hom(G,H) complex. For H=K_k this is the problem of finding paths between k-colorings, which was shown to be in P for k<=3 and PSPACE-complete otherwise by Cereceda et al. 2011. We generalize the positive side of this dichotomy by providing an algorithm that solves the problem in polynomial time for any H with no C_4 subgraph. This gives a large class of constraints for which finding solutions to the Constraint Satisfaction Problem is NP-complete, but finding paths in the solution space is P. The algorithm uses a characterization of possible reconfiguration sequences (paths in Hom(G,H)), whose main part is a purely topological condition described in algebraic terms of the fundamental groupoid of H seen as a topological space.


Introduction Reconfiguration
Reconfiguration is a framework in which we study how discrete structures, constrained in various ways, can be carefully transformed with small steps. This is often best described by finding paths in a solution graph, whose vertices are all solutions to a combinatorial problem and whose edges define the steps between solutions one is allowed to make.
For example, in k-Recoloring [BC09; CHJ11; Joh+14; BM14], one is given two proper k-colorings of a graph G and the question is whether one can be transformed into another by changing one color at a time, maintaining a proper coloring throughout. In other words, the solutions are proper k-colorings and a reconfiguration step is changing the color of one vertex. Another well studied example is Token Jumping [HD05; KMM12;BKW14], where the solutions are independent sets of some given size (seen as sets of tokens on the graph's vertices) and a reconfiguration step removes one vertex from the set to add another (jumps one token to a different vertex). Yet another example is the reconfiguration of generalized SAT problems [Gop+09;Sch13;Mou+14], where solutions are satisfying assignments of a given formula, and a reconfiguration step flips one variable of the assignment.

Homomorphisms
Our aim is to give more general statements about reconfiguration by defining a problem parameterized by the different constraints allowed. The natural tool for expressing systems being reconfigured seems to be Constraint Satisfaction Problems. This generalizes k-Coloring and generalized SAT problems, while (weighted, counting, . . . ) variants generalize Independent Set, for example. However, graph homomorphisms form an elegant subclass of problems, which is known to express many features of general CSPs. This is why we consider homomorphism reconfiguration. Indeed, this approach allowed us to argue in [Wro14b] that the only notion of sparseness that can apply to (unparameterized) reconfiguration problems in general is treedepth, and that many of them remain PSPACE-complete even in graphs of bounded bandwidth (thus pathwidth, treewidth, etc.). The reduction showed there explains why reconfiguration variants of easy combinatorial problems can be hard. In this paper we explore why reconfiguration variants of hard problems can be easy.
A homomorphism from a graph G to a graph H is a mapping σ : V (G) → V (H) such that edges are mapped to edges, i.e., uv ∈ E(G) implies σ(u)σ(v) ∈ E(H). We also use the name H-coloring, especially when H is fixed in the context. Vertices of H are then called colors. Note that a K k -coloring (so H is the graph with all edges except loops) is the same as a k-coloring.
Define the solution graph Hom 1 (G, H) to be the graph with H-colorings of G as vertices and edges between any two H-colorings that differ in the color of only one vertex (the name comes from it being the 1-skeleton of the Hom(G, H) complex, see below). For a fixed graph H, H-Recoloring is the problem asking whether two given H-colorings of a given graph G are connected by a path in Hom 1 (G, H). Shortest H-Recoloring asks whether there is such a path of at most some given length. Figure 1: A sequence of 3-colorings of C 5 and the same sequence seen as a K 3 -recoloring sequence of homomorphisms from C 5 to K 3 (a graph with three vertices: red, green, blue). One vertex of C 5 is thickened for clarity.

Motivations
The primary motivation for studying reconfiguration problems is to investigate the solution space of combinatorial problems, especially from the perspective of local search heuristics and random solution sampling. In particular, the success of Survey Propagation as a method for solving random Constraint Satisfaction Problems (CSPs) is connected to several conjectures about the structure of clusters of satisfying assignments (connected components in the solution graph) and frozen variables (variables/vertices that cannot change their value/color by any sequence of steps), see [ACORT11] (a reference the author would recommend to anyone interested in reconfiguration). While finding paths in the solution graph is, for the above purposes, mostly a toy problem, it arises more directly in some settings, such as puzzles with sliding blocks. Indeed, the Nondeterministic Constraint Logic construction of [HD05] allowed to show that many popular puzzles are PSPACE-complete [HD09], and more interestingly, so is the equivalence of proofs in a certain proof system [HH14], answering a question about normal forms of proofs that arose in this context.

Related work
H-Recoloring is known to be PSPACE-complete (as a decision problem) for H = K k where k ≥ 4 [BC09] and in P for k ≤ 3 [CHJ11]. The latter result has been improved to show that Shortest K 3 -Recoloring is also in P [Joh+14].
For CSPs in the boolean domain, a dichotomy was shown by [Gop+09] -for a fixed set of boolean constraints Γ (boolean relations, clause types), the problem of finding paths in the solution graph of a SAT(Γ) instance is either in P or PSPACE-complete. In particular it is always in P when the corresponding satisfiability problem is in P (e.g. 2-SAT or Horn-SAT), but it is also in P for some Γ for which satisfiability is NP-complete. This was slightly corrected and extended to several similar problems by Schwerdtfeger [Sch13], while a trichotomy was shown for the problem of finding shortest paths by [Mou+14]. Both [Gop+09] and [Sch13] asked whether their results could be extended to larger domains. Our work can be seen as a step in this direction, but limited to only one symmetric relation of arity 2.
The corresponding extension of Schaefer's dichotomy [Sch78] for satisfiability (deciding the existence of a solution) to CSPs with arbitrary finite domains is a long-standing open problem stated by Feder and Vardi [FV98]. They showed that the conjecture is equivalent when limited to one relation of arity 2 (digraph homomorphisms). Hell and Nešetřil proved the dichotomy when the relation is additionally assumed to be symmetic (graph homomorphism) [HN90]: the problem of deciding the existence of an H-coloring of a given graph is in P for H bipartite or containing a loop, and NP-complete otherwise.

Results
It is natural to ask whether the unexpected tractability of K 3 -Recoloring (in light of 3-Colorability being NP-complete, even in 4-regular planar graphs [Dai80]) is caused by the following property: whenever a vertex changes its color in a 3-coloring (e.g. from red to green), all of its neighbors must have one common color (blue).
We answer this in the positive considering the following definition: a graph H has the monochromatic neighborhood property if for every two colors a, b ∈ V (H), the set of common neighbors N H (a) ∩ N H (b) contains at most one color. For graphs without loops this is equivalent to not containing C 4 (the cycle on 4 vertices) as a subgraph (not necessarily induced). This includes K 3 and all graphs of girth ≥ 5, for example. For graphs with loops allowed, this is equivalent to not containing C 4 , K 3 with one loop added, nor K 2 with both loops added.
We show an algorithm that solves H-Recoloring in polynomial time for all H with the monochromatic neighborhood property. To achieve this, we characterize possible paths in Hom 1 (G, H) by describing sequences of colors which can occur when we observe one given vertex of G throughout an H-recoloring. It turns out they are mostly limited by the fact that reconfiguring an H-recoloring corresponds to a continuous transformation of a map from G to H as topological spaces.

In combinatorial algebraic topology
Reconfiguration of homomorphisms has already been studied independently in the field of combinatorial algebraic topology, though from a different angle. The notion of ×-homotopy of homomorphisms as defined by Dochtermann [Doc09] is identical to reachability in the solution graph. The solution graph of homomorphisms from G to H arises as the subgraph of the exponential graph H G induced by looped vertices and as the 1-skeleton of the Homcomplex Hom(G, H), see [BK06]. The Hom-complex, studied for its interesting categorical and topological properties, is a construction similar (and homotopy equivalent) to the clique complex of our solution graph. These definitions were introduced to provide lower bounds on the chromatic number of graphs, a notoriously hard problem. A typical theorem derived from such methods is that for loopless graphs G, H, if the solution graph of G → H homomorphisms is connected for all G of degree at most d, then the chromatic number of H is at least d/2 (and is conjectured to be at least d) [BW04]. Studies have thus been mostly concerned with highly regular graphs for which the solution graph can be proved to be in some sense tightly connected.
We do not know of any prior work on the computational complexity of deciding ×homotopy. More interestingly, we do not know of any prior example where ×-homotopy would be related to the continuous transformation of continuous mappings between graphs, more than through (functorial) analogy.

Preliminaries
An (undirected) graph G is a pair (V (G), E(G)) where V (G) is a finite set of vertices, while E(G) is the set of edges -undirected vertex pairs {u, v}, u, v ∈ V (G), written uv for short. A loop is an edge uu for some vertex u. The neighborhood N G (v) is defined as {w ∈ V (G) | vw ∈ E(G)}. Hence a ∈ N H (a) iff H has a loop at a.
G and H in this paper are always connected undirected graphs with at least one edge. G is always assumed to have no loops. H can have loops, but is always assumed to have the monochromatic neighborhood property.
An H-recoloring sequence or reconfiguration sequence is a path in Hom 1 (G, H), that is, a sequence of H-colorings of G in which consecutive colorings differ at one vertex. Consider a step of an H-recoloring sequence -a vertex v ∈ V (G) changes color from a ∈ V (H) to b ∈ V (H). Since G is connected, loopless and has an edge, v has a neighbor, say w = v. As only v changes its color in the step, w has the same color, say h ∈ V (H), before and after the step. The H-coloring before the step implies that ha ∈ E(H), while the one after the step implies that hb ∈ E(H). Thus h ∈ N H (a) ∩ N H (b). From the monochromatic neighborhood property we imply that N H (a) ∩ N H (b) = {h}. We will often call h 'the color that all neighbors of v have during the step' (that is, in the H-colorings before and after the step), without arguing its existence and uniqueness anymore.

Fundamental groupoid
An oriented edge of a graph H is an oriented pair e = (u, v) such that {u, v} is an edge of H; we denote its initial vertex u as ι(e) and its target vertex v as τ (e). We write e −1 for (τ (e), ι(e)). A walk from u to v in a graph H is a sequence of oriented edges e 1 , . . . , e l of H such that ι(e 1 ) = u, τ (e l ) = v and τ (e i ) = ι(e i+1 ) for i = 0, . . . , l − 1. We write ε for an empty walk (though some define a different empty walk for every vertex, the endpoints of ε will be irrelevant for us). The length of a walk is the number of edges in it. A walk W 1 from u to v can be concatenated to a walk W 2 from v to w to form a walk W 1 W 2 from u to w.
We call a walk reduced if it contains no two consecutive edges e i e i+1 such that e i+1 = e −1 i . One can reduce a walk by removing any such two consecutive edges from the sequence. It can easily be seen that by iteratively reducing a walk W , one always gets the same reduced walk, which we therefore denote as W . For any two reduced walks W 1 , W 2 such that W 2 starts where W 1 ends, we write W 1 · W 2 for W 1 W 2 and similarly one can observe that · is associative. For any walk W = e 1 e 2 . . . e l we write W −1 for the reversed walk This particular groupoid is called the fundamental groupoid π(H) of H. Note that if H has a loop at u, then (u, u) = (u, u) −1 is an oriented edge and a reduced walk of length 1. On the other hand, (u, u) · (u, u) = ε. (Hence π(H) is strictly speaking not a free groupoid and loops have no topological interpretation, see [KN07]).
A groupoid is in many ways similar to a group, except that the group operation · is a partial function, defined only when the 'head' of one element matches the 'tail' of the other.
More aptly, a groupoid could be defined as a group with many objects, that is, a category in which every morphism is invertible. Groupoids behave similarly to groups (much more so than semigroups) and identities such as (e · f ) −1 = f −1 · e −1 known from group theory are easily reproved in groupoids. Using the groupoid as opposed to the better known group allows us to describe calculations much more uniformly, without the tedious change of base points, for example.

Topological interpretation
Let us comment on how this algebraic structure captures the topology of curves in the graph. When referring to topology, continuous maps, curves and homotopy, we give informal interpretations without proof. Here we recall some classical results and definitions, which we do not require formally, but are helpful, if not crucial, in understanding our results.
A graph H without loops can be naturally associated with a topological space, constructed from copies of [0, 1] for each edge, with endpoints merged into vertices accordingly. A curve in this space is a continuous map f : [0, 1] → H (where H is meant as a topological space), not necessarily injective. Two curves f 0 , f 1 are homotopic if one can be continuously transformed into the other, which means there is a set of functions The fundamental groupoid fully describes curves up to homotopy. For any two vertices u, v of H, two curves f 0 , f 1 are homotopic via a homotopy φ t that fixes the endpoints (φ t (0) = u, φ t (1) = v for all t) if and only if the corresponding reduced walks in π(H) are identical. Considering only curves (or equivalently, walks) that start and end in the same vertex v, we obtain a group, which is known as the fundamental group π 1 (H, v) of the topological space H. When no vertex is fixed, a closed curve starting and ending in v 1 is homotopic to a closed curve starting and ending in v 2 (via a homotopy such that φ t (1) = φ t (0) for all t) if and only if the corresponding elements C 1 , C 2 of π(H) are conjugate, i.e. C 2 = P −1 · C 1 · P for some P ∈ π(H).

Vertex walks and realizability
As a vertex v ∈ V (G) changes colors from a to b in a step of an H-recoloring process, if h is the color that all neighbors of v have during the change, then (a, h)(h, b) is a walk in H (of length 2). Looking at all the color changes of one vertex this way gives a walk in H which traces the colors that v had. This walk (for one arbitrary vertex v), even after reducing, will be shown to almost completely describe the H-recoloring sequence. Formally, consider an H-recoloring sequence S = σ 0 , . . . , σ l of G and any vertex v ∈ V (G). We define S(v) as the following walk in H: • If l = 0, that is, S is empty, then S(v) = ε.
• If l = 1, that is, S contains only one reconfiguration step, then where h is the color that all neighbors of v have in σ 0 and σ 1 .
For two H-coloring α, β of G and a vertex q ∈ V (G), we call an element Q ∈ π(H) realizable if there is an H-recoloring sequence S = σ 0 , . . . , σ l such that σ 0 = α, σ l = β and S(q) = Q. We focus on the following question: which elements of π(H) are realizable? It is immediate from the definition that Q must be a reduced walk from α(q) to β(q) and have even length (notice that the parity of the length of walks is preserved by reducing, since we only remove pairs of edges ee −1 ). q α q β S(q) Figure 4: A realizable walk for α, β : K 2 → H and q. Note the shortest walk from α(q) to β(q) (of length 3) is not realizable because of parity.
If W is a walk in G and α is an H-coloring of G, then α(W ) is a walk in H (one way to see that is to see the walk as a homomorphism from a path: a composition of homomorphisms is a homomorphism).

Topological validity
With a homomorphism from G to H one can associate a continuous map from G to H (understood as continuous topological spaces described above). The following lemma is the key to the monochromatic neighborhood property of H. It states in algebraic terms the fact that when an H-coloring is reconfigured into another, the corresponding continuous mappings can be continuously transformed into one another, in a way such that the walk S(q) of any vertex q is the curve traced by the point q. Figure 5: If α can be transformed to β by reconfiguration, then it can by a homotopy φ : Since φ is a continuous mapping of a rectangle to H, it's boundary, and so the image of it's boundary, can be contracted to a point: We postpone the proof (which follows directly from the monochromatic neighborhood property and induction and is better explained by the 'picture proof' in Figure 5) until the end of the section, to focus on corollaries.
First, we see that in a given instance of H-Recoloring, the reduced vertex walk S(q) of one vertex q in a solution S determines all other vertex walks up to reductions (in other words, up to homotopy). Later we will see that in shortest solutions all vertex walks are already reduced, so S(q) actually determines the shortest solutions exactly, up to reordering color changes of different vertices. This is why we can focus on the realizability of one element Q ∈ π(H) instead of a whole recoloring sequence.
Second, note that the statement doesn't depend on how we choose walks in G. This means that for every closed walk C in G there is a topological condition on how solutions look like. Intuitively, two solutions can differ only in the number of times they wind around the circuit that C goes around. This is described in more detail in Lemma 15, for now let us only define this condition. The interpretation is that Q is topologically valid for α, β, q if there is a homotopy continuously transforming α to β such that q traces the curve Q throughout this transformation (φ 0 = α, φ 1 = β and the image of t → φ t (q) is Q).
Definition 2. Let α, β be two H-colorings of G and let q be a vertex of G. Let Q ∈ π(H). We say Q is topologically valid for α, β, q if any of the following equivalent statements holds.
1. For every closed walk C from q to q we have β(C) = Q −1 · α(C) · Q.
2. For every vertex w and any two walks W 1 , W 2 from q to w in G we have Proof (of equivalence). Suppose the second statement is true. Then the first one is true, because C and ε are two walks from q to q, implying Suppose the first statement is true. To check the second statement let W 1 , W 2 be two walks from q to w, for some w ∈ V (G). Then W 1 W −1 2 is a closed walk starting and ending in q, so β( Corollary 3. Let α, β be two H-colorings of G and let q be a vertex of G. If Q ∈ π(H) is realizable for α, β, q then Q is topologically valid for α, β, q.
It can be shown that this condition also characterizes exactly which curves are realizable as curves drawn by the vertex when continuously transforming α to β, so nothing more can be shown in a purely topological setting.
We note that the existence of a topologically valid walk for α, β implies in particular that cycles have the same homotopy class in α as in β, which algebraically is expressed in the fact that they have the same conjugacy class in the fundamental groupoid (that is, β(C) = Q −1 ·α(C)·Q for some Q). This generalizes one of the conditions of a characterization of 3-colorings connected by recoloring sequences given by [CHJ11] (Theorem 7 (C2)).
If W = ε then u = v and the claim follows trivially. If W has length one, that is W = (u, v), then one of the following holds: In either case σ l (W ) = S(u) −1 · σ 0 (W ) · S(v), which is equivalent to the claim.
If W is longer, the claim follows inductively by splitting it into shorter walks: W = W 1 W 2 for W 1 from u to some vertex w and W 2 from w to v. It then follows that σ l (W ) = It remains to consider the case where S has more than one step. Then the claim follows inductively by writing S as the concatenation of shorter sequences: S 1 which ends in σ i and S 2 which starts in σ i . It then follows that

Tight closed walks and frozen vertices
There is one more obstruction to reconfiguration: closed walks whose sequence of colors are in a sense tightly stretched around H. This generalizes the characterization of frozen vertices in the case of H = K 3 from [CHJ11]. In general though, frozen vertices can also arise in other situations, see Figure 6 for an example.
In an H-coloring α of G, a vertex v of G is called frozen if for every H-recoloring sequence from α the resulting H-coloring β has β(v) = α(v). A closed walk C = e 1 e 2 . . . e l is cyclically reduced if it is reduced and also e l = e −1 1 . In other words repeating C gives an infinite reduced walk. A closed walk C is α-tight if α(C) is cyclically reduced.
Lemma 4. Let α be an H-coloring of G and let C be an α-tight walk in G. Then all vertices of C are frozen in α.
Proof. Suppose to the contrary that there is an H-recoloring sequence σ 0 , . . . , σ l from α, such that σ l (C) = σ 0 (C). Let i be the least such that σ i (C) = σ 0 (C). Then in σ i−1 all vertices of C have the same color as in α = σ 0 and σ i is obtained from σ i−1 by changing the color of some vertex v ∈ C from a to b. Let h be the color that all neighbors of v have in σ i−1 and σ i . Let u, w be the vertices of C just before and just after v on C. Since they are neighbors of v, they must have the color h in σ i−1 and thus in α. The subsequent edges (u, v)(v, w) of C thus get mapped through α to (h, a)(a, h), contradicting that α(C) is cyclically reduced. Tight closed walks can be found by exploring walks W starting from some vertex such that α(W ) is reduced. If such walks can be arbitrarily long, or equivalently, contain the same oriented edge twice, then they use an α-tight closed walk. The (potentially infinite) prefix tree of such walks W gives a generalization of the layer construction of [CHJ11]. Algorithmically, we can ask what oriented edges are reachable from any starting oriented edge in time O(|E(G)|).
Finding a frozen vertex v allows us to limit potentially realizable walks Q to a single one.
Corollary 5. Let Q ∈ π(H) be realizable for α, β -H-colorings of G and q ∈ V (G). Let C be an α(C)-tight closed walk in H. Then for every vertex v on C and every walk W from v to q we have Q = α(W ) −1 · β(W ).

Characterization of realizable walks
In this section we prove that the obstructions described in the previous sections are enough to characterize all possible solutions to an H-Recoloring instance. This is very unexpected, as it shows we can view the graphs as purely topological structures and the only remaining conditions to remember are a simple parity condition and a condition on tight closed walks -the fact that edges are actually discrete and cannot be stretched arbitrarily, for example, turns out to imply no further obstructions to reconfiguration (it only restrict the H-colorings one can be given on the input).
Theorem 6. Let α, β be two H-colorings of G. Consider any vertex q of G and let Q ∈ π(H) be a reduced walk in H from α(q) to β(q). Then Q is realizable for α, β, q if and only if • Q is topologically valid for α, β, q, • Q has even length, • if there is an α-tight walk, then for any vertex v on this walk and any walk W from v to q, Q = α(W ) −1 · β(W ).
Furthermore, there is a polynomial time algorithm that given G, H, α, β and a walk Q satisfying these conditions, outputs a reconfiguration sequence such that S(q) Figure 7: Even though no vertex is frozen, α cannot be reconfigured to β. The red and green walks are not realizable for α, β, q because of parity. The blue walk has good parity, but is not topologically valid (imagine pulling q along it).
Proof. If an H-recoloring sequence is given, then the conditions are satisfied by Corollary 3 and Corollary 5, which proves the 'only if' half. Consider now a reduced walk Q ∈ π(H) that satisfies the above conditions. For every vertex v ∈ V (G) let S v = α(W ) −1 · Q · β(W ) for some walk W from q to v -by topological validity of Q, this doesn't depend on how W is chosen. In particular S q = Q. We will show an H-recoloring sequence S from α to β such that S(v) = S v for all v ∈ V (G). The idea is that S v define a correct H-recoloring sequence for each edge, but it remains to order changes of different vertices into one reconfiguration sequence. Each edge gives a condition on who should recolor first and it is enough to respect these conditions. This is impossible only if there is a cycle of conditions, which turns out to be exactly a α-tight cycle.
Note that since |Q| is even, |α(W )| = |W | = |β(W )| and reducing preserves parity, we have that each S v has even length.
Consider two adjacent vertices u, v ∈ V (G). Let W be any walk from q to u. Then W followed by (u, v) is a walk from q to v, so Let S u = (a 0 , a 1 )(a 1 , a 2 )(a 2 , a 3 ) . . . (a n−1 , a n ), Note that using concatenation (as opposed to ·) we write the exact sequence of edges of a walk. In particular S u is by definition reduced, so a i = a i+2 , similarly for S v . Now α(u) = a 0 , α(v) = b 0 and β(u) = a n , β(v) = b m , so and if we assume S u is non-empty, then by the parity condition n ≥ 2 and a 1 )(a 1 , a 2 ) . . . (a n−2 , a n−1 )(a n−1 , a n )(a n , b m ).
For two adjacent vertices u, v ∈ V (G) such that S u and S v are non-empty, let us write u → v in the first case and u ← v in the other as defined above. We have u → v iff v ← u, contradicting that S u , S v are reduced walks. We will write S j v for the j-th vertex of S v .
Furthermore, the → relation has no cycles. Suppose to the contrary that there is a cyclic sequence v 0 , v 1 , . . . , v l−1 , v 0 (l ≥ 3) such that v i → v i+1 for i ∈ Z l . Then this is an α-tight walk: indeed, arrows imply adjacency in G, Therefore by the last condition we have Q = α(W ) −1 · β(W ) and for any walk W from v i to q, But we didn't assign arrows between vertices whose sequences are empty, a contradiction.
Therefore there is an ordering v 1 , v 2 , . . . , v |V (G)| of V (G) such that if v i → v j then i < j. We claim the following reconfiguration sequence is a valid H-recoloring sequence from α to β. Recolor: . . . . . We continue this way, disregarding any undefined recolorings to S j v i for j > |S v i |. Because of the parity condition, this indeed ends in the coloring β.
To check that it is a valid H-recoloring sequence consider any edge {u, v} of G and define a i , b i as above. If both S u and S v are empty, then {u, v} gets constantly mapped to the same edge {α(u), α(v)} of H. If exactly one of S u , S v is empty, say S u , then S v = (b 0 , a 0 ) · S u · (a 0 , b m ) = (b 0 , a 0 )(a 0 , b m ) where b 0 = b m (and m = 2). Thus b 1 = a 0 , so {u, v} gets mapped initially to {α(u), α(v)} = {a 0 , b 0 } and then to {a 0 , b 2 } = {b 1 , b 2 }, which is an edge of H. If both S u and S v are non-empty, then assume without loss of generality u → v (otherwise swap u and v). We have S u = (a 0 , a 1 )(a 1 , a 2 )(a 2 , a 3 ) . . . (a n−2 , a n−1 )(a n−1 , a n ), a 3 ) . . . (a n−2 , a n−1 )(a n−1 , a n )(a n , b m ) Thus (u, v) gets mapped initially to (α(u), α(v)) = (a 0 , b 0 ) = (a 0 , a 1 ) and then to (a 1 , a 2 ), (a 3 , a 2 ), (a 3 , a 4 ), . . . , ending in either (a n , a n−1 ) or (a n , a n+1 ) depending on whether (a n−1 , a n )(a n , b m ) = ε. This is indeed always an edge of H, so since {u, v} was chosen arbitrarily, the coloring is always an H-coloring and the sequence is a valid H-recoloring sequence.
Corollary 7. Let α, β be two H-colorings of G. Let S = σ 0 , . . . , σ l be an H-recoloring sequence between σ 0 = α and σ l = β such that its length l is minimized. Then for every vertex v, S(v) is reduced.
Proof. Suppose S(q) is not reduced for some q. Let Q = S(q). But the above theorem we know from one side that Q is realizable. From the other side we obtain a solution S such that S (v) = S (v) for all v and S (q) = Q. By Lemma 1, this implies S (v) = S(v), for all v. But S(v) is always no longer that S(v), and S(q) is strictly shorter than S(q). Therefore, since the number of recoloring steps is equal to half the sum of lengths of all S(v), S was not shortest.

An algorithm
The following lemma follows from well-known calculations in the fundamental groupoid, which we recall in Appendix A. Intuitively, we consider for a cycle C of G what this cycle maps to, up to homotopy: in particular α(C) must be the same as β(C) up to homotopy (up to conjugation in π(H)). Furthermore, if this cycle is non-trivial (α(C) = ε), then two topologically valid walks may differ only in the number of times they wind around α(C) (or the least root R such that R n = α(C)). If two non-trivial such cycles wind around different roots, this implies there can be at most one topologically valid walk.
Lemma 8. Let α, β be H-colorings of G and q a vertex of G. Consider the set Π ⊆ π(H) of topologically valid walks for α, β, q. One of the following holds: 0. Π = ∅.
Furthermore, there is a algorithm that given α, β, q outputs in polynomial time which case holds and outputs Q or R, P in cases 1,2.
q α β R P R −1 · P Figure 8: There is essentially only one closed walk C from q to q in this example, which winds around the root R (α(C) = R 2 ). The topologically valid paths are exactly {R n · P | n ∈ Z} (think about deforming α by pulling q: one can pull it once or more around the top cycle by rotating all of α, but this is impossible for the bottom cycle if we are to reach β).
Theorem 9. Let α, β be H-colorings of G and q a vertex of G. Consider the set Π ⊆ π(H) of realizable walks for α, β, q. One of the following holds: 1. Π = {Q} for some Q ∈ π(H).
3. Π contains all reduced walks of even length from α(q) to β(q).
Furthermore, there is an algorithm that given α, β, q outputs in polynomial time which case holds and outputs Q or R, P in cases 1,2.
Proof. First find any α-tight closed walk and if there is one, let Q be the only possibly realizable walk as in the last condition of Theorem 6. By running the algorithm from Theorem 6 we can check whether it is realizable and return either Π = ∅ or Π = {Q}. Assume now that there is no α-tight walk. Run the algorithm of Lemma 8 to get a description of topologically valid walks Π and consider the following cases: 0. Π = ∅. Then also Π = ∅ (see Theorem 6).
2. Π = {R n · P | n ∈ Z} for some R, P ∈ π(H). The only remaining condition is parity, so one of the following holds: • R is even and P is odd -then Π = ∅, • R is even end P is even -then Π = Π, • R is odd and P is even -then Π = {R 2n · P | n ∈ Z}, • R is odd and P is odd -then Π = {R 2n · (R · P ) | n ∈ Z}.
3. Π contains all reduced walks from α(q) to β(q). Then Π contains all reduced walks of even length from α(q) to β(q).
The set of even walks from α(q) to β(q) in H is empty if and only if H is bipartite and α(q), β(q) are on different sides of a bipartition. This is easily checked in polynomial time, which conludes our main claim. Shortest recoloring sequences can also be found in polynomial time with some more care.
Corollary 10. Let H be a graph (possibly with loops) with the monochromatic neighborhood property. Then H-Coloring Reachability is in P.
Theorem 11. Let H be a graph (possibly with loops) with the monochromatic neighborhood property. Then Shortest H-Coloring Reachability is in P.
Proof sketch. By Corollary 7 all we have to do is minimize for Q ∈ Π from Theorem 9, where W v is a walk from q to v (arbitrarily chosen). In cases 0,1. this is trivial. In case 2. it is easy to show that |n| ≤ 2|V (G)| + |P | in shortest sequences, as repeating R will eventually lengthen all vertex walks. In case 3. consider a realizable walk Q. Let P 1 be the longest prefix P 1 of Q which will reduce with some α(W v ) −1 (that is, P 1 is also a prefix of α(W v ) for some v ∈ V (G)).
Let P 2 bet the longest suffix of Q which will reduce with some β(W v ). Either P 1 and P 2 overlap, or Q = P 1 Q P 2 for some Q ∈ π(H) such that Thus we can guess P 1 by enumerating all prefixes of all α(W v ), similarly guess P 2 and guess either an overlap or take Q to be an arbitrary shortest path of appropriate parity from the tail of P 1 to the head of P 2 in H.

Conclusions and future work
Our result generalizes the algorithm for K 3 -Recoloring of [CHJ11] and recovers many of its features in a more general and perhaps more intuitive setting. When limited to H = K 3 , we see that there is essentially only one possible root R for closed walks in H (a 3-cycle), and the reduced walks in K 3 (between the same endpoints) differ only by powers of R. This can be used to show that either no walk is topologically valid (that is, α, β are not homotopic), or all are. In the second case, it suffices to find tight cycles and either there is one, immediately implying the vertex walks in the only 3-recoloring sequence; or there is none, in which case any vertex walk for one vertex can be realized in a solution, as long as it has even length. In other words, if any walk is realizable, then either Q = ε is realizable for some (frozen) vertex, or the walk from α(q) to β(q) of length 0 or 2 is realizable for any vertex q. In particular, we don't need to find frozen vertices or do any of the calculations in Appendix A, it suffices to run the simple algorithm of Theorem 6 |V (G)| + 1 times.
We note that none of the proofs used any structural properties of H. If we consider H-recoloring for any graph H, but only allow recoloring a vertex if all of its neighbors have one common color (in other words, a reconfiguration step is allowed only when the homotopy class of the mapping doesn't change), the same results will follow.
An obvious question is how far can our results be extended to more general CSPs -to the asymmetric case, to multiple constraints, to hypergraphs (relations of arbitrary arity)? Is there any connection with the tractable cases of generalized SAT problems?
Another question is whether the problems of graph homomorphism reconfiguration exhibit a dichotomy. For which graphs H is H-Recoloring in P or PSPACE-complete? For the hard side, it is known that K 4 -Recoloring is PSPACE-complete even for G bipartite [BC09]. This is equivalent to saying that H-Recoloring is PSPACE-complete for H the cube graph K 4 × K 2 , which similarly implies that H-Recoloring is PSPACEcomplete for H the 4-cycle C 4 with all loops added, for example. An easy reduction (known as folding, see [FL12]) allows us to focus on so called stiff graphs. This is discussed in more detail in the author's master thesis [Wro14a].
Finally, it could be interesting to explore the implications of the monochromatic neighborhood property for the whole Hom complex.

A. Calculations in the fundamental groupoid
In this appendix we prove Lemma 8. Any algorithm will need to limit the number of closed walks considered. The standard way to do that is as follows: fix a vertex q ∈ V (G) and an arbitrary spanning tree T of G (a minimal connected subgraph that includes all vertices). For e ∈ E(G) \ E(T ) and an arbitrary orientation (ι(e), τ (e)) of e define the fundamental cycle C e as the cycle that goes from q to ι(e) along the unique shortest path that connects them in T , then to τ (e) through e, then back to q along the shortest path in T . There are |E(G)| − |E(T )| = |E(G)| − |V (G)| + 1 fundamental cycles and together they have the following property (see e.g. Lemma 1.2. of [KN07]).
Fact 12. Let C be any closed walk from q to q in G. Then C = C e 1 s 1 · . . . · C en sn for some s i ∈ {−1, +1} and e 1 , . . . , e n ∈ E(G) \ E(T ).
Fact 13. There is a polynomial time algorithm that given two H-colorings of a graph G and a vertex q can decide whether there is a Q ∈ π(H) that is topologically valid for α, β, q and if so, outputs such a Q.
Proof. Q is topologically valid if and only if for every closed walk C from q to q we have β(C) = Q −1 · α(C) · Q. By Fact 12, this is equivalent to satisfying the equation for each fundamental cycle C e . Finding a satisfying Q is the Simultaneous Conjugacy Search Problem, for which a linear time algorithm is described in Theorem 6.5. of [MU08].
To describe all valid walks we will need the following. For a non-zero closed reduced walk C ∈ π(H) (not necessarily cyclically reduced) we define the primitive root of C as the unique R ∈ π(H) such that C = R n for some n ∈ N such that n is maximized. It is a routine exercise to check this is well defined, can be computed in linear time, and that the following holds (see e.g. Lemma 2.1. of [MA80] and Lemma I.2.4. of [Mya04]): Fact 14. Let C 1 , C 2 ∈ π(H). Then C 1 and C 2 commute, i.e. C 1 · C 2 = C 2 · C 1 , if and only if C 1 = ε or C 2 = ε or both have the same primitive root or one of the roots is the inverse of the other.
Lemma 15. Let α, β be two H-colorings of G and let q be a vertex of G. Let P ∈ π(H) be topologically valid for α, β, q Then Q ∈ π(H) is topologically valid for α, β, q if and only if for every closed walk C in G starting and ending in q such that α(C) = ε, we have Q = R n · P for some n ∈ Z, where R ∈ π(H) is the primitive root of α(C).
For the other side, suppose that for every closed walk C from q to q with α(C) = ε and a primitive root R of α(C), there is an n ∈ Z such that Q = R n · P . Then for every closed walk C from q to q, α(C) commutes with Q · P −1 , because either α(C) = ε or α(C) = R k and Q · P −1 = R n for some R ∈ π(H) and n, k ∈ Z. Thus β(C) = = P −1 · α(C) · P = = Q −1 · Q · P −1 · α(C) · P = = Q −1 · α(C) · Q · P −1 · P = = Q −1 · α(C) · Q, which shows the topological validity of Q.
Furthermore, there is a algorithm that given α, β, q outputs in polynomial time which case holds and outputs Q or R, P in cases 1,2.
Proof. Use Fact 13 to compute a topologically valid walk P ∈ π(H) for α, β, q. If there is none, we immediately answer case 0. Fix an arbitrary spanning tree and compute the elements α(C e ) for all fundamental cycles of G. One of the following holds: 1. There are C e , C f such that α(C e ) and α(C f ) do not commute. Then we show Π = {P }.
Clearly α(C i ) = ε, so let R i be the primitive root of α(C i ) for i = 1, 2. Suppose Q ∈ π(H) is topologically valid. Then by Lemma 15, Q = R n 1 1 · P and Q = R n 2 2 · P for some n 1 , n 2 ∈ Z. Thus R n 1 1 = R n 2 2 . If this element has a primitive root (n 1 , n 2 = 0), then it is equal to both R 1 and R 2 , implying that α(C 1 ) and α(C 2 ) have the same primitive root, contradicting Fact 14. Therefore n 1 = n 2 = 0 and Q = P .
2. There is a C e such that α(C e ) = ε and for every C f , α(C f ) commutes with α(C e ).
Then by Fact 12, for every closed walk C starting and ending in q, α(C) commutes with α(C e ). Let R be the primitive root of α(C e ). R (or its inverse) is also the primitive root of every non-empty α(C), so by Lemma 15, Q is topologically valid iff Q = R n · P for some n ∈ Z.