On the Expressive Power of 2-Stack Visibly Pushdown Automata

Visibly pushdown automata are input-driven pushdown automata that recognize some non-regular context-free languages while preserving the nice closure and decidability properties of finite automata. Visibly pushdown automata with multiple stacks have …

Authors: Benedikt Bollig

On the Expressive Power of 2-Stack Visibly Pushdown Automata
Logical Methods in Computer Science V ol. 4 (4:16) 2008, pp. 1–35 www .lmcs-online.org Submitted Sep . 3, 2007 Published Dec. 24, 2008 ON THE EXPRESSIVE PO WE R OF 2-ST A CK VISIBL Y PU SHDO WN A UTOMA T A BENEDIKT BOLLIG LSV, ENS Cac han, CNRS — 61, a venue du Pr´ esiden t Wilson, 94235 Cac han Cedex, F rance e-mail addr ess : b ollig@lsv.ens-ca cha n.fr Abstra ct. Visibly pushdown automata are input-driven pu shdow n automata that rec- ognize some n on-regular context-free languages while preserving the nice closure and de- cidabilit y p roperties of finite automata. Visibly pushdown automata with m ultiple stacks hav e b een considered recen tly by La T orre, Madhusudan, and Parlato, who exploit the concept of visibili ty further to obtain a ric h automata class that can ev en express prop- erties b eyond the cla ss of context-free languages. At th e same time, t h eir automata are closed u nder b o olean operations, hav e a decidable emptiness and inclusion problem, and enjo y a logical characteriza tion in terms of a monadic second-order logic ov er wo rds with an additional nesting structu re. These results require a restricted version of visibly push- dow n automata with multiple stacks whose b ehavior can b e split up into a fixed number of ph ases. In this p aper, w e consider 2-stack visibly pushdo wn automata (i.e., visibly pushdown automata with tw o stac ks) in their unrestricted form. W e show that they are expressivel y equiv alen t to the existential fragment of monadic second-order logic. F urthermore, it turns out that monadic second-order quantifier alternation forms an infinite hierarc hy wrt. w ords with m ultiple nestings. Combining these results , w e conclude that 2-stac k visibly pushdown aut omata are not closed under complementation. Finally , we discuss the ex pressiv e p ow er of B ¨ uchi 2-stac k v isibly pu shdow n automata running on infinite (nested) words. Extending the logic by an infinit y quantifier, w e can lik ewise establish eq uiv alence to ex isten tial monadic second-order logic. 1. Introduction The notion of a regular w ord language has ev er pla y ed an imp ortan t rˆ ole in computer science, as it constitutes a robust concept th at enjo ys manifold represent ations in terms of finite automat a, regular expressions, mon adic second-order logic , etc. Generalizing regular languages to wards richer classes and m ore expressiv e formalisms is often accompanied by the loss of robustness and deci dabilit y prop erties. It is, for example, well -kno w n that the class of con text -free languages, repr esen ted by p ushdown automata, is not closed und er complemen tation and that unive rsalit y , equiv alence, and inclusion are un d ecidable problems [12]. 1998 ACM Subje ct Classific ation: F.4.3. Key wor ds and phr ases: visibly pushdown automata, multiple stacks, nested w ords, monadic second-order logic. LOGICAL METHODS l IN COMPUTER SCIENCE DOI:10.216 8/LMCS-4 (4:16) 2008 c  B. Bollig CC  Creat ive Commons 2 B. BO LLIG Visibly pushdown languages ha ve b een introdu ced by Alur and Madh usudan to o v er- come this deficiency while su bsuming man y in teresting and useful con text-free pr op ertie s [1]. Visibly pushd own languages are r epresen ted by sp ecia l p ushdown automata whose stac k op - erations are driv en b y the input. More precisely , the underlying alphab et of p ossible actions is partitioned into (1) call, (2) r eturn, and (3) in ternal ac tions, w hic h, when reading an ac- tion, indicates if (1) a sta c k symbol is pushed on the stac k, (2) a sta c k symbol is read and p opp ed fr om th e stac k, or (3) the stac k is not touc hed at all, resp ectiv ely . Su c h a partition giv es rise to a c al l-r eturn alphab et . Though this limits the expressiv e p ow er of push do wn automata, the such defined class of visibly p ushdown languages is ric h enough to mo del v ar- ious in teresting non-regular p rop erties for program analysis. Ev en more, this class p reserv es some imp ortan t closure prop erties of regular la nguages, suc h as the closure under bo o lean op erations, and it exhib its d ecidable p roblems, suc h as in clusion, that are und ecidable in the con text of general pus hdo wn automata. L ast but not least, the visibly push do wn languages are captured by a monadic second-order logic that mak es use of a binary nesting predicate. Suc h a logic is su itable in the cont ext of visibilit y , as the nesting structure of a w ord is uniquely determined, regardless of a particular run of the pushdo w n automaton. The log i- cal c h aracteriza tion smo othly extends the classica l theory of regular languages [7, 10]. F or con text-free languages, quant ification o ver matchings , whic h are not imp licitly giv en when w e d o not ha v e visibilit y , is necessary to obtain a logi cal c haracterizatio n [15]. Visibly push do wn automata with multiple stac ks hav e b een considered recen tly and indep end en tly by La T orre, Madhusudan, and Parla to [13], as w ell as Carotenuto , Murano, and Pe ron [8]. The aim of these p ap ers is to exploit th e concept of visibilit y further to obtain ev en ric her classes of n on-regular languages w hile p reserving imp ortan t closure prop erties and decidabili t y of v erificati on-related problems suc h as emptiness and inclusion. In [13 ], the authors consider visibly p ushdown automata with arb itrarily man y stac ks. T o retain the nice prop erties of visibly push d o wn automata with only one stac k, the idea is to restrict the domain, i.e., the p ossible inputs, to those w ords that can b e divided in to at most k ph ases for a pr edefined k . In ev ery ph ase, p op actions corresp ond to one and the same stac k. These restricted visibly push do wn automata h a ve a decidable emp tiness problem, which is shown b y a redu ction to th e emptiness problem for finite tree automata, and are closed un der u nion, in tersectio n, and complemen tatio n (wrt. the d omain of k -phase w ords). M oreo ver, a word language is recognizable if, and only if, it can b e defi n ed in monadic second-order logic where the usu al logic ov er words is expand ed by a matc hing predicate that matc hes a push w ith its corresp ond in g p op ev en t. As mentioned ab o v e, su c h a matc hing is unique wrt. the und erlying call-return alphab et. The only n egativ e result in this r egard is that mult i-stac k visibly pushdown automata cannot b e d eterminized. The p ap er [8] considers visibly push do wn automata with t wo stac ks and call-return alphab ets that appear m ore general th an those o f [13]: An y stac k is asso ciated with a partition of one and the same alphab et in to call, r etur n, and lo cal transitions so that an action migh t b e b oth a call action for the fir st s tac k and, at the same time, a return action for the second. In this wa y , b oth stac ks can b e work ed on sim ultaneously . Note that, if w e restrict to the alphab ets of [13] w here the stac k alphab ets are disjoin t, the m o dels from [8] and [13] coincide. Carot en uto et al. sho w that th e emptiness p roblem of their mo del is undecidable. Their approac h to gain decidabilit y is to exclude sim ultaneous p op op erations b y introd ucing an ordering constrain t on stac ks, wh ic h is inspired by [6] (see also [3]). More precisely , a p op op eration on th e second stac k is only p ossible if the first stac k is empt y . ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 3 Under these restrictions, th e emp tiness problem turns out to b e d ecidable in p olynomial time (n ote that the num b er of stac ks is fixed). 1 In this pap er, we consider 2-stac k visibly push d o wn automata (i.e., visibly p ushdown automata with t wo stac ks) where eac h action is exclusiv e to one of the stac ks, unless we deal with an internal actio n, wh ic h do es not affect the stac ks at all. Th u s , w e adopt the mo del of [13], though w e ha ve to restrict to t w o stac ks for our main results. One of these results states that the corresp ondin g language class is precisely charact erized b y the existen tial fragmen t of monadic second-order logic where a fir st-order k ernel is preceded by a blo c k of existen tially qu an tified second-order v ariables. In a second step, we sh o w that the full monadic seco nd-order log ic is strictly more expressive than its existen tial fr agmen t so that w e conclude that 2-stac k visibly pushd o w n automata are not closed und er complemen tation. Note that our mod el has an un decidable emptiness problem, as can b e ea sily seen. The k ey tec hn ique in our pro ofs is to consider w ord s o v er call-ret urn alphab ets as relational s tructures, called neste d wor ds [2]. Ne sted w ords augment ordinary words with a nesting relation that, as the logi cal atomic predicate menti oned ab ov e, relates push with corresp onding p op ev ents. More precisely , w e consider a nested w ord to b e a graph w h ose no des are lab eled with actions and are related in terms of a matc hing and an immediate- predecessor relation. W e thus deal with structures of b ounded degree: every n o de has at most t wo incoming edges (one from the immediate predecessor and one from a push eve n t if w e deal with a p op ev en t op erating on the non-empty stac k) and, similarly , at m ost t wo outgoing edges. As there is a one-to-one corresp ondence b et w een words and their nested coun terpart, we ma y consider nested-w ord automata [2], whic h are equiv alen t to visibly pushd own automata bu t op erate on the enric hed w ord structures. There h a ve b een sev eral notions of automata on graph s and partial orders [18, 19] that are similar to nested-w ord automata and hav e one idea in common: the state that is tak en after executing some eve n t dep ends on th e states that ha v e b een visited in n eigh b oring ev ents. Such defined automata ma y lik ewise op erate on mo dels for concurrent- systems executions such as Mazurkiewicz traces [9] and message sequence c h arts [5]. In the framework of nested-w ord automata, to determine the state after executing a p op op eration, we therefore hav e to consider b oth th e state of the immediate-predecessor p osition and the state that had b een reac hed after the execution of the corresp onding push ev en t. T o obtain a logica l c haracteriz ation of nested- w ord automata ov er t w o stac ks, we adopt a tec hnique from [5]: for a natur al num b er r , w e compute a nested-w ord auto maton B r that computes the spher e of radius r around an y ev ent i , i.e., the restriction of the input w ord to those even ts that ha v e d istance at most r from i . Once we ha ve this automaton, w e can app ly Hanf ’s Th eorem, whic h states that satisfactio n of a giv en first-order form ula dep end s on the num b er of these lo cal spheres coun ted u p to a threshold that dep end s on the quanti fier-nesting depth of the form ula [11]. This finally leads us to a logical c haracte rization of 2-stac k visibly p ushdown automata in terms of existent ial monadic second-order logic. Note that our construction of B r is close to the nontrivia l tec hnique applied in [5]. In the cont ext of nested w ords, ho w ever, the correctness pro of is more complicated. The fact that we deal with t w o stac ks only is crucial, and the constructio n fails as so on as a third stac k comes into pla y . 1 In [8], th e auth ors argue that 2-stack v isibly p u shdow n automata without restriction are clo sed und er complemen tation, but th eir proof mak es use of the incorrect assumption that these automata are determiniz- able. In fact, 2-stac k visibly p ushdown automata can in general not b e determinized [13]. In the present pap er, we show that 2-stack visibly pushdown automata are actu ally not closed under complementa tion. 4 B. BO LLIG Then, w e exploit the concept of nested words to s ho w that full monadic second-order logic is more expressiv e than its existent ial fragmen t. Th is is d one by a fi rst-order interpre- tation of nested words o ve r t w o stac ks in to grids, for which the analogous r esult has b een kno wn [17]. An extension of Hanf ’s Theorem has b een established to cope with infinite structures [4]. This allo ws u s to apply th e automaton B r to also obtain a logical c haracteriz ation of the canonical extension of 2-stac k visibly p u shdown automata to w ards B ¨ uc h i automata ru nning on infi nite words. Outline of the pap er. In Section 2, we introduce multi-st ac k visibly push d o wn automata, runnin g on words, as well as multi- stac k nested-word automata, w hic h op erate on nested w ords. W e establish expressiv e equiv alence of these tw o mo dels. Section 3 recalls monadic second-order logic o v er relational structur es and, in particular, n ested words. There, w e also state Hanf ’s Theorem, whic h provides a normal form of fi rst-order defin able prop erties in te rms of spheres. The constructio n of the sp here automaton B r , whic h i s, to some exten t, the core con tribution of this pap er, is the sub ject of Sectio n 4.2. By means of this automaton, w e can show expressiv e equiv al ence of 2-stac k visibly pushdown au tomata and existen tial monadic second-order logic (Section 4. 1). S ection 5 establishes the gap b et w een this fragment and the fu ll logic, from w hic h we conclude that 2-stac k visibly pus h do wn automata cannot b e complemen ted in general. By sligh tly mo difying our logic , we obta in, in S ection 6, a charac terizati on of B ¨ uc h i 2-stac k visibly pushd own automata, ru nning on infinite words. W e conclude with Section 7 s tating some r elated op en p roblems. 2. Mul ti-St a ck Visibl y Pushd own A u toma t a The set { 0 , 1 , 2 , . . . } of natural num b ers is denoted by N , the set { 1 , 2 , . . . } of p ositiv e natural n u m b ers b y N + . W e call an y finite set an alph ab et . F or a set Σ, w e d enote b y Σ ∗ , Σ + , an d Σ ω the sets of fi nite, nonempty finite, and infi nite strings ov er Σ, resp ectiv ely . 2 The empt y string is denoted by ε . F or a natural n um b er n ∈ N , we let [ n ] s tand for the set { 1 , . . . , n } (i.e., [0] is the empt y set). In this pap er, w e will identi fy isomorphic structures and w e use ∼ = to d enote isomorph ism. Let K ≥ 1 b e a p ositiv e natural num b er. A ( K -stac k) c al l-r eturn alphab et is a collectio n h{ (Σ s c , Σ s r ) } s ∈ [ K ] , Σ int i of pairwise disjoin t alphab ets. Intuitiv ely , Σ s c con tains the actions that call the stac k s , Σ s r is the set of returns of stac k s , and Σ int is a set of internal actions, whic h do not in vo lv e an y stac k op eration. W e fi x K ≥ 1 and a K -stac k call-return alphab et e Σ = h{ (Σ s c , Σ s r ) } s ∈ [ K ] , Σ int i . Moreo v er, w e set Σ c = S s ∈ [ K ] Σ s c , Σ r = S s ∈ [ K ] Σ s r , and Σ = Σ c ∪ Σ r ∪ Σ int . 2.1. Multi-Stac k Visibly Pushdo wn Aut omata. Definition 2.1. A mult i-stack visibly pushdo wn automaton ( Mvp a ) o v er e Σ is a tup le A = ( Q, Γ , δ , Q I , F ) where • Q is its fi nite set of sta tes , • Q I ⊆ Q is the set of initial states , • F ⊆ Q is the set of final states , 2 F rom now on, to av oid confusion with nested words, w e use the term “string” rather than “w ord” if w e deal with elements from Σ ∗ ∪ Σ ω . ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 5 • Γ is the finite stack alp hab et conta ining a sp ecial symb ol ⊥ that will represent the empt y stac k, and • δ pr o vides the tr ansition s in terms of a triple h δ c , δ r , δ int i with δ c ⊆ Q × Σ c × (Γ \ {⊥} ) × Q, δ r ⊆ Q × Σ r × Γ × Q, and δ int ⊆ Q × Σ int × Q . A 2-stack visibly pushdown automaton (2 vp a ) is an Mvp a that is defin ed o v er a 2-stac k alphab et (i .e., K = 2). A transition ( q , a, A, q ′ ) ∈ δ c , sa y with a ∈ Σ s c , is a push transition meaning that, b eing in state q , the automaton can r ead a , push the sym b ol A ∈ Γ \ {⊥} on to the s -th stac k, and go o ve r to state q ′ . A transition ( q , a, A, q ′ ) ∈ δ r , sa y w ith a ∈ Σ s r , allo ws us to p op A 6 = ⊥ from the s -th stac k wh en reading a , w hile the con trol c hanges from state q to state q ′ . If, ho w ever, A = ⊥ , then th e stac k is not touc hed , i.e., ⊥ is nev er p opp ed. Finally , a transition ( q , a, q ′ ) ∈ δ int is applied when reading int ernal actions a ∈ Σ int . They do n ot in volv e an y stac k op eration and , actually , do not ev en allo w us to read from the stac k. Let us formalize the b eha vior of the Mvp a A . A stack c ontents is a nonemp t y fi nite sequence from Cont = (Γ \ {⊥} ) ∗ · {⊥} . The leftmost symbol is th us the top s ymb ol of the stac k con tents. A configuration of A consists of a state and a stac k con tents for every stac k. Hence, it is an elemen t of Q × Cont [ K ] . Consider a string w = a 1 . . . a n ∈ Σ + . A run of A on w is a sequence ρ = ( q 0 , σ 1 0 , . . . , σ K 0 ) . . . ( q n , σ 1 n , . . . , σ K n ) ∈ ( Q × Cont [ K ] ) + suc h that q 0 ∈ Q I , σ s 0 = ⊥ for eac h stac k s ∈ [ K ], and, for all i ∈ { 1 , . . . , n } , the f ollo wing hold: [Push]: If a i ∈ Σ s c for s ∈ [ K ], then there is a stac k symbol A ∈ Γ \ {⊥} suc h that ( q i − 1 , a i , A, q i ) ∈ δ c , σ s i = A · σ s i − 1 , and σ s ′ i = σ s ′ i − 1 for every s ′ ∈ [ K ] \ { s } . [P op]: If a i ∈ Σ s r for s ∈ [ K ], then there is a stac k sym b ol A ∈ Γ such that ( q i − 1 , a i , A, q i ) ∈ δ r , σ s ′ i = σ s ′ i − 1 for ev ery s ′ ∈ [ K ] \ { s } , and either A 6 = ⊥ and σ s i − 1 = A · σ s i , or A = ⊥ and σ s i − 1 = σ s i = ⊥ . [In ternal]: If a i ∈ Σ int , then ( q i − 1 , a i , q i ) ∈ δ int , and σ s i = σ s i − 1 for ev ery s ∈ [ K ]. The run ρ is accepting if q n ∈ F . A string w ∈ Σ + is accepted by A if there is an accepting run of A on w . T he set of accepted strings forms the (string) language of A , which is a subset of Σ + and denoted by L ( A ). 3 Example 2.2. There is no Mvp a that recog nizes th e con text-sensitiv e language { a n b n c n | n ≥ 1 } , n o matt er wh ic h call- return alphab et w e c hose. Note that, ho wev er, with the more general notion of a call-return alphab et f r om [8], it is p ossible to recognize th is language b y means of tw o stac ks. No w consid er th e 2-stac k call-return alphab et e Σ giv en by Σ 1 c = { a } , Σ 1 r = { a } , Σ 2 c = { b } , Σ 2 r = { b } , and Σ int = ∅ . The language L = { ( ab ) n a n +1 b n +1 | n ≥ 1 } can b e recognized by some 2 vp a o v er e Σ, ev en b y the restricted mo d el of 2-phase 2 vp a from [13], as ev ery word from L can b e split into at most tw o return ph ases. In the follo w ing, w e d efi n e a 2 vp a A = ( { q 0 , . . . , q 4 } , { $ , ⊥} , δ , { q 0 } , { q 0 } ) ov er e Σ su c h that L ( A ) = L + , which is no longer divisible in to a b ounded n u m b er of return phases. Th e transitio n relation δ is 3 T o simplify the presentati on, th e empty word ε is excluded from the domain. 6 B. BO LLIG giv en as follo ws (a graphical illustration is p ro vided in Figure 1): δ c : ( q 0 , a, $ , q 2 ) δ r : ( q 3 , a , $ , q 3 ) ( q 2 , b, $ , q 1 ) ( q 3 , a, ⊥ , q 4 ) ( q 1 , a, $ , q 2 ) ( q 4 , b, $ , q 4 ) ( q 2 , b, $ , q 3 ) ( q 4 , b, ⊥ , q 0 ) The idea is that the fin ite-state cont rol ensures that an input w ord matc h es the regular expression (( ab ) + a + b + ) + . T o guarantee that, in an y iteration, the n um b er of a is by one less than the num b er of a , an y push action a stores a stac k symb ol $ in stac k 1, whic h can then b e r emov ed b y the corresp onding p op action a u n less th e sym b ol ⊥ is disco v ered. W e do the same for b and b on stac k 2. q 0 q 1 q 2 q 3 q 4 a, $ b, $ a, $ b, $ a, ⊥ b, ⊥ b, $ a, $ Figure 1: A 2 vp a 2.2. Nested W ords and Multi-Stack N e st e d- W ord Automata. W e will now see how strings o ver sym b ols from the call-return alphab et e Σ can b e represen ted by r elational stru c- tures. Basically , to a string, w e add a b in ary pr edicate th at com b in es push with corresp ond- ing p op ev en ts. Let s ∈ [ K ]. A strin g w ∈ Σ ∗ is called s - wel l forme d if it is generated by the con text-free grammar A ::= aAb | AA | ε | c where a ∈ Σ s c , b ∈ Σ s r , and c ∈ Σ \ (Σ s c ∪ Σ s r ). Definition 2.3. A neste d wor d ov er e Σ is a structure ([ n ] , ⋖ , µ, λ ) where n ∈ N + (w e call the elemen ts from [ n ] p ositions , no des , or events ), ⋖ = { ( i, i + 1) | i ∈ [ n − 1] } , λ : [ n ] → Σ, and µ = S s ∈ [ K ] µ s ⊆ [ n ] × [ n ] where, for ev ery s ∈ [ K ] and ( i, j ) ∈ [ n ] × [ n ], ( i, j ) ∈ µ s iff i < j , λ ( i ) ∈ Σ s c , λ ( j ) ∈ Σ s r , and λ ( i + 1) . . . λ ( j − 1) is s -w ell formed. The set of nested words o v er e Σ is denoted b y NW ( e Σ). Figure 2 depicts a nested word o v er a 2-stac k call-return alphab et. Thr oughout the pap er, w e tak e adv an tag e of the fact th at nested w ord s o ve r a 2-sta c k call-return alphab et can b e written as a string with one t yp e of stack e dges ab o v e th e strin g and the other b elo w the s tring, w h ere the first typ e concerns the fi rst stac k and the other t yp e concerns the second stac k. In the 2-stac k case, the edges do not int ersect. Note that a nested word needs not b e wel l-matche d . It migh t hav e p ending calls, i.e., calls without matc hing r eturn, as we ll as p ending returns, i.e., r eturns that do not h a v e a m atc hing call. Therefore, the rela tions µ and its inv erse µ − 1 can b e s een as partia l maps [ n ] 99K [ n ], in the obvious mann er. Moreo v er, observe that, giv en nested w ords ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 7 W = ([ n ] , ⋖ , µ, λ ) and W ′ = ([ n ′ ] , ⋖ ′ , µ ′ , λ ′ ), n = n ′ ∧ λ = λ ′ implies W = W ′ . It is therefore justified to represent W as the string strin g( W ) := λ ( 1) . . . λ ( n ) ∈ Σ + . Th is naturally extends to sets L of nested w ord s and w e set string( L ) := { string( W ) | W ∈ L } . Vice ve rsa, given a string w ∈ Σ + , there is precisely one n ested word W ov er e Σ su c h that string( W ) = w . This uniqu e nested w ord is d enoted n ested( w ). F or L ⊆ Σ + , w e let nested( L ) := { nested( w ) | w ∈ L } . Example 2.4. Consider the 2-stac k call-return alphab et e Σ from Examp le 2.2, which w as giv en by Σ 1 c = { a } , Σ 1 r = { a } , Σ 2 c = { b } , Σ 2 r = { b } , and Σ int = ∅ . Figure 2 depicts a nested w ord W = ([ n ] , ⋖ , µ, λ ) o ver e Σ with n = 10. Th e straigh t arro w s represen t ⋖ , the cur v ed arro ws capture µ (those ab o v e th e horizon tal corresp ond to the fi rst stac k). F or example, (2 , 9) ∈ µ . Thus, µ (2) and µ − 1 (9) are d efined, w h ereas b oth µ − 1 (7) and µ − 1 (10) are not. In terms of visibly pu shdo wn automata, this means that p ositions 7 and 10 are emp lo yed when the fi rst/second stac k is empt y , resp ectiv ely . O bserv e that W = nested( a b a b a a a b b b ) and string( W ) = a b a b a a a b b b . a − → b − → a − → b − → a − → a − → a − → b − → b − → b 1 2 3 4 5 6 7 8 9 10 Figure 2: A nested w ord W e no w turn to an automata mo del that is suited to nested words and, to some exten t, is equiv alen t to Mvp a . Ou r mo del is an extension of n ested-w ord automata for one sta c k, whic h has b een considered in [2], to m ultiple stac ks. W e also extend the mo d el of [2] by c al ling states . If the state that is reac hed after executing some action a is a calling state, then the co rresp ond ing r un is accepting only if this a is a call with a matc h ing return (i.e., it is n ot p end ing). W e will later see that this concept do es not in crease the expr essiv e p o w er of our automata bu t turns out to b e a conv enien t to ol wh en w e translate logical formulas in to automata. Definition 2.5. A gener alize d multi-stack neste d-wor d automaton (generalized Mnw a ) ov er e Σ is a tuple B = ( Q, δ , Q I , F , C ) where • Q is the finite set of states , • Q I ⊆ Q is the set of initial states , • F ⊆ Q is the set of final states , • C ⊆ Q is a set of c al ling states , and • δ is a pair h δ 1 , δ 2 i of relations δ 1 ⊆ Q × Σ × Q and δ 2 ⊆ Q × Q × Σ r × Q , whic h con tain the tr ans itions . W e call B a multi-stack neste d-wor d automaton ( Mnw a ) if C = ∅ . A (gener alize d) 2-stack neste d-wor d automaton ((generalized) 2 nw a ) is a (generalize d, resp ectiv ely) Mn w a that is defined o v er a 2-stac k alphab et (i.e., K = 2). 8 B. BO LLIG In tuitiv ely , δ 1 con tains all the lo cal and push transitions, as well as all the p op transi- tions that act on an emp t y stac k (i.e., in terms of nested words and nested-word automata, those transitions that p erform an action fr om Σ r that is not matc hed by a corresp ond- ing calling action). A r un of B on a nested word W = ([ n ] , ⋖ , µ, λ ) ov er e Σ is a mapping ρ : [ n ] → Q such that ( q , λ (1) , ρ (1)) ∈ δ 1 for some q ∈ Q I , and, for all i ∈ { 2 , . . . , n } , we ha v e ( ( ρ ( µ − 1 ( i )) , ρ ( i − 1) , λ ( i ) , ρ ( i )) ∈ δ 2 if µ − 1 ( i ) is defined ( ρ ( i − 1) , λ ( i ) , ρ ( i )) ∈ δ 1 otherwise The ru n ρ is accepting if ρ ( n ) ∈ F and, for all i ∈ [ n ] with ρ ( i ) ∈ C , µ ( i ) is defined . T he language of B , denoted b y L ( B ), is the set of nested words from NW ( e Σ) that allo w for an accepting r un of B . Recall that there is a one-to-one corresp onden ce b et ween strings and nested words. W e let therefore L ( A ) w ith A an Mvp a stand for the set nested( L ( A )). Example 2.6. Consid er again the 2-st ac k call-return alphab et e Σ giv en by Σ 1 c = { a } , Σ 1 r = { a } , Σ 2 c = { b } , Σ 2 r = { b } , and Σ int = ∅ . I n Examp le 2.2, we hav e s een th at, for L = { ( ab ) n a n +1 b n +1 | n ≥ 1 } , the iteration L + is the language of some 2 vp a o ver e Σ. W e can also s p ecify a 2 nw a B = ( { q 0 , . . . , q 4 } , δ, { q 0 } , { q 0 } , ∅ ) ov er e Σ suc h th at L ( B ) = nested( L + ). Note that L ( B ) will con tain, for example, the nested word that is depicted in Figure 2. Th e transition rela tion δ is giv en as follo ws: δ 1 : ( q 0 , a, q 2 ) δ 2 : ( q 2 , q 3 , a, q 3 ) ( q 2 , b, q 1 ) ( q 3 , q 4 , b, q 4 ) ( q 1 , a, q 2 ) ( q 1 , q 4 , b, q 4 ) ( q 2 , b, q 3 ) ( q 3 , a, q 4 ) ( q 4 , b, q 0 ) Similarly to Example 2.2, the finite-state control will ensure the general regular structure of a word without explicit “coun ting”. Th is coun ting is then implicitly done b y the r elation δ 2 , which requires a matc hing call for a return . A graphical description of B is giv en in Figure 3 . Hereb y , a return transition with an adjoining set of states indicates that one state of this set must ha ve b een reac h ed r ight after executing the corresp on d ing call (in particular, the return must not b e p endin g), w hereas the r emaining return transitions, ( q 3 , a, q 4 ) and ( q 4 , b, q 0 ), apply only to p ending return s. q 0 q 1 q 2 q 3 q 4 { q 2 } , a { q 1 , q 3 } , b a b a b b a Figure 3: A 2 nw a ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 9 A general te c h nique for a r eduction from Mvp a to Mnw a and vice versa can b e found b elo w (Lemma 2.8). W e can sho w that the use of calling states does not in crease the expressiv eness of Mnw a . Note that, how ev er, the concept of calling states will turn out to b e helpful when building the sphere automat on in Section 4.2. Lemma 2.7. F or every gene r alize d Mnw a B over e Σ , ther e is an Mnw a B ′ over e Σ such that L ( B ′ ) = L ( B ) . Pr o of. In the construction of a n Mnw a , we e xploit the follo wing pr op ert y of a nested w ord W = ([ n ] , ⋖ , µ, λ ): giv en ( i, j ) ∈ µ , sa y , with λ ( i ) ∈ Σ s c , µ ( i ′ ) is defin ed for all i ′ ∈ { i + 1 , . . . , j − 1 } satisfying λ ( i ′ ) ∈ Σ s c . Ba sically , B ′ will sim ulate B . In addition, whenev er a calling sta te is assigned to a p osition lab eled with an elemen t from Σ s c , w e will set a flag b[ s ] = 1, w hic h can only b e resolv ed and turn into a fi n al state (b[ s ] = 0) wh en a matc hing retur n position has b een found. As any int erim call p osition that concerns stac k s is matc hed anyw a y , th e flags b[ s ] in that in terv al are set to 2. T h us, while a fl ag is 1 or 2, th ere is still some unmatc hed calling p osition. Hence, a final stat e requires eve ry flag to equal 0, whic h also designates the initial state. Let us b ecome more precise and let B = ( Q, δ, Q I , F , C ) b e a generalize d Mnw a . W e determine the Mnw a B ′ = ( Q ′ , δ ′ , Q ′ I , F ′ , ∅ ) by Q ′ = Q × { 0 , 1 , 2 } [ K ] , Q ′ I = Q I × { (0) s ∈ [ K ] } , F ′ = F × { (0) s ∈ [ K ] } , and δ ′ = h δ ′ 1 , δ ′ 2 i where • δ ′ 1 is the set of triples (( q , b) , a, ( q ′ , b ′ )) ∈ Q ′ × Σ × Q ′ suc h that ( q , a, q ′ ) ∈ δ 1 , q ′ ∈ C implies a ∈ Σ c , and, for ev ery s ∈ [ K ], b ′ [ s ] =        2 if b[ s ] ∈ { 1 , 2 } 1 if b[ s ] = 0 and a ∈ Σ s c and q ′ ∈ C 0 otherwise • δ ′ 2 is the set of quadru ples (( p, c) , ( q , b ) , a, ( q ′ , b ′ )) ∈ Q ′ × Q ′ × Σ r × Q ′ suc h that ( p, q , a, q ′ ) ∈ δ 2 , q ′ 6∈ C , and, for every s ∈ [ K ], b ′ [ s ] = ( 0 if c[ s ] = 1 b[ s ] otherwise In fact , w e can sho w that L ( B ) = L ( B ′ ). Note that the flag assignmen ts dep end d eterministicall y on the inpu t word and the states assig ned to the p ositions. Let W = ([ n ] , ⋖ , µ, λ ) b e a nested word o v er e Σ. Supp ose ρ to b e an accepting run of B on W and let b ρ : [ n ] → { 0 , 1 , 2 } [ K ] b e the unique supplement of ρ according to the fl ag construction. T o v erify that ( ρ, b ρ ) is indeed an accepting r un of B ′ on W , w e need to sho w that b ρ ( n )[ s ] = 0 for all s ∈ [ K ]. So let s ∈ [ K ]. If there is no i ∈ [ n ] suc h that λ ( i ) ∈ Σ s c and ρ ( i ) ∈ C , then we clearly hav e b ρ ( n )[ s ] = 0, as the flag for stac k s n ev er c h anges its v alue during the run . If the flag changes its v alue from 0 to 1, then this happ ens at a p osition i ∈ [ n ] suc h that λ ( i ) ∈ Σ s c and ρ ( i ) ∈ C . As ρ is an acc epting run of B on W , there is j ∈ [ n ] suc h that ( i, j ) ∈ µ . By construction of B ′ , b ρ ( i )[ s ] = 1, b ρ ( i ′ )[ s ] = 2 for all i ′ ∈ { i + 1 , . . . , j − 1 } , and b ρ ( j )[ s ] = 0. T h us, we finally ha ve b ρ ( n )[ s ] = 0. Con v ersely , le t ρ : [ n ] → Q and b ρ : [ n ] → { 0 , 1 , 2 } [ K ] b e mappings such that ( ρ, b ρ ) is an accepting run of B ′ on W . Clearly , ρ is a run of B on W . So let u s v erify that it is accepting. 10 B. BO LLIG First, observ e th at ρ ( n ) ∈ F . So sup p ose i ∈ [ n ] su c h that ρ ( i ) is a calling state. Acco rding to the construction of B ′ , λ ( i ) ∈ Σ s c for some s . Moreo ver, we hav e b ρ ( i )[ s ] = { 1 , 2 } . As b ρ ( n )[ s ] = 0, there must b e i ′ ≤ i and j ′ > i su c h that λ ( i ′ ) ∈ Σ s c and ( i ′ , j ′ ) ∈ µ . T his implies that µ ( i ) is ind eed defi n ed so that we can conclude that ρ is an accepting run of B on W . The flag construction from the previous p ro of is illustrated in Figure 4, where we assu me a run on the nested word su c h that ev ery s tate asso ciated with a symb ol fr om { a, b } is a calling sta te. a − → b − → a − → b − → a − → a − → a − → b − → b − → b 1 2 3 4 5 6 7 8 9 10 b[1] b[2] ! 0 0 ! 1 0 ! 2 1 ! 2 2 ! 2 2 ! 2 2 ! 0 2 ! 0 2 ! 0 2 ! 0 0 ! 0 0 ! Figure 4: The flag construction Lemma 2.8. L et L ⊆ NW ( e Σ) b e a set of neste d wor ds over e Σ . The fol lowing ar e e quivalent: (1) Ther e is an Mvp a A over e Σ such that L ( A ) = L . (2) Ther e is an Mnw a B over e Σ such that L ( B ) = L . Pr o of. Giv en an Mvp a A = ( Q, Γ , δ, Q I , F ), we d efine an Mn w a B = ( Q ′ , δ ′ , Q ′ I , F ′ , ∅ ) with L ( A ) = L ( B ) as follo ws: Q ′ = Q × Γ, Q ′ I = Q I × {⊥} , F ′ = F × Γ, and δ ′ = h δ ′ 1 , δ ′ 2 i where • δ ′ 1 is the set of triples (( q, A ) , a, ( q ′ , A ′ )) ∈ Q ′ × Σ × Q ′ suc h t hat ( q, a, A ′ , q ′ ) ∈ δ c , ( q , a, q ′ ) ∈ δ int , or ( q , a, ⊥ , q ′ ) ∈ δ r , and • δ ′ 2 is the s et of quadruples (( p, B ) , ( q , A ) , a, ( q ′ , A ′ )) ∈ Q ′ × Q ′ × Σ × Q ′ suc h that ( q , a, B , q ′ ) ∈ δ r . The idea is that the stac k symb ol asso ciated with a transition is incorp orated into the state of the Mnw a . When an inte rnal or unm atc hed return action is p erformed, then w e ma y c h ose an arbitrary stac k symbol, as it will not b e reconsidered later in the run. F or the con v erse direction, let B = ( Q, δ , Q I , F , ∅ ) b e an Mnw a . Consider the Mvp a A = ( Q, Q · ∪ {⊥} , δ ′ , Q I , F ) where δ ′ = h δ ′ c , δ ′ r , δ ′ int i is giv en b y • δ ′ c = { ( q , a, q ′ , q ′ ) | ( q , a, q ′ ) ∈ δ 1 ∩ ( Q × Σ c × Q ) } , • δ ′ int = δ 1 ∩ ( Q × Σ int × Q ), and • δ ′ r is the set of tuples ( q , a, A, q ′ ) ∈ Q × Σ r × Γ × Q suc h that either ( q , a, q ′ ) ∈ δ 1 and A = ⊥ , or ( A, q , a, q ′ ) ∈ δ 2 . Here, w e n eed to ensur e that, when A p erforms a matc hed return action, we can access th e state that B has asso ciated with the corresp ond ing call. T o this aim, A j ust push es the state on to the stac k so that it b ecomes ac cessible when the corresp onding return is executed. It is straight forw ard to s h o w that L ( A ) = L ( B ). ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 11 3. Monadic Second-Order Logic and Hanf’s Theorem 3.1. Monadic Second-Order Log ic ov er Relational Structures. W e fi x supplies of first-order v ariables x, y , . . . and second-order v ariables X, Y , . . . . Let τ b e a fu n ction-free signature. The set MSO( τ ) of monadic se c ond-or der (MSO) form ulas o v er τ is giv en by th e follo wing grammar: ϕ ::= P ( x 1 , . . . , x m ) | x 1 = x 2 | x ∈ X | ¬ ϕ | ϕ 1 ∨ ϕ 2 | ∃ xϕ | ∃ X ϕ Hereb y , m ≥ 1, P ∈ τ is an m -ary predicate symbol, the x k and x are first-order v ariables, and X is a second-order v ariable. Moreo v er, we will make use of the usual abbreviations suc h a s ϕ 1 ∧ ϕ 2 for ¬ ( ¬ ϕ 1 ∨ ¬ ϕ 2 ), ϕ 1 → ϕ 2 for ¬ ϕ 1 ∨ ϕ 2 , etc. Giv en a τ -structure A with u niv erse A , a formula ϕ ( x 1 , . . . , x m , X 1 , . . . , X n ) ∈ MSO( τ ) with free v ariables in { x 1 , . . . , x m , X 1 , . . . , X n } , ( u 1 , . . . , u m ) ∈ A m , and ( U 1 , . . . , U n ) ∈ (2 A ) n , we write, as usual, A | = ϕ [ u 1 , . . . , u m , U 1 , . . . , U n ] if A satisfies ϕ wh en assigning ( u 1 , . . . , u m ) to ( x 1 , . . . , x m ) and ( U 1 , . . . , U n ) to ( X 1 , . . . , X n ). Let u s ident ify some imp ortant fragmen ts of MSO( τ ). Th e set F O( τ ) of first or der (F O) form ulas o ver τ comprises those form u las from MSO( τ ) that do not con tain an y second-order quan tifier. F urthermore, an existential MSO (EMSO) form u la is of the form ∃ X 1 . . . ∃ X n ϕ with ϕ ∈ F O( τ ). Th e corresp ond ing class of form ulas is d enoted EMSO( τ ). More generally , giv en m ≥ 1, we d enote b y Σ m ( τ ) th e set of form ulas of the form ∃ X 1 ∀ X 2 . . . ∃ / ∀ X m ϕ where ϕ ∈ F O ( τ ) and the X k are blo cks of second-order v ariables, p ossibly empty or of differen t length. W e will later mak e use of the notion of definability relativ e to a class of stru ctures. Let F ⊆ MSO( τ ) b e a cl ass of form ulas and L , C b e sets of τ -structures. W e sa y that L is F - definable r elative to C if there is a sen tence (i.e., a formula without any free v ariables) ϕ ∈ F such that L is the set of τ -structures A ∈ C suc h that A | = ϕ . 3.2. Hanf ’s Theorem for Nested W ords, and Spheres. W e will n o w pro vid e a s igna- ture that allo ws us to sp ecify MSO prop erties of nested w ord s. Let e Σ b e a call-ret urn alphab et. W e defin e τ e Σ to b e the signature { λ a | a ∈ Σ } ∪ { ⋖ , µ } with λ a a unary and ⋖ and µ binary predicate symb ols. W e wr ite the MSO f ormula λ a ( x ) as λ ( x ) = a and the f ormula ⋖ ( x 1 , x 2 ) as x 1 ⋖ x 2 . M SO form ulas ov er τ e Σ can b e c anonically in- terpreted o ver nested w ords ([ n ] , ⋖ , µ, λ ) ∈ NW ( e Σ), as λ can b e seen as a collection of unary relations λ a = { i ∈ [ n ] | λ ( i ) = a } w here a ∈ Σ . Th us, nested w ords o v er e Σ are ac tually τ e Σ -structures. A sample MSO formula o ver τ e Σ suc h that Σ = { a, b } is ∀ x ∀ y ( λ ( x ) = a ∧ µ ( x, y ) → λ ( y ) = b ). It expresses that ev ery matc hing p air with a ca lling a has a b -lab eled return p osition. Giv en a s entence ϕ ∈ MSO( τ e Σ ), w e d en ote by L ( ϕ ) the set of nested w ords o v er e Σ th at s atisfy ϕ , i.e ., L ( ϕ ) = { W ∈ NW ( e Σ) | W | = ϕ } . Ov er nested w ords (more generall y , structur es of b oun ded degree) , FO form ulas enjoy a normal form in terms of lo cal form ulas. A form u la ϕ ( x ) ∈ F O ( τ e Σ ) with one free v ariable x is said to b e lo c al if there is r ∈ N su c h that, in every subformula ∃ y ψ of ϕ , ψ is of the form ( d ( x, y ) ≤ r ) ∧ χ . Hereb y , the form ula d ( x, y ) ≤ r has the exp ected meaning and ca n b e obtained inductiv ely . Informally , the tru th of a lo cal form u la ϕ ( x ) dep end s only on the lo cal neigh b orho o d around x . Next, we state Hanf ’s localit y theorem in terms of nested w ords. It act ually applies to general classes of structures of b ounded d egree. 12 B. BO LLIG Theorem 3.1 (Hanf [11]) . L et ϕ ∈ F O ( τ e Σ ) b e a sentenc e . Ther e is a p ositive Bo ole an c ombination ψ of formulas of the form ∃ = t x χ ( x ) and ∃ >t x χ ( x ) wher e t ∈ N and χ ∈ F O( τ e Σ ) is lo c al (with the obvious me aning of the quantifiers ∃ = t and ∃ >t ; note that ther e might o c cur differ ent thr esholds t in ψ ) su c h that, for every neste d wor d W ∈ NW ( e Σ) , we have W | = ϕ iff W | = ψ . Mor e over, ψ c an b e c ompute d effe ctively and in elementary time. F or a comprehensiv e pro of of this theorem, see, for example, [16, 20]. Ho w ev er, th ese pro ofs are not effectiv e, whereas the original pro of by Hanf is effectiv e. It is cru cial to note that Hanf ’s Theorem applies to the case of nested words as we deal with a class of s tr u ctures of b ounded degree (see b elo w for a formal definition). Indeed, there is a uniform b ound on the degree of nested words. Let A = ( N , ⋖ , µ, λ, . . . ) and A ′ = ( N ′ , ⋖ ′ , µ ′ , λ ′ , . . . ) b e tup les such that ( N , ⋖ , µ, λ ) and ( N ′ , ⋖ ′ , µ ′ , λ ′ ) are τ e Σ -structures. F or i, j ∈ N and i ′ , j ′ ∈ N ′ , we wr ite ( i, j ) ⊑ A A ′ ( i ′ , j ′ ) if λ ( i ) = λ ′ ( i ′ ), λ ( j ) = λ ′ ( j ′ ), ( i, j ) ∈ ⋖ implies ( i ′ , j ′ ) ∈ ⋖ ′ , and ( i, j ) ∈ µ implies ( i ′ , j ′ ) ∈ µ ′ . Theorem 3.1 suggests that, o v er nested w ords, the v alidit y of an F O f ormula in a nested w ord dep ends on the lo cal n eigh b orho o ds of the latter. T his leads to the notion of a spher e , whic h w ill actually pla y a cen tral role in the r emainder of this pap er. A sphere of radius r ∈ N includes elemen ts whose distance from a distinguished sphere cent er is b oun ded b y r . Give n i, j ∈ N , the dist anc e d A ( i, j ) of i and j in A is the minimal length of a path from i to j in the Gaifman gr aph of ( N , ⋖ , µ, λ ). The Gaifman graph of ( N , ⋖ , µ, λ ) is defined to b e the u ndirected graph ( N , Ar cs ) where ( i, j ) ∈ Ar cs iff ( i, j ) ∈ ⋖ ∪ µ ∪ ⋖ − 1 ∪ µ − 1 [16]. In p articular, we hav e d A ( i, i ) = 0. If d A ( i, j ) = 1, we also wr ite i ↔ A j . W e wr ite i → A j if ( i, j ) ∈ ⋖ ∪ µ . Th e degree of a τ e Σ -structure is said to b e b ounde d b y some natural num b er B if the degree of its Gaifman graph is b oun ded by B . Ob serv e that the d egree of a nested w ord is b ounded b y 3, w hic h is therefore a uniform b ound f or the class NW ( e Σ). Let B = ( N , ⋖ , µ, λ ) b e a τ e Σ -structure, r ∈ N , and i ∈ N . The r - spher e of B aroun d i , which w e d enote b y r -Sph( B , i ), is basically the substru ctur e of B ind uced by the new univ erse { j ∈ N | d B ( i, j ) ≤ r } , but extended by the constan t i as a d istinguished elemen t, called the spher e c enter . Giv en an isomorphism t yp e S of an r -sphere, we let | B | S := |{ i ∈ N | S ∼ = r -Sph( B , i ) }| den ote the num b er of p oin ts in B that r e alize S . F or an example, consider Figure 5, sho wing a nested w ord W and the 2-sph ere of W around i = 10 w here the sph ere cen ter is marke d as a rectangle. Note that 2-Sp h( W , 10) ∼ = 2-Sph( W , 14) and | W | 2-Sph( W , 10) = 2. W e denote b y Spher es r ( e Σ) the set of (iso morphism t yp es of ) r -spheres that arise from nested words o v er e Σ, i.e., Spher es r ( e Σ) := { r - Sph( W , i ) | W ∈ NW ( e Σ) and i is a no de of W } . Note that Spher es r ( e Σ) is fin ite up to isomorphism, wh ic h is crucial for the constructions in Section 4 . ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 13 c − → a − → b b − → b − → a − → b − → b j 1 j 2 j c − → a − → b − → c − → a − → b − → b − → b − → b − → a − → b − → b − → b − → a − → b − → b i i ′ i 1 i 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 6 Figure 5: A 2-shp ere em b edded in to a nested w ord 4. 2-St a ck Visibl y Pushd own A u toma t a vs. Logic In this s ection, we f o cus on 2 vp a . So let us fi x a 2-stac k call-return alphab et e Σ = h{ (Σ 1 c , Σ 1 r ) , (Σ 2 c , Σ 2 r ) } , Σ int i . 4.1. The Main Result. The key connection b et w een FO logic and 2 vp a /2 nw a is pr o vid ed b y th e follo wing pr op osition, whic h states the existence of an automaton that compu tes the sphere around an y nod e of a nested w ord. Prop osition 4.1. L et r b e any natur al numb er. Ther e ar e a gener alize d 2 nw a B r = ( Q, δ, Q I , F , C ) over e Σ and a mapping η : Q → Spher es r ( e Σ) such that • L ( B r ) = NW ( e Σ) (i.e., eve ry neste d wor d admits an ac c epting run of B r ), and • for every neste d wor d W ∈ NW ( e Σ) , every ac c epting run ρ of B r on W , and every no de i of W , we have η ( ρ ( i )) ∼ = r - Sph( W , i ) . Before we turn tow ards the pro of of this statemen t, we will fi rst show ho w Prop osi- tion 4. 1 ca n b e u sed to establish expr essiv e equiv alence of 2 vp a and EMSO logic. Lemma 4.2 . L et r, t ∈ N and let S ∈ Spher es r ( e Σ) b e an r -spher e in some neste d wor d over e Σ . Ther e ar e gener alize d 2 nw a B 1 and B 2 over e Σ such that L ( B 1 ) = { W ∈ NW ( e Σ) | | W | S = t } and L ( B 2 ) = { W ∈ N W ( e Σ) | | W | S > t } . Pr o of. In b oth cases, we start from the generalized 2 nw a B r = ( Q, δ, Q I , F , C ) and the mapping η : Q → Spher es r ( e Σ) from Prop osition 4.1. F or k = 1 , 2, w e obtain B k b y extending the state space with a count er that, using η , counts the n um b er of realizat ions of S up to t + 1. The n ew set of in itial states is th us in b oth cases Q I × { 0 } . Ho wev er, the set of final s tates of B 1 is F × { t } , the one of B 2 is F × { t + 1 } . 14 B. BO LLIG W e are now pr epared to state the first m ain result of this pap er. Theorem 4.3. L et L ⊆ NW ( e Σ) b e a set of neste d wor ds over the 2-stack c al l-r eturn alphab et e Σ . Then, the fol lowing ar e e quivalent: (1) Ther e is a 2 vp a A over e Σ such that L ( A ) = L . (2) Ther e is a sentenc e ϕ ∈ EMS O( τ e Σ ) such that L ( ϕ ) = L . Both dir e c tions ar e effe ctive. In p articular, the 2 vp a that we c onstruct for a given EMSO sentenc e c an b e c ompute d in elementary time, and its size is elementary in the size of the formula. Pr o of. T o pro v e (1) → (2), one can p erform a standard constru ction of an EMSO for- m ula from a 2 nw a , where the latter can b e extracted from the giv en 2 vp a according to Lemma 2.8. Basical ly , the formula “guesses” a p ossible run on the input w ord in terms of existen tially qu an tified seco nd-order v ariables and then verifies, in its first-order fragmen t, that we actually deal with a run that is accepting. So let us directly pro v e (2) → (1) and let ϕ = ∃ X 1 . . . ∃ X m ψ ( X 1 , . . . , X m ) ∈ EMSO( τ e Σ ) b e a sentence with ψ ( X 1 , . . . , X m ) ∈ F O( τ e Σ ) (we s u pp ose m ≥ 1). W e define a new 2-stac k call-return al phab et b Σ = h{ (Σ 1 c × 2 [ m ] , Σ 1 r × 2 [ m ] ) , (Σ 2 c × 2 [ m ] , Σ 2 r × 2 [ m ] ) } , Σ int × 2 [ m ] i where 2 [ m ] shall denote the p o w erset of [ m ]. F rom ψ , w e obtain an FO form ula ψ ′ o ver τ b Σ b y replaci ng eac h o ccurrence of λ ( x ) = a with W M ∈ 2 [ m ] λ ( x ) = ( a, M ) and eac h o ccurrence of x ∈ X k with W a ∈ Σ , M ∈ 2 [ m ] λ ( x ) = ( a, M ∪ { k } ). W e set L ⊆ N W ( b Σ) to b e the s et of nested w ord s that sati sfy ψ ′ . F rom Hanf ’s Theorem (Theorem 3.1), w e kn o w that L is the language of a p ositiv e Bo olean com bination of formulas of the f orm ∃ = t x χ ( x ) and ∃ >t x χ ( x ) where χ is lo cal. It is easy to see that the class of n ested-w ord languages that are recognized b y generalized 2 nw a is closed un der un ion and intersect ion. Thus, the v alidit y of one suc h basic form ula can b e c hec ked by a generalized 2 nw a due to Lemma 4.2. W e deduce that there is a generali zed 2 nw a B ′ o ver e Σ r ecognizing L . No w, to c h ec k w hether s ome nested w ord from N W ( e Σ) satisfies ϕ , a generalized 2 nw a B with L ( B ) = L ( ϕ ) will guess an additional lab eling for eac h no de in terms of an elemen t from 2 [ m ] and then simulate B ′ . By Lemma 2.7 and Lemma 2.8, we finally obtain a 2 vp a A suc h that L ( A ) = L ( ϕ ). 4.2. Pro of of Prop osition 4.1. W e n o w turn to the pro of of Pr op osition 4.1. In eac h state, the generalized 2 nw a B r will guess the curren t sphere as wel l as spheres of no d es nearb y and the current p osition in these add itional sp heres. Add ing s ome global information allo ws us to lo cally c h ec k whether all the guesses are correct. Th e rest of this section is dev oted to the construction of B r and a corresp ond ing mapping η to pro ve Prop osition 4.1. 4.2.1. The Construction. Recall that Spher es r ( e Σ) denotes the set of all the r -spheres that arise from nested w ords, i.e., Spher es r ( e Σ) = { r - Sph( W , i ) | W is a nested word and i is a p osition in W } . An extende d r -sphere o v er e Σ is a tuple E = ( N , ⋖ , µ, λ, γ , α, c ol ) where c or e ( E ) := ( N , ⋖ , µ, λ, γ ) ∈ Spher e s r ( e Σ) (in p articular, γ ∈ N ), α ∈ N , and c ol ∈ [# Col ] with # Col = 4 · maxSize ( r ) 2 + 1 w here maxSize ( r ) is the maximal size of an r -sphere, i.e., maxSize ( r ) = max {| N | | ( N , ⋖ , µ, λ, i ) ∈ Spher es r ( e Σ) } . W e sa y that α is the active ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 15 no de of E and c ol is its c olo r . Str ictly sp eaking, ( N , ⋖ , µ, λ, γ , α, c ol ) is n ot a m athematica l structure, as c ol do es not refer to an elemen t of N . W e int ro duced the fu nction c or e to extract a m athematica l structure fr om an extended sphere, wh ich will allo w us to deal with notions suc h as isomorphism. Let eSpher es r ( e Σ) d en ote the set of all the (isomorphism classes of ) extended spheres o ver e Σ. F or an extended sphere E = ( N , ⋖ , µ, λ, γ , α, c ol ) and an elemen t i ∈ N , we denote b y E [ i ] the extended sphere ( N , ⋖ , µ, λ, γ , i, c ol ), i.e., the extended sphere that w e obtain b y replacing the ac tiv e no de α with i . The idea of the construction of the generalize d 2 nw a B r is the follo wing: A state E of B r is a set of extended spheres, w h ic h r eflect the “en vironmen t” of a n o de th at E is assigned to. No w supp ose that, in a r un of B r on a nested wo rd f W = ([ e n ] , e ⋖ , e µ , e λ ), E is assigned to a p osition i ∈ [ e n ] and con tains E = ( N , ⋖ , µ, λ, γ , α, c ol ). If the run is accepting, this will mean that the environmen t of i in f W lo oks lik e the environmen t of α in E . In particular, E will con tain exactly one extended sp here E = ( N , ⋖ , µ, λ, γ , α, c ol ) such that γ and α coincide, m eaning that r -Sph( f W , i ) ∼ = ( N , ⋖ , µ, λ, γ ). This is illustrated in Figure 6 depicting a nested w ord and a step of a run of the sphere automaton for r = 1 on this w ord. States E and E ′ are assigned to positions 4 and 5, resp ectiv ely . Eac h state is a set of extended spheres. F or clarit y , ho w ev er, w e will neglect colors in the example. Th e sphere cen ter is, as u sual, d epicted as a rectangle; the activ e n o de is mark ed as a circle. Observe that eac h state con tains p recisely one exte nded sphere in whic h the sph ere ce n ter and the activ e no de are ident ical. These are E 1 ∈ E , and, resp ectiv ely , E ′ 2 ∈ E ′ . Ind eed, E 1 corresp onds to th e 1-sphere of the nested word around 4, while E ′ 2 reflects the 1-sphere around 5. Of course, B r has to lo cally guess the en vironm en t of a p osition. But ho w ca n w e ensure that a guess is correct? Obviously , w e ha v e to pass a lo cal guess to eac h n eigh b oring p osition in f W . So su pp ose again that a s tate E conta ining E = ( N , ⋖ , µ, λ, γ , α, c ol ) is assigned to a no de i of f W . As α shall co rresp ond to i , we need to ensure that λ ( α ) = e λ ( i ) (this will b e tak en care of by item (2) in the definition of the transition relation b elo w). No w supp ose that α has a ⋖ -successor j ∈ N , i.e., α ⋖ j . Then, we hav e to guaran tee that i < e n . Th is is done b y simply excluding E from the set of final states (in Figure 6, neither E nor E ′ are final states). Moreo v er, j sh ould corresp ond to i + 1, w hic h is ensu red by passing E [ j ] to the state that will b e assigned to i + 1 (see item (7); in Figure 6, E ′ m ust therefore con tain E 1 [ j ] where j is the ⋖ -successor of the activ e no de of E 1 , and we actually hav e E ′ 1 ∼ = E 1 [ j ]). On the other hand, if i h as a e ⋖ -successor, th en α m ust ha v e a ⋖ -successor j as wel l suc h that E [ j ] b elongs to the state that will b e assigned to i + 1. Observe that this rule applies un less d E ( γ , α ) = r , as then i + 1 lies out of the area of resp onsibilit y of E (see item (5)). Similar requirements ha v e to b e considered wrt. p oten tial ⋖ -/ e ⋖ -predecessors (see (3), (4), and (6)), as wel l as wrt. the relations µ and e µ (see (3’)–(7’)). On e d ifficult y in our construction, ho w ever, is to guaran tee the lac k of an edge. So assume the extended sphere E is the one giv en b y Figure 5 with j 1 as the activ e no de. Let us neglect colors for the moment. Supp ose fur thermore that f W is the nested w ord f r om Figure 5 , b elo w the sphere. Then, an accepting run ρ of B r on f W will assign to i 1 a state that conta ins E (mo dulo some coloring). Moreo v er, th e state assigned to i will conta in E [ j ], where the sphere cente r and the activ e no de coincide. W e observe that, in E , th e no de j 1 is m aximal. In particular, there is no µ -edge b et w een j 1 and j 2 . This should b e reflected in f W . A first idea to guaran tee this m ight b e to just pr ev ent ρ ( i 2 ) from con tai ning the extended sp here 16 B. BO LLIG a − → b − → a − → b − → a − → a − → a − → b − → b − → b E E ′ 1 2 3 4 5 6 7 8 9 10 E : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E 1 : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E 2 : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E 3 : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E 4 : — E ′ : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E ′ 1 : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E ′ 2 : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E ′ 3 : a − → b − → a − → b − → a − → a − → a − → b − → b − → b E ′ 4 : Figure 6: A step of th e sphere automato n E [ j 2 ] (note that ( i 1 , i 2 ) ∈ e µ ). This is, ho w ever, too restrictiv e. Actually , ( r -Sph( f W , i ) , i 2 ) and E [ j 2 ] are isomorphic (neglecting the coloring of E ) so th at ρ ( i 2 ) must con tain E [ j 2 ]. The solution is already pr esen t in terms of the coloring of extended spheres. More precisely , ρ ( i 2 ) is allo wed to carry E [ j 2 ] as so on as it has a color th at is differen t from the color of the extended sph ere E [ j 1 ] assigned to i 1 . R ou ghly sp eaking, there migh t b e isomorphic sp heres in f W that are o v erlapping. T o consider them sim ultaneously , they are th u s equipp ed with distinct co lors. The construction we obtain follo wing the ab o v e ideas indeed allo ws us to infer, from an accepting run assigning a state E to a no de i , the r -sp here aroun d i . As m en tioned ab o v e, w e simp ly consider the (unique up to isomorphism) extended sph ere ( N , ⋖ , µ, λ, γ , α, c ol ) con tained in E such that γ = α . Then, ( N , ⋖ , µ , λ, γ ) is indeed the sphere of in terest (recall that, in Figure 6, these are E 1 for E and E ′ 2 for E ′ if we ignore activ e no des and colors). It is n ot obvio us that the ab ov e id eas really d o wo rk, all the less as the constru ction will apply to nested w ords o v er tw o stac ks, but n o longer to nested w ords o ver more than t wo stac ks. After all, the key argum en t will b e p ro vided by Prop osition 4.5, stating an imp ortant prop ert y of nested wo rds o ve r t wo stac ks. In tuitiv ely , it states the follo w in g: Supp ose that, in a nested w ord, there is an acyclic path from a no d e i to another no de i ′ , and supp ose this path is of a certa in t yp e w (recording the lab elings and edges seen in the path). Then, applying th e same path seve ral times will never lead back to i . Th is is fin ally the reason why a cycle in an extended sphere that o ccurs in a run on a nested word f W is in f act simulate d b y f W . ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 17 Let us formally construct the generalized 2 nw a B r = ( Q, δ , Q I , F , C ). An element of Q is a subs et E of eSpher es r ( e Σ) such that either E = ∅ , whic h will b e the only initial state, or the follo wing conditions are satisfied: (a) there is a u nique ext ended sphere ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E su c h that γ = α (w e set c or e ( E ) := ( N , ⋖ , µ, λ, γ )) (b) there is a ∈ Σ suc h that, for ev ery ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E , λ ( α ) = a (so th at we can assign a unique lab el a to E , denoted b y lab el ( E )) (c) for ev ery tw o e lemen ts E = ( N , ⋖ , µ, λ, γ , α, c ol ) and E ′ = ( N ′ , ⋖ ′ , µ ′ , λ ′ , γ ′ , α ′ , c ol ′ ) from E , if c or e ( E ) = c or e ( E ′ ) and c ol = c ol ′ , then α = α ′ So let us turn to the transition relatio n δ = h δ 1 , δ 2 i : • F or E , E ′ ∈ Q and a ∈ Σ, w e let ( E , a, E ′ ) ∈ δ 1 if E ′ 6 = ∅ and the follo wing hold: (1) for all ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E ′ , α 6∈ dom( µ − 1 ) (i. e., µ − 1 ( α ) is not defined) (2) lab el ( E ′ ) = a (3) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E and i ∈ N , E [ i ] ∈ E ′ = ⇒ ( α, i ) ∈ ⋖ (4) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E ′ , E 6 = ∅ ∧ ¬∃ i : ( i, α ) ∈ ⋖ = ⇒ d E ( γ , α ) = r (5) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E , ¬∃ i : ( α, i ) ∈ ⋖ = ⇒ d E ( γ , α ) = r (6) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E ′ and i ∈ N , ( i, α ) ∈ ⋖ = ⇒ E [ i ] ∈ E (7) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E and i ∈ N , ( α, i ) ∈ ⋖ = ⇒ E [ i ] ∈ E ′ • F or E c , E , E ′ ∈ Q and a ∈ Σ r , we let ( E c , E , a, E ′ ) ∈ δ 2 if E c , E , E ′ 6 = ∅ and (2)–(7) as ab ov e hold as we ll as the foll o w ing: (3’) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E c and i ∈ N , E [ i ] ∈ E ′ = ⇒ ( α, i ) ∈ µ (4’) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E ′ , α 6∈ dom( µ − 1 ) = ⇒ d E ( γ , α ) = r (5’) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E c , α 6∈ dom( µ ) = ⇒ d E ( γ , α ) = r (6’) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E ′ , α ∈ dom( µ − 1 ) = ⇒ E [ µ − 1 ( α )] ∈ E c (7’) for all E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E c , α ∈ dom( µ ) = ⇒ E [ µ ( α )] ∈ E ′ As already men tioned, the only initial state of B r is the empt y set, i.e., Q I = {∅} . Moreo v er, E ∈ Q is a final state if, for ev ery extended sphere ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E , b oth α 6∈ dom( µ ) and th ere is no i ∈ N such that ( α, i ) ∈ ⋖ . Finally , E is con tained in C , the set of calling sta tes, if there is ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ E su c h that α ∈ dom( µ ). 18 B. BO LLIG The mapping η : Q → Spher es r ( e Σ) as required in Prop osition 4.1 is pro vided b y c or e . More p recisely , w e set η ( ∅ ) to b e some arb itrary sp here and η ( E ) = c or e ( E ) if E 6 = ∅ . Let u s come bac k to the example in Figure 6, depicting t wo states, E and E ′ , of the sphere automaton for radiu s r = 1, and a nested wo rd that mak es use of these states for b eing ac cepted. The sp here automaton con tains a transitio n ( E c , E , a, E ′ ) for some E c . W e will ve rify in the follo wing th at conditions (2)–(7) are indeed satisfied. T he cases (3’)–( 7’) as w ell as the construction of E c are left to the reader. (2) All the activ e no des in E ′ are la b eled with a . (3) Whenev er a sphere fr om E is already pr esen t in E ′ , then th e corresp ond ing activ e no des are in the ⋖ -relation. Th is app lies to E 1 and E ′ 1 as well as to E 2 and E ′ 2 . (4) The exte nded sphere E ′ 4 is the only one in E ′ whose activ e no de has no ⋖ -predecessor. Ho wev er, the distance b et w een this ac tiv e no de and the sphere cen ter equals r = 1. (5) There is one extended sphere in E without a ⋖ -successor wrt. the act iv e no d e, namely E 4 . As required, the distance to the sphere cent er is r = 1. (6) There are thr ee extended sph eres in E ′ whose activ e n o des h a ve a ⋖ -predecessor: E ′ 1 , E ′ 2 , and E ′ 3 . In f act, E con tains, in terms of E 1 , E 2 , and, resp ectiv ely , E 3 , all three extended sp heres with the activ e no de r eplaced by the resp ectiv e ⋖ - predecessor. (7) Symmetrically to the case (6), E 1 , E 2 , and E 3 from E , where the activ e no de is follo w ed b y a ⋖ -successor, ha v e their coun terparts in E ′ in terms of E ′ 1 , E ′ 2 , and E ′ 3 , resp ectiv ely . 4.2.2. Every Neste d Wor d Is A c c epte d. Let f W = ([ e n ] , e ⋖ , e µ, e λ ) b e an arbitrary nested w ord o ver e Σ. W e show that f W ∈ L ( B r ). Let us first distribu te colors to eac h of the inv olv ed spheres. F or this, w e define the n otion of an o verlap: for an y i, i ′ ∈ [ e n ], i and i ′ are said to ha v e an r - overlap in f W if r -Sph( f W , i ) ∼ = r -Sph( f W , i ′ ) and d f W ( i, i ′ ) ≤ 2 r + 1. F or example, in Figure 5, i and i ′ ha v e a 2-o v erlap. Claim 4.4. There is a mapping χ : [ e n ] → [# Col ] s u c h that, for all i, i ′ ∈ [ e n ] with i 6 = i ′ , the follo wing holds: if i and i ′ ha v e an r -o verla p in f W , then χ ( i ) 6 = χ ( i ′ ). Pr o of. The m ap p ing is obtained as a graph coloring. Consider the graph ([ e n ] , Ar cs ), Ar cs ⊆ [ e n ] × [ e n ], wh ere, for i, i ′ ∈ [ e n ], we ha v e ( i, i ′ ) ∈ Ar cs iff i 6 = i ′ and i and i ′ ha v e an r -o verlap in f W . O b serv e that ([ e n ] , Ar cs ) cannot b e of degree greate r than 4 · maxSize ( r ) 2 . F or eac h i ∈ [ e n ], there are at m ost four d istinct ev en ts i ′ suc h that d f W ( i, i ′ ) ≤ 1. No w, if a p osition j ∈ [ e n ] wan ts to “get in touc h ” w ith i , it requir es a p osition in its own sp h ere, another p osition in the sphere around i , and one of the four p ossibilities to relate these t wo p ositions. Hence, ([ e n ] , Ar cs ) can b e # Col - c olor e d by a mapping χ : [ e n ] → [# Col ] (i.e ., χ ( i ) 6 = χ ( i ′ ) for ev ery ( i , i ′ ) ∈ Ar cs ), whic h concludes the pro of of Claim 4.4. W e now sp ecify ρ : [ e n ] → Q : for i ∈ [ e n ], we set ρ ( i ) = { ( r -Sp h( f W , i ′ ) , i, χ ( i ′ )) | i ′ ∈ [ e n ] suc h th at d f W ( i, i ′ ) ≤ r } . With th is definition, we can c hec k that, for all i ∈ [ e n ], ρ ( i ) is a v alid state of B r , and that ρ is indeed an acce pting r u n of B r on f W . So let i ∈ [ e n ] and let E = ( N , ⋖ , µ, λ, γ , α, c ol ) and E ′ = ( N ′ , ⋖ ′ , µ ′ , λ ′ , γ ′ , α ′ , c ol ′ ) b e con tained in ρ ( i ). (a) Assume that γ = α and γ ′ = α ′ . Then, ( N , ⋖ , µ, λ, γ , γ ) ∼ = ( r -Sph( f W , i ) , i ) and ( N ′ , ⋖ ′ , µ ′ , λ ′ , γ ′ , γ ′ ) ∼ = ( r -Sph( f W , i ) , i ). Consequen tly , w e h a ve ( N , ⋖ , µ , λ, γ , γ ) ∼ = ( N ′ , ⋖ ′ , µ ′ , λ ′ , γ ′ , γ ′ ). Moreo v er, c ol = c ol ′ = χ ( i ). (b) Of course, λ ( α ) = λ ′ ( α ′ ). ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 19 (c) Assume ( N , ⋖ , µ, λ, γ ) ∼ = ( N ′ , ⋖ ′ , µ ′ , λ ′ , γ ′ ) and c ol = c ol ′ . There are i 1 , i 2 ∈ [ e n ] with d f W ( i, i 1 ) ≤ r , d f W ( i, i 2 ) ≤ r , ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i ), ( N , ⋖ , µ, λ, γ , α ′ ) ∼ = ( r -Sph( f W, i 2 ) , i ), and c ol = χ ( i 1 ) = χ ( i 2 ). Clearly , we ha v e r -Sph( f W , i 1 ) ∼ = r -Sph( f W , i 2 ). F urthermore, i 1 = i 2 and, therefore, α = α ′ . This is b ecause i 1 and i 2 ha v e an r - o verlap in f W so that, according to Claim 4.4, i 1 6 = i 2 w ould imp ly χ ( i 1 ) 6 = χ ( i 2 ), which con tradicts the premise. No w, for i ∈ { 0 , . . . , e n } and i ′ = i + 1 with i ′ 6∈ dom( e µ − 1 ), we c hec k th at the triple ( ρ ( i ) , λ ( i ′ ) , ρ ( i ′ )) is con tained in δ 1 , where w e let ρ (0) = ∅ . Note first that, of course, ρ ( i ′ ) 6 = ∅ . (1) Supp ose E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i ′ ). W e hav e E ∼ = ( r -Sph( f W , i ′′ ) , i ′ , χ ( i ′′ )) for some i ′′ ∈ [ e n ] with d f W ( i ′ , i ′′ ) ≤ r . As i ′ 6∈ d om( e µ − 1 ), w e deduce α 6∈ dom( µ − 1 ). (2) Obvi ously , w e ha v e lab el ( ρ ( i ′ )) = e λ ( i ′ ). (3) Supp ose E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i ) (we th us ha v e i ≥ 1) and j ∈ N suc h that E [ j ] ∈ ρ ( i ′ ). R ecall that w e ha v e to sh ow that, then, ( α, j ) ∈ ⋖ . There are i 1 , i ′ 1 ∈ [ e n ] suc h that d f W ( i 1 , i ) ≤ r , d f W ( i ′ 1 , i ′ ) ≤ r , ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i ), ( N , ⋖ , µ, λ, γ , j ) ∼ = ( r -Sph( f W , i ′ 1 ) , i ′ ), and c ol = χ ( i 1 ) = χ ( i ′ 1 ). W e easily see that i 1 and i ′ 1 ha v e an r -o v erlap in f W . W e deduce, according to Claim 4.4, i 1 = i ′ 1 . As, then, ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i ), ( N , ⋖ , µ, λ, γ , j ) ∼ = ( r -Sp h( f W , i 1 ) , i ′ ), and ( i, i ′ ) ∈ e ⋖ , we can infer ( α, j ) ∈ ⋖ . (4) Let E = ( N , ⋖ , µ , λ, γ , α, c ol ) ∈ ρ ( i ′ ), supp ose i ′ ≥ 2, and supp ose th at there is no j ∈ N s uc h that ( j, α ) ∈ ⋖ . Recall that we h a v e to sh o w that d E ( γ , α ) = r . There is i ′ 1 ∈ [ e n ] suc h that d f W ( i ′ 1 , i ′ ) ≤ r and ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i ′ 1 ) , i ′ ). But if d E ( γ , α ) < r , then d f W ( i ′ 1 , i ′ ) < r , and there must b e a ⋖ -predecessor of α , w hic h is a con tradiction. W e therefore deduce that d E ( γ , α ) = r . (5) Let E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i ) and supp ose that there is no j ∈ N suc h th at ( α, j ) ∈ ⋖ . Similarly to the case (4), we sho w that d E ( γ , α ) = r . In fact, there is i 1 ∈ [ e n ] suc h that d f W ( i 1 , i ) ≤ r and ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sp h( f W , i 1 ) , i ). Again, if d E ( γ , α ) < r , then d f W ( i 1 , i ) < r so that th ere m ust b e a ⋖ -successor of α , w h ic h is a con tradiction. W e conclude that d E ( γ , α ) = r . (6) Let E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i ′ ) and j ∈ N suc h that ( j, α ) ∈ ⋖ . W e sho w that, then, E [ j ] ∈ ρ ( i ). T here is i ′ 1 ∈ [ e n ] suc h that d f W ( i ′ 1 , i ′ ) ≤ r , ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i ′ 1 ) , i ′ ), and c ol = χ ( i ′ 1 ). As ( j, α ) ∈ ⋖ , α is not minimal so th at we ha v e i ≥ 1. Since, fur th ermore, d E ( γ , j ) ≤ r imp lies d f W ( i ′ 1 , i ) ≤ r , and since we also hav e ( N , ⋖ , µ, λ, γ , j ) ∼ = ( r -Sph( f W , i ′ 1 ) , i ) and c ol = χ ( i ′ 1 ), w e d educe E [ j ] = ( N , ⋖ , µ, λ, γ , j, c ol ) ∈ ρ ( i ). (7) Let E = ( N , ⋖ , µ , λ, γ , α, c ol ) ∈ ρ ( i ) and j ∈ N suc h that ( α, j ) ∈ ⋖ . W e ha ve to sho w that E [ j ] ∈ ρ ( i ′ ). There is i 1 ∈ [ e n ] such that d f W ( i 1 , i ) ≤ r , ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i ), and c ol = χ ( i 1 ). Since d E ( γ , j ) ≤ r imp lies d f W ( i 1 , i ′ ) ≤ r , and since we h av e ( N , ⋖ , µ, λ, γ , j ) ∼ = ( r -Sph( f W , i 1 ) , i ′ ) and c ol = χ ( i 1 ), we deduce E [ j ] = ( N , ⋖ , µ, λ, γ , j, c ol ) ∈ ρ ( i ′ ). Next, for i c , i, i ′ ∈ [ e n ] w ith i ′ = i + 1 and ( i c , i ′ ) ∈ e µ , w e chec k that the quadruple ( ρ ( i c ) , ρ ( i ) , λ ( i ′ ) , ρ ( i ′ )) is conta ined in δ 2 . Checki ng (2)– (7) pro ceeds as in th e abov e cases. 20 B. BO LLIG F or completeness, we present the cases (3’)–(7’), whic h are sh own analogo usly . First observe that, ind eed, ρ ( i c ), ρ ( i ), and ρ ( i ′ ) are all nonempt y . (3’) Supp ose E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i c ) and j ∈ N such that E [ j ] ∈ ρ ( i ′ ). W e sho w that ( α, j ) ∈ µ . There are i 1 , i ′ 1 ∈ [ e n ] suc h that d f W ( i 1 , i c ) ≤ r , d f W ( i ′ 1 , i ′ ) ≤ r , ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i c ), ( N , ⋖ , µ, λ, γ , j ) ∼ = ( r -Sph( f W , i ′ 1 ) , i ′ ), and c ol = χ ( i 1 ) = χ ( i ′ 1 ). Again, i 1 and i ′ 1 ha v e an r -o v erlap in f W . According to Claim 4.4, i 1 = i ′ 1 . Then, ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i c ), ( N , ⋖ , µ , λ, γ , j ) ∼ = ( r -Sph( f W , i 1 ) , i ′ ), and ( i c , i ′ ) ∈ e µ , so that w e can deduce ( α, j ) ∈ µ . (4’) Let E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i ′ ) and su pp ose that there is n o j ∈ N su c h that ( j, α ) ∈ µ . W e ha v e to sh o w that d E ( γ , α ) = r . There is i ′ 1 ∈ [ e n ] suc h th at d f W ( i ′ 1 , i ′ ) ≤ r and ( N , ⋖ , µ , λ, γ , α ) ∼ = ( r -Sph( f W , i ′ 1 ) , i ′ ). But if d E ( γ , α ) < r , then d f W ( i ′ 1 , i ′ ) < r , so there m ust b e a µ -predecessor of α , whic h is a contradic tion. W e dedu ce d E ( γ , α ) = r . (5’) Let E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i c ) and supp ose that there is n o j ∈ N su c h that ( α, j ) ∈ µ . W e show that, then, d E ( γ , α ) = r . There is i 1 ∈ [ e n ] suc h that d f W ( i 1 , i c ) ≤ r and ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i c ). If d E ( γ , α ) < r , then d f W ( i 1 , i c ) < r , so there m ust b e a µ -successor of α , whic h is a con tradictio n. W e conclude that d E ( γ , α ) = r . (6’) Let E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i ′ ) and j ∈ N su c h that ( j, α ) ∈ µ . W e sho w E [ j ] ∈ ρ ( i c ). There is i ′ 1 ∈ [ e n ] such that d f W ( i ′ 1 , i ′ ) ≤ r , ( N , ⋖ , µ, λ, γ , α ) ∼ = ( r -Sp h( f W , i ′ 1 ) , i ′ ), and c ol = χ ( i ′ 1 ). Due to d E ( γ , j ) ≤ r , we also ha v e d f W ( i ′ 1 , i c ) ≤ r , and since ( N , ⋖ , µ, λ, γ , j ) ∼ = ( r -Sph( f W , i ′ 1 ) , i c ) and c ol = χ ( i ′ 1 ), w e deduce E [ j ] ∈ ρ ( i c ). (7’) Let E = ( N , ⋖ , µ, λ, γ , α, c ol ) ∈ ρ ( i c ) and j ∈ N such that ( α, j ) ∈ µ . W e hav e to sho w E [ j ] ∈ ρ ( i ′ ). There is i 1 ∈ [ e n ] su c h that d f W ( i 1 , i c ) ≤ r , ( N , ⋖ , µ , λ, γ , α ) ∼ = ( r -Sph( f W , i 1 ) , i c ), and c ol = χ ( i 1 ). F rom d E ( γ , j ) ≤ r , it follo ws d f W ( i 1 , i ′ ) ≤ r . As, moreo ver, ( N , ⋖ , µ, λ, γ , j ) ∼ = ( r -Sph( f W , i 1 ) , i ′ ) and c ol = χ ( i 1 ), we d educe E [ j ] = ( N , ⋖ , µ, λ, γ , j, c ol ) ∈ ρ ( i ′ ). 4.2.3. Every Run Ke eps T r ack Of Spher es. W e will now s ho w that an accepting r un reve als the sphere around any no de. This constitutes the m ore d ifficult part of the correctness pro of. W e in tro du ce some useful notation: By ∆, w e denote the set {→ , ← , y , x , x , y } of dir e ctions . No w let W = ([ n ] , ⋖ , µ, λ ) ∈ NW ( e Σ) b e a nested w ord, i, j ∈ [ n ], and let w = e 1 . . . e m ∈ ∆ ∗ (where e k ∈ ∆ for all k ∈ { 1 , . . . , m } ). W e write i w = = ⇒ W j if there are i 0 , i 1 , . . . , i m ∈ [ n ] such that i 0 = i , i m = j , and , for ev ery k ∈ { 0 , . . . , m − 1 } , one of the follo wing holds: (a) e k +1 = → and i k +1 = i k + 1 (b) e k +1 = ← and i k +1 = i k − 1 (c) e k +1 = y and i k ∈ d om( µ ) and λ ( i k ) ∈ Σ 1 c and i k +1 = µ ( i k ) (d) e k +1 = x and i k ∈ d om( µ ) and λ ( i k ) ∈ Σ 2 c and i k +1 = µ ( i k ) (e) e k +1 = x and i k ∈ d om( µ − 1 ) and λ ( i k ) ∈ Σ 1 r , and i k +1 = µ − 1 ( i k ) (f ) e k +1 = y and i k ∈ d om( µ − 1 ) and λ ( i k ) ∈ Σ 2 r , and i k +1 = µ − 1 ( i k ) Moreo ve r, we write i w ֒ − → W j if there are pairwise distinct i 0 , i 1 , . . . , i m − 1 ∈ [ n ] and i m ∈ [ n ] \ { i 1 , . . . , i m − 1 } su c h that i 0 = i , i m = j , and, for every k ∈ { 0 , . . . , m − 1 } , (a)–(f ) as ab o v e hold. ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 21 W e sa y that a string w ∈ ∆ + is cir c u lar if i w ֒ − → W i for some nested word W ∈ NW ( e Σ) and some p osition i of W . In other w ords, a circular string can pro d uce a circle in a nested w ord. F or example, y → y → and y → x → x → are circular (for an app ropriate alphab et e Σ), whereas y → x → x ← is not circular. The follo wing prop osition is crucial for our pro ject, and it f ails wh en considering nested w ords ov er more than t w o stac ks. Prop osition 4.5. L et w ∈ ∆ + b e cir c ular. Then, for al l k ≥ 2 , w k is not cir cular. Before w e prov e Prop osition 4.5, observe t hat it does not hold a s so on as a t hird stac k comes into pla y . T o see th is, consider Figure 7, d escribing a part of a nested word W o v er the 3-stac k call-ret urn alphab et h{ ( { a } , { a } ) , ( { b } , { b } ) , ( { c } , { c } ) } , ∅i . Su p p ose w = y ← y ← 3 x ← (where the meaning of 3 x is the exp ected one), which is circular if we apply our definition to the framewo rk of thr ee stac ks. Ho wev er, we ha v e i w w ֒ − − → W i . It s h ould b e n oted that this do es not imply that there is no sp here automaton or logi- cal c haracteriz ation in the fr amew ork with more than t w o stac ks. Indeed, we lea v e as an op en question if m ultiple stac ks generally allo w for a logical c h aracteriza tion in terms of a fragmen t of MSO logic. a − → c a − → c c − → b c − → b b − → a b − → a i Figure 7: Prop osition 4.5 fails when considering three stac ks In the ab ov e d efi n ition of i w ֒ − → W j , it is crucial to r equ ir e the elemen ts i 0 , i 1 , . . . , i m − 1 ∈ [ n ] to b e pairwise distinct. This can b e seen considering a part of the nested w ord W o v er the 2-stac k call-return alphab et h{ ( { a } , { a } ) , ( { b } , { b } ) } , ∅i that is depicted in Figure 8. Let w = y ← ← x ← y ← , whic h is a circular string. W e ha v e i w w = = = ⇒ W i , i.e., starting from i , w e can follo w the sequence of directio ns w twice , arriving at i ag ain. Ho w ev er, apart from i , w e ha v e to visit j 1 and j 2 t w ice. I n deed, i 6 w w ֒ − − → W i . Pro of. (of Pr op osition 4.5). Let W = ([ n ] , ⋖ , µ, λ ) ∈ NW ( e Σ), w ∈ ∆ + , and i ∈ [ n ]. W e ha v e to sh o w th at, if i w ֒ − → W i , then w cannot b e decomp osed n on trivially in to iden tical circular fact ors, i.e ., there is no circular u ∈ ∆ + suc h that w = u k for some k ≥ 2. 4 T o see this easily , we observe that a situat ion suc h as i w ֒ − → W i corresp on d s to a top ologica l circle, as depicted in Figure 9. A top ological circle is a closed line in the t wo-dimensional plane that nev er crosses o ver itself. Let us construct top ological circles according to the follo wing pro cedur e: W e assume a straigh t (horizon tal) line of the plane. 4 Actually , one can even show that t here is no u ∈ ∆ + at all (not even non-circular) such that w = u k for some k ≥ 2. 22 B. BO LLIG a − → b a − → b b − → a b − → a a − → a − − − − − → a − → a i j 2 j 1 Figure 8: In termediate p ositions n eed to b e pairwise distinct Assume further a p oin t i on this line. Starting from i , w e c ho ose another t w o p oin ts as follo ws: Pic k a symb ol γ from the alphab et { ❀ , ❀ ,  ,  } . According to this c hoice, w e first dra w a semicircle ab o v e the straight line end ing somewhere on the line, and then, without inte rruption, a semicircle b elo w the line, again resulting in a p oin t on the line. Eac h semicircle is drawn in the d ir ection ind icated by γ , e.g.,  requires to draw the up p er semicircle righ tw ards and the lo wer one left w ards, and ❀ requires b oth the upp er and the lo wer semicircle to b e drawn righ t wards. Th is pro cedure is con tin ued until we reac h the original p oin t i . W e call a sequence from { ❀ , ❀ ,  ,  } + that allo ws u s to dra w a top ological circle cir cular . F or example, in Figure 9, we construct a topological circle b y follo w ing the sequence x = ❀ ❀ ❀  ❀ ❀ , starting in the left outermost p oint of in tersecti on on the horizon tal line. Thus, x is circular, whereas   is not circular. Observe that we h a ve x 6 = y k for all y ∈ { ❀ , ❀ ,  ,  } + and k ≥ 2. Figure 9: Pro of of Prop osition 4.5 It is not hard to see that top ological circles b ehav e ap erio dically in general, i.e., for any giv en y ∈ { ❀ , ❀ ,  ,  } , there is no k ≥ 2 suc h that y k is circular. T o sho w our prop osition, w e can ev en restrict to circular y . So let y ∈ { ❀ , ❀ ,  ,  } + . But if y is circular, then, for gro w in g k , y k giv es rise to a “spiral”, and going bac k to the starting p oint w ould r equire to in tersect the line that has been dra wn hitherto. Let u s relate our top ologica l circles to the nested-wo rd setting o v er t wo stac ks. T o this aim, we defin e a partial mapp ing f : ∆ + 99K { ❀ , ❀ ,  ,  } + that asso ciates with any circular string a sequence o v er { ❀ , ❀ ,  ,  } . This is done by r eading a string from left to righ t and su ccessiv ely replacing eve ry direction from ∆ with a sym b ol from { ❀ , ❀ ,  ,  } , according to the follo wing rules: ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 23 • y is alw a ys replaced with ❀ • x is alw a ys replaced with ❀ • → is replaced w ith (  if the previous letter has b een x ❀ otherwise • ← is replaced w ith (  if the previous letter has b een y ❀ otherwise • x is replaced with (  if the previous letter has b een ← ❀ otherwise • y is replaced with (  if the previous letter has b een → ❀ otherwise F or example, f ( ← x → x → x → y ) = ❀ ❀  ❀ ❀ ❀   . Let w b e circular. Clearly , f ( w ) is circular as well, i.e., it allo ws us to dra w a top ological circle. W e assume that the first letter of w stems from { y , x } . Other cases are either trivial or can b e reduced to that one. Then, if w can b e decomp osed nontriviall y in to iden tical circular f actors, then this also app lies to f ( w ). Summarizing, the p o wer of a circular string is not circula r an ymore. This concl udes the pr o of of Prop osition 4.5 . W e will no w sh o w that, indeed, B r disco vers the r -sph ere around an y nod e of an input nested word. Let W = ([ n ] , ⋖ , µ, λ ) ∈ NW ( e Σ) b e a nested word and ρ b e a run of B r on W . C onsider an y i ∈ [ n ], let ( N i , ⋖ i , µ i , λ i , γ i ) refer to c or e ( ρ ( i )), and let c ol i b e the u nique elemen t from [# Col ] satisfying E i := ( N i , ⋖ i , µ i , λ i , γ i , γ i , c ol i ) ∈ ρ ( i ). The follo wing statemen t claims that an arb itrarily long p ath in E i is sim ulated by a corresp onding p ath in W . Claim 4.6. Let d ≥ 0 and su pp ose th ere are j 0 , . . . , j d ∈ N i suc h that γ i = j 0 ↔ E i j 1 ↔ E i . . . ↔ E i j d . Then, there is a (unique) sequence of no des i 0 , . . . , i d ∈ [ n ] suc h that • i 0 = i , • for eac h k ∈ { 0 , . . . , d } , E i [ j k ] ∈ ρ ( i k ) (in particular, λ ( i k ) = λ i ( j k )), and • for eac h k ∈ { 0 , . . . , d − 1 } , ( j k , j k +1 ) ⊑ E i W ( i k , i k +1 ). Pr o of. The p ro of is b y indu ction. O b viously , the statemen t holds for d = 0. So assume d ≥ 0 and supp ose there are a sequence j 0 , . . . , j d , j d +1 ∈ N i suc h that γ i = j 0 ↔ E i j 1 ↔ E i . . . ↔ E i j d ↔ E i j d +1 and a uniqu e sequence i 0 , i 1 , . . . , i d ∈ [ n ] such that i 0 = i , E i [ j k ] ∈ ρ ( i ) for eac h k ∈ { 0 , . . . , d } , and ( j k , j k +1 ) ⊑ E i W ( i k , i k +1 ) for eac h k ∈ { 0 , . . . , d − 1 } . W e consider four ca ses: • Assume ( j d , j d +1 ) ∈ ⋖ i . Then, ρ ( i d ) is not a fi nal state so that i d < n . W e set i d +1 = i d + 1. Due to (7), we h av e E i [ j d +1 ] ∈ ρ ( i d +1 ). • Assume ( j d +1 , j d ) ∈ ⋖ i . Then, according to (6), i d ≥ 2. W e set i d +1 = i d − 1. Due to (6), w e also ha v e E i [ j d +1 ] ∈ ρ ( i d +1 ). • Assume ( j d , j d +1 ) ∈ µ i . C learly , ρ ( i d ) is a calling state so that µ ( i d ) is defin ed. Setting i d +1 = µ ( i d ), w e ha v e, due to (7’), E i [ j d +1 ] ∈ ρ ( i d +1 ). • Assume ( j d +1 , j d ) ∈ µ i . According to (1), i d ∈ dom( µ − 1 ). With (6’), let ting i d +1 = µ − 1 ( i d ), w e ha v e E i [ j d +1 ] ∈ ρ ( i d +1 ). This concl udes the pr o of of Claim 4.6. 24 B. BO LLIG Claim 4.7. There is a homomorphism h : r -Sph( W , i ) → c or e ( ρ ( i )). Pr o of. W e sho w b y induction th e follo w in g stat emen t: F or eve ry d ∈ { 0 , . . . , r } , there is a h omomorph ism h : d -Sph( W, i ) → d -Sph(( N i , ⋖ i , µ i , λ i ) , γ i ) suc h that, f or eac h i ′ ∈ [ n ] with d W ( i, i ′ ) ≤ d , w e h a ve E i [ h ( i ′ )] ∈ ρ ( i ′ ). (*) Of course, (*) h olds for d = 0. So assume that (*) h olds true for some n atural num b er d ∈ { 0 , . . . , r − 1 } , i.e., there is a h omomorphism h : d -Sph( W , i ) → d -Sph(( N i , ⋖ i , µ i , λ i ) , γ i ) suc h that E i [ h ( i ′ )] ∈ ρ ( i ′ ) for eac h i ′ ∈ [ n ] with d W ( i, i ′ ) ≤ d . W e sho w that then (*) holds for d + 1 as w ell. F or this, let i 1 , i 2 ∈ [ n ] suc h that d W ( i, i 1 ) = d and d W ( i, i 2 ) = d + 1. • Supp ose i 1 ⋖ i 2 . Since d W ( i, i 1 ) < r , w e also ha v e d E i ( γ i , h ( i 1 )) < r . Due to (5), there is j 2 ∈ N i suc h that h ( i 1 ) ⋖ i j 2 . Since E i [ h ( i 1 )] ∈ ρ ( i 1 ), w e obtain, by (7) and (2), that λ i ( j 2 ) = λ ( i 2 ) and E i [ j 2 ] ∈ ρ ( i 2 ). • Similarly , w e pro ceed if i 2 ⋖ i 1 . By d E i ( γ i , h ( i 1 )) < r and (4), there is j 2 ∈ N i suc h that j 2 ⋖ i h ( i 1 ). Since E i [ h ( i 1 )] ∈ ρ ( i 1 ), we obtain, b y (6) and (2), that λ i ( j 2 ) = λ ( i 2 ) and E i [ j 2 ] ∈ ρ ( i 2 ). • If ( i 1 , i 2 ) ∈ µ , then there exists, exploiting (5’) and (7’), j 2 ∈ N i suc h that ( h ( i 1 ) , j 2 ) ∈ µ i , λ i ( j 2 ) = λ ( i 2 ), and E i [ j 2 ] ∈ ρ ( i 2 ). • If ( i 2 , i 1 ) ∈ µ , then we can fi nd, due to (4’) and (6’), j 2 ∈ N i suc h that ( j 2 , h ( i 1 )) ∈ µ i , λ i ( j 2 ) = λ ( i 2 ), and E i [ j 2 ] ∈ ρ ( i 2 ). Observe that j 2 is uniquely d etermined by i 2 and do es not dep end on the c hoice of i 1 or on the relatio n b etw een i 1 and i 2 : If we obtained distinct elemen ts j 2 and j ′ 2 , then the constrain ts E i [ j 2 ] ∈ ρ ( i 2 ) and E i [ j ′ 2 ] ∈ ρ ( i 2 ) would imply that ρ ( i 2 ) is not a v alid state . The ab ov e pro cedu r e extends the domain of th e homomorph ism h by those elemen ts whose distance to i is d + 1. I.e., for i 1 , i 2 ∈ [ n ] with d W ( i, i 1 ) = d W ( i, i 2 ) = d + 1, w e determined t wo unique elemen ts h ( i 1 ) , h ( i 2 ) ∈ N i , resp ectiv ely . Let us show that ( i 1 , i 2 ) ⊑ W c or e ( ρ ( i )) ( h ( i 1 ) , h ( i 2 )). Sup p ose i 1 ⋖ i 2 (the ca se i 2 ⋖ i 1 is symmetric). As E i [ h ( i 1 )] ∈ ρ ( i 1 ) and E i [ h ( i 2 )] ∈ ρ ( i 2 ), w e hav e, by (3), h ( i 1 ) ⋖ i h ( i 2 ). Similarly , with (3’), ( i 1 , i 2 ) ∈ µ implies ( h ( i 1 ) , h ( i 2 )) ∈ µ i . Claim 4.8. There is a homomorphism h ′ : c or e ( ρ ( i )) → r -S p h( W , i ). Pr o of. W e sho w, aga in b y induction, the follo wing sta temen t: F or ev ery natural num b er d ∈ { 0 , . . . , r } , there is a h omomorphism h ′ : d -Sph(( N i , ⋖ i , µ i , λ i ) , γ i ) → d -Sph( W , i ) such that, for ev ery j ∈ N i with d E i ( γ i , j ) ≤ d , w e ha v e E i [ j ] ∈ ρ ( h ′ ( j )). (**) Clearly , (**) holds for d = 0. Assu m e that (** ) holds for some natural n um b er d ∈ { 0 , . . . , r − 1 } an d let h ′ : d -Sph(( N i , ⋖ i , µ i , λ i ) , γ i ) → d -Sph( W , i ) b e a corresp ondin g ho- momorphism. L et j 1 , j 2 ∈ N i suc h that d E i ( γ i , j 1 ) = d and d E i ( γ i , j 2 ) = d + 1. Supp ose that j 1 ⋖ i j 2 . As E i [ j 1 ] ∈ ρ ( h ′ ( j 1 )), ρ ( h ′ ( j 1 )) cannot b e a fin al state of B r so that there is i 2 ∈ [ n ] such that h ′ ( j 1 ) ⋖ i 2 . Clearly , we h a ve E i [ j 2 ] ∈ ρ ( i 2 ). Analogously , w e pro ceed in the cases j 2 ⋖ i j 1 , ( j 1 , j 2 ) ∈ µ i , and ( j 2 , j 1 ) ∈ µ i to obtain suc h an elemen t i 2 . Note that i 2 is uniqu ely determined by j 2 and do es not d ep end on the c h oice of j 1 or on the sp ecific r elation b et w een j 1 and j 2 . This is less obvio us than the co rresp ond in g fact in the p ro of of Claim 4.7 but can b e shown along the lines of the follo wing pr o cedure, pro ving that the extension of the d omain of h ′ b y elemen ts j ∈ N i with d E i ( γ i , j ) = d + 1 is a homomorphism: ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 25 W e sho w that, for j, j ′ ∈ N i with d E i ( γ i , j ) = d E i ( γ i , j ′ ) = d + 1, we hav e ( j, j ′ ) ⊑ E i W ( h ′ ( j ) , h ′ ( j ′ )) (where the elemen ts h ′ ( j ) and h ′ ( j ′ ) are obtained as indicated ab o v e). So supp ose j ↔ E i j ′ . T here are ℓ ∈ { 0 , . . . , d } and pairwise distinct j 0 , . . . , j 2( d +1) − ℓ ∈ N i , suc h that j ℓ +1 ↔ E i . . . ↔ E i j d +1 = j γ i = j 0 ↔ E i . . . ↔ E i j ℓ ↔ E i ↔ E i ↔ E i j 2( d +1) − ℓ ↔ E i . . . ↔ E i j d +2 = j ′ F or ease of notation, set D = 2( d + 1) − ℓ and let, for k ∈ N , mo d ( k ) = ( k if k ≤ D (( k − ℓ ) mod ( D − ℓ + 1)) + ℓ if k > D I.e., the mapping mo d counts unt il D and afterw ards mo du lo D − ℓ + 1. According to Claim 4.6, there is a unique infi nite sequence i 0 , i 1 , . . . ∈ [ n ] suc h that • i 0 = i , • for eac h k ∈ N , E i [ j mo d ( k ) ] ∈ ρ ( i k ), and • for eac h k ∈ N , ( j mo d ( k ) , j mo d ( k +1) ) ⊑ E i W ( i k , i k +1 ). In wh at follo ws, w e show that i D + 1 = i ℓ , wh ic h implies ( j d +1 , j d +2 ) ⊑ E i W ( i d +1 , i d +2 ) so that ( j d +1 , j d +2 ) ⊑ E i W ( h ′ ( j d +1 ) , h ′ ( j d +2 )). There is a circular string w = e ℓ . . . e D ∈ ∆ + suc h that • j ℓ w = = ⇒ E i j ℓ , • j ℓ e ℓ ...e ℓ + k − 1 = = = = = = = ⇒ E i j ℓ + k for eac h k ∈ { 1 , . . . , D − ℓ } , and • i ℓ w k = = ⇒ W i ℓ + k ( D − ℓ +1) for eac h k ≥ 1. W e can obtain suc h a w by setting, for eac h k ∈ { ℓ, . . . , D } , e k =                        → if j k ⋖ i j mo d ( k +1) ← if j mo d ( k +1) ⋖ i j k y if λ i ( j k ) ∈ Σ 1 c and ( j k , j mo d ( k +1) ) ∈ µ i and j k 6 ⋖ i j mo d ( k +1) x if λ i ( j k ) ∈ Σ 1 r and ( j mo d ( k +1) , j k ) ∈ µ i and j mo d ( k +1) 6 ⋖ i j k x if λ i ( j k ) ∈ Σ 2 c and ( j k , j mo d ( k +1) ) ∈ µ i and j k 6 ⋖ i j mo d ( k +1) y if λ i ( j k ) ∈ Σ 2 r and ( j mo d ( k +1) , j k ) ∈ µ i and j mo d ( k +1) 6 ⋖ i j k As [ n ] is a fi nite set 5 , there are p, q ∈ N suc h that ℓ ≤ p < q and i p = i q . W e c ho ose p and q such that i ℓ , . . . , i q − 1 are pairwise distinct. W e hav e b oth E i [ j mo d ( p ) ] ∈ ρ ( i p ) and E i [ j mo d ( q ) ] ∈ ρ ( i p ). According to the definition of the set of states of B r , this implies j mo d ( p ) = j mo d ( q ) . Let us d istinguish th r ee cases: Case 1: p = ℓ and q = ℓ + k ( D − ℓ + 1) for some k ≥ 1. Then, i ℓ w k ֒ − − → W i ℓ + k ( D − ℓ +1) so that, acc ording to Prop osition 4.5, w e hav e k = 1 and i ℓ = i D + 1 , and we are d one. 5 In the context of infin ite n ested words, this argument can b e replaced with the fact that, starting in i , there is no infinite sequence of p airwise distinct nod es that follo ws the infinite sequence of directions w ω , i.e., th e infinite rep etition of w (see S ection 6). 26 B. BO LLIG Case 2: p > ℓ and q = p + k ( D − ℓ + 1) for some k ≥ 1. Setting e = e mo d ( p − 1) , w e ha v e b oth i p − 1 e ֒ − → W i p and i q − 1 e ֒ − → W i p , wh ic h is a con tradictio n, as i p − 1 6 = i q − 1 . Case 3: p ≥ ℓ and q 6 = p + k ( D − ℓ + 1) for ev ery k ≥ 1. But this implies mo d ( p ) 6 = mo d ( q ) and, as the j ℓ , . . . , j D are pairwise distinct, j mo d ( p ) 6 = j mo d ( q ) , a con trad iction. This concl udes the pr o of of Claim 4.8. So let h : r -Sph( W , i ) → c or e ( ρ ( i )) and h ′ : c or e ( ρ ( i )) → r -Sph( W , i ) b e the un ique homomorphisms that we obtain follo w in g the constructiv e pro ofs of Claims 4.7 and 4.8, resp ectiv ely . It is now immediate th at h is injectiv e, h − 1 = h ′ , and h : r -Sph( W , i ) → c or e ( ρ ( i )) is an isomorphism. Recall that η : Q → Spher es r ( e Σ) shall map the empt y set to an arbitrary sphere and a nonempt y set E ∈ Q on to c or e ( E ). In deed, we constructed a generalize d 2 nw a B r = ( Q, δ , Q I , F , C ) to gether with a mapping η : Q → Spher es r ( e Σ) suc h that • L ( B r ) is the set of all nested w ords o ver e Σ (cf. Section 4. 2.2), and • for every nested w ord W ∈ NW ( e Σ), eve ry accepting run ρ of B r on W , and eve ry no de i of W , w e ha ve η ( ρ ( i )) ∼ = r -Sph( W , i ) (cf. Secti on 4.2. 3). This sho ws Prop osition 4.1. 5. Grids and Monadic Second-Order Quantifier Al terna tion In this section, we show that the m onadic second-order quantifier-al ternation hierarc h y o ver n ested words is infin ite. In other words, the more alternation of second-order quan tifi- cation we allo w, the more expr essiv e formulas b ecome. F rom th is, w e can finally deduce that 2-stac k visibly pushd o wn automata cannot b e complemente d in general. In the pro of, we use results that ha v e been gained in the setting of grids. By means of fi rst-order red u ctions from grids in to nested words, we can indeed transf er expr essiv eness results for grid s to the nested-w ord setting. Let us first state a general result from [17], starting with the formal definition of a strong first-order reduction: Definition 5.1 ( [17], Definitio n 32) . Let C and C ′ b e classes of structures o ve r relational signatures τ and τ ′ , resp ectiv ely . A str ong first-or der r e duction fr om C to C ′ with rank m ≥ 1 is an injectiv e mappin g Φ : C → C ′ suc h that the follo wing hold: (1) F or ev ery G ∈ C , the universe of the structure Φ( G ) is S k ∈{ 1 ,...,m } ( { k } × dom( G )), i.e., the d isjoin t u nion of m copies of d om( G ), where dom( G ) shall denote the universe of G . (2) There exists s ome ψ ( x 1 , . . . , x m ) ∈ F O( τ ′ ) su c h that, for ev ery structure G ∈ C , ev ery u 1 , . . . , u m ∈ dom( G ), and ev ery k 1 , . . . , k m ∈ [ m ], Φ( G ) | = ψ [( k 1 , u 1 ) , . . . , ( k m , u m )] iff (( k 1 , u 1 ) , . . . , ( k m , u m )) = ((1 , u 1 ) , . . . , ( m, u 1 )). (The in tuition is that u ∈ dom( G ) is represen ted by a mod el ((1 , u ) , . . . , ( m, u )) of ψ .) (3) F or ev ery relation sym b ol r ′ from τ ′ , s a y with arity l , and ev ery κ : [ l ] → [ m ], there is ϕ r ′ κ ( x 1 , . . . , x l ) ∈ F O( τ ) such that, for eac h G ∈ C and eac h u 1 , . . . , u l ∈ dom( G ), G | = ϕ r ′ κ [ u 1 , . . . , u l ] iff Φ( G ) | = r ′ [( κ (1) , u 1 ) , . . . , ( κ ( l ) , u l )]. (4) F or ev ery relation sym b ol r from τ , say with arit y l , there is ϕ r ( x 1 , . . . , x l ) ∈ F O( τ ′ ) suc h that, for eac h G ∈ C and eac h u 1 , . . . , u l ∈ dom( G ), G | = r [ u 1 , . . . , u l ] iff Φ( G ) | = ϕ r [(1 , u 1 ) , . . . , (1 , u l )]. ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 27 Once we h a ve a strong first-order redu ction f r om C to C ′ , logical definabilit y carries o v er from C to C ′ : Theorem 5.2 ( [17], Th eorem 33) . L et C and C ′ b e classes of structur es over r elational signatur es τ and τ ′ , r esp e ctively. L et Φ : C → C ′ b e a str ong first-or der r e duction such that Φ( C ) is Σ 1 ( τ ′ ) -definable r elative to C ′ . Then, for e very L ⊆ C and k ≥ 1 , L is Σ k ( τ ) - definable r elative to C iff Φ ( L ) is Σ k ( τ ′ ) -definable r elative to C ′ . W e pro ceed as follo ws. W e fir st recall the notion of the class of grids, of whic h we kn o w that the monadic seco nd-order quantifier-a lternation hierarc hy is infinite. Th en, w e giv e a strong fi rst-order r eduction from the class of grids to the class of nested w ords ov er a simple 2-stac k visibly p ushdown alphab et so that w e can deduce that the monadic second-order quan tifier-alte rnation hierarc hy o v er n ested w ords is infinite, to o. Note that w e will add to ordinary grids some p articular lab eling in terms of a and b , w h ic h w ill simplify the up coming constructions. It is, ho wev er, easy to s ee that w ell-kno wn results concerning ordinary grids extend to these extended grids (cf. Th eorem 5.3 b elo w). W e fix a signature τ Grids = { P a , P b , succ 1 , succ 2 } with P a , P b unary and succ 1 , succ 2 binary r elation symbols. Let n, m ≥ 1 b e n atural num b ers. The ( n, m )- grid is the τ Grids - structure G ( n, m ) = ([ n ] × [ m ] , succ 1 , succ 2 , P a , P b ) such that succ 1 = { (( i, j ) , ( i + 1 , j )) | i ∈ [ n − 1], j ∈ [ m ] } , su cc 2 = { (( i, j ) , ( i, j + 1)) | i ∈ [ n ], j ∈ [ m − 1] } , P a = { ( i, j ) ∈ [ n ] × [ m ] | j is odd } , and P b = { ( i, j ) ∈ [ n ] × [ m ] | j is ev en } . Th e (3 , 4)-grid is ill ustrated in Figure 10. By G , w e denote the set of all the grids. a a a b b b a a a b b b Figure 10 : Th e (3,4)-grid Theorem 5.3 ( [17]) . The monadic se c ond-or der quantifier-alternation hier ar chy over grids is i nfinite. I.e., for every k ≥ 1 , ther e is a set of grids that is Σ k +1 ( τ Grids ) -definable r elative to G but not Σ k ( τ Grids ) -definable r elative to G . F or the r est of this section, w e su pp ose that e Σ is the 2-stac k call-ret urn alph ab et giv en b y Σ 1 c = { a } , Σ 1 r = { a } , Σ 2 c = { b } , Σ 2 r = { b } , and Σ int = ∅ . In particular, the follo w in g results assu me all alphab ets apart from Σ int to b e nonempt y . W e now d escrib e an enco ding Φ : G → NW ( e Σ) of grids in to nested words o v er e Σ. Giv en n, m ≥ 1, w e let Φ( G ( n, m )) :=    nested  a n  ( ab ) n ( ba ) n  ( m − 1) / 2 a n  if m is odd nested  a n  ( ab ) n ( ba ) n  m/ 2 − 1 ( ab ) n b n  if m is ev en The idea is that the first n a ’s (and, as explained b elo w , the corresp onding return ev ents) in a n ested w ord represent the fir st column of G ( n, m ) seen from top to b ottom; the fir st n b ’s represen t the second column , w h ere the column is seen from b ottom to top; the second n a ’s stand for the third column, again co nsidered fr om top to b ottom, and so on. The enco d ing 28 B. BO LLIG a − − − − − → a − − − − − → a → a → b → a → b → a → b → b → a → b → a → b → a → a → b → a → b → a → b → b − − − − − → b − − − − − → b Figure 11 : The enco d ing Φ ( G (3 , 4)) of the (3,4)-grid as a nested w ord Φ( G (3 , 4)) of the (3,4)-grid as a nested word is depicted in Figure 11. W e claim that Φ is indeed a strong fi rst-order r ed u ction from the set of grid s to th e set NW ( e Σ) of nested wo rds o ver e Σ. O bserv e that Φ( G ( n, m )) d o es not h a ve as domain the set { 1 , 2 } × ([ n ] × [ m ]) as required in the defin ition of a strong first-order reduction. Ho w ev er, b elo w, we will in tro duce a bijection χ n,m : { 1 , 2 } × ([ n ] × [ m ]) → [2 · n · m ] to identify ev ery elemen t in the domain of Φ( G ( n, m )) w ith some elemen t in { 1 , 2 } × ([ n ] × [ m ]). Prop osition 5.4. We have that Φ : G → NW ( e Σ) i s a str ong first-or der r e duction with r ank 2 . Mor e over, Φ ( G ) is Σ 1 ( τ e Σ ) -definable r elative to NW ( e Σ) . Pr o of. Let us first introdu ce a useful notation. Give n a nested word W = ([ n ] , ⋖ , µ, λ ) and c ∈ Σ suc h that W con tains at least k p ositions lab eled w ith c , we let p os c ( W , k ) denote the least p osition i in W such that |{ j ∈ [ i ] | λ ( j ) = c }| = k (i.e., p os c ( W , k ) denotes the p osition of the k -th c in W ). Let n, m ≥ 1 and let ([2 · n · m ] , ⋖ , µ, λ ) refer to Φ( G ( n, m )). Recall that λ ca n b e seen as the collect ion of unary relations λ c = { i ∈ [2 · n · m ] | λ ( i ) = c } for c ∈ Σ. Let us map an y no de in the ( n, m )-grid (i.e., an y element from [ n ] × [ m ]) to a p osition of Φ( G ( n, m )) b y defin ing a function χ n,m : [ n ] × [ m ] → [2 · n · m ] as follo ws: χ n,m ( i, j ) = ( p os a (Φ( G ( n, m )) , n · [( j + 1) / 2 − 1] + i ) if j is o dd p os b (Φ( G ( n, m )) , n · [ j / 2 − 1] + ( n + 1 − i )) if j is eve n for an y ( i, j ) ∈ [ n ] × [ m ]. I ntuitiv ely , χ n,m ( i, j ) ∈ [2 · n · m ] repr esen ts the no de ( i, j ) in the ( n, m )-grid. This mapping is furth er extended tow ards a bijection χ n,m : { 1 , 2 } × ([ n ] × [ m ]) → [2 · n · m ] as required by Definition 5.1 (item (1)). Namely , we map χ n,m (1 , ( i, j )) on to χ n,m ( i, j ) and χ n,m (2 , ( i, j )) on to µ ( χ n,m ( i, j )). W e are pr epared to sp ecify the first-order form u las as supp osed in Definition 5.1: Let ψ ( x 1 , x 2 ) = µ ( x 1 , x 2 ) . (2) Indeed, for ev ery n , m ≥ 1, k 1 , k 2 ∈ { 1 , 2 } , and u 1 , u 2 ∈ [ n ] × [ m ], w e ha ve Φ( G ( n, m )) | = ψ [ χ n,m ( k 1 , u 1 ) , χ n,m ( k 2 , u 2 )] iff (( k 1 , u 1 ) , ( k 2 , u 2 )) = ((1 , u 1 ) , (2 , u 1 )) . W e will iden tify a map κ : [ l ] → { 1 , 2 } with the tuple ( κ (1) , . . . , κ ( l )). Let, for c ∈ Σ and κ ∈ { 1 , 2 } , ϕ λ c κ ( x ) =        P c ( x ) if c ∈ { a, b } and κ = 1 P c ( x ) if c ∈ { a, b } and κ = 2 false otherwise (3) ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 29 where w e let a = a and b = b . F or ev ery n, m ≥ 1, κ ∈ { 1 , 2 } , and u ∈ [ n ] × [ m ], w e ha v e G ( n, m ) | = ϕ λ c κ ( x )[ u ] iff Φ( G ( n, m )) | = ( λ ( x ) = c )[ χ n,m ( κ, u )] . F urther, let, f or κ ∈ { 1 , 2 } × { 1 , 2 } , ϕ ⋖ κ ( x 1 , x 2 ) =                                          succ 1 ( x 1 , x 2 ) ∧ ¬∃ z succ 2 ( z , x 1 ) if κ = (1 , 1) P a ( x 1 ) ∧ succ 1 ( x 2 , x 1 ) ∧ ¬∃ z su cc 2 ( x 1 , z ) ∨ P b ( x 1 ) ∧ succ 1 ( x 1 , x 2 ) ∧ ¬∃ z succ 2 ( x 1 , z ) ! if κ = (2 , 2)        ( x 1 = x 2 ) ∧ P a ( x 1 ) ∧ ¬∃ z succ 1 ( x 1 , z ) ∨ ( x 1 = x 2 ) ∧ P b ( x 1 ) ∧ ¬∃ z succ 1 ( z , x 1 ) ∨ P a ( x 1 ) ∧ P b ( x 2 ) ∧ ∃ z (succ 1 ( z , x 1 ) ∧ succ 2 ( z , x 2 )) ∨ P b ( x 1 ) ∧ P a ( x 2 ) ∧ ∃ z (succ 1 ( z , x 1 ) ∧ succ 2 ( x 2 , z ))        if κ = (1 , 2) P a ( x 1 ) ∧ P b ( x 2 ) ∧ succ 2 ( x 1 , x 2 ) ∨ P b ( x 1 ) ∧ P a ( x 2 ) ∧ succ 2 ( x 1 , x 2 ) ! if κ = (2 , 1) F or ev ery n, m ≥ 1, κ ∈ { 1 , 2 } × { 1 , 2 } , and u 1 , u 2 ∈ [ n ] × [ m ], w e ha ve G ( n, m ) | = ϕ ⋖ κ ( x 1 , x 2 )[ u 1 , u 2 ] iff Φ( G ( n, m )) | = ( x 1 ⋖ x 2 )[ χ n,m ( κ (1) , u 1 ) , χ n,m ( κ (2) , u 2 )] . Finally , to complete step (3), let, for κ ∈ { 1 , 2 } × { 1 , 2 } , ϕ µ κ ( x 1 , x 2 ) = ( x 1 = x 2 if κ = (1 , 2) false otherwise Then, for ev ery n , m ≥ 1, κ ∈ { 1 , 2 } × { 1 , 2 } and u 1 , u 2 ∈ [ n ] × [ m ], G ( n, m ) | = ϕ µ κ ( x 1 , x 2 )[ u 1 , u 2 ] iff Φ( G ( n, m )) | = ( µ ( x 1 , x 2 ))[ χ n,m ( κ (1) , u 1 ) , χ n,m ( κ (2) , u 2 )] . Let ϕ P a ( x ) = ( λ ( x ) = a ) and ϕ P b ( x ) = ( λ ( x ) = b ) . (4) Of co urse, w e ha ve, f or eac h n, m ≥ 1, c ∈ { a, b } , and u ∈ [ n ] × [ m ], G ( n, m ) | = P c ( x )[ u ] iff Φ( G ( n, m )) | = ( ϕ P c )[ χ n,m (1 , u )] . Let ϕ succ 1 ( x 1 , x 2 ) = λ ( x 1 ) = a ∧ λ ( x 2 ) = a ∧ ( x 1 ⋖ x 2 ∨ ∃ z ( x 1 ⋖ z ∧ z ⋖ x 2 )) ∨ λ ( x 1 ) = b ∧ λ ( x 2 ) = b ∧ ∃ z ( x 2 ⋖ z ∧ z ⋖ x 1 ) ! and let furthermore ϕ succ 2 ( x 1 , x 2 ) = ∃ z ( µ ( x 1 , z ) ∧ z ⋖ x 2 ) . Then, for eac h n, m ≥ 1, u 1 , u 2 ∈ [ n ] × [ m ], and k ∈ { 1 , 2 } , it holds G ( n, m ) | = succ k ( x 1 , x 2 )[ u 1 , u 2 ] iff Φ( G ( n, m )) | = ( ϕ succ k )[ χ n,m (1 , u 1 ) , χ n,m (1 , u 2 )] . With the ab ov e form ulas, it is no w immediate to v erify that Φ is indeed a strong first-order reduction. No w observe that Φ( G ) is the “conjunction” of • the regular expression  a +  ( ab ) + ( ba ) +  ∗ a +  +  a +  ( ab ) + ( ba ) +  ∗ ( ab ) + b +  , • the first-order form ula ∀ x ∃ y  µ ( x, y ) ∨ µ ( y , x )  , and 30 B. BO LLIG • the first-order prop erty (written in shorthand ) ∀ x 1 , x 2 , y 1 , y 2  λ ( x 1 ) = λ ( x 2 ) ∧ µ ( x 1 , y 1 ) ∧ µ ( x 2 , y 2 ) →  λ ( x 1 ) = a ∧ x 2 − x 1 = 1 → y 1 − y 2 ∈ { 1 , 2 }  ∧  λ ( y 1 ) = a ∧ y 1 − y 2 = 1 → x 2 − x 1 ∈ { 1 , 2 }  ∧  λ ( y 1 ) = b ∧ y 1 − y 2 = 1 → x 2 − x 1 = 2  ∧  x 2 − x 1 = 2 ∧ λ ( x 1 + 1) 6 = λ ( x 1 ) → y 1 − y 2 ∈ { 1 , 2 }  ∧  y 1 − y 2 = 2 ∧ λ ( y 2 + 1) 6 = λ ( y 2 ) → x 2 − x 1 ∈ { 1 , 2 }   As th e regular expression repr esen ts a Σ 1 ( τ e Σ )-definable prop ert y , Φ( G ) is Σ 1 ( τ e Σ )-definable relativ e to NW ( e Σ), whic h concludes the pro of of Pr op osition 5.4. Com bining Th eorem 5.2, Theorem 5.3, and Prop osition 5.4, w e obtain the follo wing: Theorem 5.5. The monadic se c ond-or der qu antifier-alternation hier ar chy over neste d wor ds is infinite. I.e., for al l k ≥ 1 , ther e is a set of neste d wor ds over e Σ (with e Σ as sp e cifie d ab ove) that is Σ k +1 ( τ e Σ ) -definable r elative to NW ( e Σ) but not Σ k ( τ e Σ ) -definable r elative to NW ( e Σ) . Recall that Theorem 5.5 relies on a particularly simple call-return alphab et and the presence of at least tw o stac ks. Indeed, its pr o of is b ased on the 2-stac k call-return alphab et e Σ, w h ic h is giv en b y Σ 1 c = { a } , Σ 1 r = { a } , Σ 2 c = { b } , Σ 2 r = { b } , and Σ int = ∅ . Finally , Theorems 4.3 and 5.5 giv e rise to the follo wing theorem: Theorem 5.6. The class of neste d-wor d languages that ar e r e c o gnize d by 2 vp a is, in gen- er al, not close d under c omplementation . M or e pr e cisely, ther e is a set L of neste d wor ds over e Σ (with e Σ as sp e cifie d ab ove) such that the fol lowing hold: (1) Ther e is a 2 vp a A over e Σ such that L ( A ) = L . (2) Ther e is no 2 vp a A over e Σ such that L ( A ) = NW ( e Σ) \ L . This implies that the deterministic mo del of a 2 vp a (see [1 3] for its formal definition) is strictly wea k er than the general mo d el. Th is fact w as, h o w eve r, already sho wn in [13]: Consider the language L = { ( ab ) m c n d m − n x n y m − n | m ∈ N , n ∈ [ m ] } and the 2-stac k call- return alphab et e Σ giv en by Σ 1 c = { a } , Σ 1 r = { c, d } , Σ 2 c = { b } , Σ 2 r = { x, y } , and Σ int = ∅ . Then, L is ac cepted b y some 2 vp a o ver e Σ b ut not b y any deterministic 2 vp a o v er e Σ. ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 31 6. B ¨ uchi Mul ti-St a ck Visibl y Pus hdown A utoma t a W e now transfer some fu n damen tal notions and results from the fin ite case in to the setting of infinite (neste d) w ord s. 6.1. B ¨ uc hi Multi-Stac k Visibly Pushdo wn Automata. Let K ≥ 1, and let e Σ = h{ (Σ s c , Σ s r ) } s ∈ [ K ] , Σ int i b e a K -stac k call-return alphab et. Definition 6.1. A B¨ uchi multi-stack visibly pushdo wn automato n (B ¨ uc hi Mvp a ) o v er e Σ is a tuple A = ( Q, Γ , δ , Q I , F ) wh ose comp on ents agree w ith those of an ordin ary Mvp a , i.e., Q is its finite set of states , Q I ⊆ Q is the set of initial states , F ⊆ Q is th e set of final states , Γ is the finite stack alphab et con taining the sp ecial symb ol ⊥ , and δ is a triple h δ c , δ r , δ int i with δ c ⊆ Q × Σ c × (Γ \ {⊥} ) × Q , δ r ⊆ Q × Σ r × Γ × Q , and δ int ⊆ Q × Σ int × Q . A B ¨ uchi 2-stack vi sib ly pushdown automato n (B ¨ uc hi 2 vp a ) is a B ¨ uc h i Mvp a that is defined ov er a 2-stac k alphab et. Consider an infin ite string w = a 1 a 2 . . . ∈ Σ ω . A run of the B ¨ uc hi Mvp a A on w is a sequence ρ = ( q 0 , σ 1 0 , . . . , σ K 0 )( q 1 , σ 1 1 , . . . , σ K 1 ) . . . ∈ ( Q × Cont [ K ] ) ω (recall that Cont = (Γ \ {⊥} ) ∗ · {⊥} ) su c h that q 0 ∈ Q I , σ s 0 = ⊥ for eve ry stac k s ∈ [ K ], and [Push] , [P op] , and [In ternal] as sp ecified in the finite case h old for ev ery i ∈ N + . W e call the r u n accepting if { q | q = q i for infinitely m any i ∈ N } ∩ F 6 = ∅ . A string w ∈ Σ ω is accepted b y A if there is an accepting run of A on w . The such defi n ed (string) languag e of A is denoted by L ω ( A ). F or the infin ite case, we can lik ewise establish a relational stru ctur e of infinite nested w ords: Definition 6.2. An infinite neste d wor d ov er e Σ is a structure ( N + , ⋖ , µ, λ ) where ⋖ = { ( i, i + 1) | i ∈ N + } , λ : N + → Σ, and µ = S s ∈ [ K ] µ s ⊆ N + × N + where, for ev ery s ∈ [ K ] and ( i , j ) ∈ N + × N + , ( i, j ) ∈ µ s iff i < j , λ ( i ) ∈ Σ s c , λ ( j ) ∈ Σ s r , and λ ( i + 1) . . . λ ( j − 1) is s -w ell formed. The set of infin ite nested w ords o v er e Σ is denoted by NW ω ( e Σ). Again, giv en infi nite nested w ord s W = ( N + , ⋖ , µ, λ ) and W ′ = ( N + , ⋖ ′ , µ ′ , λ ′ ), λ = λ ′ implies W = W ′ so that w e can repr esen t W as string( W ) := λ (1) λ (2 ) . . . ∈ Σ ω . Vice v ersa, giv en a string w ∈ Σ ω , there is exact ly one infi nite n ested word W o v er e Σ suc h that string( W ) = w , wh ic h we denote nested( w ). Definition 6.3. A gener alize d B ¨ uchi multi-stack neste d-wor d automaton (ge neralized B ¨ uc h i Mnw a ) o ver e Σ is a tuple B = ( Q, δ, Q I , F , C ) where Q , δ , Q I , F , and C are as in a generalize d Mnw a . Recall that, in particular, δ is a pair h δ 1 , δ 2 i with δ 1 ⊆ Q × Σ × Q and δ 2 ⊆ Q × Q × Σ r × Q . W e call B a gener alize d B¨ uchi 2-stack neste d-wor d automaton (generalize d B ¨ uc hi 2 nw a ) if it is defined o v er a 2-stac k alphab et. If C = ∅ , then w e ca ll B a B ¨ uc hi Mnw a (B ¨ uchi 2 nw a , if K = 2). A run of B o n an infinite nested w ord W = ( N + , ⋖ , µ, λ ) ∈ NW ω ( e Σ) is a mapping ρ : N + → Q suc h that ( q, λ (1) , ρ (1)) ∈ δ 1 for some q ∈ Q I , and, for all i ≥ 2, w e ha v e ( ( ρ ( µ − 1 ( i )) , ρ ( i − 1) , λ ( i ) , ρ ( i )) ∈ δ 2 if λ ( i ) ∈ Σ r and µ − 1 ( i ) is defined ( ρ ( i − 1) , λ ( i ) , ρ ( i )) ∈ δ 1 otherwise 32 B. BO LLIG The r u n ρ is accepting if ρ ( i ) ∈ F for infinitely many i ∈ N + and, for all i ∈ N + with ρ ( i ) ∈ C , b oth λ ( i ) ∈ Σ c and µ ( i ) is defin ed. The language of B , denoted b y L ω ( B ), is the set of infinite nested wo rds o ve r e Σ th at allo w for an accepting run of B . As we still h a ve a one-to-one corresp ond en ce b et w een strings and nested wo rds, w e ma y let L ω ( A ) with A a B ¨ u c hi Mv p a stand for the set { nested( w ) | w ∈ L ω ( A ) } . It is no w straightfo rw ard to adapt Lemma 2.7 and Lemma 2.8 to the infinite setting: Lemma 6.4. F or every gener alize d B ¨ uchi Mnw a B , ther e is a B ¨ uchi Mnw a B ′ such that L ω ( B ′ ) = L ω ( B ) . Lemma 6.5. L et L ⊆ NW ω ( e Σ) . The fol lowing ar e e quivalent: (1) Ther e is a B¨ uchi Mvp a A such that L ω ( A ) = L . (2) Ther e is a B¨ uchi Mnw a B such that L ω ( B ) = L . 6.2. B ¨ uc hi 2-Stac k Visibly Pushdo wn Automata vs. Logic. In this section, we will again restrict to tw o stac ks. Unfortunately , EMSO logic ov er infi nite nested wo rds turns out to b e to o weak to capture all the b eh avio rs of B ¨ uchi 2 vp a . Giv en that EMSO logic considers a successor relation instead of an order r elation, one cannot ev en express that one particular action o ccurs infinitely often. T o o verco me this deficiency , one can in trod uce a first-order quan tifier ∃ ∞ xϕ meaning that there are infinitely many p ositions x to satisfy the prop erty ϕ [4]. So let us fix a 2-stac k call-return alphab et e Σ = h{ (Σ 1 c , Σ 1 r ) , (Σ 2 c , Σ 2 r ) } , Σ int i for the rest of the pap er. W e introd uce the logic MSO ∞ ( τ e Σ ), which is giv en by the follo wing grammar: ϕ ::= λ ( x ) = a | x ⋖ y | µ ( x, y ) | x = y | x ∈ X | ¬ ϕ | ϕ 1 ∨ ϕ 2 | ∃ xϕ | ∃ ∞ xϕ | ∃ X ϕ where a ∈ Σ. The fragment s EMSO ∞ ( τ e Σ ) and FO ∞ ( τ e Σ ) are defin ed as one wo uld exp ect. The sat isfaction relat ion is as usual concerning the familiar fragmen t MSO( τ e Σ ). Moreo v er, giv en a formula ϕ ( y , x 1 , . . . , x m , X 1 , . . . , X n ) ∈ MSO ∞ ( τ e Σ ), an infin ite nested wo rd W , ( i 1 , . . . , i m ) ∈ ( N + ) m , and ( I 1 , . . . , I n ) ∈ (2 N + ) n , we set W | = ( ∃ ∞ y ϕ )[ i 1 , . . . , i m , I 1 , . . . , I n ] iff W | = ϕ [ i, i 1 , . . . , i m , I 1 , . . . , I n ] for infinitely many i ∈ N + . Giv en a sen tence ϕ ∈ MSO ∞ ( τ e Σ ), w e denote by L ω ( ϕ ) the set of infinite nested w ords o v er e Σ th at s atisfy ϕ . T o establish a connection b etw een the extended log ic and our B ¨ uchi automata mod els, w e h a ve to provi de an extension of Hanf ’s Theorem. Theorem 6.6 (cf. [4]) . L et ϕ ∈ F O ∞ ( τ e Σ ) b e a sentenc e. Ther e is a p ositive Bo ole an c ombination ψ of formulas of the form ∃ = t x χ ( x ) and ∃ >t x χ ( x ) and ∃ < ∞ x χ ( x ) and ∃ = ∞ x χ ( x ) wher e t ∈ N and χ ( x ) ∈ F O( τ e Σ ) is lo c al such that, for eve ry neste d wor d W ∈ NW ω ( e Σ) , we have W | = ϕ iff W | = ψ . Unfortunately , we do n ot kno w if ψ can b e computed effectiv ely in this extended setting. W e observe that the 2 nw a B r constructed in the pro of of P rop osition 4.1 can b e easily adapted to obtain its coun terpart for infinite nested words: Prop osition 6.7. L et r ∈ N b e any natur al numb er. Th er e ar e a gener alize d B¨ uchi 2 nw a B ω r = ( Q, δ , Q I , F , C ) over e Σ and a mapping η : Q → Spher es r ( e Σ) such that ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 33 • L ω ( B ω r ) = NW ω ( e Σ) and • for every W ∈ N W ω ( e Σ) , ev e ry ac c epting run ρ of B ω r on W , and ev ery no de i ∈ N + of W , we have η ( ρ ( i )) ∼ = r - Sph( W , i ) . Pr o of. First, note that Prop osition 4.5 and the cru cial argum en t stated in the pro of o f Claim 4.8 (see F o otnote 5) hold for infin ite nested words ju st as well. No w , we lo ok at the generalized 2 nw a B r = ( Q, δ, Q I , F , C ) as constru cted in the p ro of of Prop osition 4.1. As the only pur p ose of the set F of final states is to ensure progress in some states wh ere progress is r equired in terms of spheres w ith a non-maximal activ e no d e, w e can set B ω r to b e ( Q, δ , Q I , Q, C ), and we are done. With this, we can easily exte nd Lemma 4. 2 and determine a B¨ uchi 2 nw a to detect if a particular sphere o ccurs infinitely often in an infinite nest ed word: Lemma 6.8. L et r ∈ N and let S ∈ Spher es r ( e Σ) . Ther e is a gener alize d B¨ uchi 2 nw a B over e Σ such that L ω ( B ) = { W ∈ NW ω ( e Σ) | ther e ar e infinitely many i ∈ N + such that r - Sph( W , i ) ∼ = S } . Pr o of. W e start f rom the generalized B ¨ u c hi 2 nw a B ω r = ( Q, δ, Q I , Q, C ) and the mapping η : Q → Spher es r ( e Σ) from Prop osition 6.7. T o obtain B as required in the prop osition, w e simply set the s et of final state s to b e { q ∈ Q | η ( q ) ∼ = S } . Theorem 6.9 . L et L ⊆ N W ω ( e Σ) b e a set of infinite neste d wor ds over the 2-stack c al l- r eturn alphab et e Σ . Then, the fol lowing ar e e quivalent: (1) Ther e is a B¨ uchi 2 vp a A over e Σ such that L ω ( A ) = L . (2) Ther e is a sentenc e ϕ ∈ EMS O ∞ ( τ e Σ ) such that L ω ( ϕ ) = L . Pr o of. T o pro ve (1 ) → (2), one again uses standard metho ds. Basically , second-order v ariables X q for q ∈ Q encode an assignment of states to p ositions in a nested word. Then, the first-order part of the formula expresses that this assignment is actually an accepting run. T o tak e care of the acceptance condition, we add the disjun ction of formulas ∃ = ∞ x ( x ∈ X q ) with q a final state. F or the d irection (2) → (1), w e mak e u se of Lemmas 6.4, 6.5, 6.8, (a simple v ariation of ) Lemma 4.2, and the easy fact that the class of languages of infinite nested words that are r ecognize d by generalized B ¨ uc hi 2 nw a is closed und er union and inte rsection. With this, the pro of pro ceeds exactly as in the finite case. 7. Open Pr oblems W e lea ve op en if visibly p ushdown automata still adm it a logica l c haracteriza tion in terms of EMSO logi c once they are equipp ed w ith more than t wo stac ks. W e conjecture that ev ery first-order definable set of nested words o v er t wo stac ks is recognized by some unam biguous 2 vp a , i.e., by a 2 vp a in w h ic h an accepting run is uniqu e. T o ac hiev e such an automaton, the coloring of spheres as p erformed by B r b y simply guessing and subsequen tly v erifying it has to b e done un am biguously . W e d o not kn o w if EMSO logic o v er nested w ords b ecomes more expressiv e if w e allo w atomic f orm ulas x < y with the ob vious meaning. F or this logic, it is no longer p ossible to apply Hanf ’s theo rem as the degree of the resulting structures is not b ounded anymore. 34 B. BO LLIG Our metho d might lead to logical c haracterizat ions f or concurrent queue systems, where sev eral visibly p ushdown automata communica te with eac h other via c hann els [14]. I n this extended setting, we deal with b oth multiple stac ks and c hannels. A corresp ond ing logic then has to provi de an additional matc hing pred icate msg( x, y ) to relate the send ing and reception of a message (see, for example, [5]). It remains to id en tify c h annel arc hitectures for which a logical c haracterizat ion is p ossible. Using results from [14], this might lead to partial r esults concerning the decidabilit y of corresp onding satisfiabilit y problems. Finally , it migh t b e worth wh ile to stud y if our tec h nique leads to a logical charac teri- zation of 2 vp a for more ge neral 2-st ac k call-return alph ab ets as int ro duced in [8]. Ac knowledgmen t W e thank th e anon ymous referees for their careful reading and many useful remarks. Referenc es [1] R. Alur and P . Madhusudan. Visibly pushd o wn languages. I n Pr o c e e dings of the 36th Annual ACM Symp osium on The ory of Computing (STOC 2004) , pages 202–211. ACM Press, 2004. [2] R. A lur and P . Madhusudan. Ad ding n esting stru cture to w ords. In Pr o c e e dings of the 10t h Interna- tional Conf er enc e on Developments in L anguage The ory (DL T 2006) , volume 4036 of L e ctur e Not es in Computer Scienc e , p ages 1–13. Springer, 2006. [3] M. F. Atig , B. Bollig, and P . Hab ermehl. Emptiness of m ulti-pushdown automata is 2ETIME-complete. In Pr o c e e dings of the 12th International Confer enc e on Developments in Language The ory (DL T 2008) , vol ume 5257 of L e ctur e Notes in Computer Scienc e , p ages 121–1 33. Springer, 2008. [4] B. Bollig and D. Kuske. Muller message-passing aut omata and logics. Information and Computation , 206(9-10):1 084–1 094, 2008. [5] B. Bollig and M. Leu cker. Message-pass ing automata are ex pressive ly equiva len t to EMSO logic. The- or etic al Computer Scienc e , 358(2-3):150–17 2, 2006. [6] L. Brevegli eri, A. Cherubini, C. Citrini, and S. Crespi R eghizzi. Multi-pu sh-down languages and gram- mars. International Journal of F oundations of Computer Scienc e , 7(3):253–292, 1996. [7] J. B ¨ uc hi. W eak second order logic and finite automata. Z. Math. L o gik Grund lag. Math. , 5:66–62, 1960. [8] D. Caroten uto, A. Murano, and A . P eron. 2-visibly pu shd ow n automata. In Pr o c e e dings of the 11th International Confer enc e on Developments i n L anguage The ory (DL T 2007) , volume 4588 of L e ctur e Notes i n Computer Scienc e , p ages 132–144. S p ringer, 2007. [9] M. Droste, P . Gastin, and D. Ku ske. Asynchronous cellular automata for pomsets. The or etic al Computer Scienc e , 247(1-2):1–38, 2000. [10] C. C. Elgot. D ecision p roblems of finite automata design and related arithmetics. T r ans. Amer. M ath. So c. , 98:21–52 , 1961. [11] W. Hanf. Model-th eoretic metho ds in the stud y of elemen tary logic. In J. W. Addison, L. Hen kin, and A. T arski, editors, The The ory of Mo dels . N orth - Holland, Amsterdam, 1965. [12] J. E. H op croft, R . Mot w ani, and J. D. Ullman. Intr o duct ion to Automat a The ory, L anguages and Computability . Ad d ison-W esley , 2000. [13] S . La T orre, P . Madhusudan, and G. P arlato. A robust class of context-sensitiv e languages. In Pr o c e e d- ings of the 22nd IEEE Symp osium on L o gic i n C omputer Scienc e (LICS 2007) , pages 161 –170. IEEE Computer S ociety Press, 2007. [14] S . La T orre, P . Madhusudan, and G. Parlato . Con text-b ounded analysis of concurrent queue systems. In Pr o c e e dings of the 14th International Confer enc e on T o ols and Algorithms for the Construct ion and An alysis of Systems (T ACAS 2008) , Lecture Notes in Computer Science, pages 299–314. Springer, 2008. [15] C. Lautemann, Th. Sch w en tic k, and D. Therien. Logics for con text-free languages. In Pr o c e e dings of the 1994 Annu al Confer enc e of the Eur op e an Asso ciation for Computer Scienc e L o gic (CSL 1994) , volume 933 of L e ctur e Notes in Computer Scienc e , p ages 205–21 6, 1995. [16] L. Libkin . Elements of Finite Mo del The ory . S pringer, 2004. [17] O . Matz, N. Sch w eik ardt, and W. Thomas. The monadic qu antifier alternation hierarc hy o ver grids and graphs. Inf ormation and Computation , 179(2):356–383 , 2002. ON TH E EXPRESSIVE POWER OF 2-ST A CK VISIBL Y PUSHDOWN AUTOMA T A 35 [18] W. Thomas. Elemen ts of an automata theory ov er p artial orders. In Pr o c e e dings of Workshop on Partial Or der Metho ds in V erific ation (POMIV 1996) , volume 29 of DIMACS . AMS, 1996. [19] W. Thomas. Aut omata theory on trees and p artial orders. In Pr o c e e dings of The ory and Pr actic e of Softwar e Development (T APSOFT 1997), 7th International Joint Confer enc e CAAP/F ASE , volume 1214 of L e ctur e Notes in Computer Scienc e , p ages 20–38. Springer, 1997. [20] W. Thomas. Languages, automata and logi c. In A. S alomaa and G. Rozenberg, editors, Handb o ok of F ormal L anguage s , volume 3, Beyond W ords, pages 389–45 5. Springer, 1997. This work is licensed under the Cr eative Commons Attribution-No Derivs License. T o view a copy of this license, visit http://reative o mm on s. org /l i en se s/b y- nd /2 .0 / or send a letter to Creative Commons , 559 Nathan Abbott Wa y , S tanford, California 94305, USA.

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment