CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Finite Automata CPSC 388 Ellen Walker Hiram College.
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
NFAs Sipser 1.2 (pages 47–54). CS 311 Mount Holyoke College 2 Recall… Last time we showed that the class of regular languages is closed under: –Complement.
Regular operations Sipser 1.2 (pages 47-63). First… a sample proof
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Finite Automata Sections:1.1 page 44 September 8, 2006.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
CS 310 – Fall 2006 Pacific University CS310 Finite Automata Sections: September 1, 2006.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Topics Automata Theory Grammars and Languages Complexities
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Lecture 5UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 5.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
Basics of automata theory
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Finite Automata Chapter 1. Automatic Door Example Top View.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
1 Introduction to the Theory of Computation Regular Expressions.
Lecture #5 Advanced Computation Theory Finite Automata.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Languages and Automata By: Mojtaba Khezrian.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Nondeterminism The Chinese University of Hong Kong Fall 2011
CIS Automata and Formal Languages – Pei Wang
Non Deterministic Automata
PROGRAMMING LANGUAGES
Chapter 2 Finite Automata
Theory of Computation Lecture # 9-10.
Nondeterministic Finite Automata
Recognizer for a Language
Finite Automata & Regular Languages
Examples for Finite Automata
An Introduction to Finite Automata
Non-Determinism 12CS45 Finite Automata.
Non-Deterministic Finite Automata
COSC 3340: Introduction to Theory of Computation
Regular languages, regular expressions, & finite automata (intro)
Non Deterministic Automata
DFA Equivalence & Minimization
NFAs and Transition Graphs
Finite Automata.
CSCI 2670 Introduction to Theory of Computing
Chapter 1 Regular Language
CSCI 2670 Introduction to Theory of Computing
NFAs and Transition Graphs
CSCI 2670 Introduction to Theory of Computing
Non Deterministic Automata
Lexical Analysis Uses formalism of Regular Languages
COSC 3340: Introduction to Theory of Computation
Finite Automata Part Three
COSC 3340: Introduction to Theory of Computation
Presentation transcript:

CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/ Deterministic finite automata (DFA) & Non-deterministic finite automata (NFA) CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/

DFA transition diagram 𝐿={hello} h e l o q0 q1 q2 q3 l q4 q5 DFA transition diagram

Formally, each DFA is a 5-tuple: A set of final states Formally, each DFA is a 5-tuple: (𝑄,Σ,𝛿, 𝑞 0 ,𝐹) A starting state A finite set of states {q…} A transition function An alphabet

Formally, each DFA is a 5-tuple: (𝑄,Σ,𝛿, 𝑞 0 ,𝐹) 𝛿⊆(𝑄×Σ⇀𝑄) 𝐹⊆𝑄 𝑞 0 ∈𝑄

(𝑄,Σ,𝛿, 𝑞 0 ,𝐹),where 𝑄={ 𝑞 0 ,…, 𝑞 5 } Σ={a,b,…,z} 𝐹={ 𝑞 5 } l l o q0 q1 q2 q3 q4 q5 (𝑄,Σ,𝛿, 𝑞 0 ,𝐹),where 𝑄={ 𝑞 0 ,…, 𝑞 5 } Σ={a,b,…,z} 𝛿={( 𝑞 0 ,h, 𝑞 1 ),( 𝑞 1 ,e, 𝑞 2 ), ( 𝑞 2 ,l, 𝑞 3 ),( 𝑞 3 ,l, 𝑞 4 ),( 𝑞 4 ,o, 𝑞 5 )} 𝐹={ 𝑞 5 }

h e l o q0 q1 q2 q3 l q4 q5 𝛿 h l e o … … 𝑞 0 𝑞 1 DFA transition table 𝑞 1 𝑞 2 𝑞 2 𝑞 3 𝑞 3 𝑞 4 𝑞 4 𝑞 5 𝑞 5 𝛿={( 𝑞 0 ,h, 𝑞 1 ),( 𝑞 1 ,e, 𝑞 2 ), ( 𝑞 2 ,l, 𝑞 3 ),( 𝑞 3 ,l, 𝑞 4 ),( 𝑞 4 ,o, 𝑞 5 )}

