2

I was given this problem on regular languages, which I solved, but I was wondering there is another, more elegant way to approach it. I'll share the problem first, along with my solution, and then state how I first thought how to solve it - from which my question then arises.

The problem

Bitwise OR is a binary operation that takes two binary strings of the same length and returns a string consisting of the logical or between each bit in the same position. E.g.: $$0011\sqcap0101 = 0111$$ Let $L$ and $M$ be two regular languages on the alphabet $\{0,1\}$. Prove that the following language $$L\sqcap M=\{x\sqcap y|x\in L, y\in M, |x|=|y|\}$$ is also regular.

The first "bad" solution

My most successful attempt involves a "brute force" approach that construct an NFA to try every possible combination of states in order to determine if the input word could have been the result of the bitwise OR between the words $x\in L$ and $y\in M$. The NFA has

  • $Q=Q_L\times Q_M \times \{0,1,2\}$ states, where each state is represented by the triplet $\{q_L,q_M,\{0,1,2\}\}$. I use $0$ to indicate that I'm reading $x$, $1$ to read $y$ and $2$ to end the computation and possibly accept the input word.
  • $q_0=(q_{0L},q_{0M},0)$ is the starting state
  • $F=\{(q_L,q_M,2 )|q_L \in F_L , q_M \in F_M\}$ are the final states

The transitions between the various states are described as follows:

For an OR operation to produce a zero, a zero must be present in both the first and the second string.

For an OR operation to produce a one, there are three possible cases:

The first string has a $1$, and the second has a $0$.

The first string has a $0$, and the second has a $1$.

Both strings have a $1$. I then derived the following transitions:

  • $\delta((q_L , q_M , 0),0)=\{(δ_L(q_L, 0), δ_M(q_M, 0),0)\}$
  • $\delta((q_L , q_M , 0),1)=\{(δ_L(q_L, 0), δ_M(q_M, 0),1)\}$
  • $\begin{align*}\delta((q_L, q_M, 0),\ 1) &= \left\{\begin{aligned}&(\delta_L(q_L, 1),\ \delta_M(q_M, 0),\ 0), \\&(\delta_L(q_L, 0),\ \delta_M(q_M, 1),\ 0), \\&(\delta_L(q_L, 1),\ \delta_M(q_M, 1),\ 0)\end{aligned}\right\}\end{align*}$
  • $\begin{align*}\delta((q_L, q_M, 1),\ 1) &= \left\{\begin{aligned}&(\delta_L(q_L, 1),\ \delta_M(q_M, 0),\ 1), \\&(\delta_L(q_L, 0),\ \delta_M(q_M, 1),\ 1), \\&(\delta_L(q_L, 1),\ \delta_M(q_M, 1),\ 1)\end{aligned}\right\}\end{align*}$
  • $δ((q_L, q_M, 1), ε) = {(q_L, q_M, 2)}$

where $δ(X, s)$ indicates the states that we can reach from the state $X$ by reading $s$. Since it is always possible to construct a NFA that recognizes $L\sqcap M$, $L\sqcap M$ is a regular language.

The question

The solution itself should be correct, but it's not particularly elegant, nor much useful for construct said NFA (it gets complex very quickly).

My first ever approach was realizing that since $L$ and $M$ are regular languages, there exists at least one regular expression that recognizes each of the respective languages. Let's call them $R_L$ and $R_M$. My initial thought was to find a procedure that always allowed to combine these two regular expressions into a new regular expression $R_{L\sqcap M}$ that recognizes $L\sqcap M$. E.g.:
$$R_L=(01)^* , R_M = (10)^* , R_{L\sqcap M} = (11)^*$$ However, this becomes quite hard with more complex regular expressions. Take: $$R_L=00(10^*1)^*1(0|1)^*0$$ and $$R_M=1011(0|1)^*11(0|1)^*$$ What would the resulting $R_{L\sqcap M}$ be?

In this case I'm sure that $R_{L\sqcap M}$ would start with $1011$ by performing bitwise OR on the predetermined starting symbols, but then we have various strings repeating 0+ times, and I don't know how to approach these cases (I suppose by taking into account every possible combination between the strings recognized by the regular expressions?). I'm sure this is possible, since in theory I could just convert the NFA I previously created into a regular expression, but I wonder if I can use just the regular expressions to do that.

So the final question is:

How can I construct a regular expression $R_{L\sqcap M}$ from any arbitrary pair of regular expressions $R_L$ and $R_M$ (where $R_L$ recognizes the language $L$ and $R_M$ recognizes the language $M$) so that $R_{L\sqcap M}$ regognizes the language $L\sqcap M=\{x\sqcap y|x\in L, y\in M, |x|=|y|\}$?

It would be intresting, then, to extend this to other bitwise operations.

Thanks in advance.

0 Answers0