expressions of dfas, nfas, and regular cse 311 lecture 26 ...key idea 1 if tw o string prefixes...

58
CSE 311 Lecture 26: Limitations CSE 311 Lecture 26: Limitations of DFAs, NFAs, and Regular of DFAs, NFAs, and Regular Expressions Expressions and Emina Torlak Sami Davies 1

Upload: others

Post on 12-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

CSE 311 Lecture 26: LimitationsCSE 311 Lecture 26: Limitationsof DFAs, NFAs, and Regularof DFAs, NFAs, and RegularExpressionsExpressions

and Emina Torlak Sami Davies

1

Page 2: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

TopicsTopicsDFAs NFAs regular expressions

A quick review of .Languages and representations

Regular, context-free, and other languages.Proving irregularity

A proof template for showing that a language is not regular.

≡ ≡

Lecture 25

2

Page 3: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

DFAs DFAs NFAs NFAs regular expressions regular expressionsA quick review of .

≡≡ ≡≡

Lecture 25

3

Page 4: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Equivalence of DFAs, NFAs, and regular expressionsEquivalence of DFAs, NFAs, and regular expressions

We have shown how to build an optimal DFA for every regular expression.Build an NFA.Convert the NFA to a DFA using the subset construction.Minimize the resulting DFA.

4

Page 5: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Equivalence of DFAs, NFAs, and regular expressionsEquivalence of DFAs, NFAs, and regular expressions

We have shown how to build an optimal DFA for every regular expression.Build an NFA.Convert the NFA to a DFA using the subset construction.Minimize the resulting DFA.

TheoremA language is recognized by a DFA (or NFA) if and only if it has a regularexpression.

You need to know this fact but we won’t ask you anything about the “only if”direction from DFAs/NFAs to regular expressions.

4

Page 6: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Equivalence of DFAs, NFAs, and regular expressionsEquivalence of DFAs, NFAs, and regular expressions

We have shown how to build an optimal DFA for every regular expression.Build an NFA.Convert the NFA to a DFA using the subset construction.Minimize the resulting DFA.

TheoremA language is recognized by a DFA (or NFA) if and only if it has a regularexpression.

Languages represented by NFAs, DFAs, and regular expressions are calledregular languages.

You need to know this fact but we won’t ask you anything about the “only if”direction from DFAs/NFAs to regular expressions.

4

Page 7: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Languages and representationsLanguages and representationsRegular, context-free, and other languages.

5

Page 8: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A hierarchy of languages and representationsA hierarchy of languages and representations

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

6

Page 9: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A hierarchy of languages and representationsA hierarchy of languages and representations

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

How do we prove that all finite languages are regular?

6

Page 10: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A hierarchy of languages and representationsA hierarchy of languages and representations

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

How do we prove that all finite languages are regular? By showing how toconstruct a DFA/NFA/RegEx for every finite language!

6

Page 11: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Converting a finite language to a regular expressionConverting a finite language to a regular expression

7

Page 12: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Converting a finite language to a regular expressionConverting a finite language to a regular expression

Convert each string in the language to a regular expression.This is just each string itself.

Then put these regular expressions together using the operator.The resulting regular expression accepts exactly the strings in .

Example

L

L

{010, 11, 21} ⟶ 010 ∪ 11 ∪ 21

7

Page 13: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Back to languages and representations …Back to languages and representations …

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

8

Page 14: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Back to languages and representations …Back to languages and representations …

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

How do we prove that all regular languages are context-free?

8

Page 15: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Back to languages and representations …Back to languages and representations …

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

How do we prove that all regular languages are context-free? By showing how toconstruct a CFG for every regular language!

8

Page 16: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Converting a regular expression to a CFGConverting a regular expression to a CFG

Use the following function on regular expressions: the CFG with no productions. the CFG with just the production . the CFG with just the production for every .

the CFG with the productions , , and . the CFG with the productions , , and .

the CFG with the productions and .

Example:

𝖼𝖿𝗀(∅) =

𝖼𝖿𝗀(ε) = → εSε

𝖼𝖿𝗀(a) = → aSa a ∈ Σ

𝖼𝖿𝗀(AB) = 𝖼𝖿𝗀(A) 𝖼𝖿𝗀(B) →SAB SASB

