Theory of Computer Science C2. Regular Languages: Finite Automata - - PowerPoint PPT Presentation

theory of computer science
SMART_READER_LITE
LIVE PREVIEW

Theory of Computer Science C2. Regular Languages: Finite Automata - - PowerPoint PPT Presentation

Theory of Computer Science C2. Regular Languages: Finite Automata Gabriele R oger University of Basel March 23, 2020 Regular Grammars DFAs NFAs Summary Regular Grammars Regular Grammars DFAs NFAs Summary Overview Regular Languages


slide-1
SLIDE 1

Theory of Computer Science

  • C2. Regular Languages: Finite Automata

Gabriele R¨

  • ger

University of Basel

March 23, 2020

slide-2
SLIDE 2

Regular Grammars DFAs NFAs Summary

Regular Grammars

slide-3
SLIDE 3

Regular Grammars DFAs NFAs Summary

Overview

Automata & Formal Languages Languages & Grammars Regular Languages Regular Grammars DFAs NFAs Regular Expressions Pumping Lemma Minimal Automata Properties Context-free Languages Context-sensitive & Type-0 Languages

slide-4
SLIDE 4

Regular Grammars DFAs NFAs Summary

Repetition: Regular Grammars

Definition (Regular Grammars) A regular grammar is a 4-tuple Σ, V , P, S with

1 Σ finite alphabet of terminals 2 V finite set of variables (with V ∩ Σ = ∅) 3 P ⊆ (V × (Σ ∪ ΣV )) ∪ {S, ε} finite set of rules 4 if S → ε ∈ P, there is no X ∈ V , y ∈ Σ with X → yS ∈ P 5 S ∈ V start variable.

slide-5
SLIDE 5

Regular Grammars DFAs NFAs Summary

Repetition: Regular Grammars

Definition (Regular Grammars) A regular grammar is a 4-tuple Σ, V , P, S with

1 Σ finite alphabet of terminals 2 V finite set of variables (with V ∩ Σ = ∅) 3 P ⊆ (V × (Σ ∪ ΣV )) ∪ {S, ε} finite set of rules 4 if S → ε ∈ P, there is no X ∈ V , y ∈ Σ with X → yS ∈ P 5 S ∈ V start variable.

Rule X → ε is only allowed if X = S and S never occurs in the right-hand side of a rule.

slide-6
SLIDE 6

Regular Grammars DFAs NFAs Summary

Repetition: Regular Grammars

Definition (Regular Grammars) A regular grammar is a 4-tuple Σ, V , P, S with

1 Σ finite alphabet of terminals 2 V finite set of variables (with V ∩ Σ = ∅) 3 P ⊆ (V × (Σ ∪ ΣV )) ∪ {S, ε} finite set of rules 4 if S → ε ∈ P, there is no X ∈ V , y ∈ Σ with X → yS ∈ P 5 S ∈ V start variable.

Rule X → ε is only allowed if X = S and S never occurs in the right-hand side of a rule. How restrictive is this?

slide-7
SLIDE 7

Regular Grammars DFAs NFAs Summary

Start Variable in Right-Hand Side of Rules

For every type-0 language L there is a grammar where the start variable does not occur on the right-hand side of any rule. Theorem For every grammar G = Σ, V , P, S there is a grammar G ′ = Σ, V ′, P′, S with rules P′ ⊆ (V ′ ∪ Σ)+ × (V ′ \ {S} ∪ Σ)∗ such that L(G) = L(G ′).

slide-8
SLIDE 8

Regular Grammars DFAs NFAs Summary

Start Variable in Right-Hand Side of Rules: Proof

Proof. Let G = Σ, V , P, S be a grammar and S′ ∈ V be a new variable. Construct rule set P′ from P as follows: for every rule r ∈ P, add a rule r′ to P′, where r′ is the result

  • f replacing all occurences of S in r with S′.

for every rule S → w ∈ P, add a rule S → w′ to P′, where w′ is the result of replacing all occurences of S in w with S′. Then L(G) = L(Σ, V ∪ {S′}, P′, S).

slide-9
SLIDE 9

Regular Grammars DFAs NFAs Summary

Start Variable in Right-Hand Side of Rules: Proof

