Affine Extensions of Integer Vector Addition Systems with States

We study the reachability problem for affine $\mathbb{Z}$-VASS, which are integer vector addition systems with states in which transitions perform affine transformations on the counters. This problem is easily seen to be undecidable in general, and we therefore restrict ourselves to affine $\mathbb{Z}$-VASS with the finite-monoid property (afmp-$\mathbb{Z}$-VASS). The latter have the property that the monoid generated by the matrices appearing in their affine transformations is finite. The class of afmp-$\mathbb{Z}$-VASS encompasses classical operations of counter machines such as resets, permutations, transfers and copies. We show that reachability in an afmp-$\mathbb{Z}$-VASS reduces to reachability in a $\mathbb{Z}$-VASS whose control-states grow linearly in the size of the matrix monoid. Our construction shows that reachability relations of afmp-$\mathbb{Z}$-VASS are semilinear, and in particular enables us to show that reachability in $\mathbb{Z}$-VASS with transfers and $\mathbb{Z}$-VASS with copies is PSPACE-complete. We then focus on the reachability problem for affine $\mathbb{Z}$-VASS with monogenic monoids: (possibly infinite) matrix monoids generated by a single matrix. We show that, in a particular case, the reachability problem is decidable for this class, disproving a conjecture about affine $\mathbb{Z}$-VASS with infinite matrix monoids we raised in a preliminary version of this paper. We complement this result by presenting an affine $\mathbb{Z}$-VASS with monogenic matrix monoid and undecidable reachability relation.


Introduction
Vector addition systems with states (VASS) are a fundamental model of computation comprising a finite-state controller with a finite number of counters ranging over the natural numbers. When a transition is taken, a counter can be incremented or decremented provided that the resulting counter value is greater than or equal to zero. Since the counters of a VASS are unbounded, a VASS gives rise to an infinite transition system. One of the biggest advantages of VASS is that most of the standard decision problems such as configuration reachability and coverability are decidable [KM69,May84,Kos82,Ler12]. Those properties make VASS and their extensions a prime choice for reasoning about and modelling concurrent, distributed and parametrised systems, see e.g. the recent surveys by Abdulla and Delzanno [AD16,Del16].
In order to increase their modelling power, numerous extensions of plain VASS have been proposed and studied in the literature over the last 25 years. Due to the infinite-state nature of VASS, even minor extensions often cross the undecidability frontier. For example, while in the extension of VASS with hierarchical zero-tests on counters both reachability and coverability remain decidable [Rei08,Bon13], all important decision problems for VASS with two counters which can arbitrarily be tested for zero are undecidable [Min67]. Another example is the extension of VASS with reset and transfer operations. In a reset VASS, transitions may set a counter to zero, whereas transfer VASS generalize reset VASS and allow transitions to move the contents of a counter onto another. While it was initially widely believed that any extension of VASS either renders both reachability and coverability undecidable, reset and transfer VASS have provided an example of an extension which leads to an undecidable reachability [AK76] yet decidable coverability problem [DFPS98]. Nevertheless, the computational costs for those extensions are high: while coverability is EXPSPACE-complete for VASS [Lip76,Rac78], it becomes Ackermann-complete in the presence of resets and transfers [Sch10,FFSPS11]. For practical purposes, the extension of VASS with transfers is particularly useful since transfer VASS allow for reasoning about broadcast protocols and multithreaded non-recursive C programs [EN98,KKW14]. It was already observed in [EN98] that transfer VASS can be viewed as an instance of so-called affine VASS. An affine VASS is a generalization of VASS with transitions labelled by pairs (A, b), where A is a d × d matrix over the integers and b ∈ Z d is an integer vector. A transition switches the control-state while updating the configuration of the counters v ∈ N d to A · v + b, provided that A · v + b ≥ 0; otherwise, the transition is blocked. Transfer VASS can be viewed as affine VASS in which the columns of all matrices are d-dimensional unit vectors [EN98].
Due to the symbolic state-explosion problem and Ackermann-hardness of coverability, standard decision procedures for transfer VASS such as the backward algorithm [ACJT96] do not per se scale to real-world instances. In recent years, numerous authors have proposed the use of over-approximations in order to attenuate the symbolic state-explosion problem for VASS and some of their extensions (see, e.g., [ELM + 14, ALW16,BH17]). Most commonly, the basic idea is to relax the integrality or non-negativity condition on the counters and to allow them to take values from the non-negative rational numbers or the integers. The latter class is usually referred to as Z-VASS, see e.g. [HH14]. It is easily seen that if a configuration is not reachable under the relaxed semantics, then the configuration is also not reachable under the standard semantics. Hence, those state-space over-approximations can, for instance, be used to prune search spaces and empirically drastically speedup classical algorithms for VASS such as the backward-algorithm. In this paper, we investigate reachability in integer over-approximations of affine VASS, i.e., affine VASS in which a configuration of the counters is a point in Z d , and in which all transitions are non-blocking. Subsequently, we refer to such VASS as affine Z-VASS.
Main contributions. We focus on affine Z-VASS with the finite-monoid property (afmp-Z-VASS), i.e. where the matrix monoid generated by all matrices occurring along transitions in the affine Z-VASS is finite. By a reduction to reachability in Z-VASS, we obtain decidability of reachability for the whole class of afmp-Z-VASS and semilinearity of their reachability relations.
In more detail, we show that reachability in an afmp-Z-VASS can be reduced to reachability in a Z-VASS whose size is polynomial in the size of the original afmp-Z-VASS and in the norm of the finite monoid M generated by the matrices occurring along transitions, denoted by M . For a vast number of classes of affine transformations considered in the literature, M is bounded exponentially in the dimension of the matrices. This enables us to deduce a general PSPACE upper bound for extensions of Z-VASS such as transfer Z-VASS and copy Z-VASS. By a slightly more elaborated analysis of this construction, we are also able to provide a short proof of the already known NP upper bound for reset Z-VASS [HH14]. We also show that a PSPACE lower bound of the reachability problem already holds for the extension of Z-VASS that only use permutation matrices in their transition updates. This in turn gives PSPACE-completeness of interesting classes such as transfer Z-VASS and copy Z-VASS.
Finally, we show that an affine Z-VASS that has both transfers and copies may not have the finite-monoid property, and that the reachability problem for this class becomes undecidable. We complement this result by investigating the case of monogenic classes, i.e. classes of monoids with a single generator. We show that although reachability can still be undecidable for an affine Z-VASS with a monogenic matrix monoid, there exists a monogenic class without the finite-monoid property for which reachability is decidable.
All complexity results obtained in this paper are summarized in Figure 1, except for the undecidability of general monogenic classes as it is a family of classes rather than one class.
Related work. Our work is primarily related to the work of Finkel and Leroux [FL02], Iosif and Sangnier [IS16], Haase and Halfon [HH14], and Cadilhac, Finkel and McKenzie [CFM12,CFM13]. In [FL02], Finkel and Leroux consider a model more general than affine Z-VASS in which transitions are additionally equipped with guards which are Presburger formulas defining admissible sets of vectors in which a transition does not block. Given a sequence of transitions σ, Finkel and Leroux show that the reachability set obtained from repeatedly iterating σ, i.e., the acceleration of σ, is definable in Presburger arithmetic. Note that the model of Finkel and Leroux does not allow for control-states and the usual tricks of encoding each control-state by a counter or all control-states into three counters [HP79] do not work over Z since transitions are non-blocking. Iosif and Sangnier [IS16] investigated the complexity of model checking problems for a variant of the model of Finkel and Leroux with guards defined by convex polyhedra and with control-states over a flat structure. Haase and Halfon [HH14] studied the complexity of the reachability, coverability and inclusion problems for Z-VASS and reset Z-VASS, two submodels of the affine Z-VASS that we study in this paper. In [CFM12,CFM13], Cadilhac, Finkel and McKenzie consider an extension of Parikh automata to affine Parikh automata with the finite-monoid restriction like in our paper. These are automata recognizing boolean languages, but the finite-monoid restriction was exploited in a similar way to obtain some decidability results in that context. We finally remark that our models capture variants of cost register automata that have only one + operation [AR13,AFR14].
Structure of the paper. We introduce general notations and affine Z-VASS in Section 2. In Section 3, we give the reduction from afmp-Z-VASS to Z-VASS. Subsequently, in Section 4 we show that afmp-Z-VASS have semilinear reachability relations and discuss semilinearity of affine Z-VASS in general. In Section 5, we show PSPACE and NP upper bounds of the reachability problem for some classes of afmp-Z-VASS; and in Section 6 we show PSPACEhardness and undecidability results for some classes of affine Z-VASS. In Section 7, we show that reachability is undecidable for monogenic affine Z-VASS and remains decidable for a specific class of infinite monoids. Some concluding remarks will be made in Section 8.