𝖼𝖿𝗀(A ∪ B) = 𝖼𝖿𝗀(A) 𝖼𝖿𝗀(B) → |SA∪B SA SB

𝖼𝖿𝗀( ) =A∗ 𝖼𝖿𝗀(A) → ε |SA∗ SASA∗

𝖼𝖿𝗀((1 ∪ 0 0))∗

S(1∪0 0)∗

S(1∪0)∗

S(1∪0)

S1

S0

→ S(1∪0)∗ S0

→ ε | S1∪0S(1∪0)∗

→ |S1 S0

→ 1

→ 0

9

Page 17: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Back again to languages and representations …Back again to languages and representations …

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

10

Page 18: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Back again to languages and representations …Back again to languages and representations …

Finite{010,11, 21}

Regular0*1* DFA

NFA Regex

Context-FreeCFG

All

S → 0S1 | ε

We saw in that the language of all binary palindromes can berepresented by a CFG. We also said that can’t be represented by any regularexpression. How would you prove that?

Lecture 21 B

B

10

Page 19: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Why isn’t Why isn’t (binary palindromes) a regular language? (binary palindromes) a regular language?

If were regular, we could express it as a DFA/NFA/RegEx.Let’s choose a DFA as our hypothetical representation.

BB

B

11

Page 20: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Why isn’t Why isn’t (binary palindromes) a regular language? (binary palindromes) a regular language?

If were regular, we could express it as a DFA/NFA/RegEx.Let’s choose a DFA as our hypothetical representation.

Now, recall that consists of infinitely many strings where is the reverse of and .

BB

B

B wvw⎯ ⎯⎯⎯

w⎯ ⎯⎯⎯

w v ∈ {ε, “0”, “1”}

11

Page 21: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Why isn’t Why isn’t (binary palindromes) a regular language? (binary palindromes) a regular language?

If were regular, we could express it as a DFA/NFA/RegEx.Let’s choose a DFA as our hypothetical representation.

Now, recall that consists of infinitely many strings where is the reverse of and .

What would a DFA need to keep track of to decide ?

BB

B

B wvw⎯ ⎯⎯⎯

w⎯ ⎯⎯⎯

w v ∈ {ε, “0”, “1”}

B

11

Page 22: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Why isn’t Why isn’t (binary palindromes) a regular language? (binary palindromes) a regular language?

If were regular, we could express it as a DFA/NFA/RegEx.Let’s choose a DFA as our hypothetical representation.

Now, recall that consists of infinitely many strings where is the reverse of and .

What would a DFA need to keep track of to decide ?It would need to keep track of in order to check against it.

BB

B

B wvw⎯ ⎯⎯⎯

w⎯ ⎯⎯⎯

w v ∈ {ε, “0”, “1”}

B

w w⎯ ⎯⎯⎯

11

Page 23: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Why isn’t Why isn’t (binary palindromes) a regular language? (binary palindromes) a regular language?

If were regular, we could express it as a DFA/NFA/RegEx.Let’s choose a DFA as our hypothetical representation.

Now, recall that consists of infinitely many strings where is the reverse of and .

What would a DFA need to keep track of to decide ?It would need to keep track of in order to check against it.But there are infinitely many possible ’s and finitely many DFA states!

BB

B

B wvw⎯ ⎯⎯⎯

w⎯ ⎯⎯⎯

w v ∈ {ε, “0”, “1”}

B

w w⎯ ⎯⎯⎯

w

11

Page 24: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Why isn’t Why isn’t (binary palindromes) a regular language? (binary palindromes) a regular language?

If were regular, we could express it as a DFA/NFA/RegEx.Let’s choose a DFA as our hypothetical representation.

Now, recall that consists of infinitely many strings where is the reverse of and .

What would a DFA need to keep track of to decide ?It would need to keep track of in order to check against it.But there are infinitely many possible ’s and finitely many DFA states!

BB

B

B wvw⎯ ⎯⎯⎯

w⎯ ⎯⎯⎯

w v ∈ {ε, “0”, “1”}

B

w w⎯ ⎯⎯⎯

w

This is the intuition for why is not regular. Let’s see how to turn this intuitioninto a formal proof.

B

11

Page 25: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A strategy for proving that A strategy for proving that is not regular is not regular

