On the complexity of the universality and inclusion problems for unambiguous context-free grammars (technical report)
aa r X i v : . [ c s . F L ] J un To appear in EPTCS. c (cid:13)
L. ClementeThis work is licensed under theCreative Commons Attribution License.
On the complexity of the universality and inclusion problemsfor unambiguous context-free grammars(Invited Paper)
Lorenzo Clemente
Department of Mathematics, Informatics, and Mechanics (MIMUW)University of Warsaw (Warsaw, Poland) ∗ [email protected] We study the computational complexity of universality and inclusion problems for unambiguousfinite automata and context-free grammars. We observe that several such problems can be reduced tothe universality problem for unambiguous context-free grammars. The latter problem has long beenknown to be decidable and we propose a
PSPACE algorithm that works by reduction to the zeronessproblem of recurrence equations with convolution. We are not aware of any non-trivial complexitylower bounds. However, we show that computing the coin-flip measure of an unambiguous context-free language, a quantitative generalisation of universality, is hard for the long-standing open problem
SQRTSUM . The purpose of this note is to attract attention to a long-standing open problem in formal language theory.The problem in question is the exact complexity of deciding universality of unambiguous context-freegrammars (
UUCFG ). A context-free grammar is unambiguous if every accepted word admits a uniqueparse tree, and the universality problems asks, for a given grammar G over a finite set of terminals Σ (alphabet), whether G accepts every word L ( G ) = Σ ∗ . While the universality problem for context-free grammars is undecidable [19], the same problem for unambiguous grammars is long-known to bedecidable (a corollary of [29, Theorem 5.5]), e.g., by reducing to the first-order theory of the reals withone quantifier alternation [29, eq. (3), page 149]. Since the latter fragment is decidable in EXPTIME [16], this yields an
EXPTIME upper bound for
UUCFG . No non-trivial lower bound for
UUCFG seemsto be known in the literature.The typical way to solve a containment problem of the form L ⊆ M is to complement M and solve L ∩ ( Σ ∗ \ M ) = /0. For instance, when L is regular and M is deterministic context-free (DCFG), this gives a PTIME procedure since DCFG languages are efficiently closed under complement and intersection withregular languages, and their emptiness problem is in
PTIME . However, UCFG languages are not closedunder complement (the complement is not even context-free in general [18]), so the language-theoreticapproach is not available. As Salomaa and Soittola remark in their book from 1978, “no proof is knownfor Theorem 5.5 which uses only standard formal language theory”. To this day, we are not aware of aproof of decidability for
UUCFG using different techniques . The UUCFG problem is not isolated in thisrespect. ∗ This work has been partially supported by the Polish NCN grant 2017/26/D/ST6/00201. This is a technical report of aninvited paper of the same title to appear in the proceedings of VPT 2020. In a later book, Kuich and Salomaa reprove decidability [23, Corollary 16.25] by using variable elimination, which isarguably closer to algebraic geometry than formal languages.
Complexity ofthe universality problem for unambiguous context-free grammars ⊆ DFA UFA NFA DCFG UCFG CFGDFA
PTIME PTIME PSPACE -c. [26]
PTIME = UUCFG (Th. 8) undec.UFA
PTIME PTIME [33]
PSPACE -c. [26]
PTIME = UUCFG (Th. 8) undec.NFA
PTIME PTIME (Th. 7)
PSPACE -c. [26]
PTIME = UUCFG (Th. 8) undec.DCFG
PTIME ≤ UUCFG (Th. 9)
EXPTIME -c. [20] undec. undec. undec.UCFG
PTIME ≤ UUCFG (Th. 9)
EXPTIME -c. [20] undec. undec. undec.CFG
PTIME ≤ UUCFG (Th. 9)
EXPTIME -c. [20] undec. undec. undec.“ ≤ UUCFG ”: the problem reduces in
PTIME to UUCFG .“ = UUCFG ”: the problem is
PTIME inter-reducible with
UUCFG .Figure 1: Inclusion problems for various classes of regular and context-free languages.
State of the art.
Let A , B be two classes of language acceptors. Examples include deterministic(DFA), unambiguous (UFA), and nondeterministic finite automata (NFA), and similarly for context-freegrammars we have the classes DCFG, UCFG, and CFG. The “ A ⊆ B ” inclusion problem asks, given alanguage acceptor A from A and B from B , whether the languages they recognise satisfy L ( A ) ⊆ L ( B ) .A summary of decidability and complexity result for inclusion problems involving finite automata andgrammars is presented in Fig. 1. Many entries in the table are well-known. The problem NFA ⊆ NFA isa classic
PSPACE -complete problem [26]. The problem UFA ⊆ UFA was shown in
PTIME by Stearnsand Hunt in their seminal paper [33] . The fact that CFG ⊆ NFA is
EXPTIME -complete is somewhatless known [20, Theorem 2.1]. The inclusion problems A ⊆ UFA when B is DCFG, UCFG, or CFG donot appear to have been studied before. The A ⊆ B problem is undecidable as soon as both A , B arecontext-free grammars, since DCFG ⊆ DCFG is well-known to be undecidable [19, Theorem 10.7, Point2]. We have already observed that NFA ⊆ DCFG is in
PTIME . The equivalence problem NFA = UCFGis shown to be decidable in [29, Theorem 5.5], although no complexity bound is given. The more generalinclusion NFA ⊆ UCFG does not seem to have been studied before.
Contributions.
We establish several connections between inclusion problems A ⊆ B when B is UFAor UCFG with the UUCFG problem. Our contributions are as follows.1. We observe that in many cases the inclusion problem L ⊆ M reduces in polynomial time to the sub-case where L is deterministic (Section 3.1.1). One application is lower bounds: Once we know thatCFG ⊆ NFA is
EXPTIME -hard [20, Theorem 2.1], we can immediately deduce that the same lowerbound carries over to DCFG ⊆ NFA [20, Theorem 3.1].2. We observe that in many cases the inclusion problem L ⊆ M with L deterministic reduces in poly-nomial time to the universality problem (Section 3.1.2). One application is upper bounds (combinedwith the previous point): For instance, from the fact that UFA = Σ ∗ is in PTIME we can deduce thatthe more general problem NFA ⊆ UFA is also in
PTIME (Theorem 7), which seems to be a newobservation.3. We apply the last two points to show that the following inclusion problems A ⊆ B reduce to UUCFG : A ∈ { DCFG , UCFG , CFG } and B = UFA (Theorem 9); A ∈ { DFA , UFA , NFA } and B = UCFG(Theorem 8). Since
UUCFG is a special instance of the latter set of problems, they are
PTIME inter-reducible with
UUCFG . An incomparable NC upper bound for this problem is also known [25, Fact 4.5] (c.f. [35, Theorem 2]). .Clemente 34. We show that UUCFG is in
PSPACE (Theorem 10), which improves the
EXPTIME upper bound thatcan be extracted from [29]. A
PSPACE upper bound for the same problem has also been shown byS. Purgał in his master thesis [28, Section 3.7].5. We complement the upper bound in the previous point by showing that computing the so-called coin-flip measure of a UCFG (a quantitative problem generalising universality; c.f. Section 4) is
SQRT-SUM -hard (Theorem 11). The latter is a well-known problem in the theory of numerical computation,which is not known to be in NP or NP -hard [1, 13].The generic and simple polynomial time reductions of points 1. and 2. above do not seem to be knownin the literature. Beyond the seminal work on UFA [33], they also apply to very recent contributions onexpressive models such as unambiguous register automata (c.f. [27] for equality atoms) and unambiguousfinite and pushdown Parikh automata [4]. In each of the cases above, one can reduce from inclusion touniversality. A non-example where the reduction cannot be applied is unambiguous Petri-nets withcoverability semantics [8].The PSPACE upper bound on
UUCFG is obtained by reduction to a more general counting probleminteresting on its own. We introduce a natural class of number sequences f : N → N which we call convolution recursive (conv-rec). Examples include the Fibonacci F ( n + ) = F ( n ) + F ( n − ) andCatalan numbers C ( n + ) = ( C ∗ C )( n ) , where “ ∗ ” denotes the convolution product. We show that thefunction counting the number of words in L ( G ) of a given length is conv-rec if G is UCFG. (This resultis analogous to the well-known fact that UCFG have algebraic generating functions [7].) The zeronessproblem asks whether such a sequence is identically zero. Our last contribution is a complexity upper-bound for the zeroness problem of conv-rec sequences.6. We show that the zeroness problem of conv-rec sequences is in PSPACE (Theorem 4). We expressthis problem with a formula in the existential fragment for first-order logic over the reals, which canbe decided in
PSPACE [6].
Convolution recursive sequences.
Let N , Z , Q , and R be the sets of natural, resp., integer, rational,and real numbers. Let Q [ x , . . . , x k ] denote the ring of polynomials with coefficients from Q and variables x , . . . , x k . For two sequences indexed by natural numbers f , g : N → R , their sum f + g is the sequence ( f + g )( n ) = f ( n ) + g ( n ) , and their convolution is the sequence ( f ∗ g )( n ) = ∑ nk = f ( k ) · g ( n − k ) . Theconvolution operation is associative f ∗ ( g ∗ h ) = ( f ∗ g ) ∗ h , commutative f ∗ g = g ∗ f , has as (left andright) identity the sequence 1 , , , . . . , and distributes over the sum operation ( f + g ) ∗ h = f ∗ g + g ∗ h .Thus, sequences with the operations “ + ” and “ ∗ ” form a semiring. Let σ : ( N → R ) → ( N → R ) be the (forward) shift operator on sequences, which is defined as ( σ f )( n ) = f ( n + ) . The zeroness problemfor a sequence f : N → R amounts to decide whether f ( n ) = n ∈ N .A convolution polynomial p ( x , . . . , x k ) is a polynomial where the multiplication operation is in-terpreted as convolution and a constant k ∈ Q is interpreted as the sequence k , , , . . . . For example,4 ∗ ( x ∗ x ) + ∗ ( x ∗ x ) is a convolution polynomial of two variables x , x . Let Q ∗ [ x , . . . , x k ] denotethe ring of convolution polynomials with variables x , . . . , x k . A sequence f : N → R is convolution re-cursive ( conv-rec ) if there are k auxiliary sequences f , . . . , f k : N → R with f = f and k convolution Complexity ofthe universality problem for unambiguous context-free grammarspolynomials p , . . . , p k ∈ Q ∗ [ x , . . . , x k ] s.t., σ f = p ( f , . . . , f k ) , ... σ f k = p k ( f , . . . , f k ) . (1)The combined degree of the representation above is the sum of the degrees of p , . . . , p k . For example,the Catalan numbers C : N → N are conv-rec (of combined degree two) since ( σ C )( n ) = ( C ∗ C )( n ) . Lemma 1.
Let f : N → R be a conv-rec sequence of combined degree ≤ d. Then lim n → ∞ f ( n + ) f ( n ) = O ( d ) .Proof. The maximal relative growth f ( n + ) f ( n ) of a conv-rec sequence is achieved when f satisfies a re-currence of the form σ f = f ∗ · · · ∗ f ( d times) for some degree d ∈ N . If f ( ) =
1, then the resultingsequence is known as the Fuss-Catalan numbers [15] and it equals f ( n ) = (cid:0) d · n + n (cid:1) d · n + . It can be checkedby using Stirling’s approximation n ! ∼ √ π n (cid:0) ne (cid:1) n that lim n → ∞ f ( n + ) f ( n ) = d d ( d − ) d − = d · ( + d − ) d − . Thelatter quantity is upper bounded by d · e for every d ≥ Generatingfunctionology.
The formal power series (a.k.a. ordinary generating function ) associatedwith a number sequence a : N → R is the infinite polynomial g a ( x ) = ∑ ∞ n = a ( n ) · x n . Let [ x n ] g a denotethe coefficient a ( n ) of x n in g a . Let f , f , f : N → R be sequences. It is well known that g k ( x ) = k for k ∈ R , g f + f = g f + g f , g f ∗ f = g f · g f , and g f ( x ) = f ( ) + x · g σ f ( x ) . Consequently, if f isconv-recursive with auxiliary sequences f , . . . , f k , then their generating functions g f , . . . , g f k satisfy thefollowing system of polynomial equations g f ( x ) = f ( ) + x · ˆ p ( g f ( x ) , . . . , g f k ( x )) , ... g f k ( x ) = f k ( ) + x · ˆ p k ( g f ( x ) , . . . , g f k ( x )) . (2)where ˆ p i is the polynomial obtained from the convolution polynomial p i by replacing the convolutionoperation “ ∗ ” on sequences by the product operation “ · ” on real numbers. Thus, the generating function g f of a conv-rec sequence f is algebraic . Lemma 2.
The system of equations (2) has a unique formal power series solution.Proof.
By construction, g f = ( g f , . . . , g f k ) is a formal power series solution of (2). We now arguethat there is no other solution. Assume that g = ( g , . . . , g k ) is a solution of (2). We prove that, forevery n ∈ N , [ x n ] g = ([ x n ] g , . . . , [ x n ] g ) equals [ x n ] g f = ([ x n ] g f , . . . , [ x n ] g f k ) . The base case followsimmediately from (2), since [ x ] g i = f i ( ) by definition. For the inductive step n >
0, notice that 1) from(2) we have [ x n ] g i = [ x n ]( x · ˆ p i ( g )) = [ x n − ] ˆ p i ( g ) , and 2) the latter quantity is a (polynomial) function ofthe coefficients [ x i ] g for 0 ≤ i ≤ n −
1. By inductive assumption, [ x i ] g = [ x i ] g f for every 0 ≤ i ≤ n − [ x n ] g = [ x n ] g f . Lemma 3.
Let d be the combined degree of f = ( f , . . . , f k ) . The system (2) has a unique solutiong f ( x ∗ ) = ( g f ( x ∗ ) , . . . , g f k ( x ∗ )) ∈ R k for every ≤ x ∗ < d .Proof. Let g f = ( g f , . . . , g f k ) be the tuple of formal power series of the sequences f , . . . , f k . By Lemma 1,lim n → ∞ f i ( n + ) f i ( n ) = O ( d ) . Thus, g f ( x ∗ ) = ( g f ( x ∗ ) , . . . , g f k ( x ∗ )) ∈ R k converges for every 0 ≤ x ∗ < d . ByLemma 2, g f is the unique formal power series solution of (2)..Clemente 5 Theorem 4.
The zeroness problem for conv-rec sequences is in
PSPACE .Proof.
Let f be a conv-rec sequence of combined degree d with auxiliary sequences f , . . . , f k satisfying(1). Consider the associated generating functions g = ( g f , . . . , g f k ) . Clearly, f ( n ) = n ∈ N if,and only if, g f ( x ) = x sufficiently small. By Lemma 3, g ( x ∗ ) is the unique solution of (2) forevery 0 ≤ x ∗ < d . It thus suffices to say that, for every 0 ≤ x ∗ < d , all solutions g ( x ∗ ) of the system (2)satisfy g f ( x ∗ ) =
0. This can be expressed by the following universal first-order sentence over the reals(where ¯ y = ( y , . . . , y k ) ) ∀ (cid:18) ≤ x < d (cid:19) . ∀ ¯ y . ¯ y = f ( ) + x · ˆ p ( ¯ y ) → y = . The sentence above can be decided in
PSPACE by appealing to the existential theory of the reals [6,Theorem 3.3].
Let Σ be a finite alphabet. We denote by Σ ∗ the set of all finite words over Σ , including the empty word ε . A language is a subset L ⊆ Σ ∗ . The concatenation of two languages L , M ⊆ Σ ∗ is unambiguous if w ∈ L · M implies that w factors uniquely as w = u · v with u ∈ L and M ∈ v . A context-free grammar (CFG) is a tuple G = ( Σ , N , S , ← ) where Σ is a finite alphabet of terminal symbols , N is a finite set of nonterminal symbols , of which S ∈ N is the starting nonterminal symbol , and ← ⊆ N × ( N ∪ Σ ) ∗ is a setof productions. A CFG is in short Greibach normal form if productions are of the form either X ← ε . or X ← aY Z . An X -derivation tree is a tree satisfying the following conditions: 1) the root node ε is labelledby the nonterminal X ∈ X , 2) every internal node is labelled by a nonterminal from N , 3) whenever a node u has children u · , . . . , u · k there exists a rule Y ← w · · · w k with w i ∈ N ∪ Σ s.t. Y is the label of u and w i is the label of u · i , and 4) leaves are labelled with terminal symbols from Σ . The language recognised by a nonterminal X is the set L ( X ) of words w = a · · · a n ∈ Σ s.t. there exists an X -derivation tree withleaves labelled by (left-to-right) a , . . . , a n ; the language recognised by G is the language recognised bythe starting nonterminal L ( G ) = L ( S ) . A CFG G is unambiguous (UCFG) if for every accepted word w ∈ L ( G ) there exists exactly one derivation tree witnessing its acceptance. The universality problem( UUCFG ) asks, given a UCFG G , whether L ( G ) = Σ ∗ . In this section present
PTIME reductions from inclusion problems for NFA and UCFG to
UUCFG . Thisserves us as a motivation to study the complexity of
UUCFG in Section 3.2. We proceed in two steps. Inthe first step, we present a general l.h.s. determinisation procedure for inclusion problems (Section 3.1.1)which is widely applicable to essentially any machine-based model of computation. In the second step,assuming a deterministic l.h.s., we show a reduction from inclusion to universality (Section 3.1.2). Weapply these two reductions in Section 3.1.3.
It is an empirical observation that in many inclusion problems of the form L ⊆ M the major source ofdifficulty is with M and not with L . For example, for finite automata the inclusion problem is PSPACE -complete when M is presented by a NFA and in NLOGSPACE when it is presented by a DFA. In either Complexity ofthe universality problem for unambiguous context-free grammarscase, it is folklore that whether L is presented as a NFA or DFA does not matter. A more dramaticexample is given when L is regular and M context-free, since the inclusion above is undecidable when M is presented by a CFG and in PTIME when it is presented by a DCFG.In this section we give a formal explanation of this phenomenon by providing a generic reduction ofan inclusion problem as above to one where the l.h.s. L is a deterministic language. The reduction willbe applicable under mild assumptions which are satisfied by most machine-based models of languageacceptors such as finite automata, B ¨uchi automata, context-free grammars/pushdown automata, Petri-nets, register automata, timed automata, etc. For the language class of the r.h.s. M it suffices to haveclosure under inverse homomorphic images, and for the l.h.s. L it suffices that we can rename the inputsymbols read by transitions in a suitable machine model . Moreover, we argue that such transformationpreserves whether M is recognised by a deterministic or an unambiguous machine.Let Σ be a finite alphabet . Assume that L = L ( A ) ⊆ Σ ∗ is recognised by a nondeterministic machine A with transitions of the form δ = p a , op −−→ q ∈ ∆ A , where op is an optional operation that manipulatesa local data structure (a stack, queue, a tape of a Turing machine, etc...). The construction below doesnot depend on what op does. We assume w.l.o.g. that A is total , i.e., for every control location p andinput symbol a ∈ Σ there exists a transition of the form p a , −→ ∈ ∆ A . Consider a new alphabet Σ ′ = ∆ A ,together with the projection homomorphism h : Σ ′ → Σ that maps a transition δ = p a , op −−→ q ∈ ∆ A to itslabel h ( δ ) = a ∈ Σ . We modify A into a new machine A ′ by replacing each transition δ above with p δ , op −−→ q ∈ ∆ A ′ . Intuitively, A ′ behaves like A except that it needs to declare which transition δ it isactually taking in order to read a = h ( δ ) . By construction, A ′ is deterministic (in fact, every transitionhas a unique label across the entire machine) and L ( A ) = h ( L ( A ′ )) is the homomorphic image of L ( A ′ ) .We need to adapt the machine B recognising M = L ( B ) in order to preserve inclusion. For everytransition r a , op −−→ s ∈ ∆ B and for every δ = p b , op ′ −−−→ q ∈ ∆ A with b = a , we have in B ′ a transition r δ , op −−→ s ∈ ∆ B ′ . Intuitively, B ′ behaves like B except that it reads additional information on the transition takenby A ′ . This information is not actually used by B ′ during its execution but it is merely added in order tolift the alphabet from Σ to Σ ′ . We have L ( B ′ ) = h − ( L ( B )) is the inverse homomorphic image of L ( B ) .The following lemma states the correctness of the reduction. Lemma 5.
We have the following equivalence: L ( A ) ⊆ L ( B ) if, and only if, L ( A ′ ) ⊆ L ( B ′ ) . Proof.
By generic properties of images and inverse images we have the following two inclusions: L ( A ′ ) ⊆ h − ( h ( L ( A ′ ))) and h ( h − ( L ( B ))) ⊆ L ( B ) . (3)For the “only if” direction, if L ( A ) ⊆ L ( B ) holds, then h − ( L ( A )) ⊆ h − ( L ( B )) , which, by the definitionof A ′ and B ′ , is the same as h − ( h ( L ( A ))) ⊆ L ( B ′ ) . By (3), L ( A ′ ) ⊆ h − ( h ( A ′ )) ⊆ L ( B ′ ) , as required. Forthe “if” direction, if L ( A ′ ) ⊆ L ( B ′ ) holds, then also h ( L ( A ′ )) ⊆ h ( L ( B ′ )) holds. Similarly as above, wehave L ( A ) = h ( L ( A ′ )) ⊆ h ( L ( B ′ )) = h ( h − ( L ( B ))) ⊆ L ( B ) , as required.The following lemma states that the reduction above preserves whether B is deterministic or unam-biguous. We mean here the following generic semantic notion of unambiguity: B is unambiguous if forevery w ∈ Σ ∗ , there exists at most one accepting run of B over w . (This notion specialises to the classicalnotion of unambiguity of finite automata, pushdown automata, Parikh automata, etc.) The reduction applies also to undecidable instances of the language inclusion problem such as CFG ⊆ DCFG, however inthis case it is of no use since DCFG ⊆ DCFG is known to be undecidable [19, Theorem 10.7, Point 2]. The construction below can easily be adapted to infinite alphabets of the form Σ × A , where Σ is finite and A is an infiniteset of data values [3]. Languages of infinite words can be handled similarly. .Clemente 7
Lemma 6.
If B is deterministic, then so is B ′ . If B is unambiguous, then so is B ′ .Proof. A transition p δ , op −−→ q ∈ ∆ B ′ in B ′ is obtained taking several distinct copies of a transition p a , op −−→ q ∈ ∆ B in B w.r.t. every possible transition δ ∈ ∆ A over the same input symbol h ( δ ) = a . By way of contradic-tion, assume that B is deterministic and that B ′ is not deterministic. There are two distinct transitions p δ , op −−−→ q , p δ , op −−−→ q ∈ ∆ B ′ in B ′ from the same control location p and input δ ∈ Σ ′ . If δ is labelled by h ( δ ) = a ∈ Σ , then by construction there are two distinct transitions p a , op −−−→ q , p a , op −−−→ q ∈ ∆ B in B overthe same input symbol a . This contradicts the fact that B was assumed to be deterministic, and thus B ′ must be deterministic as well. An analogous argument shows that also unambiguity is preserved. Let L and M be two classes of languages and let L ∈ L and M ∈ M . A naive approach to decide theinclusion problem (and the most common) is to use the following equivalence: L ⊆ M if, and only if, L ∩ ( Σ ∗ \ M ) = /0 . (4)However, this requires complementation of M , which is either expensive (exponential complexity forNFA) or just impossible (context-free languages are not closed under complemenetation, even for theunambiguous subclass [18]). However, we observe the following related reduction which works muchbetter in our setting: L ⊆ M if, and only if, ( M ∩ L ) ∪ ( Σ ∗ \ L ) = Σ ∗ . (5)On the face of it, this looks more complicated than (4) because we now have to perform a complemen-tation (of L ), an intersection, a union, and finally we reduce to the universality problem instead of thenonemptiness, which is still difficult in general. However, in our setting there are gains. First of all,thanks to Section 3.1.1 we can assume that L is a deterministic language, and thus complementation isusually available (and cheap). Second, while universality is still a difficult problem, it can be easier thaninclusion, e.g., DCFG inclusion is undecidable while DCFG universality is decidable (even in PTIME ).In order to apply (5) we require that L is a deterministic class efficiently closed under complement(i.e., a representation for the complement is constructible in PTIME ) and that the class M is closed un-der disjoint unions and intersections with languages from L . Most deterministic languages classes, suchas those recognised by deterministic finte automata, deterministic context-free grammars, deterministicParikh automata, deterministic register automata, etc., satisfy the first requirement . The second require-ment is satisfied for classes of languages for which the underlying machine models admit a productconstruction . In this section we apply the reductions of Section 3.1.1 and Section 3.1.2 in order to reduce certaininclusion problems to their respective universality variant. A notable exception is deterministic Petri-net languages under coverability semantics, since the complement of suchlanguages intuitively requires checking whether some counter is negative, which is impossible without zero tests. In fact, ifboth a language and its complement are deterministic Petri-net recognisable under coverability semantics, then they are bothregular [9]. As an example not satisfying this requirement, one can take L = M to be the class of DCFL, since they are not closedunder intersection. In fact, while we show in this paper that UUCFG is decidable, the equivalence problem for UCFG is open.
Complexity ofthe universality problem for unambiguous context-free grammars
Theorem 7. “NFA ⊆ UFA” is in
PTIME . While equivalence and inclusion of UFA is well-known to be in
PTIME [33, Corollary 4.7], the samecomplexity for the more general problem “NFA ⊆ UFA” does not seem to have been observed before.
Proof.
By Section 3.1.1, the problem reduces to “DFA ⊆ UFA”. By (5), L ⊆ M is equivalent to N : = M ∩ L ∪ ( Σ ∗ \ L ) = Σ ∗ . Notice that N is effectively UFA, since the DFA language L can be complementedin PTIME , the intersection M ∩ L is also UFA and computable in quadratic time, and the disjoint unionof a UFA and a DFA is also a UFA computable in linear time. Since the universality problem forunambiguous automata can be solved in PTIME , also “DFA ⊆ UFA”, and thus “NFA ⊆ UFA”, is in
PTIME as well.
Theorem 8. “NFA ⊆ UCFG” is
PTIME inter-reducible with
UUCFG .Proof.
By Section 3.1.1, the problem reduces to “DFA ⊆ UCFG”. Thanks to Section 3.1.2, the latterproblem reduces to
UUCFG since 1) DFA languages are efficiently closed under complement (in
PTIME ),2) UCFG languages are efficiently closed under intersection with DFA languages (in
PTIME ), and 3) thedisjoint union of a UCFG language and a DFA language is a UCFG language. Thus, “NFA ⊆ UCFG”reduces to
UUCFG , and since
UUCFG is a special case of the former problem, “NFA ⊆ UCFG” is
PTIME inter-reducible with
UUCFG . Theorem 9. “CFG ⊆ UFA” reduces to
UUCFG .Proof.
By Section 3.1.1, “CFG ⊆ UFA” reduces to “DCFG ⊆ UFA”, which in turn reduces to
UUCFG thanks to Section 3.1.2 because 1) DCFG languages are efficiently closed under complement, 2) the in-tersection of a UFA and a DCFG language is efficiently DCFG, and 3) the disjoint union of two DCFGlanguages is efficiently UCFG. (The latter problem reduces to universality of two disjoint DCFG lan-guages, which in principle may be easier than
UUCFG .) UUCFG in PSPACE
In this section we show that
UUCFG is in
PSPACE by reducing to the zeroness problem for conv-rec se-quences. This complexity upper bound appears also in [28], albeit with a more direct argument reducingto systems of monotone polynomial equations.Let Σ = { a , b } be a finite alphabet and let L ⊆ Σ ∗ be a language of finite words over Σ . The countingfunction of L is the sequence f L : N → N s.t. for every n ∈ N , f L ( n ) = | L ∩ Σ n | counts the number ofwords of length n in L . Given a unambiguous context-free grammar G = ( Σ , N , S , ← ) in short Greibachnormal form, let f X : = f L ( X ) : N → N be the counting function of the language L ( X ) recognised bythe nonterminal X ∈ N . It is well-known that the f X ’s satisfy the following system of equations withconvolution: f X ( n + ) = ∑ X ← aY Z ( f Y ∗ f Z )( n ) . (6)The initial condition is f X ( ) = X ← ε and f X ( ) = f S , which is thecounting function of the language L ( G ) recognised by G , is conv-rec. Unambiguity is used crucially toshow that any word w in L ( Y · Z ) factorises uniquely as w = u · v with u ∈ L ( Y ) and v ∈ L ( Z ) , whichallows us to obtain f L ( Y · Z ) = f L ( Y ) ∗ f L ( Z ) ..Clemente 9Clearly, G is universal if, and only if, f S is identically equal to the sequence g ( n ) = n . The lattersequence is conv-rec since it satisfies g ( n + ) = ( g ∗ g )( n ) , with the initial condition g ( ) =
1. Thus G is universal if, and only if, f ( n ) = g ( n ) − f S ( n ) is identically zero. Since conv-rec sequences are closedunder subtraction, f ( n ) is also conv-rec. By Theorem 4, we can decide zeroness of f in PSPACE , andthus the same upper bound holds for
UUCFG . Theorem 10.
The universality problem for unambiguous context-free grammars
UUCFG is in
PSPACE . SQRTSUM -hardness of coin-flip measure
In this section we show that a quantitative generalisation of
UUCFG is hard for a well-known problemin numerical computing. Let Σ n = { a , . . . , a n } be a finite alphabet of n distinct letters. Consider thefollowing random process to generate a finite word in Σ ∗ . At step k we select one option a k ∈ Σ ε = Σ n ∪{ ε } uniformly at random. If a k = ε , then we terminate and we produce in output a · · · a k − . Otherwise,we continue to the next step k +
1. It is easy to see that the probability to generate a word depends onlyon its length and equals µ coin ( w ) = (cid:16) | Σ | + (cid:17) | w | + . The coin-flip measure of a language of finite words L ⊆ Σ ∗ is µ coin ( L ) = ∑ w ∈ L µ coin ( w ) . Clearly, 0 ≤ µ coin ( L ) ≤ µ coin ( L ) = L = /0, and µ coin ( L ) = L = Σ ∗ .Since µ coin ( w ) depends just on | w | , we can write µ coin ( L ) = ∑ ∞ k = f L ( k ) · (cid:0) n + (cid:1) k + , where f L ( k ) = (cid:12)(cid:12) L ∩ Σ k (cid:12)(cid:12) is the counting function of L . In other words, one possible way of computing the coin-flip mea-sure it by evaluating the generating function g f L ( x ) at x = n + (modulo a correction factor): µ coin ( L ) = n + · g f L (cid:0) n + (cid:1) . Consequently, the coin-flip measure of a regular language is rational, and that of anunambiguous context-free language is algebraic (following from the analogous, and more general, factsabout the respective generating functions [7]). Let L , M ⊆ Σ ∗ n be two languages with unambiguous con-catenation L · M . Then µ coin ( L · M ) = ( n + ) · µ coin ( L ) · µ ( M ) . (7)The coin-flip comparison problem asks, given a language L ⊆ Σ ∗ , a rational threshold 0 ≤ ε ≤ ∼ ∈ {≤ , <, >, ≥} , whether µ coin ( L ) ∼ ε holds. The uni-versality problem for L is the special case when ε =
1. We now relate the coin-flip comparison problem toan open problem in numerical computing. The
SQRTSUM problem asks, given d , . . . , d n ∈ N encodedin binary and a comparison operator ∼ ∈ {≤ , <, >, ≥} , whether : n ∑ i = p d i ∼ d . (8)This problem can be shown to be in PSPACE by deciding the existential formula ∃ x , . . . , x n . x = d ∧· · · ∧ x n = d n ∧ x + · · · + x n ∼ d over the reals [6]. It is a long-standing open problem in the theory ofnumerical computation whether SQRTSUM is in NP , or whether it is NP -hard [1, 13]. Theorem 11.
The coin-flip measure comparison problem is
SQRTSUM -hard for UCFG. In fact, the problem reduces to the case when ∼ = ≥ is fixed. By doing binary search in the interval { , ,..., n · d } , withonly O ( log ( n · d )) queries to (8) we can find the unique ˆ d ∈ N s.t. ˆ d ≤ ∑ ni = √ d i ≤ ˆ d +
1. We can then solve ∑ ni = √ d i ≤ d by checking d ≤ ˆ d +
1, and similarly for the other comparison operators. d , . . . , d n ∈ N be the input to SQRT-SUM . We assume w.l.o.g. that n is an odd number ≥
3. We construct a rational constant ε ∈ Q anda UCFG G = ( Σ n , N , X , ← ) over a n -ary alphabet Σ n = { a , . . . , a n } and nonterminals N containing { X , . . . , X n , C , . . . , C n , A } plus some auxiliary nonterminals (omitted for readability) s.t. µ coin ( L ( G )) ∼ ε if, and only if, (8) holds. The principal productions of the grammar are: X ← a · X | · · · | a n · X n , X ← C | A · X · a n · X , ... X n ← C n | A · X n · a n · X n . The remaining nonterminals C i ’s and A will generate certain regular languages to be determined below.Let d = max ni = d i . For every 1 ≤ i ≤ n , let x i = − √ d i d . It is easy to check that x i is the least non-negativesolution of x i = c i + a · x i where c i : = (cid:18) − d i d (cid:19) and a : = . (9)In the following, we write µ ( X ) for a non-terminal X ∈ N as a shorthand for µ coin ( L ( X )) . Since µ ( a ) = · · · = µ ( a n ) = ( n + ) , by (7) we have µ ( X ) = n + ( µ ( X ) + · · · + µ ( X n )) and µ ( X i ) = µ ( C i ) + ( n + ) · µ ( A ) · µ ( X i ) , i ∈ { , . . . , n } . (10)We aim at obtaining µ ( X i ) = x i . By comparing (10) with (9) we deduce that the nonterminals C i and A must generate languages of measure µ ( C i ) = c i , resp., µ ( A ) = an + = ( n + ) . Since the measures a , c i are rational, it suffices to find regular languages L ( A ) , L ( C i ) . The main difficulty is to define theselanguage as to ensure that G is unambiguous and of polynomial size. In order to achieve this we furtherrequire that 1) L ( A ) ⊆ Σ n − is a finite set of words of length 1 (single letters) not containing letter a n , and2) L ( C i ) ⊆ Σ ∗ n − is a set of words not containing letter a n .We first define L ( A ) . Let A ← a | · · · | a n + . In order to avoid letter a n , we require ( n + ) ≤ n −
1. The latter condition is satisfied since we assumed n ≥
3. Thus, L ( A ) ⊆ Σ n − is finite, contains only words of length 1, and has measure µ ( A ) = n + · ( n + ) = an + , as required.The definition of L ( C i ) of measure µ ( C i ) = c i is more involved. In general, it is easy to constructa regular expression (or a finite automaton) recognising a language of measure equal to a given rationalnumber. However, we have two constraints to respect: 1) we can use only letters from Σ n − , and 2) theregular expression must have size polynomial in the bit encoding of c i . The first constraint entails anupper bound µ ( Σ ∗ n − ) = on the maximal measure that L ( C i ) can have. However, this is not a problemin our case since c i < by definition. The second constraint is handled by the following lemma. Lemma 12 (Representation lemma) . Let n + ∈ N with n ≥ be a base, let m ∈ N s.t. ≤ m ≤ n, andlet c ∈ R with ≤ c ≤ n − m + be a target rational measure written in reduced form as c = pq , with p , q ∈ N , p ≤ q. There exists an unambiguous regular expression e using only letters from Σ m ⊆ Σ n recognisinga language of measure µ ( L ( e )) = c. Moreover, if there exists ℓ ∈ N s.t. q | ( n + ) ℓ , then e can be takenof size polynomial in log q, n, and ℓ . .Clemente 11We apply Lemma 12 with m : = n − c : = c i and obtain an unambiguous regular expression e recognising a language L ( e ) ⊆ Σ ∗ n − of measure c i . We now argue that e can be taken of polynomialsize. In order to achieve this, we assume w.l.o.g. that d = ( n + ) h for some h . (This can be ensured byadding a new integer d n + = ( n + ) h for some h large enough, and by replacing d with d + √ d n + = d + ( n + ) h .) Consequently, c i = d ( d − d i )( n + ) h = pq with p , q ∈ N relatively prime and q | ( n + ) h , andthus e has polynomial size by taking ℓ = h in the lemma. The set of polynomially many productionrules for nonterminal C i is derived immediately from the regular expression e by adding some auxiliarynonterminals. Moreover, since e is unambiguous, the same applies to the rules for C i . This completes thedescription of the grammar G . Lemma 13.
The grammar G is unambiguous.Proof.
Since L ( G ) = L ( X ) is the union of languages L ( a · X ) , . . . , L ( a n · X n ) , and the latter are disjoint,it suffices to show that the L ( X i ) ’s are recognised unambiguously. Let w ∈ L ( X i ) . If w does not containany a n , then necessarily w ∈ L ( C i ) . Otherwise, let w = ua n v where v does not contain any a n . Thus v ∈ L ( C i ) and u ∈ L ( A · X i ) . Since A produces only words of fixed length, u = xw ′ unambiguously with x ∈ A and w ′ ∈ L ( X i ) . This argument shows that for any w ∈ L ( X i ) if we let s be the number of a n in w ,then w ∈ L ( A s · C i · ( a n · C i ) s ) . Since A produces words of fixed length and C i does not produce any wordcontaining a n , the latter concatenation is unambiguous and thus w is produced unambiguously by X i .Let ε : = n + (cid:16) n − d d (cid:17) . The following lemma states the correctness of the reduction. Lemma 14.
We have µ ( L ( G )) ∼ ε if, and only if, (8) holds.Proof. Since x i = − √ d i d , we have µ ( X ) = µ ( a · X ) + · · · + µ ( a n · X n ) = ( n + )( µ ( a ) · µ ( X ) + · · · + µ ( a n ) · µ ( X n )) = n + ( µ ( X )+ · · · + µ ( X n )) = n + ( x + · · · + x n ) = n + (cid:16)(cid:16) − √ d d (cid:17) + · · · + (cid:16) − √ d n d (cid:17)(cid:17) = n + (cid:16) n − √ d + ··· + √ d n d (cid:17) , and thus ∑ ni = √ d i ∼ d if, and only if, µ ( L ( X )) ∼ ε , as required. We have shown novel
PSPACE upper bounds for several inclusion problems on UCFG and finite au-tomata. We did not address language equivalence problems L = M , which in principle can be easierto decide than the corresponding inclusions. For instance, while DCFG ⊆ DCFG is undecidable [19,Theorem 10.7, Point 2], DCFG = DCFG is decidable by the result of G. S´enizergues [30]. It is worthremarking that decidability of the equivalence problem UCFG = UCFG is not known. In fact, this is aspecial case of the multiplicity equivalence problem for CFG, which asks whether two CFGs have thesame number of derivations for every word they accept. Decidability of the latter problem is open as well[22] and inter-reducible with the language equivalence for probabilistic pushdown automata [14]. Therestriction of the UCFG = UCFG equivalence problem to words of a given length has been studied in[24].
Number sequences and the zeroness problem.
We obtained the
PSPACE upper bound for
UUCFG by reducing to the zeroness problem for conv-rec sequences. Conv-rec sequences generalise linear dif-ference recurrence with constant coefficients (a.k.a. constant-recursive or C-finite [21]; c.f. also [2] andcitations therein) by allowing the convolution product in the recurrence. They are a special case of moreexpressive classes such as P-recursive [21, Ch. 7] (a.k.a. holonomic ) and polynomial recursive sequences2 Complexity ofthe universality problem for unambiguous context-free grammars[5]. The zeroness problem for P-recursive sequences is decidable [36] and the same holds for polyno-mial recursive sequences (as a corollary of the existence of cancelling polynomials [5, Theorem 11]).However, no complexity upper bounds are known for those more general classes.
Coin-flip measure.
As a complement to the
PSPACE upper bound for
UUCFG , we have shown thatthe coin-flip measure comparison problem µ coin ( L ( G )) ∼ ε of a UCFG G with ∼ ∈ {≤ , <, ≥ , > } and0 ≤ ε ≤ SQRTSUM -hard. The main difficulty is that the measure is generated according to a fixedstochastic process. If we relax this constraint and generate the measure according to an arbitrary finiteMarkov process, then one can obtain
SQRTSUM -hardness already for DCFG.It is known that the quantitative decision problem for µ G ( Σ ∗ ) where G is a stochastic context-freegrammar (SCFG) is SQRTSUM -hard [13]. Our setting is incomparable: On the one hand we fix aparticular measure, namely the coin-flip measure µ coin (which corresponds to a fixed SCFG with rules X ← ε | a · X | · · · | a n · X ). On the other hand, we are interested in the quantity µ coin ( L ( G )) where G isan arbitrary UCFG (and thus not necessarily universal).We leave it as an open problem to establish the exact complexity of the universality problem forUCFG and the coin-flip measure 1 problem. When the system of polynomial equations obtained fromthe grammar is probabilistic (PPS ) the measure 1 problem is in PTIME [13] (and even in stronglypolynomial time [11]). However, the equations obtained from UCFG are monotone (MPS) but not PPSin general. As an example, consider a singleton alphabet Σ = { a } and productions of the form X ← a and, for n ≥ X n + ← X n · X n . The corresponding MPS system is x = and x n + = · x n . The formersystem is not a PPS, since in the second equation the coefficients sum up to 2. It may be argued that bythe change of variable z n : = · x n we obtain the system z = and z n + = z n which is PPS. However,this transformation reduces the value 1 problem on the original MPS to the value 1 / PTIME .One source of difficulty in the
UUCFG problem is that witnesses of non-universality can have expo-nential length. Extending the previous example, consider the additional rules Y ← ε and Y n + ← Y n | X n · Y n . The nonterminal X n generates a single word L ( X n ) = (cid:8) a n (cid:9) of length 2 n . It can be verified byinduction that Y n generates all words L ( Y n ) = (cid:8) a , a , . . . , a n − (cid:9) of length ≤ n −
1, and consequentlythe grammar is unambiguous. Thus L ( Y n ) is not universal, however the shortest witness has length 2 n . Interms of measures, µ coin ( L ( X n )) = n + and µ coin ( L ( Y n )) = − n + , and thus UCFG have measures thatcan be exponentially close to 0, resp., to 1. Since a word of length n over a unary alphabet has measure n + = − O ( n ) , if language L is not universal µ coin ( L ) <
1, then there is a non-universality witness oflength at most log ( − µ coin ( L )) . Thus upper bounds on 1 − µ coin ( L ) yield upper bounds on the shortestnon-universality witness. The “CFG ⊆ UFA” problem.
We have shown that CFG ⊆ UFA reduces to DCFG ⊆ UFA and, inturn, the latter reduces to
UUCFG and thus can be solved in
PSPACE . This needs not be optimal andthere are reasons to suspect that better algorithms may be obtained. If we interpret a DCFG G as astochastic context-free grammar (SCFG), then query L ( G ) ⊆ L ( A ) is equivalent to µ G ( L ( A )) = A is unambiguous, where µ G is the measure generated by G (a generalisation of the coin-flip measure).When A is DFA, µ G ( L ( A )) can be approximated in PTIME [12]. Generalising this result for A beingUFA would put DCFG ⊆ UFA in
PTIME . The sum of all coefficients is at most 1. .Clemente 13
The regularity problem for UCFG.
There are other problems which are known to be undecidable forCFG but decidable for DCFG, such as the regularity problem [32, 34, 31]. An interesting open problem[10] is whether the regularity problem is decidable for UCFG.
Acknowledgements.
I warmly thank Alberto Pettorossi for his encouragement and guidance duringmy first steps in doing research. I also thank an anonymous reviewer for his helpful comments on apreliminary version of this draft.
References [1] Eric Allender, Peter B¨urgisser, Johan Kjeldgaard-Pedersen & Peter Bro Miltersen (2009):
On the Complexityof Numerical Analysis . SIAM J. Comput. 38(5), pp. 1987–2006, doi:10.1137/070697926. Available at http://dx.doi.org/10.1137/070697926 .[2] Corentin Barloy, Nathana¨el Fijalkow, Nathan Lhote & Filip Mazowiecki (2020):
A Robust Class of LinearRecurrence Sequences . In Maribel Fern´andez & Anca Muscholl, editors: 28th EACSL Annual Conferenceon Computer Science Logic (CSL 2020), LIPIcs 152, Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik,pp. 9:1–9:16.[3] Mikołaj Boja´nczyk, Bartek Klin & Sławomir Lasota (2014):
Automata theory in nominal sets . Log-ical Methods in Computer Science Volume 10, Issue 3, doi:10.2168/LMCS-10(3:4)2014. Available at https://lmcs.episciences.org/1157 .[4] Alin Bostan, Arnaud Carayol, Florent Koechlin & Cyril Nicaud (2020):
Weakly-unambiguous Parikh au-tomata and their link to holonomic series . In: ToappearinICALP’20.[5] Micha¨el Cadilhac, Filip Mazowiecki, Charles Paperman, Michał Pilipczuk & G´eraud S´enizergues (2020):
On polynomial recursive sequences . In: ToappearinICALP’20.[6] John Canny (1988):
Some Algebraic and Geometric Computations in PSPACE . In: Proc. ofSTOC ’88, ACM, New York, NY, USA, pp. 460–467, doi:10.1145/62212.62257. Available at http://doi.acm.org/10.1145/62212.62257 .[7] N. Chomsky & M. P. Sch¨utzenberger (1963):
The Algebraic Theory of Context-Free Languages . In P. Braffort& D. Hirschberg, editors: ComputerProgrammingandFormalSystems, StudiesinLogicandtheFoundationsofMathematics 35, Elsevier, pp. 118 – 161, doi:https://doi.org/10.1016/S0049-237X(08)72023-8. Availableat .[8] Wojciech Czerwi´nski, Diego Figueira & Piotr Hofman (2020):
Universality Problem for Unambiguous VASS .Available at https://hal.archives-ouvertes.fr/hal-02483495 . Working paper or preprint.[9] Wojciech Czerwinski, Slawomir Lasota, Roland Meyer, Sebastian Muskalla, K. Narayan Kumar& Prakash Saivasan (2018):
Regular Separability of Well-Structured Transition Systems . InSven Schewe & Lijun Zhang, editors: Proc. of CONCUR’18, LIPIcs 118, Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, pp. 35:1–35:18, doi:10.4230/LIPIcs.CONCUR.2018.35. Available at http://drops.dagstuhl.de/opus/volltexte/2018/9573 .[10] Volker Diekert & Steffen Kopecki (2010):
Complexity Results and the Growths of Hairpin Completions ofRegular Languages . In: Proc.ofCIAA’10, CIAA’10, Springer-Verlag, Berlin, Heidelberg, pp. 105–114.[11] Javier Esparza, Andreas Gaiser & Stefan Kiefer (2010):
Computing Least Fixed Points of Probabilistic Sys-tems of Polynomials . In Jean-Yves Marion & Thomas Schwentick, editors: STACS’10, LIPIcs 5, SchlossDagstuhl–Leibniz-Zentrum fuer Informatik, pp. 359–370, doi:10.4230/LIPIcs.STACS.2010.2468. Availableat http://drops.dagstuhl.de/opus/volltexte/2010/2468 .[12] Kousha Etessami, Alistair Stewart & Mihalis Yannakakis (2013):
Stochastic Context-free Grammars, Regular Languages, and Newton’s Method . In: Proc. of ICALP’13,
Springer-Verlag, pp. 199–211, doi:10.1007/978-3-642-39212-2 20. Available at http://dx.doi.org/10.1007/978-3-642-39212-2_20 .[13] Kousha Etessami & Mihalis Yannakakis (2009):
Recursive Markov Chains, Stochastic Grammars, and Mono-tone Systems of Nonlinear Equations . J.ACM56(1), pp. 1:1–1:66, doi:10.1145/1462153.1462154. Availableat http://doi.acm.org/10.1145/1462153.1462154 .[14] Vojtˇech Forejt, Petr Janˇcar, Stefan Kiefer & James Worrell (2014):
Lan-guage equivalence of probabilistic pushdown automata . Information and Com-putation 237, pp. 1–11, doi:https://doi.org/10.1016/j.ic.2014.04.003. Available at .[15] Ronald Graham, Donald Knuth & Oren Patashnik (1994):
Concrete Mathematics , 2nd edition. AddisonWesley.[16] D. Yu Grigor’ev (1988):
Complexity of deciding Tarski algebra . Journal of Symbolic Com-putation 5(1), pp. 65–108, doi:https://doi.org/10.1016/S0747-7171(88)80006-3. Available at .[17] Wright E.M. Hardy G.H. (2008):
An introduction to the theory of numbers , 6ed. edition. OUP.[18] Thomas N. Hibbard & Joseph Ullian (1966):
The Independence of Inherent Ambiguity From Complemented-ness Among Context-Free Languages . J.ACM 13(4), pp. 588–593.[19] John Hopcroft & Jeffrey Ullman (1979):
Introduction to Automata Theory, Languages, and Computation .Addison-Wesley.[20] Takumi Kasai & Shigeki Iwata (1992):
Some Problems in Formal Language Theory Known as Decidable areProved EXPTIME Complete . 数 理 解 析 研究 所 講 究 録 C-Finite Sequences , pp. 63–86. Springer Vienna, Vienna,doi:10.1007/978-3-7091-0445-3 4. Available at https://doi.org/10.1007/978-3-7091-0445-3_4 .[22] Werner Kuich (1994):
On the Multiplicity Equivalence Problem for Context-Free Grammars . In: Proceed-ings of the Colloquium in Honor of Arto Salomaa on Results and Trends in TheoreticalComputer Science,Springer-Verlag, Berlin, Heidelberg, pp. 232—250.[23] Werner Kuich & Arto Salomaa (1986):
Semirings, Automata, Languages . EATCSMonographs on Theoretical Computer Science 5, Springer. Available at http://gen.lib.rus.ec/book/index.php?md5=c22e327ec8a3a010137c7809f7a5abe1 .[24] B. Litow (1996):
Bounded length UCFG equivalence . In Tetsuo Asano, Yoshihide Igarashi, Hiroshi Nag-amochi, Satoru Miyano & Subhash Suri, editors: AlgorithmsandComputation, Springer Berlin Heidelberg,Berlin, Heidelberg, pp. 239–246.[25] P. Massazza & N. Sabadini (1989):
Some applications and techniques for generating functions . In Josep D´ıaz& Fernando Orejas, editors: TAPSOFT’89, Springer Berlin Heidelberg, Berlin, Heidelberg, pp. 321–336.[26] A. R. Meyer & L. J. Stockmeyer (1972):
The Equivalence Problem for Regular Expressions with SquaringRequires Exponential Space . In: Proceedings of the 13th Annual Symposium on Switching and AutomataTheory, SWAT ’72, IEEE Computer Society, Washington, DC, USA, pp. 125–129.[27] Antoine Mottet & Karin Quaas (2019):
The Containment Problem for Unambiguous Register Automata .In Rolf Niedermeier & Christophe Paul, editors: Proc. of STACS’19, LIPIcs 126, Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, pp. 53:1–53:15, doi:10.4230/LIPIcs.STACS.2019.53. Available at http://drops.dagstuhl.de/opus/volltexte/2019/10292 .[28] Stanisław Purgał (2018):
Learning regular languages offline from a positive sample . Master’s thesis, Univer-sity of Warsaw.[29] Arto Salomaa & Marti Soittola (1978):
Automata-theoretic aspects of formal powerseries . Texts and Monographs in Computer Science, Springer. Available at http://gen.lib.rus.ec/book/index.php?md5=1E7B3DCFFFC7F6146062637382E5067D . .Clemente 15 [30] G´eraud S´enizergues (1997): The equivalence problem for deterministic pushdown automata is decidable . InPierpaolo Degano, Roberto Gorrieri & Alberto Marchetti-Spaccamela, editors: Proc.ofICALP’97, SpringerBerlin Heidelberg, Berlin, Heidelberg, pp. 671–681.[31] Priti Shankar & B. S. Adiga (1991):
A Graph-based Regularity Test for Deterministic Context-free Lan-guages . Theor. Comput. Sci. 88(1), pp. 117–125, doi:10.1016/0304-3975(91)90076-E. Available at http://dx.doi.org/10.1016/0304-3975(91)90076-E .[32] R.E. Stearns (1967):
A regularity test for pushdown machines . Information and Control11(3), pp. 323 – 340, doi:http://dx.doi.org/10.1016/S0019-9958(67)90591-8. Available at .[33] Richard E. Stearns & Harry B. Hunt (1981):
On the equivalence and containment problemsfor unambiguous regular expressions, grammars, and automata . In: Proc. of SFCS’81, IEEEComputer Society, Washington, DC, USA, pp. 74–81, doi:10.1109/SFCS.1981.29. Available at http://dx.doi.org/10.1109/SFCS.1981.29 .[34] Leslie G. Valiant (1975):
Regularity and Related Problems for Deterministic Push-down Automata . J. ACM 22(1), pp. 1–10, doi:10.1145/321864.321865. Available at http://doi.acm.org/10.1145/321864.321865 .[35] Tzeng Wen-Guey (1996):
On path equivalence of nondeterministic finite automata . InformationProcessingLetters 58(1), pp. 43–46.[36] Doron Zeilberger (1990):
A holonomic systems approach to special functions identities . Journalof Compu-tational and Applied Mathematics 32(3), pp. 321–368, doi:https://doi.org/10.1016/0377-0427(90)90042-X.Available at . A Appendix
Lemma 12 (Representation lemma) . Let n + ∈ N with n ≥ be a base, let m ∈ N s.t. ≤ m ≤ n, andlet c ∈ R with ≤ c ≤ n − m + be a target rational measure written in reduced form as c = pq , with p , q ∈ N , p ≤ q. There exists an unambiguous regular expression e using only letters from Σ m ⊆ Σ n recognisinga language of measure µ ( L ( e )) = c. Moreover, if there exists ℓ ∈ N s.t. q | ( n + ) ℓ , then e can be takenof size polynomial in log q, n, and ℓ .Proof. Fix an alphabet Σ n and let m ≤ n as in the statement of the lemma. If m = n then there is nodifficulty since we can just look at the periodic expansion c = ∑ i = c i ( n + ) i + of c in base n +
1, wherecrucially 0 ≤ c i ≤ n , and one can just interpret c i as the number of words of length i that the regularexpression must accept (since there are n i such words of length i , this can always be done, perhaps withthe exception of i = m ≤ n , which requires arefinement of the analysis above.There are m k words of length k over Σ m ⊆ Σ n , and thus the measure µ coin ( Σ ∗ m ) (which is alwayscomputed w.r.t. alphabet Σ n ) satisfies µ coin ( Σ ∗ m ) = ∞ ∑ k = m k ( n + ) k + = n + · ∞ ∑ k = (cid:18) mn + (cid:19) k = n + · − mn + = n − m + . (11)We consider two cases. If c = n − m + , then just let e = Σ ∗ m , and we are done. Otherwise, assume c < n − m + .Our aim is to find some k ∈ N and write c as c = k ∑ i = c i ( n + ) i + + ∞ ∑ j = d j ( n + ) k + j + , with 0 ≤ c i ≤ m i and 0 ≤ d j ≤ n . (12)6 Complexity ofthe universality problem for unambiguous context-free grammarsIntuitively, c i counts the number of words of length i in L ( e ) for 0 ≤ i ≤ k , and d j counts the numberof words of length k + j in L ( e ) for j ≥
1. Moreover, in the first part the c i ’s are allowed to be very big(up to m i ) and in the second part the d j ’s must be small (up to n ). Thus we will be able to interpret the d j ’s as digits in the base n + k .Generalising (11), the measure of all words of length at most k ∈ N over the sub-alphabet Σ m is (alwayscomputed w.r.t. Σ n ) µ coin ( Σ ≤ km ) = k ∑ i = m i ( n + ) i + = n − m + − (cid:18) mn + (cid:19) k + ! . (13)Since c < n − m + = lim k → ∞ µ coin ( Σ ≤ km ) , there is some k s.t. c < µ coin ( Σ ≤ km ) . Let k be such a minimalnumber, i.e., µ coin ( Σ ≤ k − m ) ≤ c < µ coin ( Σ ≤ km ) . Consequently, for this choice of k we have c = m , c = m , . . . , c k − = m k − , and 0 ≤ c k < m k where µ Σ n ( Σ ≤ k − m ) + c k ( n + ) k + ≤ c < µ Σ n ( Σ ≤ k − m ) + c k + ( n + ) k + . For complexity considerations, we note that k satisfies c < µ coin ( Σ ≤ km ) , and thus k > log ( − ( n − m + ) c ) log m − log ( n + ) − = − log ( − ( n − m + ) c ) log ( n + ) − log m . The minimal denominator is achieved by m = n , and the maximal numerator by m = k > − log ( − nc ) log ( n + ) − log n . Since − log ( − nc ) = O ( log q ) and log ( n + ) − log n = log n + n = log ( + n ) = O ( n ) , we obtain k = O ( n log q ) . (14)This choice of k also guarantees n ≤ m k . Let d : = c − (cid:16) µ Σ n ( Σ ≤ k − m ) + c k ( n + ) k + (cid:17) be the remaining part of c after all terms up to k have been considered: Thus, d is small in the sense that 0 ≤ d < ( n + ) k + . Since ∑ ∞ j = n ( n + ) j + = n + , we can write d in base n + d = ( n + ) k ∞ ∑ j = d j ( n + ) j + , with 0 ≤ d j ≤ n ≤ m k . The coefficients are small numbers d j at most n , which can thus be interpreted as digits in base n +
1. Since d is a rational number, the sequence d , d , . . . is ultimately periodic [17], i.e., there exists athreshold j ∈ N and a period l ∈ N s.t. , for every j ≥ j , d j + l = d j . Let γ = d j , γ = d j + , . . . , γ l = d j + l − be the coefficients comprising the period. Consequently, d = ( n + ) k j − ∑ j = d j ( n + ) j + + ∞ ∑ s = (cid:18) γ ( n + ) j + sl + + · · · + γ l ( n + ) j + sl + l (cid:19)! = ( n + ) k j − ∑ j = d j ( n + ) j + + ( n + ) j − ∞ ∑ s = γ ( n + ) ( s + ) l + ! = (15) = ( n + ) k j − ∑ j = d j ( n + ) j + + γ ( n + ) j ( n + ) l − ! , (16)where γ : = γ ( n + ) l − + · · · + γ l ( n + ) is the number of words of length k + j − + ( s + ) l , for every s ∈ N ..Clemente 17We are now ready to build the regular expression e . We begin with a basic building block. For agiven length k and a cardinality 0 ≤ h ≤ m k written in base m as h = ∑ ki = h i · m i (0 ≤ h i < m ), considerthe regular expression e h , k s.t. e h , k = Σ km if h = m k , and otherwise: e h , k = a k − m · ( a + · · · + a h ) · Σ m + a k − m · ( a + · · · + a h ) · Σ m + · · · + a m · ( a + · · · + a h k − ) · Σ k − m . Claim . The expression e h , k is unambiguous and L ( e h , k ) contains precisely h words of length k . Con-sequently, µ coin ( L ( e h , k )) = h ( n + ) k + . Proof (of the claim).
All words recognised by e h , k have length k . The i -th block a k − i − m · ( a + · · · + a h i ) · Σ im contains h i · m i words since there are h i distinct options to choose a letter from a + · · · + a h i and m i distinct options to choose a word from Σ im . The languages of different blocks are disjoint, since theprefix a k − i − m uniquely determines the block (since h i < m and thus a + · · · + a h i does not contain a m ).Similarly, the two concatenations in a block are unambiguous, and thus e h , k is unambiguous.The sought expression of measure c is e = Σ ≤ k − m + e c k , k + e d , k + + · · · + e d j − , k + j − + e γ , k + j − + l · e ∗ , l . (17) Claim . The expression e is well defined provided k ≥ l · log ( n + ) log m − + l . Proof (of the claim).
The e d j , k + j ’s are well defined since d j ≤ n ≤ m k ≤ m k + j and thus there are d j wordsof length k + j over alphabet Σ m .) In order for e γ , k + j − + l to be well defined we need γ ≤ m k + j − + l . Since γ ≤ ( n + ) l and n ≤ m k , it suffice to require ( n + ) l ≤ m k − + l . The latter condition follows from theassumption. Claim . The expression e is unambiguous and µ coin ( L ( e )) = c . Proof (of the claim).
Unambiguity follows from the fact that 1) all disjuncts of e recognise disjointlanguages, since Σ ≤ k − m recognises only words of length ≤ k − e c k , k only words of length k , e d , k + only words of length k +
1, . . . , e d j − , k + j − only words of length k + j −
1, and e γ , k + j − + l · e ∗ , l onlywords of length ≥ k + j − + l , and 2) all disjuncts e c k , k , e d , k + , . . . , e d j − , k + j − are unambiguous byClaim 15, and e γ , k + j − + l · e ∗ , l is unambiguous since e ∗ , l contains only one word of length l . In gen-eral µ coin ( L k ) = ( n + ) k − µ coin ( L ) k (by (7), when such power is unambiguous) and thus µ coin ( L ∗ ) = µ coin ( L ∪ L ∪ · · · ) = µ coin ( L ) + µ coin ( L ) + · · · = n + ((( n + ) µ coin ( L )) + (( n + ) µ coin ( L )) + · · · ) = n + · − ( n + ) µ coin ( L ) when the Kleene iteration is unambiguous. Since µ coin ( L ( e , l )) = ( n + ) l + , we obtain µ coin ( L ( e ∗ , l )) = n + · − ( n + ) ( n + ) l + = ( n + ) l − ( n + ) l − . Consequently, µ coin ( L ( e γ , k + j − + l · e ∗ , l )) = ( n + ) · µ coin ( L ( e γ , k + j − + l )) · µ coin ( L ( e ∗ , l )) == ( n + ) · γ ( n + ) k + j + l · ( n + ) l − ( n + ) l − == γ ( n + ) k + j · ( n + ) l − . By (16), µ coin ( L ( e )) = µ coin ( Σ ≤ k − m ) + µ coin ( L ( e c k , k )) + µ coin ( L ( e d , k + )) + · · · + µ coin ( L ( e d j − , k + j − )) + µ coin ( L ( e γ , k + j − + l · e ∗ , l )) = c , as required.8 Complexity ofthe universality problem for unambiguous context-free grammars Claim . The expression e has size O (( n log q + j + l + ) ) . Proof (of the claim).
The size of e h , k is | e h , k | = O ( k · ( m + k )) = O ( k · ( n + k )) , since m ≤ n . Thus thesize of e is | e | ≤ O (( k + n + j + l + ) ) . By (14), | e | ≤ O (( n log q + j + l + ) ) , as required.If we further assume that q | ( n + ) ℓ for some ℓ ∈ N , then we argue that we can take e to have sizepolynomial in log q , n , and ℓ . By (14) and the additional assumption on q , k = O ( n ℓ log ( n + )) . (18)We can write d = rs with r , s ∈ N and r ≤ s relatively prime, where s | ( n + ) k + . If we decompose the base n + n + = p z p z · · · p z m m with z , . . . , z m ∈ N , then s is of the form s = p t p t · · · p t m m with t i ≤ ( k + ) z i . By [17, Theorem 136] , d can be written in base ( n + ) with a finite expansionof length j = max n t z , . . . , t m z m o = O ( k + ) . In particular, the period has zero length l =
0. By (18), j = O ( n ℓ log ( n + )) . By applying Claim 18 to this case, we obtain a regular expression e of size O (( n log q + j + l + ) ) ≤ O (( n log q + n ℓ log ( n + ) + ) ) which is polynomial in log q = O ( ℓ log n ) , ℓ ,and n , as required. Strictly speaking, [17, Theorem 136] requires that the base n + n ++