Complement of a given Language for a DFA - state-machine

For DFA, the alphabet Σ = {a,b} the language this DFA will recognise is {w|w must contain a}. For this language that the DFA recognises, what would be the compliment of this language or how would it be written please?
I can't work out if b should also be in the compliment of the language or not. a I know should be excluded from the compliment as it is in the original L or language.
I would have posted an image of the alphabet but I don't have enough points or reputation to.
I am unable to determine the complement of the language that the DFA recognises

The complement of the language {w in {a, b}* | w must contain a} is the language {w in {a, b}* | w contains no a}. Strings in this language can be empty or consist of any number of b; the regular expression for this is b* and there is a 2-state minimal DFA that loops on the accepting initial state in case of b, and goes to a non-accepting dead state in case of a, where both transitions from the dead state are loops back to the dead state itself.

Related

infinite regular language and finite regular language proof

Suppose L is an infinite regular language. Does it follow that there exists a finite language S such that L = SS* ? Prove or disprove by finding a counterexample.
What i have tried:
Intuitively this should be true. Any infinite language can be represented by a finite language S if S has the same alphabets as L e.g if L is the infinite language over the alphabet {a, b}* then S = {a, b} works, so essentially S contains just one occurrence of all the alphabets in L. Is this correct or am i missing something fundamental? or is this just not valid at all?
Any help would be appreciated!
My intuition on this is that it's not true. Let's take the example of the language of all odd-length strings over {a, b}. This is trivially regular, and trivially infinite. However, any finite subset of this language will have odd-length strings, and any infinite suffix would have to have an even length, so there is no reasonable construction of L = SS* for some finite language S.
I'll leave turning this intuition into a formal proof to the reader.
Here's an alternative counterexample that might be easier. Consider the infinite regular language ab*. Now suppose L = SS* for some S. Now, either S contains a string with a in it, or it does not. If it does, then L = SS* contains strings with multiple a's, so it cannot be the language ab*. If S does not contain a, then L = SS* contains no strings with any a's at all, and can't be the language ab*. In either case, L is not ab*, a contradiction. So L cannot be written as SS* for any S.

Is it possible for a subset of a non-context free language to be context-free?