Proof. Let G = Σ, V , P, S be a grammar and S′ ∈ V be a new variable. Construct rule set P′ from P as follows: for every rule r ∈ P, add a rule r′ to P′, where r′ is the result

  • f replacing all occurences of S in r with S′.

for every rule S → w ∈ P, add a rule S → w′ to P′, where w′ is the result of replacing all occurences of S in w with S′. Then L(G) = L(Σ, V ∪ {S′}, P′, S). Note that the rules in P′ are not fundamentally different from the rules in P. In particular: If P ⊆ V × (Σ ∪ ΣV ∪ {ε}) then P′ ⊆ V ′ × (Σ ∪ ΣV ′ ∪ {ε}). If P ⊆ V × (V ∪ Σ)∗ then P′ ⊆ V ′ × (V ′ ∪ Σ)∗.

slide-10
SLIDE 10

Regular Grammars DFAs NFAs Summary

Start Variable in Right-Hand Side of Rules: Example

slide-11
SLIDE 11

Regular Grammars DFAs NFAs Summary

Epsilon Rules

Theorem For every grammar G with rules P ⊆ V × (Σ ∪ ΣV ∪ {ε}) there is a regular grammar G ′ with L(G) = L(G ′). Proof. Let G = Σ, V , P, S be a grammar s.t. P ⊆ V × (Σ ∪ ΣV ∪ {ε}). Use the previous proof to construct grammar G ′ = Σ, V ′, P′, S s.t. P′ ⊆ V ′ × (Σ ∪ Σ(V ′ \ {S}) ∪ {ε}). Let Vε = {A | A → ε ∈ P′}. Let P′′ be the rule set that is created from P′ by removing all rules

  • f the form A → ε (A = S). Additionally, for every rule of the form

B → xA with A ∈ Vε, B ∈ V ′, x ∈ Σ we add a rule B → x to P′′. Then G ′′ = Σ, V ′, P′′, S is regular and L(G) = L(G ′′).

slide-12
SLIDE 12

Regular Grammars DFAs NFAs Summary

Epsilon Rules: Example

slide-13
SLIDE 13

Regular Grammars DFAs NFAs Summary

Questions Questions?

slide-14
SLIDE 14

Regular Grammars DFAs NFAs Summary

DFAs

slide-15
SLIDE 15

Regular Grammars DFAs NFAs Summary

Overview

Automata & Formal Languages Languages & Grammars Regular Languages Regular Grammars DFAs NFAs Regular Expressions Pumping Lemma Minimal Automata Properties Context-free Languages Context-sensitive & Type-0 Languages

slide-16
SLIDE 16

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1

slide-17
SLIDE 17

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0,

slide-18
SLIDE 18

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0,

slide-19
SLIDE 19

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1,

slide-20
SLIDE 20

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1,

slide-21
SLIDE 21

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1, q0,

slide-22
SLIDE 22

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1, q0,

slide-23
SLIDE 23

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1, q0, q0,

slide-24
SLIDE 24

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1, q0, q0,

slide-25
SLIDE 25

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1,

slide-26
SLIDE 26

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1,

slide-27
SLIDE 27

Regular Grammars DFAs NFAs Summary

Finite Automata: Example

q0 q1 q2 1 1 1 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, q2.

slide-28
SLIDE 28

Regular Grammars DFAs NFAs Summary

Finite Automata: Terminology and Notation

q0 q1 q2 1 1 1

states Q = {q0, q1, q2} input alphabet Σ = {0, 1} transition function δ start state q0 end states {q2}

slide-29
SLIDE 29

Regular Grammars DFAs NFAs Summary

Finite Automata: Terminology and Notation

q0 q1 q2 1 1 1

states Q = {q0, q1, q2} input alphabet Σ = {0, 1} transition function δ start state q0 end states {q2}

slide-30
SLIDE 30

Regular Grammars DFAs NFAs Summary

Finite Automata: Terminology and Notation

q0 q1 q2 1 1 1

states Q = {q0, q1, q2} input alphabet Σ = {0, 1} transition function δ start state q0 end states {q2}

slide-31
SLIDE 31

Regular Grammars DFAs NFAs Summary

