Book: pdf

Q1: T/F, if F explain why. Q4: regular expression, 5 separate q Q2/Q3: DFAs and NFAs

  • Product construction: \cap \cup of DFAs
  • Subset construction: NFA to DFA
  • Quotient construction: State minimization

Set theory

Complement in Σ\Sigma^{*}:

L=ΣL\overline{L} = \Sigma^{*} - L

associative:

(AB)C=A(BC),(AB)C=A(BC),(AB)C=A(BC).\begin{align*} (A \cup B) \cup C &= A \cup (B \cup C), \\ (A \cap B) \cap C &= A \cap (B \cap C), \\ (AB)C &= A(BC). \end{align*}

commutative:

AB=BAAB=BA\begin{align*} A \cup B &= B \cup A \\ A \cap B &= B \cap A \end{align*}

null set

null set \emptyset is the identity for \cup and annihilator for set concatenation

A=AA \cup \emptyset = A and A=A=A \emptyset = \emptyset A = \emptyset

set {ϵ}\{\epsilon\} is an identity for set concatenation {ϵ}A=A{ϵ}=A\{\epsilon\}A = A\{\epsilon\} = A

Set union and intersection are distributive over set concatenation

A(BC)=(AB)(AC) A(BC)=(AB)(AC)\begin{align*} A \cup (B \cap C) &= (A \cup B) \cap (A \cup C) \\\ A \cap (B \cup C) &= (A \cap B) \cup (A \cap C) \end{align*}

Set concatenation distributes over union

A(BC)=ABAC (AB)C=ACBC\begin{align*} A(B \cup C) &= AB \cup AC \\\ (A \cup B)C &= AC \cup BC \end{align*}

DFA

definition

Σ:set of all strings based off Σ\Sigma^{*}: \text{set of all strings based off }\Sigma DFAM=(Q,Σ,δ,s,F) Q:finite set of states Σ:finite alphabet δ:Q×ΣQδ:Q×ΣQ s:start state,sQ F:set of final states,FQ \begin{align*} \text{DFA}\quad M &= (Q, \Sigma, \delta, s, F) \\\ Q &: \text{finite set of states} \\\ \Sigma &: \text{finite alphabet} \\\ \delta &: Q \times \Sigma \rightarrow Q \rightarrow \delta: Q \times \Sigma \rightarrow Q \\\ s &: \text{start state},\quad s\in{Q} \\\ F &: \text{set of final states},\quad F\subseteq{Q} \\\ \end{align*}

examples

Ex: Σ={a,b}\Sigma = \{a, b\}. Creates a DFA MM that accepts all strings that contains at least three a’s.

Q={s1,s2,s3,s4} s=1 F={s4} \begin{align*} Q &= \{s_1, s_2, s_3, s_4\} \\\ s &= 1 \\\ F &= \{s_4\} \\\ \end{align*}

Transition function:

δ(1,a)=s2 δ(1,b)=s1 δ(2,a)=s3 δ(2,b)=s2 δ(3,a)=s4 δ(3,b)=s3 δ(4,a)=δ(4,b)=s4 \begin{align*} \delta(1, a) = s_2 \\\ \delta(1, b) = s_1 \\\ \delta(2, a) = s_3 \\\ \delta(2, b) = s_2 \\\ \delta(3, a) = s_4 \\\ \delta(3, b) = s_3 \\\ \delta(4, a) = \delta(4, b) = s_4 \\\ \end{align*}

representation:

stateDiagram-v2
    direction LR
    classDef accepting fill:#4CAF50,stroke:#333,stroke-width:2px
    classDef start fill:#FFD700,stroke:#333,stroke-width:2px

    s1: s1
    s2: s2
    s3: s3
    s4: s4

    [*] --> s1
    s1 --> s1: b
    s1 --> s2: a

    s2 --> s2: b
    s2 --> s3: a

    s3 --> s3: b
    s3 --> s4: a

    s4 --> s4: a,b

    class s4 accepting
    class s1 start

if in final string then accept, otherwise reject the string

Lien vers l'original

Let δ:Q×ΣQ\delta : Q \times \Sigma \rightarrow Q, thus δ^:Q×ΣQ\hat{\delta} : Q \times \Sigma^{*} \rightarrow Q

δ(q,c)p\delta(q, c) \rightarrow p therefore δ^(q,w)p\hat{\delta}(q, w) \rightarrow p