Preliminaries
General notation. For n ∈ N, we write [n] for the set {1, 2, . . . , n}. For every x = (x 1 , x 2 , . . . , x d ) ∈ Z d and every i ∈ [d], we define x(i) def = x i . We denote the identity matrix and the zero-vector by I and 0 in every dimension, as there will be no ambiguity. For x ∈ Z d and A ∈ Z d×d , we define the max-norm of x and A as where A i denotes the i th column of A. We naturally extend this notation to finite sets, i.e. G def = max{ A : A ∈ G} for every G ⊆ fin Z d×d . We assume that numbers are represented in binary, hence the entries of vectors and matrices can be exponential in the size of their encodings.
Affine Integer VASS. An affine integer vector addition system with states (affine Z-VASS) is a tuple V = (d, Q, T ) where d ∈ N, Q is a finite set and T ⊆ Q × Z d×d × Z d × Q is finite. Let us fix such a V. We call d the dimension of V and the elements of Q and T respectively control-states and transitions. For every transition t = (p, A, b, q), we define src(t) def = p, tgt(t) def = q, M (t) def = A and ∆(t) def = b, and let f t : Z d → Z d be the affine transformation defined by f t (x) = A · x + b. The size of V, denoted |V|, is the number of bits used to represent d, Q and T with coefficients written in binary. For our purposes, we formally define it in a crude way as |V| def = d + |Q| + (d 2 + d) · |T | · max(1, log( T + 1) ) where We naturally extend − → to sequences of transitions as follows. For every w = w 1 · · · w k ∈ T k and p(u), q(v) ∈ Q × Z d , we write p(u) w − → q(v) if either k = 0 (denoted w = ε) and p(u) = q(v), or k > 0 and there exist p 0 (u 0 ), p 1 (u 1 ), . . . , p k (u k ) ∈ Q × Z d such that , then we say that w is a run from p(u) to q(v), or simply a run if the source and target configurations are irrelevant. We also say that w is a path from p to q, and if p = q then we say that w is a cycle.  Figure 1. Classification of the complexity of reachability in affine Z-VASS in terms of classes of matrices. The rectangular regions below and above the horizontal dashed line correspond to classes of matrices with finite and infinite monoids respectively. The rectangular green dotted region and the elliptical red striped region correspond to the classes where reachability is decidable and undecidable, respectively. The elliptical blue region and the orange elliptical region correspond to the classes where reachability is NP-complete and PSPACE-complete respectively. The term "C J -Z-VASS" refers to the specific monogenic class of infinite monoids that will be defined in Section 7.1.
M, is the monoid generated by M (V), i.e. it is the smallest set that contains M (V), is closed under matrix multiplication, and contains the identity matrix. We say that a matrix A ∈ N d×d is respectively a (i) reset, (ii) permutation, (iii) transfer, (iv) copyless, or (v) copy matrix if A ∈ {0, 1} d×d and (i) A does not contain any 1 outside of its diagonal; (ii) A has exactly one 1 in each row and each column; (iii) A has exactly one 1 in each column; (iv) A has at most one 1 in each column; (v) A has exactly one 1 in each row.
Analogously, we say that V is respectively a reset, permutation, transfer, copyless, or copy Z-VASS if all matrices of M (V) are reset, permutation, transfer, copyless, or copy matrices. The monoids of such affine Z-VASS are finite and respectively of size at most 2 d , d!, d d , (d + 1) d and d d . Copyless Z-VASS correspond to a model of copyless cost-register automata studied in [AFR14] (see the remark below). If M (V) only contains the identity matrix, then V is simply called a Z-VASS.
A class of matrices C is a union d≥1 C d where C d is a finitely generated, but possibly infinite, submonoid of N d×d for every d ≥ 1. We say that V belongs to a class C of Z-VASS if M V ⊆ C. If each C d is finite, then we say that this class of affine Z-VASS has the finite-monoid property (afmp-Z-VASS). For two classes C and C we write C + C to denote the smallest set D = d≥1 D d such that D d is a monoid that contains both C d and C d for every d ≥ 1. Note that this operation does not preserve finiteness. For example if C and C are the classes of transfer and copy matrices, respectively, then C + C is infinite (see Figure 2 and Section 6). We say that a class C = d≥1 C d is nonnegative if C d ⊆ N d×d for every d ≥ 1. We say that an affine Z-VASS V is nonnegative if M V belongs to some nonnegative class of matrices. Note that the classes of reset, permutation, transfer, copyless and copy matrices are all nonnegative, respectively. We discuss the Z-VASS V in Figure 2 to give some intuition behind the names transfer and copy Z-VASS. The transition from p to q is a copy transition and the transition from q to p is a transfer transition. Notice that for every vector (x, y) ∈ Z 2 , we have p(x, y) − → q(x, x), i.e. the value of the first counter is copied to the second counter. Similarly, for the other transition we have q(x, y) − → p(x + y, 0), that is the value of the second counter is transferred to the first counter (resetting its own value to 0). Let A and B be the two matrices used in V. Note that (A · B) n is the matrix with all entries equal to 2 n−1 , and hence M V is infinite.
Remark 2.1. The variants of affine Z-VASS that we consider are related to cost register automata (CRA) with only the + operation [AR13,AFR14] and without an output function. These are deterministic models with states and registers that upon reading an input, update their registers in the form x ← y + c, where x, y are registers and c is an integer. An affine Z-VASS does not read any input, but is nondeterministic. Thus, one can identify an affine Z-VASS with a CRA that reads sequences of transitions as words. In particular, the restrictions imposed on the studied CRAs correspond to copy Z-VASS [AR13] and copyless Z-VASS [AFR14]. Decision problems. We consider the reachability and the coverability problems parameterized by classes of matrices C: Reach C (reachability problem) Cover C (coverability problem) For standard VASS (where configurations cannot hold negative values), the coverability problem is much simpler than the reachability problem. However, for affine Z-VASS, these two problems coincide as observed in [HH14, Lemma 2]: the two problems are inter-reducible in logarithmic space at the cost of doubling the number of counters. Therefore we will only study the reachability problem in this paper.

From affine Z-VASS with the finite-monoid property to Z-VASS
The main result of this section is that every affine Z-VASS V with the finite monoid property can be simulated by a Z-VASS with twice the number of counters whose size is polynomial in M V and |V|. More formally, we show the following: Moreover, V , p and q are effectively computable from V.
Proof. By Theorem 3.1, it suffices to construct, for a given afmp-Z-VASS V, the Z-VASS V and to test for reachability in V . It is known that reachability for Z-VASS is in NP [HH14]. To effectively compute V it suffices to provide a bound for M V . It is known that if |M V | is finite then it is bounded by a computable function (see [MS77]), and hence M V is also computable.
For the remainder of this section, let us fix some affine Z-VASS V such that M V is finite. We proceed as follows to prove Theorem 3.1. First, we introduce some notations and intermediary lemmas characterizing reachability in affine Z-VASS. Next, we give a construction that essentially proves the special case of Theorem 3.1 where the initial configuration is of the form p(0). Finally, we prove Theorem 3.1 by extending this construction to the general case.
It is worth noting that proving the general case is not necessary if one is only interested in deciding reachability. Indeed, an initial configuration p(v) can be turned into one of the form p (0) by adding a transition that adds v. The reason for proving the general case is that it establishes a stronger relation that allows us to prove semilinearity of afmp-Z-VASS reachability relations in Section 4.
3.1. A characterization of reachability. For every w ∈ T * , t ∈ T and u ∈ Z d , let Intuitively, for any sequence w ∈ T * , w(u) is the effect of w on u, regardless of whether w is an actual path of the underlying graph. A simple induction yields the following characterization: Testing for reachability with Lemma 3.3 requires evaluating w(u). This value can be evaluated conveniently as follows: Lemma 3.4. For every w = w 1 w 2 · · · w k ∈ T k and u ∈ Z d , the following holds: (3.1) Proof of Lemma 3.4. We prove (3.1) by induction on k. The base case follows from ε(u) = u = I · u + 0 = M (ε) · u + 0. Assume that k > 0 and that the claim holds for sequences of length k − 1. For simplicity we denote σ def = w 1 · · · w k−1 . We have: where (3.2), (3.3) and (3.4) follow respectively by definition of σw k (u), by induction hypothesis and by definition of M (σw k ). The last part of the lemma follows from applying (3.1) to w(0) and w(u), and observing that subtracting them results in w(u) − w(0) = M (w) · u.
Observe that Lemma 3.4 is trivial for the particular case of Z-VASS. Indeed, we obtain w(u) = u + k i=1 ∆(w i ), which is the sum of transition vectors as expected for a Z-VASS.
3.2. Reachability from the origin. We make use of Lemmas 3.3 and 3.4 to construct a Z-VASS V = (d, Q , T ) for the special case of Theorem 3.1 where the initial configuration is of the form p(0). The states and transitions of V are defined as: The idea behind V is to simulate a path w of V backwards and to evaluate w(0) as the sum identified in Lemma 3.4. More formally, V and V are related as follows: Note that the validity of the claim completes the proof since A 0 = I and A k = M (w).
It follows immediately from the definition of T that w i ∈ T for every i ∈ [k] and hence that w is a path from (q, A 0 ) to (p, A k ). By Lemma 3.3, it remains to show that w (0) = v: = w(0) (by Lemma 3.4 applied to w(0)). (b) Similarly, by Lemma 3.3, there exists a path w of V such that w (0) = v, and it suffices to exhibit a path w ∈ T * from p to q in V such that w(0) = v and M (w) = A.
It is readily seen that w is a path from p to q. To prove w(0) = v and M (w) = A, Lemma 3.4 can be applied as in the previous implication.
3.3. Reachability from an arbitrary configuration. We now construct the Z-VASS V = (2d, Q , T ) of Theorem 3.1 which is obtained mostly from V . The states of V are defined as: To simplify notation, given two vectors u, v ∈ Z d we write (u, v) for the vector of Z 2d equal to u on the first d components and equal to v on the last d components. The set T consists of four disjoint subsets of transitions T simul ∪ T end ∪ T mult ∪ T final working in four sequential stages. Intuitively, these transitions allow (1) V to simulate a path w of V backwards in order to compute w(0); (2) guess the end of this path; (3) compute M (w)·u by using the fact that M (w) is stored in its control-state; and (4) guess the end of this matrix multiplication. The first set of transitions is defined as: Its purpose is to simulate T on the last d counters. The second set is defined as: and its purpose is to nondeterministically guess the end of a run in V by simply marking q.
The third set is defined as: where e i is the i-th unit vector such that e i (i) = 1 and e i (j) = 0 for all i = j. The purpose of T mult is to compute A · u from the d first counters onto the d last counters. Finally, T final is defined as: and its purpose is to guess the end of the matrix multiplication performed with T mult . We may now prove Theorem 3.1: Proof of Theorem 3.1. First, note that we obtain Moreover, we have: We conclude by proving that By definition of T simul and T end , and by Proposition 3.5, it is the case that ). The transitions of T mult allow to transform (u, w(0)) into (0, w(0)+M (w)·u). Thus, using T final , we can reach the configuration p(w(0) + M (w) · u). This concludes the proof since w(u) = w(0) + M (w) · u by Lemma 3.4.
⇐) The converse implication follows the same steps as the previous one. It suffices to observe that the first part of a run of V defines the value w(0), while the second part of the run defines M (w) · u.

