3
$\begingroup$

A knob is used to select one of three positions A, B, C.

The knob can never be turned from A to C, or from C to A, without spending at least one second in position B. The initial position of the knob can be any of A, B, C.

Give a regular expression for this language.

I tried starting from B, and ended up with:

BB*((AA*(BB*)*) u (CC*(BB*)*)*

But, it seems impossible to express all possible transitions.

$\endgroup$

1 Answer 1

1
$\begingroup$

We can build it up from smaller pieces:

How can you describe sequences made up of only a's? Just $a^*$

How about sequences made up of only a's and b's? $(a|b)^*$ These can be thought of as turning the knob from A to B, then going back to A, etc..

Similarly for b's and c's: $(b|c)^*$

Say we stay in positions A-B for a while, and then we want to go to C; this can be expressed as: $(a|b)^* (bb^*) c$

Now let's say we stay in positions A-B for a while, and then we switch to C, and stay in B-C for a while. Then the rule means we must pass through b at least once: ${(a|b)^* (bb^*) (b|c)^*}$

Now what if we want to stay in A-B, then switch to C, stay in B-C, then switch back to A, and stay in A-B again? ${(a|b)^* (bb^*) (b|c)^* (bb^*) (a|b)^*}$

The pattern starts to appear. You can see that whenever we want to transition we need to stick a $bb^*$ in between.

To get full sequences, we could try:

$(\, (a|b)^*(bb^*) \, | \, (c|b)^*(bb^*) \, )^*$ which you can check, obeys the transition rule. The only problem is that this assumes the sequence ends with b. To fix that, we just include options to end at a or c; naming the above as $$ L=(\, (a|b)^*(bb^*) \, | \, (c|b)^*(bb^*) \, )^*, $$ we arrive at an answer: $L\, | \,La^* \,| \,Lc^*$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.