Conversions between NFAs and REs

Slides:



Advertisements
Similar presentations
Exercises for Chapter 2. Summary for the Quiz Some numbers –199  less than 100  55 Conclusion –There are students who did read textbook at least for.
Advertisements

LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.
Regular Expressions and DFAs COP 3402 (Summer 2014)
CMSC Spring Finite Automaton: Example accepted.
Regular expressions Regular languages Sipser 1.3 (pages 63-76)
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
CS 3240 – Chapter 3.  How would you delete all C++ files from a directory from the command line?  How about all PowerPoint files that start with the.
CS 310 – Fall 2006 Pacific University CS310 Converting NFA to DFA Sections:1.2 Page 54 September 15, 2006.
CS 310 – Fall 2006 Pacific University CS310 Regular Expressions Sections:1.3 page 63 September 18, 2006 September 20, 2006.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Regular Expression to NFA-  (a+ba) * a. First Parsing Step concatenate (a+ba) * a.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
Lecture 8 Sept 29, 2011 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to.
CS 310 – Fall 2006 Pacific University CS310 Homework 2 & JFLAP September 22, 2006.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Second lecture REGULAR EXPRESSION. Regular Expression.
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
How to check the equivalence of two regular expressions using JFLAP One of the questions in the previous HW involved converting an NFA to a regular expression.
Transition Diagrams Lecture 3 Wed, Jan 21, Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b,
Lecture 5 Sept 06, 2012 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Lecture # 12. Nondeterministic Finite Automaton (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
CSC312 Automata Theory Lecture # 3 Languages-II. Formal Language A formal language is a set of words—that is, strings of symbols drawn from a common alphabet.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts.
Brian K. Strickland a ba Λ a aa b Λ -NFA for Regular Expression (aab)*(a + aba)*
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
Lecture # 4.
Regular Expressions Section 1.3 (also 1.1, 1.2) CSC 4170 Theory of Computation.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
1 Introduction to the Theory of Computation Regular Expressions.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
1 Closure E.g., we understand number systems partly by understanding closure properties: Naturals are closed under +, , but not -, . Integers are closed.
CS314 – Section 5 Recitation 2
Kleene’s Theorem and NFA
Theory of Computation Lecture #
Formal Language & Automata Theory
Regular Expressions.
Theory of Computation Lecture # 9-10.
Regular Expressions Sections:1.3 page 63 September 17, 2008
Language Recognition (12.4)
Non-deterministic Finite Automata (NFA)
Regular languages, regular expressions, & finite automata (intro)
Kleene’s Theorem Muhammad Arif 12/6/2018.
DFA Equivalence & Minimization
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
NFAs and Transition Graphs
NFAs, DFAs, and regular expressions
Regular Expression to NFA
Regular Expression to NFA
Language Recognition (12.4)
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Recap lecture 11 Proof of Kleene’s theorem part II (method with different steps), particular examples of TGs to determine corresponding REs.
RECAP Lecture 7 FA of EVEN EVEN, FA corresponding to finite languages(using both methods), Transition graphs.
Recap lecture 23 Mealy machines in terms of sequential circuit.
Recap Lecture 15 Examples of Kleene’s theorem part III (method 3), NFA, examples, avoiding loop using NFA, example, converting FA to NFA, examples, applying.
NFAs and Transition Graphs
LECTURE # 07.
Lexical Analysis Uses formalism of Regular Languages
CSCI 2670 Introduction to Theory of Computing
Intro to Theory of Computation
CSCI 2670 Introduction to Theory of Computing
Finite Automata Part Three
Presentation transcript:

Conversions between NFAs and REs CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/

Converting REs to NFAs

q0 q1 ℒ(Ø) ℒ(𝜖) q0 a q0 q1 ℒ(a)

|𝐹|=1 As we build up a corresponding NFA for an RE, we want to enforce that: |𝐹|=1

ℒ( 𝑒 0 ) 𝑒 0

ℒ( 𝑒 0 𝑒 1 ) 𝑒 0 𝑒 1

ℒ( 𝑒 0 𝑒 1 ) 𝑒 0 𝜖 𝑒 1

ℒ( 𝑒 0 𝑒 1 )=ℒ( 𝑄 ′ , Σ ′ , 𝛿 ′ , 𝑞 00 ,{ 𝑞 1𝐹 }) where ℒ( 𝑒 0 )=ℒ( 𝑄 0 , Σ 0 , 𝛿 0 , 𝑞 00 ,{ 𝑞 0𝐹 }) ℒ( 𝑒 1 )=ℒ( 𝑄 1 , Σ 1 , 𝛿 1 , 𝑞 10 ,{ 𝑞 1𝐹 }) 𝑄 ′ = 𝑄 0 ∪ 𝑄 1 Σ ′ = Σ 0 ∪ Σ 1 𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 0𝐹 ,𝜖, 𝑞 10 )}

ℒ( 𝑒 0 | 𝑒 1 ) 𝑒 0 𝑒 1

ℒ( 𝑒 0 | 𝑒 1 ) 𝑒 0 𝜖 𝜖 𝑒 1 𝜖 𝜖

