70
Study Material 2IT70 Finite Automata and Process Theory Technische Universiteit Eindhoven June 11, 2014

Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Embed Size (px)

Citation preview

Page 1: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Study Material

2IT70 Finite Automata and Process Theory

Technische Universiteit Eindhoven

June 11, 2014

Page 2: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Study material

Updated reader: Chapters 2, 3 and 5

Hopcroft, Motwani & Ullman (2001)

Background reading: Chapters 1-7More specific: 2.2, 2.3, 2.5; 3.1, 3.2; 4.1-3; 5.1, 5.2; 6.1-3; 7.2

Exercises

Proofs

Theorem 2.13: from NFA to DFATheorem 2.27: Pumping Lemma for regular languagesTheorem 3.20: from CFG to parse treeTheorem 3.23: from parse tree to CFGTheorem 3.25: from CFG to PDATheorem 3.33: intersection of context-free and regular

2 IT70 (2014) Study Material 2 / 45

Page 3: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finite Automata

and Regular Languages

2IT70 Finite Automata and Process Theory

Technische Universiteit Eindhoven

July 16, 2014

Page 4: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Deterministic finite automaton

DFA D = (Q, Σ, δ, q0, F )

Q finite set of states

Σ finite alphabet

δ ∶ Q ×Σ→ Q transition function

q0 ∈ Q initial state

F ⊆ Q set of final states

L(D) = {w ∈ Σ∗ ∣ ∃q ∈ F ∶ (q0,w) ⊢∗D(q, ε)}

2 IT70 (2014) Finite Automata and Regular Languages 4 / 45

Page 5: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Language accepted by DFA

q0 q1 q2 q3

b

a

a a,b

ba

b

accepted language {w ∈ {a,b}∗ ∣ w has a substring aab }

2 IT70 (2014) Finite Automata and Regular Languages 5 / 45

Page 6: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Path sets

DFA D, state q

pathsetD(q) = {w ∈ Σ∗ ∣ (q0,w) ⊢

∗D(q, ε)}

q0 q1 q2

0

1

0

1

0,1

L = {w ∈ {0,1}∗ ∣ w has no substring 11}

state pathset regular expressions

q0 no substring 11 and no last symbol 1 0∗ (10+)∗

q1 no substring 11 and last symbol 1 0∗ (10+)∗1

q2 substring 11 (0 + 1)∗11(0 + 1)∗

2 IT70 (2014) Finite Automata and Regular Languages 6 / 45

Page 7: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Non-deterministic finite automaton with τ -moves

silent action τ ∉ Σ

NFA N = (Q, Σ, →, q0, F )

Q finite set of states

Σ finite alphabet

→ ∶ Q ×Στ → Q

transition relation

q0 ∈ Q initial state

F ⊆ Q set of final states

q0

q1

q2τ

aa a

b

language accepted by NFA N

L(N) = {w ∈ Σ∗ ∣ ∃q ∈ F ∶ (q0,w) ⊢∗N(q, ε)}

2 IT70 (2014) Finite Automata and Regular Languages 7 / 45

Page 8: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

One of two theorems (Theorem 2.13)

theorem

if L = L(N) for some NFA, then L = L(D) for some DFA

proof say N = (QN , Σ, →N , q0N,FN)

ε-closure E(q) = { q̄ ∈ QN ∣ (q, ε) ⊢∗N(q̄, ε)} for q ∈ QN

2 IT70 (2014) Finite Automata and Regular Languages 8 / 45

Page 9: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

One of two theorems (Theorem 2.13)

theorem

if L = L(N) for some NFA, then L = L(D) for some DFA

proof say N = (QN , Σ, →N , q0N,FN)

ε-closure E(q) = { q̄ ∈ QN ∣ (q, ε) ⊢∗N(q̄, ε)} for q ∈ QN

put D = (QD , Σ, δD , q0D, FD) with

set of states QD = P(QN)

transtion function δD(Q,a) = ⋃{E(q̄) ∣ q ∈ Q, qaÐ→N q̄ }

initial state q0D= E(q0

N)

final states FD = {Q ⊆ QN ∣ Q ∩ FN ≠ ∅}

