65
Finite Automata COMP 455 – 002, Spring 2019 Jim Anderson (modified by Nathan Otterness) 1

Finite Automata

Embed Size (px)

Citation preview

Finite AutomataCOMP 455 – 002, Spring 2019

Jim Anderson (modified by Nathan Otterness) 1

Example: Detect Even Number of 1s

Jim Anderson (modified by Nathan Otterness) 2

This is a β€œtransition diagram” for a deterministic finite automaton.

Diagrams like this visualize automata like a simple game.

Example: Detect Even Number of 1s

Jim Anderson (modified by Nathan Otterness) 3

In this β€œgame”, we will move from circle to circle, following the instructions given by an input string.

Input string: 1111

Example: Detect Even Number of 1s

Jim Anderson (modified by Nathan Otterness) 4

The β€œplayer” starts at the indicated circle:

Input string: 1111

Example: Detect Even Number of 1s

Jim Anderson (modified by Nathan Otterness) 5

The β€œgame” proceeds by reading one character at a time from the input string and following the path labeled with the character.

Input string: 1111

Current Symbol

Example: Detect Even Number of 1s

Jim Anderson (modified by Nathan Otterness) 6

The β€œgame” ends when all input symbols have been read.

Input string: 1111

Current Symbol

Done!

Defining a Deterministic Finite Automaton

We define a deterministic finite automaton (DFA) as a 5-tuple: 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

𝑄: A set of states

Ξ£: A set of input symbols (the alphabet)

π‘ž0: The initial state. π‘ž0 ∈ 𝑄.

𝐹: A set of accepting (β€œfinal”) states. 𝐹 βŠ† 𝑄.

𝛿: The β€œtransition function” mapping 𝑄 Γ— Ξ£ β†’ 𝑄.

Jim Anderson (modified by Nathan Otterness) 7

𝛿 must be defined for all symbols in all states.

𝛿 returns a single state.

From the Diagram to 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

Jim Anderson (modified by Nathan Otterness) 8

The circles represent states.

𝑄 = π‘ž0, π‘ž1

From the Diagram to 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

Jim Anderson (modified by Nathan Otterness) 9

This automaton only handles strings of 1s

Ξ£ = 1

From the Diagram to 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

Jim Anderson (modified by Nathan Otterness) 10

The initial state is labeled with β€œStart”

π‘ž0 = π‘ž0

From the Diagram to 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

Jim Anderson (modified by Nathan Otterness) 11

Accepting states have double circles. This automaton only has one.

𝐹 = π‘ž0

From the Diagram to 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

Jim Anderson (modified by Nathan Otterness) 12

The arrows connecting the states represent possible transitions.

𝛿 is the automaton’s transition function:𝛿 π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘ π‘ π‘‘π‘Žπ‘‘π‘’, π‘π‘’π‘Ÿπ‘Ÿπ‘’π‘›π‘‘ π‘ π‘¦π‘šπ‘π‘œπ‘™= π‘‘π‘’π‘ π‘‘π‘–π‘›π‘Žπ‘‘π‘–π‘œπ‘› π‘ π‘‘π‘Žπ‘‘π‘’

𝛿 can be represented as a table:

𝜹 1

π‘ž0 π‘ž1

π‘ž1 π‘ž0

Current state

Current input symbol

Destination state

From the Diagram to 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

Jim Anderson (modified by Nathan Otterness) 13

This automaton in tuple notation:

𝑄 = π‘ž0, π‘ž1

Ξ£ = 1

π‘ž0 = π‘ž0

𝐹 = π‘ž0

𝛿 = 𝜹 1

π‘ž0 π‘ž1

π‘ž1 π‘ž0

We use a table here, but 𝛿 can also be described using words,

mathematical formulas, etc.

β€œTransition Table” Representation

Jim Anderson (modified by Nathan Otterness) 14

The table for 𝛿 implicitly lists the states and alphabet.

A β€œtransition table” just adds the remaining needed information:

Indicate the start state with β†’

Indicate accepting states with βˆ—

Example: 𝜹 1

βˆ—β†’ π‘ž0 π‘ž1

π‘ž1 π‘ž0

Notation: Extending 𝛿 to Strings

