{'fraction_non_alphanumeric': 0.056146234264446225, 'fraction_numerical': 0.014214397317175413, 'mean_word_length': 3.519951771257966, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 116, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Logspace and compressed-word computations in nilpotent groups

For finitely generated nilpotent groups, we employ Mal'cev coordinates to solve several classical algorithmic problems efficiently. Computation of normal forms, the membership problem, the conjugacy problem, and computation of presentations for subgroups are solved using only logarithmic space and quasilinear time. Logarithmic space presentation-uniform versions of these algorithms are provided. Compressed-word versions of the same problems, in which each input word is provided as a straight-line program, are solved in polynomial time.

Some of the earlier results in this area were obtained before complexity issues became a concern in algebra, while others were mostly focused on practical aspects of computing. Lately, ideas from space complexity are exerting a strong influence on computations in algebra, and in particular there is an active research interest in logarithmic space computations. Another influence of computer science on modern algebraic computing concerns data representation in compressed form and its use in developing algorithms with lower computational complexity. Polynomial time, logarithmic space, and compressed-word computations are now main players in modern algorithmic group theory. We will elaborate their roles in §1.2- §1.4 below.
In this paper we study the computational complexity of several fundamental algorithmic problems in finitely generated nilpotent groups. These problems include computing normal forms (Mal'cev coordinates) of group elements (hence deciding the word problem), deciding the conjugacy and membership problems, computing kernels of homomorphisms, and finding presentations for finitely generated subgroups. We prove that in a fixed group all these problems are computable in space logarithmic in the size of the input and, simultaneously, in quasilinear time.
For the decision problems above (i.e., word, conjugacy, and membership problems), our algorithms also solve the 'search' version of the problem, meaning if the algorithm answers "Yes" it also provides a witness to its answer, in logarithmic space and quasilinear time. For the word problem, this means writing a trivial element as a product of conjugates of relators; for the conjugacy problem, finding a conjugator; for the membership problem, expressing the given element as a product of subgroup generators. Note that, generally speaking, the search version of the word problem can be arbitrarily more difficult than the decision problem, for example, see [24,Section 4].
We also consider compressed-word versions of these problems, in which each input word is provided as a straight-line program (compressed word) producing a word over the generating set. We solve all compressed versions in time quartic in the input size.
All our algorithms can be executed uniformly, meaning the nilpotent group may be given by an arbitrary presentation as part of the input, but in general this will invalidate the complexity assessment as the nilpotency class and number of generators play a role in the complexity bound. However, if both the number of generators and the nilpotency class are bounded, the algorithms run in logarithmic space and polynomial time, with the degree of the polynomial depending on the bound.
1.1. Known approaches and summary of new results. An early example of the study of algorithmic problems in nilpotent groups is the work of Mostowski [28], who provided solutions to several algorithmic problems (word, membership, finiteness problems) and further expressed hope that the algorithms are practical for carrying out on a digital computer. As another example, while the word problem in nilpotent groups has long been known to be decidable, it was only established comparatively recently [13] that it is in fact decidable in real (therefore, linear) time. In 1958, Mal'cev [26] investigated finite approximations of finitely generated nilpotent groups, which allowed him to prove that they have decidable membership problem. In 1965, Blackburn [2], using the same method, showed decidability of the conjugacy problem for the same class of groups. Such separability arguments, while sufficient to show that the corresponding decision problems are solvable, offer, by themselves, no reasonable estimates on the time or space complexity of the algorithms involved. Only very recently, certain bounds for so-called full residual finiteness growth of nilpotent groups were established [3].
We would like to point out two more established approaches to algorithmic questions in nilpotent groups. One is based on the fact that every torsion-free nilpotent group embeds into a linear group UT d (Z) (see for example [10] or [15]). This easily solves the word problem, and was used by Grunewald and Segal in 1980 [9] to solve the last (at the time) standing major algorithmic problem in nilpotent groups, the isomorphism problem. It is worth mentioning that such an embedding shows that the word problem for torsion-free finitely generated nilpotent groups is, indeed, in LSPACE [19], but does not seem to provide any concrete time or space complexity estimates in the case of the conjugacy or membership problems.
Another fruitful approach is due to the fact that finitely generated nilpotent groups admit a so-called Mal'cev (Hall-Mal'cev) basis (see, for example, [10] and [15]), which allows one to carry out group operations by evaluating polynomials (see Lemma 2.2). This approach was systematically used in [16], which gave solutions to a number of algorithmic problems in a class of groups that includes finitely generated nilpotent groups. It was also used in the above-mentioned work of Mostowski [28].
Mal'cev basis techiniques can be viewed as part of a more general picture. Indeed, every finitely generated nilpotent group G is polycyclic. To a polycyclic series one may associate a polycyclic presentation, which in the case of nilpotent groups is closely connected to establishing a Mal'cev basis. Many algorithimic problems may be solved using such a presentation. This approach is described in detail in [35] and further studied in [18,31], and in particular may be used to solve the membership and conjugacy problems in polycyclic groups. To our knowledge, no robust complexity estimates for such methods have been established in the case of nilpotent groups, with one exception of the recent papers [29,30], which find polynomial bounds for the equalizer and membership problems.
We follow the Mal'cev basis approach. Let G be a fixed finitely generated nilpotent group. We describe algorithms to solve each of the following problems.
(I) Given g ∈ G, compute the (Mal'cev) normal form of g. (II) Given g, h 1 , . . . , h n ∈ G, decide whether g ∈ h 1 , . . . , h n and if so express g as a product of subgroup generators from a standardized set. (III) Fix another finitely generated nilpotent group, H. Given K = g 1 , . . . , g n , a homomoprhism φ : K → H specified by φ(g i ) = h i , and h ∈ Im(φ), compute a generating set for ker(φ) and find g ∈ G such that φ(g) = h. (IV) Given K = g 1 , . . . , g n ≤ G, compute a presentation for K. (V) Given g ∈ G, compute a generating set for the centralizer of g. (VI) Given g, h ∈ G, decide whether or not there exists u ∈ G such that u −1 gu = h and if so find such an element u.
In every case, the algorithm runs in space O(log L) and, simultaneously, in time O(L log 3 L), where L is the size of the input of the given problem. Problems (I), (V), and (VI) in fact run in time O(L log 2 L). To every subgroup one may associate a standardized or full-form generating set, and it is this set that is used in problem (II) to express g as a product of subgroup generators; we may in addition express g in terms of the given generating set, but the algorithm then runs in polynomial time (and not logspace). A Mal'cev basis consisting of m elements establishes a coordinatization of G, whereby each element is identified with an m-tuple of integers. The coordinates of a product gh are given by polynomial functions of the coordinates of g and h, and the coordinates of a power g l are given by polynomial functions of l and the coordinates of g. Our algorithms work directly with the coordinate tuples and these multiplication/exponentiation polynomials. The key to obtaining logarithmic space bounds, and polynomial time bounds for compressed-word problems, is the fact that coordinates of an n-fold product g 1 g 2 . . . g n are bounded in magnitude by a polynomial function whose degree depends only on the nilpotency class c of G (a constant) and not, as may be inferred by composing the polynomials n times, on the length of the product (Theorem 2.3).
The class LSPACE of problems decidable in logarithmic space is defined via machines called logspace transducers, and we recall the relevant definitions in §1.2. Logarithmic space computations in groups have been studied primarily in relation to the word and normal form problems. In free groups, the word problem was solved in logarithmic space by [19]. Normal forms were computed in logarithmic space for graph groups and Coxeter groups in [5] and the class of groups with logspace-computable normal forms was shown to be closed under several important constructions in [6]. The conjugacy problem was also solved in logspace for free solvable groups, the Grigorchuk group, and certain wreath products in [36].
We also consider compressed-word versions of problems (I)-(VI). In this formulation, every input word is given in the form of a straight-line program (see §1.3) and the input size L is the sum of the sizes of all input programs. A program of size L may encode a word of length up to 2 L−1 , and so efficient (i.e. polynomial time) algorithms must work directly on the straight-line program without producing the encoded word itself. We solve all of the problems (I)-(VI), with compressed-word inputs, in time O(L 4 ), with (I), (V), and (VI) being solved in time O(L 3 ). The approach is to first solve (I) to compute the Mal'cev coordinates of each input element, write each coordinate as a binary number, then apply the previous algorithms to the coordinate tuples. This also shows that a second 'compressed' formulation, in which every input word is given by its (binary) Mal'cev coordinates, can be solved in the same time complexity for each problem.
The compressed version of the word problem is known to be polynomial-time decidable in several classes of groups, including free groups [21], partially commutative groups [20], limit groups [23], and nilpotent groups [11]; further, polynomialtime decidability is preserved under many important group-theoretic constructions, such as graph products (see [22] for a summary). One motivation for obtaining a polynomial-time solution to the compressed word problem in a group G is that such a solution give rise to a polynomial-time solution to the (non-compressed) word problem in any finitely generated subgroup of Aut(G) and in semi-direct products involving G [34].
Less is known about the compressed conjugacy problem. It is polynomial-time decidable in free groups [34] and more generally partially commutative groups [11], these results being part of a polynomial-time solution to the word problem in the outer automorphism group of these groups. Further, the compressed conjugacy problem was recently shown to be polynomial-time decidable in hyperbolic groups [12]. For the compressed membership problem, we are not aware of any previous results for interesting classes of groups. Even in free groups no polynomialtime algorithm is known, though recent results of Jez [14] on DFAs with compressed labels are closely related. Compressed membership in abelian groups is easily solved in polynomial time by converting the straight-line programs to O(n)-bit integer vectors and applying linear algebra techniques, and our proof for nilpotent groups uses a similar approach.
1.2. Logspace. We define logarithmic space computation via a machine called a logspace transducer. Briefly, this is a deterministic Turing machine with three tapes: a read-only input tape, a read-write work tape with number of cells logarithmic in the size of the input tape, and a write-only output tape. We provide the details below.
Let Σ be a finite alphabet containing a symbol ǫ called the blank symbol. A tape is an infinite sequence X = {x n } n with x n ∈ Σ and all but finitely many x n being the blank symbol. The subsequence consisting of all symbols up to and including the last non-blank symbol is called the content of the tape and the length of this sequence is the size of the tape. Intuitively, we think of it as a one-ended infinite array of cells, each cell holding an element of this sequence. To every tape X we associate a positive integer h X called the head position.
Let S be a finite set, called the set of states. A configuration is a tuple C = (s, I, h I , W, h W , O, h O ) consisting of a state s ∈ S and three tapes I, W, O called the input tape, work tape, and output tape (respectively) together with the head positions for each tape. A transducer is a function which assigns to every possible configuration C a successor configuration C ′ = (s ′ , I ′ , h I ′ , W ′ , h W ′ , O ′ , h O ′ ) with the following properties: • C ′ depends only on s and the symbols at h I on I and at h W on W ; • I = I ′ and h I ′ differs from h I by at most 1; • W and W ′ are identical except possibly at position h W , and h W ′ differs from h W by at most 1; A run of the transducer is a finite sequence of configurations C 1 , C 2 , . . . , C k where there is no further computation to perform), and the work and output tapes of C 1 contain only the blank symbol β. The content of the input tape of C 1 is called the input and the content of the output tape of C k is the output.
Let c > 0 be any integer. A transducer is called a c-logspace transducer if for every possible run the size of the work tape in every configuration is bounded by c log n where n is the size of the input tape (the base of the logarithm is not generally relevant, though using |Σ| or |Σ| − 1 is natural). Provided such a constant c exists for a given transducer, it will be called simply a logspace transducer.
Let Σ ′ be another alphabet. We say that a function f : Σ * → (Σ ′ ) * is logspace computable if there is a logspace transducer which for every input w ∈ Σ * produces f (w) on the output tape. A decision problem, which we define as a subset of Σ * , is logspace decidable if its characteristic function is logspace computable. The complexity class LSPACE consists of all decision problems that are logspace decidable.
Note that in order to discuss multi-variable functions, we simply add a new symbol α to the alphabet and separate the input words by this symbol.
Any function that is logspace computable is also computable in polynomial time (meaning the length of every run is bounded by a polynomial function of n). Indeed, in any run the sequence of configurations that follow a given configuration C i are determined by C i only. Hence no run may contain the same configuration twice since runs have finite length by definition. Thus, the length of any given run (and hence the time complexity of the machine) is bounded by the number of possible configurations |S| · n · |Σ| c log n · c log n ∈ O(n c+2 ), where n is the length of the input. Since the degree c + 2 of this polynomial can be expected to be quite high, it is usually advantageous to analyze the time complexity of logspace transducers directly and obtain, if possible, a low-degree polynomial time bound.
The type of computations that can be done in logspace are quite limited. For example, to store an integer M requires log M bits. Hence we can store and count up to n c , but not higher. We may also store and manipulate pointers to different locations in the input, as each such pointer is an integer of size at most n. Basic arithmetic operations are also computable in logspace, and it is possible to compose logspace transducers (i.e., the class of logspace computable functions is closed under composition).
The above is a formal description of logspace computability via transducers, but in practice we simply work with informal algorithm descriptions and ensure that our algorithms require no more than logarithmic space. Each of our algorithms may be formally encoded as a logspace transducer.
1.3. Compressed words. Let Σ be a set of symbols containing a special symbol ǫ used to denote the empty word. A straight-line grammar A over Σ in Chomsky normal form consists of an ordered finite set A, called the set of non-terminal symbols, together with for each A ∈ A exactly one production rule either of the form A → BC where B, C ∈ A and B, C < A or of the form A → x where x ∈ Σ. The greatest non-terminal is called the root, elements of Σ are called terminal symbols, and the size of A is the number of non-terminal symbols and is denoted |A|. For shortness, with a slight abuse of terminology, in this paper we refer to straight-line grammars in Chomsky normal form as straight-line programs or compressed words. Note that any program A may, by encoding the non-terminal symbols as integers, be written down using O(|A| · log |A|) bits.
The output or evaluation of A is the word in Σ * obtained by starting with the root non-terminal and successively replacing every non-terminal symbol with the right-hand side of its production rule. It is denoted eval(A) and we similarly denote by eval(A) the word obtained starting with the non-terminal A ∈ A. For example, the program B over {x} with production rules B n → B n−1 B n−1 , B n−1 → B n−2 B n−2 , . . . , B 1 → x has eval(B) = x 2 n−1 and eval(B 2 ) = x 2 . As this example illustrates, the length of eval(A) may be exponential in |A| (this program in fact achieves the maximumlength output). Thus to have efficient algorithms dealing with compressed words, one must avoid computing eval(A) and instead work directly with the production rules. A fundamental result of Plandowski [32] states that two straight-line programs may be checked for character-for-character equality of their outputs in time polynomial in the sum of the program lengths.
Let us note here that for any fixed word w = x 1 x 2 · · · x m over Σ, the word w n may be encoded with a program of size O(log(n)). Indeed, we may first encode w using binary subdivision, i.e. with the scheme W i → x i for i = 1, . . . , m, W m+1 → W 1 W 2 , W m+2 → W 3 W 4 and so on, obtaining eval(W k ) = w where k is some integer bounded by |w| + log 2 |w|. A program similar to B above, with W k in place of x and suitable modifications when n is not a power of 2, will encode w n .
A straight-line program over a group G is a straight-line program over a given symmetrized generating set of G. Any algorithmic problem for G which takes words as input may be considered in 'compressed-word form' where all input words are provided as straight-line programs. For example, the compressed conjugacy problem asks, given two straight-line programs A and B over G, whether or not eval(A) and eval(B) represent conjugate group elements.

Computing Mal'cev normal forms
To produce efficient algorithms, our nilpotent group will need to be given by a particular type of presentation, known as a consistent nilpotent presentation. Such a presentation can be computed from an arbitrary presentation (Prop. 2.1). During computation, we represent group elements in their Mal'cev normal form, which we define below. Critically, converting a general group word to Mal'cev form involves at most a polynomial expansion in word length (Theorem 2.3), and may be performed in logarithmic space (Theorem 2.7).
. . , s where Z denotes the center. Equivalently, G possesses a normal series in which [G, G i ] ≤ G i+1 for all i = 1, . . . , s. If G is finitely generated, so are the abelian quotients G i /G i+1 , 1 ≤ i ≤ s. Let a i1 , . . . , a imi be a standard basis of G i /G i+1 , i.e. a generating set in which G i /G i+1 has presentation a i1 , . . . , a imi |a eij ij , j ∈ T i in the class of abelian groups, where T i ⊆ {1, . . . , m i } and e ij ∈ Z >0 . Formally put e ij = ∞ for j / ∈ T i . Note that A = {a 11 , a 12 , . . . , a sms } is a polycyclic generating set for G, and we call A a Mal'cev basis associated to the central series (1). For convenience, we will also use a simplified notation, in which the generators a ij and exponents e ij are renumbered by replacing each subscript ij with j + ℓ<j m ℓ , so the generating set A can be written as A = {a 1 , . . . , a m }. We allow the expression ij to stand for j + ℓ<j m ℓ in other notations as well. We also denote By the choice of the set {a 1 , . . . , a m } every element g ∈ G may be written uniquely as a group word of the form g = a α1 1 . . . a αm m , where α i ∈ Z and 0 ≤ α i < e i whenever i ∈ T . The m-tuple (α 1 , . . . , α m ) is called the coordinate tuple of g and is denoted Coord(g), and the expression a α1 1 . . . a αm m is called the (Mal'cev) normal form of g. We also denote α i = Coord i (g). When we need to make a distinction between integers and their binary notation for algotithmic purposes, we refer to the tuple of binary notations for (α 1 , . . . , α m ) as binary coordinate tuple of g.
To a Mal'cev basis A we associate a presentation of G as follows. For each 1 ≤ i ≤ m, let n i be such that a i ∈ G ni \ G ni+1 . If i ∈ T , then a ei i ∈ G ni+1 , hence a relation (2) a ei i = a µ iℓ ℓ · · · a µim m holds in G for some µ ij ∈ Z and ℓ > i such that a ℓ , . . . , a m ∈ G ni+1 . Let 1 ≤ i < j ≤ m. Since the series (1) is central, relations of the form hold in G for some α ijk , β ijk ∈ Z and l > j such that a ℓ , . . . , a m ∈ G nj +1 . The set of (abstract) symbols {a 1 , . . . , a m } together with relators (2)-(4) present a group G ′ that is isomorphic to G under the natural isomorphism (relator (4) may be omitted when j ∈ T ). Indeed, any presentation on symbols {a 1 , . . . , a m } with relators of the form (2) for any choice of T and relators of the form (3) and (4) for all 1 ≤ i < j ≤ m defines a nilpotent group G ′′ with cyclic central series having terms a i , . . . , a m for i = 1, . . . , m. Such a presentation is called a consistent nilpotent presentation for G ′′ if the order of a i modulo a i+1 , . . . , a m is precisely e i . While presentations of this form need not, in general, be consistent, those derived from a central series of a group G as above must be consistent (if in G ′ the order of a i is e ′ i < e i , then this fact follows from (2)-(4) and hence a relation for a e ′ i i would have been written in (2)). Consistency of the presentation implies that G ′ ≃ G. Proposition 2.1. There is an algorithm that, given a finite presentation of a nilpotent group G, finds a consistent nilpotent presentation of G and an explicit isomorphism. The presentation may be chosen to be the presentation derived from a Mal'cev basis associated with the lower or upper central series of G.
Proof. Prop. 3.2 of [1] proves that a given nilpotent presentation may be checked for consistency, so to produce a consistent nilpotent presentation it suffices to enumerate presentations obtained from the given presentation of G by finite sequences of Tietze transformations until a consistent nilpotent presentation is found (cf. [1] Thm. 3.3).
Further, we may compute both the lower and upper central series from a presentation of G. Indeed, each term Γ i = [G, Γ i−1 ] of the lower central series is precisely the normal closure of the set {[g, γ]} g,γ where g and γ run over generating sets of G and Γ i−1 , respectively, and as such a generating set may be computed by [1] Lem. 2.5. The upper central series is computed in Cor. 5.3 of the same work. From either series we may find a Mal'cev basis and then write down, via exhaustive search, the required relators (2)-(4).
In Proposition 5.1 we employ techniques described in Section 3.1 to give a polynomial-time version of Proposition 2.1.
An essential feature of the coordinate tuples for nilpotent groups is that the coordinates of a product (a α1 1 · · · a αm m )(a β1 1 · · · a βm m ) may be computed as a "nice" (polynomial if T = ∅) function of the integers α 1 , . . . , α m , β 1 , . . . , β m , and the coordinates of a power (a α1 1 · · · a αm m ) l may similarly be computed as a 'nice' function of α 1 , . . . , α m and l. The existence of such polynomial functions for torsion-free nilpotent groups is proved in [10] and [15], and an explicit algorithm to construct them from a nilpotent presentation of G is given in [18].
If any of the factors G i /G i+1 are finite (which must occur when G has torsion), the coordinate functions also involve the extraction of quotients and remainders modulo e i . For each i ∈ T , we define functions r i : Z → {0, 1, . . . , e i − 1} and where t ∈ Z. Let F Q (n) denote the set of all functions f : Z n → Z formed as a finite composition of the functions from the set {·, +, r i , s i | i ∈ T } using constants from Q, where · and + denote multiplication and addition in Q.
We note that the existence of such functions extends to nilpotent groups admitting exponents in a binomial principal ideal domain, as described in Theorem 5.7 of [27].
Computation of the functions p 1 , . . . , p m , q 1 , . . . , q m , in the case when all factors G i /G i+1 are infinite, can be done via the "Deep Thought" algorithm [18]. If some factors are finite, one may introduce the functions r i and t i one factor at a time using a procedure similar to that used to compute normal forms given in §7.2 of [18]. It is worth observing that in this construction the values of the numbers α ijl , β ijl , µ il , and e i are not essential: one may compute functions in which all of these values appear as variables.
For §3 and §4, and the remainder of this section, we fix G to be a finitely presented nilpotent group. Set c to be the nilpotency class of G and fix a Mal'cev basis A = {a 1 , . . . , a m } associated with the lower central series of G, with m the size of this basis. Algorithmic results in these sections do not take G as part of the input and so we may, in light of Proposition 2.1 and Lemma 2.2, assume that the presentation of G is precisely the consistent nilpotent presentation corresponding to A and that the functions p i , q i are known (computed in advance). However, we state algorithmic results without restriction on the presentation of G with the understanding that such algorithms will, in pre-computation, translate to such a presentation if needed. In §5 we provide uniform algorithms, in which G is included in the input.