2 IT70 (2014) Finite Automata and Regular Languages 8 / 45

Page 10: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

One of two theorems (Theorem 2.13)

theorem

if L = L(N) for some NFA, then L = L(D) for some DFA

proof say N = (QN , Σ, →N , q0N,FN)

ε-closure E(q) = { q̄ ∈ QN ∣ (q, ε) ⊢∗N(q̄, ε)} for q ∈ QN

put D = (QD , Σ, δD , q0D, FD) with

set of states QD = P(QN)

transtion function δD(Q,a) = ⋃{E(q̄) ∣ q ∈ Q, qaÐ→N q̄ }

initial state q0D= E(q0

N)

final states FD = {Q ⊆ QN ∣ Q ∩ FN ≠ ∅}

it holds that (q,w) ⊢∗N(q′, ε) iff

∃Q ′ ⊆ QN ∶ (E(q),w) ⊢∗D(Q ′, ε) and q′ ∈ Q ′

2 IT70 (2014) Finite Automata and Regular Languages 8 / 45

Page 11: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

One of two theorems (Theorem 2.13)

theorem

if L = L(N) for some NFA, then L = L(D) for some DFA

proof say N = (QN , Σ, →N , q0N,FN)

ε-closure E(q) = { q̄ ∈ QN ∣ (q, ε) ⊢∗N(q̄, ε)} for q ∈ QN

put D = (QD , Σ, δD , q0D, FD) with

set of states QD = P(QN)

transtion function δD(Q,a) = ⋃{E(q̄) ∣ q ∈ Q, qaÐ→N q̄ }

initial state q0D= E(q0

N)

final states FD = {Q ⊆ QN ∣ Q ∩ FN ≠ ∅}

it holds that (q,w) ⊢∗N(q′, ε) iff

∃Q ′ ⊆ QN ∶ (E(q),w) ⊢∗D(Q ′, ε) and q′ ∈ Q ′

then L(N) = L(D) follows ⊠2 IT70 (2014) Finite Automata and Regular Languages 8 / 45

Page 12: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Another NFA-to-DFA example

0

1

2

τa

τ

b

a

ac

{0,1,2}

{1,2}

{2}

b

c

aa

b

c

a

b c

a,b, c

2 IT70 (2014) Finite Automata and Regular Languages 9 / 45

Page 13: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Regular expressions

class REΣ of regular expressions over alphabet Σ

1 and 0

a for all a ∈ Σ

(r1 + r2) and (r1 ⋅ r2) for all r1, r2 ∈ REΣ

(r∗) for all r ∈ REΣ

interpretation as languages over Σ

2 IT70 (2014) Finite Automata and Regular Languages 10 / 45

Page 14: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Language of a regular expression

r L(r)

0 ∅

1 {ε}

a {a}

r1 + r2 L(r1) ∪L(r2)

r1 ⋅ r2 L(r1)L(r2)

r∗ L(r)∗

contatenation: L1L2 = {w1w2 ∣ w1 ∈ L1, w2 ∈ L2 }iteration: L∗ = {w1⋯wk ∣ k ⩾ 0, w1, . . . ,wk ∈ L}

2 IT70 (2014) Finite Automata and Regular Languages 11 / 45

Page 15: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finding a RE for a DFA

q0 q1

q2

a

b

ba

b

a

2 IT70 (2014) Finite Automata and Regular Languages 12 / 45

Page 16: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finding a RE for a DFA

qs q0 q1

q2 qf

1 a

b

ba

b

a 1

1

2 IT70 (2014) Finite Automata and Regular Languages 12 / 45

Page 17: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finding a RE for a DFA

qs q0 q1

qf

1

bb

a + bab

a1

b

2 IT70 (2014) Finite Automata and Regular Languages 12 / 45

Page 18: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finding a RE for a DFA

qs q0

qf

1

bb + (a + ba)b∗a

b + (a + ba)b∗

2 IT70 (2014) Finite Automata and Regular Languages 12 / 45

Page 19: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finding a RE for a DFA

qs

qf

(bb + (a + ba)b∗a)∗(b + (a + ba)b∗)