Proof by contradiction:Assume that is regular.Therefore, there is a DFA that recognizes .Show that accepts or rejects a string it shouldn’t.

BB

B

M B

M

12

Page 26: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A strategy for proving that A strategy for proving that is not regular is not regular

Proof by contradiction:Assume that is regular.Therefore, there is a DFA that recognizes .Show that accepts or rejects a string it shouldn’t.

Key Idea 1If two string prefixes collide by reaching the same state, aDFA can no longer distinguish their suffixes.

0a10b1

?

BB

B

M B

M

12

Page 27: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A strategy for proving that A strategy for proving that is not regular is not regular

Proof by contradiction:Assume that is regular.Therefore, there is a DFA that recognizes .Show that accepts or rejects a string it shouldn’t.

Key Idea 1If two string prefixes collide by reaching the same state, aDFA can no longer distinguish their suffixes.

0a10b1

?

Key Idea 2The machine has finitely many states, and since thestrings in have infinitely many distinct prefixes, two ofthem must collide!

BB

B

M B

M

M

B

12

Page 28: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A strategy for proving that A strategy for proving that is not regular is not regular

Proof by contradiction:Assume that is regular.Therefore, there is a DFA that recognizes .Show that accepts or rejects a string it shouldn’t.

Key Idea 1If two string prefixes collide by reaching the same state, aDFA can no longer distinguish their suffixes.

0a10b1

?

Key Idea 2The machine has finitely many states, and since thestrings in have infinitely many distinct prefixes, two ofthem must collide!

BB

B

M B

M

M

B

We choose an infinite set of prefixes. This choice mustensure that for every pair ofprefixes in ,there is a suffix such thatone of of is in butnot the other.

S

≠ ∈ Ssa sb

t

t, tsa sb B

S = {1, 01, 001, 0001, …}

= { 1 : n ≥ 0}0n

12

Page 29: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Proving that Proving that is not regular is not regularSuppose that some DFA recognizes . We show accepts or rejects astring it shouldn’t. Consider the set .

BB

M B M

S = { 1 : n ≥ 0}0n

13

Page 30: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Proving that Proving that is not regular is not regularSuppose that some DFA recognizes . We show accepts or rejects astring it shouldn’t. Consider the set .

Since there are finitely many states in and infinitely many strings in ,there exist strings and with that end in the samestate of .

BB

M B M

S = { 1 : n ≥ 0}0n

M S

1 ∈ S0a 1 ∈ S0b a ≠ b

M

13

Page 31: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Proving that Proving that is not regular is not regularSuppose that some DFA recognizes . We show accepts or rejects astring it shouldn’t. Consider the set .

Since there are finitely many states in and infinitely many strings in ,there exist strings and with that end in the samestate of .

BB

M B M

S = { 1 : n ≥ 0}0n

M S

1 ∈ S0a 1 ∈ S0b a ≠ b

M

Important: We don’t get to choose and ! We just know they exist.a b

13

Page 32: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Proving that Proving that is not regular is not regularSuppose that some DFA recognizes . We show accepts or rejects astring it shouldn’t. Consider the set .

Since there are finitely many states in and infinitely many strings in ,there exist strings and with that end in the samestate of .

Now, consider appending to both strings. 0a10b1

0a

BB

M B M

S = { 1 : n ≥ 0}0n

M S

1 ∈ S0a 1 ∈ S0b a ≠ b

M

0a

13

Page 33: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Proving that Proving that is not regular is not regularSuppose that some DFA recognizes . We show accepts or rejects astring it shouldn’t. Consider the set .

Since there are finitely many states in and infinitely many strings in ,there exist strings and with that end in the samestate of .

Now, consider appending to both strings. 0a10b1

0a

Since and end in the same state, so do and , call it .But then must make a mistake: needs to be an accept state since

, but then would accept , which is an error.

BB

M B M

S = { 1 : n ≥ 0}0n

M S

1 ∈ S0a 1 ∈ S0b a ≠ b

M

0a

10a 10b 0a10a 0b10a q

M q

∈ B0a10a M ∉ B0b10a◻

13

Page 34: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Proving irregularityProving irregularityA proof template for showing that a language is not regular.

14

Page 35: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A template for proving that a language A template for proving that a language is not regular is not regular

① Suppose for contradiction that some DFA recognizes .

