I'm working on a problem from the Languages and Machines: An Introduction to the Theory of Computer Science (3rd Edition) in Chapter 2 Example 6.
I need help finding the answer of:
Recursive definition of set strings over {a,b} that contains one b and even number of a's before the first b?
When looking for a recursive definition, start by identifying the base cases and then look for the recursive steps - like you're doing induction. What are the smallest strings in this language? Well, any string must have a
b
. Isb
alone a string in the language? Why yes it is, since there are zeroa
s that come before it and zero is an even number.Now, given any string in the language, how can we get more strings? Well, we can apparently add any number of
a
s to the end of the string and get another string in the language. In fact, we can get all such strings fromb
if we simply allow you to add one morea
to the end of a string in the language. Fromx
inL
, we therefore recoverxa
,xaa
, ...,xa^n
, ... =xa*
.Finally, what can we do to the beginning of strings in our language? The number of
a
s must be even. So far, rules 1 and 2 only allow us to construct strings that have zeroa
s before theb
. We should be able to get two, four, six, etc., all the even numbers, ofa
s. A rule that lets us add twoa
s to any string in our language will let us add ever morea
s to the beginning while maintaining the evenness property we require. Starting withx
inL
, we recoveraax
,aaaax
, ...,(aa)^(2n)x
, ... =(aa)*x
.Optionally, you may add the sometimes implicitly understood rule that only those things allowed by the aforementioned rules are allowed. Otherwise, technically anything is allowed since we haven't explicitly disallowed anything yet.