TOC-Regular language
Regular Language
+ Def: regular language
A language is regular if it is recognized by a DFA or an NFA.
To Prove a Language is regular, we need to construct a DFA or an NFA for the language.
Regular Operations
+ Def: Let $A$ and $B$ be languages.
- Union :
- Concatenation:
Star
Note: each
+ Def: Star operator
Let
$$A^{*} = \cup_{i\in \mathbb{N}} A^{i}$$
Complement
Let
Note:
is the set difference. is the set complement.
The goal
Thus, we need to prove
(
Assume
Then
Thus, DFA
In other words, DFA
By the construction of
Thus,
(
Assume
DFA
In other words, DFA
By the construction of
Thus,
Thus,
Let
Closure
+ Theorem (Closure)
Regular language is closed under union, concatenation, star and complement.
if A and B are two regular languages, then
Construct an NFA for .
Construct an NFA for .
Construct an NFA for .
Regular Expression
Regular languages can be recursively constructed. A regular expression describes the common pattern the strings in a regular language (machine independent).
+ Def: Regular expression (Recursive Definition)
for some , , or
, where and are regular expressions, , where and are regular expressions, or , where is a regular expression.
Languages Defined by Regular Expression
+ Def: Let $R$ be a regular expression. The language $L(R)$ defined by $R$ is
, , , .
- if
, then - if
, then - if
, then
Example:
Suppose
Match nothing
Equivalence of Regular Expression and Finite Automata
+ Theorem
Regular expressions are equivalent to finite automata.
The proof has two steps.
- The language defined by a regular expression can be recognized by a finite automaton.
- The conversion is also doable vice versa.
The conversion from a regular expression to an NFA is trivially ensured by the closure property . So, we only need to convert NFA to regular expressions.
Conversion from NFA to Regular Expression
The Conversion requires generalized NFA, which is a special type of NFA.
Only one start state and one final state. The start state is different from the final state. The transition function is
Suppose
- It means transition from
to requires . - If the GNFA has only 2 states
and , then the label on the transition is the regular expression for the language. - Thus, the conversion recursively merges states and transitions of the generalized NFA.
\begin{algorithm}
\caption{Convert NFA$_\varepsilon$ to 2-state gNFA}
\begin{algorithmic}
\Input An NFA $N = (Q, \Sigma, \delta, q_0, F)$
\Output A regular expression which defines $L(N)$
\STATE $N' \gets N$ // convert the domain and codomain of the transition function
\STATE $Q' \gets Q' \cup \{q_0', q_f'\}$
\STATE $\delta'(q_0', q_0) = \varepsilon$
\FORALL{$q \in F$}
\STATE $\delta'(q, q_f') = \varepsilon$
\ENDFOR
\FORALL{state $q$ in $Q'$ except $q_0'$ and $q_f'$}
\STATE $Q' \gets Q' \setminus \{q\}$
\FORALL{state $q_i$ in $Q'$ except $q_f'$}
\FORALL{state $q_j$ in $Q'$ except $q_0'$}
\STATE \textbf{Suppose} $\delta'(q_i, q) = R_1$, $\delta'(q, q) = R_2$, $\delta'(q, q_j) = R_3$, and $\delta'(q_i, q_j) = R_4$
\STATE $\delta'(q_i, q_j) = ((R_1)(R_2)^* R_3) \cup (R_4)$
\ENDFOR
\ENDFOR
\ENDFOR
\RETURN $\delta'(q_0', q_f')$
\end{algorithmic}
\end{algorithm}