2 IT70 (2014) Finite Automata and Regular Languages 12 / 45

Page 20: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finding a RE for a DFA

q0 q1

q2

a

b

ba

b

a

qs q0 q1

q2 qf

1 a

b

ba

b

a 1

1

qs q0 q1

qf

1

bb

a + bab

a1

b

qs q0

qf

1

bb + (a + ba)b∗a

b + (a + ba)b∗

qs

qf

(bb + (a + ba)b∗a)∗(b + (a + ba)b∗)

2 IT70 (2014) Finite Automata and Regular Languages 12 / 45

Page 21: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Finding a RE for a DFA

q0 q1

q2

a

b

ba

b

a

qs q0 q1

q2 qf

1 a

b

ba

b

a 1

1

qs q0 q1

qf

1

bb

a + bab

a1

b

qs q0

qf

1

bb + (a + ba)b∗a

b + (a + ba)b∗

qs

qf

(bb + (a + ba)b∗a)∗(b + (a + ba)b∗)

R(D) = (bb + (a + ba) ⋅ b∗ ⋅ a)∗(b + (a + ba) ⋅ b∗)

2 IT70 (2014) Finite Automata and Regular Languages 12 / 45

Page 22: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Regular languages

L ⊆ Σ∗ is regular iff L = L(N) for some NFA N

theorem the following statement are equivalent

L is regular

L = L(D) for some DFA D

L = L(r) for some RE r

proof combine earlier results ⊠

2 IT70 (2014) Finite Automata and Regular Languages 13 / 45

Page 23: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Closure properties

theorem

if L1 and L2 are regular, then L1 ∪ L2 is regular

if L is regular, then L∗ is regular

if L1 and L2 are regular, then L1 ∩ L2 is regular

proof use a suitable representation for L1, L2 and L ⊠

2 IT70 (2014) Finite Automata and Regular Languages 14 / 45

Page 24: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

The Pumping Lemma (Theorem 2.27)

theorem if L ⊆ Σ∗ is a regular language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃x , y , z ∶ w = x y z ∧ ∣x y ∣ ⩽ m ∧ ∣y ∣ > 0 ∶

∀i ⩾ 0 ∶ x y iz ∈ L

2 IT70 (2014) Finite Automata and Regular Languages 15 / 45

Page 25: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

The Pumping Lemma (Theorem 2.27)

theorem if L ⊆ Σ∗ is a regular language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃x , y , z ∶ w = x y z ∧ ∣x y ∣ ⩽ m ∧ ∣y ∣ > 0 ∶

∀i ⩾ 0 ∶ x y iz ∈ L

proof suppose L = L(D) for DFA D

take m the number of states of D ⊠

2 IT70 (2014) Finite Automata and Regular Languages 15 / 45

Page 26: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Example non-regular languages

Pumping Lemma: if L ⊆ Σ∗ is a regular language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃x , y , z ∶ w = x y z ∧ ∣x y ∣ ⩽ m ∧ ∣y ∣ > 0 ∶

∀i ⩾ 0 ∶ x y iz ∈ L

the language L1 = { anbn ∣ n ⩾ 0} is not regular

the language L2 = {ww ∣ w ∈ {a,b}∗ } is not regular

2 IT70 (2014) Finite Automata and Regular Languages 16 / 45

Page 27: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Example non-regular languages

Pumping Lemma: if L ⊆ Σ∗ is a regular language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃x , y , z ∶ w = x y z ∧ ∣x y ∣ ⩽ m ∧ ∣y ∣ > 0 ∶

∀i ⩾ 0 ∶ x y iz ∈ L

the language L1 = { anbn ∣ n ⩾ 0} is not regular

for any m > 0, consider ambm

the language L2 = {ww ∣ w ∈ {a,b}∗ } is not regular

2 IT70 (2014) Finite Automata and Regular Languages 16 / 45

Page 28: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Example non-regular languages

Pumping Lemma: if L ⊆ Σ∗ is a regular language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃x , y , z ∶ w = x y z ∧ ∣x y ∣ ⩽ m ∧ ∣y ∣ > 0 ∶

∀i ⩾ 0 ∶ x y iz ∈ L

