# Nested word

Jump to navigation Jump to search

In computer science, more specifically in automata and formal language theory, nested words are a concept proposed by Alur and Madhusudan as a joint generalization of words, as traditionally used for modelling linearly ordered structures, and of ordered unranked trees, as traditionally used for modelling hierarchical structures. Finite-state acceptors for nested words, so-called nested word automata, then give a more expressive generalization of finite automata on words. The linear encodings of languages accepted by finite nested word automata gives the class of visibly pushdown languages. The latter language class lies properly between the regular languages and the deterministic context-free languages. Since their introduction in 2004, these concepts have triggered much research in that area.[1]

## Formal definition

To define nested words, we first need to define matching relation. As usual, for a nonnegative integer ${\displaystyle \ell }$, we use the notation ${\displaystyle [\ell ]}$ to denote the set ${\displaystyle \{1,2,\ldots ,\ell -1,\ell \}}$, with the special case ${\displaystyle [0]=\emptyset }$.

A matching relation ↝ of length ${\displaystyle \ell \geq 0}$ is a subset of ${\displaystyle \{-\infty ,1,2,\ldots ,\ell -1,\ell \}\times \{1,2,\ldots ,\ell -1,\ell ,\infty \}}$ such that:

1. all nesting edges are forward, that is, if i ↝ j then i < j;
2. nesting edges never have a finite position in common, that is, for −∞ < i < ∞, there is at most one position h such that h ↝ i, and there is at most one position j such that ij; and
3. nesting edges never cross, that is, we can't find i < i ′ ≤ j < j ′ such that both i ↝ j and i ′ ↝ j ′.

A position i is referred to as

• a call position, if ij for some j,
• a pending call if i ↝ ∞,
• a return position, if hi for some h,
• a pending return if −∞ ↝ i, and
• an internal position in all remaining cases.

A nested word of length ${\displaystyle \ell }$ over an alphabet Σ is a pair (w,↝), where w is a word of length ${\displaystyle \ell }$ over Σ (in the usual sense) and ↝ is a matching relation of length ${\displaystyle \ell }$.

## Encoding nested words into ordinary words

Nested words over the alphabet ${\displaystyle \Sigma =\{a_{1},a_{2},\ldots ,a_{n}\}}$ can be encoded into "ordinary" words over the tagged alphabet ${\displaystyle {\hat {\Sigma }}}$, in which each symbol a from Σ has three tagged counterparts: the symbol ⟨a for encoding a call position in a nested word labelled with a, the symbol a⟩ for encoding a return position labelled with a, and finally the symbol a itself for representing an internal position labelled with a. More precisely, let φ be the function mapping nested words over Σ to words over ${\displaystyle {\hat {\Sigma }}}$ such that each nested word (${\displaystyle w_{1}w_{2}\cdots w_{\ell }}$,↝) is mapped to the word ${\displaystyle x_{1}x_{2}...x_{\ell }}$, where the letter ${\displaystyle x_{i}}$ equals ⟨a, a, and a⟩, if ${\displaystyle w_{i}=a}$ and i is a (possibly pending) call position, an internal position, and a (possibly pending) return position, respectively.

### Example

For illustration, let n=(w,↝) be the nested word over a ternary alphabet with w=abaabccca and matching relation ↝ = {(−∞,1),(2,∞),(3,4),(5,7),(8,∞)}. Then its encoding as word reads as φ(n) = a⟩⟨baa⟩⟨bcc⟩⟨ca.

## Automata

### Nested word automaton

A nested word automaton has a finite number of states, and operates in almost the same way as a deterministic finite automaton on classical strings: a classical finite automaton reads the input word ${\displaystyle w=w_{1}\cdots w_{\ell }}$ from left to right, and the state of the automaton after reading the jth letter ${\displaystyle w_{j}}$ depends on the state in which the automaton was before reading ${\displaystyle w_{j}}$.

In a nested word automaton, the position ${\displaystyle j}$ in the nested word (w,↝) might be a return position; if so, the state after reading ${\displaystyle w_{j}}$ will not only depend on the linear state in which the automaton was before reading ${\displaystyle w_{j}}$, but also on a hierarchical state propagated by the automaton at the time it was in the corresponding call position. In analogy to regular languages of words, a set L of nested words is called regular if it is accepted by some (finite-state) nested word automaton.

