COMPRESSED DECISION PROBLEMS IN HYPERBOLIC GROUPS

. We prove that, for any hyperbolic group, the compressed word and the compressed conjugacy problems are solvable in polynomial time. We also prove that the compressed simultaneous conjugacy and the compressed centraliser problems are solvable in polynomial time. Finally, we prove that, for any inﬁnite hyperbolic group, the compressed knapsack problem is NP –complete.

1. Introduction 1.1. Background. Suppose that G is a finitely generated group. Let Σ be a finite generating set which is symmetric: if a lies in Σ then so does a −1 . The word problem for G asks, given a word w ∈ Σ * , if w represents the identity in G. This, along with the conjugacy and isomorphism problems, was set out by Dehn [16] in 1911. These three decision problems are fundamental in group theory generally [54,11].
However, Dehn's claimed justification was that solutions to these problems have applications in what is now called low-dimensional topology. Dehn's techniques, in particular his solution to the word problem in surface groups, were greatly generalised by Gromov. In [29] Gromov introduced what are now called word-hyperbolic or Gromov hyperbolic groups. (We will simply call these hyperbolic groups. See Section 3.) With this and other innovations Gromov revived the strictly geometric study of groups. For example, he characterised hyperbolic groups as being exactly those that satisfy a linear isoperimetric inequality; see [29,Section 6.8.M] as well as [60,9,62]. Gromov also showed that, in certain models of random groups, all groups are almost surely hyperbolic; see [29,Section 5.5.F] as well as [61].
Another theme in geometric group theory is the subject of distortion. As a concrete example, consider the Baumslag-Solitar group [6] The subgroup a is exponentially distorted in G, in the sense that the element a 2 n = G b −n ab n has length 2 n as an element of a but length 2n + 1 as an element of G. Thus, to solve the word problem efficiently in G it seems necessary to record exponents of a, say in binary; see also [70].
The second author has been supported by the DFG research project LO 748/13-1.
So, seeking to solve the word problem in groups leads us to consider compressed words: elements of the group given by some useful succinct representation. One popular such representation is by straight-line programs; we give definitions and examples of these in Section 4.1. We will call the word problem for group elements that are represented by straight-line programs the compressed word problem.
The motivating result for this paper is a theorem due to the second author [47,Theorem 4.5]. Let F n be the free group on n generators. Lohrey gives a polynomial-time algorithm to solve the compressed word problem for F n ; in fact this problem is P-complete. Building on this, the third author shows in [66, Theorems 5.2 and 6.1] that the word problems for Aut(F n ) and Out(F n ) can be solved in polynomial time and then goes on to show that the compressed word problem for closed surface groups can be solved in polynomial time. This also gives a new solution to the word problem in mapping class groups of surfaces.
This sequence of results closely parallels Dehn's original development, but in the compressed setting.
1.2. This paper. Suppose that w is a word in the generators of G. We say w is shortlex reduced if it is shorter than, or of the same length and lexicographically earlier than, any other word representing the same group element; see Definition 2.2. Suppose that G is a straight-line program over Σ. Then we denote the output of G by eval(G). Here is our main result.
Theorem 5.7. Let G be a hyperbolic group, with symmetric generating set Σ. There is a polynomial-time algorithm that, given a straight-line program G over Σ, finds a straight-line program H so that eval(H) is the shortlex reduction of eval(G).
This was previously announced without proof in [49,Theorem 4.12]. From this theorem we deduce the following.
Corollary 5.8. Let G be a hyperbolic group. Then the compressed word problem for G can be solved in polynomial time.
In the recent paper [38] the first author, with Sarah Rees, has generalised the techniques of this paper to relatively hyperbolic groups where all peripheral groups are free abelian. So, for a knot K ⊂ S 3 , the compressed word problem for the knot complement is polynomial time. This gives a further parallel with Dehn's programme for low-dimensional topology via the study of the fundamental group.
1.3. Applications. Given these results, in Section 6.2 we deal with the compressed versions of several other algorithmic problems. Recall that the order problem for a group G asks us, given an element g ∈ G, to compute the order of g. Since hyperbolic groups only have torsion elements of bounded order we can prove the following. Corollary 6.1. Let G be a hyperbolic group. Then the compressed order problem for G can be solved in polynomial time.
The first author, with Epstein, proved in [23] that the conjugacy problem in hyperbolic groups is linear time. If, in the conjugacy problem, we replace the given pair of elements by a pair of finite ordered lists of elements then we obtain the simultaneous conjugacy problem. See [44] and its references for a discussion of this problem, for various classes of groups.
The centraliser problem asks for the centraliser of a given finitely generated subgroup of G. Holt and Buckley proved in [10] that the simultaneous conjugacy problem as well as the centraliser problem for hyperbolic groups is linear time.
Using the results of [23,10], and our work above, we solve the compressed versions of these problems. Theorem 6.3. Let G be a hyperbolic group. Then the compressed simultaneous conjugacy problem for G can be solved in polynomial time. Moreover, if the two input lists are conjugate, then we can compute a straight-line program for a conjugating element in polynomial time.
Theorem 6.4. Let G be a hyperbolic group. Then the compressed centraliser problem for G can be solved in polynomial time.
We remark that, for finitely generated nilpotent groups, the (compressed) simultaneous conjugacy problem is solvable in polynomial time [53,Theorem 7].
As suggested in [66,Remark A.5], the word problem for a finitely generated subgroup of the automorphism group Aut(G) is polynomial-time reducible to the compressed word problem for G. Similarly, the word problem for a finitely generated subgroup of the outer automorphism group Out(G) is polynomial-time reducible to the compressed simultaneous conjugacy problem for G; see [33,Proposition 10].
Note that, if G is hyperbolic then Aut(G), and thus Out(G), is finitely generated; see [15,Corollary 8.4]. We deduce the following. Corollary 1.1. Let G be a hyperbolic group. Then the word problems for Aut(G) and Out(G) can be solved in polynomial time.
Our final application is to knapsack problems. Suppose that G is a finitely generated group. The given input is a list (u 0 , u 1 , u 2 , . . . , u k ) of words over the generators of G. We are asked if there are natural numbers n i such that u 0 = G u n 1 1 u n 2 2 · · · u n k k When G is hyperbolic, the knapsack problem can be solved in polynomial time; see [57,Theorem 6.1].
In the compressed knapsack problem, the words u i are represented by straight-line programs. For the special case G = Z this problem is a variant of the classical knapsack problem for binary encoded integers, which is NPcomplete [42, page 95]. Using this, and our results above, we prove the following.
Theorem 6.5. Let G be an infinite hyperbolic group. Then the compressed knapsack problem for G is NP-complete.
1.4. Related work. We here give a brief overview of previous work. For a more in-depth treatment, we refer to [48,49].
Compressed word problems. The use of straight-line programs in group theory dates back to, at least, the methods developed by Sims [67] for computing with a subgroup of the symmetric group S n defined by generators. The first step in virtually all of the algorithms developed by Sims is to expand the given list of generators to a longer list (a strong generating set) by defining a sequence of new generators as words in the existing generators. Straight-line programs were later used, again in the context of finite groups, by Babai and Szemeredi [3] in the proof of their Reachability Theorem.
Note that the compressed word problem for a group G is decidable if and only if the word problem for G is decidable. However, the computational complexity of the compressed word problem for G can be strictly more difficult than the word problem itself. We return to this topic below.
It is interesting to note that the compressed word problem for a group G is exactly the circuit evaluation problem for G. For finite groups the compressed word problem, and thus the circuit evaluation problem, is nearly linear time. In fact, more is known. The parallel complexity of the circuit evaluation problem over finite groups is investigated in [7]. If G is a finite solvable group, then the compressed word problem for G belongs to the parallel complexity class DET ⊆ NC 2 . If G is finite and not solvable, then the compressed word problem for G is P-complete.
We now turn our attention to infinite, but finitely generated, groups. As mentioned above, the word problem for a finitely generated subgroup of Aut(G) is polynomial-time reducible to the compressed word problem for G. A similar reduction exists for certain group extensions [49,Theorem 4.8 and 4.9]. These results on automorphisms are tightly connected to the study of distortion of subgroups, mentioned above.
Beyond hyperbolic groups, there are several important classes of groups where the compressed word problem can be solved in polynomial time. These include the following.
• Finitely generated nilpotent groups [49,Section 4.7]. Here, the compressed word problem belongs to the parallel complexity class DET [45]. • Virtually special groups; that is, finite extensions of finitely generated subgroups of right-angled Artin groups [49,Corollary 5.6].
Right-angled Artin groups are also known as graph groups or partially commutative groups. The class of virtually special groups contains all Coxeter groups [32], one-relator groups with torsion [71], fully residually free groups [71], and fundamental groups of hyperbolic three-manifolds [1]. Note that the case of fully residually free groups is independently due to Macdonald [52].
Furthermore, the class of groups with polynomial time compressed word problem is closed under the following operations.
We also note that, for finitely generated linear groups, the compressed word problem belongs to the complexity class coRP [49,Theorem 4.15]. That is, there is a randomised polynomial-time algorithm that may err with a small probability on negative input instances. On the other hand: the uncompressed word problem for the Grigorchuk group can be solved in logarithmic space [26]. Also, if G is finite then the uncompressed word problem for G ≀ Z belongs to the circuit complexity class NC 1 [68]. Thus we have examples of groups where the compressed word problem is provably more difficult than the uncompressed word problem.
• There exist automaton groups with an EXPSPACE-complete compressed word problem [69]. On the other hand, the uncompressed word problem for any automaton group belongs to PSPACE. Again this gives examples where the compressed word problem is provably more difficult than the uncompressed. • The compressed word problem for the linear group SL(3, Z) is equivalent, up to polynomial-time reductions, to the problem of polynomial identity testing. This last is the decision problem of whether a given circuit over the polynomial ring Z[x 1 , . . . , x n ] evaluates to the zero polynomial [49,Theorem 4.16]. The existence of a polynomial-time algorithm for polynomial identity testing is an outstanding open problem in the area of algebraic complexity theory.
On the other hand, the uncompressed word problem for SL(3, Z) is polynomial time.
1.4.3. Knapsack problems over groups. The uncompressed knapsack problem has been studied for various classes of groups; see [24,25,46]. For non-elementary hyperbolic groups, the knapsack problem lies in LogCFL (the logspace closure of the class of context-free languages); see [50,Theorem 4.1]. The second author further shows, in [51,Theorem 3.1], that the compressed knapsack problem for every virtually special group belongs to NP.