the language L1 = { anbn ∣ n ⩾ 0} is not regular

for any m > 0, consider ambm

the language L2 = {ww ∣ w ∈ {a,b}∗ } is not regular

for any m > 0, consider ambamb

2 IT70 (2014) Finite Automata and Regular Languages 16 / 45

Page 29: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Push-Down Automata & Context-Free Languages

2IT70 Finite Automata and Process Theory

Technische Universiteit Eindhoven

July 16, 2014

Page 30: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Formal definition

push-down automaton P = (Q, Σ, ∆, ∅, →, q0, F )

Q states

Σ input alphabet, τ ∉ Σ

∆ stack alphabet, ∅ ∉∆ empty stack symbol

→ ⊆ Q ×Στ ×∆∅ ×∆∗×Q transition relation

with Στ = Σ ∪ {τ} and ∆∅ =∆ ∪ {∅}

q0 ∈ Q initial state

F ⊆ Q final states

accepted language

L(P) = {w ∈ Σ∗ ∣ ∃q ∈ F ∃x ∈∆∗∶ (q0,w , ε) ⊢∗P(q, ε, x)}

2 IT70 (2014) Push-Down Automata & Context-Free Languages 18 / 45

Page 31: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Invariant table

q0 q1 q2 q3a[∅/1] b[1/ε] τ[∅/ε]

a[1/11] b[1/ε]

L(P) = { anbn ∣ n ⩾ 1}

2 IT70 (2014) Push-Down Automata & Context-Free Languages 19 / 45

Page 32: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Invariant table

q0 q1 q2 q3a[∅/1] b[1/ε] τ[∅/ε]

a[1/11] b[1/ε]

L(P) = { anbn ∣ n ⩾ 1}

state q input w stack x

q0 ε ε

q1 an 1n 1 ⩽ n

q2 anbm 1n−m 1 ⩽ m ⩽ n

q3 anbn ε 1 ⩽ n

if (q,w , x) in invariant table then (q0,w , ε) ⊢∗P(q, ε, x)

2 IT70 (2014) Push-Down Automata & Context-Free Languages 19 / 45

Page 33: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Language of a CFG

context-free grammar G = (V , T , R , S )

V variables and T terminals

R ⊆ V ×(V ∪T )∗ production rules A→ α

S ∈ V start symbol

productions ⇒G ⊆ (V∪T ) × (V∪T )

γ ⇒G γ′ if γ = β1Aβ2, A→ α rule of G , γ′ = β1αβ2

production sequences

γ0 ⇒G γ1 ⇒G ⋯⇒G γn

language of a variable

LG(A) = {w ∈ T∗ ∣ A ⇒∗

Gw }

language of the grammar

L(G) = LG(S)

2 IT70 (2014) Push-Down Automata & Context-Free Languages 20 / 45

Page 34: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Avoiding the inductive proofs

lemma CFGs G1 = (V1, T1, R1, S1 ) and G2 = (V2, T2, R2, S2 )

moreover V1 and V2 disjoint

define CFG G = ({S} ∪V1 ∪ V2, T1 ∪T2, R , S )

if R = {S → S1 ∣ S2} ∪R1 ∪ R2 then L(G) = L(G1) ∪L(G2)

if R = {S → S1S2} ∪R1 ∪ R2 then L(G) = L(G1) ⋅L(G2)

if R = {S → ε ∣ S1S} ∪ R1 then L(G) = L(G1)∗

2 IT70 (2014) Push-Down Automata & Context-Free Languages 21 / 45

Page 35: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Avoiding the inductive proofs (cont.)

CFG G with production rules

S → S1 ∣ S2S1 → aB B → ε ∣ bBS2 → bA A→ ε ∣ aA

then L(G) = { abn, bam ∣ n,m ⩾ 0}

proof use the lemma

LG(A) = {am ∣ m ⩾ 0} and LG(B) = {b

n ∣ n ⩾ 0}

LG(S1) = {a} ⋅ {bn ∣ n ⩾ 0} and LG(S2) = {b} ⋅ { a

m ∣ m ⩾ 0}