### Visibly pushdown automaton

Nested word automata are an automaton model accepting nested words. There is an equivalent automaton model operating on (ordinary) words. Namely, the notion of a deterministic visibly pushdown automaton is a restriction of the notion of a deterministic pushdown automaton.

Following Alur and Madhusudan,[2] a deterministic visibly pushdown automaton is formally defined as a 6-tuple ${\displaystyle M=(Q,{\hat {\Sigma }},\Gamma ,\delta ,q_{0},F)}$ where

• ${\displaystyle Q}$ is a finite set of states,
• ${\displaystyle {\hat {\Sigma }}}$ is the input alphabet, which – in contrast to that of ordinary pushdown automata – is partitioned into three sets ${\displaystyle \Sigma _{\text{c}}}$, ${\displaystyle \Sigma _{\text{r}}}$, and ${\displaystyle \Sigma _{\text{int}}}$. The alphabet ${\displaystyle \Sigma _{\text{c}}}$ denotes the set of call symbols, ${\displaystyle \Sigma _{\text{r}}}$ contains the return symbols, and the set ${\displaystyle \Sigma _{\text{int}}}$ contains the internal symbols,
• ${\displaystyle \Gamma }$ is a finite set which is called the stack alphabet, containing a special symbol ${\displaystyle \bot \in \Gamma }$ denoting the empty stack,
• ${\displaystyle \delta =\delta _{\text{c}}\cup \delta _{\text{r}}\cup \delta _{\text{int}}}$ is the transition function, which is partitioned into three parts corresponding to call transitions, return transitions, and internal transitions, namely
• ${\displaystyle \delta _{\text{c}}\colon Q\times \Sigma _{\text{c}}\to Q\times \Gamma }$, the call transition function
• ${\displaystyle \delta _{\text{r}}\colon Q\times \Sigma _{\text{r}}\times \Gamma \to Q}$, the return transition function
• ${\displaystyle \delta _{\text{int}}:Q\times \Sigma _{\text{int}}\to Q}$, the internal transition function,
• ${\displaystyle q_{0}\in \,Q}$ is the initial state, and
• ${\displaystyle F\subseteq Q}$ is the set of accepting states.

The notion of computation of a visibly pushdown automaton is a restriction of the one used for pushdown automata. Visibly pushdown automata only add a symbol to the stack when reading a call symbol ${\displaystyle a_{\text{c}}\in \Sigma _{\text{c}}}$, they only remove the top element from the stack when reading a return symbol ${\displaystyle a_{\text{r}}\in \Sigma _{\text{r}}}$ and they do not alter the stack when reading an internal event ${\displaystyle a_{\text{i}}\in \Sigma _{\text{int}}}$. A computation ending in an accepting state is an accepting computation.

As a result, a visibly pushdown automaton cannot push to and pop from the stack with the same input symbol. Thus the language ${\displaystyle L=\{a^{n}ba^{n}\mid n\in \mathrm {N} \}}$ cannot be accepted by a visibly pushdown automaton for any partition of ${\displaystyle \Sigma }$, however there are pushdown automata accepting this language.

If a language ${\displaystyle L}$ over a tagged alphabet ${\displaystyle {\hat {\Sigma }}}$ is accepted by a deterministic visibly pushdown automaton, then ${\displaystyle L}$ is called a visibly pushdown language.

### Nondeterministic visibly pushdown automata

Nondeterministic visibly pushdown automata are as expressive as deterministic ones. Hence one can transform a nondeterministic visibly pushdown automaton into a deterministic one, but if the nondeterministic automaton had ${\displaystyle s}$ states, the deterministic one may have up to ${\displaystyle 2^{s^{2}}}$ states.[3]

## Decision problems

Let ${\displaystyle |A|}$ be the size of the description of an automaton ${\displaystyle A}$, then it is possible to check if a word n is accepted by the automaton in time ${\displaystyle O(|A|^{3}\ell )}$. In particular, the emptiness problem is solvable in time ${\displaystyle O(|A|^{3})}$. If ${\displaystyle A}$ is fixed, it is decidable in time ${\displaystyle O(\ell )}$ and space ${\displaystyle O(d)}$ where ${\displaystyle d}$ is the depth of n in a streaming seeing. It is also decidable with space ${\displaystyle O(\log(\ell ))}$ and time ${\displaystyle O(\ell ^{2}\log(\ell ))}$, and by a uniform boolean circuit of depth ${\displaystyle O(\log \ell )}$.[2]