ℒ( 𝑒 0 | 𝑒 1 )=ℒ( 𝑄 ′ , Σ ′ , 𝛿 ′ , 𝑞 0 ,{ 𝑞 𝐹 }) where ℒ( 𝑒 0 )=ℒ( 𝑄 0 , Σ 0 , 𝛿 0 , 𝑞 00 ,{ 𝑞 0𝐹 }) ℒ( 𝑒 1 )=ℒ( 𝑄 1 , Σ 1 , 𝛿 1 , 𝑞 10 ,{ 𝑞 1𝐹 }) 𝑄 ′ = 𝑄 0 ∪ 𝑄 1 ∪{ 𝑞 0 , 𝑞 𝐹 } Σ ′ = Σ 0 ∪ Σ 1 𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 0 ,𝜖, 𝑞 00 ),( 𝑞 0 ,𝜖, 𝑞 10 ), ( 𝑞 0𝐹 ,𝜖, 𝑞 𝐹 ),( 𝑞 1𝐹 ,𝜖, 𝑞 𝐹 )}

ℒ( 𝑒 0 ∗ ) 𝑒 0

ℒ( 𝑒 0 ∗ ) 𝑒 0 𝜖 𝜖

𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 𝐹 ,𝜖, 𝑞 00 ),( 𝑞 0𝐹 ,𝜖, 𝑞 𝐹 )} ℒ( 𝑒 0 ∗ )=ℒ( 𝑄 ′ , Σ ′ , 𝛿 ′ , 𝑞 𝐹 ,{ 𝑞 𝐹 }) where ℒ( 𝑒 0 )=ℒ( 𝑄 0 , Σ 0 , 𝛿 0 , 𝑞 00 ,{ 𝑞 0𝐹 }) 𝑄 ′ = 𝑄 0 ∪ 𝑄 1 ∪{ 𝑞 𝐹 } Σ ′ = Σ 0 ∪ Σ 1 𝛿 ′ = 𝛿 0 ∪ 𝛿 1 ∪{( 𝑞 𝐹 ,𝜖, 𝑞 00 ),( 𝑞 0𝐹 ,𝜖, 𝑞 𝐹 )}

Show the NFA for L((a|b)*c*). Try an example: Show the NFA for L((a|b)*c*).

Show the NFA for L((a|b)*c*). Try an example: Show the NFA for L((a|b)*c*). a q0 q1 b q2 q3

Show the NFA for L((a|b)*c*). Try an example: Show the NFA for L((a|b)*c*). a q0 q1 𝜖 𝜖 q4 q5 b q2 q3 𝜖 𝜖

Show the NFA for L((a|b)*c*). Try an example: Show the NFA for L((a|b)*c*). 𝜖 a q0 q1 𝜖 𝜖 q6 𝜖 q4 q5 b q2 q3 𝜖 𝜖

Show the NFA for L((a|b)*c*). Try an example: Show the NFA for L((a|b)*c*). 𝜖 a q0 q1 𝜖 𝜖 q6 𝜖 q4 q5 b q2 q3 𝜖 𝜖 𝜖 c q9 q7 q8 𝜖

Show the NFA for L((a|b)*c*). Try an example: Show the NFA for L((a|b)*c*). 𝜖 a q0 q1 𝜖 𝜖 q6 𝜖 q4 q5 b q2 q3 𝜖 𝜖 𝜖 𝜖 c q9 q8 𝜖 q7

Converting NFAs/DFAs to REs (intuitions, examples)

Idea 1: Permit whole REs on (G)NFA edges Idea 2: Repeatedly remove one state until a RE can simply be read off the (G)NFA.

Idea 1: Permit whole REs on (G)NFA edges Idea 2: Repeatedly remove one state until a RE can simply be read off the (G)NFA. q0 a c q2 q3 b q1 d e

Idea 1: Permit whole REs on (G)NFA edges Idea 2: Repeatedly remove one state until a RE can simply be read off the (G)NFA. q0 ae*(c|d) q0 a c q2 q3 q3 b q1 d q1 be*(c|d) e

Alternative paths may have their REs disjoined: Basic simplification rules: Disjunction e0 q0 q1 e1 Alternative paths may have their REs disjoined: e0 | e1 q0 q1

Sequential paths may have their REs juxtaposed: Basic simplification rules: Juxtaposition q2 e1 q0 q1 e0 q3 e2 Sequential paths may have their REs juxtaposed: q2 q0 e0e1 q3 e0e2

Self-loops can be replaced by an edge with a kleene-star of the RE: Basic simplification rules: Star e1 q0 q1 q2 e0 e2 Self-loops can be replaced by an edge with a kleene-star of the RE: q0 q1 q1’ q2 e0 e1* e2 q0 q2 e0e1*e2

Try an example: b q0 q2 b a a q1 b

Try an example: b q0 q2 b ab*a

Try an example: q0 q2 b|ab*a b

Try an example: q0 q’0 q2 b* b|ab*a

Thus possible regexes are: b*(b|ab*a) Try an example: q0 q2 b*(b|ab*a) Thus possible regexes are: b*(b|ab*a) Or: b+|b*ab*a

Try an example: a q0 q2 a b b b b q1 a q3 a

Try an example: aa q0 ba ab b b bb q1 a q3 a

Try an example: aa q0 ba ab bb bb ba q3 ab aa

Try an example: aa|bb q0 ab|ba q3 aa|bb

Try an example: aa|bb|(ab|ba)(aa|bb)*(ab|ba) q0 So an answer is: (aa|bb|(ab|ba)(aa|bb)*(ab|ba))*

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