Deterministic Finite Automata elements
An alphabet Σ \Sigma Σ is any finite set
i.e: Σ = { 0 , 1 } \Sigma =\{0,1\} Σ = { 0 , 1 }
A string is a finite sequence of elements from Σ \Sigma Σ
i.e: Given Σ = { 0 , 1 } \Sigma = \{0,1\} Σ = { 0 , 1 } string 011011 … 011011\ldots 011011 …
Or also known as ϵ \epsilon ϵ
We get length of a string for given Σ \Sigma Σ : ∣ a a b a ∣ = 4 \mid aaba \mid = 4 ∣ aaba ∣= 4
or ∣ a 3 ∣ ≡ ∣ a a a ∣ = 3 \mid a^3 \mid \equiv \mid aaa \mid = 3 ∣ a 3 ∣≡∣ aaa ∣= 3
set of string
the set of all string over Σ \Sigma Σ be Σ ∗ \Sigma^{*} Σ ∗
implication:
Σ ≠ ∅ ⟹ Σ ∗ is infinite \Sigma \neq \emptyset \implies \Sigma^{*} \text{ is infinite} Σ = ∅ ⟹ Σ ∗ is infinite
All elements of Σ ∗ \Sigma^{*} Σ ∗ is finite
ϵ ∈ Σ ∗ ϵ ∉ Σ Σ = ∅ ⟹ Σ ∗ = { ϵ } \begin{aligned}
\epsilon &\in \Sigma^{*} \\
\epsilon &\not\in \Sigma \\
\Sigma &= \emptyset \implies \Sigma^{*} = \{ \epsilon \}
\end{aligned} ϵ ϵ Σ ∈ Σ ∗ ∈ Σ = ∅ ⟹ Σ ∗ = { ϵ }
concatenation
x = 101 , y = 111 ⟹ x y = 101111 x = 101, y=111 \implies xy=101111 x = 101 , y = 111 ⟹ x y = 101111
x n = x x n − 1 x 0 = ϵ x y z = x ( y z ) ∣ x y ∣ = ∣ x ∣ + ∣ y ∣ ϵ x = x ϵ = x \begin{align}
x^n &= x x^{n-1} \\
x^0 &= \epsilon \\
xyz &= x(yz) \\
|xy| &= |x| + |y| \\
\epsilon x &= x \epsilon = x
\end{align} x n x 0 x yz ∣ x y ∣ ϵ x = x x n − 1 = ϵ = x ( yz ) = ∣ x ∣ + ∣ y ∣ = x ϵ = x
language
A language L L L is a set of string that conform to a set of rules.
ops: L 1 ∪ L 2 L_{1} \cup L_{2} L 1 ∪ L 2 , L 1 ∩ L 2 L_{1} \cap L_{2} L 1 ∩ L 2 , ¬ L = { x ∣ x ∈ Σ ∗ ∧ x ∉ L } \neg L = \{ x \mid x \in \Sigma^{*} \wedge x \not\in L\} ¬ L = { x ∣ x ∈ Σ ∗ ∧ x ∈ L } , L 1 L 2 = { x y ∣ x ∈ L ∧ y ∈ L 2 } L_{1}L_{2}=\{ xy \mid x \in L \wedge y \in L_{2} \} L 1 L 2 = { x y ∣ x ∈ L ∧ y ∈ L 2 }
properties:
L 0 = { ϵ } L^0 = \{ \epsilon \} L 0 = { ϵ }
L n = L L n − 1 L^n = L L^{n-1} L n = L L n − 1
Σ ∗ = ⋃ i = 0 ∞ Σ = Σ 0 ∪ Σ 1 … \Sigma^{*} = \bigcup_{i=0}^{\infty} \Sigma = \Sigma^0 \cup \Sigma^1 \ldots Σ ∗ = ⋃ i = 0 ∞ Σ = Σ 0 ∪ Σ 1 …
definition
DFA M = ( Q , Σ , δ , s , F ) Q : finite set of states Σ : finite alphabet δ : Q × Σ → Q → δ : Q × Σ → Q s : start state , s ∈ Q F : set of final states , F ⊆ Q \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*} DFA M Q Σ δ s F = ( Q , Σ , δ , s , F ) : finite set of states : finite alphabet : Q × Σ → Q → δ : Q × Σ → Q : start state , s ∈ Q : set of final states , F ⊆ Q
examples
Ex: Σ = { a , b } \Sigma = \{a, b\} Σ = { a , b } . Creates a DFA M M M that accepts all strings that contains at least three a’s.
Q = { s 1 , s 2 , s 3 , s 4 } s = 1 F = { s 4 } \begin{align*}
Q &= \{s_1, s_2, s_3, s_4\} \\\
s &= 1 \\\
F &= \{s_4\} \\\
\end{align*} Q s F = { s 1 , s 2 , s 3 , s 4 } = 1 = { s 4 }
Transition function:
δ ( 1 , a ) = s 2 δ ( 1 , b ) = s 1 δ ( 2 , a ) = s 3 δ ( 2 , b ) = s 2 δ ( 3 , a ) = s 4 δ ( 3 , b ) = s 3 δ ( 4 , a ) = δ ( 4 , b ) = s 4 \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*} δ ( 1 , a ) = s 2 δ ( 1 , b ) = s 1 δ ( 2 , a ) = s 3 δ ( 2 , b ) = s 2 δ ( 3 , a ) = s 4 δ ( 3 , b ) = s 3 δ ( 4 , a ) = δ ( 4 , b ) = s 4
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
The following is the transfer function:
δ ( 1 , a ) = 2 δ ( 2 , a ) = 3 δ ( 3 , a ) = 4 δ ( ρ , b ) = ρ ( ∀ ρ ∣ ρ ∈ Q s.t δ ( ρ , b ) = ρ ) \begin{aligned}
\delta (1,a) &= 2 \\
\delta (2, a) &= 3 \\
\delta (3,a) &= 4 \\
\delta (\rho, b) &= \rho (\forall \rho \mid \rho \in Q \text{ s.t } \delta (\rho,b)=\rho)
\end{aligned} δ ( 1 , a ) δ ( 2 , a ) δ ( 3 , a ) δ ( ρ , b ) = 2 = 3 = 4 = ρ ( ∀ ρ ∣ ρ ∈ Q s.t δ ( ρ , b ) = ρ )
Or displayed as a transition table:
language.
Language of machine L ( M ) \mathcal{L}(M) L ( M ) is the set of strings M accepts, such that L ( M ) ∈ Σ ∗ \mathcal{L}(M) \in \Sigma^{*} L ( M ) ∈ Σ ∗
L ( M ) = { w ∈ Σ ∗ ∣ δ ( s , w ) ∈ F } \mathcal{L}(M) = \{w \in \Sigma^{*} | \delta(s, w) \in F\} L ( M ) = { w ∈ Σ ∗ ∣ δ ( s , w ) ∈ F }
Assumption: Σ = { a , b } \Sigma = \{a, b\} Σ = { a , b }
Find DFA M M M such that L ( M ) = \mathcal{L}(M)= L ( M ) = the following
{ x a b ∣ x ∈ Σ ∗ } \{ xab \mid x \in \Sigma^{*} \} { x ab ∣ x ∈ Σ ∗ }
{ x ∣ ∣ x ∣ % 2 = 0 } \{ x \mid |x| \space \% \space 2 = 0 \} { x ∣ ∣ x ∣ % 2 = 0 }
{ x ∣ x is a binary string even number } , Σ = { 0 , 1 } \{ x \mid \text{x is a binary string even number}\}, \Sigma = \{0, 1\} { x ∣ x is a binary string even number } , Σ = { 0 , 1 }
{ x ∣ " a b c " ∈ x } , Σ = { a , b , c } \{ x \mid "abc" \in x \}, \Sigma = \{a, b, c\} { x ∣ " ab c " ∈ x } , Σ = { a , b , c }
{ x ∣ a is the second last char of x } \{ x \mid \text{a is the second last char of x} \} { x ∣ a is the second last char of x }
{ a n ⋅ b n ∣ n ≥ 0 } \{ a^n \cdot b^n \mid n \ge 0 \} { a n ⋅ b n ∣ n ≥ 0 }
{ x ∣ a is the fifth last char of x } \{ x \mid \text{a is the fifth last char of x} \} { x ∣ a is the fifth last char of x }
∅ \emptyset ∅
Σ ∗ \Sigma^{*} Σ ∗
stateDiagram-v2
direction LR
classDef accepting fill:#4CAF50,stroke:#333,stroke-width:2px
classDef start fill:#FFD700,stroke:#333,stroke-width:2px
s0: q0
s1: q1
s2: q2
[*] --> s0
s0 --> s0: b
s0 --> s1: a
s1 --> s0: a
s1 --> s2: b
s2 --> s0: a
s2 --> s1: b
class s2 accepting
class s0 start
stateDiagram-v2
direction LR
classDef accepting fill:#4CAF50,stroke:#333,stroke-width:2px
classDef start fill:#FFD700,stroke:#333,stroke-width:2px
s0: q0
s1: q1
[*] --> s0
s0 --> s1: a,b
s1 --> s0: a,b
class s0 accepting
class s0 start
stateDiagram-v2
direction LR
classDef accepting fill:#4CAF50,stroke:#333,stroke-width:2px
s0: q0
s1: q1
[*] --> s0
s0 --> s1: 0
s1 --> s0: 1
s0 --> s0: 1
s1 --> s1: 0
class s1 accepting
transfer function
δ : Q × Σ → Q δ ^ : Q × Σ ∗ → Q \begin{aligned}
\delta: Q \times \Sigma &\to Q \\
\hat{\delta}: Q \times \Sigma^{*} &\to Q
\end{aligned} δ : Q × Σ δ ^ : Q × Σ ∗ → Q → Q
δ ^ ( ρ , ϵ ) = ρ δ ^ ( ρ , x a ) = δ ( δ ^ ( ρ , x ) , a ) \begin{aligned}
\hat{\delta} (\rho, \epsilon) &= \rho \\
\hat{\delta} (\rho, xa) &= \delta (\hat{\delta }(\rho, x), a)
\end{aligned} δ ^ ( ρ , ϵ ) δ ^ ( ρ , x a ) = ρ = δ ( δ ^ ( ρ , x ) , a )
acceptance
M M M accepts string x x x iff δ ^ ( s , x ) ∈ F \hat{\delta } (s,x) \in F δ ^ ( s , x ) ∈ F
Or L ( M ) = { x ∣ δ ^ ( s , x ) ∈ F } \mathcal{L}(M) = \{x \mid \hat{\delta}(s,x) \in F \} L ( M ) = { x ∣ δ ^ ( s , x ) ∈ F }
Q: Create DFA M M M where Σ = { 0 , 1 } \Sigma = \{0,1\} Σ = { 0 , 1 } such that L ( M ) = { x ∣ x is a binary string representation of a multiple of 3 or x = 6 } \mathcal{L}(M) = \{x \mid \text{x is a binary string representation of a multiple of 3 or x = 6}\} L ( M ) = { x ∣ x is a binary string representation of a multiple of 3 or x = 6 }
L ( M ) = { a n ∣ n ≥ 0 } L ( M ) = { a n b m ∣ n , m ≥ 0 } L ( M ) = { a n b n ∣ 0 ≤ n ≤ 3 } L ( M ) = { a n b n ∣ n ≥ 0 } L ( M ) = { x ∣ x [ − 2 ] = a } L ( M ) = { x ∣ x [ − 5 ] = a } \begin{align}
\mathcal{L}(M) &= \{a^n \mid n \ge 0\} \\
\mathcal{L}(M) &= \{a^nb^m \mid n,m \ge 0\} \\
\mathcal{L}(M) &= \{a^nb^n \mid 0 \le n \le 3\} \\
\mathcal{L}(M) &= \{a^nb^n \mid n\ge 0\} \\
\mathcal{L}(M) &= \{x \mid x[-2] = a\} \\
\mathcal{L}(M) &= \{x \mid x[-5] = a\}
\end{align} L ( M ) L ( M ) L ( M ) L ( M ) L ( M ) L ( M ) = { a n ∣ n ≥ 0 } = { a n b m ∣ n , m ≥ 0 } = { a n b n ∣ 0 ≤ n ≤ 3 } = { a n b n ∣ n ≥ 0 } = { x ∣ x [ − 2 ] = a } = { x ∣ x [ − 5 ] = a }
4 cannot be solved with DFA, or 4 is irregular
regular
A language L \mathcal{L} L is a regular language iff ∃ M s.t M is a DFA and L ( M ) = L \exists M \text{ s.t } M \text{ is a DFA and } \mathcal{L}(M)=L ∃ M s.t M is a DFA and L ( M ) = L
If L 1 L_{1} L 1 and L 2 L_{2} L 2 are regular:
¬ L \neg L ¬ L is regular (closed under comparison)
L 1 ∩ L 2 L_{1} \cap L_{2} L 1 ∩ L 2
L 1 ∪ L 2 L_{1} \cup L_{2} L 1 ∪ L 2
proof (1)
Let M = ( Q , Σ , ∇ t a , s , F ) M = (Q, \Sigma, \nabla ta, s, F) M = ( Q , Σ , ∇ t a , s , F ) and M ′ = ( Q , Σ , δ , s , Q − F ) M^{'} = (Q, \Sigma, \delta, s, Q-F) M ′ = ( Q , Σ , δ , s , Q − F )
L ( M ′ ) = ¬ L ( M ) \mathcal{L}(M^{'}) = \neg \mathcal{L}(M) L ( M ′ ) = ¬ L ( M )
Or ¬ L = L ( M ′ ) \neg L = \mathcal{L}(M^{'}) ¬ L = L ( M ′ )
proof (2)
Let L 1 L_1 L 1 and L 2 L_2 L 2 be regular languages, there ∃ M 1 ∩ M 2 s.t M 1 = ( Q 1 , Σ , δ 1 , s 1 , F 1 ) ∩ M 2 = ( Q 2 , Σ , δ 2 , s 2 , F 2 ) \exists M_{1} \cap M_{2} \text{ s.t } M_{1}=(Q_{1}, \Sigma,\delta_{1}, s_{1},F_{1}) \cap M_{2}=(Q_{2}, \Sigma, \delta_{2}, s_{2}, F_{2}) ∃ M 1 ∩ M 2 s.t M 1 = ( Q 1 , Σ , δ 1 , s 1 , F 1 ) ∩ M 2 = ( Q 2 , Σ , δ 2 , s 2 , F 2 ) and L ( M 1 ) = L ∩ L ( M 2 ) = L 2 \mathcal{L}(M_{1})=L \cap \mathcal{L}(M_{2}) = L_{2} L ( M 1 ) = L ∩ L ( M 2 ) = L 2