LL

M

L

15

Page 36: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A template for proving that a language A template for proving that a language is not regular is not regular

① Suppose for contradiction that some DFA recognizes .

② Consider the set { }.

LL

M

L

S = …

must be infinite, andfor every pair of prefixes

, there is asuffix such that one ofof is in but notthe other.

S

≠ ∈ Ssa sb

t

t, tsa sb L

15

Page 37: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A template for proving that a language A template for proving that a language is not regular is not regular

① Suppose for contradiction that some DFA recognizes .

② Consider the set { }.

③ Since is infinite and has finitely many states, theremust be two strings such that and bothend in the same state of .

LL

M

L

S = …

S M

,sa sb ∈ S ≠sa sb

M

must be infinite, andfor every pair of prefixes

, there is asuffix such that one ofof is in but notthe other.

We don’t get to choose and !

S

≠ ∈ Ssa sb

t

t, tsa sb L

sa sb

15

Page 38: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A template for proving that a language A template for proving that a language is not regular is not regular

① Suppose for contradiction that some DFA recognizes .

② Consider the set { }.

③ Since is infinite and has finitely many states, theremust be two strings such that and bothend in the same state of .

④ Consider appending to both and .

LL

M

L

S = …

S M

,sa sb ∈ S ≠sa sb

M

t sa sb

must be infinite, andfor every pair of prefixes

, there is asuffix such that one ofof is in but notthe other.

We don’t get to choose and !

should be an acceptsuffix for but not .

S

≠ ∈ Ssa sb

t

t, tsa sb L

sa sb

t

sa sb

15

Page 39: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A template for proving that a language A template for proving that a language is not regular is not regular

① Suppose for contradiction that some DFA recognizes .

② Consider the set { }.

③ Since is infinite and has finitely many states, theremust be two strings such that and bothend in the same state of .

④ Consider appending to both and .

⑤ Since and end in the same state of , then and also end in the same state of . Since and , does not recognize .

LL

M

L

S = …

S M

,sa sb ∈ S ≠sa sb

M

t sa sb

sa sb M tsa

tsb q M t ∈ Lsa

t ∉ Lsb M L

must be infinite, andfor every pair of prefixes

, there is asuffix such that one ofof is in but notthe other.

We don’t get to choose and !

should be an acceptsuffix for but not .

S

≠ ∈ Ssa sb

t

t, tsa sb L

sa sb

t

sa sb

15

Page 40: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A template for proving that a language A template for proving that a language is not regular is not regular

① Suppose for contradiction that some DFA recognizes .

② Consider the set { }.

③ Since is infinite and has finitely many states, theremust be two strings such that and bothend in the same state of .

④ Consider appending to both and .

⑤ Since and end in the same state of , then and also end in the same state of . Since and , does not recognize .

⑥ Since was arbitrary, no DFA recognizes .

LL

M

L

S = …

S M

,sa sb ∈ S ≠sa sb

M

t sa sb

sa sb M tsa

tsb q M t ∈ Lsa

t ∉ Lsb M L

M L

must be infinite, andfor every pair of prefixes

, there is asuffix such that one ofof is in but notthe other.

We don’t get to choose and !

should be an acceptsuffix for but not .

S

≠ ∈ Ssa sb

t

t, tsa sb L

sa sb

t

sa sb

15

Page 41: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set

LL == {{ :: nn ≥≥ 00}}00nn11nn

M L

S =

16

Page 42: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

LL == {{ :: nn ≥≥ 00}}00nn11nn

M L

S = { : n ≥ 0}0n

16

Page 43: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

LL == {{ :: nn ≥≥ 00}}00nn11nn

M L

S = { : n ≥ 0}0n

S M

,0a 0b∈ S a ≠ b M

16

Page 44: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

LL == {{ :: nn ≥≥ 00}}00nn11nn

M L

S = { : n ≥ 0}0n

S M

,0a 0b∈ S a ≠ b M

0a 0b

16

Page 45: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

LL == {{ :: nn ≥≥ 00}}00nn11nn

M L

S = { : n ≥ 0}0n

S M

,0a 0b∈ S a ≠ b M

1a 0a 0b

16

Page 46: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

Since and end in the same state of , then and also end inthe same state of . Since and , does not recognize

.

