Will L = {a*b*} be classified as a regular language?
I am confused because I know that L = {a^n b^n} is not regular. What difference does the kleene star make?
Well it is makes difference when you have a L = {a^n b^n} and a L = {a*b*}.
When you have a a^n b^n language it is a language where you must have the same number of a's and b's example:{aaabbb, ab, aabb, etc}. As you said this is not a regular expression.
But when we talk about L = {a*b*} it is a bit different here you can have any number of a followed by any numbers of b (including 0). Some example are:
{a, b, aaab, aabbb, aabbbb, etc}
As you can see it is different from the {a^n b^n} language where you needed to have the same numbers of a's and b's.
And yes a*b* is regular by its nature. If you want a good explanation why it is regular you can check this How to prove a language is regular they might have a better explanation then me (:
I hope it helped you
The language described by the regular expression ab is regular by definition. These expressions cannot describe any non-regular language and are indeed one of the ways of defining the regular languages.
{a^n b^n: n>0} (this would be a formally complete way of describing it) on the other hand, cannot be described by a regular expression. Intuitively, when reaching the border between a and b you need to remember n. Since it is not bounded, no finite-memory device can do that. In ab you only need to remember that from now on only b should appear; this is very finite. The two stars in some sense are not related; each expands its block independently of the other.
Related
This is a grammar and I wan to check if this language is regular or not.
L → ε | aLcLc | LL
For example the result of this grammar is:
acc, accacc ..., aacccc, acaccc, accacc, aaacccccc, ...
I know that is not a regular language but how to prove it? Is building an automata the right way to prove it? What is the resulting automata. I don't see pattern to use it for build the automata.
Thank you for any help!
First, let me quickly demonstrate that you cannot deduce the language of a grammar is irregular based solely on the grammar's being irregular. To see this, consider the unrestricted grammar:
S -> SSaSS | aS | e
SaS -> aSa
aaS -> SSa
This is clearly not a regular grammar but you should be able to verify it generates the infinite regular language of all strings of a.
That said, how should we proceed? We will need to figure out what language your grammar generates, and then argue that particular language cannot be regular. We notice that the only rule that introduces terminal symbols always introduces twice as many c as it does a. Furthermore, it's not hard to see the language must be infinite. We can use the Myhill-Nerode theorem to show that these observations imply the language must be irregular.
Consider the prefix a^n of a hypothetical string in the language of this grammar. The shortest string which can be appended to the end of this prefix to give us a string generated by this grammar is c^(2n). No shorter string will work, and that string always works. Imagine now that we were looking at a correct deterministic finite automaton for the language of the grammar. Then, whatever state processing the prefix a^n left us in, we'd need the shortest path from there to an accepting state in the automaton to have length 2n. But a DFA must have finitely many states, and n is an arbitrary natural number. Our DFA cannot work for all possible n (it would need to have arbitrarily many states). This is a contradiction, so there can be no correct DFA for the language of the grammar. Since all regular languages have DFAs, that means the language of this grammar cannot be regular.
I have 2 questions to ask and I have some ideas about it also.
1) X-Context free grammer(X-CFG) with 1 terminal or variable at the right hand side of every rule.
2) Y-CFG with 2 terminal or variable at the right hand side of every rule.
Questions:
a) Do they generate any non-regular languages? Prove.
b) Do they generate all regular languages? Prove.
Answers:
a) I think for X-CFG, they can not generate any non regular because it can can only generate finite number of strings so they cant generate any non regular languages.
b) There are infinite number of regular languages like a^* . We can nor generate infinite strings with CFG, so we can say that it can not generate all regular languages.
Am I right?
I have no idea about question b.
Consider the Y-CFG:
S → aA
S → ab
A → Sb
Is this not a Y-CFG that satisfies your constraints and generates a non-regular language? an bn such that n >= 1
Also see this as it states:
Every regular grammar is context-free, but not all context-free grammars are regular. And explains a little why with an example to help grasp it.
So I believe both of your answers are wrong if I understood the question correctly.
UPDATE
Every regular grammar is context-free. So then the question is can we define all CFG's using 2 variables (t is terminal and N is non-terminal):
S → SS
S → t
S → N
S → tN
S → Nt
Therefore we can define things that terminate, things that grow out from multiple starting strings, things that grow in front and things that grow in back. Which is every case in a CFG. So I would say yes you can generate all regular languages.
How does the pumping length of a regular language relate to the pumping length of a related language. For example, if A :< B :< C are all regular languages and k is the pumping length of B, do we know anything about the pumping lengths of A and C?
One might be inclined naively to think that a sublanguage has a smaller (<=) pumping length when we look at finite languages. {a,ab,abc} :< {a,ab,abc,abcd} have respective pumping lengths 4 <= 5. Taking an element out of a set can't make its longest word even longer.
On the other hand if you look at the state machine formed by the synchronized product of two languages, the intersection language and the union language have the same state machine structure, but differ in that the set of final states of the intersection is a subset of the set of final states of the union. Having more final states, could make it more probable to find a shorter path through the state machine. But on the contrary having fewer final states makes it more likely that the state machine has non-co-accessible states, and is thus reducible.
Note first that all languages over an alphabet are related to all other languages over that alphabet by some relation, however contrived. We really do need to limit discussion, as you have suggested, to something like subset in order to meaningfully scope the question.
Now, you've already correctly noted that in the general case, the subset relation doesn't have a clear bearing on the pumping lengths of relative languages. You can easily take a* and compare to {a^n} and show that a minimal DFA for a* is almost always simpler than one for {a^n}.
Let us further restrict ourselves to languages that differ by a finite number of entries; that is, L \ R is finite and R \ L is finite. This is an indicator of similarity different from subset; but if we require that, w.l.o.g., that R \ L be empty, then we recover a restricted version of subset. We might now ask the same question given this modified version: for languages that differ in a finite number of entries, does the subset relation tell us anything?
The answer is still no. Consider L = a* and R = a* \ A, where A is a finite non-empty subset of a*. Even still, L takes one state and R takes potentially many more.
Restricting ourselves to finite sets only, as you suggest, does let us deduce what you propose: that a minimal automaton for R will have no more states than the one for L. Why is this? We must have n+1 states to accept any string of length n, and we must have a dead state to accept strings not in the language (of which there will be infinitely many). A minimal DFA will have no loops at all (except centering on the dead state) if the language is finite, since otherwise you'd be able to get infinitely many strings.
Your observation about taking the Cartesian product is correct, in that the result of applying the construction gives a structurally identical DFA for any set operation (union, difference, intersection, etc.); however, these DFAs are not guaranteed to be minimal and the point for finite languages still holds, namely, the DFA for intersection will have no more states than the one for union, before and after DFA minimization of both machines.
You might be able to take the Myhill-Nerode theorem and define a notion of "close-relatedness" using that which does allow you to compare languages to determine which will have the larger minimal DFA. I am not sure about that, however, since an easy way of doing that would allow you to compare to parameterized reference languages to, for instance, easily prove any non-regular language is non-regular, which might be a big deal in mathematics in its own right (like, either it's impossible in general or it would prove P=NP, etc. to do so).
This is the definition of regular languages from Wikipedia's article:
The collection of regular languages over an alphabet Σ is defined recursively as follows:
The empty language Ø is a regular language.
For each a ∈ Σ (a belongs to Σ), the singleton language {a} is a regular language.
If A and B are regular languages, then A ∪ B (union), A • B (concatenation), and A* (Kleene star) are regular languages.
No other languages over Σ are regular.
Now think about aⁿbⁿ which we know is not regular, but doesn't it pass the above rules?
{a} is regular, so is {b} and also their concatenation and thus the mentioned lang!
it feels like I'm mistaking set of languages which is, in other words, set of sets; for set of words which is, the language?
You are mistaken in your statement that you can form this specific language from the rules. Formally, this follows from the Pumping Lemma. To address the reasoning in your question, though:
{a} is regular, so by repeated concatenation, {a^m} is regular
{b} is regular, so by repeated concatenation, {b^n} is regular
so their concatenation, which is anything of the form {a^m b^n} is regular as well, but it is precisely the constraint m == n that you cannot formulate via this family.
aⁿbⁿ is a language that contains only the strings with nx as followed by nxbs.
You can create a regular language that is a superset of this language, but not this language itself.
You're right, {a} is regular and {b} is regular. Thus, by the rules you mentioned, their concatenation is regular as well. However, the concatenation of two languages is defined as {vw | v in L_1, w in L_2}. Since both L_1 and L_2 only contain a single word (a and b, respectively), this definition is equivalent to {vw | v = a, w = b}, which is the set {ab}.
Thus, the concatenation of the two languages is the set {ab}, not a^n b^n.
I have the language {4^(w⋅g)34^(g)|w,g∈NAT} over the alphabet {0,1}.
I need to find out if this language is recognizable, decidable, context free, regular or none of these.
How would i go about doing that or knowing?
Thanks
Consider any string of the form 4^a 3 4^b. Can we find w, g for our a, b? Well, we know that g must equal b, and then we can choose w = a + g. Since a, b and g are natural numbers, so too must be w; the answer is that, yes, for any string of the form 4^a 3 4^b, we have a string in your language.
The language of all strings of the form 4^a 3 4^b is described by the regular expression 4* 3 4* and, as such, your language is regular, context free, decidable and recognizable.
Suppose your language weren't regular; how could you tell? You could use the Myhill-Nerode theorem or the Pumping Lemma for regular languages to derive a contradiction from assuming the language were regular.
Suppose your language weren't context-free. You could use the Pumping Lemma for context-free languages to derive a contradiction from assuming the language were context-free.
Of course, if your language weren't decidable or recognizable, you could prove that in various ways as well.