Why is {a^n a^n | n >= 0} regular? - regular-language

I understand the reason and the proof why {a^n b^n | n >= 0} is NOT regular.
Why is {a^nb^n | n >= 0} not regular?
The solution of one of my exercises is: {a^n a^n | n >= 0} is regular. How can I prove this thesis?

Yes, Language {an an | n >= 0} is a regular language. To proof that certain language is regular, you can draw its dfa/regular expression. And you can drive do for this language as follows:
Because "anan for n >= 0" is same as "a2n for n >=0", and that is "set of all string contests of even number of symbol a" that is regular — regular expression for this is (aa)*.
Note, regular expressions is only possible for regular languages hence it is proved that {an an | n >= 0} is a regular language. and DFA would be:
I would suggest you to read this why languages like {an bn | n >= 0} are not regular.

First change the definition to the equivalent L = {a^2n | n >= 0}. Now observe that any string that belongs to L is simply a multiple of 2 as. Then change that definition to (aa)*, which is a regular expression since it only uses primitives for expressing regular languages - individual characters (a), concatenation (aa) and Kleene star (*). Now you're done.

Related

Is L = {ww^Ru | w, u ∈ {0,1}+} regular language?

let L = {wwRu | w, u ∈ {0,1}+}. Is L regular language ? Note that w, u cannot be empty.
I've tried to prove it is not regular language by the pumping lemma, but I failed when w = 0^p1^p, 01^p, (01)^p. Once I take y = 0^p or 1^p, xyyz will be 00.../11.../01^n0... etc.
And I cannot draw its DFA/NFA or write its regular expression to prove it is regular language.
So is L regular or not ? How can I prove it ?
The language is not regular, and we can prove it using the Myhill-Nerode theorem.
Consider the sequence of strings 01, 0101, ..., (01)^n, ...
First, notice that none of these strings are in the language. Any prefix of any of these strings which has even length is of the form (01)^2m for some m, and therefore just a shorter string in the sequence; splitting such a prefix in two either has both substrings start with 0 and end with 1, or else it has the first substring start and end with 0 and the second start and end with 1. In either case, these strings are not of the form w(w^R)u for any w or u.
Next, notice that the shortest possible string which we can append to any of these strings, to produce a string in the language, is always the reverse of itself followed by either 0 or 1. That is, to turn 01 into a string in the language, we must append 100 or 101; there are no shorter strings we can append to 01 to get a string in the language. The same holds true for 0101: 10100 and 10101 are the shortest possible strings that take 0101 to a string in L. And so on for each string of the form (01)^n.
This means that each string of the form (01)^n is distinguishable with respect to the target language w(w^R)u. The Myhill-Nerode theorem tells us that a minimal DFA for a regular language has exactly as many states as there are equivalence classes under the indistinguishability relation. Because we have infinitely many distinguishable strings with respect to our language, a minimal DFA for this language must have infinitely many states. But, a DFA cannot have infinitely many states; this is a contradiction. This means that our language cannot be regular.
The language is REGULAR:
L = 00(0+1)+ + 11(0+1)+ + 0(11)+0(0+1)+ + 1(00)+1(0+1)+

Proving the inexpressibility of a function in a given language

