Tropical Two-Way Automata

In this paper we study two-way min-plus automata. We prove that two-way distance automata are equivalent to one-way distance automata. In the second part of the paper we show that, with general min-plus semirings, it is decidable whether every accepted word has a weight diﬀerent from −∞ and that, in contrast, it is undecidable whether there exists a word accepted with a weight diﬀerent from −∞ .


Introduction
Min-plus automata have attracted much attention for three decades. N-min-plus is one of the simplest extensions of the Boolean semiring and min-plus automata are therefore a very natural extension of automata with various applications in natural language processing or optimization. They are indeed very powerful tools and take part in some very important results like star height.
We study here two-way min-plus automata. When the weights are non negative, we extend the classical result [8,7] that states that a two-way finite automaton is equivalent to a one-way finite automaton.
In the second part, we show that in general some words may be accepted in some two-way automata by a family of runs whose the infimum over weights is −∞. In this case, the behaviour of the automata may be not rational. We prove that the existence of such accepted words is decidable. In contrast, we prove that given a Z-min-plus automaton, it is undecidable whether there exists a word accepted with a finite weight. 1 2 Tropical Two-way Automata

Automata and Runs
An alphabet is a finite set of letters; for every alphabet A, we assume that there exist two fresh symbols and that are marks at the beginning and the end of the tapes of automata. We denote A the alphabet A ∪ { , }. For every word w in A, w is the word in A equal to w .
Tropical automata are instances of automata weighted by a semiring. For every additive submonoid K of R, we can define the min-plus semiring K = (K ∪ {∞}, min, +). For instance, from N, Z and R + , we can respectively define the min-plus semirings N , Z and R + . Notice that in a K-automaton, only weights in K appear (∞ is an algebraic way to specify the absence of transition).
In the sequel, we call distance automaton every min-plus automaton with non negative weights. Hence, N -automata and R + -automata are distance automata.
In some applications, the semiring P = ([0; 1], max, ·) is used (the weight of a path is in this case the product of the probabilities of the path and the weight of a word is the weight of the run on this word with the highest probability). The application x −→ − log x is actually an isomorphism from P onto R + . Every result on distance automata is therefore valid for P-automata.
One-way and two-way K-automata share a part of their definition. A Kautomaton is a tuple A = (Q, A, E, I, T ) where Q is a finite set of state, A is a finite alphabet, and I and T are partial functions from Q to K. The support of I, I, is the set of initial states of A, and the support of T , T , is the set of final states of A.
The definition of transitions differ. In a two-way K-automaton, E is a partial function from Q × (A × {−1, +1}) × Q into K and the support of E, E, is the set of transitions of A. Moreover, the intersection of E and Q×({ }×{−1}∪{ } × {1}) × Q must be empty. Let t be a transition in E; if t = (p, a, d, q), we denote σ(t) = p, τ (t) = q, λ(t) = a, δ(t) = d. On figures, the value of δ is represented by a left (-1) or right (+1) arrow. For instance, if t = (p, a, −1, q) and E t = k, we draw In a one-way K-automaton, E is a partial function from Q × A × Q into K, and the support of E, E, is the set of transitions of A. Let t be a transition in E; if t = (p, a, q), we denote σ(t) = p, τ (t) = q, λ(t) = a. Definition 1. Let w = w 1 . . . w n be a word of A * , we set w 0 = and w n+1 = .
A configuration of A on w is a pair (t, i) where i is in [0; n + 1] and t is a transition of A with λ(t) = w i . A computation (or run) ρ of A on w is a finite sequence of configurations ((t 1 , i 1 ), . . . , (t k , i k )) such that :  The weight of such a computation, denoted by |ρ|, is I(σ(t 1 ))+ k j=1 E(t j )+ T (τ (t k )). The weight of w in A, denoted by |A|, w , is the infimum of the weights of all the runs with label w in A. Notice that there may be an infinite number of computations with the same label w; in this case the infimum may not belong to K; actually, K can always be embedded into the semiring (R ∪ {−∞, ∞}, min, +) (with −∞ + ∞ = ∞) where the infimum of every family is always defined.

δ-normalization
Definition 2. Let A be a two-way K-automaton. If, for each state p of A, every outgoing transition from p has the same direction, then A is δ-local. If A is δ-local and, for each state p of A, every transition arriving at p has the same direction, then A is δ-normalized.
If A is a δ-local automaton, for every state p in Q, we set δ O (p) = δ(t), where t is any transition outgoing from p; if it is normalized, we also set δ I (p) = δ(t), where t is any transition incoming to p.
The following proposition is proved in [2].
Proposition 1. For every two-way K-automaton, there exists an equivalent δ-local two-way K-automaton.
To make a two-way automaton A δ-local, a covering of A is built: every state p with outgoing transitions with different directions is split into two states p + and p − that have the same incoming transitions as p, transitions outgoing from p + (resp. p − ) are the transitions outgoing from p with direction +1 (resp. −1).
The dual construction consists in splitting the states to separate incoming transitions with different directions. Applied to a δ-local two-way automaton, it results in a δ-normalized automaton.
Example 2. Figure 3 shows the conversion of a two-way automaton into a δ-local automaton, and then into a δ-normalized automaton. Example 3. The automaton A 1 of Figure 1 is not δ-normalized: in states q and r, there are outgoing transitions with direction −1 and others with direction +1. The automaton A 1 of Figure 4 is a δ-normalized equivalent automaton.

