Yes it is regular language!
Any string consists if a
and b
belongs the language A = {xy | Na(x) = Nb(y)}
.
Example:
Suppose string is: w = aaaab
we can divide this string into prefix x
and suffix y
w = a aaab
--- -----
x y
Number of a
in x
is one, and number of b
in in y
is also one.
Similarly as string like: abaabaa
can be broken as x = ab
(Na(x) = 1) and y = aabaa
(Nb(y) = 1).
Or w = bbbabbba
as x = bbbabb
(Na(x) = 1) and y = ba
(Nb(y) = 1)
Or w = baabaab
as x = baa
and y = baab
with (Na(x) = 2) and (Nb(y) = 2).
So you can always break a string consist of a
and b
into prefix x
and suffix y
such that Na(x) = (Nb(y).
Formal Prrof:
Note: A strings consists of only a
s or consist of b
s doesn't belongs to languagr e.g. aa
, a
, bbb
...
Lets defined new Lagrange CA
such that CA = {xy | Na(x) != Nb(y)}
. CA
stands for complement of A
consists of string consists of only a
s or only b
s.
1And CA is a regular language it's regular expression is a+ + b+
.
Now as we know CA is a regular language (it can be expression by regular expression and so DFA) and Complement of any regular language is Regular hence language A
is also regular language!
To construct DFA for complement language refer: Finding the complement of a DFA? and to write regular expression for DFA refer following two techniques.
- How to write regular expression for a DFA
- How to write regular expression for a DFA using Arden theorem
'+' Operator in Regular Expression in formal languages
PS: Btw regular expression for A = {xy | Na(x) = Nb(y)}
is (a + b)*a(a + b)*b(a + b)*
.