Parikh's theorem
Parikh's theorem in theoretical computer science says that if one looks only at the number of occurrences of each terminal symbol in a context-free language, without regard to their order, then the language is indistinguishable from a regular language.[1] It is useful for deciding that strings with a given number of terminals are not accepted by a context-free grammar.[2] It was first proved by Rohit Parikh in 1961[3] and republished in 1966.[4]
Definitions and formal statement
Let [math]\displaystyle{ \Sigma=\{a_1,a_2,\ldots,a_k\} }[/math] be an alphabet. The Parikh vector of a word is defined as the function [math]\displaystyle{ p:\Sigma^*\to\mathbb{N}^k }[/math], given by[1] [math]\displaystyle{ p(w)=(|w|_{a_1}, |w|_{a_2}, \ldots, |w|_{a_k}) }[/math] where [math]\displaystyle{ |w|_{a_i} }[/math] denotes the number of occurrences of the letter [math]\displaystyle{ a_i }[/math] in the word [math]\displaystyle{ w }[/math].
A subset of [math]\displaystyle{ \mathbb{N}^k }[/math] is said to be linear if it is of the form [math]\displaystyle{ u_0 + \mathbb{N}u_1 + \dots + \mathbb{N}u_m = \{u_0+t_1u_1+\dots+t_mu_m \mid t_1,\ldots,t_m\in\mathbb{N}\} }[/math] for some vectors [math]\displaystyle{ u_0,\ldots,u_m }[/math]. A subset of [math]\displaystyle{ \mathbb{N}^k }[/math] is said to be semi-linear if it is a union of finitely many linear subsets.
Theorem — Let [math]\displaystyle{ L }[/math] be a context-free language or a regular language, let [math]\displaystyle{ P(L) }[/math] be the set of Parikh vectors of words in [math]\displaystyle{ L }[/math], that is, [math]\displaystyle{ P(L) = \{p(w) \mid w \in L\} }[/math]. Then [math]\displaystyle{ P(L) }[/math] is a semi-linear set.
If [math]\displaystyle{ S }[/math] is any semi-linear set, then there exists a regular language (which a fortiori is context-free) whose Parikh vectors is [math]\displaystyle{ S }[/math].
In short, the image under [math]\displaystyle{ p }[/math] of context-free languages and of regular languages is the same, and it is equal to the set of semilinear sets.
Two languages are said to be commutatively equivalent if they have the same set of Parikh vectors. Thus, every context-free language is commutatively equivalent to some regular language.
Proof
The second part is easy to prove.
Given semi-linear set [math]\displaystyle{ S }[/math], to construct a regular language whose set of Parikh vectors is [math]\displaystyle{ S }[/math].
[math]\displaystyle{ S }[/math] is a union of 0 or more linear sets. Since the empty language is regular, and union of regular languages is regular, it suffices to prove that any linear set is the set of Parikh vectors of a regular language.
Let [math]\displaystyle{ S = \{u_0+t_1u_1+\dots+t_mu_m \mid t_1,\ldots,t_m\in\mathbb{N}\} }[/math], then it is the set of Parikh vectors of [math]\displaystyle{ \{z_0\} \cdot (\cup_{i=1}^m \{z_i\})^* }[/math], where each [math]\displaystyle{ z_i }[/math] has Parikh vector [math]\displaystyle{ u_i }[/math].
The first part is less easy. The following proof is credited to Goldstine.[5]
First we need a small strengthening of the pumping lemma for context-free languages:
Lemma — If [math]\displaystyle{ L }[/math] is generated by a Chomsky normal form grammar, then [math]\displaystyle{ \exists N \geq 1 }[/math], such that
For any [math]\displaystyle{ k \geq 1 }[/math], and for any [math]\displaystyle{ w \in L }[/math] with [math]\displaystyle{ |w| \geq N^k }[/math], there exists a way to split [math]\displaystyle{ w }[/math] into segments [math]\displaystyle{ ux_1\cdots x_kzy_k\cdots y_1v }[/math], and a nonterminal symbol [math]\displaystyle{ A }[/math], such that
[math]\displaystyle{ |x_iy_i|\geq 1 }[/math] for all [math]\displaystyle{ i }[/math], and [math]\displaystyle{ |x_1\cdots x_kzy_k\cdots y_1| \leq N^k }[/math]
[math]\displaystyle{ S \Rightarrow^* uAv\quad A \Rightarrow^* z\quad \forall i, A \Rightarrow^* x_iAy_i }[/math]
The proof is essentially the same as the standard pumping lemma: use the pigeonhole principle to find [math]\displaystyle{ k }[/math] copies of some nonterminal symbol [math]\displaystyle{ A }[/math] in the longest path in the shortest derivation tree.
First, construct a Chomsky normal form grammar for [math]\displaystyle{ L }[/math].
For each finite nonempty subset of nonterminals [math]\displaystyle{ U }[/math], define [math]\displaystyle{ L_U }[/math] to be the set of sentences in [math]\displaystyle{ L }[/math] such that there exists a derivation that uses every nonterminal in [math]\displaystyle{ U }[/math], no more and no less. It is clear that [math]\displaystyle{ L = \cup_U L_U }[/math], so it suffices to prove that each [math]\displaystyle{ p(L_U) }[/math] is a semilinear set.
Now fix some [math]\displaystyle{ U }[/math], and let [math]\displaystyle{ k = |U| }[/math]. We construct two finite sets [math]\displaystyle{ F, G }[/math], such that [math]\displaystyle{ p(L_U) = p(F\cdot G^*) }[/math], which is obviously semilinear.
- For notational clarity, write [math]\displaystyle{ \Rightarrow^*_U }[/math] to mean "there exists a derivation using no more (but possibly less) than nonterminals in [math]\displaystyle{ U }[/math]. With that, we define [math]\displaystyle{ F, G }[/math] as follows:
[math]\displaystyle{ F = \{w \in L_U: |w| \lt N^k\} }[/math] [math]\displaystyle{ G = \{xy: 1 \leq |xy| \leq N^k \text{ and there exists } A\in U \text{ such that } A \Rightarrow^*_U xAy\} }[/math]
To prove [math]\displaystyle{ p(L_U) \subset p(F\cdot G^*) }[/math], we induct on the length of [math]\displaystyle{ w\in L_U }[/math].
- If [math]\displaystyle{ |w| \lt N^k }[/math], then [math]\displaystyle{ w \in F }[/math], so [math]\displaystyle{ p(w) \in p(F\cdot G^*) }[/math]. Otherwise, by the strengthened pumping lemma, there exists a derivation of [math]\displaystyle{ w }[/math] using precisely the elements of [math]\displaystyle{ U }[/math], and is of the form
[math]\displaystyle{ S \underset{d_0}{\stackrel{*}{\Rightarrow}} u A v \underset{d_1}{\stackrel{*}{\Rightarrow}} u x_1 A y_1 v \underset{d_2}{\stackrel{*}{\Rightarrow}} \cdots \underset{d_{k}}{\stackrel{*}{\Rightarrow}} u x_1 \cdots x_k A y_k \cdots y_1 v \underset{d_{k+1}}{\stackrel{*}{\Rightarrow}} u x_1 \cdots x_k z y_k \cdots y_1 v }[/math]
- where [math]\displaystyle{ A\in U }[/math], [math]\displaystyle{ 1 \leq |x_iy_i| }[/math], and [math]\displaystyle{ |x_1 \cdots x_k z y_k \cdots y_1| \leq N^k }[/math].
- Since there are only [math]\displaystyle{ k-1 }[/math] elements in [math]\displaystyle{ U\setminus \{A\} }[/math], but there are [math]\displaystyle{ k }[/math] sub-derivations [math]\displaystyle{ d_1, ..., d_k }[/math] in the middle, we may delete one sub-derivation [math]\displaystyle{ d_i }[/math], and obtain a shorter [math]\displaystyle{ w' }[/math] that is still in [math]\displaystyle{ L_U }[/math], with
[math]\displaystyle{ p(w) = p(uzv) + p(x_1y_1) + \cdots + p(x_ky_k) = p(w') + p(x_iy_i) }[/math]
- By induction, [math]\displaystyle{ p(w') \in p(F\cdot G^*) }[/math], and by construction, [math]\displaystyle{ x_iy_i\in G }[/math], so [math]\displaystyle{ p(w)\in p(F\cdot G^*) }[/math].
To prove [math]\displaystyle{ p(L_U) \supset p(F\cdot G^*) }[/math], we induct on the length of [math]\displaystyle{ w\in F\cdot G^* }[/math].
- If [math]\displaystyle{ |w| \lt N^k }[/math] then by construction, [math]\displaystyle{ w\in F \subset L_U }[/math].
- Otherwise, [math]\displaystyle{ w = w'xy }[/math] for some [math]\displaystyle{ w'\in F\cdot G^* }[/math] and [math]\displaystyle{ xy\in G }[/math].
- By induction, [math]\displaystyle{ p(w') = p(w'') }[/math] for some [math]\displaystyle{ w''\in L_U }[/math]. By construction of [math]\displaystyle{ G }[/math], there exists some [math]\displaystyle{ A\in U }[/math] such that [math]\displaystyle{ A\Rightarrow^*_U xAy }[/math].
- By construction of [math]\displaystyle{ L_U }[/math], the symbol [math]\displaystyle{ A }[/math] appears in a derivation of [math]\displaystyle{ w'' }[/math] using exactly all of [math]\displaystyle{ U }[/math]. Then we can interpolate [math]\displaystyle{ A\Rightarrow^*_U xAy }[/math] into that derivation to obtain some [math]\displaystyle{ w'''\in L_U }[/math] such that
[math]\displaystyle{ p(w''') = p(w'') + p(xy) = p(w') + p(xy) = p(w) }[/math]
Strengthening for bounded languages
A language [math]\displaystyle{ L }[/math] is bounded if [math]\displaystyle{ L\subset w_1^*\ldots w_k^* }[/math] for some fixed words [math]\displaystyle{ w_1,\ldots, w_k }[/math]. Ginsburg and Spanier [6] gave a necessary and sufficient condition, similar to Parikh's theorem, for bounded languages.
Call a linear set stratified, if in its definition for each [math]\displaystyle{ i\ge 1 }[/math] the vector [math]\displaystyle{ u_i }[/math] has the property that it has at most two non-zero coordinates, and for each [math]\displaystyle{ i,j\ge 1 }[/math] if each of the vectors [math]\displaystyle{ u_i,u_j }[/math] has two non-zero coordinates, [math]\displaystyle{ i_1\lt i_2 }[/math] and [math]\displaystyle{ j_1\lt j_2 }[/math], respectively, then their order is not [math]\displaystyle{ i_1\lt j_1\lt i_2\lt j_2 }[/math]. A semi-linear set is stratified if it is a union of finitely many stratified linear subsets.
Ginsburg-Spanier — A bounded language [math]\displaystyle{ L }[/math] is context-free if and only if [math]\displaystyle{ \{(n_1,\ldots,n_k)\mid w_1^{n_1}\ldots w_k^{n_k}\in L\} }[/math] is a stratified semi-linear set.
Significance
The theorem has multiple interpretations. It shows that a context-free language over a singleton alphabet must be a regular language and that some context-free languages can only have ambiguous grammars[further explanation needed]. Such languages are called inherently ambiguous languages. From a formal grammar perspective, this means that some ambiguous context-free grammars cannot be converted to equivalent unambiguous context-free grammars.
References
- ↑ 1.0 1.1 Kozen, Dexter (1997). Automata and Computability. New York: Springer-Verlag. ISBN 3-540-78105-6.
- ↑ Håkan Lindqvist. "Parikh's theorem". Umeå Universitet. http://www8.cs.umu.se/kurser/TDBC92/VT06/final/3.pdf.
- ↑ Parikh, Rohit (1961). "Language Generating Devices". Quarterly Progress Report, Research Laboratory of Electronics, MIT.
- ↑ Parikh, Rohit (1966). "On Context-Free Languages". Journal of the Association for Computing Machinery 13 (4): 570–581. doi:10.1145/321356.321364. http://portal.acm.org/citation.cfm?id=321364&dl=.
- ↑ Goldstine, J. (1977-01-01). "A simplified proof of parikh's theorem" (in en). Discrete Mathematics 19 (3): 235–239. doi:10.1016/0012-365X(77)90103-0. ISSN 0012-365X. https://dx.doi.org/10.1016/0012-365X%2877%2990103-0.
- ↑ Ginsburg, Seymour; Spanier, Edwin H. (1966). "Presburger formulas, and languages". Pacific Journal of Mathematics 16 (2): 285–296. doi:10.2140/pjm.1966.16.285. https://projecteuclid.org/euclid.pjm/1102994974.
Original source: https://en.wikipedia.org/wiki/Parikh's theorem.
Read more |