2.2.
Polynomial bound on the length of normal forms. Suppose w = x 1 x 2 · · · x n is a word over A ± . In order to compute the coordinate tuple of w, one may use the polynomials p i to compute the coordinates of x 1 x 2 , then use this result to find the coordinates of (x 1 x 2 )x 3 and so on. However, the resulting computation is an n-fold composition of the polynomials and thus we may a priori expect a bound of order k n on the magnitude of the coordinates, with k being the maximum degree of the polynomials. This presents an obstacle to logspace computation, as the binary representation of integers that size requires linear space. We show that the coordinates are in fact of order n c , where c is the nilpotency class of G. The following result is, to our knowledge, folklore (our proof is adapted from unpublished lecture notes by C.Druţu and M.Kapovich).

Theorem 2.3. Let G be a nilpotent group with a lower central series
There is a constant κ, depending only on the presentation of G, such that for every word w over A ± , ik with ik ∈ T , we have a relation (7) a e ik = a µt1 t1 a µt2 t2 · · · a µcm c cmc , where t > i. Put E = max{e ik |ik ∈ T } (or E = 1 if T = ∅). Let C 0 ∈ Z be greater than the word length of the right hand sides of all equalities (6), (7). Note that C 0 only depends on the presentation of G.
For any word v over A ± and integer 1 ≤ n ≤ c, denote by |v| n the number of occurrences of letters a 11 , . . . , a 1m1 , . . . , a n1 , . . . , a nmn and their inverses in v. We also formally put |v| n = 0 for n ≤ 0 and |v| n = |v| c for n > c.
Claim. For every 1 ≤ k ≤ c there is a constant C k+1 that depends only on k and the presentation of G such that for every word w over A ± the corresponding group element can be represented in the form We prove this claim by induction on k. We allow k = 0 as the base case, which holds with w 1 = w and C 1 = 1.
Suppose the claim holds for some k − 1 ≥ 0. Denote w (0) k+1 = w k and push an occurrence of a ±1 k1 in this word to the left, using the commutation relations (6). This gives the expression w k1 and a ′ = a ±1 ij , the right-hand side R of (6) satisfies |R| k+ℓ = 0 for all i > ℓ and |R| k+ℓ ≤ C 0 otherwise. Therefore swapping a ±1 k1 with a ±1 ij increases the word length, by at most C 0 , only for i = 1, . . . , ℓ. So Notice that this inequality holds in fact for all ℓ ∈ Z.
We proceed in the same fashion to move left all occurrences of a ±1 k1 , followed by all occurrences of a ±1 k2 and so on. At step j + 1 we represent w ki are collected on the left in at most N ≤ |w k | k ≤ C k |w| k steps, which gives k+1 ∈ Γ k+1 . We immediately see by the induction hypothesis that |γ ki | ≤ |w k | k ≤ C k |w| k , which delivers (A) provided C k+1 is chosen to be at least C k . We also find a bound on |w (N ) k+1 | k+ℓ , for all k + 1 ≤ k + ℓ ≤ c, which will be used to prove (C), by applying (8) repeatedly. Namely, when we apply (8) Before obtaining (C), we must first reduce certain exponents to obtain (B), then repeat the collection process described above. Consider the word a γ k1 k1 · · · a γ km k km k and, for each ki ∈ T , rewrite using (7) and v i consists of s i copies of the right-hand side of (7). Note that For ki / ∈ T , put δ ki = γ ki and v i = 1. Thus the resulting word Repeating the collection procedure for the wordw k , as above, we obtain that k1 · · · a δ km k km k u k+1 , where, using (8) repeatedly as before, Combining this with with (9), we get Thus setting w k+1 = u k+1 w (N ) k+1 and C k+1 = C k+1 + C ′ k+1 delivers (C), completing the inductive step and the proof of the claim.
To prove the theorem it is only left to notice that the claim with k = c suffices, which gives κ = C c+1 .
Remark 2.4. Observe that the torsion part of the above argument (obtaining (B)) can be adjusted to allow group relations ik in place of (7), by processing a k1 , a k2 , . . . , a km k in succession (in that order). Further, note that though we use the lower central series in Theorem 2.3, we only need the property (10) [ Therefore, any central series having this property will suffice, with c being replaced by the length of the series.
In light of the importance of Theorem 2.3 to our work, we will refer to any Mal'cev basis associated with the lower central series of G as a lower central Mal'cev basis. Our algorithmic results usually assume that a lower central Mal'cev basis of G is given, though by Remark 2.4 one may substitute a central series satisfying (10). If one instead uses a polycyclic basis derived from a cyclic central series (called simply a Mal'cev basis in the literature) a similar polynomial bound, albeit of a higher degree, takes place (recall that the functions p i and q i are described in Lemma 2.2, and m is the polycyclic length of G).

