This may sound like theoretically void question, because certainly permutation is expressible even on the lowest level of Chomsky hierarchy:

P -> a b c
  |  a c b
  |  b a c
  |  b c a
  |  c a b
  |  c b a

In practice, however, proposition that the only way to describe SQL syntax is permuting "where", "group by", "having" (and many more similar clauses in some SQL dialects) is silly.

Boolean grammars allow succinct expression for permutation

X -> a
   | b
   | c

Y -> 
   | X

P -> X X X & - Y a Y a Y & - Y b Y b Y & - Y c Y c Y

but perhaps there is a way to do it in the context free realm too?

  • $\begingroup$ For any finite language, if you just iterate over all the member you could express it as a regular language. The problem is with infinite languages, and this is where we need patterns and higher level in the Chomsky hierarchy. Is your question is how to express permutations of an infinite set of symbols in a context free grammar ? $\endgroup$ May 12 '11 at 23:03
  • $\begingroup$ Let scope it to finite set of symbols and require a grammar of the size proportional (or growing moderately) with the number of terminals. $\endgroup$ May 12 '11 at 23:23
  • $\begingroup$ The complement is easily expressed as e.g. $S \rightarrow AaAaA, A \rightarrow aA | \epsilon$ for all $a \in \Sigma$. $\endgroup$
    – Raphael
    May 13 '11 at 13:27
  • $\begingroup$ @Raphael: The complement should also include all "subpermutations". In particular, we could intersect it with the regular language $(A \setminus a)^{|A|-1}$ to get all permutations on $A \setminus a$, along with some "extras". $\endgroup$ May 13 '11 at 17:57
  • $\begingroup$ Yuval, I intended to build the complement of $\{ w_1\dots w_n \in \Sigma^* \mid i \neq j \leadsto w_i \neq w_j\}$, that is I considered the set of all permutations to include all permutations of subsets of the alphabet. $\endgroup$
    – Raphael
    May 13 '11 at 19:58

Using the method in this answer one can show that the smallest context-free grammar for all permutation of $n$ symbols has exponential size in $n$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.