The Slice Automaton
The slice automaton is a one-way automaton that (non-deterministicly) emulates the runs of a two-way automaton. On a given run, for each position of the input, the slice of the run is the vector made of the states visited at this position. Every state of the slice automaton is such a vector and there is a transition between two states if the corresponding slices can successively appear in a run of the two-way automaton.
We give here the formal definition of the slices. A more complete description of the slice automaton is given in [2].
. The j-th slice of ρ is the vector s (j) of states obtained by the projection of the first component of each pair of h. The signature S(ρ) of ρ is the sequence of its slices.
The slices we define here are not exactly the crossing sequences defined in [8].
Let A = (Q, A, E, I, T ) be a δ-local two-way K-automaton. In order to define a one-way K-automaton from slices we consider the set X of subvectors of slices, that are vectors in Q * with an odd length; let Y be the vectors in Q * with an even length.
We define inductively two partial functions θ : X × A × X → K and η : Since A is δ-local, if θ is defined on a triple (u, a, v), it is uniquely defined. For every vector pu in X, pu is initial if p is in I and (ε, , u) is in η; in this case, we set I(pu) = I(p) + η(ε, , u). Likewise, every vector up in X is final if p is in T and (u, , ε) is in η; in this case, we set T (up) = η(u, , ε) + T (p).

Two-way Distance Automata
In two-way automata, in the same computation, there may be two steps where the automaton is in the same state and reads the same letter of the input. In this case we say that the computation contains an unmoving circuit.
If a run contains unmoving circuits, they can all be removed with a finite number of iterations since the removing of such a circuit leads to a shorter run. Proposition 1. If a two-way K-automaton admits a run ρ which is not reduced, it admits a reduced run with the same label.
Proposition 2. Let A be a two-way distance automaton on an alphabet A. For each w in A * , |A|, w is the weight of a reduced run of w.
Proof. By contradiction, let us suppose that, for a word w, there is no reduced run in A labeled by w with a minimal weight. Then let ρ = ((t 1 , i 1 ), . . . , (t l , i l )) be one of the shortest non reduced run labeled by w with a minimal weight. Since it is not reduced, then there exist j and k, with j < k, such that i j = i k and σ(t j ) = σ(t k ). Then there exists a run ρ = ((t 1 , i 1 ), . . . , (t j−1 , i j−1 ), (t k , i k ), . . . , (t l , i l )) labeled by w with |ρ | ≤ |ρ| which is a contradiction.
By Lemma 2 to simulate a two-way distance automaton by a one-way automaton, we only need to simulate reduced runs.
Actually, if a run of a two-way automaton contains an unmoving circuit, the signature of this run contains a vector where two entries with an index with the same parity are equals. In [2], we prove that the restriction of the slice automaton of A to states labelled by vectors that do not contain this kind of entry results in a finite one-way automaton where every computation corresponds to a reduced computation of A with the same weight and that every reduced computation of A has a representative in this finite one-way automaton.  Finally, by Lemma 2, Proposition 2. Every two-way distance automaton is equivalent to a one-way distance automaton.

Two-way Min-plus Automata
In this part, we study two-way automata on min-plus semirings based on non postive submonoids of R. In this case, a word may label an infinite number of paths with an increasingly smaller weight.
We say that a two-way min-plus automaton is valid if the weight of every accepted word is finite. We address the problem of deciding whether a two-way min-plus automaton is valid. Example 6. Let A 2 be the two-way Z-automaton of Figure 6 (left). Every time this automaton reads a word from left to right it computes the difference between the number of 'b's and the number of 'a's. Since for each accepted word, there can be an unbounded number of left-right reading, if there are more 'a's than 'b's, the weight of runs is not lowerly bounded. Thus, the behaviour of this automaton is only defined for words where the number of 'a's is at most equal ⊢, → |0 This example shows the following fact.
Proposition 3. There exist two-way min-plus automata such that the language of words accepted with a finite weight is not rational (or regular).

