Regular or context-free or other - regular-language

I have a problem that needs to find out the following language is regular or context-free or other.
{a^(2i+3j) | i>0, j>0}
I have some doubts to say it is a regular or context-free language because it has no pattern.

The strings in the language are the following:
a^5 = aaaaa is in the language, choosing i = j = 1
a^7 = aaaaaaa is in the language, choosing i = 2, j = 1
a^8 = aaaaaaaa is in the language, choosing i = 1 and j = 2
a^k is in the language for all k > 8
assume k is even. then choose j = 2 and choose i = (k - 6) / 2
assume k is odd. then choose j = 1 and choose i = (k - 3) / 2
The only strings not in the language are the following:
L' = {e, a, aa, aaa, aaaa, aaaaaa}
The complement of our language is finite, thus regular; and by closure properties we know our language must be regular, since the complement of a regular language is regular.

We can solve this by constructing the automata. Doing this with a non-deterministic automata is easier, so that will be a more general solution.
NFA
Non-deterministic finite automata are equivalent to DFAs and regular languages.
To construct such automata, you simply concatenate an automata that has to see an even,non zero number of as to an automata that has to see a multiply of 3 times number of as, keeping only the last step of the latter as accepting.
Basically, the non-determinism of moving between those 2 automatas (and staying at the first one) is checking whether the number of as can be expressed as 2i+3j.
Specific solution
A more specific solution, would use the fact that the gcd(2,3)=1, which means that there's some N=6 so that for any n>N this automata will accept.
We also note that we can accept n=5. We can now construct a DFA that after getting 6 as has a "sink" state that accepts.

Related

Is (0*1*)* equal to (0 | 1)*?

Are the regular expressions (0*1*)* and (0 | 1)* the same?
Could someone provide a proof or intuitive disproof for that? I feel like it is true but I’m struggling to write a step by step proof.
Two different regular expressions or two grammars can generate the same languages as these do but the regular expressions or grammars are not the same. There is a standard method of constructing a non-deterministic finite state automaton from a regular expression and from that constructing a deterministic finite state automaton. That method will produce two different automata for the regular expressions in question. Though each one will recognize the same strings, they will go through different states in doing so.
The regular expressions are equivalent.
I don't have a fully rigorous proof, but hand-waving follows.
Let R1 = (0*1*)* and R2 = (0 | 1)*. These are both regular expressions over the alphabet A = {0, 1}.
Part 1:
0 | 1 is the set {0, 1}. 0 is an element of 0*1* (because 0 ∈ 0* and ɛ ∈ 1* and 0 ∘ ɛ = 0) and so is 1.
Thus 0 | 1 is a subset of 0*1*, which means (0 | 1)* is a subset of (0*1*)*, i.e. R2 ⊆ R1.
Part 2:
R2 covers all possible words over the alphabet A. That is, every string containing only the characters 0 and 1 is in R2. (This seems obvious to me; a proof probably involves the definition of * and/or induction.)
Therefore R1 ⊆ R2.
By combining part 1 and part 2 we get R1 = R2.

If the string of L consists of 0's only prove that L* is regular

A question 4.2.10 from Introduction to Automata Theory by Hopcroft and Ullman. The original language L can also be non-regular.
Let's say we got a function of 0^(2^n+5), n>=0, how would you prove that (0^(2^n+5))* is regular? And also for the more general case, when f(0) can be any function?
Suppose that L contains two strings 0^n and 0^m and that n and m share no common factors: they are relatively prime. Then, by concatenating some number of instances of 0^n with some number of instances of 0^m, any string of length (n - 1)(m - 1) can be formed. Since L* must therefore exclude only a finite number of words, the complement (L*)' must be finite, hence regular; because regular languages are closed under complement, L* must be regular too.
Where did (n - 1)(m - 1) come from? Well, it's a special case (n = 2) of the coin problem for which we have a closed-form solution. You should be able to research this and find some proofs.
What about the case where all strings in L have lengths divisible by some GCD, say g? Well, the proof of regularity is quite similar; consider a modified alphabet where 0 is replaced by the symbol (0^g) and then prove the analogous language over this alphabet is regular as above. In other words, you can show that L* contains only strings divisible by g and all strings divisible by g of length at least (n/g - 1)(m/g - 1) where n and m have GCD g. The language is regular because it excludes only finitely many words whose lengths are divisible by g.

Proof a language is not regular using Pumping Lemma