Extended transition function h e l q3 l o q0 q1 q2 q4 q5 Extended transition function 𝛿 ̂ ={( 𝑞 0 ,h, 𝑞 1 ),( 𝑞 1 ,e, 𝑞 2 ), ( 𝑞 2 ,l, 𝑞 3 ),( 𝑞 3 ,l, 𝑞 4 ),( 𝑞 4 ,o, 𝑞 5 ), ( 𝑞 0 ,he, 𝑞 2 ),( 𝑞 1 ,el, 𝑞 3 ),( 𝑞 2 ,ll, 𝑞 4 ),( 𝑞 3 ,lo, 𝑞 5 ), ( 𝑞 0 ,hel, 𝑞 3 ),( 𝑞 1 ,ell, 𝑞 4 ),( 𝑞 2 ,llo, 𝑞 5 ), ( 𝑞 0 ,hell, 𝑞 4 ),( 𝑞 1 ,ello, 𝑞 5 ),( 𝑞 0 ,hello, 𝑞 5 )} 𝛿={( 𝑞 0 ,h, 𝑞 1 ),( 𝑞 1 ,e, 𝑞 2 ), ( 𝑞 2 ,l, 𝑞 3 ),( 𝑞 3 ,l, 𝑞 4 ),( 𝑞 4 ,o, 𝑞 5 )}

Computing the extended transition function as a least fixed point 𝛿 ̂ ,where 𝑓 𝛿,𝑄 ( 𝛿 ̂ )= 𝛿 ̂ 𝑓 𝛿,𝑄 ( 𝛿 ̂ )={( 𝑞 𝑖 , 𝑠 0 𝑠 1 , 𝑞 𝑗 )|( 𝑞 𝑖 , 𝑠 0 , 𝑞 𝑘 )∈𝛿∧( 𝑞 𝑘 , 𝑠 1 , 𝑞 𝑗 )∈ 𝛿 ̂ } ∪{( 𝑞 𝑖 ,𝜖, 𝑞 𝑖 )| 𝑞 𝑖 ∈𝑄}

Computing the extended transition function as a least fixed point 𝑓 𝛿,𝑄 ( 𝛿 ̂ )={( 𝑞 𝑖 , 𝑠 0 𝑠 1 , 𝑞 𝑗 )|( 𝑞 𝑖 , 𝑠 0 , 𝑞 𝑘 )∈𝛿∧( 𝑞 𝑘 , 𝑠 1 , 𝑞 𝑗 )∈ 𝛿 ̂ } ∪{( 𝑞 𝑖 ,𝜖, 𝑞 𝑖 )| 𝑞 𝑖 ∈𝑄} ℒ( a ∗ ) 𝛿 a 𝑞 0 𝑞 0 a q0

Computing the extended transition function as a least fixed point 𝑓 𝛿,𝑄 ( 𝛿 ̂ )={( 𝑞 𝑖 , 𝑠 0 𝑠 1 , 𝑞 𝑗 )|( 𝑞 𝑖 , 𝑠 0 , 𝑞 𝑘 )∈𝛿∧( 𝑞 𝑘 , 𝑠 1 , 𝑞 𝑗 )∈ 𝛿 ̂ } ∪{( 𝑞 𝑖 ,𝜖, 𝑞 𝑖 )| 𝑞 𝑖 ∈𝑄} ℒ( a ∗ ) 𝛿 ̂ 𝜖 a . . . 𝑞 0 𝑞 0 𝑞 0 a q0

Computing the extended transition function as a least fixed point 𝑓 𝛿,𝑄 ( 𝛿 ̂ )={( 𝑞 𝑖 , 𝑠 0 𝑠 1 , 𝑞 𝑗 )|( 𝑞 𝑖 , 𝑠 0 , 𝑞 𝑘 )∈𝛿∧( 𝑞 𝑘 , 𝑠 1 , 𝑞 𝑗 )∈ 𝛿 ̂ } ∪{( 𝑞 𝑖 ,𝜖, 𝑞 𝑖 )| 𝑞 𝑖 ∈𝑄} ℒ( a ∗ ) 𝛿 ̂ 𝜖 a aa aaa . . . 𝑞 0 𝑞 0 𝑞 0 𝑞 0 𝑞 0 a q0

