Pumping lemmas for weighted automata

We present pumping lemmas for five classes of functions definable by fragments of weighted automata over the min-plus semiring, the max-plus semiring and the semiring of natural numbers. As a corollary we show that the hierarchy of functions definable by unambiguous, finitely-ambiguous, polynomially-ambiguous weighted automata, and the full class of weighted automata is strict for the min-plus and max-plus semirings.


Introduction
Weighted automata (WA for short) are a quantitative extension of finite state automata used to compute functions over words. They have been extensively studied since Schützenberger's early works [Sch61], see also [DKV09]. In particular, decidability questions [Kro92,ABK11], model extensions [DG07], logical characterisations [DG07,KR13], and various applications [Moh97,CIK93] have been thoroughly investigated in recent years.
The class of functions computed by WA enjoys several equivalent representations in terms of automata and logics. Alur et al. introduced the model of cost register automata (CRA for short) [ADD + 13, AR13], an alternative model to compute functions over words inspired by programming paradigms, that recently received a lot of attention [MR,MR19, min-plus and max-plus semirings. More recently, [DG19] studied aperiodic WA over arbitrary weights, relating fragments of aperiodic WA with various degrees of ambiguity, and providing separating examples over the min-plus, max-plus and the natural semiring. In all these papers the strict inclusions are shown by analysing particular functions. Gathering these results we obtain strict inclusions between unambiguous automata, finitely-ambiguous automata, and the full class of WA over the min-plus semiring. However, to our knowledge, there is no reference for a strict inclusion between polynomially-ambiguous automata and the full class of WA. There is some work on the semiring of rational numbers with the usual sum and product [MR19,BFLM20]. In these papers the polynomially-ambiguous fragment over the one-letter alphabet is characterised in terms of a fragment of linear recurrence sequences. Both papers provide proofs that polynomially-ambiguous weighted automata are strictly contained in the full class of weighted automata over the semiring of rationals.
Differences with the conference version. Compared to [MR18], we present new pumping lemmas for the max-plus semiring (Section 6) regarding finitely ambiguous and polynomially ambiguous max-plus automata. As a corollary we obtain a strict hierarchy of functions similar to the one for min-plus automata.
Organization. In Section 2 we introduce weighted automata and some basic definitions. In Section 3 and Section 4 we present pumping lemmas for weighted automata over the semiring of natural numbers and its extension using the operation min. In Section 5 we show the pumping lemma for polynomially-ambiguous automata over the min-plus semiring, then we turn to the max-plus semiring in Section 6. Concluding remarks can be found in Section 7.

Preliminaries
In this section, we recall the definitions of weighted automata. We start with the definitions that are standard in this area. A monoid M = (M, ⊗, 1) is a set M with an associative operation ⊗ and a neutral element 1. Standard examples of monoids are: the set of words Σ * with concatenation and empty word; or the set of matrices with multiplication and the identity matrix. A semiring is a structure S = (S, ⊕, , 0, 1), where (S, ⊕, 0) is a commutative monoid, (S, , 1) is a monoid, multiplication distributes over addition, and 0 s = s 0 = 0 for each s ∈ S. If the multiplication is commutative, we say that S is commutative. In this paper, we always assume that S is commutative. We usually denote S or M by the name of the semiring or monoid S or M. We are interested mostly in the tropical semirings: the min-plus semiring (N ∪ {+∞}, min, +, +∞, 0) and the max-plus semiring (N ∪ {−∞}, max, +, −∞, 0). We are also interested in the semiring of natural numbers with infinity (N ∪ {∞}, +, ·, 0, 1), where ∞ + n = ∞ for every n ∈ N ∪ {∞} and ∞ · n = ∞ if n = 0 and 0 otherwise. We denote the tropical semirings by N min,+ and N max,+ ; and the latter semiring by N +,× . Note that N +,× is an extension of the standard semiring of natural numbers N and all our results for N +,× also hold for N. We use the extended version of N to transfer some results from N +,× to N min,+ and N max,+ (see Section 3 and Section 4). Notice that in N +,× we did not put a sign in front of ∞. For the semiring structure, this is not relevant. However, some statements in Section 3 and Section 4 will assume that the semiring is given with an order. Then one should think that the results hold both when ∞ = +∞ and when ∞ = −∞.
Given a finite set Q, we denote by S Q×Q (S Q ) the set of square matrices (vectors resp.) over S indexed by Q. The algebra induced by S over S Q×Q and S Q is defined as usual.
2.1. Weighted automata. Fix a finite alphabet Σ and a commutative semiring S. A weighted automaton (WA for short) over Σ and S is a tuple A = (Q, Σ, {M a } a∈Σ , I, F ) where Q is a finite set of states, {M a } a∈Σ is a set of matrices such that M a ∈ S Q×Q and I, F ∈ S Q are the initial and the final vectors, respectively [Sak09,DKV09]. We say that a state q is initial if I(q) = 0 and accepting if F (q) = 0. We say that (p, a, s, q) is a transition, where M a (p, q) = s and we write p a/s − → q. Furthermore, we say that a run ρ of A over a word w = a 1 . . . a n is a sequence of transitions: ρ = q 0 a 1 /s 1 − → q 1 a 2 /s 2 − → · · · an/sn − → q n , where s i = 0 for all 1 ≤ i ≤ n and I(q 0 ) = 0. We refer to q i as the i-th state of the run ρ. The run ρ is accepting if F (q n ) = 0, and the weight of an accepting run ρ is defined by |ρ| = I(q 0 ) ( n i=1 s i ) F (q n ). We define Run A (w) as the set of all accepting runs of A over w. Finally, the output of A over a word w is defined by A (w) = I t · M a 1 · . . . · M an · F = ρ∈Run A (w) |ρ| where I t is the transpose of I and the sum is equal to 0 if Run A (w) is empty. For a word w = a 1 . . . a n , by M w we denote M a 1 · . . . · M an , so that A (w) = I t · M w · F . Note that M w (p, q) provides the cost of moving from state p to state q reading the word w. Functions defined by weighted automata are called recognisable functions.
In this paper, we study the specification of functions from words to values, namely, from Σ * to S. We say that a function f : Σ * → S is definable by a weighted automaton A if f (w) = A (w) for all w ∈ Σ * .
A weighted automaton A is called unambiguous (U-WA) if | Run A (w)| ≤ 1 for every w ∈ Σ * ; and A is called finitely-ambiguous (FA-WA) if there exists a uniform bound N such that | Run A (w)| ≤ N for every w ∈ Σ * [Web94,KLMP04]. Furthermore, A is called polynomially-ambiguous (PA-WA) if the function | Run A (w)| is bounded by a polynomial in the length of w [KL09]. We call the classes of functions definable by such automata unambiguously recognisable, finite-ambiguously recognisable and polynomial-ambiguously recognisable.
Note that every unambiguous WA over N min,+ and N max,+ can be defined by a WA over the semiring N +,× (recall that ∞ is in N +,× ). Indeed, let A be an unambiguous WA over N min,+ (or N max,+ ). We define two copies of A: A 1 and A 2 such that all previously non-0 transitions between the states inside each copy have weights 1. The initial vector is inherited from A in the copy A 1 and defined as 0 for states in A 2 . Conversely, the final vector is inherited from A in the copy A 2 and defined as 0 for states in A 1 . Finally, for every transition (p, a, s, q) in A we add a transition (p 1 , a, s, q 2 ), where p 1 is the copy of p in A 1 and q 2 is the copy of q in A 2 . Since A is unambiguous it is easy to see that the construction works for words w such that A(w) = ∞. Let L be the language of the remaining words. Then for w ∈ L the new automaton outputs 0 instead of ∞. Since L is regular it suffices to take a union with another weighted automaton over N +,× that outputs ∞ for w ∈ L and 0 for w ∈ L.
Therefore, the class of unambiguously recognisable functions over N min,+ (and N max,+ ) is included in the class of recognisable functions over N +,× . The inclusions are strict since recognisable functions over N min,+ (and N max,+ ) are always bounded by a linear function in W 5 over N min,+ Figure 1: Examples of weighted automata. For WA over N min,+ the initial and accepting states are labelled by 0 in the corresponding vector, and ∞ otherwise. Similarly, for WA over N +,× the initial and accepting states are labelled by 1 in the corresponding vector, and 0 otherwise; except for the initial state labeled ∞.
the size of the word, and it is easy to define the function f (w) = 2 |w| over N +,× . Below, we give several examples of functions defined by WA over N +,× and N min,+ that will be used in paper. Recall that in the latter semiring 0 = ∞ and = +. Transitions p a/s − → q, where s = 0, are omitted.
Example 2.1. Let Σ = {a, b}. Consider the function f 1 that for given word w ∈ Σ * outputs the length of the biggest suffix of a's (and ∞ for the empty word). This is defined by the WA W 1 over N min,+ in Figure 1. One can easily check that W 1 is unambiguous, hence f 1 is an unambiguously recognisable function over N min,+ . In Figure 1, the WA W 1 over N +,× also defines f 1 .
Example 2.2. Let Σ = {a, b}. Consider the function f 2 that for a given word w ∈ Σ * outputs min{|w| a , |w| b }, namely, counts the number of each letter and returns the minimum. This is defined by the WA W 2 in Figure 1. The WA W 2 is finitely-ambiguous, hence f 2 is a finite-ambiguously recognisable function.
Consider the function f 3 that for a given word w = a 1 . . . a n ∈ Σ * outputs min 0≤i≤n {|a 1 . . . a i | a + |a i+1 . . . a n | b }. This is defined by the WA W 3 in Figure 1. This WA is polynomially-ambiguous, hence f 3 is a polynomial-ambiguously recognisable function.
Example 2.4. Let Σ = {a, b}. Consider the function f 4 that for a given word w ∈ Σ * computes the shortest subword of b's (if there is none it outputs +∞). This is defined by W 4 in Figure 1. The WA is polynomially-ambiguous, hence f 4 belongs to polynomially-ambiguous functions.
Example 2.5. Let Σ = {a, b, #}. Consider the function f 5 such that, for every w ∈ Σ * of the form w 0 #w 1 # . . . #w n with w i ∈ {a, b} * , it computes min{|w i | a , |w i | b } for each subword w i and then it sums these values over all subwords w i , that is, f 5 (w) = n i=0 min{|w i | a , |w i | b }. This function is defined by the WA W 5 in Figure 1. Given that this WA has an exponential number of runs, the function f 5 is a recognisable function, but not necessarily a polynomialambiguously recognisable function.
We will also discuss variants of the functions f 1 , f 2 , f 3 , f 4 and f 5 in the max-plus semiring in Section 6.
We assume that our weighted automata are always trim, namely, all their states are reachable from some initial state (accessible in short) and they can reach some final state (co-accessible in short). Verifying if a state is accessible or co-accessible is reduced to a reachability test in the transition graph [Pap93] and this can be done in NLogSpace. Thus, we can assume without loss of generality that all our automata are trimmed.
2.2. Finite monoids and idempotents. We say that a monoid is finite if the set of its elements is finite. Let M = (M, ⊗, 1) be a finite monoid. We say that ι ∈ M is an idempotent if ι ⊗ ι = ι. The following lemma is a standard result for finite monoids and idempotents (see e.g. [Pin10]).
Lemma 2.6. Let M be a finite monoid. There exists some N > 0 such that every sequence m 1 , . . . , m n , with m i ∈ M and n ≥ N , can be factorised as: We will mainly use two finite monoids of matrices, B Q×Q and B Q×Q ∞ . We define abstractions, i.e. homomorphisms of N Q×Q min,+ to B Q×Q , N Q×Q max,+ to B Q×Q , and N Q×Q +,× to B Q×Q ∞ . They are obtained from the homomorphisms defined on elements of the matrices, namely By abuse of language we say that a matrix M from N Q×Q min,+ , N Q×Q max,+ or N Q×Q +,× is idempotent, if its abstractionM is idempotent.

Recognisable functions over N +,×
In this section we consider recognisable functions over N +,× . As a corollary of the pumping lemma we show that FA-WA are strictly more expressive than U-WA over N min,+ and N max,+ (Example 3.2 and beginning of Section 6). Moreover, this shows that there are finite-ambiguously recognisable functions over N min,+ and N max,+ that cannot be defined by any recognisable function over N +,× . We introduce some notation to simplify the presentation. Given u · v · w =û ·v ·ŵ, where u, v, w,û,v,ŵ ∈ Σ * , we say thatû ·v ·ŵ is a refinement of u · v · w if there exist u , w such that u · u =û, w · w =ŵ, u ·v · w = v, andv = . We underline the infixes v andv to emphasise the refined part.
Theorem 3.1 (Pumping Lemma for recognisable functions over N +,× ). Let f : Σ * → N∪{∞} be a recognisable function over N +,× . There exists N such that for all words of the form u · v · w ∈ Σ * with |v| ≥ N , v = , there exists a refinementû ·v ·ŵ of u · v · w such that one of the following two conditions holds: Before going into the details of the proof let us show how to use the lemma. Example 3.2. We show that f 2 from Example 2.2 is not definable by any WA over N +,× . Indeed, suppose it is definable and fix N from Theorem 3.1. Consider the word w = a (N +1) 2 b N and notice that f 2 (w) = N . By refining w we getû·v·ŵ = a (N +1) 2 b n b m b l for some n, m, l such that 1 ≤ m ≤ N and n+m+l = N . Since n+m·N +l < n+m·(N +1)+l < (N +1) 2 it must be the case that f 2 (û ·v i ·ŵ) < f 2 (û ·v i+1 ·ŵ) for all i ≥ N . However, f 2 (û ·v i ·ŵ) = (N + 1) 2 for i sufficiently large, which is a contradiction.
Example 3.3. On the other hand, the function f 1 from Example 2.1 satisfies Theorem 3.1. Consider a word u · v · w ∈ Σ * and its refinementû ·v ·ŵ. Ifŵ orv contain b then f (û ·v i ·ŵ) = f (û ·v i+1 ·ŵ) because the suffix of a's remains the same. Otherwise, f (û ·v i ·ŵ) < f (û ·v i+1 ·ŵ) since the suffix of a's increases when pumping. Moreover, it is straightforward to generalise this argument and prove Theorem 3.1 for all U-WA over N min,+ .
To prove Theorem 3.1 we use the following definitions. For a matrix M ∈ N Q×Q +,× recall thatM is its homomorphic image in B Q×Q ∞ (see Section 2.2). We write that M and N in We also extend the homomorphic image and equivalence relation from matrices to vectors. We say that D ∈ N Q×Q +,× is an idempotent ifD is an idempotent in the finite monoid B Q×Q ∞ .
Given that M ≡ B∞ N we conclude N (p, q) > 0 and x(p) · N (p, q) · y(q) > 0, which proves Without loss of generality, we assume that I(q) = ∞ and M a (p, q) = ∞ for every p, q ∈ Q and a ∈ Σ, namely, ∞ can only appear in the final vector F . Indeed, if ∞ is used in I or some M a , we can construct two weighted automata A , A ∞ such that A is the same as A but each ∞-initial state or each ∞-transition is replaced with 0, and A ∞ outputs ∞ if there exists some run in A that outputs ∞ and 0 otherwise. Note that A has no ∞-transition or ∞-initial state and A ∞ can be constructed in such a way that only the final vector contains ∞-values. The disjoint union of A and A ∞ is equivalent to A. Let N = max{|Q|, K} where K is the constant from Lemma 2.6 for the finite monoid B Q×Q ∞ . For every word u · v · w ∈ Σ * such that v = a 1 . . . a n with n ≥ N , consider the output By Lemma 2.6, there exists a factorisation of the form: for some i < j where M a i+1 ...a j is an idempotent (i.e.,M a i+1 ...a j is an idempotent). We define the refinementû ·v ·ŵ of u · v · w such thatû = u · (a 1 . . . a i ),v = a i+1 . . . a j , andŵ = (a j+1 . . . a n ) · w. Furthermore, define x T = I T · M ua 1 ...a i , D = M a i+1 ...a j , and y = M a j+1 ...anw · F . Note that f (û ·v i ·ŵ) = x T · D i · y for every i ≥ 0 and D is an idempotent (i.e.,D is an idempotent). It remains to show the following lemma. Lemma 3.5. For every idempotent D ∈ N Q×Q +,× and x, y ∈ N Q +,× where D and x do not contain ∞-values, one of the conditions holds: We start showing that Lemma 3.5 holds when y = e p for some p ∈ Q, where e p (q) = 1 if q = p and 0 otherwise. Note that z = p∈Q z(p) · e p for every vector z.
We say that Suppose that p is stable and D · e p = e p + z for some vector z. Then for i > 0: Let P ⊆ Q be the set of all non-stable states in D. One can easily check that D restricted to P forms a partial order, namely, that D is reflexive, antisymmetric, and transitive. Indeed, transitivity holds because D is idempotent. To prove antisymmetry, note that for every non-stable states p and q, if p D q, q D p and p = q hold, then D(p, p) > 0. This is a contradiction since p is non-stable.
Since D is a partial order, we prove the lemma for y = e p by induction over D . Formally, we strengthen the inductive hypothesis such that conditions (3.1) and (3.2) hold for every i ≥ N q , where N q = |{q ∈ P | q D q}| (notice that N q ≤ |Q| for every q). The base case is for N p = 1, which means that p is stable. For the inductive case suppose that N p > 1. Then for pairwise different states q 1 , . . . , q k and positive values c 1 , . . . , c k ∈ N such that q j is either stable or q j ≺ D p. Thus all states q 1 , . . . , q k satisfy our inductive hypothesis.
Consider the partition of q 1 , . . . , q k into sets C = and C < such that C = and C < satisfy condition (3.1) and (3.2), respectively. If C < = ∅, then for every i ≥ N p we have: (3.3) Note that x T · D i · e q j = x T · D i−1 · e q j holds by the inductive hypothesis and because N p > N q j for every q j . Suppose otherwise, that C < = ∅ and there exists a state q j that satisfies x T · D i · e q j < x T · D i+1 · e q j for every i ≥ N q j . Then it is straightforward that equality (3.3) becomes a strict inequality and condition (3.2) holds. We have shown that either (3.1) or (3.2) holds for y = e p . It remains to extend this to any vector y ∈ N Q +,× (possibly with ∞). Note that for some states q 1 , . . . , q k such that y(q j ) > 0 for every j ≤ k. We consider two cases. First, if there exists j such that y(q j ) = ∞ and Thus, x T · D i · y satisfies condition (3.1). Second, suppose that for every j we have y(q j ) = ∞ or x T · D i · e q j = 0 for i ≥ N . It suffices to consider the case when y(q j ) = ∞ for all j. Then if some x T · D i · e q j satisfies condition (3.2) we have that x T · D i · y satisfies condition (3.2). Conversely, if every x T · D i · e q j satisfies condition (3.1) we have that x T · D i · y satisfies condition (3.1).
One could try to simplify Theorem 3.1 changing the condition i ≥ N to i ≥ 0. Unfortunately, we do not know if the theorem would remain true. A naive approach would be to use a generalisation of Lemma 2.6, but intuitively, the behaviour of non-stable states is problematic. We conclude with the following remarks, straightforward from the proof. We will use them in Section 4.
Remark 3.6. Changing y to y such that y ≡ B∞ y does not influence whether condition (3.1) or condition (3.2) holds in Lemma 3.5 (notice that here we need that the abstractions have values in B ∞ not in B). Similarly, changing x to x such that x ≡ B∞ x does not influence whether condition (3.1) or (3.2) holds.
Remark 3.7. The constant N and the refinement of w depend only on the finite monoid B Q×Q ∞ . In particular they are independent from the initial and final vectors I and F .

Finite-min recognisable functions
In this section we focus on recognisable functions over N +,× with some min operations allowed. Formally, we say that f : Σ * → N ∪ {∞} is a finite-min recognisable function, if there exist recognisable functions f 1 , . . . , f m over N +,× such that f (w) = min{f 1 (w), . . . , f m (w)}. It is known that over N min,+ , FA-WA are equivalent to a finite minimum of U-WA [Web94], hence the functions defined by FA-WA are included in the class of finite-min recognisable functions. As a corollary of the pumping lemma in this section we show that PA-WA are strictly more expressive than FA-WA over N min,+ (Example 4.2 and Example 4.3).
We start by introducing some notation. Generalising the notation used in the previous section, we define for n > 0 an n-pumping representation for a word w ∈ Σ * as a factorisation of the form . v n · u n and v k = for all k. A refinement of an n-pumping representation for w is given by . . , n} such that S = ∅. Let y k be a factor of the refined n-pumping representation of w. By y k (S, i) we denote the word y i k if k ∈ S and y k otherwise. By w(S, i) we denote the word w = u 0 · y 1 (S, i) · u 1 · y 2 (S, i) · . . . u n−1 · y n (S, i) · u n .
In other words, in w(S, i) we pump i times each factor y k , for all k ∈ S. Note that the pumping always refers to the refinement of the n-pumping representation.
such that for every sequence of non-empty, pairwise different subsets S 1 , . . . , S k ⊆ {1, . . . , n} with k ≥ N one of the following holds: • there exists j such that f (w(S j , i)) < f (w(S j , i + 1)) for all but finitely many i; • there exist j 1 = j 2 such that f (w(S j 1 ∪ S j 2 , i)) = f (w(S j 1 ∪ S j 2 , i + 1)) for all but finitely many i.  On the other hand f 3 (w(S j 1 ∪S j 2 , i)) < f 3 (w(S j 1 ∪S j 2 , i+1)) for all i and j 1 = j 2 . Hence f 3 does not satisfy the pumping lemma for finite-min recognisable functions. Then by definition f 4 (w) = N . In the refinement all pumping parts will be of the form b n for 1 ≤ n ≤ N . We define the sets S j = {1, . . . , N }\{j} for all 1 ≤ i ≤ N . Clearly f 4 (w(S j , i)) = N for all j and i. On the other hand f 4 (w(S j 1 ∪S j 2 , i)) < f 4 (w(S j 1 ∪S j 2 , i+1)) for all i and j 1 = j 2 . Hence f 4 does not satisfy the pumping lemma for finite-min recognisable functions.
Proof of Theorem 4.1 . Let f 1 , . . . , f m be recognisable functions over N +,× such that f (w) = min{f 1 (w), . . . , f m (w)} for every w. Furthermore, consider A j = (Q j , Σ, {M j,a } a∈Σ , I j , F j ) the corresponding WA for f j . Let Q = j Q j (we assume that Q 1 , . . . , Q m are pairwise disjoint) and consider the set of matrices {U a } a∈Σ where U a ∈ N Q×Q +,× such that U a (p, q) = M j,a (p, q) whenever p, q ∈ Q j and 0 otherwise. Then f j (w) = (I j ) t · U w · F j for every j and w ∈ Σ * where I j and F j are the extensions of I j and F j from Q j into Q such that I j (q) = I j (q) and F j (q) = F j (q) whenever q ∈ Q j and 0 otherwise. Notice that {U a } a∈Σ synchronise the behaviour of f 1 , . . . , f m in a single set of matrices and project the output of f j with I j and F j . Let N = max{K, m + 1} such that K is the constant from Lemma 2.6 applied to B Q×Q ∞ . Let w = u 0 ·v 1 ·u 1 ·v 2 ·. . . u n−1 ·v n ·u n . be an n-pumping representation as in the statement of the theorem. For every i we apply Theorem 3.1 to u ≤i · v i · t ≥i , where u ≤i = u 0 · v 1 · . . . u i−1 and t ≥i = u i · v i+1 · . . . u n , and {U a } a∈Σ (recall that the refinement of u ≤i · v i · t ≥i depends only on {U a } a∈Σ , and not on the initial or final vector, see Remark 3.7). As in the proof of Theorem 3.1 we obtain a refinement w = u 0 · y 1 · u 1 · y 2 · . . . u n−1 · y n · u n , where each y i is idempotent w.r.t. {U a } a∈Σ . Note that the refinement is the same for each function f j . Therefore, we obtain Lemma 4.4. Let S ⊆ {1, . . . , n} be a non-empty set and fix one function f j . Then Proof. By definition f j (w(S, i)) = (I j ) t · U u 0 · D s 1 1 · . . . · U u n−1 · D sn n · U u n · F j where s k = i if k ∈ S and s k = 1 otherwise. Since all D i are idempotents then for all k: Hence, the lemma follows from Remark 3.6.
To finish the proof we analyse f (w(S, i)) = min{f 1 (w(S, i)), . . . , f m (w(S, i))}. Consider a sequence of subsets S 1 , . . . , S k with k ≥ N . Suppose there is a set S l such that for every 1 ≤ j ≤ m, we have f j (w(S l , i)) < f j (w(S l , i + 1)) for every i ≥ N . In this case, f (w(S l , i)) < f (w(S l , i + 1)) holds for all i ≥ N , so the first condition of the theorem is met.
Suppose otherwise that no such S l exists. In particular, for every S l there is at least one j such that f j (w({s}, i)) = f j (w({s}, i + 1)) for all i ≥ N and all s ∈ S l , hence f j (w(S l , i)) = f j (w(S l , i + 1)) for all i ≥ N . For every S l let X l ⊆ {1, . . . , m} be the set of indices j such that f j (w(S l , i)) = f j (w(S l , i + 1)) for all i ≥ N . By the above assumptions, every X l is non-empty. Since k ≥ N > m there exists l 1 , l 2 such that X l 1 ∩ X l 2 = ∅. From Lemma 4.4 it follows that for i ≥ N it holds: f j (w(S l 1 ∪ S l 2 , i)) = f j (w(S l 1 ∪ S l 2 , i + 1)) for all j ∈ X l 1 ∩ X l 2 ; and f j (w(S l 1 ∪ S l 2 , i)) < f j (w(S l 1 ∪ S l 2 , i + 1)) for all j ∈ {1, . . . , m} \ (X l 1 ∩ X l 2 ). Hence for i sufficiently large f (w(S l 1 ∪ S l 2 , i)) = min j∈X l 1 ∩X l 2 (f j (w(S l 1 ∪ S l 2 , i))) = f (w(S l 1 ∪ S l 2 , i + 1)), which concludes the proof.

Poly-ambiguous recognisable functions over the min-plus semiring
In this section we focus on polynomial-ambiguously recognisable functions over N min,+ . We expect that there is a wider class of functions, definable like in the previous section, where Theorem 5.1 holds, but this is left for future work. A consequence of this section is that WA are strictly more expressive than PA-WA (see Examples 5.2 and 5.3).
We will use in the following the notation of n-pumping representations from Section 4. A sequence of non-empty sets S 1 , . . . , S m over {1, . . . , n} is called a partition if the sets are pairwise disjoint and their union is {1, . . . , n}. Furthermore, we say that S ⊆ {1, . . . , n} is a selection set for S 1 , . . . , S m if |S ∩ S i | = 1 for every i. Theorem 5.1 (Pumping Lemma for polynomially-ambiguous automata). Let f : Σ * → N ∪ {∞} be a polynomial-ambiguously recognisable function over N min,+ . There exist N and a function ϕ : N → N such that for every n-pumping representation: where |v i | ≥ N for every i ≤ n, there exists a refinement: w = u 0 · y 1 · u 1 · y 2 · . . . u n−1 · y n · u n , such that for every partition π = S 1 , . . . , S m of {1, . . . , n} with m ≥ ϕ(max j (|S j |)), one of the following holds: • there exists j such that f (w(S j , i)) = f (w(S j , i + 1)) for all but finitely many i; • there exists a selection set S ⊆ {1, . . . , n} for π such that f (w(S, i)) < f (w(S, i + 1)) for all but finitely many i.
Example 5.2. We show that f 5 from Example 2.5 is not definable by any PA-WA. Indeed, let N and ϕ be the constant and the function from Theorem 5.1. Consider the following 2m-pumping representation: w = (a N · b N #) m where m ≥ ϕ(2) (here max i (|S i |) will be equal to 2). We index the j-th block of a's with j and the j-th block of b's with j . We define the subsets S 1 , . . . , S m as S j = {j, j }. Clearly, for all j we have f 5 (w(S j , i)) < f 5 (w(S j , i + 1)).
On the other hand for every selection set S we have f 5 (w(S, i)) = f 5 (w(S, i + 1)). Hence f 5 does not satisfy Theorem 5.1.
Example 5.3. The function f 5 in Example 2.5 is essentially the function f 2 from Example 2.2 applied to the subwords between the symbols #, where the outputs are aggregated with +. In a similar way one can define a min-plus automaton recognising f 6 (w) = i f 4 (w i ) for any w ∈ Σ * of the form w 0 #w 1 # . . . #w n with w i ∈ {a, b} * , where f 4 is the function computing the minimal block of b's from Example 2.4. We show that f 6 is not definable by PA-WA over N min,+ . Consider the following 2m-pumping representation: w = (b N · a · b N #) m where m ≥ ϕ(2) (here max i (|S i |) is again 2). As in Example 5.2, we index the first j-th block of b's with j and the second j-th block of b's with j , and we set S j = {j, j }, for 1 ≤ j ≤ m. Clearly, for all j we have f 6 (w(S j , i)) < f 6 (w(S j , i + 1)). On the other hand for every selection set S we have f 6 (w(S, i)) = f 6 (w(S, i + 1)). Hence f 6 does not satisfy Theorem 5.1 either.
Consider the set of matrices N Q×Q min,+ over the min-plus semiring. Recall that here ⊕ = min, = +, 0 = ∞, 1 = 0, and the product of matrices M, N ∈ N Q×Q min,+ is defined by M · N (p, q) = min r (M (p, r) + N (r, q)). Also, recall that for any M ∈ N Q×Q min,+ we denote bȳ M the homomorphic image of M into the finite monoid B Q×Q (see Section 2.2). Similar as in Section 3 and Section 4, we say that D ∈ N Q×Q min,+ is an idempotent ifD is an idempotent in the finite monoid B Q×Q .
The following lemma states a special property of polynomially-ambiguous automata that we exploit in the proof of Theorem 5.1.
Lemma 5.4. Let A = (Q, Σ, {M a } a∈Σ , I, F ) be a polynomially-ambiguous weighted automaton over the min-plus semiring. For every idempotent D ∈ {M w | w ∈ Σ * } and for every p, q ∈ Q, there exist constants c, d ∈ N min,+ and b ∈ N such that D b+i (p, q) = c · i + d for all i ≥ 0. Proof. We can viewD ∈ B Q×Q as the adjacency matrix of a graph. Now we show that the cycles of the directed graph defined byD can be only self-loops. Indeed, assume by contradiction that there exists a cycle passing through r, s ∈ Q with r = s thenD(r, s) = D(s, r) =D(r, r) =D(s, s) = 1 (becauseD is an idempotent). Since D ∈ {M w | w ∈ Σ * }, it can be verified that A cannot be polynomially-ambiguous [WS91]. Indeed, let w be the word such that D = M w . Then there are at least two different paths from r to r when reading w 2 . Hence when reading w 2n the number of paths is at least 2 n . Since all automata considered in this paper are trimmed the state r is both accessible and co-accessible. Hence for every n there is a word of length linear in n with at least 2 n accepting runs. This is a contradiction with the assumption that A is polynomially-ambiguous. We conclude thatD forms an acyclic graph with some self-loops and the states in Q can be ordered as p 1 , . . . , p n , such thatD(p j , p i ) = +∞ for every i < j.
If D(p, q) = +∞ then it suffices to take c = d = +∞ since D is an idempotent. Otherwise, , where the minimum is over all sequences (j k ) i k=0 such that p j 0 = p, p j i = q. Since D(p, q) < +∞ we can restrict to sequences such that D(p j k−1 , p j k ) < +∞ for all k. Let A i be the set of indices such that k ∈ A i if: 0 < k ≤ i; D(p j k−1 , p j k ) < +∞; and p j k−1 = p j k . SinceD is acyclic it follows that |A i | ≤ |Q|. In particular this means that the number of possible sets A i depends only on |Q|, not on i. Suppose a sequence (j k ) i k=0 is a witness for the value of D i (p, q). Let k ∈ A i such that 0 < k ≤ i. Then D(p j k , p j k ) ≤ D(p js , p js ) for all 0 < s ≤ i. Thus we can modify (j k ) i k=0 into a witness such that for all k ∈ A i such that k > 0 the states p j k are all the same. We denote this state p j . Notice that for i big enough the value of D i (p, q) depends mostly on D(p j , p j ). Then p j can be only one of the states r such that c = D(r, r) is minimal. In particular c does not depend on i.
Therefore for i big enough, denoted i ≥ i 0 , this sum is achieved for A i such that d i − c · |A i | is minimal. Since the number of different A i is bounded we can assume that A i and d i do not depend on i, for i ≥ i 0 , and denote them A and d , respectively.
The lemma follows by fixing c as above, b = |A| + i 0 , and d = d + c · i 0 .
Proof of Theorem 5.1. Consider a polynomially-ambiguous WA A = (Q, Σ, {M a } a∈Σ , I, F ) over N min,+ such that f = A . We take for N the constant from Lemma 2.6 for the finite monoid B Q×Q . The function ϕ : N → N will be determined later in the proof. Consider an n-pumping representation w like in the statement of the theorem. By Lemma 2.6, for every v k there exists a factorisation v k = x k y k z k such that M y k is an idempotent and |y k | ≤ N . We denote D k = M y k and define: w = u 0 · y 1 · u 1 · y 2 · . . . u n−1 · y n · u n such that each word y k is the factor of v k corresponding to the idempotent D k . In the remainder of the proof we denote w ≤k = u 0 · y 1 · . . . u k−1 . For every S ⊆ {1 . . . n} we denote by w ≤k (S, i) the word w ≤k with all y j pumped i times for all j < k such that j ∈ S.
Recall that Run A (w) is the set of all accepting runs on w, and let ρ ∈ Run A (w). Every run induces two states for each 1 ≤ k ≤ n: states preceding and following each word y k . In the rest of the proof these will be the most important parts of a run. To work with them, we define the abstraction of ρ, denoted byρ : {1, . . . , n} → Q × Q, such thatρ(k) = (p, q) where p and q are the states of ρ reached after w ≤k and w ≤k · y k , respectively. Similarly, for S ⊆ {1, . . . , n}, i ≥ 1, and ρ ∈ Run A (w(S, i)) we defineρ : {1, . . . , n} → Q × Q such that ρ(k) = (p, q) where p and q are the states of ρ reached after w ≤k (S, i) and w ≤k (S, i) · y k (S, i), respectively. We denote by Run A (w) the set of allρ with ρ ∈ Run A (w), and same for Run A (w(S, i)). Observe that since all D k are idempotents, Run A (w(S, i)) = Run A (w) for all subsets S and i ≥ 1. The next step is to prove that the cardinality of Run A (w) is bounded by a polynomial P (·) depending only on A, namely such that |Run A (w)| ≤ P (n). Let w be the word obtained from w where each u i is replaced with a word u i of length at most |B Q×Q | such that M u i = M u i . To see that u i exists suppose that u i = a 1 . . . a s and s > |B Q×Q |. By the pigeonhole principle in the sequence of matrices M a 1 , M a 1 a 2 , . . . , M a 1 ...as there is a repetition that can be removed giving a shorter u i such thatM u i = M u i . Then | Run A (w )| ≥ |Run A (w)|. Recall that |y i | ≤ N and that N depends only on B Q×Q . Then by definition |w | ≤ (N + |B Q×Q |) · (n + 1) and thus | Run A (w )| ≤ R((N + |B Q×Q |) · (n + 1)), where R is the polynomial bounding the number of runs in A. Recall that A is polynomially-ambiguous. The claim follows for P (n) = R((N + |B Q×Q |) · (n + 1)).
Fix a non-empty set S ⊆ {1, . . . , n} and a run ρ ∈ Run A (w). For every k ∈ S let b k ρ , c k ρ and d k ρ be the constants from Lemma 5.4 such that D such that c k ρ = 0 for every k ∈ S; (2) A (w(S, i)) < A (w(S, i + 1)) for all sufficiently large i iff for every run ρ ∈ Run A (w) there exists k such that c k ρ > 0. Since the number of different b k ρ is bounded we can assume that they are all equal to some i 0 by choosing the maximal b k ρ . Let ρ ∈ Run A (w(S, i + 1)) be a run realising the minimum value for i ≥ i 0 . Given that D k is idempotent one can obtain a run ρ ∈ Run A (w(S, i)) such thatρ =ρ by removing one copy of each y k . In particular |ρ | ≤ |ρ|, which proves A (w(S, i)) ≤ A (w(S, i + 1)). It follows that it suffices to show (1) above.
To prove (1) suppose first that A (w(S, i)) = A (w(S, i + 1)) for all sufficiently large i. Let ρ ∈ A(w(S, i + 1)) and ρ ∈ A(w(S, i)) be the previous runs realising the minimum on w(S, i + 1) and its shortening, respectively. By Lemma 5.4 D i 0 +i+1 k [ρ(k)] = c k ρ · (i + 1) + d k ρ . If c k ρ > 0 for some k then the inequality A (w(S, i 0 + i)) ≤ A (w(S, i 0 + i + 1)) would be sharp, which is a contradiction. For the other direction suppose there exists a run ρ ∈ Run A (w) such that c k ρ = 0 for every k ∈ S. Then for every i ≥ 0 there exists a run ρ i ∈ Run A (w(S, Given the previous discussion, letR k = {ρ ∈ Run A (w) | c k ρ > 0} for every k ∈ {1, . . . , n}. The setR k represents the abstractions of the runs over w that will grow when pumping w({k}, i). Then, we can restate (2) as: A (w(S, i)) < A (w(S, i + 1)) for all sufficiently large i iff k∈SR k = Run A (w).
We are now ready to prove the theorem. Fix a partition S 1 , . . . , S m of {1, . . . , n} for some m ≥ ϕ(max |S l |) (ϕ will be defined below). Suppose the first condition is not true, namely, for all 1 ≤ j ≤ m there exist arbitrarily big values i such that f (w(S j , i)) = f (w(S j , i + 1)). From (2) it follows that f (w(S j , i)) < f (w(S j , i + 1)) for all sufficiently large i and k∈S jR k = Run A (w) for every j ≤ m. Let L = max |S l |. We assume that L > 1, otherwise every selection S contains a whole set S k for some k and we are done. To construct the selection set S = {k 1 , . . . , k m } we define by induction the sets G j . For every j ∈ {1, . . . , m} let G j = Run A (w)\ l≤jR k l (where k 0 is undefined, so G 0 = Run A (w)). Intuitively, G j correspond to runs that are not covered by the set {k 1 , . . . , k j }. For the inductive case, suppose that j ≥ 0 and G j = ∅. Since k∈S j+1R k = Run A (w), by the pigeonhole principle there exist k j+1 ∈ S j+1 such that |R k j+1 ∩G j | ≥ |G j |/|S j+1 |. We add k j+1 to S and so |G j+1 | ≤ |G j |−|G j |/|S j+1 | = |G j |·(|S j+1 |−1)/|S j+1 | ≤ |G j |·(L−1)/L. Suppose this procedure continues until j = m and G m = ∅. Then 1 ≤ |Run A (w)| · ((L − 1)/L) m , and |Run A (w)| ≥ (L/(L − 1)) m . However, we know that |Run A (w)| is bounded by a polynomial function P (n) depending on |A|. Thus, it suffices to choose ϕ such that m ≥ ϕ(L) implies (L/(L − 1)) m > P (L · m) ≥ P (n) ≥ |Run A (w))| (recall that S 1 , . . . , S m is a partition of {1, . . . , n} and L · m ≥ n). Therefore, G m = ∅ and thus k∈SR k = Run A (w), which concludes the proof.

Pumping lemmas for the max-plus semiring
In this section, we consider finitely ambiguous and polynomially ambiguous weighted automata over the N max,+ semiring. Notice that U-WA over N max,+ is the same class of functions as U-WA over N min,+ and thus Theorem 3.1 also holds for this class. For this reason, here we focus on the ambiguous cases, dividing the section into two parts to deal separately with the finitely ambiguous and polynomially ambiguous cases.
6.1. Pumping Lemma for Finitely Ambiguous Weighted Automata over N max,+ . We use the definitions of refinements and n-pumping representations from Section 3 and Section 4. In order to formulate the pumping lemma for finitely-ambiguous functions over the N max,+ semiring, we define a few more notations.
Fix a function f : Σ * → N and a word w ∈ Σ * . Suppose that we have an n-pumping representation for w, and a refinement thereof. Let {1, . . . , n} be the set of all indices in the refinement. We say that a refinement is linear if for every subset S ⊆ {1, . . . , n}, there exists K such that f (w(S, i + 1)) = K + f (w(S, i)) for all sufficiently large i. For linear refinements we let ∆(S) denote the above value K (note that ∆ depends on f and w, which are fixed). Furthermore, we say that S ⊆ {1, . . . , n} is decomposable if Theorem 6.1. Let f : Σ * → N be a finitely ambiguous function over the semiring N max,+ . There exists N ∈ N such that for every n-pumping representation where n ≥ N and and |v i | ≥ N for all i, there exists a linear refinement w = x 0 · y 1 · x 1 · y 2 · . . . y n · x n such that for every sequence of pairwise different, non-empty sets S 1 , S 2 , . . . S k ⊆ {1, . . . , n} with k ≥ N , one of the following holds: • there exists j such that S j is not decomposable; • there exist j 1 and j 2 such that {l 1 , l 2 } is decomposable for every l 1 ∈ S j 1 and l 2 ∈ S j 2 .
Before proving the theorem we show how to use the pumping lemma on two examples. Example 6.2. Consider the function g 3 which computes max 0≤i≤n |a 1 . . . a i | a + |a i+1 . . . a n | b , for any w = a 1 . . . a n ∈ {a, b} * . This is defined by a small modification of W 3 in Figure 1. The weights of the transitions changing the states is modified to 1 and the semiring is changed from N min,+ to N max,+ . We show that this function cannot be expressed by any finitely ambiguous WA over N max,+ . Towards a contradiction fix N from Theorem 6.1 and consider the (2N + 2)-pumping representation (a N +1 b N +1 ) N +1 . In the refinement, we index the j-th block of a's with j and the j-th block of b's with j . Let x 1 , . . . , x N +1 and y 1 , . . . , y N +1 be the lengths of all blocks of a's and b's in the refinement. We define the sets S j = {j, j } for all 1 ≤ j ≤ N + 1. We show that none of the conditions of the pumping lemma hold. First, it is easy to see that all sets S j are decomposable. Indeed ∆(S j ) = x j + y j = ∆({j}) + ∆({j }).
For the second condition we can assume that j 2 > j 1 . Since the function counts a's before b's, the set {j 1 , j 2 } is not decomposable because ∆({j 1 , j 2 }) = max(y j 1 , x j 2 ). Thus, any S j 1 and S j 2 will not satisfy the second condition either.
Example 6.3. Consider the function g 4 which computes the length of longest block of b's. This is defined by W 4 in Figure 1 if we change the semiring of the automaton from N min,+ to N max,+ . We shall show that g 4 cannot be expressed by a FA-WA over N max,+ . Towards a contradiction let N be the constant from Theorem 6.1. Consider the (N + 1)-pumping representation (b N +1 a) N +1 . We define the sets S j = {j} for all 1 ≤ j ≤ N + 1. First, each set is also decomposable for trivial reasons. Second, every index is not decomposable with any other since the function takes into account the value of at most one block of b's.
Proof of Theorem 6.1. Let A be the finitely ambiguous WA that computes f . Suppose that A has ambiguity at most m. Let N = max{K, m + 1} such that K is the constant from Lemma 2.6 applied to B Q×Q . Now, consider a word w and an n-pumping representation of w according to the theorem. Since each v j in the representation has length more than K we can refine every v j to y j such that everyM y j is an idempotent. We prove that this refinement is linear. Fix S ⊆ {1, . . . , n}. We prove that f (w(S, i + 1)) = K + f (w(S, i)) such that K does not depend on i for all i big enough. Consider i > |Q|. Let ρ be an accepting run over w(S, i). For every j ∈ S let p j,0 be the state in the run ρ before reading y j and p j,1 , . . . p j,i the states after reading y j the respective amount of times. Notice that by definitionM y j (p j,s , p j,s+1 ) = 1 for all s ∈ {0, . . . , i − 1}. We will need some observations that follow from the assumption that A is finitely-ambiguous.
First, let 0 ≤ s < s ≤ i such that p j,s = p j,s . We prove that p j,s = p j,s for all s ≤ s ≤ s . Since ρ is an accepting run andM y j is idempotentM y j (p j,s , p j,s ) =M y j (p j,s , p j,s ) = 1 for all s ≤ s ≤ s . Therefore, if there exists s such that p j,s = p j,s then there would be two different accepting runs from p j,s to p j,s when reading (y j ) 2 (with p j,s or p j,s in the middle). This contradicts the EDA criterion in [WS91] (by pumping (y j ) 2 one could generate arbitrary many accepting runs).
To state the second property we introduce some notation. We say that (s, s ) is a maximal cycle in p j,0 , . . . , p j,i if 0 ≤ s < s ≤ i, p j,s = p j,s and p j,s−1 = p j,s , p j,s = p j,s +1 (the last condition is required for s > 0 and s < i). We prove that there is at most one maximal cycle in every p j,0 , . . . , p j,i . Suppose otherwise that there are 0 ≤ s < s < t < t ≤ i such that (s, s ) and (t, t ) are maximal cycles. Since ρ is an accepting run andM y j is idempotentM y j (p j,s , p j,s ) =M y j (p j,s , p j,t ) =M y j (p j,t , p j,t ) = 1. This contradicts the IDA criterion in [WS91], i.e. for every k when reading when reading (y j ) k there would be at least k runs from s to t. We conclude that every run ρ over w(S, i) has a unique maximal cycle in every block j ∈ {1, . . . , n}. Notice that the number of accepting runs over w(S, i + 1) can only increase compared to the number of runs over w(S, i) since every accepting run ρ over w(S, i) can be prolonged by increasing the maximal cycle. Recall that A is finitely-ambiguous. Therefore, for i big enough the number of accepting runs over w(S, i) and w(S, i + 1) will be always the same. We denote this number by m.
We say that a cycle ) for all l . The rest of the proof involves reasoning about the dominant cycles. First we make a simple observation. Suppose ρ l [j] is dominant, then wt(ρ l [j]) = ∆({j}). We make one more observation.
Claim 6.4. Assume that we have a linear refinement and S ⊆ {1, . . . , n} is a subset of indices of the refinement. Then S is decomposable if and only if there exists some run ρ such that for all j ∈ S, ρ[j] is dominant.
Proof. Assume first that S is decomposable, and consider some run ρ such that j∈S wt(ρ[j]) is maximal among all runs on w. We claim that ρ[j] is dominant for all j ∈ S. Assume this is not the case. Notice that the value computed by the automaton increases by j∈S wt(ρ[j]) when S is pumped in ρ. By the choice of ρ and the fact that the refinement is linear, we have that ∆(S) = j∈S wt(ρ[j]). By assumption we know that there is some j * ∈ S such that ρ is not dominant for j * , so wt(ρ[j * ]) < ∆({j * }). But this means that ∆(S) = j∈S wt(ρ[j]) < j∈S ∆({j}), which is a contradiction to S being decomposable.
For the reverse implication, consider a run ρ such that ρ[j] is dominant for all j ∈ S. In particular, j∈S wt(ρ[j]) ≥ j∈S wt(ρ [j]) for any other run ρ . This means that when the set S is pumped, the value computed by the automaton increases by j∈S wt(ρ[j]), which also happens to be j∈S ∆({j}) since the cycles in consideration are dominant.
To conclude we show that if the first condition of the pumping lemma does not hold then the second condition must hold. Indeed, suppose that all sets are decomposable. Then by Claim 6.4 for every set S j there is some run ρ l j in which all the cycles corresponding to S j are dominant. But since there are more sets than runs, there must be some j 1 = j 2 such that l j 1 = l j 2 , namely, two sets which have the same corresponding runs. However, by Claim 6.4 this means that {k 1 , k 2 } is decomposable for every k 1 ∈ S j 1 and k 2 ∈ S j 2 .
6.2. Pumping Lemma for Polynomially Ambiguous Weighted Automata over N max,+ . In this section, we will re-use the definition of linear refinement and decomposability from the previous section. We will also re-use the definition of selection set from Section 5. Theorem 6.5. Let f : Σ * → N be a polynomial-ambiguously recognisable function over N max,+ . There exist N and a function ϕ : N → N such that for all n-pumping representations where |v i | ≥ N for every 1 ≤ i ≤ n, there exists a linear refinement w = u 0 · y 1 · u 1 · y 2 · · · u n−1 · y n · u n , such that for every partition π = S 1 , S 2 , . . . S m of {1, . . . , n} with m ≥ ϕ(max j (|S j |)) one of the following holds: • there exists j such that S j is decomposable; • there exists a selection set S for π such that S is not decomposable.
Before proving this lemma, we show how to use it on examples.
Example 6.6. Consider the function g 5 such that, for any w of the form w 0 #w 1 # . . . #w n with w i ∈ {a, b} * it computes g 5 (w) = n i=0 max{|w i | a , |w i | b }. This is defined by W 5 in Figure 1 if we change the semiring of the automaton to N max,+ . We show that g 5 cannot be expressed by a PA-WA. Assume the contrary and let N and ϕ be the constant and the function from Theorem 6.5. Let m be a number larger than ϕ(2). We consider the refinements of the pumping representation (a N b N #) m . In the refinement, we refer to the j-th block of a's as j and to the j-th block of b's as j . We define the sets in the partition as S j = {j, j } for all 1 ≤ j ≤ m. It is clear from the definition of the function g 5 that no set S j is decomposable, since only one of the blocks j and j is relevant for the outer sum. Now, consider any selection set S. Since any two elements of S belong to different blocks of the word separated by #'s, S is a decomposable set of indices. Therefore, the function g 5 is not polynomially ambiguous over N max,+ .
Example 6.7. Consider the function g 6 that given a word of the form w 0 #w 1 # . . . #w n with w i ∈ {a, b} * computes g 6 (w) = n i=0 g 3 (w i ), where g 3 from Example 6.2. We show now that g 6 cannot be expressed as a PA-WA over N max,+ . Assume the contrary and let N and ϕ be the constant and the function from the lemma above. Let m be a number larger than ϕ(2). We consider the refinements of the pumping representation (b N a N #) m . Like in Example 6.6 in the refinement we refer to the j-th block of b's as j and to the j-th block of a's as j . Let x j and y j be the lengths of the block of b's and the block of a's, respectively. We define the sets in the partition as S j = {j, j } for all 1 ≤ j ≤ m. Every set S j is not decomposable since ∆(S j ) = max(x j , y j ). Consider any selection set S of π. It is easy to see that S is decomposable given that all elements belong to different blocks. We conclude that g 6 cannot be defined by PA-WA over N max,+ .
Proof of Theorem 6.5. The first part of the proof is the same as in the proof of Theorem 5.1 which only depends on the (polynomial) ambiguity of the automaton, and not on the semiring. We will use the same same notation for the refinement (y k ) k and in particular, all D k = M y k are idempotents. We will also use the notation Run A (w) of abstractions of runs and the notationρ : {1, . . . , n} → Q × Q. Finally recall from the proof of Theorem 5.1 that |Run A (w)| ≤ P (n) for some polynomial P (·).
We will also reuse Lemma 5.4, but over the N max,+ semiring. One can easily check that this lemma continues to hold over the max-plus semiring. The difference is that then c, d ∈ N max,+ . Therefore, for every k ∈ S let b k ρ(k) , c k ρ(k) and d k ρ(k) be the constants from Lemma 5.4 such that: for i ≥ 0. Since ρ is accepting, we have c k ρ(k) , d k ρ(k) = −∞. First, we argue that the refinement defined by (y k ) k is linear. Fix a non-empty set S ⊆ {1, . . . , n}. Forρ ∈ Run A (w) let cρ = k∈S c k ρ(k) . Recall that every run in Run A (w(S, i)) has some abstraction in Run A (w) and A outputs the maximal value among all runs. It follows by considering i big enough that ∆(S) = max{cρ |ρ ∈ Run A (w)}.
Claim 6.8. Assume that we have a linear refinement and S ⊆ {1, . . . , n} is a subset of indices of the refinement. Then S is decomposable if and only if there exists ρ such that for all j ∈ S, ρ[j] is j-dominant.
Proof. Follows the same steps as the proof of Claim 6.4. By Claim 6.8, S is not decomposable if and only if k∈SR k = Run A (w).
We are ready to prove the theorem. Fix a partition S 1 , . . . , S m for some m ≥ ϕ(max l |S l |). Suppose the first condition is not true, namely, for every j, the set S j is not decomposable. Let L = max l |S l |. Since no set S l is decomposable we know that L > 1. By the observations in the previous paragraph it suffices to construct a selection set S such that k∈SR k = Run A (w), which will imply that S is not decomposable.

Conclusion
We have shown five pumping lemmas for five different classes of functions. We believe that the pumping lemmas in Section 5 and in Section 6 could be proved for a wider class of functions that would contain the class N +,× , but this is left for future work. As a corollary of our results, we showed that recognisable functions over N min,+ and N max,+ form a strict hierarchy, namely: U-WA FA-WA PA-WA WA.

7:20
A. Chattopadhyay, F. Mazowiecki, A. Muscholl, and C. Riveros Vol. 17:3 All strict inclusions, except for PA-WA WA, could be extracted from the analysis of examples in [KLMP04]. However, our results provide a general machinery to prove such results.