regularity

Important

δ^(q,ϵ)=q δ^(q,xa)=δ(δ^(q,x),a)\begin{align*} \hat{\delta}(q, \epsilon) &= q \\\ \hat{\delta}(q, xa) &= \delta(\hat{\delta}(q, x), a) \end{align*}

Important

a subset AΣA \subset \Sigma^{*} is regular if and only if there exists a DFA MM such that L(M)=L\mathcal{L}(M) = L

Important

All finite languages are regular, but not all regular languages are finite

examples

Show LL is regular where L={xx%3=0x=ϵ}L = \{ x \mid x \% 3 = 0 \cup x = \epsilon \}, with Σ={0,1}\Sigma = \{0, 1\}

Three states, q0,q1,q2q_{0}, q_{1}, q_{2}, where q0q_{0} denotes the string mod 3 is 0, q1q_{1} denotes the string mod 3 is 1, and q2q_{2} denotes the string mod 3 is 2.

x{0,1}δ(q0,x)=0    #x0 mod 3\forall x \in \{0, 1\} \rightarrow \delta(q_{0}, x) = 0 \iff \#x \equiv 0 \space mod \space 3, δ(q0,x)=q1    #x1 mod 3\delta(q_{0}, x) = q_{1} \iff \#x \equiv 1 \space mod \space 3, δ(q0,x)=q2    #x2 mod 3\delta(q_{0}, x) = q_{2} \iff \#x \equiv 2 \space mod \space 3

stateDiagram-v2
  direction LR

  [*] --> q0
  q0 --> q1 : 1
  q0 --> q0 : 0
  q1 --> q2 : 0
  q1 --> q0 : 1
  q2 --> q1 : 0
  q2 --> q2 : 1
  q0 --> [*]

product construction

Assume that A, B are regular, there are automata

M1=(Q1,Σ,δ1,s1,F1)M2=(Q2,Σ,δ2,s2,F2)M_1 = (Q_1, \Sigma, \delta_1, s_1, F_1) \quad M_2 = (Q_2, \Sigma, \delta_2, s_2, F_2)

Thus

M3=(Q3,Σ,δ3,s3,F3)M_{3} = (Q_{3}, \Sigma, \delta_3, s_{3}, F_{3})

where Q3=Q1×Q2Q_{3}=Q_{1} \times Q_{2}, s3=(s1,s2)s_{3} = (s_{1}, s_{2}), F3=F1×F2F_{3} = F_{1} \times F_{2}, and δ3((p,q),x)=(δ1(p,x),δ2(q,x))\delta_{3}((p, q), x) = (\delta_{1}(p, x), \delta_{2}(q, x))

with L(M1)=AL(M_{1}) = A and L(M2)=BL(M_{2}) = B, then ABA \cap B is regular.

Lemma 4.1

δ3((p,q),x)=(δ1(p,x),δ2(q,x)) xΣ\delta_3((p, q), x) = (\delta_1(p, x), \delta_2(q, x)) \space \forall x \in \Sigma^*

Complement set: QFQQ - F \in Q

Trivial machine L(M1)={}\mathcal{L}(M_{1}) = \{\}, L(M2)=Σ\mathcal{L}(M_{2}) = \Sigma^*, L(M3)={ϵ}\mathcal{L}(M_{3})=\{ \epsilon \}

De Morgan laws

AB=ABA \cup B = \overline{\overline{A} \cap \overline{B}}

Theorem 4.2

L(M3)=L(M1)L(M2)L(M_3) = L(M_1) \cap L(M_2)

L\overline{L} is regular

L1L2L_{1} \cap L_{2} is regular

L1L2L_{1} \cup L_{2} is regular


NFA

definition

Σ:set of all strings based off Σ\Sigma^{*}: \text{set of all strings based off }\Sigma NFAM=(Q,Σ,Δ,S,F) Q:finite set of states Σ:finite alphabet Δ:Q×ΣP(Q) S:Start states,SQ F:Final states,FQ \begin{align*} \text{NFA}\quad M &= (Q, \Sigma, \Delta, S, F) \\\ Q &: \text{finite set of states} \\\ \Sigma &: \text{finite alphabet} \\\ \Delta &: Q \times \Sigma \rightarrow P(Q) \\\ S &: \text{Start states},\quad S \subseteq Q \\\ F &: \text{Final states},\quad F \subseteq Q \\\ \end{align*} Lien vers l'original