An automaton’s standard transition function, 𝛿, takes two parameters: a state and a symbol.

The β€œextended transition function”, αˆ˜π›Ώ, takes a state and a string.

αˆ˜π›Ώ can be defined in terms of 𝛿:

❖ Assume that 𝑀 is a string, π‘Ž is a symbol in Ξ£, and π‘ž is a state.

❖ Recursively, αˆ˜π›Ώ π‘ž,π‘€π‘Ž = 𝛿 αˆ˜π›Ώ π‘ž, 𝑀 , π‘Ž .

Examples from the previous automaton:

❖ αˆ˜π›Ώ π‘ž0, νœ€ = π‘ž0

❖ αˆ˜π›Ώ π‘ž0, 111 = π‘ž1

❖ αˆ˜π›Ώ π‘ž0, 1111 = π‘ž0

Jim Anderson (modified by Nathan Otterness) 15

𝛿 π‘ž, π‘Ž = αˆ˜π›Ώ π‘ž, π‘Ž for DFAs.

Example: Proofs About Automata

Here is a more complex automaton.

Transition table representation:

Jim Anderson (modified by Nathan Otterness) 16

𝜹 0 1

β†’ π‘ž0 π‘ž1 π‘ž0

π‘ž1 π‘ž0 π‘ž2

βˆ— π‘ž2 π‘ž0 π‘ž2

Example: Proofs About Automata

Questions:

What language does this automaton represent?

How should we prove it’s correct?

Jim Anderson (modified by Nathan Otterness) 17

Example: Proofs About Automata

𝐿 = {π‘₯|π‘₯ has an odd number of 0s and ends with a 1}.

We will prove this by induction on the length of an input string, π‘₯.

Jim Anderson (modified by Nathan Otterness) 18

Example: Proofs About Automata

We start our proof by defining what each state means about the input read so far:

π‘ž0: Even # of 0s

π‘ž1: Odd # of 0s, and ends with a 0

π‘ž2: Odd # of 0s, and ends with a 1

Jim Anderson (modified by Nathan Otterness) 19

Proof obligation:Show that these definitions are correct!

Example: Proofs About Automata

Base case: Prove the definition is correct for a string of length 0 (νœ€).

The automaton is in state π‘ž0 after processing νœ€.

Since νœ€ contains an even number of 0s, our definition of π‘ž0 holds.

Jim Anderson (modified by Nathan Otterness) 20

Example: Proofs About Automata

Inductive step: Assume that αˆ˜π›Ώ π‘ž0, π‘₯ is correct for string π‘₯.

We need to prove that αˆ˜π›Ώ π‘ž0, π‘₯π‘Ž remains correct for any symbol π‘Ž.

This requires proving correctness for all possible transitions from all three states (mutual induction).

Jim Anderson (modified by Nathan Otterness) 21

Example: Proofs About Automata

Induction part 1: state π’’πŸŽ

If αˆ˜π›Ώ π‘ž0, π‘₯ = π‘ž0, then we can assume π‘₯ contained an even number of 0s.

𝛿 π‘ž0, 1 = π‘ž0. Reading a 1 doesn’t change the # of 0s, so this is correct.

𝛿 π‘ž0, 0 = π‘ž1. We’ve read an odd # of zeros, but the string doesn’t end in 1 yet.

Jim Anderson (modified by Nathan Otterness) 22

Example: Proofs About Automata

Induction part 2: state π’’πŸ

If αˆ˜π›Ώ π‘ž0, π‘₯ = π‘ž1, then we can assume π‘₯ contained an odd number of 0s and ends with a 0.

𝛿 π‘ž1, 1 = π‘ž2. The string contains an odd # of 0s, but now ends with 1.

𝛿 π‘ž1, 0 = π‘ž0. Reading an additional 0 means that the string contains an even number of 0s.Jim Anderson (modified by Nathan Otterness) 23

Example: Proofs About Automata

Induction part 3: state π’’πŸIf αˆ˜π›Ώ π‘ž0, π‘₯ = π‘ž2, then we can assume π‘₯ contained an odd number of 0s and ends with a 1.

𝛿 π‘ž2, 1 = π‘ž2. This doesn’t change the # of 0s or the fact that the string ends with a 1.

