# Finding whether the language is CFL or regular

$L = (0^i 1)^n$ where i=1,2,3,4...n and n>=0

For eg :- 00010001 doesn't belong to the language as n=2 but i=3 at the beginning.

001001001 belongs to L as n=3 and i=2 in all cases.

I know the above language is not regular for sure as value of 'i' depends on value of 'n' and it requires comparison. So DFA not possible.

Now I am not sure to which class of language does the above language belong because to check number of zeroes or 'i', we need value of 'n' which can be found out only after reading the entire string.

• To check whether a language is context-free or not, try simultaneously to construct a context-free grammar for it, and to use the pumping lemma or closure properties to prove that it isn't. – Yuval Filmus Dec 9 '17 at 14:58
• It's not super clear what $L$ is – try harder explaining it. – Yuval Filmus Dec 9 '17 at 14:58
• For example, it's not clear whether it has to be the same number of zeroes $i$ in all $n$ copies. – Yuval Filmus Dec 9 '17 at 15:42
• You should update your post accordingly. The notation $w^n$ means $n$ concatenated copies of $w$. – Yuval Filmus Dec 9 '17 at 16:38
• @YuvalFilmus Oh, yes, sorry for that. Yes, number of i's should be same in all concatenated copies. I don't know what I was thinking. – Zephyr Dec 9 '17 at 16:42

Suppose there exists a CFG whose language is $L$, and let $k$ be the pumping length. Consider the string $(0^k1)^k \in L$. Then, by pumping lemma, there exists a decomposition $(0^k1)^k = uvwxy$ where $|vwx| \leq k$, $vx \neq \varepsilon$, and for each $i \geq 0$, $uv^iwx^iy \in L$. Since $|vx| \leq |vwx| \leq k$, there are four types of values of $vx$: either $vx \in 0^+$, $vx \in 0^+1$, $vx \in 10^+$, or $vx \in 0^+10^+$. Try showing that in each of these cases, pumping $vx$ gives a string not in $L$, thus giving a contradiction and demonstrating that $L$ is not context-free.
• That's not something I'm familiar with, but at a glance, I think it is likely, since deciding whether a string is in $L$ is straightforward. Feel free to ask it as a separate question. – theyaoster Dec 11 '17 at 7:12
• @Brian Yao, Suppose I take a string 001 001 which belongs to the language. I can take $v$ = 001 and $x$=001. Now if I pump $v$ and $x$ for $i$ times, all of those strings belong to the language . So why is it not CFL ? – Rajesh R Jan 18 '18 at 15:08
• Similarly for other strings (infact all) like 0001 0001 0001, we can have $u$ = $\epsilon$, $v$ = 0001, $w$=$\epsilon$, $x$ = 0001 $y$=$\epsilon$. We can again pump all strings belonging to L with the above $v$ and $x$. – Rajesh R Jan 18 '18 at 15:13
• While those strings can be pumped, the one that I provided cannot. Showing this one string cannot be pumped is sufficient to prove that the language is not a CFL. The argument uses the pumping length $k$; since $|vwx| \leq k$, it must be the case that $|v| \leq k$ and $|x| \leq k$. Thus, since $|0^k1| = k + 1 > k$, $v$ and $x$ cannot be equal to $0^k1$. – theyaoster Jan 18 '18 at 18:51