HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Simplifying regular expressions

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
regularexpressionssimplifying

Problem

This is the homework question:


$ \{w \in \{a, b, c\}^* : \text{(no symbol occurs twice in succession in w)}\} $

This is my answer:


$$\{((abc)^| (acb)^| (ab)^ | (ac)^)^ | (bac)^ | (bca)^ | (ba)^ | (bc)^)^ | ((cab)^ | (cba)^ | (ca)^ | (cb)^)^* | ((\epsilon +a) | (\epsilon + b) | (\epsilon+c)) \}
$$

Is there a way to simplify this expression?

Solution

Let's solve this exercise "by induction". Suppose first that the alphabet is only $a,b$. In this case, the only possible words are $ababab\ldots$ and $bababa\ldots$, and you can write a simple regular expressions for them. Now take such a word over the alphabet $a,b,c$. You can break it apart as $w_1 c w_2 c w_3 c \ldots$, in which $w_i \in \{a,b\}^*$. We already have a regular expression describing the $w_i$, so we can write one for the language in question. This approach is general, and you can apply it to any alphabet size.

Context

StackExchange Computer Science Q#9492, answer score: 4

Revisions (0)

No revisions yet.