3

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.

Perplexityy
  • 133
  • 3

1 Answers1

1

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^*$

Matthew C
  • 499
  • 3
  • 13