𝛿 π‘ž2, 0 = π‘ž0. Reading an additional 0 means that the string contains an even number of 0s.

Jim Anderson (modified by Nathan Otterness) 24

Example: Proofs About Automata

Finishing up:We’ve now proven that our claims about the states were correct, but we still need to prove the automaton recognizes the language.

Jim Anderson (modified by Nathan Otterness) 25

The automaton ends in π‘ž2 if and only if the string contained an odd number of 0s and ended with 1.

Since π‘ž2 is the only accepting state, the automaton accepts strings if and only if they contain an odd number of 0s and end with a 1.

Nondeterministic Finite Automata

We’ve been looking at deterministic finite automata (DFAs) so far.

❖𝛿 returns exactly one state for every symbol in every state

With nondeterministic finite automata (NFAs), the transition function 𝛿 returns a set of states.

❖𝛿: 𝑄 Γ— Ξ£ β†’ 2𝑄

❖This can include no states at all!

Jim Anderson (modified by Nathan Otterness) 26

2𝑄: The power set of 𝑄. (the set of all possible

subsets of 𝑄)

Note on β€œNondeterministic” Terminology

DFAs always follow the same path for a single input string.

❖DFAs accept a string if and only if this path leads to an accepting state.

NFAs may follow one of many different paths for the same input string.

❖This is why they are called nondeterministic.

❖NFAs accept strings if and only if it is possible for them to reach an accepting state for a given input string.

Jim Anderson (modified by Nathan Otterness) 27

Extended Transition Function for NFAs

As with DFAs, αˆ˜π›Ώ for NFAs processes a string rather than a single character.

As with the definition of 𝛿 for NFAs, αˆ˜π›Ώ for NFAs returns the set of states an NFA is in after processing a string.

If an NFA has a start state π‘ž, then the NFA accepts

string π‘₯ if and only if αˆ˜π›Ώ π‘ž, π‘₯ ∩ 𝐹 β‰  βˆ…

β–β€œThe set of states after processing π‘₯ contains at least one accepting state”

Jim Anderson (modified by Nathan Otterness) 28

Recursive Definition of αˆ˜π›Ώ for NFAs

αˆ˜π›Ώ π‘ž, νœ€ = π‘ž

αˆ˜π›Ώ π‘ž, π‘€π‘Ž ={ 𝑝 | for some state π‘Ÿ in αˆ˜π›Ώ π‘ž, 𝑀 , 𝑝 is in 𝛿 π‘Ÿ, π‘Ž }

Jim Anderson (modified by Nathan Otterness) 29

q

w

w

a

a

aStates inαˆ˜π›Ώ π‘ž, π‘€π‘Ž .

Note: This isa set.

As with DFAs,

𝛿 π‘ž, π‘Ž = αˆ˜π›Ώ π‘ž, π‘Ž for NFAs.

Definition of 𝛿 for Sets of States

Since 𝛿 can return a set of states for NFAs, it can be helpful to define a version of 𝛿 that takes a set of states rather than a single state.

If 𝑃 is a set of states,𝛿 𝑃, π‘Ž = β‹ƒπ‘žβˆˆπ‘ƒπ›Ώ π‘ž, π‘Ž

Jim Anderson (modified by Nathan Otterness) 30

Nondeterministic Finite Automata

Example: Match all strings ending with 01

Jim Anderson (modified by Nathan Otterness) 31

𝜹 0 1

β†’ π‘ž0 π‘ž0, π‘ž1 π‘ž0

π‘ž1 βˆ… π‘ž2

βˆ— π‘ž2 βˆ… βˆ…

Example NFA Execution

Jim Anderson (modified by Nathan Otterness) 32

Input string: 10101

Current Symbol

Example NFA Execution

Jim Anderson (modified by Nathan Otterness) 33

Input string: 10101

Current Symbol

Done!

Example NFA Execution

Jim Anderson (modified by Nathan Otterness) 34

Input string: 10101

𝐹 = π‘ž2

αˆ˜π›Ώ π‘ž0, 10101 = π‘ž0, π‘ž2

π‘ž0, π‘ž2 ∩ 𝐹 = π‘ž2

As expected, this NFA accepts 10101, because it ends in a set of states containing an accepting state.

NFAs vs DFAs

