On the termination problem for counter machines with incrementing errors

. In contrast to their reliable and lossy-error counterparts whose termination problems are either undecidable or non-primitive recursive, the termination problem for counter machines with incrementing errors is shown to be PSpace -hard but remains solvable in ExpSpace . This is a notable decrease in complexity over that of insertion-error channel systems (with emptiness testing) whose termination problem is known to be non-elementary. Furthermore, by ﬁxing the number of available counters, we obtain a tight NLogSpace -complete bound for the termination problem.


Introduction
Reliable (Minsky) counter machines are well-known to be Turing-complete [12] and their reachability and termination problems have served as invaluable 'master' problems in establishing undecidable lower-bounds for a range of diverse decision problems. Furthermore, two counters are sufficient to establish Turingcompleteness [12]. Lossy counter machines (LCMs), by contrast, were introduced by Mayr [11] as a weakened version of Minsky's counter machines whose counters are permitted to spontaneously 'leak' their contents, analogous to that of the much-studied lossy FIFO-channel systems [2,4,1,5]. Indeed, LCMs can be seen as a degenerate case of lossy channel systems (with emptiness testing) in which the channel alphabet comprises a single symbol. Mayr showed that the reachability and termination problems for LCMs are both decidable [11], with the exact complexity pinned at being Ackermann-complete by Schnoebelen [18] (see [17] for a comprehensive survey of non-elementary complexity classes). Indeed, just five counters are sufficient to establish non-elementary complexity, with each additional counter moving the problem further up the Fast Growing Hierarchy [18].
Less well-studied than LCMs are incrementing counter machines (ICMs) which are permitted to spontaneously increase the value of their counters. Incrementing errors have been considered in the context of both counter machines and their more expressive channel systems (both with and without emptiness testing) [6,4,15,13], but appear to have received far less attention than their lossy counterparts.
Insertion channel systems (without emptiness testing) were first introduced in [4], where the authors show that the termination problem (among others) is trivially decidable as every transition can be traversed with the aid of timely insertion errors. The problem thus reduces to that of cycle-finding in the underlying control-state diagram. In the presence of emptiness testing-more akin to the operational semantics of incrementing counter machines-the termination problem was shown to be Tower-complete [3], being among the hardest problems that are primitive recursive but not solvable in elementary time [17].
With regards to the control-state reachability problem, there is no difference between lossy errors and incrementing/insertion errors for counter machines or channel systems, owing to a dualisation that reverses the 'arrow of time' [14,6]. Consequently, the reachability problem for both LCMs and ICMs is Ackermann-complete [18,6], while that of both lossy channel systems and incrementing channel systems (with emptiness testing) is HyperAckermann-complete [5,14].
It appears, however, that the problem of termination for incrementing counter machines has remained unaddressed. In what follows we shall establish that the termination problem is, in general, PSpace-hard but remains decidable in ExpSpace. Furthermore, we show that the problem is even NLogSpacecomplete when restricted to a fixed (finite) number of counters. Table 1 summarizes the known results relating to the termination problems for counter machines and channel systems (with emptiness testing) in the presence of lossy and incrementing errors.

Preliminaries
Definition 2.1. A counter machine is a tuple M = Q, C, q init , ∆ where Q is a finite set of control-states with a designated initial state q init ∈ Q, C = {c 1 , . . . , c n } is a finite set of counters and ∆ ⊆ Q × Op C × Q is a finite set of state transitions labelled with one of of the following operations Op C = {(c i ) ++ , (c i ) --, (c i ) ?? : c i ∈ C} to increment, decrement, or test whether a given counter is empty.
A configuration of M is a tuple (q, v) ∈ Q × N C , where q ∈ Q dictates the state of the machine and v : C → N is C-vector describing the contents of each counter. We denote by Conf M the set of all possible configurations of M, and define a well-quasiordering (wqo) ≤ on Conf M by taking For each α ∈ Op C , we define a binary consecution relation on the configurations of M by taking: , which is to say that we permit the value held in the counters to spontaneously decrease (resp. increase) immediately prior to and subsequent to a reliable transition.
We write (q, v) However, for the purposes of control-state reachability and termination, it is convenient to work with a more restrictive form of incrementing errors that encroach upon our computations only at the point of decrementing an otherwise empty counter. More precisely, we employ the following alternative definition for Such lazy 'just-in-time' incrementing semantics have been introduced for incrementing channel systems in [3] and used implicitly for counter machines in [6].
We define a lossy (resp. incrementing) computation / run of M to be a In what follows, we will be primarily interested in the following decision problem:

