CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.

Slides:



Advertisements
Similar presentations
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Properties.
Advertisements

CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Examples for Finite Automata
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Fall 2006Costas Busch - RPI1 Regular Expressions.
CS 310 – Fall 2006 Pacific University CS310 Converting NFA to DFA Sections:1.2 Page 54 September 15, 2006.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
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.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Homework #2 Solutions.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
1 Finite state automaton (FSA) LING 570 Fei Xia Week 2: 10/07/09 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA.
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.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Non-Deterministic Automata Regular Expressions.
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.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Text search.
Regular Expressions Hopcroft, Motawi, Ullman, Chap 3.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 1, 2005.
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.
CHAPTER 1 Regular Languages
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.
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:
 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.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 Lexical Analysis Uses formalism of Regular Languages Uses formalism of Regular Languages Regular Expressions Regular Expressions Deterministic Finite.
Theory of Computation Automata Theory Dr. Ayman Srour.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Decidable.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Finite automate.
More on DFA minimization and DFA equivalence
NFAs, DFAs, and regular expressions
NFA to DFA conversion and regular expressions
Pushdown automata The Chinese University of Hong Kong Fall 2011
Text search and closure properties
Nondeterminism The Chinese University of Hong Kong Fall 2010
Presentation transcript:

CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA conversion and regular expressions Fall 2011

NFAs are as powerful as DFAs An NFA can do everything a DFA can do How about the other way? Every NFA can be converted into a DFA for the same language. YES

NFA → DFA in two easy steps We do this first ➊ Eliminate  -transitions ➋ Convert simplified NFA

NFA → DFA: intuition 1 0 0, 1 qq qq qq NFA: DFA: 1 qq q 0 or q 1 1 q 0 or q

NFA → DFA: intuition 1 0 0, 1 qq qq qq NFA: DFA: 1 qq {q 0, q 1 } 1 {q 0, q 2 }

NFA → DFA: states 1 0 0, 1 qq qq qq NFA: DFA: {q 0, q 1 } {q 0, q 2 }{q 0, q 1, q 2 } {q 1, q 2 } {q 0 } {q 1 } {q 2 }  DFA has a state for every subset of NFA states

NFA → DFA: transitions 10 0, 1 qq qq qq NFA: DFA: {q 0, q 1 } {q 0, q 2 }{q 0, q 1, q 2 } {q 1, q 2 } {q 0 } {q 1 } {q 2 }  , , 1

NFA → DFA: accepting states 10 0, 1 qq qq qq NFA: DFA: {q 0, q 1 } {q 0, q 2 }{q 0, q 1, q 2 } {q 1, q 2 } {q 0 } {q 1 } {q 2 }  , , 1 NFA accepts if it contains a DFA final state

NFA → DFA: dead state elimination 10 0, 1 qq qq qq NFA: DFA: {q 0, q 1 } {q 0, q 2 } {q 0 } {q 0, q 1, q 2 } {q 1, q 2 } {q 1 } {q 2 }  0 1, , 1 At the end, you can eliminate the unreachable states

General method NFADFA states q 0, q 1, …, q n  q 0 }, {q 1 }, {q 0,q 1 }, …, {q 0,…,q n } one for each subset of states in the NFA initial state q0q0 q0}q0} transitions  ’({q i1,…,q ik }, a) =  (q i1, a) ∪ … ∪  (q ik, a) accepting states F  Q F’ = {S: S contains some state in F}

NFA → DFA in two easy steps ➊ Eliminate  -transitions ➋ Convert simplified NFA ✔

Eliminating  -transitions q0q0 q1q1 q2q2 ,  NFA: NFA without  s: {q 1, q 2 } 0 1 q0q0 q1q1 q2q2 {q 0, q 1, q 2 }    Accepting states: q2q2, q 1, q 0

Eliminating  -transitions NFA: new NFA: q0q0 q1q1 q2q2 ,  q0q0 q1q1 q2q2 0, {q 1, q 2 } 0 1 q0q0 q1q1 q2q2 {q 0, q 1, q 2 }   

Eliminating  -transitions Paths with  s are replaced by a single transition States that can reach final state by  are all accepting q5q5 q0q0 q2q2 q0q0 q3q3  a q4q4 q3q3 q5q5 a   q5q5 q3q3 a q3q3 a   q9q9 q7q7 q3q3 q2q2

Regular expressions

String concatenation st = abbbab s = abb t = bab s = x 1 …x n st = x 1 …x n y 1 …y m t = y 1 …y m ts = bababb ss = abbabb sst = abbabbbab