NFAs are often more convenient than DFAs

❖Write an NFA that accepts L = {x|x is a string of 0s or 1s that contains 0101000 as a substring}

❖Now write a DFA that accepts L

Good news: Any language that can be recognized by an NFA can also be recognized by a DFA.

Jim Anderson (modified by Nathan Otterness) 35

Equivalence of NFAs and DFAs

Let 𝑁 = 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹 be an NFA.

We will show how to construct an equivalent DFA, 𝐷, using a technique called subset construction.

Main idea: 𝐷 will keep track of the subset of states that 𝑁 might be in.

❖In other words, each of 𝐷’s states corresponds to a subset of 𝑁’s states.

Jim Anderson (modified by Nathan Otterness) 36

Subset Construction

The constructed DFA 𝐷 = 𝑄′, Ξ£, 𝛿′, π‘ž0β€² , 𝐹′ , where:

❖𝑄′ = 2𝑄 = Assuming the states in 𝑄 are π‘ž0, π‘ž1, … , π‘žπ‘› , the states in 𝑄′ are all possible

subsets of π‘ž0, π‘ž1, … , π‘žπ‘› .

β–π‘ž0β€² = π‘ž0

❖𝐹′ = {π‘ž ∈ 𝑄′ | π‘ž = … , π‘žπ‘— , … and π‘žπ‘— ∈ 𝐹}

β‘β€œπ·β€™s final states consist of all subsets containing one or more of 𝑁’s final states.”

❖For all π‘ž and 𝑝 in 𝑄′, 𝛿′ π‘ž, π‘Ž = 𝑝 iff 𝛿 π‘ž, π‘Ž = 𝑝.

Jim Anderson (modified by Nathan Otterness) 37

Subset Construction: Example

Jim Anderson (modified by Nathan Otterness) 38

Start with the following NFA:

❖𝑁 = π‘ž0, π‘ž1, π‘ž2 , 0, 1 , 𝛿, π‘ž0, π‘ž2

❖𝛿 =

Construct DFA 𝐷 = 𝑄′, 0, 1 , 𝛿′, π‘ž0 , 𝐹′ , where

❖𝑄′ =

βˆ…, π‘ž0 , π‘ž1 , π‘ž2 , π‘ž0, π‘ž1 , π‘ž0, π‘ž2 , π‘ž1, π‘ž2 , π‘ž0, π‘ž1, π‘ž2

❖𝐹′ = q2 , q0, q2 , q1, q2 , q0, q1, q2

❖𝛿′ is defined on the following slide.

𝜹 0 1

π‘ž0 π‘ž1 π‘ž0

π‘ž1 π‘ž0 π‘ž1, π‘ž2

π‘ž2 βˆ… βˆ…

Subset Construction: Example

𝛿′ =

Jim Anderson (modified by Nathan Otterness) 39

𝟎 𝟏

βˆ… βˆ… βˆ…

π‘ž0 {π‘ž1} π‘ž0

π‘ž1 π‘ž0 π‘ž1, π‘ž2

π‘ž2 βˆ… βˆ…

π‘ž0, π‘ž1 π‘ž0, π‘ž1 π‘ž0, π‘ž1, π‘ž2

π‘ž0, π‘ž2 π‘ž1 π‘ž0

π‘ž1, π‘ž2 π‘ž0 π‘ž1, π‘ž2

π‘ž0, π‘ž1, π‘ž2 π‘ž0, π‘ž1 π‘ž0, π‘ž1, π‘ž2

Subset Construction: Example

Diagram for 𝐷:

Jim Anderson (modified by Nathan Otterness) 40

πœΉβ€² 𝟎 𝟏

βˆ… βˆ… βˆ…

β†’ π‘ž0 {π‘ž1} π‘ž0

π‘ž1 π‘ž0 π‘ž1, π‘ž2

βˆ— π‘ž2 βˆ… βˆ…

π‘ž0, π‘ž1 π‘ž0, π‘ž1 π‘ž0, π‘ž1, π‘ž2

βˆ— π‘ž0, π‘ž2 π‘ž1 π‘ž0

βˆ— π‘ž1, π‘ž2 π‘ž0 π‘ž1, π‘ž2

