# How to prove that these two languages are regular, or not regular? [duplicate]

I have these two languages

$L_1={\{a^n b^m,n≥m+5,m>0}\}$ Where $∑=(a,b)$

$L_2={\{a^n b^m,n≥m+5,m≤5}\}$ Where $∑=(a,b)$

As you can see that there is only one difference, the condition of m is different.

My question is to determine whether these two languages are regular or not, and to prove it.

If one or both these languages are non-regular. then how can we prove that using pumping lemma?

These two languages have so many conditions, I am just confused that how to solve these kind of Languages.

## marked as duplicate by Luke Mathieson, David Richerby, D.W.♦, Wandering Logic, Nicholas MancusoApr 8 '15 at 17:36

• @LukeMathieson Not duplicate, I am asking about these two languages, these languages has so many diff conditions. So Im just confused about these conditions. – Aniq Mar 28 '15 at 13:29
• Hint: one is simpler, because you need only ten fingers to recognize a string ... meaning you need to count only up to ten. The other one requires being able to count beyond ten. – babou Mar 28 '15 at 13:32
• @babou I need to prove using Pumping lemma, I'm always confused about how to take w? Like in a^n b^n we took a^p b^p, but in this case conditions are different. – Aniq Mar 28 '15 at 14:56
• When I am telling you one of the languages is simpler, I mean that it may be regular, while the other is not. To prove it is regular, you have to provide a NFA or a regular grammar for it (or use closure properties If the other is not regular, you can prove it with the pumping lemma. Have you tried to look at other proofs using the pumping lemma. There are many on this site, including the reference given by @LukeMathieson.. Regarding w, you have to try all permitted way and show none works. However, there is a twist in your case. – babou Mar 28 '15 at 15:29
• Cross-posted on SO: stackoverflow.com/q/29316512/781723. Please don't cross-post on multiple SE sites; it violates site rules and is impolite to answerers (by fragmenting responses). – D.W. Mar 29 '15 at 20:26

For problems like this, where there are several constraints, it can be helpful to deal with the constraints separately. In this problem, look at what the languages can be for each value of $m$ and recognize that the original language can be expressed as the union of the languages for each value of $m$.

Consider first your $L_2$. For each $0<m\le 5$, consider the languages $$A_m=\{a^nb^m\mid n\ge m+5\}$$ So $A_0=\{a^n\mid n\ge 5\}$, $A_1=\{a^nb\mid n\ge 6\}$, and so on. It's easy to see that each $A_m$ is regular. It's also easy to see that $$L_2=A_0\cup A_1\cup A_2\cup A_3\cup A_4\cup A_5$$ and since $L_2$ is the finite union of regular languages, it must be regular, as @babou implied.

For $L_1$ we can do the same thing, expressing $$L_1=\bigcup_{m=1}^\infty A_m$$ but that doesn't seem to be of much help, since the infinite union of regular languages isn't necessarily regular. We thus guess that $L_1$ is not regular, so we'll try to use the Pumping Lemma to prove that it isn't.

Let $L_1=a^{p+5}b^p$ where $p$ is the integer of the pumping lemma. Them we can express $L_1=xyz$ with $|y|>0$ and $|xy|\le p$. This means that $y=a^k$ for some $1\le k\le p$. Now pump down: $xy^0z=a^{p+5-k}b^p$ and since $n=p+5-k<p+5=m+5$ the string $xy^0z\notin L_1$ which is the contradiction we need, so $L_1$ isn't regular.

Hints:

One of the two languages is not regular. It is the one that forces you to count beyond 10 to decide whether some strings are in the language. Regular languages are not very good at counting without bound.

However, the use of the pumping lemma to prove it requires that you start from a string in the language where $n$ is as close to $m$ as permitted by the definition of the language, and that you pump out rather than in, i.e. remove the only $w$ of the $xwy$ decomposition of the string, rather than inserting more copies of $w$.

Alternatively, you can prove that the reverse of the language is not regular, if you know about closure properties.

• Drat. You posted your answer while I was composing mine. Ah well. – Rick Decker Mar 28 '15 at 16:12
• I wish I could select two best answers :( – Aniq Mar 28 '15 at 16:31
• @RickDecker that happens frequently. The worse is when you work 2 hours on an answer to an off-beat question, and it gets closed down just before you save. You do not even get to post it. That is why I refuse to vote on closing. – babou Mar 28 '15 at 16:33
• @Aniq Do not worry about that. The right way to say thank you is to work carefully on it so that you learn and can do it on your own nest time. Especially, this use of the pumping lemma has some more subtle sides worth understanding well. – babou Mar 28 '15 at 16:38
• @babou (off-topic but on-comment) In case of long answers I always compose a short one first, and then add details. – Hendrik Jan Mar 28 '15 at 22:37