跳转至

Lecture 2

Non-deterministic finite automata

Definition

A non-deterministic finite automata (NFA) is M=(K,Σ,Δ,s,F)M = (K, \Sigma, \Delta, s, F), where

  • KK is a finite set of states.
  • Σ\Sigma is the input alphabet.
  • sks \in k is initial state.
  • FkF \subseteq k is the set of final states.
  • Δ\Delta is a transition relation.

    Δ(K×(Σ{e}))×K \Delta \subseteq (K \times (\Sigma \cup \{e\})) \times K

Configurations and yields are defined similarly to DFA.

MM accepts wΣw \in \Sigma^* if (s,w)M(q,e)(s, w) \vdash_M^* (q, e) for some qFq \in F.

For L(M)={wΣ:M accepts w}L(M) = \{ w \in \Sigma^*: M \text{ accepts } w \}, we say MM accepts L(M)L(M).

The difference between DFA and NFA is that NFA allows

  • more than one choice for next state.
  • e-transition.
state diagram of NFA

Insight | A Magic

We assume that NFA always makes the right guess.

Example

Construct an FA that accepts

L={w{a,b} the second symbol from the end of w is b.} L = \{w \in \{a, b\}^* | \text{ the second symbol from the end of $w$ is $b$.}\}

Theorem

DFA is equvilent to NFA.

  •  DFA M, NFA M, s.t. L(M)=L(M).\forall \text{ DFA } M', \exist \text{ NFA } M,\ s.t.\ L(M) = L(M').
  •  NFA M, DFA M, s.t. L(M)=L(M).\forall \text{ NFA } M, \exist \text{ DFA } M',\ s.t.\ L(M) = L(M').

Proof

The first claim is trivial. For the second claim,

Idea DFA MM' simulates "tree-like computation" of NFA MM.

 NFA M=(K,Σ,Δ,s,F)\forall \text{ NFA } M' = (K, \Sigma, \Delta, s, F), we construct a DFA M=(K,Σ,δ,s,F)M' = (K', \Sigma, \delta, s', F'), where

  • K=2K={QQK}K' = 2^K = \{Q | Q \subseteq K\}.
  • F={QKQF}F' = \{Q \subseteq K | Q \cap F \neq \emptyset\}.
  • s=E(s)s' = E(s), where E(q)={pK(q,e)M(p,e)}E(q) = \{p \in K | (q, e) \vdash_M^* (p, e) \}, qK\forall q \in K.
  • QK,aΣ,  δ(Q,a)=qQp:(q,a,p)ΔE(p)\forall Q \in K', a \in \Sigma,\ \ \delta(Q, a) = \bigcup\limits_{q \in Q} \bigcup\limits_{p : (q, a, p) \in \Delta} E(p).

Then we claim that p,qK,wΣ,(p,w)M(q,e) iff (E(p),w)M(Q,e), where qQ\forall p, q \in K, w \in \Sigma^*, (p, w) \vdash_M^* (q, e) \text{ iff } (E(p), w) \vdash_{M'}^* (Q, e), \text{ where } q \in Q. (We can prove it by induction on w|w|)

Thus, DFA MM' accepts ww \Leftrightarrow NFA MM accepts ww.

Example

NFA

DFA

Closure Property (Cont.)

Since the equivalence of NFA and DFA, so a language is regular if it's accepted by some NFA. Now we can prove the following theorem by NFA.

Theorem

If AA and BB are regular, so is ABA \cdot B.

Proof

Since AA and BB are regular, thus there exist NFAs MA=(KA,Σ,ΔA,sA,FA)M_A = (K_A, \Sigma, \Delta_A, s_A, F_A) and MB=(KB,Σ,ΔB,sB,FB)M_B = (K_B, \Sigma, \Delta_B, s_B, F_B) which accepts AA and BB respectively.

We construct an NFA M=(K,Σ,Δ,s,F)M_\circ = (K_\circ, \Sigma, \Delta_\circ, s_\circ, F_\circ), where

  • K=KAKBK_\circ = K_A \cup K_B.
  • s=sAs_\circ = s_A.
  • F=FBF_\circ = F_B.
  • Δ=ΔAΔB{(q,e,sB)qFA}\Delta_\circ = \Delta_A \cup \Delta_B \cup \{(q, e, s_B) | q \in F_A\}.

Theorem

If AA is regular, so is AA^*.


最后更新: 2024.01.29 15:36:20 CST
创建日期: 2023.10.01 15:23:00 CST