Two-Way Parikh Automata with a Visibly Pushdown Stack

In this paper, we investigate the complexity of the emptiness problem for Parikh automata equipped with a pushdown stack. Pushdown Parikh automata extend pushdown automata with counters which can only be incremented and an acceptance condition given as a semi-linear set, which we represent as an existential Presburger formula over the final values of the counters. We show that the non-emptiness problem both in the deterministic and non-deterministic cases is NP-c. If the input head can move in a two-way fashion, emptiness gets undecidable, even if the pushdown stack is visibly and the automaton deterministic. We define a restriction, called the single-use restriction, to recover decidability in the presence of two-wayness, when the stack is visibly. This syntactic restriction enforces that any transition which increments at least one dimension is triggered only a bounded number of times per input position. Our main contribution is to show that non-emptiness of two-way visibly Parikh automata which are single-use is NExpTime-c. We finally give applications to decision problems for expressive transducer models from nested words to words, including the equivalence problem.


Introduction
Parikh automata. Since the classical automata-based approach to modelchecking [28], finite automata have been extended in many ways to tackle the automatic verification of more realistic and powerful systems against more expressive specifications. For instance, they have been extended to pushdown systems [3,26,30], concurrent systems [5], and systems with counters or specifications with arithmetic constraints have been the focus of many works in verification [7,11,[15][16][17][18]23].
Along this line of work, Parikh automata (or PA), introduced in [22], are an important instance of automata extension with arithmetic constraints. They are automata on finite words whose transitions are equipped with counter operations. The counters can only be incremented, and do not influence the run (enabling a transition requires no test on counter values), but the acceptance of a run is defined by the membership of the final counter valuations to some semi-linear set S. Expressivity of PAs goes beyond regularity, as the language L = {w | |w| a = |w| b } of words having the same numbers of as and bs is realised by a simple automaton counting the numbers of as and bs in counters x 1 and x 2 respectively, and the accepting condition is given by the linear-set {(i, i) | i ∈ N}. Semi-linear sets can be defined by formulas in existential Presburger arithmetic, ie first-order formulas with equality and sum predicates over integers, whose free variables are evaluated by the counter values calculated by the run.
A central problem in automata theory is the non-emptiness problem: does the automaton accepts at least one input. Although PAs go beyond regular languages, they retain relatively good algorithmic properties. The emptiness problem is decidable, and it is NP-c [12]. The hardness holds even if the semi-linear set is represented as a set of generator vectors. Motivated by applications in transducer theory for well-nested words, we investigate in this article extensions of Parikh automata with a pushdown stack.
First contribution: pushdown Parikh automata. As a first contribution, we study the complexity of the emptiness problem for Parikh automata with a pushdown store. Parikh automata extend finite automata with counter operations and an acceptance condition given as a semi-linear set, pushdown Parikh automata extend pushdown automata in the same way. We show that adding a stack can be done for free with respect to the emptiness problem, which remains, as for stackfree Parikh automata, NP-c. However in this case, we are able to strengthen the lower bound: it remains NP-hard even if there are only two counters, the automaton is deterministic, and the Presburger formula only tests for equality of these two counters. In the stack-free setting, it is necessary to have an unfixed number of counters to get such a lower bound.

