What do we know? DFA = NFA =  -NFA We have seen algorithms to transform DFA to NFA (trival) NFA to  NFA (trivial) NFA to DFA (subset construction)

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Regular Expressions and DFAs COP 3402 (Summer 2014)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Regular Expressions.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
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.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
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 Non-Deterministic Automata Regular Expressions.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
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.
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
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
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.
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Regular Language Algorithms. Algorithms We have seen many algorithms for manipulating computational systems for the regular languages. Each treats these.
CFL Big Picture. Context Free Languages Conclusion We have studied the class of context free languages (CFL) We saw two different ways to express a CFL.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Recap: Transformation NFA  DFA  s s1s1... snsn p1p1 p2p2... pmpm >...  p1p1  p2p2  pipi s e s1s1 e s2s2 e sisi >
Regular Expressions Section 1.3 (also 1.1, 1.2) CSC 4170 Theory of Computation.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Conversions Regular Expression to FA FA to Regular Expression.
 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.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
NFA’s with  Transitions We extend the class of NFAs by allowing instantaneous transitions: 1.The automaton may be allowed to change its state without.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Nondeterminism Subset Construction ε -Transitions.
Non Deterministic Automata
Regular Expressions.
Chapter 2 FINITE AUTOMATA.
Language Recognition (12.4)
REGULAR LANGUAGES AND REGULAR GRAMMARS
Non-deterministic Finite Automata (NFA)
Non-Deterministic Finite Automata
CS 154, Lecture 3: DFANFA, Regular Expressions.
4. Properties of Regular Languages
Non-Deterministic Finite Automata
RegExp = (DFA,NFA,NFAe) Sipser pages
Non Deterministic Automata
Introduction to Finite Automata
4b Lexical analysis Finite Automata
Language Recognition (12.4)
Regular Language Equivalence and DFA Minimization
NFA’s With ε-Transitions
Accepting Strings.
CFL Big Picture.
Presentation transcript:

What do we know? DFA = NFA =  -NFA We have seen algorithms to transform DFA to NFA (trival) NFA to  NFA (trivial) NFA to DFA (subset construction)  NFA to NFA (  -removal) The last piece of the puzzle is to show that regular expressions are equivalent to automata.

Outline We have two results to prove: Theorem 1. For every regular expression E, there exists an  -NFA A such that L(E)=L(A). Theorem 2. For every DFA A, there exists a regular expression E such that L(A)=L(E).

Process Since we've already seen the ``equivalence'' of various forms of finite automata, the picture is about to become complete: the same class of languages ( REGULAR LANGUAGES, of course) is defined by 1.Any of the 3 types of automata (DFA, NFA,  -NFA) 2.Regular expressions Proofs of both theorems are constructive; we'll learn algorithms to construct an  -NFA from a regular expression, and a regular expression from a DFA.

Four Algorithms 1.RegExp -> DFA via GenNFA 2.RegExp -> DFA via delta-extension 3.DFA -> RegExp via path labels 4.DFA -> RegExp via GenNFA