ICM Termination:
Input: Given a counter machine M = Q, C, q init , ∆ , Question: Is every incrementing run r ∈ Runs ↑ (M) finite?
In addition to the termination problem, we will also consider the restricted case where we admit only counter machines with a fixed number of counters.

k-ICM Termination:
Input: Given a counter machine M = Q, C, q init , ∆ such that |C| = k, Question: Is every incrementing run r ∈ Runs ↑ (M) finite?
As noted above, for reliable counter machines the two problems are computationally equivalent for k ≥ 2, but are known to differ in complexity for lossy counter machines. We will show here that the two problems also differ in complexity for incrementing counter machines.

Results
We first show that the termination problem for ICMs is decidable in ExpSpace by establishing a doubly-exponential upper-bound on the length of all finite runs that are possible for a terminating ICM. Any incrementing counter machine exhibiting a finite run exceeding this bound must necessarily possess a non-terminating run. The termination problem can therefore be decided by a non-deterministic search for such a 'long' finite run which, once found, demonstrates non-termination. Such a search can be performed using at most exponential space. It then follows from Savitch's Theorem [16] that the termination problem is decidable in ExpSpace. This is a marked contrast from the Towercompleteness of the termination problem for incrementing channel systems (with emptiness testing) [3].
Lemma 3.1. Let M = Q, C, q init , ∆ be a counter machine such that every incrementing run r ∈ Runs ↑ (M) is finite. Then the length of each incrementing run is at most n 2em! , where n = |Q|, m = |C|, and e is the base of the natural logarithm.
Proof. Let M = Q, C, q init , ∆ be as described above, with |Q| = n and |C| = m, and let r ∈ Runs ↑ (M) be any incrementing run of M. The case where n = 1 is trivial, so we may assume that n ≥ 2. We shall refer to any sub-sequence of r as an interval, with its length being the number of configuration transitions it comprises. For brevity we shall refer to any transition of the form (σ, (c i ) ?? , σ ) ∈ Conf M ×Op C ×Conf M as a c i -gate and collectively as Σ-gates whenever c i ∈ Σ, for Σ ⊆ C. An interval will be described as gate-free whenever it contains no C-gates.
To facilitate the proof, we define a increasing function T : N → N recursively by taking for all k > 0. It follows from a straightforward induction that where e is the base of the natural logarithm. For each subset Σ ⊆ C, let χ r (Σ) denote the length of the longest interval in which the only gates traversed belong to Σ. We prove by induction on the size of Σ that χ r (Σ) < n T (|Σ|) .
for all subsets Σ ⊆ C.
-Base Case) For the case where |Σ| = 0, we note that χ r (∅) < n since otherwise, by the pigeonhole principle, there would be some gate-free interval I in which the same control-state appears twice. We could then construct a non-terminating run by traversing the resulting loop indefinitely, as every underlying state transition of the form (q, (c i ) ++ , q ) or (q, (c i ) --, q ) can always be traversed. This contradicts our assumption that every incrementing computation of M is terminating.
-Inductive Case) Suppose that the claim holds for all subsets of size ≤ k and that |Σ| = (k + 1). Suppose to the contrary that χ r (Σ) ≥ n T (k+1) and let I = (σ t , α t , σ t+1 ) : t < χ , be such an interval of length χ = χ r (Σ). It follows from that induction hypothesis that I contains at least one c j -gate, for each c j ∈ Σ. Choose c i ∈ Σ and partition I into subintervals I 1 , . . . , I s by abscising all c i -gates, as illustrated in Figure 1. Note that we can abscise at most n consecutive c i -gates between each interval, else by the same argument as above, we could construct a non-terminating run by traversing a loop of such gates indefinitely.
Hence, by the induction hypothesis, the length of each subinterval can be at most χ r (Σ ) < n T (k) , since |Σ | = k. It follows that |I| ≤ s · χ r (Σ ) + (s + 1)n which is to say that for n ≥ 2. It then follows from ( †) that s > n k T (k)+1 .
c j i n c r e a s i n g c j d e c r e a s i n g For each subinterval I , let start( ) = (q, v Σ ) denote the configuration at the start of I restricted to only those counters occurring in Σ . Note that for each c j ∈ Σ , the first transition of I must appear in some interval I in which no c j -gate appears, or else must be itself a c j -gate. In the latter case, we require that the value of v(c j ) at start( ) is zero. In the former case, either the start of I or the end of I is contained within I, else I would not contain any c j -gates.
-If the start of I is contained in I then the value of v(c j ) at the start of start( ) can be at most χ r (Σ ) since otherwise the counter could not have been incremented (using the lazy semantics) since being emptied to traverse the gate at the start of I .
-Alternatively, if the end of I is contained in I then the value of v(c j ) at start( ) can be at most χ r (Σ ) since otherwise the counter could not be depleted in time to traverse the gate at the end of I . Hence, for each = 1, . . . , s, there are at most n choices for the state of start( ) and χ r (Σ ) < n T (k) choices for the values of each of the counters c j ∈ Σ in start( ). This gives at most n · (n T (k) ) k = n k T (k)+1 possible choices for start( ). However, since s > n k T (k)+1 , by the pigeonhole principle there must be at least two intervals I and I such that start( ) = start( ), where 1 ≤ < ≤ s. Consequently, it is possible to construct a non-terminating run by traversing the resulting loop indefinitely, as the two partial states agree on all counters from Σ , and the only c j -gates to be traversed are those from Σ . Any counters from (C − Σ ) are free to be incremented or decremented without impeding the computation. Again, this contradicts our assumption that every incrementing run r ∈ Runs ↑ (M) is terminating. Hence, by contradiction, we must have that χ r (Σ) < n T (k+1) .
Hence, it follows that χ r (Σ) < n T (|Σ|) for all Σ ⊆ C. In particular, we note that the maximum length of r is given by χ r (C) < n T (m) < n 2em! , as required.
With this upper-bound placed on the maximum possible length of runs for terminating ICMs, we are able to secure an ExpSpace upper-bound on the complexity of the termination problem.
Theorem 3.2. The ICM Termination problem is decidable in ExpSpace.
Proof. By Lemma 3.1, it is sufficient to identify whether a given counter machine has a finite run whose length exceeds n 2em! , where n = |Q| and m = |C|. This can be achieved via a non-deterministic search using at most exponential space, by storing only the current length and final configuration of the run as the search progresses. Both the length and the final configuration can be encoded as binary strings requiring at most O(log 2 (n)m!) bits of data, which is at most exponential in m and logarithmic in n. Should a run exceeding the aforementioned bound by found, we may conclude that the counter machine has a non-terminating incrementing run.
Hence, the non-termination problem for incrementing counter machines is decidable in NExpSpace, and so it follows that both the termination and nontermination problems belong to ExpSpace, as required.
This result stands in marked contrast to the lofty Ackermann-completeness of the termination problem for lossy counter machines [18], despite the equivalence of the reachability problem for the two types of unreliable machines [13]. Moreover, this result also highlights a jump in complexity from the relatively modest ExpSpace for incrementing counter machines to the non-Elementary complexity for incrementing channel systems (with emptiness testing) [3].
Next, we will provide a lower-bound on the complexity of the termination problem for ICMs by showing that an incrementing counter machine with m = |C| counters is capable of simulating a run of a reliable counter machine whose counters are bounded by 2 m/2 . This, in turn, provides us with a mechanism by which we can simulate any Turing machine that operates in space bounded by m/2 , thereby providing us with a PSpace-hard lower-bound for the termination problem for ICMs. Proof. Let X ⊆ {0, 1} * be an arbitrary problem solvable in PSpace, which is to say that there is some Turing machine T X and polynomial function p(n) such that T X terminates on all inputs and accepts w ∈ {0, 1} * if and only if w ∈ X, using at most p(|w|) tape cells. Following Minksy [12], we may translate T X together with a given input word w ∈ {0, 1} * into a reliable counter machine M X w = Q, C, q init , ∆ -polynomial in the size of w and constructible in polynomially time-such that w is accepted by T X if and only if M X w has a reliable run that reaches some accepting state q accept ∈ Q. Moreover, the value of the counters of M X w never exceeds 2 N − 1, where N = p(|w|) is the maximum length of tape required by T X on input w. We may modify M X w by adding a looping transition to q accept so that M X w has a non-terminating run if and only if w is accepted by T X .
We may then construct an ICM M = Q , C , q init , ∆ , polynomial in the size of both M X w and N , such that M has a non-terminating incrementing run r ∈ Runs ↑ (M ) if and only if M X w has a non-terminating reliable run r ∈ Runs(M X w ), along which the counters are bounded by 2 N . To achieve this, we first designate counters c 0 i , . . . , c N −1 i ∈ C , for each c i ∈ C, so that the value of counter c i for a given valuation v : C → N can be represented in binary as In other words, the emptiness (0) or non-emptiness (1) of each of the counters c j i collectively represent the value of c i in binary. We also require a second copy c 0 i , . . . , c N −1 i ∈ C , for each c i ∈ C, so that any incrementing errors can be detected and the computation terminated as a result. To achieve this we shall enforce that any increment (resp. decrement) to c j i is followed by a decrement (resp. increment) to c j i so that, over reliable runs, the pair (c j i , c j i ) acts like a binary switch with exactly one of the counters being empty at any given time.
For each ( , α, ) ∈ ∆, we construct a circuit of transitions that emulates the effect of α on the corresponding value of θ.
-Case α = (c i ) ?? : We can check whether θ v (c i ) = 0 by a series of emptiness checks to confirm that each of the counters c j i are empty, for j < N , as illustrated in Figure 2. It is straightforward to check that there is an incrementing path ( in , v) -Case α = (c i ) ++ : To increment the value of θ v (c i ) by one, we can execute the circuit illustrated in Figure 3.
Similarly, in the case where θ v (c i ) = 0 it is not possible to reach N −1 out and we terminate in state dead .
Note that each of the circuits are cycle-free and so do not allow for non-terminating computations to arise within the individual circuit. It follows that we can construct an equivalent ICM M by replacing each of the transitions of M X w with a copy of the appropriate circuit described above, each comprising at most 8N transitions. The resulting machine is at most polynomial in the size of M X w and N , with |Q | ≤ 8N · |∆| ≤ 8N n 2 and |C | = 2N m, and has a non-terminating incrementing run if and only if M X w has a reliable non-terminating run with counters bounded by 2 N . We could, as well, introduce a sequence of transitions to the initial state that first increment each of the c i variables by one so that v(c i ) + v(c i ) = 1 at the start of the run. However, this is not required as this can be achieved with a timely incrementing error, without which any computation would quickly terminate.
As M X w is at most polynomial in the size of w and constructible in polynomial time, it follows that X is polynomially reducible to ICM Termination, thereby demonstrating the problem to be PSpace-hard, as required.
Note that the above reduction requires an unbounded supply of counters for ever larger values of N . Indeed, such a reduction is not possible using only a fixed number of counters. Taking a closer look at the bound given in Lemma 3.1, we note that it is chiefly the number of counters m that is responsible for the doublyexponential bound on the length of the incrementing runs. By fixing the number of counters, we obtain a far more tractable bound with little additional overhead. Proof. The lower-bound is trivial and follows from a straightforward logspace reduction from the NLogSpace-hard reachability problem for directed graphs [10]. For the upper-bound, the proof is the same as that of Theorem 3.2, noting that for a fixed number of counters the bound given in Lemma 3.1 is logarithmic in the number of states. This, therefore, gives us an NLogSpace upper-bound for the non-termination problem. However, by the Immerman-Szelepcsényi theorem [9,19] we have that NLogSpace is closed under complements, thereby completing the proof.