Lemma 2.5. Let G be a finitely generated nilpotent group with Mal'cev basis
There are a constants κ ′ and δ depending on p i , q i , and m such that for every word w over A ± , Proof. Assume the lemma holds for all nilpotent groups having a cyclic series of length m − 1, in particular for G 2 = a 2 , . . . , a m . Write w in the form (11) w = w 1 a η1 1 w 2 a η2 1 · · · w r a ηr 1 w r+1 , where each w j is a word (possibly empty) in letters a ±1 2 , . . . , a ±1 m and η j ∈ Z \ {0} for all j. The proof then proceeds via a right-to-left collection process utilizing commutation relations to obtain a word of the form is an element of G 2 . We use Theorem 2.3 over the above statement in subsequent arguments, so we leave the details of the proof to the reader.
We would like to mention that our methods, generally speaking, do not extend to polycyclic groups. Indeed, while every polycyclic group has a set of polycyclic generators, below we show that no polynomial bound for coordinates similar to (5) can be met unless the group is virtually nilpotent.

Proposition 2.6. Let H be a polycyclic group with polycyclic generators
Proof. Without loss of generality, assume that P is monotone. Let B n be the ball of radius n centered at 1 in the Cayley graph of H relative to A. Then for every w ∈ B n , |Coord i (w)| is bounded by P (n), so |B n | ≤ (2P (n) + 1) m , i.e., H has polynomial growth. By a result of Gromov [8], it follows that H is virtually nilpotent.

