If the langages L1,...,Ln are regular, is the union of them regular too?
We know that the union of two regular languages is a regular language. How to prove that the union of many regular languages also is regular?
You can use induction. Here's a very very rusty sketch of the proof.
Given -
Union of two regular languages is regular.
Let f(n) be a function representing the union of n regular languages.
Question
Is f(n) a regular language?
Base Case -
if n = 1, then the union of a single regular language is regular.
if n = 2, then, by the given hypothesis, we know that f(2) is regular.
Inductive Hypothesis-
Assume for all n <= k that f(n) is regular.
Inductive Step -
Let n = k+1. We know by the inductive hypothesis that f(k) is a regular language. So . . .
f(n) = f(k+1) = Lk+1 U f(k)
Where Lk+1 is the k+1st regular language. Since f(k) and Lk+1 are regular, then f(n) = f(k+1) is regular by the given hypothesis.
QED
For More on Inductive Proofs
Wiki - http://en.wikipedia.org/wiki/Mathematical_induction
Khan Academy - https://www.khanacademy.org/math/precalculus/seq_induction/proof_by_induction/v/proof-by-induction
Related
I was trying to understand why n + k patterns were banned in Haskell. A famous post on StackOverflow gives an example of a function as follows:
f 0 = 0
f (n + 5) = 5
Haskell shows an error while matching f 1, f 2, f 3, f 4.
I cannot understand why (-1) cannot be matched with n. Firstly, I thought that integers only contain non-negative literals (0,1,..), but Haskell's definition of Int type includes negative literals.
Why can't -1 be matched? That's simply how n+k patterns were defined, presumably because it seemed like a good idea at the time. It's natural to use induction for natural numbers, so why not define our cool n+k patterns to work for naturals? From the Haskell report:
Matching an n+k pattern (where n is a variable and k is a positive integer literal) against a value v succeeds if x >= k, resulting in the binding of n to x - k, and fails otherwise. Again, the functions >= and - are overloaded, depending on the type of the pattern. The match diverges if the comparison diverges.
The fact that you found this surprising is probably one reason why n+k patterns were removed. Another is that there's no need for them: you can easily translate any n+k pattern into a pattern not using this feature.
My Argument/Answer is if y is aregular set then there exits a DFA which accepts y. In the L1 there is a condition that y=x^n, that x will belong to L1,as y is accepted by DFA. So is x^n and so is x so L1 is regular. Now L2 --> here the condition is x=y^n. Here y is accepted by DFA so is y^n so which is equal to x so x can be accepted by DFA. This makes both L1,L2 regular
Is my argument right?
This question seems like it's poorly-posed. For example, if we take A = {a}, then L1 is the language {a} and L2 is the language a*, both of which are regular. If we pick A = a*b, then L1 = a *b (which is regular) and L2 = { (anb)m | m, n ≥ 0 }, which is not regular (using the pumping lemma). In other words, the answer depends on the choice of A.
This is weird but by pumping lemma, say
Let L be a regular language. There exists a constant n such that for every string w in L such that |w| >= n, we can break w in to xyz such that xy*z is also in L.
This lemma is strong because it argues for all regular languages. But what if the regular language L = a? There is only one word (a) in it. How the pumping lemma works for this case?
If n = 2 then it is vacuously true that any w in L with |w| >= n satisfies the conclusion of the pumping lemma. No words in L are long enough to serve as counterexamples. More generally, if L is any finite language then L satisfies the pumping lemma: just take n to be greater than the length of the longest word in L.
Given an alphabet of {a, b} where Na denotes the number of occurrences of a, and Nb the number of occurrences of b:
L1 = {xy | Na(x) = Nb(y)}
L2 = {w | Na(w) and Nb(w) are even number}
Wouldn't a single DFA with four states and using mod be able to accept both languages?
No, because both languages are different so you can't draw single DFA for both languages.
An automaton uniquely defined a language, but yes of-course for a language more than one automata are possible called 'equivalent automata'.
Language L1 = A = {xy | Na(x) = Nb(y)} is a regular language. Regular expression for this language is:
(a + b)*a(a + b)*b(a + b)* + ^
To understand this language and regular expression read: "Show that the following set over {a, b} is regular".
Language L2 = A = {w | Na(w) and Nb(w) are even number} is also a regular language. Regular expression for this language is:
((a + b(aa)*ab)(bb)*(ba(aa)*ab(bb)*)*a + (b + a(bb)*ba)(aa)*(ab(bb)*ba(aa)*)*b)*
To understand this language and regular expression read: "Need Regular Expression for Finite Automata".
But both languages are not equal because there are some strings in language L1 those are not belongs to language L2 e.g. ab is a string in L1 but doesn't not consist of even number of a and b hence doesn't belongs to language L2.
Note: Language L2 is either not a subset of language L1, because in L2 a strings of even length and single symbol is possible like aa, aaaa, bb, bbbb but these strings are not member in L1.
Both languages are different hence single DFA is not possible for both languages.
Both the languages L1 = {xy | Na(x) = Nb(y)} and
L2 = {w | Na(w) and Nb(w) are even number}are different so we cannot draw a single DFA for both languages.
For Language L1 :
A = {xy | Na(x) = Nb(y)} is a regular language.
Regular expression for this language is:
(a + b)*a(a + b)b(a + b)
Language L2 :
A = {w | Na(w) and Nb(w) are even number} is also a regular language. Regular expression for this language is:
((a + b(aa)ab)(bb)(ba(aa)ab(bb))*a + (b + a(bb)ba)(aa)(ab(bb)ba(aa))b)
Both languages are not equal because there are some strings in language L1 which doesnt belong to language L2. ab is a string in L1 but doesn't not consist of even number of a and b hence doesn't belongs to language L2.
As Both languages are different,single DFA cannot be constructed that accepts both the languages.
I'm learning the difference between the lemmata in the question. Every reference I can find uses the example:
{(a^i)(b^j)(c^k)(d^l) : i = 0 or j = k = l}
to show the difference between the two. I can find an example using the regular lemma to "disprove" it.
Select w = uvxyz, s.t. |vy| > 0, |vxy| <= p.
Suppose w contains an equal number of b's, c's, d's.
I selected:
u,v,x = ε
y = (the string of a's)
z = (the rest of the string w)
Pumping y will just add to the number of a's, and if |b|=|c|=|d| at first, it still will now.
(Similar argument for if w has no a's. Then just pump whatever you want.)
My question is, how does Ogden's lemma change this strategy? What does "marking" do?
Thanks!
One important stumbling issue here is that "being able to pump" does not imply context free, rather "not being able to pump" shows it is not context free. Similarly, being grey does not imply you're an elephant, but being an elephant does imply you're grey...
Grammar context free => Pumping Lemma is definitely satisfied
Grammar not context free => Pumping Lemma *may* be satisfied
Pumping Lemma satisfied => Grammar *may* be context free
Pumping Lemma not satisfied => Grammar definitely not context free
# (we can write exactly the same for Ogden's Lemma)
# Here "=>" should be read as implies
That is to say, in order to demonstrate that a language is not context free we must show it fails(!) to satisfy one of these lemmata. (Even if it satisfies both we haven't proved it is context free.)
Below is a sketch proof that L = { a^i b^j c^k d^l where i = 0 or j = k = l} is not context free (although it satisfies The Pumping Lemma, it doesn't satisfy Ogden's Lemma):
Pumping lemma for context free grammars:
If a language L is context-free, then there exists some integer p ≥ 1 such that any string s in L with |s| ≥ p (where p is a pumping length) can be written as
s = uvxyz
with substrings u, v, x, y and z, such that:
1. |vxy| ≤ p,
2. |vy| ≥ 1, and
3. u v^n x y^n z is in L for every natural number n.
In our example:
For any s in L (with |s|>=p):
If s contains as then choose v=a, x=epsilon, y=epsilon (and we have no contradiction to the language being context-free).
If s contains no as (w=b^j c^k d^l and one of j, k or l is non-zero, since |s|>=1) then choose v=b (if j>0, v=c elif k>0, else v=c), x=epsilon, y=epsilon (and we have no contradiction to the language being context-free).
(So unfortunately: using the Pumping Lemma we are unable to prove anything about L!
Note: the above was essentially the argument you gave in the question.)
Ogden's Lemma:
If a language L is context-free, then there exists some number p > 0 (where p may or may not be a pumping length) such that for any string w of length at least p in L and every way of "marking" p or more of the positions in w, w can be written as
w = uxyzv
with strings u, x, y, z, and v such that:
1. xz has at least one marked position,
2. xyz has at most p marked positions, and
3. u x^n y z^n v is in L for every n ≥ 0.
Note: this marking is the key part of Ogden's Lemma, it says: "not only can every element be "pumped", but it can be pumped using any p marked positions".
In our example:
Let w = a b^p c^p d^p and mark the positions of the bs (of which there are p, so w satisfies the requirements of Ogden's Lemma), and let u,x,y,z,v be a decomposition satisfying the conditions from Ogden's lemma (z=uxyzv).
If x or z contain multiple symbols, then u x^2 y z^2 w is not in L, because there will be symbols in the wrong order (consider (bc)^2 = bcbc).
Either x or z must contain a b (by Lemma condition 1.)
This leaves us with five cases to check (for i,j>0):
x=epsilon, z=b^i
x=a, z=b^i
x=b^i, z=c^j
x=b^i, z=d^j
x=b^i, z=epsilon
in every case (by comparing the number of bs, cs and ds) we can see that u x^2 v y^2 z is not in L (and we have a contradiction (!) to the language being context-free, that is, we've proved that L is not context free).
.
To summarise, L is not context-free, but this cannot be demonstrated using The Pumping Lemma (but can by Ogden's Lemma) and thus we can say that:
Ogden's lemma is a second, stronger pumping lemma for context-free languages.
I'm not too sure about how to use Ogden's lemma here but your "proof" is wrong. When using the pumping lemma to prove that a language is not context free you cannot choose the splitting into uvxyz. The splitting is chosen "for you" and you have to show that the lemma is not fulfilled for any uvxyz.