Compressing integers.
In addition to straight-line programs, there are other methods of compression that arise in significant ways in computational group theory. Here we will mention just a few with particular relevance to the word problem. These are techniques for recording extremely large integers, as opposed to recording long words.
The binary representation of an integer n can be translated into a straightline program G n of size O(log n) with output a n . Following our discussion of circuit evaluation above, we could replace "concatenation of strings" by the primitive operator "addition of integers". Likewise, we replace the alphabet {a} by the alphabet {1}. This transforms the straight-line program G n into an additive circuit with output n.
If we allow multiplication as well as addition gates we obtain arithmetic circuits. For example, a circuit with n gates can produce an integer of size 2 2 n using iterated squaring. Power circuits, the topic of [59], replace multiplication of x and y by the operation x · 2 y : that is, shifting the first input by the second. Thus a power circuit of depth n can represent an integer of the size of a tower of exponentials of height n. The same authors use their new theory, in [58], to show that the word problem in Baumslag's group [5] is polynomial time. We note that Baumslag's group has a non-elementary Dehn function [64]; this demonstrates one of the many possible separations between the computational and the geometric theories of a group. Again exploiting various properties of power circuits, the authors of [18] give a cubic time algorithm for the word problem in Baumslag's group [18,Theorem 16]. They also show that the word problem for Higman's group [34] is polynomial time [18,Theorem 19].
Of course, even more extreme compression is possible and this leads to polynomial-time algorithms for even more extreme groups. The authors of [19,20] construct certain HNN-extensions of the hydra groups [21] where [x, y] = x −1 y −1 xy is a commutator and [··· [[a, b], b], . . . , b] is a nested commutator of depth k, for which the Dehn function grows roughly like the Ackermann function and the word problem is still solvable in polynomial time. For this, they use a compression scheme for integers that yields a compression ratio of order of the Ackermann function on some integers.

1.5.
Acknowledgements. An extended abstract of this paper appeared in [37]. The third author thanks the first two for their patience during the writing of this paper.

2.1.
Words. Suppose that Σ is an alphabet; the elements of Σ are called letters. We write Σ * for the Kleene closure of Σ; that is, the set of all finite words over Σ. We call any subset L ⊆ Σ * a language over Σ.
For any alphabet Σ, we use ε ∈ Σ * to denote the empty word. Suppose that u, v, and w are words over Σ. We denote the concatenation of u and v by u · v; we often simplify this to just uv (u · v is sometimes preferred for better readability). So, for example, w · ε = ε · w = w. We say that u is a factor of v if there are words x and y so that v = xuy. We say that u is a rotation of v if there are words x and y so that v = xy and u = yx. We have the following easy but useful result. Suppose that w = a 0 · a 1 · · · a n−1 lies in Σ * , where the a i are letters. Then we define |w| to be the length of w; that is, |w| = n. For any i between zero and n − 1 (inclusive) we define w[i] = a i . Note that the empty word ε is the unique word of length zero.
We now define the cut operators. Let w be a word, as above, and let i and j be indices with 0 ≤ i ≤ j ≤ n = |w|. We define w[i : j] = a i · · · a j−1 . We use w[: j] to denote w[0 : j], the prefix of length j. We use w[i :] to denote w Suppose that Σ is a finite alphabet equipped with a total order < (the concrete choice of < will never be important for us).
Definition 2.2. We define the shortlex order on Σ * as follows. For words u, v we have u < slex v if • |u| < |v| or • |u| = |v| and there are words x, y, z ∈ Σ * and letters a, b ∈ Σ so that u = xay, -v = xbz, and a < b.
Note that shortlex is a well-order on Σ * : that is, every nonempty subset of Σ * has a unique shortlex least element.

2.2.
Finite state automata. We refer to [40] for background in automata theory. A (deterministic) finite state automaton is a tuple M = (Q, Σ, q 0 , δ, F ), where • Q is a finite set of states, • Σ is a finite alphabet, Intuitively, if the automaton M is "in" state q ∈ Q, and receives input a ∈ Σ, then it transitions to the new state δ(q, a). We extend δ to a function δ ′ : Q × Σ * → Q recursively. That is, for any state q, word w, and letter a we have Since δ and δ ′ agree on words of length at most one, we will suppress δ ′ in what follows and instead reuse δ. We define to be the language accepted by M . Intuitively, if w lies in L(M ) then w, when input into M , takes it from the initial state to an accept state.
We say that a language L ⊆ Σ * is regular if there exists a finite state automaton M so that L = L(M ).