L(G) = { abn ∣ n ⩾ 0} ∪ {bam ∣ m ⩾ 0} ⊠

2 IT70 (2014) Push-Down Automata & Context-Free Languages 22 / 45

Page 36: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Context-free languages

language L is context-free if L = L(G) for CFG G

{ anbn ∣ n ⩾ 0} and {wwR ∣ w ∈ {0,1}∗ } are context-free

but not regular

2 IT70 (2014) Push-Down Automata & Context-Free Languages 23 / 45

Page 37: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Yield of a parse tree

CFG G = (V , T , R , S )

set PTG of all parse trees of G

[X ] single node tree, X ∈ V ∪T

[A→ ε] two node tree, root A, leaf ε for rule A→ ε ∈ R

[A→ PT 1,PT 2, . . . ,PT k]

rule A→ X1⋯Xk ∈ Rparse trees PTi with root Xi

yield function yield ∶ PTG → (V ∪T )∗

yield([X ]) = X yield([A → ε]) = ε

yield([A → PT 1, . . . ,PT k]) = yield(PT 1) ⋅ . . . ⋅ yield(PT k)

parse tree PT is complete if yield(PT ) ∈ T ∗

2 IT70 (2014) Push-Down Automata & Context-Free Languages 24 / 45

Page 38: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

A parse tree with yield ()(())

S

S S

( S )

ε

( S )

( S )

ε

2 IT70 (2014) Push-Down Automata & Context-Free Languages 25 / 45

Page 39: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

A parse tree with yield ()(())

S

S S

( S )

ε

( S )

( S )

ε

2 IT70 (2014) Push-Down Automata & Context-Free Languages 25 / 45

Page 40: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

From CFG to parse trees (Theorem 3.20)

theorem CFG G = (V , T , R , S )

A ⇒∗G

w implies w = yield(PT )

for parse tree PT with root A

proof by induction on n :

A ⇒n

Gw implies ∃PT ∈ PTG(A)∶w = yield(PT )

for all A ∈ V and w ∈ T ∗ ⊠

thus L(G)={w ∈ T ∗ ∣ S ⇒∗G

w }

⊆{yield(PT ) ∣ PT complete parse tree of G , root S }

2 IT70 (2014) Push-Down Automata & Context-Free Languages 26 / 45

Page 41: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

From parse tree to CFG (Theorem 3.23)

theorem CFG G

for parse tree PT , root A and yield w : Aℓ⇒∗

Gw

proof induction on the height of the parse tree PT ⊠

thus { yield(PT ) ∣ PT complete parse tree of G , root S }⊆

{w ∈ T ∗ ∣ S ⇒∗G

w }=L(G)

2 IT70 (2014) Push-Down Automata & Context-Free Languages 27 / 45

Page 42: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

From CFG to PDA (Theorem 3.25)

theorem CFG G = (V , T , R , S )

a PDA P exists such that L(P) = L(G)

proof P = ({q0,q1,q2}, T , V ∪T , ∅,→,q0,{q2}) with

(1) q0τ[∅/S]Ð→ q1

(2) q1a[a/ε]Ð→ q1 for all a ∈ T (matching step)

(3) q1τ[A/α]Ð→ q1 for all A→ α ∈ R (production step)

(3) q1τ[∅/ε]Ð→ q2

claim γℓ⇒∗

Gw iff (q1,w , γ) ⊢∗

P(q1, ε, ε)

2 IT70 (2014) Push-Down Automata & Context-Free Languages 28 / 45

Page 43: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

PDA accepting on empty stack

PDA P = (Q, Σ, ∆, D, →, q0 ) accepting on empty stack

Q finite set of states

Σ input alphabet

∆ data alphabet or stack alphabet

D ∈∆ stack bottom symbol,

→ ⊆ Q ×Στ ×∆ ×∆∗×Q transitions where Στ = Σ ∪ {τ}

q0 ∈ Q initial state.

accepted language N (P) = {w ∈ Σ∗ ∣ ∃q ∈ Q ∶ (q0,w ,D) ⊢∗P(q, ε, ε)}

2 IT70 (2014) Push-Down Automata & Context-Free Languages 29 / 45