I'm currently reading through John C. Mitchell's Foundations for Programming Languages. Exercise 2.2.3, in essence, asks the reader to show that the (natural-number) exponentiation function cannot be implicitly defined via an expression in a small language. The language consists of natural numbers and addition on said numbers (as well as boolean values, a natural-number equality predicate, & ternary conditionals). There are no loops, recursive constructs, or fixed-point combinators. Here is the precise syntax:
<bool_exp> ::= <bool_var> | true | false | Eq? <nat_exp> <nat_exp> |
if <bool_exp> then <bool_exp> else <bool_exp>
<nat_exp> ::= <nat_var> | 0 | 1 | 2 | … | <nat_exp> + <nat_exp> |
if <bool_exp> then <nat_exp> else <nat_exp>
Again, the object is to show that the exponentiation function n^m cannot be implicitly defined via an expression in this language.
Intuitively, I'm willing to accept this. If we think of exponentiation as repeated multiplication, it seems like we "just can't" express that with this language. But how does one formally prove this? More broadly, how do you prove that an expression from one language cannot be expressed in another?
Here's a simple way to think about it: the expression has a fixed, finite size, and the only arithmetic operation it can do to produce numbers not written as literals or provided as the values of variables is addition. So the largest number it can possibly produce is limited by the number of additions plus 1, multiplied by the largest number involved in the expression.
So, given a proposed expression, let k be the number of additions in it, let c be the largest literal (or 1 if there is none) and choose m and n such that n^m > (k+1)*max(m,n,c). Then the result of the expression for that input cannot be the correct one.
Note that this proof relies on the language allowing arbitrarily large numbers, as noted in the other answer.
No solution, only hints:
First, let me point out that if there are finitely many numbers in the language, then exponentiation is definable as an expression. (You'd have to define what it should produce when the true result is unrepresentable, eg wraparound.) Think about why.
Hint: Imagine that there are only two numbers, 0 and 1. Can you write an expression involving m and n whose result is n^m? What if there were three numbers: 0, 1, and 2? What if there were four? And so on...
Why don't any of those solutions work? Let's index them and call the solution for {0,1} partial_solution_1, the solution for {0,1,2} partial_solution_2, and so on. Why isn't partial_solution_n a solution for the set of all natural numbers?
Maybe you can generalize that somehow with some metric f : Expression -> Nat so that every expression expr with f(expr) < n is wrong somehow...
You may find some inspiration from the strategy of Euclid's proof that there are infinitely many primes.

Trying to prove that the complement of {a^i b^i c^i} is a context-free

I'm trying to prove that the complement of L= {a^i b^i c^i : i >= 1} is a context free. L complement is: {w is a word over {a,b,c}* : w not in L}.
As we know, context-free languages are closed under union. So, I'm trying to divide my language (complement of {a^i b^i c^i}) into context-free subsets in which their union must be context-free. Could anyone help me to find the subsets? Each time I try to, I end up with L*!
Thank you.
Note: In the following, I left out the constraint that L does not include the empty string, but that only requires a small adjustment.
Consider aibjck.
If i=j and j=k then you have aibici. Conversely, if i≠j or j≠k, then you have the part of the complement of aibici which consists of strings in a*b*c* (the rest of the complement is straight-forward).
In other words,
L = { aibjck | i=j } ∩ { aibjck | j=k }
and
L' = { aibjck | i≠j } ∪ { aibjck | j≠k }
It's easy to show that each subset in the above equations is context-free. As you say, context-free languages are closed under union, but they are not closed under intersection; consequently, L' is context-free even though L is not.

Proof the language is regular or not regular using Pumping lemma?

Can any one help to figure out that L = { am bn, m ≥ n + 2, m ≤ 3 } is regular or not using pumping lemma, It seems to be a bit difficult to prove.
I have tried to used pumping lemma and it shows that it is regular language but i am really confused that is this right or not.
I have tried to used pumping lemma and it shows that it is regular language but I am really confused that is this right or not.
First note, the pumping lemma can be used to proof that "certain language is not a regular language". But we can not use pumping lemma to proof that "certain language is a regular".
Yes, the pumping lemma for regular languages describes an essential property of all regular languages, and if a languages don't satisfy the conditions described by pumping lemma or say don't satisfy pumping lemma property then that language is actually not a regular language, But the converse of this is not true!! &mdash- there are "languages those satisfies pumping lemma's conditions and may still be non-regular", means:-
Pumping lemma is 'necessary but not sufficient condition' for a language to be regular.
This is something like: every engineer is math student - so if a student is engineer we can say that he knows math, but their are math students those don't know engineering. (just giving you an example to explain)
From your question, I have impression that you don't understand basically - "what is a regular language?".
Unlike pumping lemma for regular languages, we need to learn some other characteristics of regular languages - finding them in a language proofs that the language is a regular language. If you can represent a language using finite automata or/and regular expression that proofs that the language is a regular language.
Now, come to your original question:
How to proof that language { am bn, m ≥ n + 2, m ≤ 3 } is regular or not?
Because neither 'm' or 'n' can be negative (a string without occurrence of any symbol is possible eg. empty string1, but a string with negative occurrence of language symbols is not possible) and according to condition "m ≥ n + 2", 'm' is always greater than 'n' — so minimum value of 'm' (when 'n' is 0) is 2. From second condition "m ≤ 3", maximum value of 'm' is '3', and so 'm' can be either 2 or 3.
If you again notice fist condition: "m ≥ n + 2" for m = {2, 3} possible values for 'n' can be:
for m = 2, n can be 0 and that makes string 'aa'.
for m = 3, n can be 0 or 1 and that makes strings 'aaa', 'aaab'.
So, it came that the language is a finite language e. only consists of three strings. Every finite language is a regular language, check venn diagram:
(to lean more about this read: Finiteness of Regular Language)
Regular expression for your language L = { am bn, m ≥ n + 2, m ≤ 3 } would be aa(a + Λ)(b + Λ),
hence it is proofed that language is a regular language.
1 a string without occurrence of any symbol is called empty or null string in formal languages, in most of formal language books symbol Ɛ for empty string.
Λ is empty symbol.
we cannot use the pumping lemma for proving language is regular.To prove a language is regular we should design DFA for that language

design NFA which accepts specific length of strings

Im looking forward to design a FA which accepts some kind of string that accept some A and B.
First a string which the number of A is five more times higher than B.
i mean L={w∈{A,B}* and (nA(W)-nB(W) mod 5=0)
And also a FA which accept different number of character in a string:
L={A^n B^m C^k | n,k>0 and m>3}
I design some FAs But they did not work perfectly on this complicated strings.
Any help on how should i design this ?
Unfortunately, your questions are confusing as the english text doesn't agree with the mathematical formula. I will try to answer to these four questions then:
A language which consists of string over {a,b} that the number of a (= #a(w))
is five times as the number of b ( #b(w)),
L = { w in {a,b}* : #a(w)>#b(w) and #a(w)=#b(w)mod5 }
This cannot be done by an NFA. The proof is simple by using the pumping lemma (P.L) with the string a^pb^5p, where p is the constant of P.L.
For the language: L={w∈{A,B}* : (nA(W)-nB(W)) mod 5=0} that you wrote,
you can do it with an DFA that consists of a cycle of 5 states.
The transitions are, if you read a go clockwise if you read b go counter-clocwise. Choose at random one state to be initial state and the same state will be the final state.
For the language L={A^n B^m C^k | n,k>0 and m>3}, it should be easy to find out
if you read L as L=A(A)* B(B)* c^4(C)*
For the language that accepts different number of character in the string (let's say over a,b). The language should be R={ w in {a,b}* : #a(w) not equal #b(w)}
This language again it cannot be recognized by an NFA. If this language was regular (recognzied by an NFA) so would be this language:
L=a*b* intersection (R complement). The language L is {a^n b^n/ n non-negative integer}.
The language L is the first example of most books when they speak about languages that are non-regular.
Hopefully, you will find this answer helpful.

Resources