For example, if I have a non-context free language of B, is there such a context free language A such that A is a subset of B? I have been thinking of examples but unable to think of any valid ones.
I thought I got it when I said that A = {A = {w | w is of even length and w ∈ {a, b, c}}, which is context-free, and B = {ww | w ∈ {a,b,c}}, which is not context free. However, I realized that there are some strings A can produce that B cannot, and therefore, A is not a subset of B.
Does anyone know of any examples that could be valid in my situation?
Any finite set of strings is a context-free language. (Indeed, it is a regular language.) So any finite subset of a language is context-free, regardless of what the language is.
Another trivial case is the language L = L1 ∪ L2 where the alphabet of L1 is Σ1 and the alphabet of L2 is Σ2 and Σ1 ∩ Σ2 = ∅. Now L is context-free only if both L1 and L2 are context-free. (This is not the case if the alphabets are not disjoint.) So if exactly one of L1 and L2 is context-free, then it is a subset of the non-context-free language L.
If neither of those are interesting enough for you, then the language { a* } (where a is a symbol) is a subset of { ww | w ∈ {a, b}* }. Another subset of the same classic non-context-free language is { ww | w ∈ {a, b}* ∧ w = wR } (that is, the language of all duplicated even-length palindromes) which is context-free because it is exactly the same as { wwR | w ∈ {a, b}* ∧ w = wR }, as a result of the second condition.

Finding error in proof stating the language L = {0^(n)1^(n) | n>0} is a regular expression

Proof: Let M be the following NFA:
Automata for L
Now, if x is in L, then x = 0^(n)1^(n). Thus while processing x, M will start in state q0, loop in state q0 n times, then transition to state q1 on the rst 1, and follow the loop in state q1 a total of n 􀀀 1 times. Since it ends in state q1, x will be accepted. Thus M recognizes every string in L, so L is NFA-recognizable (and by Kleene's theorem, is thus regular).
You've shown that M accepts every string of L. But that doesn't mean that M recognizes L: for that to be true, you have to also show that M accepts exactly the strings of L and no others (or equivalently: it doesn't accept any string not in L). Unfortunately in your case, M does accept some non-L strings: for example, "011".
Your proof is indeed wrong. To prove that the language L is regular you need to prove that there exists a finite state automaton M that recognizes the language L. Hence, there are three things that you need to prove about the automaton M:
The automaton M exists.
The automaton M recognizes the language L (nothing more, nothing less).
The automaton M has a finite number of states.
The problem with your proof is that the automaton you posted does not recognize the language L:
This automaton recognizes the language 0*1+ which is not the same as the language L (0^n1^n). Yes, every string in L is recognized by this automaton. However, this automaton also recognizes strings like 1 which is clearly not in L. Hence, using this automaton in your proof is wrong.
So, how do you prove that the automaton M exists? Well, the only way to prove that the automaton M exists is by showing that M exists. The only problem is that L is not a regular language. Hence, there is no finite state automaton M that recognizes L.
The opposite way is to prove that L is not a regular language. To prove that L is not a regular language you need to prove that there is no finite state automaton M that recognizes L. This is an easier proof because you don't have to find the automaton M. You can just assume that it exists.
Here's what you need to do to prove that L is not a regular language:
Assume that an automaton M exists that recognizes the language L.
Show that M must necessarily have an infinite number of states.
The standard way of proving that an automaton M cannot have a finite number of states is by using the Pumping Lemma. I'll leave it as an exercise for you to figure that out because it's not in the scope of your question.

If pref(L) is regular, does that imply L is also regular?

I have this exercise for homework:
Say we have a language L. we know that the language pref(L) (all the prefixes of L, including all the words in L itself) is a regular language. Does this imply that the language L is regular as well?
I took the NFA of pref(L) and divided it (via 2 epsilon transitions from q0) to 2 separate NFA's, as 1 defines L and the other defines pref(L)\L.
What I actually got is a NFA for L, which means it is regular.
I am not sure this is the way or if it legal. I'd be glad for another lead.
Thanks in advance,
Yaron.
It is not necessarily the case that if pref(L) is regular, then L is regular as well.
As an example, let Σ = {a} be a unary alphabet. I'm going to claim that if L is any infinite language over Σ, then pref(L) = Σ*. To see this, first note that pref(L) ⊆ Σ* because every pref(L) is a language over Σ. Now, consider any string in Σ*, which must have the form an. If L is an infinite language over Σ, it must contain at least one string of the form am where m ≥ n. Then an would be a prefix of am, so an ∈ pref(L). This shows that Σ* ⊆ pref(L) and that pref(L) ⊆ Σ*, so in this case Σ* = pref(L).
Now, all we need to do is find a nonregular language over Σ = {a}. As an example, take the language { a2n | n ∈ N } of all strings whose length is a power of two. It's possible to prove using either the Myhill-Nerode theorem or the pumping lemma that this language is not regular. However, by the above result, we know that pref(L) is a regular language.
Hope this helps!

If L* is regular, then is L regular?

I've tried to look for the answer and I'm getting conflicting answers so I'm not sure. I know the reverse is true, that if L is regular then L* is regular under closure.
I imagine that if L* is regular then L is regular because the subset of L* should be regular and L is part of that subset.
If L* is regular, then L is not necessarily regular. For example, consider any nonregular language L over an alphabet Σ such that Σ ⊆ L. (That is, imagine you have a nonregular language where each individual character in the alphabet is a string in L.) In that case, L* = Σ*, since you can form any string as the concatenation of all the individual characters of Σ.
Here's one possible example. Let Σ = {a} and consider the language L = { a2n | n ∈ N }. This language is not regular, and you can prove it using either the pumping lemma for regular languages or the Myhill-Nerode theorem. However, the language L* is the language a*, which is regular. To see this, notice that since L contains the string a, the language L* contains all strings of the form an for any natural number n.
Another option: pick L to be any nonregular language over Σ, then consider the language L ∪ Σ. This is also a nonregular language (if L ∪ Σ were regular, then we could subtract out each character added in via the union, leaving a regular language at each step, to show that L is regular), and it satisfies the above requirements.
Hope this helps!
Take L = {a,b}*, which is regular, but has a non-regular subset L={a^n b^n} (this one can be proved to be non regular by pumping lemma...), so it's not the case that all subsets of a regular language are regular.

Resources