Page 44: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

From ePDA to CFG

ePDA P = (Q,Σ,∆,→,q0,D) gives CFG G = (V , Σ, →, S)

V = {S} ∪ { [qd q′′ ] ∣ q,q′′ ∈ Q, d ∈∆}

production rules

S → [q0Dq′] for all q′ ∈ Q

[qd q′′ ]→ a[p0d1p1][p1 d2p2]⋯[pk−1dk pk ]

if qa[d/d1⋯dk ]Ð→ P q′

with p0,p1, . . . ,pk ∈ Q such that p0 = q′ and pk = q

′′

[qd q′′ ]→ [p0d1p1][p1d2p2]⋯[pk−1dk pk ]

if qτ[d/d1⋯dk ]Ð→ P q′

with q′′,p1, . . . ,pk ∈ Q such that p0 = q′ and pk = q

′′

[qd q′′ ]: state q reaches state q′′ when processing stack symbol d

2 IT70 (2014) Push-Down Automata & Context-Free Languages 30 / 45

Page 45: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

An example construction

q0 q1a[D/1D]

a[1/11] b[1/ε]

τ[D/ε]

2 IT70 (2014) Push-Down Automata & Context-Free Languages 31 / 45

Page 46: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

An example construction

q0 q1a[D/1D]

a[1/11] b[1/ε]

τ[D/ε]

S → [q0Dq0] ∣ [q0Dq1]

[q0Dq0] → a[q11q0][q0Dq0] ∣ a[q11q1][q1Dq0]

[q0Dq1] → a[q11q0][q0Dq1] ∣ a[q11q1][q1Dq1]

[q11q0] → a[q11q0][q0 1q0] ∣ a[q11q1][q1 1q0]

[q11q1] → a[q11q0][q0 1q1] ∣ a[q11q1][q1 1q1]

[q11q1] → b

[q1Dq1] → ε

2 IT70 (2014) Push-Down Automata & Context-Free Languages 31 / 45

Page 47: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Closure properties of context-free languages

language L is context-free if L = L(G) for CFG G

theorem context-free languages L1, L2 and L

(a) the union L1 ∪ L2 is also context-free

(b) the concatenation L1 ⋅ L2 is also context-free

(c) the Kleene closure L∗ is also context-free

2 IT70 (2014) Push-Down Automata & Context-Free Languages 32 / 45

Page 48: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Intersection of context-free and regular (Theorem 3.33)

theorem context-free language L1, regular language L2then L1 ∩ L2 is context-free

proof PDA P = (Q1, Σ, ∆, ∅, →P , q10 , F ) for L1

DFA D = (Q2, Σ, δ, q20 , F2) for L2

define PDA P ′ = (Q1 ×Q2, Σ, ∆, ∅, →P′ , (q10 ,q

20), F1 × F2) by

(q1,q2)a[d/x]Ð→ P′ (q

1,q′

2) iff q1a[d/x]Ð→ P q′1 and δ(q2,a) = q

2

(q1,q2)τ[d/x]Ð→ P′ (q

1,q2) iff q1τ[d/x]Ð→ P q′1

claim ((q1,q2),w , z) ⊢∗P′((q̄1, q̄2), ε, z

′) iff

(q1,w , z) ⊢∗P(q̄1, ε, z

′) and (q2,w) ⊢∗

D(q̄2, ε) ⊠

2 IT70 (2014) Push-Down Automata & Context-Free Languages 33 / 45

Page 49: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Pumping lemma for context-free languages

theorem if L ⊆ Σ∗ is a context-free language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃u, v , x , y , z ∶ w = uv x y z ∧ ∣v x y ∣ ⩽ m ∧ ∣v y ∣ > 0 ∶

∀i ⩾ 0 ∶ uv i x y iz ∈ L

2 IT70 (2014) Push-Down Automata & Context-Free Languages 34 / 45

Page 50: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Some languages that are not context-free

Pumping Lemma: if L ⊆ Σ∗ is a context-free language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃u, v , x , y , z ∶ w = uv x y z ∧ ∣v x y ∣ ⩽ m ∧ ∣v y ∣ > 0 ∶

