profile pic
⌘ '
raccourcis clavier

elements

alphabet

An alphabet Σ\Sigma is any finite set

i.e: Σ={0,1}\Sigma =\{0,1\}

A string is a finite sequence of elements from Σ\Sigma

i.e: Given Σ={0,1}\Sigma = \{0,1\} string 011011011011\ldots

empty string

Or also known as ϵ\epsilon

We get length of a string for given Σ\Sigma: aaba=4\mid aaba \mid = 4

or a3aaa=3\mid a^3 \mid \equiv \mid aaa \mid = 3

set of string

the set of all string over Σ\Sigma be Σ\Sigma^{*}

implication:

  • Σ    Σ is infinite\Sigma \neq \emptyset \implies \Sigma^{*} \text{ 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    xy=101111x = 101, y=111 \implies xy=101111

xn=xxn1x0=ϵxyz=x(yz)xy=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}

language

A language LL is a set of string that conform to a set of rules.

ops: L1L2L_{1} \cup L_{2}, L1L2L_{1} \cap L_{2} , ¬L={xxΣx∉L}\neg L = \{ x \mid x \in \Sigma^{*} \wedge x \not\in L\}, L1L2={xyxLyL2}L_{1}L_{2}=\{ xy \mid x \in L \wedge y \in L_{2} \}

properties:

  • L0={ϵ}L^0 = \{ \epsilon \}
  • Ln=LLn1L^n = L L^{n-1}

Important

Σ=i=0Σ=Σ0Σ1\Sigma^{*} = \bigcup_{i=0}^{\infty} \Sigma = \Sigma^0 \cup \Sigma^1 \ldots

definition

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

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}

Or displayed as a transition table:

Stateab
→121
232
343
*444

language.

Language of machine L(M)\mathcal{L}(M) is the set of strings M accepts, such that L(M)Σ\mathcal{L}(M) \in \Sigma^{*}

L(M)={wΣδ(s,w)F}\mathcal{L}(M) = \{w \in \Sigma^{*} | \delta(s, w) \in F\}

Assumption: Σ={a,b}\Sigma = \{a, b\}

Questions

Find DFA MM such that L(M)=\mathcal{L}(M)= the following

  1. {xabxΣ}\{ xab \mid x \in \Sigma^{*} \}
  2. {xx % 2=0}\{ x \mid |x| \space \% \space 2 = 0 \}
  3. {xx is a binary string even number},Σ={0,1}\{ x \mid \text{x is a binary string even number}\}, \Sigma = \{0, 1\}
  4. {x"abc"x},Σ={a,b,c}\{ x \mid "abc" \in x \}, \Sigma = \{a, b, c\}
  5. {xa is the second last char of x}\{ x \mid \text{a is the second last char of x} \}
  6. {anbnn0}\{ a^n \cdot b^n \mid n \ge 0 \}
  7. {xa is the fifth last char of x}\{ x \mid \text{a is the fifth last char of x} \}
  8. \emptyset
  9. Σ\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}

properties

δ^(ρ,ϵ)=ρδ^(ρ,xa)=δ(δ^(ρ,x),a)\begin{aligned} \hat{\delta} (\rho, \epsilon) &= \rho \\ \hat{\delta} (\rho, xa) &= \delta (\hat{\delta }(\rho, x), a) \end{aligned}

acceptance

definition

MM accepts string xx iff δ^(s,x)F\hat{\delta } (s,x) \in F

Or L(M)={xδ^(s,x)F}\mathcal{L}(M) = \{x \mid \hat{\delta}(s,x) \in F \}

Q: Create DFA MM where Σ={0,1}\Sigma = \{0,1\} such that L(M)={xx 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)={ann0}L(M)={anbmn,m0}L(M)={anbn0n3}L(M)={anbnn0}L(M)={xx[2]=a}L(M)={xx[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}

Important

4 cannot be solved with DFA, or 4 is irregular

regular

Abstract

A language L\mathcal{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

If L1L_{1} and L2L_{2} are regular:

  1. ¬L\neg L is regular (closed under comparison)
  2. L1L2L_{1} \cap L_{2}
  3. L1L2L_{1} \cup L_{2}

proof (1)

Let M=(Q,Σ,ta,s,F)M = (Q, \Sigma, \nabla ta, s, F) and M=(Q,Σ,δ,s,QF)M^{'} = (Q, \Sigma, \delta, s, Q-F)

L(M)=¬L(M)\mathcal{L}(M^{'}) = \neg \mathcal{L}(M)

Or ¬L=L(M)\neg L = \mathcal{L}(M^{'})

proof (2)

Let L1L_1 and L2L_2 be regular languages, there M1M2 s.t M1=(Q1,Σ,δ1,s1,F1)M2=(Q2,Σ,δ2,s2,F2)\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}) and L(M1)=LL(M2)=L2\mathcal{L}(M_{1})=L \cap \mathcal{L}(M_{2}) = L_{2}