Definition - Generalized NFA Generalize DFA so that every transition is a regular expression rather than a letter of the alphabet. An GenNFA is a quintuple A=(Q, ,s,F,  ), where the first four components are as in a DFA, and the transition function labels arcs between states with regular expressions.  Q  Q  RegExp( 

Alg 2 - RE to  -NFA via delta-extension 1.Decompose a RegExp into its parts 2.Small parts make simple DFAs 3.Combine smaller parts by merging the delta functions of both parts, and by extending the merger (if necessary) with new transitions, and or new states. data RegExp a = Lambda | Empty | One a | Union (RegExp a) (RegExp a) | Cat (RegExp a) (RegExp a) | Star (RegExp a)

Small Cases Suppose E is a given regular expression. The construction of the automaton A such that L(RE)=L(A) is defined by induction on the structure of RE. Base Case: There are three base cases: E= , E= , and E=a, where a . Here are the corresponding automata. a E=  E=  E=a

Induction Step There are three cases to consider Case 1: E=FG. Suppose (Ind. Hyp.) we have automata B and C such that L(F)=L(B) and L(G)=L(C). Let A be the automaton obtained by taking states and transitions of B and C together, Then add  -transitions from all final states of B to the start state of C (delta-extension). Then declare the start state (of the new automata) to be the start state of B. The final states (of the new automata) to be the final states of C.

BC BC    We need to check that L(A)=L(B)L(C); it will follow then that L(A)=L(E)

Case 2: E=F+G Again, take F,G such that L(F)=L(B) and L(G)=L(C). Get A by adding a new start state and  -transitions from the new state to the start states of B and C. Check that L(A)=L(B)  L(C)! B C   A

Case 3: E = F* Take B such that L(B)=L(F)and define A as in the picture. Check that L(A)=L(B) *. B B    

Exercise Exercise. Construct an  -NFA accepting the language of the regular expression (ab+aab) *

Alg 1 - RegExp to DFA via GenNFA Given a RegExp: ab+ac+ad+ae+af 1.Construct a simple GenNFA with two states with one arc between the two states labeled with the regular expression. 2.The source of the arc is the start state 3.The target of the arc is the final state

Extend the GenNFA

(a+b)*cd*

(a+  +  )c*

Alg 3 - From DFA to RE via path labels Suppose A is a given DFA. Our goal is to find a regular expression E such that L(E)=L(A). Assume the state set of A is {1,2,…,n}$. Let L ij be the language consisting of labels of all paths from i to j. Note that L(A) =  q  F L sq s is the start state, F is the set of final states, L sq is the labels of all paths from s to q We'll be done if we can find regular expressions E ij such that L ij =L(E ij ).

Exercise: Compute L BC = {“0”, ”1”} L BD = _________________________ L AB = _________________________ L AD = _________________________ ABD 0 00,1 C 1

Alg 4 - From DFA to RE by state elimination 1.The last construction was in fact algorithmic. We can improve the algorithm as follows. With an input NFA A, it will produce a regular expression E such that L(E)=L(A). 2.First we standardize the automaton A so that: there is only one final state no arcs go out of the final state no arcs come into the initial state 3.Do this by using  -transitions    

Assume the initial and final states are n-1 and n. We eliminate the states 1,2,…,n-2 one by one, producing intermediate automata whose arcs are labeled by regular expressions (i.e GenNFA). We end up with an automaton that has two states n-1 and n, and only one arc (from n-1 to n) whose label is the required regular expression E.

Algorithm For k = 1 to n-2 (* eliminate each node, k in turn *) For i = k+1 to n-1 (* i flows into k *) For j = k+1 to n (* k flows into j *) case paths i to k to j of ikj FE ikj EF G ikj EF G H ikj EF H ij EF ij EG*F ij EF + H ij EG*F + H Each case removes k, and adds a new label from i to j.

Example a a a bb b a a a bb b 5 4    1.there is only one final state 2.no arcs go out of the final state 3.no arcs come into the initial state 4.Renumber so final = n and start = n-1

Eliminate k= (aa) (b+ab)   (ba+a) (bb)   (a) (b)   a a bb b 5 4    a 3 2 ba+a b+ab 5 4 a   b aa bb ikj FE ij EF ikj EF H ij EF + H

Eliminate k= ( (ba+a)(aa)*(b+ab) +bb )  ( (ba+a)(aa)*  +  ) (a(aa)*(b+ab) + b)  (a(aa)*  ) ba+a b+ab 5 4 a   b aa bb ikj EF G H ij EG*F + H (ba+a)(aa)*  +  a(aa)*(b+ab) + b (ba+a)(aa)*(b+ab) + bb a(aa)* 

K=  ((a(aa)*(b+ab) + b) ((ba+a)(aa)*(b+ab) + bb)* ((ba+a)(aa)*  +  a(aa)*  ) (ba+a)(aa)*  +  a(aa)*(b+ab) + b (ba+a)(aa)*(b+ab) + bb a(aa)* 

Another example

DFA NFA  NFA RegExp Lift delta fun Subset Construction Via GenNFA by RegExp decompostion State Elimination GenNFA Delta fun lifting  -removal data DFA q s = DFA { states :: [q], symbols :: [s], delta :: q -> s -> q, start :: q, final :: [q]} data NFA q s = NFA { states :: [q], symbols :: [s], delta :: q -> s -> [q], start :: q, final :: [q]} data NFAe q s = NFAe { states :: [q], symbols :: [s], delta :: q -> Maybe s -> [q], start :: q, final :: [q]} data RegExp a = Lambda | Empty | One a | Union (RegExp a) (RegExp a) | Cat (RegExp a) (RegExp a) | Star (RegExp a) data GNFA q s = GNFA { states :: [q], symbols :: [s], delta :: q -> q -> RegExp s, start :: q, final :: q }

Decidability of the Regular Languages Since we can produce an equivalent DFA for any regular expression or  -NFA, we will know how to recognize whether any two given representations of regular languages are equivalent. Transform both into into DFAs: X and Y Minimize X and Y to Xmin and Ymin Test if Xmin and Ymin are isomorphic.