Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm trying to construct a context-free grammar for the language $L = \{a^m!a^n : n > 0, m > 0, n > m\}$, but I'm not sure how to ensure that the right trail of $a$s is longer than the left one.

Is there a way I could include the left side in the right side using context-free grammar?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

We could look at the language as strings of the form $a^n!a^ka^n.$ Guided by this insight we could use the CFG with productions $S\rightarrow aSa\ |\ a!Ta,\quad T\rightarrow aT\ |\ a$. We're generating strings of the form $a^n\dots a^n$ and then finishing off by placing $!a^k$ in the middle. This idiom of "constructing the outside part and then finishing with the interior" is fairly common in CFG construction.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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