Finite Automata: Terminology and Notation

q0 q1 q2 1 1 1

states Q = {q0, q1, q2} input alphabet Σ = {0, 1} transition function δ start state q0 end states {q2} δ(q0, 0) = q1 δ(q0, 1) = q0 δ(q1, 0) = q2 δ(q1, 1) = q0 δ(q2, 0) = q2 δ(q2, 1) = q0

slide-32
SLIDE 32

Regular Grammars DFAs NFAs Summary

Finite Automata: Terminology and Notation

q0 q1 q2 1 1 1

states Q = {q0, q1, q2} input alphabet Σ = {0, 1} transition function δ start state q0 end states {q2} δ(q0, 0) = q1 δ(q0, 1) = q0 δ(q1, 0) = q2 δ(q1, 1) = q0 δ(q2, 0) = q2 δ(q2, 1) = q0 δ 1 q0 q1 q0 q1 q2 q0 q2 q2 q0 table form of δ

slide-33
SLIDE 33

Regular Grammars DFAs NFAs Summary

Finite Automata: Terminology and Notation

q0 q1 q2 1 1 1

states Q = {q0, q1, q2} input alphabet Σ = {0, 1} transition function δ start state q0 end states {q2} δ(q0, 0) = q1 δ(q0, 1) = q0 δ(q1, 0) = q2 δ(q1, 1) = q0 δ(q2, 0) = q2 δ(q2, 1) = q0 δ 1 q0 q1 q0 q1 q2 q0 q2 q2 q0 table form of δ

slide-34
SLIDE 34

Regular Grammars DFAs NFAs Summary

Finite Automata: Terminology and Notation

q0 q1 q2 1 1 1

states Q = {q0, q1, q2} input alphabet Σ = {0, 1} transition function δ start state q0 end states {q2} δ(q0, 0) = q1 δ(q0, 1) = q0 δ(q1, 0) = q2 δ(q1, 1) = q0 δ(q2, 0) = q2 δ(q2, 1) = q0 δ 1 q0 q1 q0 q1 q2 q0 q2 q2 q0 table form of δ

slide-35
SLIDE 35

Regular Grammars DFAs NFAs Summary

Deterministic Finite Automaton: Definition

Definition (Deterministic Finite Automata) A deterministic finite automaton (DFA) is a 5-tuple M = Q, Σ, δ, q0, E where Q is the finite set of states Σ is the input alphabet (with Q ∩ Σ = ∅) δ : Q × Σ → Q is the transition function q0 ∈ Q is the start state E ⊆ Q is the set of end states

German: deterministischer endlicher Automat, Zust¨ ande, German: Eingabealphabet, ¨ Uberf¨ uhrungs-/¨ Ubergangsfunktion, German: Startzustand, Endzust¨ ande

slide-36
SLIDE 36

Regular Grammars DFAs NFAs Summary

DFA: Recognized Words

Definition (Words Recognized by a DFA) DFA M = Q, Σ, δ, q0, E recognizes the word w = a1 . . . an if there is a sequence of states q′

0, . . . , q′ n ∈ Q with

1 q′

0 = q0,

2 δ(q′

i−1, ai) = q′ i for all i ∈ {1, . . . , n} and

3 q′

n ∈ E.

German: DFA erkennt das Wort

Example

q0 q1 q2 1 1 1

recognizes: 00 10010100 01000 does not recognize: ε 1001010 010001

slide-37
SLIDE 37

Regular Grammars DFAs NFAs Summary

DFA: Recognized Words

Definition (Words Recognized by a DFA) DFA M = Q, Σ, δ, q0, E recognizes the word w = a1 . . . an if there is a sequence of states q′

0, . . . , q′ n ∈ Q with

1 q′

0 = q0,

2 δ(q′

i−1, ai) = q′ i for all i ∈ {1, . . . , n} and

3 q′

n ∈ E.

German: DFA erkennt das Wort

Example

q0 q1 q2 1 1 1

recognizes: 00 10010100 01000 does not recognize: ε 1001010 010001

slide-38
SLIDE 38

Regular Grammars DFAs NFAs Summary

DFA: Accepted Language

