Parikh's theorem

In theoretical computer science, Parikh's theorem states 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. It is useful for deciding that strings with a given number of terminals are not accepted by a context-free grammar. It was first proved by Rohit Parikh in 1961 and republished in 1966.

Definitions and formal statement

Let Σ={a1,a2,…,ak} be an alphabet. The Parikh vector of a word w is defined as its image under the function p:Σ∗→ℕk, given by 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+⋯+tmum∣t1,…,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)∣w∈L}. 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+⋯+tmum∣t1,…,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.

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 ∃N≥1, such that the following is true.

For any k≥1, and for any w∈L with |w|≥Nk, given a derivation S⇒∗uAv of w from the axiom S, we can split w into segments w=ux1⋯xkzyk⋯y1v, and pick a nonterminal symbol A, such that we have:

|xiyi|≥1 for all i, and |x1⋯xkzyk⋯y1|≤Nk

and the derivation S⇒∗uAv can be split in the following (with the same parse tree, in particular using precisely the same nonterminals):

S⇒∗uAv∀i,A⇒∗xiAyiA⇒∗z

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(F⋅G∗), 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={w∈LU:|w|<Nk} G={xy:1≤|xy|≤Nk and there exists A∈U such that A⇒U∗xAy}

To prove p(LU)⊂p(F⋅G∗), we induct on the length of w∈LU.

If |w|<Nk, then w∈F, so p(w)∈p(F⋅G∗). Otherwise, since w∈LU, there is a derivation of w using precisely the elements of U. By the strengthened pumping lemma, this derivation can be rewritten to be of the form

S⇒∗d0uAv⇒∗d1ux1Ay1v⇒∗d2⋯⇒∗dkux1⋯xkAyk⋯y1v⇒∗dk+1ux1⋯xkzyk⋯y1v

where A∈U, 1≤|xiyi|, and |x1⋯xkzyk⋯y1|≤Nk.
Since there are only k−1 elements in U∖{A}, but there are k sub-derivations d1,...,dk in the middle, picking one witnessing subderivation to use each of the nonterminals in U∖{A}, we may delete one sub-derivation di and obtain a shorter w′ that still uses all the nonterminals of U, i.e., which is still in LU, with

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

By induction, p(w′)∈p(F⋅G∗), and by construction, xiyi∈G, so p(w)∈p(F⋅G∗).

To prove p(LU)⊃p(F⋅G∗), consider an element w∈F⋅G∗. 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 F⋅G∗.

If no factor from G is needed, then w∈F⊂LU.
Otherwise, w=w′xy for some w′∈F⋅G∗ and xy∈G, where w′ requires less factors from G than w.
By induction, p(w′)=p(w″) for some w″∈LU. By construction of G, there exists some A∈U such that A⇒U∗xAy.
By construction of LU, the symbol A appears in a derivation of w″ using exactly all of U. Then we can interpolate A⇒U∗xAy into that derivation to obtain some w‴∈LU such that

p(w‴)=p(w″)+p(xy)=p(w′)+p(xy)=p(w)

Strengthening for bounded languages

A language L is bounded if L⊂w1∗…wk∗ for some fixed words w1,…,wk. Ginsburg and Spanier 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 i≥1 the vector ui has the property that it has at most two non-zero coordinates, and for each i,j≥1 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)∣w1n1…wknk∈L} 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 2 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.