transition function

Δ^:P(Q)×ΣP(Q)\hat{\Delta}: P(Q) \times \Sigma^* \rightarrow P(Q)

Δ^(A,a)=pΔ^(A,ε)Δ(p,a)  =pAΔ(p,a).\begin{align*} \hat{\Delta}(A, a) &= \bigcup_{p \in \hat{\Delta}(A, \varepsilon)} \Delta(p, a) \\\ & \\\ &= \bigcup_{p \in A} \Delta(p, a). \end{align*}

subset construction

acceptance

NN accepts xΣx \in \Sigma^* if

Δ^(s,x)F\hat{\Delta}(s, x) \cap F \neq \emptyset

Define L(N)={xΣN accepts x}L(N) = \{ x \in \Sigma^* \mid N\text{ accepts } x\}

Theorem 4.3

Every DFA (Q,Σ,δ,s,F)(Q, \Sigma, \delta, s, F) is equvalent to an NFA (Q,Σ,Δ,{s},F)(Q, \Sigma, \Delta, \{s\} , F) where Δ(p,a)={δ(p,a)}\Delta(p, a) = \{ \delta(p, a) \}

Lemma 6.1

For any x,yΣAQx, y \in \Sigma^* \land A \subseteq Q,

Δ^(s,xy)=Δ^(Δ^(s,x),y)\hat{\Delta}(s, xy) = \hat{\Delta}(\hat{\Delta}(s, x), y)

Lemma 6.2

Δ^\hat{\Delta} commutes with set union:

Δ^(iAi,x)=iΔ^(Ai,x)\hat{\Delta}(\bigcup_i A_i, x) =\bigcup_i \hat{\Delta}(A_i, x)

Let N=(QN,Σ,ΔN,SN,FN)N = (Q_N, \Sigma, \Delta_N, S_N, F_N) be arbitrary NFA. Let M be DFA M=(QM,Σ,δM,sM,FM)M = (Q_M, \Sigma, \delta_M, s_M, F_M) where:

QM=P(QN) δM(A,a)=Δ^N(A,a) sM=SN FM={AQNAFN}\begin{align*} Q_M &= P(Q_N) \\\ \delta_M(A, a) &= \hat{\Delta}_N(A, a) \\\ s_M &= S_N \\\ F_M &= \{ A \in Q_N \mid A \cap F_N \neq \emptyset \} \end{align*}

Lemma 6.3

For any AQNxΣA \subseteq Q_N \land x \in \Sigma^*

δ^M(A,x)=Δ^N(A,x)\hat{\delta}_M(A, x) = \hat{\Delta}_N(A, x)

Theorem 6.4

The automata M and N accept the same sets.

regex