Definition (Language Accepted by a DFA) Let M be a deterministic finite automaton. The language accepted by M is defined as L(M) = {w ∈ Σ∗ | w is recognized by M}. Example

q0 q1 q2 1 1 1

slide-39
SLIDE 39

Regular Grammars DFAs NFAs Summary

DFA: Accepted Language

Definition (Language Accepted by a DFA) Let M be a deterministic finite automaton. The language accepted by M is defined as L(M) = {w ∈ Σ∗ | w is recognized by M}. Example

q0 q1 q2 1 1 1

slide-40
SLIDE 40

Regular Grammars DFAs NFAs Summary

DFA: Accepted Language

Definition (Language Accepted by a DFA) Let M be a deterministic finite automaton. The language accepted by M is defined as L(M) = {w ∈ Σ∗ | w is recognized by M}. Example

q0 q1 q2 1 1 1

The DFA accepts the language {w ∈ {0, 1}∗ | w ends with 00}.

slide-41
SLIDE 41

Regular Grammars DFAs NFAs Summary

Languages Accepted by DFAs are Regular

Theorem Every language accepted by a DFA is regular (type 3).

slide-42
SLIDE 42

Regular Grammars DFAs NFAs Summary

Languages Accepted by DFAs are Regular

Theorem Every language accepted by a DFA is regular (type 3). Proof. Let M = Q, Σ, δ, q0, E be a DFA. We define a regular grammar G with L(G) = L(M). Define G = Σ, Q, P, q0 where P contains a rule q → aq′ for every δ(q, a) = q′, and a rule q → ε for every q ∈ E. (We can eliminate forbidden epsilon rules as described at the start of the chapter.) . . .

slide-43
SLIDE 43

Regular Grammars DFAs NFAs Summary

Languages Accepted by DFAs are Regular

Theorem Every language accepted by a DFA is regular (type 3). Proof (continued). For every w = a1a2 . . . an ∈ Σ∗: w ∈ L(M) iff there is a sequence of states q′

0, q′ 1, . . . , q′ n with

iff q′

0 = q0, q′ n ∈ E and δ(q′ i−1, ai) = q′ i for all i ∈ {1, . . . , n}

iff there is a sequence of variables q′

0, q′ 1, . . . , q′ n with

iff q′

0 is start variable and we have q′ 0 ⇒ a1q′ 1 ⇒ a1a2q′ 2 ⇒

iff · · · ⇒ a1a2 . . . anq′

n ⇒ a1a2 . . . an.

iff w ∈ L(G)

slide-44
SLIDE 44

Regular Grammars DFAs NFAs Summary

Languages Accepted by DFAs are Regular

Theorem Every language accepted by a DFA is regular (type 3). Proof (continued). For every w = a1a2 . . . an ∈ Σ∗: w ∈ L(M) iff there is a sequence of states q′

0, q′ 1, . . . , q′ n with

iff q′

0 = q0, q′ n ∈ E and δ(q′ i−1, ai) = q′ i for all i ∈ {1, . . . , n}

iff there is a sequence of variables q′

0, q′ 1, . . . , q′ n with

iff q′

0 is start variable and we have q′ 0 ⇒ a1q′ 1 ⇒ a1a2q′ 2 ⇒

iff · · · ⇒ a1a2 . . . anq′

n ⇒ a1a2 . . . an.

iff w ∈ L(G) Example: blackboard

slide-45
SLIDE 45

Regular Grammars DFAs NFAs Summary

Question

Is the inverse true as well: for every regular language, is there a DFA that accepts it? That is, are the languages accepted by DFAs exactly the regular languages?

Picture courtesy of imagerymajestic / FreeDigitalPhotos.net

slide-46
SLIDE 46

Regular Grammars DFAs NFAs Summary

Question

Is the inverse true as well: for every regular language, is there a DFA that accepts it? That is, are the languages accepted by DFAs exactly the regular languages?

Yes! We will prove this later (via a detour).

Picture courtesy of imagerymajestic / FreeDigitalPhotos.net

slide-47
SLIDE 47

Regular Grammars DFAs NFAs Summary

Questions Questions?

slide-48
SLIDE 48

Regular Grammars DFAs NFAs Summary

NFAs

