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.