βˆ— π‘ž0, π‘ž1, π‘ž2 π‘ž0, π‘ž1 π‘ž0, π‘ž1, π‘ž2

Subset Construction: Example

Jim Anderson (modified by Nathan Otterness) 41

We don’t care about these states; they are unreachablefrom the start state.

Diagram for 𝐷:

Subset Construction: Example

Jim Anderson (modified by Nathan Otterness) 42

Diagram for 𝐷 without unreachable states:

Theorem 2.11

Proof: We need to show that αˆ˜π›Ώβ€² π‘ž0β€² , π‘₯ = 𝑆 if and only

if αˆ˜π›Ώ π‘ž0, π‘₯ = 𝑆.

We will prove this by induction on π‘₯ .

Jim Anderson (modified by Nathan Otterness) 43

Theorem 2.11 (from the textbook):If 𝑁 is the original NFA and 𝐷 is the constructed DFA (as defined earlier), then 𝐿 𝑁 = 𝐿 𝐷 .

Proof of Theorem 2.11

Base case:

π‘₯ = 0. (Put another way, π‘₯ = νœ€).

Verifying the base case:αˆ˜π›Ώβ€² π‘ž0

β€² , νœ€ = π‘ž0β€² = π‘ž0

andαˆ˜π›Ώ π‘ž0, νœ€ = {π‘ž0}

by the definition of the extended transition function.

So, 𝐿 𝑁 = 𝐿 𝐷 holds for the base case.

Jim Anderson (modified by Nathan Otterness) 44

Reminder:𝛿′ is for the DFA 𝐷𝛿 is for the NFA 𝑁

Proof of Theorem 2.11

Inductive step:

By the inductive hypothesis we assume that:

αˆ˜π›Ώβ€² π‘ž0β€² , π‘₯ = 𝑆 iff αˆ˜π›Ώ π‘ž0, π‘₯ = 𝑆

We now apply the definition of the extended transition function to advance by a single symbol:

αˆ˜π›Ώβ€² 𝑆, π‘Ž = 𝑇 iff αˆ˜π›Ώ 𝑆, π‘Ž = 𝑇, by the definition of 𝛿′.

Therefore αˆ˜π›Ώβ€² π‘ž0β€² , π‘₯ = 𝑇 iff αˆ˜π›Ώ π‘ž0, π‘₯ = 𝑇.

Jim Anderson (modified by Nathan Otterness) 45

Reminder:𝛿′ is for the DFA 𝐷𝛿 is for the NFA 𝑁

Reminder:For string 𝑀 and symbol π‘Ž:αˆ˜π›Ώ π‘ž, π‘€π‘Ž = 𝛿 αˆ˜π›Ώ π‘ž, 𝑀 , π‘Ž

Finishing the Proof of Theorem 2.11

Finally, since αˆ˜π›Ώβ€² π‘ž0β€² , π‘₯ is in 𝐹′ if and only if αˆ˜π›Ώ π‘ž0, π‘₯

contains a state in 𝐹, 𝐿 𝐷 = 𝐿 𝑁 .

Note: This construction results in a state explosion.

Jim Anderson (modified by Nathan Otterness) 46

Reminder:𝛿′ is for the DFA 𝐷𝛿 is for the NFA 𝑁

NFAs with νœ€-Transitions

NFAs with νœ€-transitions have all the same rules as regular NFAs, but with additional flexibility.

The transition function for NFAs with νœ€-transitions:𝛿: 𝑄 Γ— Ξ£ βˆͺ νœ€ β†’ 2𝑄

Example:

Jim Anderson (modified by Nathan Otterness) 47

νœ€-Closure

Let 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž β‰‘π‘ž βˆͺ 𝑝 | 𝑝 is reachable from π‘ž via νœ€ βˆ’ transitions

𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0 = π‘ž0, π‘ž1, π‘ž2

𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž1 = π‘ž1, π‘ž2

For a set of states 𝑃,𝐸𝐢𝐿𝑂𝑆𝐸 𝑃 ≑ βˆͺπ‘žβˆˆπ‘ƒ 𝐸𝐢𝐿𝑂𝑆𝐸(π‘ž)

Jim Anderson (modified by Nathan Otterness) 48

Definition of αˆ˜π›Ώ for νœ€-NFAs

