How would you prove that the following language is not context-free?
$$ L= \{a^n b^m |\, gcd(n,m)=1 \}$$
I suspect the solution uses the pumping lemma, but I'm not sure how to apply it.
How would you prove that the following language is not context-free?
$$ L= \{a^n b^m |\, gcd(n,m)=1 \}$$
I suspect the solution uses the pumping lemma, but I'm not sure how to apply it.
Let $p$ be the pumping length guaranteed by the pumping lemma (for context free languages). Then we choose $m \neq n$ such that $m,n \geq p$ and are both prime. Then clearly $s = a^{n}b^{m} \in L$.
By the pumping lemma we can divide $s$ such that $s=uvxyz$ and
For this language we get three similar cases, and one trivial case. The trivial case is where either $v$ or $y$ contains both $a$'s and $b$'s, in which case $s'$ doesn't have the correct ordering, and thus $s'\notin L$.
The nontrivial cases:
Thus there is at least one string in $L$ that cannot be divided as per the pumping lemma and still have all pumping results remain in $L$. Therefore $L$ is not context free. $Q.E.D$
Some additional notes: of course there is an infinite number of strings which can't be pumped, and it's not actually necessary for $m$ and $n$ to be prime, it just simplifies that argument, as we don't have to fiddle around with a prime decomposition - though if you did want to, you just pick one of the prime factors and do the same (or even all of them if you want).
Trick: A language is not Context free language if it has same Comaprision more then one times For Instance :L = {a^nb^c^n|n>0} as you know this is not context free why:? as you can see number of b shuld be same as the number of a "This is first Comarision" and after that again number of c shuld be same of the number of b or number of previous a.Here 2 stack is needed to remember for equal number of occurance of a and b.so this is not "pda" because you know pda has only one stack...
Another Beautifull Example: L={a^nb^na^mb^m|m,n >0} Tell me weather this language is CFL or not.
Again Here Look for number of Comparision between same Entity: Here Number of b shuld be same as number of a...In case of a^nb^n...
Here only one comarision between "n" now move to the a^mb^m Again here number of b depend up on number of a, where number of doesn't depend on any one so between a and b for power m only one comparision is going on that's why it is L={a^nb^na^mb^m|m,n >0}
is CFL
Ex: L = {a^nb^ma^nb^m | m>n>0} Tell me weather It's CFL or not By seeing number of comaprision Answer: Yes This is CFL
Now Lets move to your Questions:
L= {a^n,b^m | gcd(n,m)=1}
Here we are restricted to choose value of n and m...so that it's gcd always come 1.... Find Comarision Here:
What Will be the value of m,n ???
It's depend upon condition that whenever you will choose value of m, or n it shuld be either > and equal to m in case of value selection for m or same for value selection for m (This is first comarision between m and n or reverse for selecting value) Now think
Another comaprision : GCD of m, n shuld be 1 (This is another comarision for m, n) so here two comarision is present show it is not CFL.
And Acrding to pumping Lemma Theorem:
1)Select any string belongs to L
2)devide it in xYz part make sure that Y shuld not have o length.
3)Take any value of "i" acrding to your wish.
4)make x(Y)^iz and check weather it's belong to L if not then it will prove that it is not regular. i>and equal to 1.
Think: Can you construct a PDA For this, Condition you have one one Stack...Defenately You will come to conclusion ...If you still didn't get my point I will write more for you....