ℒ(𝑄,Σ,𝛿, 𝑞 0 ,𝐹)={𝑠|( 𝑞 0 ,𝑠, 𝑞 𝑓 )∈ 𝛿 ̂ ∧ 𝑞 𝑓 ∈𝐹} The Language L of a DFA: and 𝛿 ̂ (𝑄,Σ,𝛿, 𝑞 0 ,𝐹) ℒ(𝑄,Σ,𝛿, 𝑞 0 ,𝐹)={𝑠|( 𝑞 0 ,𝑠, 𝑞 𝑓 )∈ 𝛿 ̂ ∧ 𝑞 𝑓 ∈𝐹} where 𝛿 ̂ is the least fixed point 𝛿 ̂ = 𝑓 𝛿,𝑄 ( 𝛿 ̂ )

L is the language L((a|b)*cc(a|b)*). Try an example: L is the language L((a|b)*cc(a|b)*).

L is the language L((a|b)*cc(a|b)*). Try an example: L is the language L((a|b)*cc(a|b)*). c c q0 q1 q2 a,b a,b

L is the language L((a|b)*bab). Try an example: L is the language L((a|b)*bab).

L is the language L((a|b)*bab). Try an example: L is the language L((a|b)*bab). b b b a b q0 q1 q2 q3 a a a

Try an example: L is the language, over {a,b}, of strings with an even number of a’s and of b’s.

Try an example: L is the language, over {a,b}, of strings with an even number of a’s and of b’s. a q0 q2 a b b b b q1 a q3 a

There are an even number of a’s There are an odd number of a’s q0 q2 a b b b b q1 a q3 a

a a b b b b a a There are an even number of b’s q0 q2 a b b b b q1 a q3 a There are an odd number of bs

So this is just the DFAs for (aa). and for (bb). composed So this is just the DFAs for (aa)* and for (bb)* composed. Can this idea be generalized? a (E,E) (O,E) a b b b b (E,O) a (O,O) a

𝐹 ∩ ={( 𝑞 0𝐹 , 𝑞 1𝐹 )| 𝑞 0𝐹 ∈ 𝐹 0 ∧ 𝑞 1𝐹 ∈ 𝐹 1 } ℒ( 𝑄 0 ,Σ, 𝛿 0 , 𝑞 00 , 𝐹 0 )∩ℒ( 𝑄 1 ,Σ, 𝛿 1 , 𝑞 10 , 𝐹 1 ) =ℒ( 𝑄 ∩ ,Σ, 𝛿 ∩ , 𝑞 ∩ , 𝐹 ∩ ) 𝑄 ∩ = 𝑄 0 × 𝑄 1 𝛿 ∩ ={(( 𝑞 0 , 𝑞 1 ),𝑠,( 𝑞 0 ′ , 𝑞 1 ′ )) |( 𝑞 0 ,𝑠, 𝑞 0 ′ )∈ 𝛿 0 𝑞 ∩ =( 𝑞 00 , 𝑞 10 ) ∧( 𝑞 1 ,𝑠, 𝑞 1 ′ )∈ 𝛿 1 } 𝐹 ∩ ={( 𝑞 0𝐹 , 𝑞 1𝐹 )| 𝑞 0𝐹 ∈ 𝐹 0 ∧ 𝑞 1𝐹 ∈ 𝐹 1 }

Try an example: L is the language, over {0,1}, of strings with an even number of 0s and two 1s.

Try an example: L is the language, over {0,1}, of strings with an even number of 0s and two 1s. 1 1 q0 q1 q2 q0 q1 1 1

Try an example: L is the language, over {0,1}, of strings with an even number of 0s and two 1s. 1 1 q0,q0 q0,q1 q0,q2 1 1 q1,q0 q1,q1 q1,q2

is the complement of language (a|b)*bab Try an example: is the complement of language (a|b)*bab 𝐿

(Recall that this is how we defined L as a DFA.) Try an example: is the complement of language (a|b)*bab 𝐿 b b b a b q0 q1 q2 q3 a a a (Recall that this is how we defined L as a DFA.)

is the complement of language (a|b)*bab Try an example: is the complement of language (a|b)*bab 𝐿 b b b a b q0 q1 q2 q3 a a a

(Recall that this is how we defined {a} as a DFA.) Try an example: is the complement of language a 𝐿 a q0 q1 (Recall that this is how we defined {a} as a DFA.)

