# Determine if a language is regular from the first sight

Is there a way to guess if a language is regular from the first sight? I.e. in order to choose proof methods, I have to have some hypothesis at first. Do you know any hints/patterns?

I need this to reduce time consumption: for instance, in order not to spend time on pumping lemma/Myhill–Nerode theorem, when in fact the language IS regular and I need to construct DFA/grammar.

The language is expressed as a set of all its words possible. For example:

$$L = \left\{ {(0)^{2n}(10)^{3k+1}1^m }, n, k, m ≥ 0 \right\}, \Sigma = \left\{{0,1}\right\}$$

• How about standard criteria like left-linear/right-linear grammar? Jan 19 '13 at 20:06
• To say how the first sight may help, can you tell how the language you talking about is expressed? By the way, there is also Computer Science.SE beta
– Ilya
Jan 19 '13 at 20:06
• Imagine that you’re reading a word one symbol at a time. How much do you have to remember as you go along in order to decide whether the word is in the language? Is that amount bounded, or can it be arbitrarily large (as with the language of words of the form $0^n1^n$, for instance). If it’s bounded, you have a regular language. If it appears not to be bounded, you probably don’t have a regular language, though the impression that it’s unbounded may of course have been wrong. Jan 19 '13 at 20:16
• Unlike the pumping lemma, Myhill-Nerode works in both directions: A language $L$ is regular if and only if the number of Myhill-Nerode equivalence classes is finite (the equivalence relation being $u \sim v$ iff for every $w$, the strings $uw$ and $vw$ are either both in $L$ or both not in $L$.)
– Ted
Jan 19 '13 at 20:50
• @Ilya, I added an example showing how the language is expressed in my case. Jan 19 '13 at 20:54

Easiest Round-off Trick!!!:

Step 1: Look at the exponents of the different alphabets.

Step 2: Is there any relation between the different exponents?

Step 3a: If there is NO relation between the exponents then the language is Regular and Context free. eg: L= $a^n b^m$ , m,n >=0

Step 3b: If there are relations between the exponents, for instance, $L=a^m b^n$, and the relation can be m>n or m!=n or m< n. You will need one counter here to keep a count, inrementing it by 1 for n times for a and compare with b by decrementing by 1 for n-times and you get a 0 for a match(assuming, m=n). These languages are Not Regular but context free and accepted by a PDA.

Step 4: If you have more than one relation or need more than one counter, for instance, $L= a^m b^n c^k$, m=n=k. Here, you need 2 such counters. First, count all a's and copy this count value to another counter. Then, compare with b by decrementing it n-times to get a 0. Again, decrementing the other counter n-times to compare it with c and accept the language if both the counters are 0. These languages are neither Regular nor Context Free but they are Context Sensitive and thus Recursive, although, all Recursive languages are not Context Sensitive

• Thank you for adding extra information about context-free languages. I needed it, too, although didn't ask it in my question. Feb 24 '14 at 9:35
• That helps me alot in my next exam , thank you! Jun 26 '17 at 15:26
• @Himanshu: Can you give an example explaining step 3b and/or 4.
– SRK
Oct 30 '17 at 10:51

Imagine that you’re reading a word one symbol at a time. How much do you have to remember as you go along in order to decide whether the word is in the language? Is that amount bounded, or can it be arbitrarily large (as with the language of words of the form $0^n1^n$, for instance). If it’s bounded, you have a regular language. If it appears not to be bounded, you probably don’t have a regular language, though the impression that it’s unbounded may of course have been wrong.

• Very good answer, thanks a lot! Unfortunately I can't mark all the answers as accepted, otherwise I would have done that here too. Jan 19 '13 at 21:13
• @Umari: You're welcome. Jan 19 '13 at 21:16
• Who is @umari ? Dec 9 '14 at 11:30
• @Atul: Evidently an earlier screen name of the person now posting as petajamaja. Dec 9 '14 at 11:33

One simple criterion that works in many cases is that if you see only linear functions in the exponents (like $2n$, $3k+1$, $m$ in your formula), and no variable appears more than once in the exponents, then the language is regular. This is because a language like $\{ 0^{2n} : n \ge 0\}$ corresponds to the regular expression $(00)^*$. A rigorous proof of this rule (which also needs to be stated more precisely before it can be proved) uses closure properties of regular languages, which you should also know.

The rules of a regular grammar are in the form :-

For Right regular form:- For Left regular form:-

(Terminal)->epsilon or (non-terminal)        |  (Terminal)->epsilon or (non-terminal)

(Terminal)->(non-terminal)(Terminal)         |  (Terminal)->(Terminal)(non-terminal)

A->phi                       |  A->phi
A->aA'|aA                    |  A->A'a|Aa
A'->a                        |  A->a