# compact context free expression for permutation

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?

• 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 ? – M. Alaggan May 12 '11 at 23:03
• Let scope it to finite set of symbols and require a grammar of the size proportional (or growing moderately) with the number of terminals. – Tegiri Nenashi May 12 '11 at 23:23
• The complement is easily expressed as e.g. $S \rightarrow AaAaA, A \rightarrow aA | \epsilon$ for all $a \in \Sigma$. – Raphael May 13 '11 at 13:27
• @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". – Yuval Filmus May 13 '11 at 17:57
• 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. – 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$.