Recursive definition of αˆ˜π›Ώ:

αˆ˜π›Ώ π‘ž, νœ€ = 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž

For a string 𝑀 and symbol π‘Ž: αˆ˜π›Ώ π‘ž, π‘€π‘Ž = 𝐸𝐢𝐿𝑂𝑆𝐸 𝑃 ,

where 𝑃 = 𝑝 | for some π‘Ÿ in αˆ˜π›Ώ π‘ž, 𝑀 , 𝑝 is in αˆ˜π›Ώ π‘Ÿ, π‘Ž

In other words, αˆ˜π›Ώ π‘ž, π‘Ž = 𝐸𝐢𝐿𝑂𝑆𝐸 𝛿 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž , π‘Ž

for a starting state π‘ž and a single symbol π‘Ž.

Jim Anderson (modified by Nathan Otterness) 49

Unlike before, αˆ˜π›Ώ π‘ž, π‘Ž β‰  𝛿 π‘ž, π‘Ž for νœ€-NFAs!

νœ€-NFA Example

Jim Anderson (modified by Nathan Otterness) 50

Input string: 011

αˆ˜π›Ώ π‘ž0 , νœ€ = π‘ž0, π‘ž1, π‘ž2

How to simulate an νœ€-NFA:1. Follow transitions as you

would for a normal NFA.2. Take the νœ€-closure for

any states you end up in.

νœ€-NFA Example

Jim Anderson (modified by Nathan Otterness) 51

Input string: 011

Current Symbol

αˆ˜π›Ώ π‘ž0 , 0 = π‘ž0, π‘ž1, π‘ž2

How to simulate an νœ€-NFA:1. Follow transitions as you

would for a normal NFA.2. Take the νœ€-closure for

any states you end up in.

νœ€-NFA Example

Jim Anderson (modified by Nathan Otterness) 52

Input string: 011

Current Symbol

αˆ˜π›Ώ π‘ž0 , 01 = π‘ž1, π‘ž2

How to simulate an νœ€-NFA:1. Follow transitions as you

would for a normal NFA.2. Take the νœ€-closure for

any states you end up in.

νœ€-NFA Example

Jim Anderson (modified by Nathan Otterness) 53

Input string: 011

Current Symbol

αˆ˜π›Ώ π‘ž0 , 011 = π‘ž1, π‘ž2

How to simulate an νœ€-NFA:1. Follow transitions as you

would for a normal NFA.2. Take the νœ€-closure for

any states you end up in.

νœ€-NFA Example

Jim Anderson (modified by Nathan Otterness) 54

Input string: 011

Current Symbol

αˆ˜π›Ώ π‘ž0 , 011 = π‘ž1, π‘ž2

How to simulate an νœ€-NFA:1. Follow transitions as you

would for a normal NFA.2. Take the νœ€-closure for

any states you end up in.

Done!

Extending 𝛿 to Sets of States

This is similar to normal NFAs. If 𝑅 is a set of states:

𝛿 𝑅, π‘Ž = βˆͺπ‘žβˆˆπ‘… 𝛿 π‘ž, π‘Žαˆ˜π›Ώ 𝑅,𝑀 =βˆͺπ‘žβˆˆπ‘…

αˆ˜π›Ώ π‘ž, 𝑀

Jim Anderson (modified by Nathan Otterness) 55

The Language of an νœ€-NFA

NFAs with νœ€-transitions define languages similarly to standard NFAs:

If 𝑀 is an NFA with νœ€-transitions, then:

𝐿 𝑀 ≑ 𝑀 | αˆ˜π›Ώ π‘ž0, 𝑀 contains a state in 𝐹

More good news: any language that can be recognized by an νœ€-NFA can also be recognized by an NFA without νœ€-transitions.

Jim Anderson (modified by Nathan Otterness) 56

Eliminating νœ€-Transitions

The textbook shows how to transform an NFA with νœ€-transitions to a DFA.

We will instead show how to transform an NFA with νœ€ transitions into an NFA without νœ€-transitions.

❖You could then transform such an NFA into a DFA using subset construction.

Jim Anderson (modified by Nathan Otterness) 57

Eliminating νœ€-Transitions