slide-49
SLIDE 49

Regular Grammars DFAs NFAs Summary

Overview

Automata & Formal Languages Languages & Grammars Regular Languages Regular Grammars DFAs NFAs Regular Expressions Pumping Lemma Minimal Automata Properties Context-free Languages Context-sensitive & Type-0 Languages

slide-50
SLIDE 50

Regular Grammars DFAs NFAs Summary

Nondeterministic Finite Automata

Why are DFAs called deterministic automata? What are nondeterministic automata, then?

Picture courtesy of stockimages / FreeDigitalPhotos.net

slide-51
SLIDE 51

Regular Grammars DFAs NFAs Summary

Nondeterministic Finite Automata: Example

q0 q1 q2 0,1 differences to DFAs: multiple start states possible transition function δ can lead to zero or more successor states for the same a ∈ Σ automaton recognizes a word if there is at least one accepting sequence of states

slide-52
SLIDE 52

Regular Grammars DFAs NFAs Summary

Nondeterministic Finite Automata: Example

q0 q1 q2 0,1 differences to DFAs: multiple start states possible transition function δ can lead to zero or more successor states for the same a ∈ Σ automaton recognizes a word if there is at least one accepting sequence of states

slide-53
SLIDE 53

Regular Grammars DFAs NFAs Summary

Nondeterministic Finite Automata: Example

q0 q1 q2 0,1 differences to DFAs: multiple start states possible transition function δ can lead to zero or more successor states for the same a ∈ Σ automaton recognizes a word if there is at least one accepting sequence of states

slide-54
SLIDE 54

Regular Grammars DFAs NFAs Summary

Nondeterministic Finite Automata: Example

q0 q1 q2 0,1 differences to DFAs: multiple start states possible transition function δ can lead to zero or more successor states for the same a ∈ Σ automaton recognizes a word if there is at least one accepting sequence of states

slide-55
SLIDE 55

Regular Grammars DFAs NFAs Summary

Nondeterministic Finite Automaton: Definition

Definition (Nondeterministic Finite Automata) A nondeterministic finite automaton (NFA) is a 5-tuple M = Q, Σ, δ, S, E where Q is the finite set of states Σ is the input alphabet (with Q ∩ Σ = ∅) δ : Q × Σ → P(Q) is the transition function (mapping to the power set of Q) S ⊆ Q is the set of start states E ⊆ Q is the set of end states

German: nichtdeterministischer endlicher Automat

slide-56
SLIDE 56

Regular Grammars DFAs NFAs Summary

Nondeterministic Finite Automaton: Definition

Definition (Nondeterministic Finite Automata) A nondeterministic finite automaton (NFA) is a 5-tuple M = Q, Σ, δ, S, E where Q is the finite set of states Σ is the input alphabet (with Q ∩ Σ = ∅) δ : Q × Σ → P(Q) is the transition function (mapping to the power set of Q) S ⊆ Q is the set of start states E ⊆ Q is the set of end states

German: nichtdeterministischer endlicher Automat

DFAs are (essentially) a special case of NFAs.

slide-57
SLIDE 57

Regular Grammars DFAs NFAs Summary

NFA: Recognized Words

Definition (Words Recognized by an NFA) NFA M = Q, Σ, δ, S, E recognizes the word w = a1 . . . an if there is a sequence of states q′

0, . . . , q′ n ∈ Q with

1 q′

0 ∈ S,

2 q′

i ∈ δ(q′ i−1, ai) for all i ∈ {1, . . . , n} and

3 q′

n ∈ E.

Example

q0 q1 q2 0,1

recognizes: 10010100 01000 does not recognize: ε 1001010 010001

slide-58
SLIDE 58

Regular Grammars DFAs NFAs Summary

NFA: Recognized Words

Definition (Words Recognized by an NFA) NFA M = Q, Σ, δ, S, E recognizes the word w = a1 . . . an if there is a sequence of states q′

0, . . . , q′ n ∈ Q with

1 q′

0 ∈ S,

2 q′

i ∈ δ(q′ i−1, ai) for all i ∈ {1, . . . , n} and

3 q′

n ∈ E.

Example

q0 q1 q2 0,1