is the complement of language a Try an example: is the complement of language a 𝐿 a a q0 q1 q2 a

𝑄 ′ =𝑄∪{ 𝑞 dead } 𝐹 ′ = 𝑄 ′ −𝐹 𝛿 ′ =𝛿∪{( 𝑞 dead ,𝑠, 𝑞 dead )|𝑠∈Σ} The complement ofℒ(𝑄,Σ,𝛿, 𝑞 0 ,𝐹)isℒ( 𝑄 ′ ,Σ, 𝛿 ′ , 𝑞 0 , 𝐹 ′ ) 𝑄 ′ =𝑄∪{ 𝑞 dead } 𝐹 ′ = 𝑄 ′ −𝐹 𝛿 ′ =𝛿∪{( 𝑞 dead ,𝑠, 𝑞 dead )|𝑠∈Σ} ∪{(𝑞,𝑠, 𝑞 dead )|𝑠∈Σ∧𝑞∈𝑄∧(𝑞,𝑠, 𝑞 ′ )∉𝛿}

Non-deterministic finite automata (NFA)

Models of regular languages “Converts to” GNFA “Converts to” RE DFA “Minimizes to” NFA “Converts to” “Converts to”

L is the language L((a|b)*bab). Try an example: L is the language L((a|b)*bab). b a b q0 q1 q2 q3 a,b

b a b a,b Let’s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

/ Let’s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

/ / Let’s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

/ / / Let’s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

/ / / / Let’s run this nondeterministically on the string babab and track what paths we can take: b a b q0 q1 q2 q3 a,b

If any possible path would accept, then the NFA accepts. / / / / / Let’s run this nondeterministically on the string babab and track what paths we can take: If any possible path would accept, then the NFA accepts. b a b q0 q1 q2 q3 a,b

Formally, each NFA is also a 5-tuple: A set of final states Formally, each NFA is also a 5-tuple: (𝑄,Σ,𝛿, 𝑞 0 ,𝐹) A starting state A finite set of states {q0,…} A transition relation An alphabet

𝛿:𝑄×Σ×𝑄 A transition relation

𝛿:𝑄×Σ×𝑄 𝛿:𝑄×Σ→𝒫(𝑄) A transition relation

b 𝛿 a 𝑞 0 𝑞 1 𝑞 2 𝑞 3 NFA transition table { 𝑞 0 } { 𝑞 0 , 𝑞 1 } q0 q1 q2 q3 a,b NFA transition table b 𝛿 a 𝑞 0 { 𝑞 0 } { 𝑞 0 , 𝑞 1 } 𝑞 1 { 𝑞 2 } 𝑞 2 { 𝑞 3 } 𝑞 3

NFA extended transition table q0 q1 q2 q3 NFA extended transition table a,b 𝛿 ̂ b ab ba bab a aa 𝑞 0 { 𝑞 0 } { 𝑞 0 , 𝑞 1 } { 𝑞 0 } { 𝑞 0 , 𝑞 1 } { 𝑞 0 , 𝑞 2 } { 𝑞 0 , 𝑞 3 } 𝑞 1 { 𝑞 2 } { 𝑞 3 } … 𝑞 2 { 𝑞 3 } 𝑞 3

This is exactly the same as for a DFA, except now a relation. Computing an NFA’s extended transition relation as a least fixed point This is exactly the same as for a DFA, except now a relation. 𝛿 ̂ ,where 𝑓 𝛿,𝑄 ( 𝛿 ̂ )= 𝛿 ̂ 𝑓 𝛿,𝑄 ( 𝛿 ̂ )={( 𝑞 𝑖 , 𝑠 0 𝑠 1 , 𝑞 𝑗 )|( 𝑞 𝑖 , 𝑠 0 , 𝑞 𝑘 )∈𝛿∧( 𝑞 𝑘 , 𝑠 1 , 𝑞 𝑗 )∈ 𝛿 ̂ } ∪{( 𝑞 𝑖 ,𝜖, 𝑞 𝑖 )| 𝑞 𝑖 ∈𝑄}

The Language L of an NFA: and 𝛿 ̂ (𝑄,Σ,𝛿, 𝑞 0 ,𝐹) 𝐿={𝑠|( 𝛿 ̂ ( 𝑞 0 ,𝑠)∩𝐹)⊃Ø}