Unambigious expression for ternary strings

227 Views Asked by At

So I'm trying to find an unambiguous expression for M where M is the set of ternary strings where each block of 1s has length at least 3 and every block of 2s has odd length.Where ternary strings are of

{1,2,3}*

I started with the expression

(0*11(1)*(22)*)*

but found a contradiction as 11.1111 and 1111.11 can both be obtained how can I change my expression to make it express the question above

1

There are 1 best solutions below

0
On

The final answer is very complicated, so I will need to employ some shortcuts. Introduce the following shorthand:

X = 0(0)*
Y = 11(1)*
Z = 22(22)*

These represent nonempty legal blocks of $0$s, $1$s and $2$s. Next, let

W = (ε + Z)Y(ZY)*(ε + Z)

Here, the $+$'s represent "or," while $\varepsilon$ represents the empty string. $W$ represents any legal string which only involves $1$s and $2$s, and which has at least one $1$. Now, let $A$ be an expression for a legal string which ends in $0$. You can show that

A = (ε + Z + W)X((W + Z)X)*

Then, letting $B$ represent legal strings ending in $1$, you can show

B = (ε + A)(ε + Z)Y(ZY)*

and furthermore, letting $C$ represent legal strings ending in $2$, that

C = (ε + A + B)Z

Finally, the expression you want is

ε + A + B + C

You can combine all of these substitutions to get a string involving ε,0,1,2,+ and * alone, but it would be super complicated!