I am trying to prove that the following language is not regular using the pumping lemma.
L = {ak b3l al | k ≥ 1 , l ≥ 0}
I have decided to choose w = a b3p ap, then |w| = 4p+1 ≥ p
Any tips?
Thank you!
I am not sure about the exact formulation of the pumping lemma that you are using. At any rate, this is a rather tricky case, because standard formulations like in wikipedia only let you pump somewhere in a prefix of fixed length. But your initial block of a allows pumping anywhere and can be arbitrarily long. Thus you have to use some additional property. I suggest two:
Regular languages are closed under reversal. Thus you may as well look at $L^R = {a^l b^{3l} a^k}$. Now any pumping in the initial block of a will lead out of the language.
Regular languages are closed under intersection. If you take the intersection with a b+ a+ you end up with ${a b^{3l} a^k}$, and now pumping in the b block will take you out of the language.

Pumping lemma for regular language

I have a little confusion in checking whether the given language is regular or not using pumping lemma.
Suppose we have to check whether:
L. The language accepting even number of 0's in regular or not?
We know that it is regular because we can construct a DFA for L. But I want to prove this with pumping lemma.
Now suppose, I take a String w= "0000":
Now will divide the string as x = 0, y = 0, and z = 00. Now on applying pumping lemma for i = 2, I will get the string "00000", which is not present in my language so by pumping lemma its prove that the language is not regular. But it is accepted by DFA ?
Any help will be greatly appreciated
Thank you
You are not completely clear about pumping lemma.
What pumping lemma say:
Formal definition: Pumping lemma for regular languages
Let L be a regular language. Then there exists an integer p ≥ 1 depending only on L such that every string w in L of length at least p (p is called the "pumping length") can be written as w = xyz (i.e., w can be divided into three substrings), satisfying the following conditions:
|y| ≥ 1
|xy| ≤ p
for all i ≥ 0, xyiz ∈ L
But what this statement says is that:
If a language is really a regular language then there must be some way to generate(pump) new strings from all sufficiently large strings.
Sufficiently large string means, a string in language that is of the length ≥ P.
So it may not be possible to generate new string from small strings even if language is Regular Language
Some way means, if language is really a regular and our choice of w is correct. Then there should be at lest one way to break w in three parts xyz such that by repeating(pumping) y for any number of times we can generate new strings in the language.
correct choice of w means: w in language and sufficiently large ≥ P
note: in second point, there may be a chance that even if you breaks w correctly into xyz according to formal definition still some new generated strings are not in language. As you did.
And in this situation you are to retry with some other possible choice of y.
In you chosen string w = "0000" you can break w such that y = 00. And with this choice of y you would always find a new generated string in in Language that is "even number of zeros"
One mistake you are doing in your proof that you are doing for a specific string 0000. You should proof for all w ≥ P. So still your proof is incomplete
Read my this answer IN CONTEXT OF PUMPING LEMMA FOR REGULAR LANGUAGES
In that answer, I have explained that breaking w into xyz and pumping y means finding looping part and repeating looping part to generate new strings in language.
When we proof that some language is regular; then actually we don't know where is the looping part so we try with all possible choices that satisfies pumping lemma's rule 1,2 & 3.
And Pumping lemma says that if language is regular and infinite them there must be a loop in the DFA and every sufficiently large string in language passes through looping part (according to pigeonhole principle) of DFA (and hence y can't be null. That's rule-1 in above formal definition).
Think, loop can be at initial position or at end and so x and z can be null strings.
But actually we don't know where loop falls in DFA so we try with all possible ways.
To proof a language is regular: You are to proof that for all sufficiently long strings(w) in language there is at-least one way(y) to generate new strings in the language by repeating looping part any number (i) of times.
To proof a language is not regular:You are to find at least one sufficiently long strings (w) in language such that there no choice for any way 'y' so that its possible to generate new strings with all possible repetition (i).
To proof using Pumping Lemma:
+-------------------------+--------------------------+----------------+--------------+
| | Sufficient large W in L | y | i >=0 |
+-------------------------+--------------------------+----------------+--------------+
| language is regular | For all W (all W can use | At-least one | For all i>=0 |
| | to generate new W' in L) | | |
+-------------------------+--------------------------+----------------+--------------+
| language is NOT regular | Find Any W (at-least 1 | With all (Show | At-least one |
| | W that can't generates | no possible Y | i |
| | new W' in L | exists) | |
+-------------------------+--------------------------+----------------+--------------+
CAUTION:: The Rule always not works to proof 'Weather a Language is Regular?'
Pumping Lemma necessary but not sufficient condition for a language to be regular. A language possible that satisfies these conditions may still be non-regular.
Reference
To proof a language is regular you have some necessary and sufficient conditions for a language to be regular.
Although the accepted answer is complete in its own way, I had to add a few things. I have a very playful way to exploit the pumping lemma to be able to prove that a given language is not a Regular language.
Just to have a context to talk about, let me state the lemma:
Pumping Lemma for Regular Languages:
For any regular language L, there exists an integer k.
Such that for all x ∈ L with |x| ≥ k, there exists u, v, w ∈ Σ∗, such
that x = uvw, and
(1) |uv| ≤ k
(2) |v| ≥ 1
(3) for all i ≥ 0: u(v^i)w ∈ L
The k is called the Pumping lemma constant. Let me come straight to the point and show you how to go about proving a language L is not regular.
Now to start the game you need two players here. One is the Reader(R) and the other is the Adversary(A).
Input: A language L
The Goal of R: Somehow prove the language L is not regular by some contradiction.
The Goal of A: Somehow be prepared enough to face the arguments of R and do not let him/her create a contradiction.
Now let us start the argument.
A: The language L is not Irregular because none could show the contradiction using pumping lemma with a certain pumping constant k. (Each language is mapped to only one integer k)
R: Let me assume what you say. If language L is regular then it must satisfy the conditions of the pumping lemma. So, let me choose a suitable string x ∈ L (|x| >= k), such that it helps me create a contradiction later.
A: Challenged by the R, A tries its best to find at least one suitable partitioning u, v and w of the string x, such that
x = uvw and |uv| <= k and |v| > 0
R: With any possible partition given by A, wins the the argument if able to show an integer i >= 0 such that
u(v^i)w ∉ L
Because now the R has shown that the Language L has at least one string x which doesn't have any partition(u, v, w) such that it satisfies the pumping lemma. The contradiction happened because our assumption that L is regular is FALSE. Therefore the language L is proven to be not regular.
If the R is not able to show the above, this is not a Proof of the language being Regular. It just means that L can be a Regular or Irregular language which just happens to satisfy the pumping lemma conditions.
Always remember, the pumping lemma is if(L is regular), then Statements. The vice-versa is not necessarily TRUE. Although it might be TRUE in some cases.
Therefore the pumping lemma is useful only if you want to prove that a language is not regular.
(Source: Theory of Computation(NPTEL): Prof. Somenath Biswas(IIT Kanpur)

Using Closure Properties to prove Regularity

Here's a homework problem:
Is L_4 Regular?
Let L_4 = L*, where L={0^i1^i | i>=1}.
I know L is non-regular and I know that Kleene Star is a closed operation, so my assumption is that L_4 is non-regular.
However my professor provided an example of the above in which L = {0^p | p is prime}, which he said was regular by proving that L* was equal to L(000* + e) by saying each was a subset of one another (e in this case means the empty word).
So his method involved forming a regex of 0^p, but how I can do that when I essentially have one already?
Regular languages are closed under Kleene star. That is, if language R is regular, so is R*.
But the reasoning doesn't work in the other direction: there are nonregular languages P for which P* is actually regular.
You mentioned one such P in your question: the set of strings 0^p where p is prime.
It is easy to use the pumping lemmas for regular and context-free languages to show that P is at least context-sensitive.
However, P* is equivalent to the language 0^q, where q is the sum of zero or more primes.
But this is true for q=0 (the empty string) and any q>=2, so P* can be recognized with a 3-state DFA, even though P itself is not regular.
So L being context-free has no bearing on whether your L_4 = L* is regular or not. If you can construct a DFA that recognizes L_4, as I did for P* above, then clearly it's regular.
In the process of trying to find a DFA that works, you'll probably see some pattern
emerge that can be used as the basis for a pumping argument. The Myhill-Nerode theorem is another approach to proving a language non-regular, and is useful if the language lends itself to analysis of prefixes and distinguishing extensions. If the language can be decomposed into a finite set of equivalence classes under a certain relation, then it can be recognized with a DFA containing that many states.
Edit: For anyone wondering whether OP's example L_4 is regular or not...it's not, which can be proved using the pumping lemma for regular languages.
Assume L_4 is regular, with "pumping length" P. Consider the string w=0P1P, which is an element of L_4. We need to decompose it into the form w=xyz,
with |y| >= 1 and |xy| <= P. Any choice of xy fulfilling these conditions will consist of all zeroes. But then any string w' = xynz with n != 1 will have mismatched counts of 0s and 1s, and therefore cannot be an element of L_4. So the pumping lemma does not hold, and L_4 cannot be regular.

Resources