Contribution 1. The emptiness problem for pushdown Parikh automata (PPA)
is NP-c. The lower bound holds even if the automaton is deterministic, has only two counters whose operations are encoded in unary, and they are eventually tested for equality.
Second contribution: adding two-wayness. We investigate the complexity of pushdown Parikh automata when the input head is allowed to move in two directions. It is not difficult to see that in that case emptiness gets undecidable, since, already without counters, one can simulate the intersection of two deterministic pushdown automata, by performing two passes over the input (visiting each input position at most three times). We consider a first restriction on the stack behaviour, which is required to be visibly.
A pushdown stack is called visibly if it is driven by the type of letters it reads, which can be either call symbols, return symbols or internal symbols. Words formed over such a structured alphabet are called nested words, and well-nested words if additionally the call/return structure of the word is well-balanced, such as in the following example: c c r r c r Automata for nested words, called visibly pushdown automata (or VPA), have been introduced in [2]. They are pushdown automata whose stack behaviour is constrained by the input in the following way. Upon reading a call symbol, exactly one symbol is pushed onto the stack. Upon reading a return symbol, exactly one symbol is popped from it. Upon reading an internal symbol, the stack is left unchanged. Hence, the symbol that is pushed while reading a given call symbol is popped while reading its matching return symbol. Consequently, visibly pushdown automata enjoy nice properties, such as closure under Boolean operations and determinisation.
VPA have been extended to two-way VPA (2VPA) [8] with the following stack constraints: in a backward reading mode, the role of the return and call symbols regarding the stack are inverted: when reading a call, exactly one symbol is popped from the stack and when reading a return, one symbol is pushed. It was shown in [8] that adding this visibly condition to two-way pushdown automata allows one to recover decidability for the emptiness problem. However, for Parikh acceptance, this restriction is not sufficient. Indeed, by encoding diophantine equations, we show the following undecidability result: Contribution 2. The emptiness problem for two-way visibly pushdown Parikh automata (2VPPA) is undecidable.
Single-use property. The problem is that by using the combination of twowayness and a pushdown stack, it is possible to encode polynomially, and even exponentially large counter values, with respect to the length of the input word. We consider therefore the single-use restriction, which appears in several transducer models [6,8,10], by which it is possible to keep a linear behaviour for the counters. Informally, a single-use two-way machine bounds the size of the production per input positions. It is syntactically enforced by asking that transitions which strictly increment at least one counter are triggered at most once per input position. Our main result is the decidability of 2VPPA emptiness under the single-use restriction, with tight complexity.

Contribution 3 (Main).
The emptiness problem for two-way single-use visibly pushdown Parikh automata (2VPPA su ) is NExpTime-c. The hardness holds even if the automaton is deterministic, has only two counters whose operations are encoded in unary, and they are eventually tested for equality.
To prove the upper-bound, we show that two-wayness can be removed from single-use 2VPPA, at the price of one exponential. In other words, single-use 2VPPA and VPPA have the same expressive power, although it can be shown that the former model is exponentially more succinct. The lower bound is obtained by encoding the succinct variant of the subset sum problem, based on a reduction which uses the fact that, by combining the pushdown and two-way features, single-use 2VPPA can encode doubly-exponential values 2 2 n with a polynomial number of states (in n).