Theorem 1. It is decidable whether a two-way min-plus automaton is valid.
To prove this theorem, we need to consider another restriction of the slice automaton. Unlike the case of distance automata where we want that unmoving circuits do not appear at all, we want here to detect when unmoving circuits appear, but we want to deal with a finite automaton. So, we allow that each unmoving circuit appears at most once.
To this purpose, we consider the slices that belong to W = k W k with W k defined for all k in N as follows : (3) We consider the restriction of the slice automaton to W . Proposition 4. Let A be a two-way K-automaton and let C be the restriction of the slice automaton of A to W . If A accepts a run that contains an unmoving circuit with a negative weight, then there exists a run in A that contains an unmoving circuit with a negative weight and that is mapped into C.
Proof. Assume that there exist runs of A that contain at least one unmoving circuit with a negative weight. We chose ρ among these runs with a minimal number of transitions. Let q be the end of the unmoving circuit with negative 8 weight and let q 1 and q 2 be the both occurences of q. If ρ is not mapped into C, there exists a state p that appears (at least) three times in a slice v 1 of ρ (let p 1 , p 2 and p 3 be these three occurences); p is the end of two consecutive unmoving circuits. Different cases occur. If one of the two consecutive unmoving circuits has a negative weight, the other one can be removed to simplify the run. (This case may occur if p = q.) Likewise, if one of the two consecutive unmoving circuits does not intersect the unmoving circuit with negative weight, it can be removed. The only case that remains is when the run ρ can be decomposed as: In this case we have k 3 + k 4 < 0 and the shorter run contains an unmoving circuit with a negative weight.
In the automaton C, every run that meets a state in W \ V does contain an unmoving circuit. The problem is to detect whether such an unmoving circuit has a negative weight. The solution consists in comparing the weight of this run with the weight of the run without the unmoving circuit. To this purpose, we define an automaton which is a kind of square of the automaton C (cf. [1]): it compares paths of C that differ by unmoving circuits.
Let X 0 = {(x, y, z) ∈ X | y = 1}. We define on X the relation (x, y, z) ≡ (x , y , z ) if and only if y = y = 1 and xz = x z . In the quotientX of X by ≡, every element which is not in X 0 is the only element of its class, while the quotient of X 0 is isomorphic to W . Moreover, this equivalence is compliant with the definition ofθ. Let P = (X, A,θ, J, U ) be a one-way automaton defined as follows. The transition function isθ; every transition that corresponds to one of the two last lines of (7) is called a special transition. We set J(x, y, z) = θ(0, , xyz) − θ(0, , xz) if x is non empty or if x is empty and y 1 = z 1 (special initial Every computation in the automaton P that meets one (and only one) special transition (or special initial or final state) corresponds to two computations in the slice automaton. Each state of the first computation is obtained from every state (x, y, z) of the computation in P by concatenating x, y and z, while each state of the second computation is given by the concatenation of x and z. This two computations correspond to two runs in A, one with an unmoving circuit, the second one where the unmoving circuit has been removed.
Example 7. From the automaton A 2 of Figure 6 (right), we can build the automaton P 2 of Figure 8. The states in X 0 are labelled by one vector, and the other ones by three vectors. The special transitions and special initial states are red (there is no special final state). Each run in this automaton that contains a special transition (or initial state) corresponds two runs in A 2 , one with an unmoving circuit, the other one without this circuit. Such a pair of paths in A 2 may correspond to several paths in P 2 , depending where the path with the unmoving circuit is cut. For instance, consider the path i, s i , ; it corresponds to the path of Figure 9 and to the cut between the two red states. The weight of the path with the unmoving circuit is −4, without the unmoving circuit, it is −2; the difference is −2 which is equal to the weight of the path in P 2 .
Proposition 5. Let A be a two-way min-plus automaton and let P be the automaton built above. If A accepts a run that contains an unmoving circuit with a negative weight, then there is a run in P that meets one special transition (or special initial/final state) with a negative weight.  This property can be checked on the automaton P in polynomial time (see for instance [5]), and this implies Theorem 1.
If the two-way automaton is not valid, it could be interesting to compute an effective description of the language on which the behaviour is defined. By Proposition 3 this language must be non rational; worst, it is undecidable to know whether it is empty.
Theorem 2. Let A be a two-way Z-automaton. It is undecidable whether there exists a word w accepted by A with a finite weight.
Proof. In [4], it is prove that it is undecidable, given a one-way Z-automaton B = (Q, A, E, I, T ), to know whether there exists a word w whose weight in B is non negative. Let r be an element which is not in Q and let A = (Q ∪ {r}, A, F, I, T ) be the two-way Z-automaton defined as follow:  For every word w in A, every computation on w is any sequence of computations on w in B. Therefore, the weight of a word w in A is defined if and only if it has no computation with a negative weight in B, that is if its weight in B is non negative.

Conclusion
The problem tackled in this paper raises a more general problem on two-way automata. Actually, since the number of computations for a given input can be infinite, a proper definition of the behaviour of a weighted automaton must be forged. It meets some works on the behaviour of one-way weighted automata with ε-transitions (cf. [3,6]).
The last part of the paper also introduces some open questions. Despite the fact that the emptiness of the domain of a tropical two-way automaton is undecidable, is it possible to give a usable characterization of this domain ?