Regular Expression

Definition

R is a regular expression if R is:

  1. a for some a in the alphabet \Sigma,
  2. \epsilon
  3. \phi
  4. (R_1 \cup R_2), where R_1 and R_2 are regular expressions
  5. (R_1 \circ R_2), where R_1 and R_2 are regular expressions, or
  6. (R_1^*), where R_1 is a regular expression.

Layperson: 1—3 describe the simplest base conditions, 4—6 say that we can do a bunch of regular operations to make more complex REs.

How Everything Relates:

Regular Expression Shorthands:

Some Identities to Remember:

R \cup \phi = R

Examples

Note: Alphabet is {0,1}

Conversion and properties of RL and RE:

  1. (\Sigma\Sigma)^* = { w | w is a string of even length}
  2. (\Sigma\Sigma\Sigma)^* = { w | w is a string of length divisible by 3}
  3. 001 = { w | w is the string 001 }
  4. 001 \cup 10 = { w | w is the string 001 or 10 }
  5. \Sigma^* 001 \Sigma^* = { w | w contains the substring 001 }
  6. 0^*10^* = { w | w contains a single one }
  7. See Example 1.53 in the book for more examples…

Create the RE for the following regular languages:

Q: { w | w contains at least two 1s }

A;

Thus, the RE is \Sigma^* 1 0^* 1 \Sigma^*

Q: { w | w contains at an even amount of 1s }

A;

Thus, the RE is (0^* 1 0^* 1 0^*)^+

Q: { w | w doesn’t contain the substring 10 }

A:

Observations:

0^* 1^*

Q: { w | w contains 3 ones }

A:

Observation:


Q: What the value?

\begin{align*} a \cup b &= \\ a \circ b &= \\~\\ a \cup \epsilon &= \\ a \circ \epsilon &= \\~\\ \phi \cup \epsilon &= \\ \phi \circ \epsilon &= \\~\\ a^* &= \\ b \circ a^* b &= \\ \end{align*}

A: \begin{align*} a \cup b &= \{ a,b \} \\ a \circ b &= \{ \texttt{ab} \} \\~\\ \end{align*} \begin{align*} a \cup \epsilon &= \{ a, \epsilon \} \\ a \circ \epsilon &= \{ a \} \\~\\ \phi \cup \epsilon &= \epsilon \\ \phi \circ \epsilon &= \{ \} \\ a^* &= \{ \epsilon, a^1, a^2, a^3, ... \} \\ b \circ a^* b &= \\ \end{align*}

Takeaways:

Q: Write the NFA and GNFA for R_1 \circ (R_2)^* \circ R_3

A: