Parikh's theorem

From HandWiki
Revision as of 17:43, 6 February 2024 by NBrush (talk | contribs) (update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

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.

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. 1.0 1.1 Kozen, Dexter (1997). Automata and Computability. New York: Springer-Verlag. ISBN 3-540-78105-6. 
  2. Håkan Lindqvist. "Parikh's theorem". Umeå Universitet. http://www8.cs.umu.se/kurser/TDBC92/VT06/final/3.pdf. 
  3. Parikh, Rohit (1961). "Language Generating Devices". Quarterly Progress Report, Research Laboratory of Electronics, MIT. 
  4. 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=. 
  5. 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. 
  6. 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.