recognizes: 10010100 01000 does not recognize: ε 1001010 010001

slide-59
SLIDE 59

Regular Grammars DFAs NFAs Summary

NFA: Accepted Language

Definition (Language Accepted by an NFA) Let M = Q, Σ, δ, S, E be a nondeterministic finite automaton. The language accepted by M is defined as L(M) = {w ∈ Σ∗ | w is recognized by M}. Example

q0 q1 q2 0, 1

slide-60
SLIDE 60

Regular Grammars DFAs NFAs Summary

NFA: Accepted Language

Definition (Language Accepted by an NFA) Let M = Q, Σ, δ, S, E be a nondeterministic finite automaton. The language accepted by M is defined as L(M) = {w ∈ Σ∗ | w is recognized by M}. Example

q0 q1 q2 0, 1

slide-61
SLIDE 61

Regular Grammars DFAs NFAs Summary

NFA: Accepted Language

Definition (Language Accepted by an NFA) Let M = Q, Σ, δ, S, E be a nondeterministic finite automaton. The language accepted by M is defined as L(M) = {w ∈ Σ∗ | w is recognized by M}. Example

q0 q1 q2 0, 1

The NFA accepts the language {w ∈ {0, 1}∗ | w = 0 or {w ∈ {0, 1}∗ | w ends with 00}.

slide-62
SLIDE 62

Regular Grammars DFAs NFAs Summary

Questions Questions?

slide-63
SLIDE 63

Regular Grammars DFAs NFAs Summary

NFAs are No More Powerful than DFAs

Theorem (Rabin, Scott) Every language accepted by an NFA is also accepted by a DFA.

slide-64
SLIDE 64

Regular Grammars DFAs NFAs Summary

NFAs are No More Powerful than DFAs

Theorem (Rabin, Scott) Every language accepted by an NFA is also accepted by a DFA. Proof. For every NFA M = Q, Σ, δ, S, E we can construct a DFA M′ = Q′, Σ, δ′, q′

0, E ′ with L(M) = L(M′).

Here M′ is defined as follows: Q′ := P(Q) (the power set of Q) q′

0 := S

E ′ := {Q ⊆ Q | Q ∩ E = ∅} For all Q ∈ Q′: δ′(Q, a) :=

q∈Q

δ(q, a) . . .

slide-65
SLIDE 65

Regular Grammars DFAs NFAs Summary

NFAs are No More Powerful than DFAs

Theorem (Rabin, Scott) Every language accepted by an NFA is also accepted by a DFA. Proof (continued). For every w = a1a2 . . . an ∈ Σ∗: w ∈ L(M) iff there is a sequence of states q0, q1, . . . , qn with iff q0 ∈ S, qn ∈ E and qi ∈ δ(qi−1, ai) for all i ∈ {1, . . . , n} iff there is a sequence of subsets Q0, Q1, . . . , Qn with iff Q0 = q′

0, Qn ∈ E ′ and δ′(Qi−1, ai) = Qi for all i ∈ {1, . . . , n}

iff w ∈ L(M′)

slide-66
SLIDE 66

Regular Grammars DFAs NFAs Summary

NFAs are No More Powerful than DFAs

Theorem (Rabin, Scott) Every language accepted by an NFA is also accepted by a DFA. Proof (continued). For every w = a1a2 . . . an ∈ Σ∗: w ∈ L(M) iff there is a sequence of states q0, q1, . . . , qn with iff q0 ∈ S, qn ∈ E and qi ∈ δ(qi−1, ai) for all i ∈ {1, . . . , n} iff there is a sequence of subsets Q0, Q1, . . . , Qn with iff Q0 = q′

0, Qn ∈ E ′ and δ′(Qi−1, ai) = Qi for all i ∈ {1, . . . , n}

iff w ∈ L(M′) Example: blackboard

slide-67
SLIDE 67

Regular Grammars DFAs NFAs Summary

NFAs are More Compact than DFAs

Example For k ≥ 1 consider the language Lk = {w ∈ {0, 1}∗ | |w| ≥ k and the k-th last symbol of w is 0}. The language Lk can be accepted by an NFA with k + 1 states:

q0 q1 q2 . . . qk 0,1 0,1 0,1 0,1

There is no DFA with less than 2k states that accepts Lk (without proof). NFAs can often represent languages more compactly than DFAs.

slide-68
SLIDE 68

Regular Grammars DFAs NFAs Summary

NFAs are More Compact than DFAs

Example For k ≥ 1 consider the language Lk = {w ∈ {0, 1}∗ | |w| ≥ k and the k-th last symbol of w is 0}. The language Lk can be accepted by an NFA with k + 1 states:

q0 q1 q2 . . . qk 0,1 0,1 0,1 0,1

There is no DFA with less than 2k states that accepts Lk (without proof). NFAs can often represent languages more compactly than DFAs.

slide-69
SLIDE 69

Regular Grammars DFAs NFAs Summary

NFAs are More Compact than DFAs

Example For k ≥ 1 consider the language Lk = {w ∈ {0, 1}∗ | |w| ≥ k and the k-th last symbol of w is 0}. The language Lk can be accepted by an NFA with k + 1 states:

q0 q1 q2 . . . qk 0,1 0,1 0,1 0,1

There is no DFA with less than 2k states that accepts Lk (without proof). NFAs can often represent languages more compactly than DFAs.

slide-70
SLIDE 70

Regular Grammars DFAs NFAs Summary

NFAs are More Compact than DFAs

Example For k ≥ 1 consider the language Lk = {w ∈ {0, 1}∗ | |w| ≥ k and the k-th last symbol of w is 0}. The language Lk can be accepted by an NFA with k + 1 states:

q0 q1 q2 . . . qk 0,1 0,1 0,1 0,1

There is no DFA with less than 2k states that accepts Lk (without proof). NFAs can often represent languages more compactly than DFAs.

slide-71
SLIDE 71

Regular Grammars DFAs NFAs Summary

Regular Grammars are No More Powerful than NFAs

Theorem For every regular grammar G there is an NFA M with L(G) = L(M).

slide-72
SLIDE 72

Regular Grammars DFAs NFAs Summary

Regular Grammars are No More Powerful than NFAs

Theorem For every regular grammar G there is an NFA M with L(G) = L(M). Proof. Let G = Σ, V , P, S be a regular grammar. Define NFA M = Q, Σ, δ, S′, E with Q = V ∪ {X}, X ∈ V S′ = {S} E =

  • {S, X}

if S → ε ∈ P {X} if S → ε ∈ P B ∈ δ(A, a) if A → aB ∈ P X ∈ δ(A, a) if A → a ∈ P . . .

slide-73
SLIDE 73

Regular Grammars DFAs NFAs Summary

Regular Grammars are No More Powerful than NFAs

Theorem For every regular grammar G there is an NFA M with L(G) = L(M). Proof (continued). For every w = a1a2 . . . an ∈ Σ∗ with n ≥ 1: w ∈ L(G) iff there is a sequence on variables A1, A2, . . . , An−1 with iff S ⇒ a1A1 ⇒ a1a2A2 ⇒ · · · ⇒ a1a2 . . . an−1An−1 ⇒ a1a2 . . . an. iff there is a sequence of variables A1, A2, . . . , An−1 with iff A1 ∈ δ(S, a1), A2 ∈ δ(A1, a2), . . . , X ∈ δ(An−1, an). iff w ∈ L(M). Case w = ε is also covered because S ∈ E iff S → ε ∈ P.

slide-74
SLIDE 74

Regular Grammars DFAs NFAs Summary

Finite Automata and Regular Languages

DFA regular grammar NFA In particular, this implies: Corollary L regular ⇐ ⇒ L is accepted by a DFA. L regular ⇐ ⇒ L is accepted by an NFA.

slide-75
SLIDE 75

Regular Grammars DFAs NFAs Summary

Questions Questions?

slide-76
SLIDE 76

Regular Grammars DFAs NFAs Summary

Summary

slide-77
SLIDE 77

Regular Grammars DFAs NFAs Summary

Summary

We now know three formalisms that all describe exactly the regular languages: regular grammars, DFAs and NFAs We will get to know a fourth formalism in the next chapter. DFAs are automata where every state transition is uniquely determined. NFAs recognize a word if there is at least one accepting sequence of states.