The main problem left open by this present work is to establish where lies
the exact complexity of the termination problem for incrementing counter machines. Using the same principle as in Theorem 3.3, it is not hard to construct a terminating ICM with exponentially long runs; for example, by connecting the state N −1 out back to state 0 in in Figure 3. The resulting circuit contains no non-terminating computations, but is permitted to cycle through all binary representations from zero to 2 N − 1 before terminating in state dead . Unfortunately, it remains unclear whether it is possible to construct terminating ICMs which have doubly-exponentially long runs that would be required for the ExpSpace upper-bound given in Theorem 3.2 to be tight.
2. Reductions from various counter machine reachability problems have been used to establish lower-bounds for several first-order modal and temporal logics endowed with additional counting quantifiers [8]. Their lossy and incrementing counterparts arise naturally in this context when we consider firstorder modal logics with decreasing or expanding domains, respectively [8,7]. In particular, the recurrence problem for ICMs can be reduced to the satisfiability problem for the one-variable fragment of Linear Temporal Logic (LTL) over expanding domains with both future and next-time operators, thereby providing a Σ 0 1 -hard lower-bound. Finite satisfiability, though decidable, can be shown to be Ackermann-hard by a reduction from the ICM reachability problem; this remains true even in the absence of the 'next-time' operator. For the fragment having a single future operator, Theorem 3.3 can be utilized to provide a PSpace-lower bound for the satisfiability problem 1 . However, it is reasonable to suspect that the exact complexity may be much higher and, indeed, the decidability of this fragment still remains open.