Semilinearity of affine Z-VASS
A subset of Z d is called semilinear if it is definable by a formula of Presburger arithmetic [Pre29], i.e. by a formula of FO(Z, +, <), the decidable first-order logic over Z with addition and order. Semilinear sets capture precisely finite unions of sets of the form b + N · p 1 + N · p 2 + . . . + N · p k with each p i ∈ Z d , and are effectively closed under basic operations such as finite sums, intersection and complement. Those properties make semilinear sets an important tool in many areas of computer science and find use whenever infinite subsets of Z d need to be manipulated.
The results of Section 3 enable us to show that any affine Z-VASS with the finite-monoid property has a semilinear reachability relation:  Let V 1 and V 2 be the affine Z-VASS illustrated in Figure 3 from left to right respectively. Note that M V 1 and M V 2 are both infinite due to the matrix made only of 1s. Moreover, the reachability relations of V 1 and V 2 are semilinear since the former can reach any target configuration from any initial configuration, and since the latter can only generate finitely many vectors due to the zero matrix. Since V 1 has a single control-state, |M (V 1 )| = |M (V 2 )| = 2 and ∆(V 2 ) = {0}, any simple natural extension of the characterization of semilinearity in terms of the number of control-states, matrices and vectors fails.
It is worth noting that an affine Z-VASS with an infinite monoid may have a non semilinear reachability relation. Indeed, Figure 2 depicts a transfer + copy Z-VASS with an infinite monoid and such that {v : p(1, 1) * − → q(v)} = {(2 n , 2 n ) : n ∈ N}, which is known to be non semilinear. Moreover, this proves that even the reachability set from p(1, 1) is not semilinear.