For two nondeterministic automata A and B, deciding whether the set of words accepted by A is a subset of the word accepted by B is EXPTIME-complete. It is also EXPTIME-complete to figure out if there is a word that is not accepted.[2]

## Languages

As the definition of visibly pushdown automata shows, deterministic visibly pushdown automata can be seen as a special case of deterministic pushdown automata; thus the set VPL of visibly pushdown languages over ${\displaystyle \,{\hat {\Sigma }}}$ forms a subset of the set DCFL of deterministic context-free languages over the set of symbols in ${\displaystyle \,{\hat {\Sigma }}}$. In particular, the function that removes the matching relation from nested words transforms regular languages over nested words into context-free languages.

### Closure properties

The set of visibly pushdown languages is closed under the following operations:[3]

• set operations:
• union
• intersection
• complement,
thus giving rise to a boolean algebra.

For the intersection operation, one can construct a VPA M simulating two given VPAs ${\displaystyle M_{1}}$ and ${\displaystyle M_{2}}$ by a simple product construction (Alur & Madhusudan 2004): For ${\displaystyle i=1,2}$, assume ${\displaystyle M_{i}}$ is given as ${\displaystyle (Q_{i},\ {\hat {\Sigma }},\ \Gamma _{i},\ \delta _{i},\ s_{i},\ Z_{i},\ F_{i})}$. Then for the automaton M, the set of states is ${\displaystyle \,Q_{1}\times Q_{2}}$, the initial state is ${\displaystyle \left(s_{1},s_{2}\right)}$, the set of final states is ${\displaystyle F_{1}\times F_{2}}$, the stack alphabet is given by ${\displaystyle \,\Gamma _{1}\times \Gamma _{2}}$, and the initial stack symbol is ${\displaystyle (Z_{1},Z_{2})}$.

If ${\displaystyle M}$ is in state ${\displaystyle (p_{1},p_{2})}$ on reading a call symbol ${\displaystyle \left\langle a\right.}$, then ${\displaystyle M}$ pushes the stack symbol ${\displaystyle (\gamma _{1},\gamma _{2})}$ and goes to state ${\displaystyle (q_{1},q_{2})}$, where ${\displaystyle \gamma _{i}}$ is the stack symbol pushed by ${\displaystyle M_{i}}$ when transitioning from state ${\displaystyle p_{i}}$ to ${\displaystyle q_{i}}$ on reading input ${\displaystyle \left\langle a\right.}$.

If ${\displaystyle M}$ is in state ${\displaystyle (p_{1},p_{2})}$ on reading an internal symbol ${\displaystyle a}$, then ${\displaystyle M}$ goes to state ${\displaystyle (q_{1},q_{2})}$, whenever ${\displaystyle M_{i}}$ transitions from state ${\displaystyle p_{i}}$ to ${\displaystyle q_{i}}$ on reading a.

If ${\displaystyle M}$ is in state ${\displaystyle (p_{1},p_{2})}$ on reading a return symbol ${\displaystyle \left.a\right\rangle }$, then ${\displaystyle M}$ pops the symbol ${\displaystyle (\gamma _{1},\gamma _{2})}$ from the stack and goes to state ${\displaystyle (q_{1},q_{2})}$, where ${\displaystyle \gamma _{i}}$ is the stack symbol popped by ${\displaystyle M_{i}}$ when transitioning from state ${\displaystyle p_{i}}$ to ${\displaystyle q_{i}}$ on reading ${\displaystyle \left.a\right\rangle }$.

Correctness of the above construction crucially relies on the fact that the push and pop actions of the simulated machines ${\displaystyle M_{1}}$ and ${\displaystyle M_{2}}$ are synchronized along the input symbols read. In fact, a similar simulation is no longer possible for deterministic pushdown automata, as the larger class of deterministic context-free languages is no longer closed under intersection.

In contrast to the construction for concatenation shown above, the complementation construction for visibly pushdown automata parallels the standard construction[4] for deterministic pushdown automata.

Moreover, like the class of context free languages the class of visibly pushdown languages is closed under prefix closure and reversal, hence also suffix closure.

### Relation to other language classes

