Parikh's theorem

From The Right Wiki
Jump to navigationJump to search

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 Σ={a1,a2,,ak} be an alphabet. The Parikh vector of a word is defined as the function p:Σ*k, given by[1] p(w)=(|w|a1,|w|a2,,|w|ak) where |w|ai denotes the number of occurrences of the symbol ai in the word w. A subset of k is said to be linear if it is of the form u0+u1++um={u0+t1u1++tmumt1,,tm} for some vectors u0,,um. A subset of k is said to be semi-linear if it is a union of finitely many linear subsets.

Theorem — Let L be a context-free language or a regular language, let P(L) be the set of Parikh vectors of words in L, that is, P(L)={p(w)wL}. Then P(L) is a semi-linear set. If S is any semi-linear set, then there exists a regular language (which a fortiori is context-free) whose Parikh vectors is S.

In short, the image under p 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.

Proof

Given semi-linear set S, to construct a regular language whose set of Parikh vectors is S. S 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 S={u0+t1u1++tmumt1,,tm}, then it is the set of Parikh vectors of {z0}(i=1m{zi})*, where each zi has Parikh vector ui.

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 L is generated by a Chomsky normal form grammar, then N1, such that For any k1, and for any wL with |w|Nk, there exists a way to split w into segments ux1xkzyky1v, and a nonterminal symbol A, such that |xiyi|1 for all i, and |x1xkzyky1|Nk S*uAvA*zi,A*xiAyi

The proof is essentially the same as the standard pumping lemma: use the pigeonhole principle to find k copies of some nonterminal symbol A in the longest path in the shortest derivation tree. Now we prove the first part of Parikh's theorem, making use of the above lemma.

Proof

First, construct a Chomsky normal form grammar for L. For each finite nonempty subset of nonterminals U, define LU to be the set of sentences in L such that there exists a derivation that uses every nonterminal in U, no more and no less. It is clear that L=ULU, so it suffices to prove that each p(LU) is a semilinear set. Now fix some U, and let k=|U|. We construct two finite sets F,G, such that p(LU)=p(FG*), which is obviously semilinear.

For notational clarity, write U* to mean "there exists a derivation using no more (but possibly less) than nonterminals in U. With that, we define F,G as follows:

F={wLU:|w|<Nk} G={xy:1|xy|Nk and there exists AU such that AU*xAy} To prove p(LU)p(FG*), we induct on the length of wLU.

If |w|<Nk, then wF, so p(w)p(FG*). Otherwise, by the strengthened pumping lemma, there exists a derivation of w using precisely the elements of U, and is of the form

S*d0uAv*d1ux1Ay1v*d2*dkux1xkAyky1v*dk+1ux1xkzyky1v

where AU, 1|xiyi|, and |x1xkzyky1|Nk.
Since there are only k1 elements in U{A}, but there are k sub-derivations d1,...,dk in the middle, we may delete one sub-derivation di, and obtain a shorter w that is still in LU, with

p(w)=p(uzv)+p(x1y1)++p(xkyk)=p(w)+p(xiyi)

By induction, p(w)p(FG*), and by construction, xiyiG, so p(w)p(FG*).

To prove p(LU)p(FG*), consider an element wFG*. We need to show that p(w)p(LU). We induct on the minimal number of factors from G that is needed to identify w as an element of FG*.

If no factor from G is needed, then wFLU.
Otherwise, w=wxy for some wFG* and xyG, where w requires less factors from G than w.
By induction, p(w)=p(w) for some wLU. By construction of G, there exists some AU such that AU*xAy.
By construction of LU, the symbol A appears in a derivation of w using exactly all of U. Then we can interpolate AU*xAy into that derivation to obtain some wLU such that

p(w)=p(w)+p(xy)=p(w)+p(xy)=p(w)

Strengthening for bounded languages

A language L is bounded if Lw1*wk* for some fixed words w1,,wk. 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 i1 the vector ui has the property that it has at most two non-zero coordinates, and for each i,j1 if each of the vectors ui,uj has two non-zero coordinates, i1<i2 and j1<j2, respectively, then their order is not i1<j1<i2<j2. A semi-linear set is stratified if it is a union of finitely many stratified linear subsets.

Ginsburg-Spanier — A bounded language L is context-free if and only if {(n1,,nk)w1n1wknkL} 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" (PDF). Umeå Universitet.
  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. S2CID 12263468.
  5. Goldstine, J. (1977-01-01). "A simplified proof of parikh's theorem". Discrete Mathematics. 19 (3): 235–239. doi:10.1016/0012-365X(77)90103-0. ISSN 0012-365X.
  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.