Complexity of reachability for afmp-Z-VASS
In this section, we use the results of Section 3 to show that reachability belongs to PSPACE for a large class of afmp-Z-VASS encompassing all variants discussed in Section 2. Moreover, we give a novel proof to the known NP membership of reachability for reset Z-VASS.
For every finite set G d ⊆ Z d×d , let G d be the monoid generated by G d . We have: Theorem 5.1. Let C = d≥1 C d be a class of matrices such that C d is finite for every d ≥ 1. It is the case that Reach C ∈ PSPACE if there exists a polynomial poly such that , and (iii) α 0 β 1 α 1 · · · β k α k is a path from p to q of length at most 2 · |Q | · |T |. For every w ∈ (T ) * , let ∆(w) def = |w| i=1 ∆(w i ). By Lemma 3.4 (see the remark below the proof of Lemma 3.4), we have w(u) = u + ∆(w) for every u ∈ Z d . Thus, by Lemma 3.3, checking (i), assuming (iii), amounts to testing whether e is a solution of the following system of linear Diophantine equations: x + k i=0 ∆(α i ) + ∆(β 1 ) ∆(β 2 ) · · · ∆(β k ) · e = y. (5.1) Let m def = 2 · |Q | · |T |. By Theorem 3.1, we have m ≤ 48d · |M| 2 · |Q| 2 · |T |. Thus, since G d is a submonoid of C d , and by assumption on C d , we have Thus, m is exponential in |V|.
We describe a polynomial-space non deterministic Turing machine A for testing whether p (x) * − → q (y) in V . The proof follows from NPSPACE = PSPACE. Machine A guesses k ≤ |T |, a path π = α 0 β 1 α 1 · · · β k α k of length at most m from p to q , and e ∈ N k , and tests whether (5.1) holds for π. Note that we are not given V , but V, so we must be careful for the machine to work in polynomial space.
Instead of fully constructing V and fully guessing π, we do both on the fly, and also construct ∆(α 0 ), ∆(β 1 ), . . . , ∆(β k ), ∆(α k ) on the fly as partial sums as we guess π. Note that to ensure that each β i is a cycle, we do not need to fully store β i but only its starting control-state. Moreover, note that ∆(α i ) , ∆(β i ) ≤ m · T for every i. By Theorem 3.1 and by assumption on C d , we have Hence, each α i and β i has a binary representation of polynomial size in |V|.
By [CH16, Prop. 4], (5.1) has a solution if and only if it has a solution e ∈ N k such that Since d = 2 · d, this means that we can guess a vector e ∈ N k whose binary representation is of polynomial size, and that we can thus evaluate (5.1) in polynomial time.
Corollary 5.2. The reachability problem for nonnegative afmp-Z-VASS is in PSPACE, and hence in particular for reset, permutation, transfer, copy and copyless Z-VASS.
Proof. Let C = d≥1 C d be a class of nonnegative matrices. Let d ≥ 1 and let G d be a finite set of matrices such that G d ⊆ C d . By [WS91, Theorem A.2], whose proof appears in [Web87] written by one of the same authors, we have: Note that this proof applies to reset, permutation, transfer, copy and copyless classes, respectively, as they are all nonnegative. However, there is a much simpler argument for these specific classes. Indeed, their matrices all have a max-norm of a most 1 and thus their monoids contain at most 2 d 2 matrices.
Theorem 5.3 [HH14]. The reachability problem for reset Z-VASS belongs to NP.
Proof. Let V = (d, Q, T ) be a reset Z-VASS. The proof does not follow immediately from Theorem 3.1 because M V can be of size up to 2 d . We will analyze the construction used in the proof of Theorem 3.1, where reachability in V is effectively reduced to reachability in a Z-VASS V = (d , Q , T ). Recall that Q = (Q × M V ) ∪ (Q × M V ) ∪ Q, and thus that the size of V depends only on the sizes of Q and M V .
It follows from the proof of Theorem 3.1 and Proposition 3.5 that for every run q (u, 0) * there is a corresponding run p(u) w − → q(v) in V for some w ∈ T * of length k ≥ 0. Moreover, the i th matrix occuring within the control-states of this run are is the form A i where A i = A i−1 · B for some B ∈ M V . Since M V consists of reset matrices, it holds that A 0 , A 1 , A 2 , . . . , A k is monotonic, i.e. if A i−1 has a 0 somewhere on its diagonal, then A i also contains 0 in that position. It follows that A 0 , A 1 , . . . , A k is made of at most d + 1 distinct matrices.
To prove the NP upper bound we proceed as follows. We guess at most d + 1 matrices of M V that could appear in sequence A 0 , A 1 , . . . , A k . We construct the Z-VASS V as in Theorem 3.1, but we discard each control-state of Q containing a matrix not drawn from the guessed matrices. Since the constructed Z-VASS is of polynomial size, reachability can be verified in NP [HH14].
Remark 5.4. Observe that the proof of Theorem 5.3 holds for any class of affine Z-VASS with a finite monoid such that every path of its Cayley graph contains at most polynomially many different vertices. For a reset Z-VASS of dimension d, the number of vertices on every path of the Cayley graph is bounded by d + 1.

