This is an old revision of the document!


Lab

Key insights:

  • more languages than regular expressions
  • we do not know how to write regular expressions for some languages (as a direct consequence of the above)
  • reg.exps. are unambiguous and FINITE language representations

Objectives:

  • Understand what is a language and a regular expression is, and the relation between them;
  • Write several regular expressions for designated languages
  • Identify languages described by some regular expressions (e.g. ?!)

Resources (tentative):

Exercises

I. What is the regular expression for the following languages:

  • $ \Sigma=\{0, 1\}$ , $ L=\{011\}$

Solution: $ E=011$
Obs: By definition the correct expression is $ E=((01)1)$ , but we won't write them when not needed and we use a precedence rule to reduce the number of parantheses in regular expressions as much as possible (Kleene Star > Concatenation > Union).

  • $ \Sigma=\{a, b\}$ , $ L=\{a, b\}$

Solution: $ E=a \cup b$
Obs: By definition the correct expression is $ E=(a \cup b)$ , but we can remove parentheses for the same reason as above.

  • $ \Sigma=\{0, 1\}$ , $ L=\{e, 0, 1, 00, 01, 10, 11, 000, \ldots\}$

Solution: $ E=(0 \cup 1)^{*}$

  • $ \Sigma=\{0, 1\}$ , $ L=\{010010101000010, 010010101000011\}$

Solution: $ E=01001010100001(0 \cup 1)$

  • $ \Sigma=\{0, 1\}$ , $ L=\{w \in \Sigma^{*} \mid w \text{ ends with } 0\}$

Solution: $ E=(0 \cup 1)^{*}0$

  • $ \Sigma=\{0, 1\}$ , $ L=\{w \in \Sigma^{*} \mid w=w_101 \lor w=1w_1, w_1 \in \Sigma^{*}\}$

Solution: $ E=(0 \cup 1)^{*}01 \cup 1(0 \cup 1)$

  • $ \Sigma=\{x, y\}$ , $ L=\{w \in \Sigma^{*} \mid \#_x(w) = 2\}$

Solution: $ E=y^{*}xy^{*}xy^{*}$
Obs: $ \#_x(w)$ denotes number of $ x$ in $ w$ .

  • $ \Sigma=\{a, b\}$ , $ L=\{w \in \Sigma^{*} \mid \#_a(w) \,\vdots\, 2\}$

Solution: $ E=(b^{*}ab^{*}ab^{*})^{*}$

  • $ \Sigma=\{x, y\}$ , $ L=\{w \in \Sigma^{*} \mid \#_x(w) \ge 1\}$

Solution: $ E=(x \cup y)^{*}x(x \cup y)^{*}$

  • $ \Sigma=\{a, b, c\}$ , $ L=\{w \in \Sigma^{*} \mid \#_a(w) \ge 1 \land \#_c(w) \ge 1\}$

Solution: $ E=((a \cup b \cup c)^{*}a(a \cup b \cup c)^{*}b(a \cup b \cup c)^{*}) \cup ((a \cup b \cup c)^{*}b(a \cup b \cup c)^{*}a(a \cup b \cup c)^{*})$

  • $ \Sigma=\{a, b\}$ , $ L=\{w \in \Sigma^{*} \mid w \text{ does not contain } ba\}$

Solution: $ E=a^{*}b^{*}$

  • $ \Sigma=\{a, b\}$ , $ L=\{w \in \Sigma^{*} \mid \#_a(w) + \#_b(w) = 0\}$

Solution: $ E=\epsilon$

  • $ \Sigma=\{a, b\}$ , $ L=\{w \in \Sigma^{*} \mid \#_a(w) + \#_b(w) < 0\}$

Solution: $ E=\emptyset$