LL == {{ :: nn ≥≥ 00}}00nn11nn

M L

S = { : n ≥ 0}0n

S M

,0a 0b∈ S a ≠ b M

1a 0a 0b

0a 0b M 0a1a 0b1a

q M ∈ L0a1a∉ L0b1a M

L

16

Page 47: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

Since and end in the same state of , then and also end inthe same state of . Since and , does not recognize

.

Since was arbitrary, no DFA recognizes .

LL == {{ :: nn ≥≥ 00}}00nn11nn

M L

S = { : n ≥ 0}0n

S M

,0a 0b∈ S a ≠ b M

1a 0a 0b

0a 0b M 0a1a 0b1a

q M ∈ L0a1a∉ L0b1a M

L

M L

16

Page 48: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set

LL == {{ :: nn ≥≥ 00}}((nn))nn

M L

S =

17

Page 49: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

LL == {{ :: nn ≥≥ 00}}((nn))nn

M L

S = { : n ≥ 0}(n

17

Page 50: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

LL == {{ :: nn ≥≥ 00}}((nn))nn

M L

S = { : n ≥ 0}(n

S M

,(a (b ∈ S a ≠ b M

17

Page 51: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

LL == {{ :: nn ≥≥ 00}}((nn))nn

M L

S = { : n ≥ 0}(n

S M

,(a (b ∈ S a ≠ b M

(a (b

17

Page 52: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

LL == {{ :: nn ≥≥ 00}}((nn))nn

M L

S = { : n ≥ 0}(n

S M

,(a (b ∈ S a ≠ b M

)a (a (b

17

Page 53: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

Since and end in the same state of , then and also end in thesame state of . Since and , does not recognize .

LL == {{ :: nn ≥≥ 00}}((nn))nn

M L

S = { : n ≥ 0}(n

S M

,(a (b ∈ S a ≠ b M

)a (a (b

(a (b M (a)a (b)a

q M ∈ L(a)a ∉ L(b)a M L

17

Page 54: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

Example: prove that Example: prove that is not regular is not regularSuppose for contradiction that some DFA recognizes .

Consider the set .

Since is infinite and has finitely many states, there must be two strings with that both end in the same state of .

Consider appending to both and .

Since and end in the same state of , then and also end in thesame state of . Since and , does not recognize .

Since was arbitrary, no DFA recognizes .

LL == {{ :: nn ≥≥ 00}}((nn))nn

M L

S = { : n ≥ 0}(n

S M

,(a (b ∈ S a ≠ b M

)a (a (b

(a (b M (a)a (b)a

q M ∈ L(a)a ∉ L(b)a M L

M L

17

Page 55: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A fun fact about this proof methodA fun fact about this proof methodSuppose that for a language , the set is a largest set of prefix strings withthe property that for every pair , there is some string such thatone of is in but the other isn’t.

L S

≠ ∈ Ssa sb t

t, tsa sb L

18

Page 56: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A fun fact about this proof methodA fun fact about this proof methodSuppose that for a language , the set is a largest set of prefix strings withthe property that for every pair , there is some string such thatone of is in but the other isn’t.

If is infinite, then is not regular.

L S

≠ ∈ Ssa sb t

t, tsa sb L

S L

18

Page 57: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

A fun fact about this proof methodA fun fact about this proof methodSuppose that for a language , the set is a largest set of prefix strings withthe property that for every pair , there is some string such thatone of is in but the other isn’t.

If is infinite, then is not regular.

If is finite, then the minimal DFA for has precisely states, one reachedby each member of .

L S

≠ ∈ Ssa sb t

t, tsa sb L

S L

S L |S|

S

18

Page 58: Expressions of DFAs, NFAs, and Regular CSE 311 Lecture 26 ...Key Idea 1 If tw o string prefixes collide b y reaching the same state, a DFA can no longer distinguish their suffix es

SummarySummaryDFAs NFAs regular expressions.

We’ve shown how to go from a regular expression to an NFA to a DFA.(And going from an NFA to a DFA can lead to exponential blow-up.)But we won’t show how to go from an NFA/DFA to a regular expression.

Finite regular context-free languages.To show that a language is regular, construct a DFA/NFA/RegEx for it.To show that it is not regular, use the proof method from this lecture.

≡ ≡

⊂ ⊂

19