Skip to content
PostTheory Of Computation / Lecture

04-TOC-RL

2024-10-26
Back to Blog

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|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|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.

Algorithm 2 Convert NFAε_\varepsilon to 2-state gNFA

Input: An NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F)

Output: A regular expression which defines L(N)L(N)

1:NNN' \gets N // convert the domain and codomain of the transition function

2:QQ{q0,qf}Q' \gets Q' \cup \{q_0', q_f'\}

3:δ(q0,q0)=ε\delta'(q_0', q_0) = \varepsilon

4:for all qFq \in F do

5:δ(q,qf)=ε\delta'(q, q_f') = \varepsilon

6:end for

7:for all state qq in QQ' except q0q_0' and qfq_f' do

8:QQ{q}Q' \gets Q' \setminus \{q\}

9:for all state qiq_i in QQ' except qfq_f' do

10:for all state qjq_j in QQ' except q0q_0' do

11:Suppose δ(qi,q)=R1\delta'(q_i, q) = R_1, δ(q,q)=R2\delta'(q, q) = R_2, δ(q,qj)=R3\delta'(q, q_j) = R_3, and δ(qi,qj)=R4\delta'(q_i, q_j) = R_4

12:δ(qi,qj)=((R1)(R2)R3)(R4)\delta'(q_i, q_j) = ((R_1)(R_2)^* R_3) \cup (R_4)

13:end for

14:end for

15:end for

16:return δ(q0,qf)\delta'(q_0', q_f')