Alur & Madhusudan (2004) point out that the visibly pushdown languages are more general than the parenthesis languages suggested in McNaughton (1967). As shown by Crespi Reghizzi & Mandrioli (2012), the VPL in turn are strictly contained in the class of languages described by operator-precedence grammars, which were introduced by Floyd (1963) and enjoy the same closure properties and characteristics (see Lonati et al. (2015) for ω languages and logic and automata-based characterizations). In comparison to conjunctive grammars, a generalization of context-free grammars, Okhotin (2011) shows that the linear conjunctive languages form a superclass of the visibly pushdown languages. The table at the end of this article puts the family of visibly pushdown languages in relation to other language families in the Chomsky hierarchy. Rajeev Alur and Parthasarathy Madhusudan[5][6] related a subclass of regular binary tree languages to visibly pushdown languages.

## Other models of description

### Visibly pushdown grammars

Visibly pushdown languages are exactly the languages that can be described by visibly pushdown grammars.[2]

Visibly pushdown grammars can be defined as a restriction of context-free grammars. A visibly pushdown grammar G is defined by the 4-tuple:

${\displaystyle G=(V=V^{0}\cup V^{1}\,,\Sigma \,,R\,,S\,)}$ where

• ${\displaystyle V^{0}\,}$ and ${\displaystyle V^{1}\,}$ are disjoint finite sets; each element ${\displaystyle v\in V}$ is called a non-terminal character or a variable. Each variable represents a different type of phrase or clause in the sentence. Each variable defines a sub-language of the language defined by ${\displaystyle G\,}$, and the sub-languages of ${\displaystyle V^{0}\,}$ are the one without pending calls or pending returns.
• ${\displaystyle \Sigma \,}$ is a finite set of terminals, disjoint from ${\displaystyle V\,}$, which make up the actual content of the sentence. The set of terminals is the alphabet of the language defined by the grammar ${\displaystyle G\,}$.
• ${\displaystyle R\,}$ is a finite relation from ${\displaystyle V\,}$ to ${\displaystyle (V\cup \Sigma )^{*}}$ such that ${\displaystyle \exists \,w\in (V\cup \Sigma )^{*}:(S,w)\in R}$. The members of ${\displaystyle R\,}$ are called the (rewrite) rules or productions of the grammar. There are three kinds of rewrite rules. For ${\displaystyle X,Y\in V,Z\in V^{0}}$, ${\displaystyle a\in {\hat {\Sigma }}}$ and ${\displaystyle b\in {\hat {\Sigma }}}$
• ${\displaystyle X\to \epsilon }$
• ${\displaystyle X\to aY}$ and if ${\displaystyle X\in V^{0}}$ then ${\displaystyle Y\in V^{0}}$ and ${\displaystyle a\in \Sigma }$
• ${\displaystyle X\to \langle aZb\rangle Y}$ and if ${\displaystyle X\in V^{0}}$ then ${\displaystyle Y\in V^{0}}$
• ${\displaystyle S\in V\,}$ is the start variable (or start symbol), used to represent the whole sentence (or program).

Here, the asterisk represents the Kleene star operation and ${\displaystyle \epsilon }$ is the empty word.

### Uniform Boolean circuits

The problem whether a word of length ${\displaystyle \ell }$ is accepted by a given nested word automaton can be solved by uniform boolean circuits of depth ${\displaystyle \mathrm {O} (\log \ell )}$.[2]

### Logical description

Regular languages over nested words are exactly the set of languages described by Monadic second-order logic with two unary predicates call and return, linear successor and the matching relation ↝.[2]

## Notes

1. ^ Google Scholar search results for "nested words" OR "visibly pushdown"
2. Alur & Madhusudan (2009)
3. ^ a b Alur & Madhusudan (2004)
4. ^ Hopcroft & Ullman (1979, p. 238 f).
5. ^ Alur, R.; Madhusudan, P. (2004). "Visibly pushdown languages" (PDF). Proceedings of the thirty-sixth annual ACM symposium on Theory of computing - STOC '04. pp. 202–211. doi:10.1145/1007352.1007390. ISBN 1581138520. Sect.4, Theorem 5,
6. ^ Alur, R.; Madhusudan, P. (2009). "Adding nesting structure to words" (PDF). Journal of the ACM. 56 (3): 1–43. doi:10.1145/1516512.1516518. Sect.7