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 : A∪B=x|x∈A or x∈B
  • Concatenation: A∘B={xy∣x∈A and y∈B}

Star ​

A∗={x1x2…xk|k≥0 and each xi∈A}

Note: each xi is a string in the language A. And x1x2…xk is the concatenation of x1,x2 , until xk. Equivalently, A∗=A0∪A1∪A2∪…

+ Def: Star operator

Let A be a language. An for n∈N is recursively define

  • A0={ϵ}
  • An=An−1∘A$$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,Q∖F). Prove that L(M―)=L(M′).

Note:

  • Q∖F 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∈Σ∗, w∈L(M―)⟺w∈L(M′).

(⇒)
Assume w∈L(M―).
Then w∉L(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 w∈L(M′).


(⇐)
Assume w∈L(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 w∉L(M).
Thus, w∈L(M―).

L(M―)=L(M′).


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

  • A∪B={00,1,10}
  • A∘B={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 A∪B, A∘B, and A∗ are also regular languages.

EaP8bA

Construct an NFA for A∪B. ​

Construct an NFA for A∘B. ​

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)

  • (R1∪R2), where R1 and R2 are regular expressions,
  • R1∘R2, 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=R1∪R2, then L(R)=L(R1)∪L(R2)
  • if R=R1∘R2, 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.

  • 0∗10∗
  • Σ∗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:N′←NN' \gets N // convert the domain and codomain of the transition function

2:Q′←Q′∪{q0′,qf′}Q' \gets Q' \cup \{q_0', q_f'\}

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

4:for all q∈Fq \in F do

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

6:end for

7:for all state qq in Q′Q' except q0′q_0' and qf′q_f' do

8:Q′←Q′∖{q}Q' \gets Q' \setminus \{q\}

9:for all state qiq_i in Q′Q' except qf′q_f' do

10:for all state qjq_j in Q′Q' except q0′q_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')