Hardness results for reachability
It is known that the reachability problem for Z-VASS is already NP-hard [HH14], which means that reachability is NP-hard for all classes of affine Z-VASS. In this section, we show that PSPACE-hardness holds for some classes, matching the PSPACE upper bound derived in Section 5. Moreover, we observe that reachability is undecidable for transfer + copy Z-VASS.
Theorem 6.1. The reachability problem for permutation Z-VASS is PSPACE-hard.
Proof. We give a reduction from the membership problem of linear bounded automata, which is known to be PSPACE-complete (see, e.g., [HU79,Sect. 9.3 and 13]). Let A = (P, Σ, Γ, δ, q ini , q acc , q rej ) be a linear bounded automaton, where: • P is the set of states, • Σ ⊆ Γ is the input alphabet, • Γ is the tape alphabet, • δ is the transition function, and • q ini , q acc , q rej are the initial, accepting and rejecting states respectively. The transition function is a mapping δ : P × Γ → P × Γ × {Left, Right}. The intended meaning of a transition δ(p, a) = (q, b, D) is that whenever A is in state p and holds letter a at the current position of its tape, then A overwrites a with b and moves to state q and to the next tape position in direction D.
Let us fix a word w ∈ Σ * of length n that we will check for membership. We construct a permutation Z-VASS V = (d, Q, T ) and configurations r(u) and r (0) such that A accepts w if and only if r(u) * − → r (0). We set d def = n · |Γ| + 1 and associate a counter to each position of w and each letter of the tape alphabet Γ, plus one additional counter. For readability, we denote these counters respectively as x i,a and y, where i ∈ [n] and a ∈ Γ. The idea is to maintain, for every i ∈ [n], a single non zero counter among {x i,a : a ∈ Γ} in order to represent the current letter in the i th tape cell of A. The initial vector is u ∈ {0, 1} d such that u(y) = n and u(x i,a ) = 1 if and only if w i = a for every i ∈ [n] and a ∈ Γ. The invariant that will be maintained during all runs is y = i,a x i,a .
The control-states of V are defined as: The purpose of each state of the form r p,i is to store the current state p and head position i of A. States of the form r a,i will be part of a gadget testing whether A is simulated faithfully. We associate a transition to every triple (p, a, i) ∈ P × Γ × The purpose of the swap is to simulate the transition of A, upon reading a in tape cell i and state p, by moving the contents from x i,a to x i,b . Note that this transition may be faulty, i.e. it can simulate reading letter a even though tape cell i contains another letter. The purpose of the vector a is to detect such faulty behaviour: if the cell i does not contain a, then more than one counter among {x i,a : a ∈ Γ} will be a nonzero counter.
Recall that y = i,a x i,a . We conclude that A accepts w if and only if there exist j ∈ [n], u ∈ N d and a 1 , a 2 , . . . , a n ∈ Γ such that r q ini ,1 (u) * − → r q acc ,j (u ) and u (y) = i∈ [d] u (x i,a i ).
To test whether such index j, vector u and letters a 1 , a 2 , . . . , a n exist, we add some transitions to T as illustrated on the right of Figure 4. For every i ∈ [n] and every a ∈ Γ, we add to T the transitions (r q acc ,i , I, 0, r a,1 ). For every i ∈ [n] and a ∈ Γ, we add to T the transitions (r a,i , I, b, r a,i ) where b is the vector whose only non zero components are b(x i,a ) = b(y) = −1. Moreover, if i < n, then for every a, b ∈ Γ we also add transitions (r a,i , I, 0, r b,i+1 ). Finally, for all a ∈ Γ, we also add transitions (r a,n , I, 0, r acc ). The purpose of these transitions is to guess for each i some letter a i and simultaneously decrease x i,a i  and y. We do this for each i starting from 1 to n and in the end we move to the state r acc . We conclude that A accepts w if and only if r q ini ,1 (u) * − → r acc (0) in V.
Corollary 6.2. The reachability problem is PSPACE-complete for permutation Z-VASS, transfer Z-VASS and copy Z-VASS.
Proof. PSPACE-hardness for permutation Z-VASS was shown in Theorem 6.1, and the upper bound for transfer Z-VASS and copy Z-VASS follows from Theorem 5.1. It remains to observe that permutation matrices are also transfer and copy matrices.
Proposition 6.3. The reachability problem for transfer + copy Z-VASS is undecidable, even when restricted to three counters.
Proof. Reichert [Rei15] gives a reduction from the Post correspondence problem over the alphabet {0, 1} to reachability in affine Z-VASS with two counters. The trick of the reduction Figure 5. Gadget (on the right) made of copy and transfer transitions simulating the doubling transition on the left.
is to represent two binary sequences as the natural numbers the sequences encode, one in each counter. If we add an artificial 1 at the beginning of the two binary sequences, then these sequences are uniquely determined by their numerical values. We only need to be able to double the counter values, which corresponds to shifting the sequences. This can be achieved using the following matrices: The only matrices used in the construction of Reichert are I, D 1 and D 2 . The last two matrices can be simulated by a gadget made of copy and transfer matrices and by introducing a third counter. This gadget is depicted in Figure 5 for the case of matrix D 1 . The other gadget is symmetric. Note that if a run enters control-state p of the gadget with vector (x, y, 0), then it leaves control-state q in vector (2x + b 1 , y + b 2 , 0) as required.
Remark 6.4. The coverability problem for nonnegative affine VASS is known to be decidable in Ackermann time [FFSPS11]. Recall that coverability and reachability are inter-reducible for affine Z-VASS. Thus, Proposition 6.3 gives an example of a decision problem, namely coverability, which is more difficult for affine Z-VASS than for affine VASS.