2.3.
Computation of normal forms and the word problem. Since our algorithms will accept words of A ± as input, but perform subsequent computations using Mal'cev coordinates, a necessary first step is to compute these coordinates. The following statement improves on a result in [6], which proved that UT n (Z) has normal forms computable in logspace.
Theorem 2.7. Let G be a finitely generated nilpotent group with Mal'cev basis A.
There is an algorithm that, given a word w of length L over A ± , outputs the binary coordinate tuple of w in space O(log L) and, simultaneously, time O(L log 2 L).
Proof. Denote w = x 1 x 2 · · · x L . We hold in memory an array γ = (γ 1 , . . . , γ m ), initialized to (0, . . . , 0), which at the end of the algorithm will hold the Mal'cev coordinates of w. First, we use the functions {p i } i to compute the coordinates of the product x 1 x 2 , storing the result in γ. We then compute, again using the {p i } i , the coordinates of the product (x 1 x 2 ) · x 3 , using the saved coordinates of x 1 x 2 . We continue in this way, performing m(L − 1) total evaluations of functions from {p i } i , and obtain the coordinates of w.
Each subword x 1 · · · x j has length bounded by L, so by Theorem 2.3 each of its coordinates may be stored as an O(log L)-bit number and hence γ may be stored in logarithmic space. Each evaluation of a function p i involves addition, multiplication, and division (needed to evaluate the functions r k and s k ) with O(log L)-bit inputs. The time complexity of these operations is (sub)quadratic in the number of bits, hence the overall time complexity is O(L log 2 L). The standard 'schoolbook' arithmetic operations use space linear in the number of bits, hence space O(log L) in this case. Theorem 2.7 of course implies that the word problem in G is decidable in logspace. This was previously known via embedding into UT n (Z), since [19] proved that linear groups have LSPACE word problem. Corollary 2.9. Every finitely generated nilpotent group has word problem decidable in LSPACE.
Note that Theorem 2.7 does not give a solution to the search version of the word problem, that is, the problem of writing a trivial element w as a product of conjugates of relators. We give a polynomial-time solution to this problem in Theorem 4.3.
While the above 'letter-by-letter' application of the functions p i is efficient for the initial conversion of input words into coordinates, subsequent coordinate computations generally involve a product of a constant number of factors, the coordinates each of which are known, hence it is more efficient to apply the polynomials to the coordinates of the factors. Proof. Since k is fixed, this follows immediately from the fact that arithmetic operations are computable in quadratic time and linear space.

2.4.
Compressed-word problems and binary Mal'cev coordinates. Theorem 2.3 implies that there is a constant b, depending on G, such that every coordinate of a word of length L may be expressed as a b log(L)-bit number. Therefore every element g ∈ G which may be, on the one hand, represented by a word of length L, may be more efficiently represented as an m-tuple of b log(L)-bit numbers. In this sense, the specification of a Mal'cev basis provides a natural compression scheme on G.
In formulating algorithmic problems over G it is therefore natural to expect that input group elements are encoded in this scheme, similar to the expectation that elements of Z are encoded as binary numbers rather than in 'unary encoding' as words. On the other hand, straight-line programs provide a general method to formulate algorithmic problems over groups with compressed input, and in the case of nilpotent groups the use of straight-line programs eliminates the need to specify a particular Mal'cev basis.
The two schemes are in fact equivalent for nilpotent groups: a coordinate tuple (α 1 , . . . , α m ) encoded using L bits is easily converted to a straight-line program of size O(L) producing the normal form a α1 1 · · · a αm m , and we show below that conversion is also efficient in the opposite direction. We can now approach compressed-word versions of various algorithmic problems in G by converting straight-line programs to Mal'cev coordinates then applying algorithms which work with coordinates. The first of these is the compressed word problem. A polynomial-time solution to this problem was also observed in [11], via reduction to UT n (Z), and a new result in [17] shows, using the same reduction, that the compressed word problem in any non-trivial finitely generated torsion-free nilpotent group is complete for the logspace counting class C = L.
Corollary 2.12. The compressed word problem in every finitely generated nilpotent group is decidable in (sub)cubic time.
Throughout this paper we describe several algorithms which take as input one or more words over a finitely presented nilpotent group G. Each such algorithm also comes in two 'compressed' versions.
In the 'compressed-word' version, all inputs and outputs are straight-line programs and the size L of the input is the sum of the sizes of all input programs. In the 'binary Mal'cev coordinate' version, G is provided with a fixed Mal'cev basis A and all input and output words are coordinate tuples (relative to A) with each entry written as a binary number. The size L of the input is the total number of bits in the input coordinates.
In all cases, the compressed-word version works by first computing the Mal'cev coordinates of each input straight-line program using Theorem 2.11 and then invoking the binary Mal'cev coordinate version.

Matrix reduction, membership problem, and subgroup presentations
Several algorithmic problems, including the membership problem, may be solved by constructing an integer matrix from coordinate tuples corresponding to the generating set of a subgroup and performing a process similar to Gaussian elimination over Z to reduce the matrix to a unique 'standard form'. This approach was detailed in [35], but without a computational complexity analysis. We review this reduction process and analyze its complexity in §3.1, apply it to solve the membership problem in §3.2, and use it to compute presentations for subgroups in §3.3. It is also essential for computing kernels of homomorphisms and thereby solving the conjugacy problem in §4.

Matrix reduction.
Let h 1 , . . . , h n be elements of G given in normal form by h i = a αi1 1 · · · a αim m , for i = 1, . . . , n, and let H = h 1 , . . . , h n . To the tuple (h 1 , . . . , h n ) we associate the matrix of coordinates and conversely, to any n × m integer matrix, we associate an n-tuple of elements of G, whose Mal'cev coordinates are given as the rows of the matrix, and the subgroup H generated by the tuple. For each i = 1, . . . , n where row i is non-zero, let π i be the column of the first non-zero entry ('pivot') in row i. The sequence (h 1 , . . . , h n ) is said to be in standard form if the matrix of coordinates A is in row-echelon form with no zero rows and its pivot columns are maximally reduced, i.e. if A satisfies the following properties: (i) all rows of A are non-zero (i.e. no h i is trivial), (ii) π 1 < π 2 < . . . < π s (where s is the number of pivots), (iii) α iπi > 0, for all i = 1, . . . , n, (iv) 0 ≤ α kπi < α iπi , for all 1 ≤ k < i ≤ s, (v) if π i ∈ T , then α iπi divides e πi , for i = 1, . . . , s.
The sequence is called full if in addition (vi) H ∩ a i , a i+1 , . . . , a m is generated by {h j | π j ≥ i}, for all 1 ≤ i ≤ m. In (vi), note that {h j | π j ≥ i} consists of those elements having 0 in their first i − 1 coordinates. Let us remark here that (vi) holds for a given i if and only if the following two properties hold.
, and h eπ j /αjπ j j have coordinates 1 through π j equal to 0, so the forward implication is clear. Conversely, given an element of H ∩ a i , a i+1 , . . . , a m , written as a product of generators of H, one may first reduce exponents of h 1 using (vi.ii) (if π 1 ∈ T ), and then, observing that the exponent sum of h 1 must be 0, eliminate all occurrences of h ±1 1 in conjugate pairs using (vi.i). Repeating with h 2 , h 3 , . . . , h k where π k < i ≤ π k+1 , we obtain a word in generators {h j | π j ≥ i}.
The importance of full sequences is described in the lemma below, which can be found in [35], Propositions 9.5.2 and 9.5.3. i+1 · · · a αm m . Clearly, all three of these operations preserve H. By combining these operations, we may also (4) replace h i with h −1 i , and (5) append to the tuple an arbitrary product h i1 · · · h i k of elements in the tuple. We also note that these operations, with exception of (3 ′ ), preserve the property that all rows are Mal'cev coordinate tuples. Further, operation (3 ′ ) is applied only in Step 3 (see below on p. 19), by completion of which that property is regained.
Using the row operations defined above, we show how to reduce any coordinate matrix to its unique full form, thus producing the unique full generating sequence for the corresponding subgroup H. While it is not difficult to see that such reduction is possible, the details of the procedure are essential for our complexity estimates. We make use of the following algorithmic fact regarding greatest common divisors.

