Skip to content

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 : AB=x|xA or xB
  • Concatenation: AB={xyxA and yB}

Star

A={x1x2xk|k0 and each xiA}

Note: each xi is a string in the language A. And x1x2xk is the concatenation of x1,x2 , until xk. Equivalently, A=A0A1A2

+ Def: Star operator

Let A be a language. An for nN is recursively define

  • A0={ϵ}
  • An=An1A$$A^{*} = \cup_{i\in \mathbb{N}} A^{i}$$

Complement

Let M=(Q,Σ,δ,q0,F) be an arbitrary DFA. And we construct a new DFA M=(Q,Σ,δ,q0,QF). Prove that L(M)=L(M).

Note:

  • QF is the set difference.
  • L(M)=ΣL(M) is the set complement.

The goal L(M)=L(M) is understood as set equality.
Thus, we need to prove wΣ, wL(M)wL(M).

()
Assume wL(M).
Then wL(M).
Thus, DFA M rejects w.
In other words, DFA M halts on a non-final state qx by consuming all symbols in w.
By the construction of M, qx is a final state of M.
Thus, M accepts w, and wL(M).


()
Assume wL(M).
DFA M accepts w.
In other words, DFA M halts on a final state qy by consuming all symbols in w.
By the construction of M, qy is a non-final state of M.
Thus, M rejects w, so wL(M).
Thus, wL(M).

L(M)=L(M).


Let Σ={0,1},{A={00,1}},and B={10,1}.

  • AB={00,1,10}
  • AB={0010,001,110,11}
  • A0={ε}
  • A1={00,1}
  • A2={0000,001,100,11}
  • A={ε,00,1,0000,001,100,11,}

Closure

+ Theorem (Closure)

Regular language is closed under union, concatenation, star and complement.

if A and B are two regular languages, then AB, AB, and A are also regular languages.

EaP8bA

Construct an NFA for AB.

Construct an NFA for AB.

Construct an NFA for A.

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)

R is a regular expression over Σ if R is (Base Case)

  • a for some aΣ,
  • ϵ, or

(Recursion)

  • (R1R2), where R1 and R2 are regular expressions,
  • R1R2, where R1 and R2 are regular expressions, or
  • R1, where R1 is a regular expression.

Languages Defined by Regular Expression

+ Def: Let $R$ be a regular expression. The language $L(R)$ defined by $R$ is

Base case:

  • L()=,
  • L(ϵ)={ϵ},
  • aΣ, L(a)={a}.

Recursion:

  • if R=R1R2, then L(R)=L(R1)L(R2)
  • if R=R1R2, then L(R)=L(R1)L(R2)
  • if R=R1, then L(R)=L(R1)

Example:

Suppose Σ={0,1}. Describe the language defined by the following regular expressions in English.

  • 010
  • Σ1Σ
  • (0ϵ)(1ϵ)
  • (ΣΣ)
  • Σ Match nothing

Equivalence of Regular Expression and Finite Automata

+ Theorem

Regular expressions are equivalent to finite automata.

The proof has two steps.

  1. The language defined by a regular expression can be recognized by a finite automaton.
  2. 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

  • δ:(Q{qf})×(Q{q0})R

Suppose δ(a,b)R

  • It means transition from a to b requires R.
  • If the GNFA has only 2 states q0 and qf, 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.
pseudo
\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}