Contribution 4 (Applications).
As an application, we give an elementary upper-bound (NExpTime) for the equivalence problem of functional single-use two-way visibly pushdown transducers [8], while an ExpTime lower bound was known. This transducer model defines transductions from well-nested words to words and, as shown in [8], they are well-suited to define XML transformations, have the same expressive power as Courcelle's MSO-transducers [6] (casted to well-nested words), and admit a memory-efficient evaluation algorithm. We also provide two other new results on single-use 2VPT (not necessarily functional). First, we show that given a positive integer k, it is decidable whether a singleuse 2VPT produces at most k different output words per input (k-valuedness problem). Then, we show the decidability of a typechecking problem: given a single-use 2VPT T and a finite (stack-free) Parikh automaton P , it is decidable whether the codomain of T has a non-empty intersection with P . This allows for instance to decide whether a single-use 2VPT produces only well-nested words and thus describes a well-nested words to well-nested words transformation, since the property of a word to be non well-nested is definable, as we show, by a Parikh automaton.
Finite-visit vs single-useness. The single-use property is more general than the more classical finite-visit restriction, used for instance in [9,19]: it requires to visit any input position a (machine-dependent) constant number of times, while single-useness only bounds the number of visits by producing transitions. Although, consequently to our results, 2VPPA single-use and finite-visit have the same expressive power, this extra modelling feature is desirable, for instance when using 2VPPA to test properties of 2VPT: single-use 2VPT are strictly more expressive than finite-visit ones, and this relaxation is crucial to capture MSO transductions [8]. Moreover, we somehow get it for free: we show that the NEx-pTime lower bound also holds for finite-visit 2VPPA. Finally, we note that as we deal with single-use machines rather than finite-visit ones, the usual ingredient for going from two-way to one-way consisting of memorizing simply crossing sections of states, is not sufficient to get the result here, since we cannot bound the size of these crossing sections.
Related work. Parikh automata are closely related to reversal-bounded counter machines [18]. In fact, both models have equivalent expressiveness in the nondeterministic case [22]. The difference of expressive power in the deterministic case is due to the fact that counter machines can perform tests on its counters that can influence the run, while counters in Parikh automata only matter at the end of the run. Several extensions of reversal-bounded counter machines were studied, whether they are two-way or equipped with a (visibly) pushdown stack. However, to the best of our knowledge, the combination of the two features has never been studied (see [19] for a survey). It is possible to define a model of single-use reversal-bounded two-way visibly pushdown counter machines, where the single-useness is put on transitions that modify the counters. This model is expressively equivalent to 2VPPA su in the non-determinstic case, and thanks to our result, has a decidable emptiness problem. The non-emptiness problem for reversal-bounded (one-way) pushdown counter machines for fixed numbers of counters and reversals is known to be in NP [13] and NP-hard [16]. Converting PPA into reversal-bounded counter machines would yield an unfixed number of counters. Our NP lower-bound for PPA however follows ideas of [16] about encoding, using the stack, integers n with O(log(n)) states and stack symbols. Two-way (stack-free) reversal-bounded counter machines, even deterministic, are known to have undecidable emptiness problem [19]. Decidability is recovered by taking the finite-visit restriction [19]. Our result on 2VPPA su entails the decidability of emptiness of two-way reversal-bounded counter machines which are single-use.
Finally, all the decidability results we prove on two-way visibly pushdown transducers were already known in the one-way case [13]. Two-way visibly pushdown transducers, which are strictly more expressive, can also be seen as a model of unranked tree-to-word transducers, modulo tree linearisation. To the best of our knowledge, this is the first model of unranked tree-to-word transducers for which k-valuedness and codomain well-nestedness is shown to be decidable. Another model, introduced in [1], is known to be expressively equivalent to 2VPT su [8], and in the functional case, has decidable equivalence problem in NExpTime. However, translating 2VPT su to this model requires an exponential blow-up, yielding a worst complexity for equivalence testing.
Structure. Section 2 introduces the computing models used, the proof of the lower bound for 2VPPA su is given in Sect. 3 and the upper bound in Sect. 4. Finally, some applications to the main theorem to transducers are given in Sect. 5.

Two-Way Visibly Pushdown (Parikh) Automata
In this section, we first recall the definition of two-way visibly pushdown automata and later on extend them to two-way visibly pushdown Parikh automata.
We consider a structured alphabet Σ defined as the disjoint union of call symbols Σ c , return symbols Σ r and internal symbols Σ i . The set of words over Σ is Σ * . As usual, denotes the empty word. Amongst nested words, the set of well-nested words Σ * wn is defined as the least set such that Σ i ∪ { } is included into Σ * wn and if w 1 , w 2 ∈ Σ * wn then both w 1 w 2 and cw 1 r (for all c ∈ Σ c and r ∈ Σ r ) belong to Σ * wn .
When dealing with two-way machines, we assume the structured alphabet Σ to be extended to Σ by adding a left and right marker symbols , in Σ c and Σ r respectively, and we consider words in the language Σ * .