Lemma 3.2.
There is an algorithm that, given integers a 1 , . . . , a n as binary numbers, computes in time O(L 3 ) an expression x 1 a 1 + . . . + x n a n = d = gcd(a 1 , . . . , a n ) with |x i | ≤ 1 2 max{|a 1 |, . . . , |a n |}, where L is the total number of bits in the input. If n is fixed, the algorithm may be run in space O(L).
Proof. We compute the expression using the binary tree method described in [25] Thm. 9. This computation proceeds in two phases. In the first or 'bottom-top' phase, we place the integers a 1 , . . . , a n as the leaves of a binary tree, and we compute GCDs of the pairs (a 1 , a 2 ), (a 3 , a 4 ), . . . , (a n−1 , a n ), recording each GCD as its expression as a linear combination of a i and a i+1 in the parent node. We then continue up the tree computing the GCDs of the pairs of parents in the same fashion, obtaining d at the root. This involves invoking the extended Euclidean algorithm (or a more efficient algorithm) at most n − 1 times, each time with inputs bounded by M = max{|a 1 |, . . . , |a n |}. Each invocation runs in time O(log 2 M ), hence the entire phase runs in time O(L 3 ).
In the second or 'top-bottom' phase, we compute the coefficients x 1 , . . . , x n (satisfying the given bound) from the top of the tree downward, using 'small' coefficients at each step. Each computation uses a fixed number of arithmetic operations, hence this phase also runs in time O(L 3 ).
For the space complexity, simply observe that when n is fixed the tree has constant size and we use logspace arithmetic operations, which must run in time polynomial in log L.
Let A 0 be a matrix of coordinates, as in (13) above. We produce matrices A 1 , . . . , A s , with s the number of pivots in the full form of A 0 , such that for every k = 1, . . . , s the first π k columns of A k form a matrix satisfying (ii)-(v), the condition (vi) is satisfied for all i < π k+1 , and A s is the full form of A 0 . Here we formally denote π s+1 = m + 1.
Set π 0 = 0 and assume that A k−1 has been constructed for some k ≥ 1. In the steps below we construct A k . We let n and m denote the number of rows and columns, respectively, of A k−1 . At all times during the computation, h i denotes the group element corresponding to row i of A k and α ij denotes the (i, j)-entry of A k , which is Coord j (h i ). These may change after every operation.
Step 1: Locate the column π k of the next pivot, which is the minimum integer π k−1 < π k ≤ m such that α iπ k = 0 for at least one k ≤ i ≤ n. If no such integer exists, then k − 1 = s and A s is already constructed. Otherwise, set A k to be a copy of A k−1 and denote π = π k . Compute a linear expression of d = gcd(α kπ , . . . , α nπ ), d = l k α kπ + · · · + l n α nπ .
Using (1), swap row k with row n + 1. At this point, properties (ii)-(iv) hold on the first k columns of A k .
Step 4: Identify the next pivot π k+1 , setting π k+1 = m + 1 if π k is the last pivot. We now ensure condition (vi) for i < π k+1 . Observe that Steps 1-3 preserve h j | π j ≥ i for all i < π k . Hence (vi) holds in A k for i < π k since it holds in A k−1 for the same range. Now consider i in the range π k ≤ i < π k+1 . It suffices to prove (vi.i) for all j > k and (vi.ii) for π k only. To obtain (vi.i), we notice that h −1 Further, note that the subgroup generated by the set where h k appears m − π k times in the last commutator, is closed under commutation with h k since if h k appears more than m − π k times then the commutator is trivial. An inductive argument shows that the subgroup S j coincides with h h ℓ k j | 0 ≤ ℓ ≤ m − π k . Similar observations can be made for conjugation by h −1 k . Therefore, appending via operation (5) rows Coord(h h ℓ k j ) for all 1 ≤ |ℓ| ≤ m − π k and all k < j ≤ n + 3 delivers (vi.i) for all j > k. Note that (vi.i) remains true for i < π k .
To obtain (vi.ii), in the case π k ∈ T , we add row Coord(h e k /α kπ k k ). Note that this element commutes with h k and therefore (vi.i) is preserved.
Step 5: Using (3), eliminate all zero rows. The matrix A k is now constructed. In applying row operation (2) or (5), the magnitude of the largest entry in the matrix may increase. It is essential to observe that during the matrix reduction algorithm the growth of this value is bounded by a polynomial of fixed degree (depending on G). Lemma 3.3. Let g 1 , . . . , g t ∈ G and let R be the full form of the associated matrix of coordinates. Then every entry α ij of R is bounded by where L = |g 1 |+· · ·+|g t | is the total length of the given elements, and K = m(8c 2 ) m and C are constants depending on G.
Proof. Denote by A 0 the t × m matrix of coordinates associated with (g 1 , . . . , g t ).
Following the matrix reduction algorithm described above, we will bound the entries of A k in terms of the entries of A k−1 and by induction obtain a bound of the entries of R = A s in terms of the entries of A 0 .
For a given A k−1 , denote by n the number of rows of A k−1 and by N the magnitude of the largest entry, i.e., Observe that for each 1 ≤ i ≤ n, the element h i corresponding to row i of A k−1 has length |h i | = |a αi1 1 · · · a αim m | ≤ mN . Now in Step 1 we append the row h n+1 , which satisfies Denote by α ′ ij the (i, j)-entry at the end of Step 2. Since this number is For i = k, the tighter bound (14) holds.
Proceeding to Step 2, denote E = max{e i | i ∈ T }. The new rows h n+2 and h n+3 satisfy Let α ′′ ij denote the (i, j)-entry of A k−1 at the end of Step 4, and recall that Step 4 only appends rows to the bottom of the matrix. For row n + 3 (row k before swapping) we have, for all j, In row n + 2 we have Finally, for rows 1 through k−1 notice that each of h 1 , . . . , h k−1 has length bounded by m times the bound (15), hence Note that at the conclusion of Step 3, bound (19) applies to rows 1 through k − 1, bound (16) applies to the element h k (formerly h n+3 ) in row k, and the maximum of (17) and (18) applies to all rows after k.