Reachability beyond finite monoids
Thus far, we have shown, on the one hand, that reachability is decidable for affine Z-VASS with the finite-monoid property, and, on the other hand, that reachability is undecidable for arbitrary affine Z-VASS. This raises the question of whether there is a decidability dichotomy between classes of finite and infinite monoids, i.e. whether reachability is undecidable for every class of infinite monoids. In this section, we show that this is not the case: we exhibit a non-trivial class of infinite monoids for which affine Z-VASS reachability is decidable. In other words, the top rectangular region of Figure 1 is not equal to the red ellipse, which answers a question we left open in [BHM18]. The class of affine Z-VASS will have a particular shape, namely, the matrix monoids have a single generator. More formally, we say that a class of matrices C = d≥1 C d is monogenic if each monoid C d is generated by a single matrix. In the second part of this section we prove that reachability is in general undecidable for monogenic classes. 7.1. Decidability for a class of affine Z-VASS with infinite monoids. Let C d be the monoid generated by the (nonnegative) matrix J d ∈ N d×d whose entries are all equal to 1. Clearly, C d is infinite for every d ≥ 2 since (J d ) n is the matrix whose entries are all equal to d n . Let C J = d≥1 C d . The rest of this section is devoted to proving the following theorem: Theorem 7.1. The reachability problem Reach C J is decidable.
Let V = (d, Q, T ) be an affine Z-VASS belonging to C J . We will simply write J instead of J d as d is implicit from the dimension of V. Observe that we can assume w.l.o.g. that for every transition (p, A, b, q) ∈ T either A = I or b = 0, i.e. each transition either performs a transformation of the form x ← x + b or x ← A · x. Indeed, by adding an extra state r, we can always split such a transition into two transitions (p, A, 0, r) and (r, I, b, q). We can further assume w.l.o.g. that I and J are the only matrices occurring in V. Indeed, if T contains a transition t = (p, A, b, q) where A ∈ {I, J}, then A = J n for some n ≥ 2 and b = 0. Thus, we can simply replace t by a sequence of transitions t 1 , t 2 , . . . , t n leading from p to q and such that M (t i ) = J and ∆(t i ) = 0 for every i ∈ [n].
Let T I and T J denote the (maximal) subsets of T of transitions with matrix I and J respectively. Note that T I and T J form a partition of T . We will write S − → and S * −→ to denote respectively the restriction of − → and (1) p(u) for some w ∈ T * . If w does not contain any transition from T J , then (1) holds and we are done. Thus, suppose that w contains at least one transition from T J . Let t ∈ T J be the last such transition occurring in w. Recall that, by assumption, M (t) = J and ∆(t) = 0. Therefore, we are done since there exist r, r ∈ Q and w ∈ Z d such that In order to prove that Reach C J is decidable, it suffices to show that there exist procedures to decide the two conditions of Proposition 7.2. Testing condition (1) amounts to Z-VASS reachability, which belongs to NP [HH14]. Indeed, any run restricted to T I is a run of the Z-VASS induced by T I . Thus, in the rest of the proof, we focus on showing how to test condition (2).
For this purpose, let us introduce an auxiliary model. An affine one-counter Z-net is a pair (P, U ) where • P is a finite set of states, and Furthermore, for every transition t = (p, , c, q), we write p(n) The notions of runs and reachability are defined accordingly as for affine Z-VASS. These machines are a special case of one-counter register machines with polynomial updates whose reachability problem belongs to PSPACE [FGH13], i.e. we only allow the counter to be multiplied or incremented by constants, whereas the model of [FGH13] allows to update the counter by a polynomial such as x 2 or x 3 − x + 1.
For every v ∈ Z d , let Consider the transitions T in the affine Z-VASS V. For every transition t ∈ T , let t be defined as: where p = src(t) and q = tgt(t). Let W = (Q, T ) be the affine one-counter Z-net obtained from V = (d, Q, T ) by keeping the same states and taking T def = {t : t ∈ T }. We write w ∈ T * to denote the (unique) sequence of transitions in W corresponding to the sequence w ∈ T * of V. Let us observe the following correspondence between V and W: Lemma 7.3. For every p, q ∈ Q, u ∈ Z d , m ∈ Z and w ∈ T * , we have p(δ(u)) Proof. The claim follows from a simple induction on |w|.
We may now prove Theorem 7.1. Proof of Theorem 7.1. Recall that it suffices to show how to decide condition (2) of Proposition 7.2. By definition of J, this condition is equivalent to determining whether there exist r ∈ Q and n ∈ Z such that p(u) Let S = {m ∈ Z : ∃n ∈ Z (m = d · n) ∧ r∈Q r(n, n, . . . , n) As we mentioned earlier, V can be seen as a standard Z-VASS when restricted to T I . Since the reachability relation of any Z-VASS is effectively semilinear [HH14], the set S is also effectively semilinear.
Thus, it suffices to test whether p(δ(u)) in W for some m = d · n ∈ S. This can be achieved by extending W with a gadget that non deterministically subtracts some element of S after executing a transition from T J . More precisely, since S is an (effectively) semilinear set of integers, it is also (effectively) ultimately periodic. Thus, it is possible to obtain a description of S = F ∪ B + a · N where F = {f 1 , f 2 , . . . , f k } and B = {b 1 , b 2 , . . . , b } are finite subsets of Z. We extend W with the gadget depicted in Figure 6. More precisely, for every transition t ∈ T J leading to r, we add a new transition leading to a gadget that either subtracts some number from F or some number from B + a · N. Note that the gadget is not "attached" directly to r as we must ensure that r is entered by a transition of T J . Hence, testing whether amounts to testing whether p(δ(u)) * − → r (0) in the new net. Since the latter can be done in polynomial space [FGH13], we are done. 7.2. Undecidability for monogenic classes. In contrast with the previous result, we prove that decidability is undecidable in general for monogenic classes: Theorem 7.4. Reachability for monogenic affine Z-VASS is undecidable. Moreover, there exists a fixed monogenic affine Z-VASS for which deciding reachability is undecidable.
We show the first part of Theorem 7.4 by giving a reduction from the problem of determining whether a given Diophantine equation has a solution over the natural numbers, which is well-known to be undecidable. The second part of Theorem 7.4 follows as a corollary. Indeed, by Matiyasevich's theorem, Diophantine sets correspond to recursively enumerable sets. In particular, there exists a polynomial P such that x ∈ N is the encoding of a halting Turing machine ⇐⇒ ∃y : P (x, y) = 0.
The forthcoming construction will yield a monogenic affine Z-VASS that can test "∃y : P (x, y) = 0" by nondeterministically guessing y and testing P (x, y) = 0. Hence, reachability cannot be decided for this monogenic affine Z-VASS as the above language is undecidable.
Let us show the first part of Theorem 7.4. Let x 1 , x 2 , . . . , x k be variables of a given polynomial P (x 1 , x 2 , . . . , x k ). We will construct an instance of the reachability problem, for a monogenic affine Z-VASS V, such that reachability holds if and only if P (x 1 , x 2 , . . . , x k ) = 0 has a solution over N k .
The affine Z-VASS will be described using the syntax of counter programs; see [Esp98, CLL + 19], where a similar syntax was used to present the VASS model. We will make use of two instructions: zero(x)? and loop. The former checks whether counter x has value 0, and the latter repeats a block of instructions an arbitrary number of times. Figure 7 gives an example of such a program together with its translation as an affine Z-VASS.
Macros. Before describing the reduction, let us introduce helpful macros. First, we define macros "transfer x onto y" and "remove x from y". The former computes y = y + x and x = 0, and the latter computes y = y − x and x = 0. Both macros work under the assumption that x is initially non negative. These macros are implemented as follows: We define another macro "t = square(s)" for squaring the contents of a counter. More precisely, it computes s = t 2 and t = 0. This macro is implemented as follows: Right: an affine Z-VASS V equivalent to P, where its first and second components correspond to counters x and y respectively. The program loops are simulated by loops within the control structure of V. Note that whenever P only adds and subtracts constants from counters, the associated matrix is the identity. Since the only way V can test whether a counter equals 0 is at the end of the program via a reachability query, instruction zero(y)? merely emphasizes that counter y will never be used again. The above program starts with t and its auxiliary counters set to 0, and ends with s and the auxiliary counters set to 0. Its correctness follows by observing that (n + 1) 2 = n 2 + (2n + 1). We introduce one last macro "t = mult(s, s )" for multiplication. More precisely, it computes t = s · s and s = s = 0. Its implementation exploits the fact that 2mn = (m + n) 2 − m 2 − n 2 : // t = s · s , z = 0 The above program starts with t and its auxiliary counters set to 0, and ends with s, s and its auxiliary counters set to 0. Note that a macro "t = mult(s, c)" for multiplying by a constant c can be achieved by a simpler program: Although these programs can be implemented rather straightforwardly by an affine Z-VASS, two remarks are in order: • Affine Z-VASS do not have any native operation for testing a counter for zero. However, a counter x can be tested once via a reachability query, provided that x is left untouched after instruction zero(x)? has been invoked. Consequently, a constant number of zero-tests can be performed on a counter, provided its initial contents has been duplicated; • Instruction "transfer s onto t" at line 2 of macro "t = square(s)" destroys the contents of s which is later needed at line 9. As for zero-tests, this is not an issue provided that some counter holds a copy of s. Thus, only a constant number of squaring, and hence of multiplications, can be performed from a given counter.
The construction. Let us now describe the reachability instance. The initial vector is 0, which corresponds to having all counters set to 0 at the start of the program. The target vector is also 0, which corresponds to performing zero tests on all counters. The program starts by performing a sequence of loops that guess a valuation x for which P (x) = 0 is to be tested. More precisely, a value is nondeterministically picked for each variable x i and stored in counters x 1 i , x 2 i , . . . , x n i i . The reason for having n i copies of the value is to address the two issues mentioned earlier concerning zero-tests and reusing counters within macros. The precise number of copies, n i , will be determined later. The fragment of code achieving the initialization is as follows: loop x 1 1 = x 1 1 + 1; x 2 1 = x 2 1 + 1; · · · x n 1 1 = x n 1 1 + 1 loop x 1 2 = x 1 2 + 1; x 2 2 = x 2 2 + 1; · · · x n 2 2 = x n 2 2 + 1 . . .

loop
x 1 k = x 1 k + 1; x 2 k = x 2 k + 1; · · · x n k k = x n k k + 1 After the initialization, we compute the value of each monomial occurring within polynomial P (x 1 , x 2 , . . . , x k ). This can be achieved using counters x j i and the multiplication macro. Let Q(x 1 , x 2 , . . . , x k ) be a monomial of degree d. We show how to proceed by induction on d. If d = 0, then this is trivial. For larger degrees, we evaluate Q without its coefficient c, and then apply macro "t = mult(s, c)". If d = 1, then we can simply transfer the appropriate counter x j i . Otherwise, Q is a product of two monomials Q and Q of smaller degrees. By induction hypothesis, we can construct three copies of both monomials Q and Q . Then, using the multiplication macro, we obtain Q. Having evaluated all monomials, we can transfer each of their values to a common counter using the transfer and remove macros depending on whether their sign is positive or negative. Finally, we test if the resulting value equals zero, which corresponds to having a solution to P (x 1 , x 2 , . . . , x k ) = 0. Before arguing correctness of the construction, let us see why the whole program can be translated as a monogenic affine Z-VASS V, i.e. using only the identity matrix and one extra matrix A. First, note that all macros have internal counters x, y and z. Every time we use a macro, we use three fresh counters, increasing the dimension of V. Second, note that the only macro that requires a matrix different from the identity is "t = square(s)", which doubles y during an assignment to z at line 6. We will construct the matrix A as follows. Suppose we want to encode one of the squaring macros. Matrix A will have the same updates for all counters denoted as z in all macros, but the vector will use constants according to this macro. That is, all coordinates for counters not occurring in this macro will be 0. In particular, counter z from this macro will be updated like in line 6, i.e. "z = z + 2y + 1", and all other counters corresponding to some other z will be updated as "z = z + 2y".
Correctness. We conclude by proving correctness of the construction. If P has a solution, then it is straightforward to extract a run from V: (a) each x j i is initialized according to the solution; and (b) each loop of the program is performed the exact number times so that each zero-test holds. It remains to observe that after performing a zero-test on some counter, V does not perform any operation on this counter or performs "z = z + 2y". But if the values of y and z are equal to zero, then z will remain equal to zero after such an update.
Conversely, suppose there is a reachability witness (from 0 to 0). We claim that the initialization of counters x j i provides a solution to P . To prove this, it suffices to show that every zero-test was valid. This is clear for all counters except for the z within the squaring macro. Indeed, all other counters never change their values afterwards. However, counter z is updated by "z = z + 2y". If y is non zero, then this will be detected by the zero-test on y. Otherwise, the update "z = z + 2y" never changes the value of z as required.

Conclusion
We have shown that the reachability problem for afmp-Z-VASS reduces to the reachability problem for Z-VASS, i.e. every afmp-Z-VASS V can be simulated by a Z-VASS of size polynomial in |V|, |M V | and M V . In particular, this allowed us to establish that the reachability relation of any afmp-Z-VASS is semilinear.
For all nonnegative classes and consequently for all of the variants we studied -reset, permutation, transfer, copy and copyless Z-VASS -|M V | and M V are of exponential size, thus yielding a PSPACE upper bound on their reachability problems. Moreover, we have established PSPACE-hardness for all of these specific classes, except for the reset case which is NP-complete.
We do not know whether an exponential bound on M V holds for any class of afmp-Z-VASS over Z d×d . We are aware that an exponential upper bound holds when M V is generated by a single matrix [IS16]; and when M V is a group then we have an exponential bound but only on |M V | (see [KP02] for an exposition on the group case).
Finally, we have shown that there exists a (monogenic) class without the finite-monoid property for which reachability is decidable. This result was complemented by showing that reachability is undecidable in general for monogenic classes.