Inserting a regular language into other regular language - regular-language

Let L1 and L2 be the regular languages over the alphabet {a,b}. We define the language L3 as follows:
L3 = {pqr | pr ∈ L1, q ∈ L2}
L3 is obtained by inserting a string from L2 inside a string from L1. Is language L3 is still regular or not?
I am trying to solve this problem. Is it possible to prove this using string substitution property or homomorphism of regular language? Is there any better and easier way to prove this?

Here is a high-level description of a construction to show there is an NFA accepting L3.
Let M1 and M2 be minimal DFAs such that L(M1) = L1 and L(M2) = L2. Copy M1 so there are two copies, M1[1] and M1[2]. Copy M2 so there are |Q1| copies M2[1], M2[2], …, M2[|Q1|]. Also, number the states q1, q2, …, q|Q1| of M1. Now construct an NFA for M3 as follows:
From state qk of M1[1], add a lambda/epsilon transition to the initial state of M2[k]
From the accepting state(s) of M2[k], add lambda/epsilon transitions to state qk of M1[2]
The accepting states are the accepting states of M1[2]
The initial state is the initial state of M1[1].
This NFA reads some input and then nondeterministically jumps to an instance of M2. It then reads a string in M2 and jumps back to where it left off in the next copy of M1 where it can accept. This NFA has a number of states equal to 2|Q1| + |Q1| * |Q2|.

Related

Showing that the intersection of two language accepted by NFA is undecidable

I am having problem with this problem.
Let A = {〈N1, N2〉 | N1 and N2 are NFAs and L(N1) ∩ L(N2) =∅}. Show that A is decidable.
Any help is appreciated.
Given an input , here is an algorithm that determines whether L(N1) ∩ L(N2) =∅:
determinize N1 and N2 into D1 and D2 using the powerset construction. slow, but effective.
intersect D1 and D2 into M using the Cartesian product machine construction.
minimize M into M' using some DFA minimization algorithm
see whether M' has an accepting state. if so, halt-reject; otherwise, halt-accept.
This is an effectively computable procedure for determining inclusion and/or exclusion from the set, so the set is decidable.

how to convert a DFA to a regular expression?

I am reading the book: introduction to the theory of computation and got stuck on this example.
Convert a DFA to an equivalent expression by converting it first to a GNFA(generalized nondeterministic finite automaton) and then convert GNFA to a regular expression.
here is the example:
enter image description here
I should use this recursively to arrive at the the fourth state:
enter image description here
Unfortunately, I cannot understand what is going on from b to c? I only understand that we are trying to get rid of state 2, but how we arrive at c from b?
Thank you very much!
This can be quite tricky at first but I suggest you check definition 1.64 and see the function CONVERT(G) for more clearance. But as a brief explanation using the function for each possible neighbour state:
First from a to b, add a start state and a new accept state;
Afterwards you need to calculate each new path after qrip is removed, in this case state 1;
So, from start to q2, you get only label a from epsilon and a;
Same goes from start to q3, resulting only in b;
Now from q2 to q2 going trough qrip, you have label a to qrip and label a to get back, so you get (aa U b);
Same goes to q3 to q3 through qrip, so resulting in bb, notice that there is no loop in q3 so no union;
Now from q2 to q3 through qrip, you only need to concatenate a and b resulting in ab label;
Lastly the other way around, from q3 to q2 going through qrip, concatenate b and a resulting in ba but this time making the union with the previous path between q3 and q2;
Now choose a new qrip and proceed to do the same algorithm again.
Hope the explanation was clear enough, but as said before refer to the algorithm in the book for a better and more detailed explanation.
The two popular methods for converting a given DFA to its regular expression are-
Arden’s Method
State Elimination Method
Arden’s Theorem states that:
Let P and Q be two regular expressions over ∑.
To use Arden’s Theorem, the following conditions must be satisfied-
The transition diagram must not have any ∈ transitions.
There must be only a single initial state.
Step-01:
Form an equation for each state considering the transitions which come towards that state.
Add ‘∈’ in the equation of the initial state.
Step-02:
Bring the final state in the form R = Q + RP to get the required regular expression.
If P does not contain a null string ∈, then-
R = Q + RP has a unique solution i.e. R = QP*

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.

Prove that a language is regular

Given the regular languages L1 and L2, prove that the following language is also regular:
I know that U,*,. between 2 regular languages provides a regular language.
But, the following regular language is infinite so I don't really have an idea how to 'look' at it properly.
would love to get some assistance.
Superstar consists of concatenations of words such that
words on odd positions are taken from L1
words on even positions are taken from L2
L1 and L2 are regular languages
Then L1L2 is also a regular language, say L' := L1L2
Now L' = { w1w2 | w1 taken from L1 and w2 taken from L2 } and L' is regular
S -> epsilon | L'S | L1
is also a regular language, where epsilon is the zero-length empty word.
S will generate L'L'L'……L' and an optional L1 at the end, where L' = L1L2.
Your language is (L1L2)* U (L1L2)*L1.

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)

Resources