∀i ⩾ 0 ∶ uv i x y iz ∈ L

the language L1 = { anbncn ∣ n ⩾ 0} is not context-free

the language L2 = {ww ∣ w ∈ {a,b}∗ } is not context-free

2 IT70 (2014) Push-Down Automata & Context-Free Languages 35 / 45

Page 51: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Some languages that are not context-free

Pumping Lemma: if L ⊆ Σ∗ is a context-free language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃u, v , x , y , z ∶ w = uv x y z ∧ ∣v x y ∣ ⩽ m ∧ ∣v y ∣ > 0 ∶

∀i ⩾ 0 ∶ uv i x y iz ∈ L

the language L1 = { anbncn ∣ n ⩾ 0} is not context-free

for any m > 0, consider ambmcm

the language L2 = {ww ∣ w ∈ {a,b}∗ } is not context-free

2 IT70 (2014) Push-Down Automata & Context-Free Languages 35 / 45

Page 52: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Some languages that are not context-free

Pumping Lemma: if L ⊆ Σ∗ is a context-free language then

∃m > 0 ∶

∀w ∈ L, ∣w ∣ ⩾ m ∶

∃u, v , x , y , z ∶ w = uv x y z ∧ ∣v x y ∣ ⩽ m ∧ ∣v y ∣ > 0 ∶

∀i ⩾ 0 ∶ uv i x y iz ∈ L

the language L1 = { anbncn ∣ n ⩾ 0} is not context-free

for any m > 0, consider ambmcm

the language L2 = {ww ∣ w ∈ {a,b}∗ } is not context-free

for any m > 0, consider ambmambm

2 IT70 (2014) Push-Down Automata & Context-Free Languages 35 / 45

Page 53: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Labeled Transition Systems andBisimulation

2IT70 Finite Automata and Process Theory

Technische Universiteit Eindhoven

July 16, 2014

Page 54: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Labeled transition system

labeled transition system S = (Q, Σ, →S , q0 )

finite/infinite set of states Q

finite/infinite set of actions Σ

transition relation →S ⊆ Q ×Στ ×Q

initial state q0

transitions qαÐ→S q′ for action α ∈ Στ

2 IT70 (2014) Labeled Transition Systems and Bisimulation 37 / 45

Page 55: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Example LTS

a buffer of capacity 2

ε0 1

00 11

10 01

in1 in0

out1 out0

in0

in1

in0

out0

in1out1

out0

out1

2 IT70 (2014) Labeled Transition Systems and Bisimulation 38 / 45

Page 56: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

An infinite LTS

a counter process

q0 q1 q2 q3 q4

p1 p2 p3 p4

up up up

down down down

downdown

up

down

2 IT70 (2014) Labeled Transition Systems and Bisimulation 39 / 45

Page 57: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Branching bisimulation

LTS S = (Q, Σ, →S , q0 )

branching bisimulation relation R ⊆ Q ×Q for S

(i) if R(q,p) and qaÐ→S q′ then exist p̄,p′ ∈ Q such that

pτÐ→∗

Sp̄ and p̄

aÐ→S p′ with R(q, p̄) and R(q′,p′)

(ii) symmetric condition if R(q,p) and paÐ→S p′

2 IT70 (2014) Labeled Transition Systems and Bisimulation 40 / 45

Page 58: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Branching bisimulation

LTS S = (Q, Σ, →S , q0 )

branching bisimulation relation R ⊆ Q ×Q for S

(i) if R(q,p) and qaÐ→S q′ then exist p̄,p′ ∈ Q such that

pτÐ→∗

Sp̄ and p̄

aÐ→S p′ with R(q, p̄) and R(q′,p′)

(ii) symmetric condition if R(q,p) and paÐ→S p′

(iii) if R(q,p) and qτÐ→S q′ then either exist p̄,p′ ∈ Q such that

pτÐ→∗

Sp̄ and p̄

τÐ→S p′ with R(q, p̄) and R(q′,p′) or

exists p′ ∈ Q such that pτÐ→∗

Sp′ with R(q,p′) and R(q′,p′)

(iv) symmetric condition if R(q,p) and pτÐ→S p′