Operations on languages The concatenation of languages L 1 and L 2 is The n -th power of L n is The union of L 1 and L 2 is L 1 L 2 = {st: s  L 1, t  L 2 } L n = {s 1 s 2...s n : s 1, s 2,..., s n  L} L 1  L 2 = {s: s  L 1 or s  L 2 }

Example L 1 = {0, 01} L 2 = { , 1, 11, 111, …} L1L2L1L2 L12L12 L22L22 L 1  L 2 = {0, 01, 011, 0111, …}  {01, 011, 0111, …} = {0, 01, 011, 0111, …} 0 followed by any number of 1 s = L 2 L2nL2n (n ≥ 1) = {00, 001, 010, 0101} any number of 1 s = {0, 01, ,  1, 11, 111,...}

Operations on languages The star of L are all strings made up of zero or more chunks from L : Example: L 1 = {01, 0}, L 2 = { , 1, 11, 111, …}. What is L 1 * and L 2 * ? L * = L 0  L 1  L 2  …

Example L 1 = {0, 01} L10L10 = {  } L1*:L1*: is in L 1 * is not in L 1 * L 1 * are all strings that start with 0 and do not contain consecutive 1 s is not in L 1 * L12L12 = {00, 001, 010, 0101} L11L11 = {0, 01} L13L13 = {000, 0001, 0010, 00101, 0100, 01001, 01010, } (plus the empty string)

Example L 2 = { , 1, 11, 111, …} L20L20 = {  } L21L21 = L 2 any number of 1 s L2*L2* = L 2 0  L 2 1  L 2 2  … = {  }  L 2 1  L 2 2  … = L 2 L2* = L2L2* = L2 L22L22 L2nL2n (n ≥ 1)

Combining languages We can construct languages by starting with simple ones, like {0}, {1} and combining them {0}({0}  {1})* ({0}{1}*)  ({1}{0}*) 0 ( )* 01 * + 10 * all strings that start with 0 0 followed by any number of 1 s, or 1 followed by any number of 0 s

Regular expressions A regular expression over  is an expression formed using the following rules: –The symbols  and  are regular expressions –Every a in  is a regular expression –If R and S are regular expressions, so are R+S, RS and R*. A language is regular if it is represented by a regular expression 0 ( )* 01 * + 10 * 1 *(  + 0 )   ( )* 01 ( )*

Analyzing regular expressions 01* (01*)(01) 0 followed by any number of 1 s = 0(1*)= {0, 01, 011, 0111, …} = {001, 0101, 01101, , …} 0 followed by any number of 1 s and then 01  = {0, 1}

Analyzing regular expressions (0+1)* = { , 0, 1, 00, 01, 10, 11, …} any string 0+1= {0, 1} (0+1)*01(0+1)* strings of length 1 any string that contatins the pattern 01 (0+1)*010 any string that ends in 010

Analyzing regular expressions (0+1)(0+1) (0+1)(0+1)(0+1) strings of length 2 strings of length 3 ((0+1)(0+1))*+((0+1)(0+1)(0+1))* ((0+1)(0+1))* strings of even length ((0+1)(0+1)(0+1))* strings of length a multiple of 3 all strings whose length is even or a mutliple of 3 = strings of length 0, 2, 3, 4, 6, 8, 9, 10, 12,...

Analyzing regular expressions ((0+1)(0+1)+(0+1)(0+1)(0+1))* (0+1)(0+1) (0+1)(0+1)(0+1) strings of length 2 strings of length 3 (0+1)(0+1)+(0+1)(0+1)(0+1) strings of length 2 or 3 strings that can be broken in blocks, where each block has length 2 or 3

Analyzing regular expressions ((0+1)(0+1)+(0+1)(0+1)(0+1))* strings that can be broken in blocks, where each block has length 2 or  ✓ ✓✓✓✓✗ this includes all strings except those of length 1 ((0+1)(0+1)+(0+1)(0+1)(0+1))* = all strings except 0 and 1

Analyzing regular expressions ( )*(  +0+00) ends in at most two 0 s there can be at most two 0 s between consecutive 1 s Guess: ( )*(  +0+00) = {x: x does not contain 000} there are never three consecutive 0 s 

Writing regular expressions Write a regular expression for all strings with two consecutive 0 s.  = {0, 1} (0+1)*00(0+1)* (anything) 00 (anything else)

Writing regular expressions Write a regular expression for all strings that do not contain two consecutive 0 s.  = {0, 1}... every middle 0 followed by one or more 1 s... and at most one 0 in the last block (011*) (  + 0) 1*(011*)*(  + 0) every 0 followed by one or more 1 s maybe a 0 at the end some 1 s at the beginning

Writing regular expressions Write a regular expression for all strings with an even number of 0 s.  = {0, 1} even number of zeros = ( two zeros )* two zeros = 1*01*01* (1*01*01*)*