If L1 is the set of binary strings with an even number of zeroes, and L2 is
the set of binary strings with an odd number of 1s, can you express L1 /\ L2 as a regex?
1) Understand the problem
Data: L1 is defined, L2 is defined, L1 /\ L2 is defined.
Unkown: Regular Expression for L1 /\ L2
I know it is possible to come up with one because Prof Heap said somebody did it on the bulletin board.
Seperate: First write L1s regex, then write L2s regex then combine.
2) Plan
I will:
i) Find regular expressions for L1 and L2
ii) Break up the regular expression for L1 and insert pieces of the regular expression of L2 into it to create the cases of the intersection
iii) Combine the cases with + (ORs)
iv) Factor to reduce size.
This was devised by noticing the similarity between this and straight forward algebra. If we first examine L1, the 1s in L1's regex can be seen as variables holding the place of a regex to satisfy L2's condition also. The solution to this problem could possibly be applied to creating regular expressions to denote unions of other languages.
3) Carry out the plan
i) A regular expression to denote L1: (1*01*01*)*
A regular expression to denote L2: 0*10*(0*10*10*)*
ii) If we examine L1, we need to have an odd number of 1s in the 1*s. To do this, there are a few cases. 1) The first, second and third 1* contains an odd number of 1s (then odd + odd + odd = odd). 2) The first 1* contains an odd number of 1s (then odd + even + even = odd). 3) The second 1* contains an odd number of 1s (then even + odd + even = odd). 4) The third 1* contains an odd number of 1s (then even + even + odd = off).
1) 1(11)*[01(11)*01(11)*]*
2) 1(11)*[0(11)*0(11)*]*
3) [(11)* 0 1(11)*0(11)*][(11)*01(11)*0(11)*01(11)*0(11)*]*
# 3 is an interesting case because we cannot split up the 0s. Thus we must have at least 1 repetition and then subsequent repititions will contain two center pieces (1(11)*). This is interesting because in this case, 0s can only increment by 4 rather than 2
4) [(11)*0(11)*0]*1(11)*
iii) {1(11)*[01(11)*01(11)*]*} + {1(11)*[0(11)*0(11)*]*} + {[(11)* 0 1(11)*0(11)*][(11)*01(11)*0(11)*01(11)*0(11)*]* } + { [(11)*0(11)*0]*1(11)*}
iv) Notice how two of the cases start with the same regex? We can combine these with +
{1(11)*[[01(11)*01(11)*]+[0(11)*0(11)*]]*} + {[(11)* 0 1(11)*0(11)*][(11)*01(11)*0(11)*01(11)*0(11)*]* } + { [(11)*0(11)*0]*1(11)*}
Finally, I am sure this works because of the means of construction. All cases are accounted for.
4) Looking Back.
Although this is a complex way of doing this, the regex is right based on the way it is constructed (including each possible case then logically combining them).
We learned a better way of doing this in lecture, using FSAs and then converting them to regex. I think that is a more practical way since it is more systematic and will work on all problems. However, in problems where you are doing different things with the 0s and 1s, this solution should work.