Let 𝐸 be an NFA with νœ€-transitions: 𝑄, Ξ£, 𝛿, π‘ž0, 𝐹

Define 𝑁 to be an NFA without νœ€-transitions.𝑁 = 𝑄, Ξ£, 𝛿′, π‘ž0, 𝐹

β€² , where:

❖𝛿′ π‘ž, π‘Ž ≑ αˆ˜π›Ώ π‘ž, π‘Ž

❖𝐹′ ≑ α‰ŠπΉ βˆͺ π‘ž0𝐹

Jim Anderson (modified by Nathan Otterness) 58

, if 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0 contained a state in 𝐹, otherwise

Eliminating νœ€-Transitions: Example

Jim Anderson (modified by Nathan Otterness) 59

𝑁 = 𝑄, Ξ£, 𝛿′, π‘ž0, 𝐹′ , where:

β€’ 𝛿′ π‘ž, π‘Ž ≑ 𝛿 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž , π‘Ž

β€’ 𝐹′ ≑ α‰ŠπΉ βˆͺ π‘ž0𝐹

, if 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0 contained a state in F, otherwise

𝟎 𝟏 𝟐

π‘ž0 π‘ž0, π‘ž1, π‘ž2 π‘ž1, π‘ž2 π‘ž2

π‘ž1 βˆ… π‘ž1, π‘ž2 π‘ž2

π‘ž2 βˆ… βˆ… π‘ž2

𝛿′ = 𝐹′ = π‘ž0, π‘ž2

Theorem 2.22

If: Proving this is easy (see Theorem 2.22 in the book)

Only if: The textbook directly constructs a DFA 𝐷from νœ€-NFA 𝐸, but we will instead construct an ordinary NFA 𝑁, and use Theorem 2.11 to conclude that Theorem 2.22 holds. We start by defining 𝑁 as it was on the preceding slides.

Jim Anderson (modified by Nathan Otterness) 60

Theorem 2.22 (from the textbook):Language 𝐿 is accepted by an νœ€-NFA 𝐸 if and only if it is accepted by some DFA 𝐷.

First Claim in Proof of Theorem 2.22

Rather than starting with a claim about 𝐿 𝐸 or 𝐿 𝑁 , we instead

claim that αˆ˜π›Ώβ€² π‘ž0, π‘₯ = αˆ˜π›Ώ π‘ž0, π‘₯ for some string π‘₯.

Jim Anderson (modified by Nathan Otterness) 61

Reminder:𝛿′ is for the NFA 𝑁𝛿 is for the νœ€-NFA 𝐸

We will prove this claim using induction on π‘₯ .

Note: This may not hold for π‘₯ = 0. For example,

in the previous example αˆ˜π›Ώ π‘ž0, νœ€ = {π‘ž0, π‘ž1, π‘ž2}, but αˆ˜π›Ώβ€² π‘ž0, νœ€ = π‘ž0 .

We instead use π‘₯ = 1 as our base case (next slide).

𝑁 = 𝑄, Ξ£, 𝛿′, π‘ž0, 𝐹′ , where:

β€’ 𝛿′ π‘ž, π‘Ž ≑ 𝛿 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž , π‘Ž

β€’ 𝐹′ ≑ α‰ŠπΉ βˆͺ π‘ž0𝐹

, if 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0 contained a state in F, otherwise

Proof of Theorem 2.22: Base Case

Jim Anderson (modified by Nathan Otterness) 62

Base case: π‘₯ = 1

For any symbol π‘Ž, αˆ˜π›Ώβ€² π‘ž0, π‘Ž = αˆ˜π›Ώ π‘ž0, π‘Ž , by the definition of 𝛿′.

Reminder:𝛿′ is for the NFA 𝑁𝛿 is for the νœ€-NFA 𝐸

Claim:αˆ˜π›Ώβ€² π‘ž0, π‘₯ = αˆ˜π›Ώ π‘ž0, π‘₯

𝑁 = 𝑄, Ξ£, 𝛿′, π‘ž0, 𝐹′ , where:

β€’ 𝛿′ π‘ž, π‘Ž ≑ 𝛿 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž , π‘Ž

β€’ 𝐹′ ≑ α‰ŠπΉ βˆͺ π‘ž0𝐹