atomic patterns are:

  • L(a)={a}L(a) = \{a\}
  • L(ϵ)={ϵ}L(\epsilon) = \{\epsilon\}
  • L()=L(\emptyset) = \emptyset
  • L(#)=ΣL(\#) = \Sigma: matched by any symbols
  • L(@)=ΣL(@) = \Sigma^*: matched by any string

compound patterns are formed by combining binary operators and unary operators.

redundancy

a+aaa^+ \equiv aa^*, αβ=α+β\alpha \cap \beta = \overline{\overline{\alpha} + \overline{\beta}}

if α\alpha and β\beta are patterns, then so are α+β,αβ,α,α+,α,αβ\alpha + \beta, \alpha \cap \beta, \alpha^*, \alpha^+, \overline{\alpha}, \alpha \beta

The following holds for x matches:

L(α+β)=L(α)L(β)L(\alpha + \beta) = L(\alpha) \cup L(\beta)

L(αβ)=L(α)L(β)L(\alpha \cap \beta) = L(\alpha) \cap L(\beta)

L(αβ)=L(α)L(β)={yzyL(α)zL(β)}L(\alpha\beta) = L(\alpha)L(\beta) = \{yz \mid y \in L(\alpha) \land z \in L(\beta)\}

L(α)=L(α)0L(α)1=L(α)L(\alpha^*) = L(\alpha)^0 \cup L(\alpha)^1 \cup \dots = L(\alpha)^*

L(α+)=L(α)+L(\alpha^+) = L(\alpha)^+

Theorem 7.1

Σ=L(#)=L(@)\Sigma^* = L(\#^*) = L(@)

Singleton set {x}=L(x)\{x\} = L(x)

Finite set: {x1,x2,,xm}=L(x1+x2++xm)\{x_{1},x_{2},\dots,x_m\} = L(x_{1}+x_{2}+\dots+x_m)

Theorem 9

α+(β+γ)(α+β)+γ(9.1)α+ββ+α(9.2)α+ϕα(9.3)α+αα(9.4)α(βγ)(αβ)γ(9.5)ϵααϵα(9.6)α(β+γ)αβ+αγ(9.7)(α+β)γαγ+βγ(9.8)ϕααϕϕ(9.9)ϵ+αα(9.10)ϵ+αα(9.11)β+αγγαβγ(9.12)β+γαγβαγ(9.13)(αβ)α(βα)(9.14)(αβ)α(α+β)(9.15)α(βα)(α+β)(9.16)(ϵ+α)α(9.17)αααα(9.18)\begin{array}{cccl} \alpha + (\beta + \gamma) & \equiv & (\alpha + \beta) + \gamma & (9.1) \\ \alpha + \beta & \equiv & \beta + \alpha & (9.2) \\ \alpha + \phi & \equiv & \alpha & (9.3) \\ \alpha + \alpha & \equiv & \alpha & (9.4) \\ \alpha(\beta\gamma) & \equiv & (\alpha\beta)\gamma & (9.5) \\ \epsilon \alpha & \equiv & \alpha\epsilon \equiv \alpha & (9.6) \\ \alpha(\beta + \gamma) & \equiv & \alpha\beta + \alpha\gamma & (9.7) \\ (\alpha + \beta)\gamma & \equiv & \alpha\gamma + \beta\gamma & (9.8) \\ \phi\alpha & \equiv & \alpha\phi \equiv \phi & (9.9) \\ \epsilon + \alpha^* & \equiv & \alpha^* & (9.10) \\ \epsilon + \alpha^* & \equiv & \alpha^* & (9.11) \\ \beta + \alpha\gamma \leq \gamma & \Rightarrow & \alpha^*\beta \leq \gamma & (9.12) \\ \beta + \gamma\alpha \leq \gamma & \Rightarrow & \beta\alpha^* \leq \gamma & (9.13) \\ (\alpha\beta)^* & \equiv & \alpha(\beta\alpha)^* & (9.14) \\ (\alpha^* \beta)^* \alpha^* & \equiv & (\alpha + \beta)^* & (9.15) \\ \alpha^* (\beta\alpha^*)^* & \equiv & (\alpha + \beta)^* & (9.16) \\ (\epsilon + \alpha)^* & \equiv & \alpha^* & (9.17) \\ \alpha\alpha^* & \equiv & \alpha^* \alpha & (9.18) \\ \end{array}

quotient automata

also known as DFA state minimization

definition

pq[p]=[q]p \approx q \equiv [p] = [q]

Define

M/ =(Q,Σ,δ,[s],F)M / \approx \space = (Q', \Sigma, \delta', [s], F')

where (13.1)

Q=Q/ δ([p],a)=[δ(p,a)] s=[s] F={[p]pF}\begin{align*} Q' &= Q / \approx \\\ \delta'([p], a) &= [\delta(p, a)] \\\ s' &= [s] \\\ F' &= \{ [p] \mid p \in F \} \end{align*}

Lemma 13.5

If pqp \approx q, then δ(p,a)δ(q,a)\delta(p, a) \approx \delta(q, a) equivalently, if [p]=[q][p] = [q], then [δ(p,a)]=[δ(q,a)][\delta(p, a)] = [\delta(q, a)]

Lemma 13.6

pF    [p]Fp \in F \iff [p] \in F'

Lemma 13.7

xΣ,δ^([p],x)=[δ^(p,x)]\forall x \in \Sigma^*, \hat{\delta'}([p], x) = [\hat{\delta}(p, x)]

Theorem 13.8

L(M/)=L(M)L(M / \approx) = L(M)

algorithm

  1. Table of all pairs {p,q}\{p, q\}
  2. Mark all pairs {p,q}\{p, q\} if pFqFqFpFp \in F \land q \notin F \lor q \in F \land p \notin F
  3. If there exists unmarked pair {p,q}\{p, q\}, such that {δ(p,a),δ(q,a)}\{ \delta(p, a), \delta(q, a) \} is marked, then mark {p,q}\{p, q\}
  4. pq    {p,q}p \approx q \iff \{p, q\} is not marked