Hyperbolic groups
We refer to [2] as a general reference on (word) hyperbolic groups. Let G be a finitely generated group. Let 1 G denote the identity element of G. Let Σ be a finite, symmetric generating set for G. That is, if a lies in Σ then so does a −1 . For two words u, v ∈ Σ * , we will use u = G v to mean that u and v represent the same element of G. We fix a total order < on Σ.
The (right) Cayley graph Γ = Γ(G, Σ) of G with respect to Σ is defined as follows.
• The vertices of Γ are the elements of G.
• The undirected edges of Γ are of the form {g, ga} for g ∈ G and a ∈ Σ.
We will label a directed edge (g, ga) with the letter a. Note that G acts, by graph automorphisms, on Γ on the left. Giving all edges length one makes Γ into a geodesic metric space. We do this in such a way so that the action of G is by isometries. The distance between two points p, q is denoted d Γ (p, q). For g ∈ G we define |g| = d Γ (1, g). We deduce that |g| is the smallest length among all words w ∈ Σ * that represent g. Fix r ≥ 0. The ball of radius r in Γ is the set Fix a word w ∈ Σ * . We define P w ⊆ Γ to be the path starting at 1 G which is labelled by w. Thus the path g · P w starts at g and is again labelled by w. In general, we will take P : [0, n] → Γ to be an edge path from P (0) to P (n). In particular, we must allow real t ∈ [0, n] as we traverse edges. We useP to denote P with its parametrisation reversed. Note thatP w = g w · P w −1 .
We call a path P geodesic if for all real t ≥ 0 we have d Γ (P (0), P (t)) = t. Suppose that the word w ∈ Σ * represents the group element g w ∈ G. We say that w ∈ Σ * is geodesic if the path P w is geodesic. We say that w ∈ Σ * is shortlex reduced if for all u ∈ Σ * the equality g u = g w implies w ≤ slex u. We use slex(w) to denote the shortlex reduced representative of g w .
Remark. Suppose that w is geodesic or shortlex reduced. Suppose that u is a factor of w. Then u is also, respectively, geodesic or shortlex reduced.
A geodesic triangle in Γ consists of three vertices p, q, r ∈ G and three sides P, Q, R ⊂ Γ. The sides are geodesic paths connecting the vertices; see Figure 3.1. Fix δ ≥ 0. We now follow [2,Definition 1.3]. We say that a geodesic triangle is δ-slim, if every point x in the side P is distance at most δ from some point of R ∪ Q, and similarly for the sides Q and R.
Fix G and Σ as above. We say G is δ-hyperbolic if every geodesic triangle in the Cayley graph Γ = Γ(G, Σ) is δ-slim. Finally, we simply say G is hyperbolic, if it is δ-hyperbolic for some δ ≥ 0. For example, the group G is 0-hyperbolic (with respect to Σ) if and only if G is a free group, freely generated by (half of) Σ.
Remark 3.1. In his article [29], Gromov proves that hyperbolic groups have many good properties. In Corollary 2.3.B he states that such groups satisfy a linear isoperimetric inequality; hence they have solvable word problem. In Corollary 2.3.E he shows that the notion of hyperbolicity is independent of the choice of finite generating set. In Section 7.4.B he proves that they have solvable conjugacy problem. For another exposition of these results (excepting the conjugacy problem) we refer to [2]: see Theorem 2.5, Proposition 2.10, and Theorem 2.18 of that work. For an exposition of the conjugacy problem we refer to [23].
We will need a seemingly stronger condition on our geodesic triangles, called δ-thinness. We here follow [2, Definition 1.5]. Suppose again that we have a geodesic triangle with vertices p, q, r ∈ G and with sides P, Q, R ⊂ Γ; see Figure 3.1. Let c P ∈ P , c Q ∈ Q, and c R ∈ R be the unique points so that We call these the meeting points of the triangle. Note that the meeting points may be elements of G or midpoints of edges of Γ. Suppose that x ∈ P and y ∈ Q are points with A geodesic triangle in a hyperbolic metric space. Note how the three sides "bow in" to a common centre. Dotted lines represent paths of length at most δ between corresponding points.
Then we call x and y corresponding points with respect to r. Note that if one of x or y lies in G then so does the other. We make the same definition with respect to the vertices p and q. Note that the three meeting points are all in correspondence. Fix δ ≥ 0. The triangle is called δ-thin if for all corresponding pairs (x, y) we have d Γ (x, y) ≤ δ. See Figure 3.1; there the dotted arcs indicate corresponding pairs. Note that a δ-thin triangle is δ-slim. A converse also holds: every geodesic triangle in a δ-hyperbolic space is 4δ-thin; see [2, Proposition 2.1]. We now fix a group G and a symmetric generating set Σ; we assume that G is δ-hyperbolic. We choose δ large enough to ensure that all geodesic triangles in Γ are δ-thin.
Remark. From a computational viewpoint, hyperbolic groups have many nice properties. For example, their word problems can be solved in linear time [2, Theorem 2.18] as can their conjugacy problems [23]. (Here we gloss over the details of the required model of computation.) In a more recent and noteworthy achievement, their isomorphism problem has also been solved; see [14,15]. Thus all three of Dehn's fundamental problems have been settled positively for hyperbolic groups.
Other positive results include the simultaneous conjugacy problem [10] and the knapsack problem [50]. We will return to both of these below.
Note that the compressed word problem easily reduces to the problem of checking the solvability of a system of equations. There is a substantial body of work on the latter, over hyperbolic groups. Dahmani and Guirardel [14] prove (building on earlier work of [65]) that the problem is decidable. The compressibility by straight-line programs of solutions of equations in hyperbolic groups is studied in [17]. Ciobanu and Elder [13] give a complete description of the set of all solutions of a given system of equations over a hyperbolic group. They obtain, as a corollary, a polynomial-space algorithm for deciding the existential theory of a hyperbolic group.
The following results come from the fact that hyperbolic groups have automatic structures with respect to any shortlex ordering [ There is a polynomial-time (in fact, quadratic) algorithm that, given a word w ∈ Σ * , produces slex(w). Remark. We will in fact need both geodesic and shortlex reduced words in our proof of Theorem 5.7. This is because the inverse of a geodesic word is again geodesic; this need not be the case for shortlex reduced words. On the other hand, shortlex reduced words provide unique representatives of group elements; this is almost never the case for geodesic words.
We will need the following standard lemma on geodesic quadrilaterals. See, for example, the proof of [2, Proposition 3.5].
Lemma 3.4. Let a, b, u, v ∈ Σ * be geodesic words such that vb = G au. Suppose that u has a factorisation u = u ′ u ′′ with |u ′ | ≥ |a| + 2δ and |u ′′ | ≥ |b| + 2δ. Then there exists a factorisation v = v ′ v ′′ and a geodesic word c so that Proof. We consider the quadrilateral with sides P v , P a , g a · P u , and Here g w is the group element represented by the word w. We are given a factorisation u = u ′ u ′′ . Set g = g a g u ′ and note that g lies in g a · P u . See Figure 3.2. Since geodesic quadrilaterals are 2δ-slim there is a group element h with d Γ (g, h) ≤ 2δ lying in the union of the three other sides. We now consider cases. Suppose that h lies in P a − {1 G }. Then the triangle inequality implies |u then |u ′′ | < |b| + 2δ. Both of these are contrary to hypothesis. We deduce that h lies in P v , proving the lemma.
The lemma has a useful corollary.
Proof. We prove this with two applications of Lemma 3.4. The first application gives us c. In the second application we restrict our attention to the quadrilateral with sides labelled c, b, u ′′ · u ′′′ , and the fourth side labelled by the resulting suffix of v. This gives d.
Suppose that S is a path in Γ of length n, and i is an integer. We adopt the convention that the use of the expression S(i) implies that i lies in [0, n]. Recall thatS denotes S with its parametrisation reversed.
Lemma 3.6. Let T be a δ-thin geodesic triangle with vertices at p, q, and r and with sides P , Q, and R. Suppose that In the statement and the proof we follow the notation of Figure 3.1.
Proof of Lemma 3.6. Since d Γ (R(j),Q(j)) > δ, the group elements R(j) and Q(j) do not correspond to each other. Thus R(j) is strictly after the meeting point c R along R. SimilarlyQ(j) is strictly after the meeting point c Q alonḡ Q. Since T is δ-thin, there are integers i R and i Q so that • R(j) corresponds to P (i R ) and so d Γ (R(j), P (i R )) ≤ δ and •Q(j) corresponds to P (i Q ) and so d Γ (Q(j), P (i Q )) ≤ δ. We deduce that P (i R ) is strictly before, and P (i Q ) is strictly after, c P along P . Thus i R < i Q and we are done. 4. Compressed words and the compressed word problem 4.1. Straight-line programs. Straight-line programs offer succinct representations of long words that contain many repeated substrings. We here review the basics, referring to [49] for a more in-depth introduction.
is an acyclic production mapping: that is, the relation is acyclic. We call ρ(A) the right-hand side of A.
Definition 4.3. Given a straight-line program G as above, we define an One proves by a delicate induction that eval is well defined. We finally take eval(G) = eval(S). We call eval(G) the output of the program G.
In other words, G is a context-free grammar that generates exactly one word eval(G) of Σ * .
So, continuing Example 4.2 above we have eval(A 0 ) = ab and more gen- We say a straight-line program G = (V, S, ρ) over Σ is trivial if S is the only variable and ρ(S) = ε = eval(G).
We say that a straight-line program is in Chomsky normal form if it is either a trivial program or all right-hand sides are of the form a ∈ Σ or BC with B, C ∈ V . There is a linear-time algorithm that transforms a given straight-line program G into a program G ′ in Chomsky normal form with the same output; see [49,Proposition 3.8].
Definition 4.4. We define the size |G| of G = (V, S, ρ) to be the sum of the bit-lengths of the right-hand sides of ρ. Symbols from V ∪ Σ are encoded by bit strings of length O(log(|V | + |Σ|)) using a prefix code.
Again considering Example 4.2, we see that the size of G n is O(n log(n)). (Note that we take into account the cost of writing out the indices of the variables A i .) Thus we see that straight-line programs can achieve (essentially) exponential compression. The following result proves that straight-line programs can do no better; the proof follows the proof of [12, Lemma 1]. 1 As a convenient short-hand, we will refer to straight-line programs over Σ as compressed words.

4.2.
Algorithms for compressed words. We will assume that all integers given as input to algorithms are given in binary. We will need to know that the following algorithmic tasks can be solved in polynomial time; see [49,Proposition 3.9].
Given a straight-line program G and natural numbers i ≤ j: 1 In [12], |G| is defined as the sum of all lengths of right-hand sides of G. Note that this value is less than or equal to our value of |G| (the bit-lengths of the right-hand sides).
• find the length |eval(G)|; The following proposition is also well-known [12, Lemma 2]. Proposition 4.6. There is a polynomial-time algorithm that, given a straightline program G and a natural number n > 0, computes a straight-line program G n with eval(G n ) = eval(G) n . In fact, the time required is linear in |G| + log n.
The following results are less trivial. A proof of this proposition can be found in [49,Theorem 3.11]. We also need the following variant of Proposition 4.7. Proof. Let M = (Q, Σ, q 0 , δ, F ) be the automaton. Suppose that w = eval(G). All non-negative powers of w belong to L(M ) if and only if δ(q 0 , w n ) lies in F , for all n ≥ 0.
It follows that w n ∈ L(M ) for all n ≥ 0 if and only if w n ∈ L(M ) for all 0 ≤ n ≤ |Q|. By Proposition 4.6, we can compute, in polynomial time and for all 0 ≤ n ≤ |Q|, a straight-line program G n with output eval(G n ) = w n . Finally we use Proposition 4.7 to test, in polynomial time, if eval(G n ) ∈ L(M ) for these programs.
The following result is central to our past and present work. It was independently discovered by Hirshfeld, Jerrum, and Moller [35,Proposition 12] (see also [36,Proposition 3.2]), by Mehlhorn, Sundar, and Uhrig [55,56] (where the result is implicitly stated in terms of dynamic string data structures), and by Plandowski [63,Theorem 13]. We now give a version of [43,Theorem 1]; this generalises Theorem 4.9 to the so-called fully compressed pattern matching problem. See [41, Theorem 1.1] for a quadratic time algorithm, which is the best currently known.  and The compressed word problem. Suppose that G is a group and Σ is a finite symmetric generating set. The compressed word problem for G, over Σ, is the following decision problem. Input: A straight-line program G over Σ. Question: Does eval(G) represent the identity of G? Note that the compressed word problem for a group G is decidable if and only if the word problem for G is decidable. As discussed in the introduction, there are in fact groups G where the compressed word problem is strictly harder than the word problem itself.
Observe that the computational complexity of the compressed word problem for G does not depend on the chosen generating set Σ. That is, if Σ ′ is another such, then the compressed word problem for G over Σ is logspace reducible to the compressed word problem for G over Σ ′ [49,Lemma 4.2]. Thus, when proving that the compressed word problem is polynomial time, we are allowed to use whatever generating set is most convenient for our purposes. . These are also called cut straight-line programs in [49]. We shall simply call them cut programs. They are used, for example, in the polynomial-time algorithm for the compressed word problem of a free group [47].
A cut program over Σ is a tuple G = (V, S, ρ), with V and S as in Sec- with the cut operator [i : j] as defined in Section 2. The size of a cut program G is the sum of the bit-lengths of the right-hand sides; as usual all natural numbers are written in binary.
We can now state a straightforward but important result of Hagenah; see [31,Algorithmus 8.1.4] as well as [49,Theorem 3.14].
Theorem 4.13. There is a polynomial-time algorithm that, given a cut program G, finds a straight-line program G ′ such that eval(G) = eval(G ′ ). Theorems 4.9 and 4.13 imply that there is a polynomial-time algorithm that, given two cut programs, decides if they have the same output.
Remark 4.14. In fact, in what follows, we will only ever need the prefix and suffix cut operators [: j] and [i :]. This is because, when using a word to represent a group element, cancellation appears where two factors meet.
We also note that iterating the cut operator can be done using arithmetic alone. That is, the cut variables have the same evaluation. This "cut elimination" is, in some sense, the heart of the proof of Theorem 4.13.

The compressed word problem for hyperbolic groups
Suppose that G is a group and Σ is a finite symmetric generating set. We fix a total order < on Σ. Suppose that G is δ-hyperbolic; here we take δ large enough so that all geodesic triangles are δ-thin, and we assume also that δ > 0 is an integer. (This assumption is used in Case 3.2 inside of the proof of Lemma 5.3.) In what follows, we take ζ = 2δ. Recall that B(r) is the ball of radius r about 1 G in the Cayley graph Γ = Γ(G, Σ). 5.1. Tethered programs. We introduce a new type of program using the tether operator.
A tethered program over Σ is a tuple G = (V, S, ρ), with V and S as in Section 4.1, and where we also allow, as right-hand sides for ρ, expressions of the form B a, b , with B ∈ V and with a, b ∈ B(ζ). We again require ρ to be acyclic. If ρ(A) = B a, b then we define We call the suffix a, b a tether operator. The size of a tethered program G is the sum of the bit-lengths of the right-hand sides; group elements in B(ζ) are represented by their shortlex representatives.
Finally, in a tether-cut program G over Σ we allow right-hand sides which are words from (V ∪ Σ) * , a cut variable, or a tethered variable. It is sometimes convenient to allow more complicated right-hand sides such as Again, we define the size of G as the sum of the bit-lengths of the right-hand sides. In what follows we will assume that all programs arising are over a fixed alphabet Σ.

Remark 5.1.
In what follows we mostly need the prefix and suffix tether operators a, 1 and 1, b . For, suppose that Γ(G, Σ) is hyperbolic and that u and v are geodesic words. Let w = G uv be a geodesic word representing their product. Then we can describe w (up to bounded Hausdorff distance) by taking a prefix of u, tethering the result at the end, concatenating with a short word, and then tethering (at the front) a suffix of v. See Figure 5.12 below.
We also note that iterating tether operators can be done "locally". That is, for any a, a ′ , b, b ′ ∈ B(ζ) there are elements a ′′ , b ′′ ∈ B(ζ), elements x, y ∈ B(2ζ), and natural numbers i, j so that the expressions B a, b a ′ , b ′ and x · B[i : j] a ′′ , b ′′ · y have the same evaluation: that is, they represent the same shortlex reduced word. See Figure 5.2. Again, this "tether-elimination" is, in some sense, the heart of our proof of Lemma 5.3.
We say that a program is in Chomsky normal form if it is either a trivial program or all right hand sides ρ(A) have one of the following forms, where B, C ∈ V , a ∈ Σ, i ≤ j and b, c ∈ B(ζ): a, BC, B[i : j], B b, c . Similar to the case of straight-line programs, there is a linear-time algorithm that transforms a given program G (with eval(G) = ε) into a program G ′ in Chomsky normal form with the same output.
We say that a program G is geodesic (or shortlex ) if for every variable A, the word eval(A) is geodesic (shortlex reduced).
Lemma 5.2. There is a polynomial-time algorithm that, given a geodesic tether-cut program G, returns a geodesic tether-cut program G ′ with the same evaluation which is in Chomsky normal form.
Proof. We essentially use the usual algorithm; see, for example [49, Proposition 3.8]. However, some care must be taken with tethered variables. If ρ(A) = B a, b and ρ(B) = ε then we set ρ(A) = slex(ab −1 ) and repeat the process.
Note that the concatenation of geodesic words may not itself be geodesic; however the concatenation does provide two sides of a geodesic triangle. When the group G is hyperbolic, this gives us the beginnings of a reduction procedure.
We now turn to the task of proving Proposition 5.5. We will give a sequence of results that allows us to transform a geodesic tether-cut program into a straight-line program, whose evaluation is the shortlex representative of the original. The first step, in Lemma 5.3, gives such a transformation for tethered programs. The second step, finishing the proof of Proposition 5.5, is to transform a geodesic tether-cut program into an geodesic tethered program with the same output. This second step is inspired by Hagenah's result (Theorem 4.13) transforming a cut program into an equivalent straight-line program.

5.3.
Transforming tethered programs. Suppose that G = (V, S, ρ) is a program, as above.
We recursively define the height of elements of Σ ∪ V . If a ∈ Σ then we take height(a) = 0. For A ∈ V we define Suppose that G is a tethered program in Chomsky normal form. If A ∈ V is a variable we define its tether-height, denoted height t (A), recursively as follows. For a variable A we define its tether-depth to be There is a polynomial-time algorithm that, given a geodesic tethered program G, finds a shortlex straight-line program G ′ so that eval(G ′ ) = slex(eval(G)).
Proof. Set G = (V, S, ρ). The straight-line program G ′ that we construct will be of the form G ′ = (V ′ , S ′ , ρ ′ ) for suitable V ′ and ρ ′ .
Applying Lemma 5.2 we may assume that G is in Chomsky normal form. Introducing a new start variable, if needed, we may assume that ρ(S) has the form A 1, 1 for a variable A. We do this to force the evaluation of G to be shortlex reduced, not just geodesic. By removing unused variables, we can assume that S has maximal height and maximal tether-height among all variables. This implies that, for all A ∈ V , the tether-depth of A is greater than zero. Finally, for every variable A ∈ V such that ρ(A) = BC with B, C ∈ V we can assume that To ensure this property we add dummy variables to G, with productions of the form X 1, 1 , as needed.
In the rest of the proof, height, height t and depth t always refer to the original tethered program G.
We carry out the proof in a bottom-up fashion; that is, we consider the variables of G in order of increasing height. Here is an outline of the proof; we give the details below. Set w = eval(A). If |w| ≤ 16ζdepth t (A) + 2ζ then we compute and record w, as a word. If w is longer than that, then we instead compute words ℓ A and r A such that w = ℓ A · w ′ · r A for some word w ′ of length at least 2ζ. The details of the computation depend on the production ρ(A). We require that the word ℓ A satisfies the following length constraint and similarly for r A . When w is long, we also add to the program G ′ the decorated variables A ′ a,b for all a, b ∈ B(ζ). We arrange the following: eval(A ′ a,b ) = slex(a · w ′ · b −1 ) These new variables A ′ a,b , and also a new start variable S ′ , are the only variables appearing in G ′ , that is, they form the set V ′ . All of the words that we compute and record along the way, such as the short words w and the prefixes and suffixes ℓ A and r A , are not separately stored as part of G ′ .
That completes our outline of the proof. We now consider the possibilities for the right-hand side ρ(A). Case 1. Suppose ρ(A) ∈ Σ. Thus w = eval(A) is geodesic and shorter than 16ζdepth t (A) + 2ζ. We record it and continue. Recall that u, v, w are geodesic by assumption. Case 2.1. Suppose |u| > 16ζη + 2ζ and |v| > 16ζη + 2ζ. Hence, in previous stages of the algorithm we computed words ℓ B , r B , ℓ C , r C such that the following properties hold.
• The prefixes and suffixes ℓ B , r B , ℓ C , r C satisfy the length constraint of Equation 4. • There are geodesic words u ′ , v ′ of length at least 2ζ with u = ℓ B ·u ′ ·r B and Also, we have already defined variables B ′ a,c and C ′ d,b for all a, b, c, d ∈ B(ζ), which produce slex(a·u ′ ·c −1 ) and slex(d·v ′ ·b −1 ), respectively. See Figure 5.5.
We now set ℓ A = ℓ B and r A = r C . Since the tether-depths of A, B, C are all the same, but A has greater height, we deduce that ℓ A and r A satisfy the length constraint of Equation 4. We also note that It remains to define the right-hand sides for the variables A ′ a,b for all in polynomial time using Lemma 3.2. We then check, using Proposition 4.7 and Lemma 3.3, whether the word Again, see Figure 5.5. Since |u ′ | ≥ 2ζ ≥ |a| + ζ = |a| + 2δ, |v ′ | ≥ 2ζ ≥ |b| + ζ = |b| + 2δ, and |r B ℓ C | ≥ 16ζ ≥ 4δ, Corollary 3.5 ensures that there must be at least one such pair c, d. (If there are several, we stop as soon as we find the first such.) We then define Case 2.2. Suppose |u| > 16ζη + 2ζ and |v| ≤ 16ζη + 2ζ. Thus, at previous stages of the algorithm we computed the geodesic word v explicitly and also computed explicit words ℓ B and r B such that the following properties hold.
• The prefix and suffix ℓ B , r B satisfy the length constraint of Equation 4. • There is a geodesic word u ′ of length at least 2ζ with u = ℓ B · u ′ · r B . Also, we already defined variables B ′ a,b for all a, b ∈ B(ζ) such that B ′ a,b produces slex(a · u ′ · b −1 ). If |v| ≤ 2ζ, then we set ℓ A = ℓ B and r A = r B v. In this case, we also define Thus the length bounds of Equation 4 are satisfied. Now assume that |v| > 2ζ. Again, we set ℓ A = ℓ B . Since |r B · v| ≥ |r B | ≥ 8ζη we can define r A as the suffix of r B ·v of length 8ζη; that is, r B ·v = y ·r A for some word y of length |y| = |r B | + |v| − |r A | ≥ |v| > 2ζ. This satisfies the required bounds on the lengths of ℓ A and r A .
It remains to define the right-hand sides for the variables A ′ a,b for all a, b ∈ B(ζ). Let us fix a, b ∈ B(ζ). For all c ∈ B(ζ) we compute z = slex(c · y · b −1 ) and check whether the word is shortlex reduced. If it is, then it equals slex(a · u ′ · y · b −1 ); see Figure 5.6. By Lemma 3.4, there must be at least one such c, for which we define Case 2.3. Suppose |u| ≤ 16ζη + 2ζ and |v| > 16ζη + 2ζ. This is dealt with in similar fashion to the previous case. Case 2.4. Suppose |u| ≤ 16ζη + 2ζ and |v| ≤ 16ζη + 2ζ. In this case, we have computed u and v explicitly at a previous stage. We now distinguish between the cases |w| ≤ 16ζη + 2ζ and |w| > 16ζη + 2ζ. In the first case, we record the word w for later use. In the second, we factorise w as w = ℓ A · w ′ · r A with |ℓ A | = |r A | = 8ζη, and thus |w ′ | ≥ 2ζ. We then explicitly compute, for each a, b ∈ B(ζ), the word slex(a · w ′ · b −1 ) and set ρ ′ (A ′ a,b ) equal to it. This again uses Lemma 3.2. Case 3. Suppose ρ (A) = B a, b for a, b ∈ B(ζ). Let u = eval(B) and v = eval(A) = slex(a · u · b −1 ). The word u is geodesic by assumption, and v is shortlex reduced by definition. Let η = depth t (B). We have depth t (A) = η − 1 ≥ 1.
Case 3.1. Suppose |u| ≤ 16ζη + 2ζ. Hence, at a previous stage, we explicitly computed the word u. Using Lemma 3.2 we explicitly compute the word v = slex(a · u · b −1 ). The rest of the work divides into cases as |v| is less than or equal to 16ζη + 2ζ or is greater. This is analogous to Case 2.4 (where w plays the role of v). Case 3.2. Suppose |u| > 16ζη + 2ζ. At a previous stage we computed words ℓ B , r B with the following properties.
• The prefix and suffix ℓ B , r B satisfy the length constraint of Equation 4. • There is a geodesic word u ′ of length at least 2ζ with u = ℓ B · u ′ · r B . Also, we already defined variables . Let s = slex(a·ℓ B ·c −1 ) and t = slex(d·r B ·b −1 ). By the triangle inequality, these words have length at least 8ζη−2ζ. Hence we can factorise these words as s = wx and t = yz with Again, see Figure 5.7. The words x and y have length at least 6ζ. We set ℓ A = w and r A = z. These words satisfy the required bounds on their lengths. Note that It remains to define the right-hand sides of the variables A ′ a ′ ,b ′ for all a ′ , b ′ ∈ B(ζ). (This, in essence, is where we call upon Remark 5.1.) Fix a ′ , b ′ ∈ B(ζ). The lower bounds on the lengths of w, x, y, z allow us to apply Lemma 3.4 to the geodesic quadrilaterals with sides labelled a, ℓ B , c, wx and d, r B , b, yz, respectively. Note that all of these words have been computed explicitly. Applying Lemma 3.2, we compute in polynomial time words e, f ∈ B(ζ) and factorisations ℓ B = w ′ x ′ and r B = y ′ z ′ such that aw ′ = G we, ex ′ = G xc, dy ′ = G yf , and f z ′ = G zb. Once again, see Figure 5.7. Now consider the geodesic quadrilateral with sides labelled x ′ · u ′ · y ′ , slex(a ′ e), slex(b ′ f ), and slex(a ′ e · x ′ · u ′ · y ′ · (b ′ f ) −1 ). The triangle inequality implies |x ′ |, |y ′ | ≥ 4ζ and |slex(a ′ e)|, |slex(b ′ f )| ≤ 2ζ. Again applying is shortlex reduced. Thus the above word is As before, we can compute such c ′ , d ′ ∈ B(ζ) in polynomial time. We finally define the right-hand side of A ′ a ′ ,b ′ as This concludes the definition of the right-hand sides for the variables A ′ a ′ ,b ′ . We complete the definition of the straight-line program G ′ . We add a new start variable S ′ to G ′ . If eval(S) is short then we set ρ ′ (S ′ ) = eval(S) and we are done. If eval(S) is long then we set ρ ′ (S ′ ) = ℓ S · S ′ 1,1 · r S . This ensures eval(G ′ ) = ℓ S · slex(s ′ ) · r S , where s ′ is such that ℓ S · s ′ · r S = eval(S) = eval(G). But eval(G) is shortlex reduced (since ρ(S) has the form A 1, 1 ). Hence s ′ is also shortlex reduced and we find This concludes the proof of the lemma.
The next lemma follows from Lemma 5.3.

Lemma 5.4.
There is a polynomial-time algorithm that, given a geodesic tethered program G, computes for every A the length |eval(A)|.
Proof. By Lemma 5.3, we can compute for every variable A a straight-line program G A with eval(G A ) = slex(eval(A)). As in Section 4.2, we can compute |eval(G A )| = |slex(eval(A))| = |eval(A)| in polynomial time. Here the last equality holds since G is a geodesic program.
We now can prove our proposition; this generalises Lemma 5.3 to tethercut programs.
Proposition 5.5. There is a polynomial-time algorithm that, given a geodesic tether-cut program G, computes a shortlex straight-line program G ′ such that eval(G ′ ) = slex(eval(G)).
Proof. The idea of the proof is taken from the proof of Theorem 4.13; see [31,Algorithmus 8.1.4]. That is, we will eliminate cut operators by pushing them towards smaller variables. We then appeal to Lemma 5.3 to eliminate tether operators.
Let G = (V, S, ρ) be the input geodesic tether-cut program. By Lemma 5.2, we can assume that G is in Chomsky normal form. Let µ = height(G). By Lemma 5.3 it suffices to transform G into a geodesic tethered program for eval(G).
We will only consider cuts of the form [: i] and [i :]; see Remark 4.14. It is not difficult to include also general cuts of the form [i : j].
Consider a variable A such that ρ(A) = B[: i]; the case that ρ(A) = B[i :] is dealt with analogously. We consider variables in order of increasing height; so the algorithm is bottom-up. By induction we may assume that no cut operator occurs in the right-hand side of any variable C with height less than that of A.
We now must eliminate the cut operator in ρ(A). In so doing, we add at most µ new variables to the tether-cut program. Moreover the height of the tether-cut program after the cut elimination will still be bounded by µ. Hence, the final tethered program will have at most µ · |V | variables. In addition, the bit length of every new right-hand side will be polynomially bounded in the input length. Thus, the size of the final tethered program will be polynomially bounded in the input length.
Recall that ρ(A) = B[: i]. We divide the work into cases, depending on the form of ρ(B). Since we already have processed B, only one of the following cases can occur.  Figure 5.9. As in Case 3.1 we can check in polynomial time whether this condition holds. We introduce a new variable X, we set ρ(X) = C 1, b ′ , and we redefine ρ(A) = X a, c . The triangle inequality implies i − 2ζ ≤ |u ′ | ≤ i + 2ζ. We can find such a factorisation of u in polynomial time; we note that j = |u ′ | lies in N and satisfies |i − j| ≤ 2ζ. So, using Theorem 4.13, we find straight-line programs for the 4ζ + 1 many words u ′ = u[: j], where j ∈ N, |i − j| ≤ 2ζ. Since u is geodesic, also all factors of u are geodesic. Hence, the straight-line programs for the words u ′ = u[: j] must be geodesic too. Then we apply Lemma 5.3 and compute for every c ∈ B(ζ) a shortlex straight-line program for the word w ′ = slex(au ′ c −1 ). Theorem 4.13 yields a shortlex straight-line program for v ′ = v[: i]. Finally, we check, using Theorem 4.9, whether v ′ = w ′ . Hyperbolicity ensures that we will find at least one such j and c. We introduce a new variable X, we set ρ(X) = C[: j], and we redefine ρ(A) = X a, c We then continue with the elimination of the cut operator in C[: j], as in Case 2.
This concludes the proof of the lemma.
Recall our convention: if w ∈ Σ * is a word then g w ∈ G is the corresponding group element. Thus g w is a vertex of the Cayley graph Γ = Γ(G, Σ).
Lemma 5.6. There is a polynomial-time algorithm that, given geodesic tether-cut programs G and H, determines if d Γ (g, h) ≤ δ, where g = g eval(G) and h = g eval(H) . Moreover, when this holds, the algorithm also finds an element b ∈ B(δ) such that g = G hb.
Proof. Let S and T be the start variables of G and H, respectively. For all b ∈ B(δ) we produce a new geodesic tether-cut program G b for slex(eval(G)b −1 ). We do this by adding to G a new start variable with right-hand side S 1, b .
We also add to H a new start variable with right-hand side T 1, 1 and denote the resulting tether-cut program by H 1 . This ensures that the evaluation of H 1 is slex(eval(H)). Using Proposition 5.5 and Theorem 4.9 we now check, in polynomial time, if eval(G b ) = eval(H 1 ). This is equivalent to g = G hb.

5.10.
Solving the compressed word problem. We now prove our main result. Recall that Σ is a symmetric generating set for the hyperbolic group G.
Theorem 5.7. There is a polynomial-time algorithm that, given a straightline program G over Σ, finds a straight-line program H with evaluation slex(eval(G)).
Proof. By Proposition 5.5 it suffices to build, in polynomial time, a geodesic tether-cut program H for slex(eval(G)). We process G from the bottomup; that is, we consider its variables in order of increasing height. Set G = (V, S, ρ); applying [49, Proposition 3.8], we may assume that G is in Chomsky normal form. We build by induction on the height a new tether- is a copy of V and S ′ ∈ V ′ is the variable corresponding to S. The construction will ensure that eval(A ′ ) = slex(eval(A)) for every A ∈ V .
In the inductive step we have ρ(A) = BC. Since B and C have smaller height than A they satisfy the induction hypotheses. Set u = slex(eval(B)) = eval(B ′ ) and v = slex(eval(C)) = eval(C ′ ) By Proposition 5.5 we can transform the geodesic tether-cut programs with start variables B ′ and C ′ into shortlex straight-line programs. Using these, we compute the lengths m = |u| and n = |v|. If one or both of these have length zero then we accordingly take ρ ′ ( We now assume that m and n are both non-zero. Breaking symmetry, we assume that m ≤ n. Let P be the path in the Cayley graph Γ starting at 1 G , ending at u, and labelled by u. Similarly, let Q be the path starting at u, ending at uv, and labelled by v. Finally, let R be the path starting at 1 G , ending at uv, and labelled by slex(uv). See Figure 5.12. The pathP , the reverse of P , is labelled by u −1 . Applying Remark 4.12 we invert the geodesic straight-line program for u to give a straight-line program for u −1 . Using Lemma 5.6 we can check whether or not d Γ (P (m), Q(m)) ≤ δ We break into cases accordingly. Case 1. Suppose that d Γ (P (m), Q(m)) ≤ δ. We compute, again using Lemma 5.6, a word a of length at most δ such that a = G uv[: m]. See the left-hand side of Figure 5.12. In this case we set ρ ′ (A ′ ) = C ′ [m :] a, 1 . Case 2. Suppose that d Γ (P (m), Q(m)) > δ. Using binary search, we compute an integer k ∈ [0, m − 1] such that d Γ (P (k), Q(k)) ≤ δ and d Γ (P (k + 1), Q(k + 1)) > δ Here are the details of the binary search. We store an interval [p, q] ⊆ [0, m] such that • p < q, • d Γ (P (p), Q(p)) ≤ δ, and • d Γ (P (q), Q(q)) > δ. We begin with p = 0 and q = m. We stop when q = p + 1. In each iteration, we compute r = ⌈(p + q)/2⌉ and check, using Lemma 5.6, whether d Γ (P (r), Q(r)) ≤ δ or d Γ (P (r), Q(r)) > δ In the first case we set p = r and do not change q; in the second case we set q = r and do not change p. In each iteration the size of the interval [p, q] is roughly halved. Thus the binary search halts after O(log(m)) iterations; this is polynomial in the input size. In addition to the final position k, we record a word a ∈ B(δ) that labels a path fromP (k) to Q(k). Let j = k + 1.
Recall that R is the path fromP (m) = 1 G to Q(n) labelled by slex(uv). By Lemma 3.6 there exist i P ≤ i Q such that d Γ (P (j), R(i P )) ≤ δ and d Γ (Q(j), R(i Q )) ≤ δ For all pairs b, c ∈ B(δ) we explicitly compute the word The symbols u[m − j] and v[k] can be computed in polynomial time from the available straight-line programs for u and v using [49, Proposition 3.9]; see Section 4.2. For each of these words s, we must check if the word is shortlex reduced; if so, it equals slex(uv). This step can be done using Lemma 3.3 and using the given geodesic tether-cut programs for u and v. From these we obtain geodesic tether-cut programs for slex(u[: m − j] · b −1 ) and slex(c · v[j :]). We then use Proposition 5.5 to transform these into equivalent straight-line programs. Lemma 3.6 ensures that that we will find a pair b, c ∈ B(δ) such that the word in (11) is shortlex reduced. Using the first such pair we find, we set This concludes the proof of the theorem.  Proof. Suppose that G is the given compressed word. Note that eval(G) ∈ Σ * represents 1 G if and only if slex(eval(G)) = ε. This, in turn, happens if and only if slex(eval(G)) has length zero. Since Theorem 5.7 gives a straight-line program G ′ for slex(eval(G)), we are done.
6. Further compressed decision problems 6.1. Compressed order problem. Suppose that G is a group. Suppose that Σ is a finite, symmetric generating set for G. For any g ∈ G we define the order of g to be the smallest positive integer k so that g k = 1 G . If there is no such k we define the order to be infinity. We define the compressed order problem as follows.
Input: Straight-line program G over Σ. Output: The order of the group element eval(G).
As a consequence of Corollary 5.8 we have the following result.
Corollary 6.1. Let G be a hyperbolic group. Then the compressed order problem for G can be solved in polynomial time.
Proof. Let G be the given compressed word. Since G is hyperbolic, it has only finitely many conjugacy classes of finite subgroups [39,Theorem 6.8.4].
Thus there is a bound c = c(G) on the size of its finite cyclic subgroups. Hence the order of any element g ∈ G belongs to {1, . . . , c} ∪ {∞}.
To compute the order of eval(G) it suffices to check whether eval(G) k = G 1 G for some integer k in the range {1, . . . , c}. Proposition 4.6 gives us the desired compressed word and Corollary 5.8 checks it, both in polynomial time.
6.2. The compressed (simultaneous) conjugacy and compressed centraliser problems. Suppose that G is a group. Suppose that Σ is a finite, symmetric generating set for G. For group elements g, h ∈ G we have the standard abbreviation g h = h −1 gh. If L = (g 1 , . . . , g k ) is a finite list of group elements then we write L h = (g h 1 , . . . , g h k ). We extend these definitions to words over Σ in the obvious way.
6.3. The problems. The compressed conjugacy problem for G is the following.
Input: Straight-line programs G and H over Σ. Question: Do eval(G) and eval(H) represent conjugate elements in G?
If L is a list of straight-line programs over Σ, then we define eval(L) to be the corresponding list of evaluations. We now define the compressed simultaneous conjugacy problem for G. In the case when the answer to either of these questions is positive, we might also want to compute a straight-line program for an element that conjugates eval(G) to eval(H) or eval(L) to eval(M).
The compressed centraliser problem for G is the following computation problem.
Input: A finite list L = (G 1 , . . . , G k ) of straight-line programs over Σ. Output: A finite list M = (H 1 , . . . , H l ) such eval(M) generates the intersection of the centralisers of the elements eval(L). Note that this intersection is in fact the centraliser of the subgroup generated by the elements eval(L). When the desired centraliser is not finitely generated, by convention the problem has no solution.
6.4. The proofs. A linear-time algorithm for solving the conjugacy problem in a hyperbolic group G is described in [23,Section 3]. This was generalised in [10] to linear-time algorithms for the (uncompressed) simultaneous conjugacy, and the centraliser, problems. We will show that essentially the same algorithms can be used to solve the compressed (simultaneous) conjugacy problem and the compressed centraliser problem, in polynomial time.
We deal with the compressed conjugacy problem in Section 6.4.1. Building on that, and making the special assumption that one of the input elements has infinite order, we solve the compressed simultaneous conjugacy problem and the compressed centraliser problem in Section 6.4.2. Finally, we deal with the case that all input group elements have finite order in Section 6.4.3.
6.4.1. Compressed conjugacy problem. We now have the following. Theorem 6.2. Let G be a hyperbolic group. Then the compressed conjugacy problem in G is polynomial time.
Proof. The input consists of two straight-line programs G and H; we wish to test if u = eval(G) and v = eval(H) are conjugate. To do this we essentially use the conjugacy algorithm from [23, Theorem 1.1], applied to the words u and v. We will describe our modification of their algorithm, step-by-step, in the following.
Our description of each step consists of two parts. The first describes operations relating to the words u and v; the second explains how we effect these operations in polynomial time using only the straight-line programs G and H. All assertions that we make in the uncompressed setting are justified in [23]. All corresponding assertions are then justified again, in the compressed setting, using the work in previous sections of this paper.
A word w ∈ Σ * is said to be shortlex straight if, for all non-negative powers k, the word w k is shortlex reduced. Applying Lemma 3.3 and Proposition 4.8 we can determine, in polynomial time, if a given compressed word eval(G) is shortlex straight.
In the preprocessing stage, we make a look-up table of all pairs of shortlex reduced words of length at most K that are conjugate in G.
Step 1. We replace u and v by slex(u) and slex(v).
By Theorem 5.7 we can replace, in polynomial time, the programs G and H by straight-line programs for slex(eval(G)) and slex(eval(H)), respectively.
Step 2. For a word w, we define w C = w R w L , where w = w L w R with |w L | ≤ |w R | ≤ |w L | + 1. Replace u by slex(u C ) and v by slex(v C ).
Using cut operators and Theorem 5.7 we can make the corresponding substitutions on G and H.
Step 3. If |u|, |v| ≤ K then use the look-up table to test for conjugacy of u and v. Otherwise, at least one of the words, u say, satisfies |u| ≥ K > 2L + 1. If |v| < 2L+1 then u and v are not conjugate [23, Section 3.1], and we return false. We assume from now on that |u|, |v| ≥ 2L + 1.
For the compressed conjugacy problem, if |eval(G)|, |eval(H)| ≤ K then we can compute eval(G) and eval(H) explicitly. We then proceed as in the uncompressed setting.
Step 4. There exists a group element g ∈ B(4δ) and a positive integer m, of size at most |B(4δ)| 2 , such that the shortlex reduction of g −1 u m g is shortlex straight [23,Section 3.2]. To find such, for every pair (g, m) of at most those sizes, we replace u by slex(g −1 ug) and test z = slex(u m ) to see if it is shortlex straight.
Using Proposition 4.8, we can perform the corresponding operations with G. Thus we find g and m and also find a straight-line program G ′ with eval(G ′ ) = z.
Step 5. We now test for the following necessary (but not sufficient) property for the conjugacy of u and v: is v m conjugate to z? We decide this as follows. For all h ∈ B(6δ), we compute v h = slex(hv m h −1 ), and then test whether v h is a rotation of z. If this fails for all h, then v m and z = G u m are not conjugate [23,Section 3.3]. But then, u and v are not conjugate, so we may stop and return false.
Otherwise, we find h and v h with this property. Let z 1 be a prefix of z such that z = G z 1 hv m h −1 z −1 1 . We replace v by slex(z 1 hvh −1 z −1 1 ). Now we have v m = G u m = G z. From this we get that every g ∈ G with g −1 ug = G v belongs to the centraliser C G (z) of z in G. In particular, u and v are conjugate in G if and only if they are conjugate in C G (z).
Using Corollary 4.11 we can do the corresponding calculations with H and G ′ . Checking whether v h is a rotation of z can be accomplished in polynomial time by the first statement of Corollary 4.11; the second statement allows us to compute in polynomial time a straight-line program for z 1 .
Step 6. Find the shortest prefix y of z that is a root of z: that is, there is an ℓ ≥ 1 so that z = y ℓ . We do that by finding the second occurrence of the substring z in the word z 2 .
To find the root of eval(G ′ ), we compute a straight-line program for eval(G ′ ) 2 and appeal to Theorem 4.10. We then build a straight-line program G ′′ with eval(G ′′ ) = y using cut operators and Theorem 4.13.
Step 7. For each h ∈ B(2δ), compute slex(hzh −1 ) and test whether it is a rotation of z. If so, find a prefix z h of z with hzh −1 = G z −1 h zz h , and compute and store slex(z h · h) (which lies in C G (z)) in a list C z . Then |C z | ≤ J = |B(2δ)|.
Corollary 4.11 allows us to do the corresponding calculations with G ′ . We obtain a list of straight-line programs that evaluate to the words in the list C z .
Step 8. For each n with 0 ≤ n ≤ (J − 1)! and for each z ′ ∈ C z , let g = y n z ′ . Test if u = G gvg −1 . If so, then return true (and a conjugating element). If not, then return false because u and v are not conjugate [23,Section 3.4].
We can perform corresponding operations on the straight-line programs. This concludes our description of a polynomial-time algorithm for the compressed conjugacy problem. The correctness proof is identical to that in [23, Section 3] 6.4.2. Compressed simultaneous conjugacy and centralisers: the infinite order case. We now turn to the following. Theorem 6.3. Let G be a hyperbolic group. Then the compressed simultaneous conjugacy problem for G can be solved in polynomial time. Moreover, if the two input lists are conjugate, then we can compute a straight-line program for a conjugating element in polynomial time.
Theorem 6.4. Let G be a hyperbolic group. Then the compressed centraliser problem for G can be solved in polynomial time.
The input now consists of two lists L = (G 1 , . . . , G k ) and M = (H 1 , . . . , H k ) of straight-line programs over the alphabet Σ. For the compressed centraliser problem we assume that L = M. For all i we let u i = eval(G i ) and v i = eval(H i ).
By Corollary 6.1 we can check in polynomial time whether some u i has infinite order. Following [10, Section 3] we begin by assuming that this is indeed the case. Reordering the lists in the same way, as needed, we may assume that u 1 has infinite order. If v 1 does not have infinite order we are done.
The conjugacy testing algorithm proceeds as follows. We first repeatedly replace the elements in L by conjugates, using a common conjugating element. This culminates in a check for a conjugating element which must lie in an explicit finite set. In each replacement, straight-line programs are known for the conjugating element. By keeping track of these, we can find (if the lists are conjugate) an overall conjugating element for the original input. We omit further details regarding this overall conjugating element.
We proceed by carrying out the eight steps of the algorithm of Section 6.4.1 as applied to u 1 and v 1 . If they are not conjugate we are done. Suppose that they are conjugate. In this case we record the programs for the words z and y produced by Steps 5 and 6. We also record the list (of straight-line programs) C z given in Step 7. The overall algorithm also gives us a straight-line program for an element g ∈ G with u g 1 = G v 1 . The algorithm also replaced u 1 and v 1 by conjugates in some of the steps; we make the corresponding replacements to the other elements of L and M. By replacing each u i by its conjugate under g, we may now assume that Thus we have reduced the problem to the following. Assuming that u 1 = v 1 and that u 1 has infinite order, we must decide if there is g ∈ C G (u 1 ) with u g i = G v i for 2 ≤ i ≤ k. We are also given z; thus u m 1 = G v m 1 = G z and z is shortlex straight element z and m ≥ 1. We are also given y with z = y ℓ and for maximal ℓ ≥ 1.
In [23,Section 3.4] it is shown that all elements g ∈ C G (z) have the form g = G y n z ′ , for some n ∈ Z and z ′ ∈ C z , where C z is the list given above. So the same applies to any g ∈ C G (u 1 ) ⊆ C G (z).
We now try each z ′ ∈ C z in turn. Replacing each v i by z ′ v i (z ′ ) −1 , the problem reduces to the following: is there some n ∈ Z such that u y n i = G v i for 1 ≤ i ≤ k?
To solve this problem, we apply [10, Proposition 24] to each pair u i , v i in turn. For each i, there are three possibilities.
The proof of [10,Proposition 24] provides an algorithm for determining which case applies, and for finding r i , t i in cases (i) and (ii). This involves calculating a number of powers u n i , v n i , and y n for integers n such that |n| is bounded by a linear function of |u i | and |v i |, and where the number of powers that need to be calculated is bounded by a constant. So we can perform these calculations in polynomial time with straight-line programs by Proposition 4.6.
After performing this calculation for each i with 1 ≤ i ≤ k, the conjugacy problem for the lists reduces to solving some modular linear equations involving the integers r i and t i , as described in [10,Section 3.4]. Since the r i and t i in case (i) are bounded by a constant and, for r i in case (ii), log |r i | is bounded by a linear function of the size of the straight-line programs representing u i and v i , these equations can be solved in polynomial time using standard arithmetical operations on the binary representations of r i and t i . This completes our discussion of the compressed simultaneous conjugacy problem in the case where there is a list element of infinite order.
For the compressed centraliser problem, we are in the same situation but with v i = u i for all i. We perform the same calculations as above, but we do them for every z ′ ∈ C z . If there are solutions, then we find them by solving modular equations. The set of solutions we find now generates the centraliser. This completes our discussion of the compressed centraliser problem in the case where there is a list element of infinite order. 6.4.3. Compressed simultaneous conjugacy and centralisers: the finite order case. Here we continue the proofs of Theorems 6.3 and 6.4. We now consider the case where all of the u i (in the list eval(L)) have finite order. We now follow [10,Section 4]. No new complications arise when applying those methods to lists of straight-line programs. Indeed, some steps become easier because we are only interested in achieving polynomial, rather than linear, time.
We follow the steps of the algorithm described in [10,Section 4.5]. We deal with the conjugacy and centraliser problems together; the two lists are taken to be equal for the centraliser calculation. At this stage we have already verified that all of the u i and v i have finite order. Furthermore all of the words are shortlex reduced. By deleting programs, we can assume that the list u 1 , . . . , u k , and likewise the list v 1 , . . . , v k , has no duplicates. Thus the u i represent distinct group elements, as do the v i .
Let n = min{|B(2δ)| 4 + 1, k}. We consider the prefix sublists eval(L ′ ) = (u 1 , . . . , u n ) and eval(M ′ ) = (v 1 , . . . , v n ). We apply the function Shorten-Words from [10, Section 4.2] to the lists L ′ and M ′ . This function applies slex to a number of words; this number is bounded above by n 2 . Each word is a concatenation (of length at most n + 2) of words either from the lists L ′ or M ′ , or of words previously calculated during this process. These operations can be executed in polynomial time when working with straight-line programs. Since there is an absolute bound |B(2δ)| 4 + 1 on the lengths of L ′ and M ′ , the complete application of ShortenWords to each list takes place in polynomial time.
ShortenWords has two possible outcomes. In the first it finds a product u r ·u r+1 · · · u s of elements of L ′ with infinite order. This reduces the problem to the case dealt with in Section 6.4.2.
We now test in time O(1) (using our precomputed look-up table) whether there exists g ∈ G with (u ′ 1 , . . . , u ′ n ) g = (v ′ 1 , . . . , v ′ n ) If so, we replace (u 1 , . . . , u k ) by (u 1 , . . . , u k ) g and thereby assume that u i = v i for 1 ≤ i ≤ n. For the centraliser problem, methods are described in [27, Proposition 2.3] of finding a generating set of the centraliser of any quasiconvex subgroup of any biautomatic group; finitely generated subgroups of hyperbolic groups satisfy these conditions. Since they need only be applied to words of bounded length their complexity does not matterindeed, we could precompute all such centralisers.
This completes the proof in the case n = k. In the case k > n, it is proved in [10,Corollary 30] that the centraliser C of the subgroup u 1 , . . . , u n is finite, and that the elements of C have lengths bounded by a constant. So we can compute the elements of C explicitly (in time O(1)). Then we simply need to check whether any g ∈ C satisfies (u n+1 , . . . , u k ) g = (v n+1 , . . . , v k ) This completes the proofs of Theorems 6.3 and 6.4. 6.5. Compressed knapsack. In this final section, we prove the following. Theorem 6.5. If G is an infinite hyperbolic group then the compressed knapsack problem for G is NP-complete.
As above, fix G a finitely generated group. Fix as well a finite symmetric generating set Σ. A knapsack expression over Σ is a regular expression of the form E = u −1 u * 1 u * 2 · · · u * k with k ≥ 0 and u, u i ∈ Σ * . The length of E is defined to be |E| = |u| + k i=1 |u i |. A solution for E is a tuple (n 1 , n 2 , . . . , n k ) ∈ N k of natural numbers such that u = G u n 1 1 u n 2 2 · · · u n k k . In other words: the language defined by E contains a word that represents the identity of G.
The knapsack problem for G, over Σ, is the following.
Input: A knapsack expression E over Σ. Question: Does E has a solution?
In [57,Theorem 6.1] it was shown that the knapsack problem for a hyperbolic group can be solved in polynomial time. A crucial step in the proof for this fact is the following result, which is of independent interest. Theorem 6.6 [57,Theorem 6.7]. For every hyperbolic group G there exists a polynomial p(x) such that the following holds. Suppose that a knapsack expression E = u −1 u * 1 u * 2 · · · u * k over G has a solution. Then E has a solution (n 1 , n 2 , . . . , n k ) ∈ N k such that n i ≤ p(|E|) for all i satisfying 1 ≤ i ≤ k.
Recently, this result has been extended to acylindrically hyperbolic group in [8].
Let us now consider the compressed knapsack problem for G. It is defined in the same way as the knapsack problem, except that the words u, u i ∈ Σ * are given by straight-line programs. Note that the compressed knapsack problem for Z is NP-complete [30, Proposition 4.1.1]. Hence, for every group with an element of infinite order, the compressed knapsack problem is NP-hard. This makes it interesting to look for groups where the compressed knapsack problem is NP-complete.
From Corollary 5.8 and Theorem 6.6 we prove Theorem 6.5, which states that compressed knapsack for an infinite hyperbolic group G is NP-complete.
Proof of Theorem 6.5. Consider a knapsack expression E = u −1 u * 1 u * 2 · · · u * k over G, where u and the u i are given by straight-line programs G and G i . We then have |u|, |u i | ≤ 3 |G i |/3 by Lemma 4.5. Let N = |G| + k i=1 |G i | be the input length.
By Theorem 6.6, there exists a polynomial p(x) such that E has a solution if and only if it has a solution (n 1 , n 2 . . . , n k ) ∈ N k with n i ≤ p(|E|) for all i so that 1 ≤ i ≤ k. Thus we obtain a bound of the form 2 O(N ) on the exponents n i . Hence, we can guess the binary encoding of a tuple (n 1 , n 2 , . . . , n k ) ∈ N k with all n i bounded by 2 O(N ) and then check whether it is a solution for E. The latter can be done in polynomial time by constructing from the straightline programs G and G i a straight-line program H for u −1 u n 1 1 u n 2 2 · · · u n k k using Proposition 4.6. Finally, we check in polynomial time whether eval(H) = G 1 using Corollary 5.8.
The NP-hardness of the compressed knapsack problem for G (an infinite hyperbolic group) now follows from the fact that G has elements of infinite order [28,