context-free-grammarcomputation-theorypushdown-automatoncontext-free-languageautomata-theory

Is the given language a valid CFG?


Language, L = { a^n b^n a^n ; n=1,2,3,.. }

I want to check whether the given language L is context free or not.

CFG make use of PDA which uses stacks. So, first store each 'a' to the stack. Then pop twice for each occurrence of 'b'. Is this logic correct?


Solution

  • This language can be shown not to be context-free using the pumping lemma for context-free languages. The proof is by contradiction. Suppose the language is context-free. Then words of length at least p in the language can be written as uvxyz with |vxy| <= p, |vy| > 0 and where u(v^n)x(y^n)z is in the language for all integers n. Choose the string a^p b^p a^p in the language. There are five cases to consider:

    1. vxy consists only of a's from the first part. Pumping up or down breaks the requirement that the number of a's in the first part equal the number of b's in the second part.

    2. vxy consists only of a's and b's from the first two parts. Pumping might keep the requirement that the number of a's in the first part equal the number of b's in the second, but it will certainly break the requirement that the numbers of a's in the first and third sections be the same.

    3. vxy consists only of b's from the second section. Pumping fails for the same reason as in case 1.

    4. vxy consists of a's and b's from the second and third parts. Pumping fails for a reason similar to that given in the second case.

    5. vxy consists only of a's from the third section. Pumping fails for a similar reason to that given in the first case.

    So, there is no way to rewrite our string a^n b^n a^n so that it can be written uvxyz and satisfy the pumping lemma's requirements. This is a contradiction, so the language cannot have been regular.