states q,p ∈ Q branching bisimilar if R(q,p)

2 IT70 (2014) Labeled Transition Systems and Bisimulation 40 / 45

Page 59: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Branching bisimulation (cont.)

s1

t1

s2

s ′2

t2

a τ

a

s1

t1

s2

s ′2

t2

τ τ

τ

s1

t1

s2

τ

left-to-right transfer condition for visible actions

left-to-right transfer condition for silent steps

2 IT70 (2014) Labeled Transition Systems and Bisimulation 41 / 45

Page 60: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Coloring for branching bisimulation

q0

q4

q1

q5

q2

q6

q3

τa

τ

b

a

b b

τ

0

0

0

0

0

0

0

2 IT70 (2014) Labeled Transition Systems and Bisimulation 42 / 45

Page 61: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Coloring for branching bisimulation

q0

q1 q2 q3

q4 q5 q6

τa

τ

b

a

b b

τ

1

1 2 2

3 3 3

2 IT70 (2014) Labeled Transition Systems and Bisimulation 42 / 45

Page 62: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Coloring for branching bisimulation

q0

q1 q2 q3

q4 q5 q6

τa

τ

b

a

b b

τ

4

5 6 6

3 3 3

2 IT70 (2014) Labeled Transition Systems and Bisimulation 42 / 45

Page 63: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Coloring for branching bisimulation

q0

q1 q2 q3

q4 q5 q6

τa

τ

b

a

b b

τ

7

8 6 6

3 3 3

2 IT70 (2014) Labeled Transition Systems and Bisimulation 42 / 45

Page 64: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Composing LTS: an abstract example

a

b

S1

c dS2

processes S1 and S2

2 IT70 (2014) Labeled Transition Systems and Bisimulation 43 / 45

Page 65: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Composing LTS: an abstract example

a

b

S1

c dS2

a

b

a

b

a

b

c d

c d

c d

S1 ∥∅ S2

process S1 ∥∅ S2

2 IT70 (2014) Labeled Transition Systems and Bisimulation 43 / 45

Page 66: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Composing LTS: an abstract example

a

b

S1

c dS2

a

b

a

b

a

b

c d

c d

c d

e

f

S1 ∥γ S2

process S1 ∥γ S2 where γ(a, c) = e and γ(b,d) = f

2 IT70 (2014) Labeled Transition Systems and Bisimulation 43 / 45

Page 67: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Composing LTS: an abstract example

a

b

S1

c dS2

e

f

∂H(S1 ∥γ S2)

process ∂H(S1 ∥γ S2) where γ(a, c) = e, γ(b,d) = f ,H = {a,b, c ,d}

2 IT70 (2014) Labeled Transition Systems and Bisimulation 43 / 45

Page 68: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Composing LTS: an abstract example

a

b

S1

c dS2

τ

f

τI (∂H(S1 ∥γ S2))

process τI (∂H(S1 ∥γ S2)) where γ(a, c) = e, γ(b,d) = f ,H = {a,b, c ,d} and I = {e}

2 IT70 (2014) Labeled Transition Systems and Bisimulation 43 / 45

Page 69: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Study Material

2IT70 Finite Automata and Process Theory

Technische Universiteit Eindhoven

June 11, 2014

Page 70: Study Material 2IT70 Finite Automata and Process Theoryevink/education/2it70/PDF2014/2it70-slides-16jun2014.pdfStudy Material 2IT70 Finite Automata and Process Theory Technische Universiteit

Study material

Updated reader: Chapters 2, 3 and 5

Hopcroft, Motwani & Ullman (2001)

Background reading: Chapters 1-7More specific: 2.2, 2.3, 2.5; 3.1, 3.2; 4.1-3; 5.1, 5.2; 6.1-3; 7.2

Exercises

Proofs

Theorem 2.13: from NFA to DFATheorem 2.27: Pumping Lemma for regular languagesTheorem 3.20: from CFG to parse treeTheorem 3.23: from parse tree to CFGTheorem 3.25: from CFG to PDATheorem 3.33: intersection of context-free and regular

2 IT70 (2014) Study Material 45 / 45