Lecture 22 - Notes
Goals
- Be able to prove that regular languages are closed under regular
operations including union, concatenation, and star.
- Know the definition of regular expressions
- Be able to construct regular expressions for a given language, and
be able to describe the language represented by a regular
expression.
Announcements
- A6 due Friday night
- Midterm wrapper due Monday night
NFA \(\rightarrow\) DFA, continued
Do Exercises Part A
Closure
of Regular Languages under Regular Operations
We’re finally ready to do the (actually quite straightforward, now!)
proof of the closure of regular operations.
Theorem: The set of regular languages is closed
under the regular operations.
Regular Operations
- The union of two languages \(A\) and \(B\) is defined as \(A \cup B = \{w : w \in A \text{ or } w \in
B\}\).
- The concatenation or product of
two languages \(A\) and \(B\) is defined as \(AB = \{ww' : w \in A \text{ and } w' \in
B\}\).
- The closure or star (or Kleene
closure) of a language \(A\) is defined
as: \(A^* = \{u_1 u_2 \ldots u_k : k \ge 0
\text{ and } u_i \in A \text{ for all } i = 1, 2, \ldots, k\}\)
- In other words, it’s the language containing all possible
concatenations of any choice of 0 or more strings over \(A\). Notice that 0 is an option here, so
\(\epsilon \in A^*\) for any language
\(A\).
- Another equivalent recursive definition is:
- Let \(A^0 = \{\epsilon\}\)
- Let \(A^k = AA^{k-1}\)
- \(A^* = \bigcup_{k=0}^{\infty}
A^k\)
Proof:
Case: \(A \cup B\) - proof by
construction:
Let \(M_A = (Q_A, \Sigma, \delta_A, q_A,
F_A)\) be a DFA accepting \(A\)
and \(M_B = (Q_B, \Sigma, \delta_B, q_B,
F_B)\) be a DFA accepting \(B\).
Construct an NFA \(N = (Q, \Sigma',
\delta, q, F)\) as follows:
- Let \(Q_B'\) be a set
containing \(Q_B\)’s elements, but
renamed to ensure that \(Q_A \cap Q_B =
\varnothing\); also let \(s\) be
a new state that is not a member of \(Q_A\) or \(Q_B\).
- The NFA’s set of states is \(Q = Q_A \cup
Q_B' \cup \{s\}\).
- The NFA’s alphabet is \(\Sigma' =
\Sigma \cup \{\epsilon\}\).
- The NFA’s transition function \(\delta =
\delta \cup \{((s, \epsilon), q_A), ((s, \epsilon),
q_B)\}\).
- The NFA’s start state is \(q =
s\).
- The NFA’s accept states are \(F = F_A \cup
F_B\).
This machine accepts \(A \cup B\)
because at the start of processing, it may nondeterministically decide
to make an \(\epsilon\)-transition to
either \(A\)’s start state or \(B\)’s start state, then proceed to process
the string exactly as \(M_A\) or \(M_B\) would. Therefore, if the string is in
\(A\) or \(B\), then there is a way that \(N\) can process the string and end in an
accept state.
- Remaining cases: Exercises! See also Section 2.6 of ToC.
Regular Expressions
Regular expressions are a
meta-language for describing regular languages. They
are defined based on the properties of regular languages that we’ve now
explored thoroughly, so a lot of what follows will probably be
unsurprising.
Definition: A regular expression over an alphabet
\(\Sigma\) is defined as follows:
- \(\epsilon\) is a regular
expression, describing the language \(\{\epsilon\}\)
- \(\varnothing\) is a regular
expression describing the language \(\varnothing\)
- For each \(a \in \Sigma\), \(a\) is a regular expression describing the
language \(\{a\}\)
- If \(R_1\) and \(R_2\) are regular expressions, then \(R_1 \cup R_2\) is a regular expression
describing the language \(L(R_1) \cup
L(R_2)\)
- If \(R_1\) and \(R_2\) are regular expressions, then \(R_1R_2\) is a regular expression describing
the language \(L(R_1) L(R_2)\)
- If \(R\) is a regular expression,
then \(R^*\) is a regular expression
describing the language \(L^*\)
Operator Precedence
in Regular Expressions
From highest to lowest precedence:
- Parentheses for grouping
- Star
- Concatenation
- Union
So, for example:
- \(01^* = 0(1^*)\)
- \(01 \cup 0 = (01) \cup 0\)
- \(1 \cup 0^* = 1 \cup (0^*)\)
Examples:
What language does \((0 \cup
1)01^*\) describe?
\(\{00, 001, 0011, \ldots, 10, 101, 1011,
\ldots\}\)
What regular expression describes \(\{w: w
\text{ has $1011$ as a substring}\}\)?
\((0 \cup 1)^*1011(0 \cup
1)^*\)