In
Step 4 we append all rows of the type h h l k j for 1 ≤ |l| ≤ m − π k and k < j ≤ n + 3. The entries of such a row are bounded by where C ′ = (4κmE) c 3 +2c 2 +3c+1 . If π k ∈ T , we also append the row h e k /α kπ k k , and so the entries in the final row r of the matrix satisfy Thus the magnitude of each entry of A k is bounded by C ′ · (nN ) 4c 2 , where n is the number of rows of A k−1 and N bounds the magnitude of the entries of A k−1 .
Next, notice that Steps 1-3 add three rows, and Step 4 adds less than 2m(n+3) rows. We may bound the number of rows added by 10m · n. Consequently, the number of rows of A k is bounded by (10m) k · t.
A simple inductive argument now shows that every entry of R is bounded by where N 0 is the maximum of the absolute value of entries in A 0 and C ′′ is a constant depending on m, c, E, and κ. Now Moreover, t ≤ L and s ≤ m. Therefore the entries of R are bounded by We simplify the exponent of L by using the bound K = m(8c 2 ) m . Lemma 3.3 allows us to produce a logspace version of the matrix reduction algorithm. Note that the matrix reduction algorithm, as presented, may use more than logarithmic space since the number of rows t of the initial matrix A 0 may be of the same order as the total input size. Proof. Algorithm description. Since the coordinate matrix for h 1 , . . . , h n cannot be stored in logarithmic space, we adopt a piecewise approach, appending one row at a time and reducing.
Form the coordinate matrix B 0 of the first m elements, h 1 , . . . , h m and compute its full form B 1 . Append to B 1 a row corresponding to the coordinates of h m+1 and compute the full form B 2 of this matrix. Append h m+2 to B 2 and continue in this way until there are no more rows to append. Since the subgroup generated by the rows is preserved under row operations, the last matrix thus obtained, B n−m , is the full form of the matrix of coordinates of h 1 , . . . , h n .
Space and time complexity. We first show that at every step the matrix we work with can be stored in logarithmic space. Since each intermediate matrix B l is in full form, Lemma 3.1 ensures that B l has at most m rows. Hence the number of rows appended the reduction of B l−1 to B l is, as seen in the proof of Lemma 3.3, bounded by 10m 2 . The size of the working matrix is therefore never more than 10m 2 × m (constant with respect to the input).
As for the size of the entries, Theorem 2.3 shows that each entry α ij of the matrix B 0 satisfies |α ij | ≤ κ|h i | c ≤ κL c .
Each entry can be encoded using O(log L) bits and therefore B 0 can be stored in logarithmic space.
Since the matrix B l , 1 ≤ l ≤ n − m, is precisely the (unique) full-form matrix for the sequence h 1 , . . . , h m+l , Lemma 3.3 ensures that each entry of B l is bounded in magnitude by C · L K . The proof of Lemma 3.3 shows that the bound given there holds during all steps of the reduction algorithm, hence during the reduction of B l−1 to B l no entry can be greater in magnitude than C(m 2 CL K ) K . Consequently, all intermediate matrices can be stored in logarithmic space.
It remains to show that the operations that we use can also be executed in logarithmic Remark 3.5. The factor of L in the time complexity arises most heavily from the fact that the number n of input elements can, in general, only be bounded by L. If n is regarded as a fixed number, the most time-consuming computation is computing the Mal'cev coordinates and the overall time complexity is reduced to O(L log 2 L). This remark also applies to Theorems 3.8, 3.11, and 4.1.
Remark 3.6. The output of the algorithm uses binary numbers to encode the exponents which are the Mal'cev coordinates of g i . If one is interested in the expression of g i as words in generators of G, the time complexity grows according to the time it takes to print out the corresponding words, similarly to Remark 2.8(b) after Theorem 2.7. Given the polynomial bound on the total length of g i provided in the statement, the overall algorithm still runs in polynomial time. This remark also applies to all the search problems considered below, that is to Theorems 3.8, 3.11, 4.1, 4.3, 4.5, and 4.7.
In order to solve the compressed-word version of the membership (and other) problems, we require a compressed version of matrix reduction that runs in polynomial time. Proof. For the compressed-word version, let A 1 , . . . , A n be the input straight-line programs encoding h 1 , . . . , h n . We first compute, by Theorem 2.11, the coordinate vectors Coord(eval(A i )) for i = 1, . . . , n. This operation occurs in time O(nL 3 ). Since |eval(A i )| ≤ 2 L , we obtain from Theorem 2.3 that each entry of B 0 is bounded by κ · (2 L ) c and hence is encoded using O(L), rather than O(log L), bits. Therefore the reduction process described in Theorem 3.4 runs in time O(nL 3 ). Note that one may instead include all n rows in the initial matrix, as in Steps 1-5, instead of the piecewise approach of Theorem 3.4, since logspace is not an issue here.
Since |eval(A i )| ≤ 2 L , it follows from Lemma 3.3 that each coordinate in the full-form sequence for H is bounded in magnitude by a polynomial function of 2 L . Then each element of the sequence may be expressed as a compressed word of size polynomial in L.
The binary Mal'cev coordinate version simply omits the initial computation of coordinates.

Membership problem.
We can now apply the matrix reduction algorithm to solve the membership problem in logspace, and its compressed-word version in quartic time. We also solve the membership search problem using only logarithmic space.
Theorem 3.8. Let G be a finitely generated nilpotent group. There is an algorithm that, given elements h 1 , . . . , h n ∈ G and h ∈ G, decides whether or not h is an element of the subgroup H = h 1 , . . . , h n . The algorithm runs in space logarithmic in L = |h| + n i=1 |h i | and time O(L log 3 L). Moreover, the algorithm additionally returns the following: • the binary coordinates tuples of g 1 , . . . , g s ∈ G s. t. (g 1 , . . . , g s ) is a full-form sequence for the subgroup H (relative to a lower central Mal'cev basis), and • if h ∈ H, then also the unique binary tuple (γ 1 , . . . , γ s ) s.t. h = g γ1 1 · · · g γs s . Furthermore, the word length of g γ1 1 · · · g γs s is bounded by a degree 2m(8c 3 ) m polynomial function of L.
Proof. Algorithm. Compute the full form B of the coordinate matrix corresponding to H and the full-form sequence (g 1 , . . . , g s ). As before, denote by α ij the (i, j)entry of B and by π 1 , . . . , π s its pivots.
By Lemma 3.1, any element of H can be written as g γ1 1 · · · g γs s . We show how to find these exponents. Denote h (1) = h and Coord(h (j) ) = (β If j < s, continue to j + 1. If j = s, then h = g γ1 1 · · · g γs s ∈ H if h (s+1) = 1 and h / ∈ H otherwise. Complexity and length bound. We first prove, by induction on s, that the length of the output g γ1 1 · · · g γs s is bounded by a degree | + |h| is also bounded by a degree δ(s−1) polynomial function, so by Theorem 2.3 |β (s) πs |, and therefore |γ s |, is bounded by a polynomial function of degree c · δ(s − 1). It follows that |g γs s | is bounded by a degree c · δ(s − 1) + m(8c 2 ) m = δ(s) polynomial function of L, and hence g γ1 1 · g γs s obeys the same degree bound. The bound stated in the theorem may be obtained using s ≤ m.
Regarding complexity, the initial computation of (g 1 , . . . , g s ) is performed within the bounds by Lemma 3.4. Since the magnitude of each γ j is bounded, for all j, by a polynomial function of L, the coordinates may be computed and stored using logarithmic space and in time O(log 2 L) by Lemma 2.10. The complexity bound then follows from the fact that the recursion has constant depth s.
Though the expression of h in terms of the full-form generators g 1 , . . . , g s of H provides a standardized representation, one may also wish to express h in terms of the given generators. Corollary 3.9. Let G be a finitely generated nilpotent group. There is an algorithm that, given elements h 1 , . . . , h n ∈ G and h ∈ h 1 , . . . , h n , computes an expression , . . . , n} and ǫ j = ±1. The algorithm runs in time polynomial in L = |h|+ n i=1 |h i | and the output has length bounded by a polynomial function of L.
Proof. We modify the matrix reduction algorithm from Section 3.1 so as to be able to express each g i as a product of h 1 , . . . , h n . To this end, along with the matrix A k , we store at every step an array C k which contains the elements corresponding to the rows of the matrix A k , each written as a product of h 1 , . . . , h n . Thus, C s will be an array containing in each entry, i, a product of h 1 , . . . , h n which is equal to g i .
To obtain the array C k from the information in step k − 1, we perform on C k−1 the corresponding row operation that was performed on A k−1 , except we record the result not in terms of Mal'cev coordinates, but directly in terms of the words in the array C k−1 .
For 1 ≤ k ≤ s, denote by L k the length (as a word over the alphabet {h ±1 1 , . . . , h ±1 n }) of the largest entry of C k . Note that at each step, every row has at most two operations performed on it that may increase its length (one application of (2) in Step 2 and one in Step 3), or is newly-created. Using the fact that all exponents involved are bounded in magnitude by C · L K , where C and K are the constants from Lemma 3.3, it easily follows that there is a poylnomial function f (L) such that L k ≤ f (L)L k−1 .
Since L 0 = 1 and k ≤ s, it follows that L s is bounded by a polynomial function of L and therefore the computation of C s is perfomed in polynomial time.
Finally, we can simply substitute the expression of g i (for 1 ≤ i ≤ s) in terms of h 1 , . . . , h n into the expression h = g γ1 1 · · · g γs s to obtain an expression h = h ±1 i1 · · · h ±1 it with i 1 , . . . , i t ∈ {1, . . . , n}. Since the length (over the alphabet {g ± 1 , . . . , g ± s }) of the expression g γ1 1 · · · g γs s is bounded by a polynomial function of L, producing the expression h = h ±1 i1 · · · h ±1 it occurs in polynomial time. Observe that this method will not yield a logspace algorithm, since the array C s is too large to be stored in memory.
The algorithm used in Theorem 3.8 may be combined with the compressed version of matrix reduction (Lemma 3.7) to give a polynomial-time solution to the compressed membership problem. 3.3. Subgroup presentations. We now apply matrix reduction to show that finitely generated nilpotent groups are logspace effectively coherent: given a finitely generated subgroup H, we can in logspace and quasilinear time compute a consistent nilpotent presentation for H. By the size of a presentation we mean the number of generators plus the sum of the lengths of the relators. Proof. Algorithm. Begin by computing the full sequence (g 1 , . . . , g s ) for H using Lemma 3.4. Let H i = g i , g i+1 , . . . , g s . We claim that is a cyclic central series for H. From property (vi) we have Since a πi , . . . , a m is a normal subgroup of G, it follows that the above is a normal series, and since H i /H i+1 = g i H i+1 the series is cyclic. For i < j, [g i , g j ] ∈ a πj +1 , . . . , a m ∩ H ≤ H j+1 hence the series is central. We conclude that (g 1 , . . . , g s ) is a Mal'cev basis for H, so it suffices to compute the relators (2)-(4) in order to give a consistent nilpotent presentation of H. The order e ′ i of g i modulo H i+1 is simply e i /Coord πi (g i ). We establish each relation (2) by invoking Theorem 3.8 with input g e ′ i i and H i+1 = g i+1 , . . . , g s . Since g e ′ i i ∈ H i+1 and (g i+1 , . . . , g s ) is the unique full sequence for H i+1 , the membership algorithm returns the expression on the right side of (2). Relations (3) and (4) are established similarly.
Complexity and size of presentation. Computation of the full sequence and invoking Theorem 3.8 occurs within the stated space and time bounds. Regarding the size of the presentation, the number of generators is s ≤ m, the number of relations is bounded by s + 2 s 2 , and each relation has length obeying the degree 2m(8c 3 ) m bound of Theorem 3.8.
Remark 3.12. By Remark 2.4, the Mal'cev basis for H obtained in Theorem 3.11 may be used in Theorem 2.3. Indeed, one may group the Mal'cev generators g 1 , . . . , g s into the appropriate terms of the lower central series of G, i.e. set . . , g s is an associated Mal'cev basis.
The compressed-word version of Theorem 3.11, running in polynomial time, follows immediately. However, the relators of the presentation are provided as straight-line programs. This is unconventional, but we may convert to an 'uncompressed' presentation, of polynomial size, using the following construction.
Consider any presentation P of a group H in which each relator R is the output of a straight-line program A R . We apply the following construction to P. Add the set of non-terminals A of all A R to the generators of P. For each production rule A → BC, add the relation A = BC to the relations of P; for each production A → x add the relation A = x; for A → ǫ add the relation A = 1. Replace the original relator eval(A R ) by the root non-terminal of A R and denote the resulting presentation P ′ .
It is clear that the sequence of Tietze transformations which at each step removes the greatest non-terminal and its production rule converts P ′ back to P. Thus P and P ′ present isomorphic groups. As the outputs eval(A R ) are, in many cases, exponentially longer than the size of the programs A R , this construction significantly reduces the size of the presentation. We can also use this construction to remove the binary numbers from the presentation found in Theorem 3.11 and at the same time produce a smaller presentation. However, the presentation will no longer fit the definition of a nilpotent presentation due to the presence of extra relators used for compressing the exponents. Proof. The number of generators and relators is bounded by a constant, as observed above. Each power a β appearing in a relator is compressed using a straight-line program of size O(log β). Since each exponent β is bounded by a polynomial function of L, the total size of the straight-line programs, and thus of the presentation, is logarithmic in L.

Homomorphisms and the conjugacy problem
Using matrix reduction, [35] showed how to compute the kernel of a homomorphism and compute a preimage for a given element under a homomorphism. We prove in §4.1 that these algorithms may be run in logarithmic space and compressedword versions in polynomial time. In §4.2 we apply these algorithms to solve the conjugacy problem. 4.1. Kernels. For fixed nilpotent groups G and H, we may specify a homomorphism φ from a subgroup K ≤ G to H via a generating set (g 1 , . . . , g n ) of K and a list of elements h 1 , . . . , h n where φ(g i ) = h i , i = 1, . . . , n. For such a homomorphism, we consider the problem of finding a generating set for its kernel, and given h ∈ φ(K) finding g ∈ G such that φ(g) = h. Both problems are solved using matrix reduction in the group H × G. There is an algorithm that, given • a subgroup K = g 1 , . . . , g n ≤ G, • a list of elements h 1 , . . . , h n ∈ H, such that the mapping g i → h i , 1 ≤ i ≤ n, extends to a homomorphism φ : K → H, • optionally, an element h ∈ H guaranteed to be in the image of φ, computes binary coordinates tuples (relative to the Mal'cev basis A) for (i) a generating set X for the kernel of φ, and (ii) an element g ∈ G such that φ(g) = h.
extends to a homomorphism. Instead, we can check if it is the case within the same time and space bounds, and if not, output "Not a homomorphism" and a word in r = g i1 · · · g is representing 1 in G s.t. h i1 · · · h is does not represent 1 in H (like in Theorem 3.11, binary numbers are used to encode exponents appearing in r).
We can apply Theorem 4.1 to solve the search version of the word problem in logspace and quasilinear time. Proof. Let G = X|R . Denote by F (X) the free nilpotent group on X of class c, by N the normal closure of R in F (X), and by φ the canonical epimorphism F (X) → G. Using Theorem 4.1, compute the full-form sequence Y = (y 1 , . . . , y s ) for N = ker φ. By exhaustive search, write each y i as a product of conjugates of elements of R. Note that this step is a precomputation.
Since w represents the trivial element, w is in N , so we run the algorithm from Theorem 3.8 in order to express w in the form w = y γ1 1 · · · y γs s . Then substitute the expression of each y i as a product of conjugates of relators of G.
The space complexity, time complexity, and length bound are as given in Theorem 3.8, noting that N is fixed and hence Remark 3.5 applies giving O(L log 2 L) rather than O(L log 3 L).
In order to solve the compressed conjugacy problem, we need a compressed version of Theorem 4.1, in which all input and output words are encoded as straightline programs. We follow the same algorithmic steps, using Lemma 3.7 to compute W in Mal'cev coordinate form and Theorem 3.10 to compute β 1 , . . . , β r .

4.2.
Conjugacy problem and centralizers. The decidability of the conjugacy problem in finitely generated nilpotent groups has been known since [33] and [7] proved that every polycyclic-by-finite group is conjugately separable: if two elements are not conjugate, there exists a finite quotient in which they are not conjugate. While this fact leads to an enumerative solution to the conjugacy problem, a much more practical approach, using matrix reduction and homomorphisms, was given in [35].
The computational complexity of this algorithm, however, was not analyzed. We show here that it may be run using logarithmic space, and that the compressedword version runs in polynomial time. A necessary step in the solution is the computation of centralizers, which is achieved by induction on the nilpotency class c of G.
Theorem 4.5. Let G be a finitely generated nilpotent group. There is an algorithm that, given g ∈ G, computes a generating set X (in the form of the corresponding binary coordinates tuples) for the centralizer of g in G. The algorithm runs in space logarithmic in L = |g| and time O(L log 2 L), X contains at most m elements, and there is a degree (16m(c + 1) 2 ) 3(c+1)m polynomial function of L that bounds the length of each element of X.
Proof. Let G = Γ 0 ≥ Γ 1 ≥ . . . ≥ Γ c+1 = 1 be the lower central series of G (or another series satisfying (10)). We proceed by induction on c. If c = 1, then G is abelian and C(g) = G so we return a 11 , a 12 , . . . , a 1m1 . Assume that the theorem holds for finitely presented nilpotent groups of class c − 1, in particular for G/Γ c . We use the series {Γ i /Γ c } c i=0 for G/Γ c . Compute a generating set K = {k 1 Γ c , . . . , k m−mc Γ c } for the centralizer of gΓ c in G/Γ c . Let J = k 1 , . . . , k m−mc , a c1 , a c2 , . . . , a cmc , which is the preimage of K under the homomorphism G → G/Γ c . Define f : J → G by Since u ∈ J, u commutes with g modulo Γ c , hence [g, u] ∈ Γ c and so Im(f ) ⊂ Γ c .
The centralizer of g is precisely the kernel of f : J → Γ c , since if h commutes with g, then hΓ c ∈ K so h ∈ J. We compute a generating set using Theorem 4.1.
Complexity and length bound. We proceed to prove the length bound by induction on c. For c = 1, the algorithm returns a single symbol. In the inductive case, the algorithm is invoked with input gΓ c , which has size L. Each returned generator k i has length bounded by some number κ which is a polynomial function of L of degree (16mc 2 ) 3cm . Since for each i = 1, . . . , m − m c , [g, k i ] has length at most 4κ, each input-output pair (k i , [g, k i ]) or (a cj , [g, a cj ]) has length at most 5κ hence the total input to the kernel algorithm of Theorem 4.1 has length bounded by 5mκ. The length of the Mal'cev basis of Γ c is m c ≤ m, and its nilpotency class is 1, so we use 2m and c + 1 in place of m and c in the degree bound in Theorem 4.1. Hence the length of each output generator has length bounded by a polynomial function of L of degree (16mc 2 ) 3cm · 2m(8(c + 1) 2 ) 2m < (16m(c + 1) 2 ) 3(c+1)m , as required.
The logarithmic space bound follows from the fact that in each recursive call, the number c of which is constant, the total size of the input is bounded by a polynomial function of L and the kernel algorithm runs in logarithmic space. The time complexity of O(L log 2 L) arises entirely from the computation of the Mal'cev coordinates of gΓ c . Indeed, the total bit-size of the coordinate tuple of g is logarithmic in L and each invocation of the kernel algorithm is made with at most m elements of bit-size logarithmic in a polynomial function of L, hence logarithmic in L, so each of the c recursive calls terminates in time O(log 3 L) by Theorem 4.4.
We also require a compressed version of  We may now solve the conjugacy and conjugacy search problems in logspace, again by induction on the nilpotency class of G.
Theorem 4.7. Let G be a finitely presented nilpotent group. There is an algorithm that, given g, h ∈ G, either (i) produces binary coordinates tuple for u ∈ G such that g = u −1 hu, or (ii) determines that no such element u exists. The algorithm runs in space logarithmic in L = |g| + |h| and time O(L log 2 L), and the word length of u is bounded by a degree 2 m (6mc 2 ) m 2 polynomial function of L.
Proof. Algorithm. We proceed by induction on c. If c = 1, then G is abelian and g is conjugate to h if and only if g = h. If so, we return u = 1. Now assume c > 1, and that the theorem holds for any nilpotent group of class c − 1, in particular for G/Γ c . Apply the algorithm to gΓ c and hΓ c , using the series {Γ i /Γ c } c i=0 for G/Γ c . If these elements are not conjugate, then g and h are not conjugate and we return 'No'. Otherwise, we obtain vΓ c ∈ G/Γ c . such that Let φ : G → G/Γ c be the canonical homomorphism, J = φ −1 (C(gΓ c )), and define f : J → Γ c by f (x) = [g, x]. As in the proof of Theorem 4.5, the image of f is indeed in Γ c and f is a homomorphism. We claim that g and h are conjugate if and only if g −1 h v ∈ f (J). Indeed, if there exists w ∈ G such that g = h vw , then hence w ∈ J, so w −1 ∈ J as well. Then g −1 h v = [g, w −1 ] ∈ f (J), as required. The converse is immediate. So it suffices to express, if possible, g −1 h v as [g, w] with w ∈ J, in which case the conjugator is u = vw −1 .
Complexity and length of u. We first prove the length bound by induction on c. For c = 1, we have u = 1. In the inductive case, each w i has length bounded by a degree (16mc 2 ) 3cm polynomial function of L and v has length bounded by a degree (16mc 3 ) m polynomial function of L. Take δ = (16mc 3 ) 3cm , which bounds both of these degrees. Then the input to Theorem 4.1, which consists of the pairs (w i , [g, w i ]) for i = 1, . . . , m − m c , the pairs (a cj , [g, a cj ]) for j = 1, . . . , m c , and the element g −1 h v , also has length bounded by a degree δ polynomial function of L. Hence w has length bounded by a polynomial function of degree (16mc 3 ) 3cm · 2m(8(c + 1) 3 ) m < (16m(c + 1) 3 ) 3(c+1)m .
Since this is greater than the degree bound for v, the output u = vw −1 satisfies this degree bound.
Logarithmic space complexity follows immediately from the fact that the conjugator length only grows by a polynomial function of L and the depth of the recursion is constant. The time complexity arises entirely from the computation of Mal'cev coordinates, in Theorem 4.5 and of g −1 h v . Indeed, Theorems 3.10 are each invoked with a constant number of inputs, each having bit-size O(log L), and therefore their time complexity is O(log 3 L).
We solve the compressed version of the conjugacy problem in the same way, using the compressed version of the centralizer algorithm. Our solution to the conjugacy probelm in nilpotent groups allows to take advantage of results in [4], where Bumagin showed that a group G hyperbolic relative to finitely generated subgroups P 1 , . . . , P k has polynomial-time solvable conjugacy (search) problem whenever the parabolic subgroups P 1 , . . . , P k have polynomialtime solvable conjgacy (search) problem. Together with Theorem 4.7 this immediately gives the following result. Theorem 4.9. Let G be a finitely generated group hyperbolic relative to finitely generated nilpotent subgroups P 1 , . . . , P k . Then the word problem, the conjugacy problem, and the conjugacy search problem in G can be solved in polynomial time. Moreover, the time complexity of the word and conjugacy problems is O(L 3 log L), where L is the length of input.
Proof. Note that [4,Theorem 1.5] allows to obtain specific estimates on the time complexity of the above algorithms in terms of the complexity of word and conjugacy (search) problems in P 1 , . . . , P k . In a given nilpotent group, on an input of length L, the time complexity of word problem is O(L) by [13], and that of a conjugacy problem is O(L log 2 L) by Theorem 4.7. By [4, Theorem 1.5], we obtain that the time complexity of conjugacy problem in G is bounded by where T (L) is as above, and C s (L) is a bound on the time complexity of conjugacy search problem in all parabolic subgroups P i . In our case, that gives a polynomial of a higher degree, according to Remark 3.6.

Presentation-uniform algorithms
The algorithms presented in the previous sections do not include the nilpotent group G as a part of the input. We now consider problems which do take G as a part of the input. Let N c be the class of nilpotent groups of nilpotency class at most c. We consider groups in N c presented using at most a fixed number, r, of generators. In the algorithms in this section, the integers c and r are constants. First, we use Theorem 3.4 to find consistent nilpotent presentations for such groups.
Proposition 5.1. Let c and r be fixed integers. There is an algorithm that, given a finite presentation with r generators of a group G in N c , produces a consistent nilpotent presentation of G and an explicit isomorphism, in space logarithmic in the size L of the given presentation. Further, the size of the presentation is bounded by a polynomial function of L and if binary numbers are used in the output relators then the algorithm runs in time O(L log 3 L).
Proof. Let G be presented as G = X | R . Let F = F (X) be the free nilpotent group of class c on generators X. As a precomputation, produce a consistent nilpotent presentation Y | S for F . One may do this in such a way that X ⊂ Y and elements of Y \ X are iterated commutators (so-called 'basic commutators') of elements of X. Consider the natural surjection φ : F → G and let N = ker(φ), which is the normal closure of R in F . Denoting R = {r 1 , . . . , r k }, N is generated by iterated commutators [. . . [[r i , x 1 ], x 2 ], . . . , x j ], where i = 1, . . . , k, j ≤ c, and x 1 , . . . , x j ∈ X ∪ X −1 . The total length of these generators is linear in L since c and r are constant. We now produce this generating set and apply Theorem 3.4 in F with this set, producing the full-form sequence T for N . Now G ≃ Y | S ∪ T , and we claim that this is a consistent nilpotent presentation. Since Y | S is a nilpotent presentation and the elements of T add relators of the form (2), the presentation is nilpotent. To prove that it is consistent, suppose some y i ∈ Y has order α i modulo y i+1 , . . . , y m in Y | S ∪ T . Since the order is infinite in F , there must be element of the form y αi i y αi+1 i+1 · · · y αm m in N . But then, by Lemma 3.1, T must contain an element y Hence α i cannot be smaller than α ′ i and so the presentation is consistent. The space and time complexity, and the polynomial bound on the size of the presentation, follow immediately from Theorem 3.4 since c is fixed and m depends only on c and r.
If G is restricted to the class N c and presented with a fixed number r of generators, the above result can be employed to produce presentation-uniform versions of our algorithms for problems (I)-(VI) (see list on p. 3) that run in logarithmic space and quasi-linear time.
Theorem 5.2. Let Π denote any of the problems (I)-(VI). For all c, r ∈ N, there is an algorithm that, given a finite presentation X|R with |X| ≤ r of a group in N c and input of Π as words over X, solves Π in X|R on that input in logarithmic space and quasi-linear time. In the case of (III), the second group may be specified in the input by a presentation but must also be in N c and use r generators.
Proof. Let L denote the total input size. By Proposition 5.1, we can produce a consistent nilpotent presentation for G, of size polynomial in L, in logarithmic space and time O(L log 3 L). The number of generators m of this presentation depends only on c and r, as it is equal to the number of generators of the precomputed nilpotent presentation of the free nilpotent group F of class c.
We compute, in advance, the functions p i and q i for any nilpotent presentation on m generators with the exponents α ijl , β ijl , µ il , e i appearing as variables (see the discussion following Lemma 2.2). Substituting the correct values for these exponents (obtained from the nilpotent presentation of G) we obtain the functions p i and q i for the specific group G. Note that the magnitude of all the numbers α ijl , β ijl , µ il , e i is bounded by a polynomial function of L, hence they may be encoded as O(log L)-bit numbers.
We note that Theorem 2.3 is satisfied for the obtained presentation, by Remark 2.4. The constant κ depends on the presentation of G, but may be seen from the proof of Theorem 2.3 to be bounded by a polynomial function of L of degree depending on c and r. Hence the magnitude of each coordinate of a word w is bounded by a polynomial function of L of constant degree. One may substitute this bound in subsequent arguments in place of κ|w| i without affecting the logspace or quasi-linear time nature of the computations. In Lemma 3.3, the constants C and K will be greater, but remain bounded by a constant depending on c and r.
Specifically, the algorithms of Theorems 2.7, 3.4, 3.8, 3.11, 4.1, 4.5, 4.7 as well as Corollaries 3.9 and 3.14 run in logspace and time O(L log 3 L) when G (from class N c with r generators) is included in the input. The length bounds given in these results do not hold as stated, but do hold with polynomials of some higher (but still constant for fixed c and r) degree.