Definition 1. A two way visibly pushdown automaton (2VPA for short)
Additionally, we require that for any states q, q and any stack symbol γ, if (q, ←, , γ, q , d) ∈ δ pop then d =→ and if (q, →, , γ, q , d) ∈ δ pop then d =← ensuring that the reading head stays within the bounds of the input word.
Informally, a 2VPA has a reading head pointing between symbols (and possibly on the left of or the right of ). A configuration of the machine is given by a state, a direction d and a stack content. The next symbol to be read is on the right of the head if d =→ and on the left if d =←. Note that when reading the left marker from right to left ← (resp. the right marker from left to right →), the next direction can only be → (resp. ←). The structure of the alphabet induces the behavior of the machine regarding the stack when reading the input word: when reading on the right, a call symbol leads to push one symbol onto the stack while a return symbol pops one symbol from the stack. When reading on the left, a dual behaviour holds. In any direction internal transitions from δ int read internal symbols and do not affect the stack; hence, at a given position in the input word, the height of the stack is always constant at each visit of that position in the run of the machine. The triggering of a transition leads to the update of the state of the machine, the future direction as well as the stack content. For a direction d, a natural i (0 ≤ i ≤ |w|) and a word w, we denote by Note that when switching directions (i.e. when the direction of the first part of the transition is different from the second part), we read twice the same letter. This ensures the good behavior of the stack, as reading a call letter from left to right pushes a stack symbol, we need to pop it if we start moving from right to left.
Formally, a stack σ is a finite word over Γ . The empty stack/word over Γ is denoted ⊥. For a word w from Σ and a 2VPA A = (Q, q I , F, Γ, δ), a configuration κ of A is a tuple (q, i, d, σ) where q ∈ Q, 0 ≤ i ≤ |w|, d ∈ D and σ is a stack. A run of A on a word w is a finite sequence ρ from K(δK) * , where K is the set of all configurations κ (that is a sequence starting and ending with a configuration and alternating between configurations and transitions); a run ρ is of the form Note that any configuration is actually a run on the empty word . The initial configuration is (q is the last position. A run for the word w is accepting if its first configuration is initial and its last configuration is final. A two-way visibly pushdown automaton A is: -finite-visit if for some k ≥ 0, any run visits at most k times the same input position.
The size of a 2VPA is the number of states times the size of the stack alphabet.
For A an automaton, we denote by L(A) the language recognized by A.

Lemma 1 ([8]). Given a 2VPA A, deciding if L(A) is empty is
Parikh automata. Parikh automata were introduced in [22]. Informally, they are automata with counters that can only be incremented, and do not act on the transition relation. Acceptance of runs is done by evaluating a Presburger formula whose free variables are set to the counter values. When clear from context, we may omit the free variables from the Presburger formula, and simply note φ. A run of a 2VPPA is a run of its underlying 2VPA. We extend canonically the mapping λ to runs. For a run ρ of the form We recall that a single configuration c is a run over the empty word .
For such a run c, we set It is deterministic (resp. one-way), denoted D2VPPA (resp. VPPA) if its underlying automaton is deterministic (resp. one-way). It is known from [4] that DPA (i.e. deterministic one-way and stack-free Parikh automata in our setting) are strictly less expressive than their nondeterministic counterpart. As a counter example, they exhibit the language L = {w | w #a(w) = b}, ie all words w such that if n is the number of a in w, the letter at the nth position is a b. Note that even in the two-way case, a deterministic machine recognizing L needs to either have access, during the computation, to the number of a's, or be able to store, in counters, the position of each b. As the first solution cannot be done since Parikh automata only access their counters at the end of the run, and the second is also impossible since there are only a finite number of counters, this language is also non definable by a D2VPPA, furthering the separation between deterministic and nondeterministic Parikh automata. Example 1. As an example, we give a deterministic 2VPPA P that, given an input i n c k i r k with c, i, r in Σ c , Σ i and Σ r respectively, accepts if k = and n = k 2 . The 2VPPA P uses 4 variables x n , x k , x and y. The first 3 variables are used to count the number of the first block of is, the number of calls and the second block of is respectively. The handling of these 3 variables is straightforward and can be done in a single pass over the input. The fourth variables y counts the multiplication k · and doing so is more involved. The part of the underlying 2VPA of P handling y is given in Fig. 2. On this part, the mapping λ simply increments the counter on transitions going to state 2 (i.e. on reading the letters i from left to right). It makes as many passes on the set of internal symbols in state 2 as there are call symbols, and the state of the stack upon reading i for the jth time is 1 j 0 k−j . Finally, the accepting formula φ of P is defined by x n = y ∧ x k = x . Note that this widget allows us to compute the set {(k 2 , k, k, k 2 ) | k ∈ N} which is not semilinear.  Fig. 2. A 2VPPA reading words c k i r k and making k passes on i , adding k · to the variable y. The transitions have two components, the first being the letter read, and the second being the stack operation. There is no stack operation upon reading internal symbols. The variable y is incremented in transitions going to state 2 only.
As we have seen in the previous example, the set Val (P ) is not necessarily semi-linear, even with P a D2VPPA. We use this fact to encode diophantine equations, and get the following undecidability result: Theorem 1. The emptiness problem of D2VPPA is undecidable.
Single-useness. In order to recover decidability, we adapt to Parikh Automata the notion of single-useness introduced in [8]. Simply put, a 2VPPA is single-use (denoted 2VPPA su ) if the transitions that affect the variables can only be taken once on any given input position, thus effectively bounding the size of variables linearly with respect to the size of the input. Formally, a state p of a 2VPPA P is producing if there exists a transition t from p on some symbol and λ(t) = 0 dim . A 2VPPA is single-use if for every input w and every accepting run ρ over w, there do not exist two different configurations (p, i, d, σ) and (p, i, d, σ ) with p a producing state, meaning that ρ does not reach any position in the same direction twice in any given state of P . This property is a syntaxic restriction of the model. However, since this property is regular, it can equivalently be seen as a semantic one. Moreover, deciding the single-useness of a 2VPPA is ExpTime-c (see [8] for the same result but on transducers). Note that the Parikh automaton given in Example 1 is not single-use, since it passes over the second subword of internal letters i in state 2 as many times as there are call symbols. In the following, we prove that 2VPPA su have the same expressiveness as VPPA, while being exponentially more succinct. In particular, this equivalence implies by Parikh's Theorem [24], semi-linearity of Val (P ) for any 2VPPA su P .

Emptiness Complexity
We show that the non-emptiness problem for VPPA is NP-complete. We actually show the upper-bound for the strictly more expressive Pushdown Parikh Automata (PPA), i.e. VPPA without the visibly restriction. While decidability was known [20,21], the precise complexity was, to the best of our knowledge, unknown. Let us also remark that the model and the proof are similar to the proof of NP-completeness of k-reversal pushdown systems from [16]. However, it is adapted here to Parikh automata as well as deterministic machines, which was not the case in [16].
From 2VPPA su to VPPA From a two-way visibly pushdown Parikh automaton satisfying the single-useness restriction, one can build an equivalent one-way visibly pushdown Parikh automaton. The construction induces an exponential blow-up, which cannot be avoided, as with most constructions from two-way to one-way machines.

Theorem 3.
For any 2VPPA su A, one can construct a VPPA B whose size is at most exponential in the size of A and such that L(A)=L(B). Moreover, the procedure can be done in exponential time.
Proof (Sketch). The goal is to be able to correctly guess all the transitions exactly taken by a run of the two-way machine at once. More precisely, the one-way machine guesses the behavior of the two-way machine on each well-nested subword of the input, i.e. a set of partial runs over a subword. A partial run is a pair from Q × {←, →}. Informally, they describe a maximal subrun over a subword of the input. We call these sets of partial runs profiles, and we define relations C and N c,r to describe compatible profiles. Formally, the relation C ⊆ P 3 is the concatenation relation, defined as set of triples (P, P , P ) such that there exists a word u = u 1 vv u 2 where v and v are well-nested subwords of u, and a run r on u such that P (resp. P ) is the profile of v in r (resp. of v ) and P is the profile of vv in r. Similarly, the relation N c,r ⊆ P 2 for c, r call and return letters respectively, is the cr-nesting relation, and defined as the set of pairs (P, P ) such that there exists a word u = u 1 cvru 2 where v is well-nested, and a run r of A on u such that P is the profile of v in r and P is the profile of cvr in r. We prove that these relations are computable in exponential time.
Given these relations, we can compute a VPPA B whose runs are bijective to the runs of A. Moreover, we can recover from a run of B which transitions are effectively taken at each positions by its bijective run of A. Then, the increment function simply does all the increments done by the run at a given position at once. Since the operation is the addition on integers, it is commutative and the variables are updated in the same way they were by the run of A. Note that we only recover which transitions are taken, and not how many times they are taken, which can depend on the size of the input. However, since A is single-use, we only have to add each non zero transition once, which gives the result.
As a direct corollary of Theorems 3 and 2, we get the following.

NExpTime-Hardness
In this section, we show that the problem of deciding whether the language of a 2VPPA su is non-empty is hard for NExpTime. Moreover, we show that this hardness does not depend on the fact that we have taken existential Presburger formulas, nor on the vector dimensions, and nor on the fact that the values in the tuples are encoded in binary.  Overview of the construction and encoding the values a i . Given an instance of SSSP I, our goal is to construct a D2VPPA su P = (C, ρ, φ) of dimension 2 such that |P| is polynomial in |θ| + k + m and L(P) = ∅ iff I has a solution.
The main idea is to ensure that L(C) = {X 1 e 1 . . . X 2 k −1 e 2 k −1 #e 2 k | X i ∈ {0, 1}} where the X i are internal symbols which are used to encode a subset J ⊆ {1, . . . , 2 k − 1}, and each e i is an encoding of a i , defined later, over some alphabet containing the symbol 1, and such that the number of occurrences of 1 in e i is a i . In other words, e i somehow encodes a i in unary. For the vector part, the machine P, when running over X i e i , updates its dimensions depending on two cases: (1) if X i = 1 ("put value a i in J"), then any transition reading 1 has weight (1, 0) and any other transition has weight (0, 0), (2) if X i = 0, then every transition has weight (0, 0). So, if X i = 1, the value in the first dimension after processing X i e i has been incremented by a i . Similarly, when processing #e 2 k , any transition reading 1 increments the 2nd dimension by 1, so that after processing #e 2 k , this dimension has value a 2 k . The formula φ(x 1 , x 2 ) then only requires equality of x 1 and x 2 , i.e. φ(x 1 , We now explain how to encode a i by a well-nested word e i . Due to the finitevisit restriction, every incremental transition can be triggered at most once for each input position. Since the value a i is possibly doubly exponential in m and The number of occurrences of 1 in e i will be exactly a i , i.e. # 1 (e i ) = a i and hence, the Parikh automaton will just have to count the number of 1 occurrences. Let us remind the reader that a i is actually given by θ, and therefore, the automaton P will somehow have to evaluate θ for valuations of its variables that will be contained in e i . Let us now define the words e i . For that, we call a binary tree either an internal symbol 1, 0, or a well-nested word of the form c j t 1 t 2 r j where t 1 , t 2 are themselves binary trees. For a well-nested word of the form cwr, a root-to-leaf branch π is a sequence of calls x 1 . . . x n such that cwr = x 1 w 1 x 2 w 2 . . . x n w n r n w n r n−1 w n−1 . . . r 2 w 2 r 1 where x 1 = c, r 1 = r and for some w i , w i well-nested words such that w n contains only internal symbols. The height of a binary tree t is the maximal length of a root-to-leaf branch, and it is complete if all root-to-leaf branches have the same length. Note that the number of internal symbols of a complete binary tree of height n is 2 n . Then, e i is the well-nested word defined by Proof. By Condition 2, every root-to-leaf branch of e i has length 2 m . Therefore, for all j ∈ {1, . . . , 2 m }, every root-to-leaf branch in t j has length 2 m − j. In particular, t 2 m does not contain any call symbol. Hence all the trees t j are complete binary trees of height 2 m − j. So, every t j has 2 2 m −j internal symbols and by Condition 4, we get Note that Condition 3 was not used in the previous proof, but it will be useful to define a succinct D2VPA recognising e i . The key result is the following. It states the existence of a succinct D2VPA which recognises exactly the candidate solutions to SSSP. in Appendix). The main idea is to construct succinct D2VPA which check each of the conditions 1 to 4 of the definition of the encoding independently, and then to take their intersection (by running the first, then the second, etc.). Condition 1 is easy to check. For condition 2, we rely on Lemma 2, and run sequentially the automata A i (in m passes) to check independently that for all i, each root-to-leaf branch has a sequence of indices that belongs to A i . Thanks to the reversibility of A i , it is possible when going upward in the tree, to recover the previous state of A i . For condition 3, we rely on the two-wayness to check that a sequence of m bits is a successor of another sequence succinctly, by doing O(m) passes over the two successor vectors. The stack is not necessary there. For condition 4, we rely on the existence of a succinct 2DFA which accepts all the valuations that satisfy a given Boolean formula.
We can finally construct the D2VPPA su P = (C, ρ, φ) of dimension 2 whose language is non-empty iff the SSSP instance I has a solution. The automaton C performs a first pass on the whole word by running the automaton B of Lemma 4, to check that the input is of the form X 1 e 1 . . . X 2 k −1 e 2 k −1 #e 2 k . During this pass, no vector dimension is incremented. During a second pass, C, when reading some X i = 1, it goes to some state q 1 from which it increments the 1st dimension whenever 1 is read (all other transitions have value (0, 0)). When reading some X i+1 , it stays in q 1 if X i+1 = 1 or to q 0 otherwise, from which no transition touches the counters. When reading #, it goes to a state from which it increments only the 2nd dimension on reading 1. Note that this automaton is single-use: any symbol 1 occurring in the whole input word is counted at most once. It is even finite-visit (each position is visited O(m + k + |θ|) times). Finally, one only needs to check whether the first dimension equals the second one, using a formula φ(x 1 , x 2 ) ≡ x 1 = x 2 . Note that the following lemma proves Theorem 4, since SSSP is NExpTime-c.

Lemma 5.
Given an instance X, Y, θ of SSSP, one can construct a D2VPPA su P of polynomial size in |θ| + |X| + |Y | such that L(P) = ∅ iff SSSP has a solution.

Applications to Decision Problems for Nested Word Transducers
In this section, we give two applications of 2VPPA, namely on decision problems for two-way visibly pushdown transducers (2VPT). 2VPT were introduced in [8] as a model to define transductions from well-nested words to words, or, modulo tree linearisation, from tree to words. It was shown that they can express, even in their deterministic and single-use version, all functions from well-nested words to words definable in MSOT, in the sense of Courcelle [6], while having decidable equivalence problem. No upper bound was provided however. Using 2VPPA, we show that the equivalence of 2VPT su defining functions can be tested in NExpTime. We also consider other standard problems from transducer theory and show, again using 2VPPA, their decidability. First, let us define formally 2VPT.
A two-way visibly pushdown transducer (2VPT for short) is a pair (A, μ) where A is a 2VPA and μ is a morphism from the sequences of transitions δ * to some output alphabet Γ * . A run of a 2VPT is a run of its underlying 2VPA. The output of a run ρ of the form (q 0 , i 0 , d 0 , σ 0 )τ 1 (q 1 , i 1 , d 1 , σ 1 )τ 2 . . . τ (q , i , d , σ ) is μ(τ 1 ...τ ). A run is accepted if it is accepted by its underlying automaton. The transduction defined by a 2VPT is the set of pairs (u, v) such that v is the output of some accepting run on u. A state p of a 2VPT is producing if there exists a transition τ such that p is the first component of τ and μ(τ ) = . Similarly to Parikh automata, a 2VPT T is single-use (denoted 2VPT su ) if for any valid run of T , we do not reach the same position twice in the same producing state. It is deterministic, denoted D2VPT, if its underlying automaton is deterministic.
Deciding the k-valuedness and equivalence problems. For any positive integer k, we say that a transducer is k-valued if all input word have at most k different outputs. In particular, it is 1-valued if it defines a (partial) function, and also called functional in that case.
Theorem 5. Let T be a 2VPT su , and k an integer. Then the k-valuedness of T can be decided in NExpTime. It is also ExpTime-hard.
The theorem is proved by reducing the k-valuedness of T to the emptiness of a 2VPPA su P that guesses k + 1 runs of T that produce k + 1 different outputs. To ensure that the output are different, during each run P guesses, and stores in counters, k output positions and the letters produced at these positions. The formula of P at the end simply checks, for each pairs of runs, that the same positions were guessed by both runs, and that the letters were different, ensuring that the guessed runs have different output pairwise. As two functional transducers are equivalent if they have the same domain and their union is 1-valued, we get the following corollary. Corollary 2. The equivalence of two functional 2VPT su T and T can be decided in NExpTime. It is also ExpTime-hard.
The NexpTime complexity of equivalence of tree to string transducers was already established for Streaming Tree to string transducers (STST), introduced in [1]. However, the conversion between the 2VPT su and STST yields an exponential blow-up.
We can generalize Corollary 2 to strictly k-valued transducers. We say that a transducer T is strictly k-valued if each input word in the domain of T has exactly k different images. Then similarly to the previous corollary, two strictly k-valued transducers are equivalent if, and only if, they have same domain and their union is k-valued. Corollary 3. The equivalence of two strictly k-valued 2VPT su T and T can be decided in NExpTime. It is also ExpTime-hard.
Strict k-valuedness is however an undecidable property (this can be shown by using the Post correspondence problem), even for k = 2. Deciding the equivalence problem for k-valued 2VPT su (which are not necessarily strictly k-valued) is open already in the stack-less case, and a (very) particular case has been solved in [14].
Type-checking against Parikh properties. Given a 2VPT T , it might be desirable to check some properties of the output words it produces, i.e., for a language L, whether the codomain of T is included in L. Formally, the type-checking problem asks, given a transducer T and a language L, whether T (Σ * ) ⊆ L. Unfortunately, this problem is undecidable when L is given by a visibly pushdown automaton (and T is a VPT) [13]. Nevertheless, we show that the type-checking problem is decidable when T is a 2VPT su and L is the complement of the language given by a (stack-less) Parikh Automaton. As a consequence, we are able to decide whether a 2VPT su T produces only well-nested words, i.e. if the output alphabet of T is structured and for every input word u and any v ∈ T (u), v is a well-nested word. Theorem 6. Let T be a 2VPT su and P be a (stack-free) Parikh Automaton over the output alphabet of T . Then we can decide whether T (Σ * ) ∩ L(P ) = ∅ in NExpTime. It is also ExpTime-hard. This is done by constructing a 2VPPA su P which simulates T , and instead of producing letters, simulates P on the output of T . A word w on a structured alphabet Σ is not well-nested if either |w| c = |w| r , i.e. the number of call letters is not equal to the number of return letters, or if there exists a prefix u of w such that |u| c < |u| r . As this can be checked by a (non-deterministic) Parikh automata, we get the following corollary.

Corollary 4.
Let T be a 2VPT su whose output alphabet is structured. It can be decided in CoNExpTime whether T only produces well-nested words.