, if 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0 contained a state in F, otherwise

Proof of Theorem 2.22: Inductive Step

Jim Anderson (modified by Nathan Otterness) 63

Reminder:𝛿′ is for the NFA 𝑁𝛿 is for the νœ€-NFA 𝐸

Claim:αˆ˜π›Ώβ€² π‘ž0, π‘₯ = αˆ˜π›Ώ π‘ž0, π‘₯

𝑁 = 𝑄, Ξ£, 𝛿′, π‘ž0, 𝐹′ , where:

β€’ 𝛿′ π‘ž, π‘Ž ≑ 𝛿 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž , π‘Ž

β€’ 𝐹′ ≑ α‰ŠπΉ βˆͺ π‘ž0𝐹

, if 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0 contained a state in F, otherwise

Let π‘₯ = π‘€π‘Ž, where 𝑀 is a string and π‘Ž is a symbol.

We must show that αˆ˜π›Ώβ€² π‘ž0, π‘₯ =αˆ˜π›Ώ π‘ž0, π‘₯ .

By the inductive hypothesis, αˆ˜π›Ώβ€² π‘ž0, 𝑀 = αˆ˜π›Ώ π‘ž0, 𝑀 .

αˆ˜π›Ώβ€²(π‘ž0, π‘€π‘Ž)

= 𝛿′ αˆ˜π›Ώβ€² π‘ž0, 𝑀 , π‘Ž , by the inductive definition of αˆ˜π›Ώβ€²

= βˆͺπ‘žβˆˆπ›Ώβ€² π‘ž0,𝑀𝛿′ π‘ž, π‘Ž , by the definition of 𝛿′ for sets of states

= βˆͺπ‘žβˆˆπ›Ώ π‘ž0,π‘€αˆ˜π›Ώ π‘ž, π‘Ž , by the inductive hypothesis and definition of 𝛿′

= αˆ˜π›Ώ αˆ˜π›Ώ π‘ž0, 𝑀 , π‘Ž , by the definition of αˆ˜π›Ώ for νœ€-NFAs and sets of states

= αˆ˜π›Ώ π‘ž0, π‘€π‘Ž , by the definition of αˆ˜π›Ώ

Proof of Theorem 2.22: Finishing Up

To show that 𝐿 𝑁 = 𝐿 𝐸 we must show that αˆ˜π›Ώβ€²(π‘ž0, π‘₯)

contains a state in 𝐹 iff αˆ˜π›Ώ π‘ž0, π‘₯ contains a state in 𝐹.

Additionally, we need to deal with π‘₯ = 0.

Case where 𝒙 = 𝜺:

αˆ˜π›Ώβ€² π‘ž0, νœ€ = π‘ž0

αˆ˜π›Ώ π‘ž0, νœ€ = 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0

π‘ž0 is in 𝐹′ if and only if 𝐸𝐢𝐿𝑂𝑆𝐸(π‘ž0) contains a state in 𝐹, by the definition of 𝐹′.

Jim Anderson (modified by Nathan Otterness) 64

Reminder:𝛿′ is for the NFA 𝑁𝛿 is for the νœ€-NFA 𝐸

Proof of Theorem 2.22: Finishing Up

Case where 𝒙 β‰  𝜺:

By the inductive proof earlier, αˆ˜π›Ώβ€² π‘ž0, π‘₯ = αˆ˜π›Ώ π‘ž0, π‘₯ .

If 𝐹′ = 𝐹 or π‘ž0 βˆ‰ αˆ˜π›Ώβ€² π‘ž0, π‘₯ , we are done.

Otherwise, π‘ž0 ∈ 𝐹′, π‘ž0 βˆ‰ 𝐹, and π‘ž0 ∈ αˆ˜π›Ώβ€² π‘ž0, π‘₯ .

❖In this case, some state in 𝐸𝐢𝐿𝑂𝑆𝐸 π‘ž0 is in 𝐹.

❖By construction of αˆ˜π›Ώ, that state is in αˆ˜π›Ώ π‘ž0, π‘₯ .

Jim Anderson (modified by Nathan Otterness) 65

Reminder:𝛿′ is for the NFA 𝑁𝛿 is for the νœ€-NFA 𝐸