Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Theory Of Automata By Dr. MM Alam
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
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.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata 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.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
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.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
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.
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.
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.
Normal forms for Context-Free Grammars
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
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.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
Athasit Surarerks THEORY OF COMPUTATION 07 NON-DETERMINISTIC FINITE AUTOMATA 1.
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.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CS 203: Introduction to Formal Languages and Automata
Modeling Computation: Finite State Machines without Output
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Algorithms for hard problems Automata and tree automata Juris Viksna, 2015.
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.
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.
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Lecture 09: Theory of Automata:2014 Asif NawazUIIT, PMAS-Arid Agriclture University Rawalpindi. Kleene’s Theorem and NFA.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Kleene’s Theorem and NFA
Non Deterministic Automata
Regular Expressions.
CSE 105 theory of computation
Chapter 2 Finite Automata
Chapter 2 FINITE AUTOMATA.
REGULAR LANGUAGES AND REGULAR GRAMMARS
Non-Deterministic Finite Automata
Kleene’s Theorem Muhammad Arif 12/6/2018.
Chapter 1 Regular Language
Finite-State Machines with No Output
CSCI 2670 Introduction to Theory of Computing
CSCE 355 Foundations of Computation
Presentation transcript:

Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1

Introduction to Computation2 Regular Languages and Regular Expressions Many simple languages can be expressed by a formula involving languages containing a single string of length 1 and the operations of union, concatenation and Kleene star. Here are three examples –Strings ending in aa: {a, b}* {aa} –(This is a simplification of ({a} ∪ {b})*{a}{a} ) –Strings containing ab or bba: {a, b}* {ab, bba} {a, b}* –The language {a, b}* {aa, aab}* {b} These are called regular languages

Regular Languages and Regular Expressions (cont’d.) Definition: If  is an alphabet, the set R of regular languages over  is defined as follows: –The language  is an element of R, and for every   , the language {  } is in R –For every two languages L 1 and L 2 in R, the three languages L 1 ∪ L 2, L 1 L 2, and L 1 * are elements of R Examples: –{  }, because  * = {  } –{a, b}*{aa} = ({a} ∪ {b})* ({a}{a}) Introduction to Computation3

Regular Languages and Regular Expressions (cont’d.) A regular expression for a language is a slightly more user-friendly formula –Parentheses replace curly braces, and are used only when needed, and the union symbol is replaced by + Regular languageRegular Expression  {}{}  {a,b}*(a+b)* {aab}*{a,ab}(aab)*(a+ab) Introduction to Computation4

Regular Languages and Regular Expressions (cont’d.) Two regular expressions are equal if the languages they describe are equal. For example, –(a*b*)* = (a+b)* –(a+b)*ab(a+b)*+b*a* = (a+b)* The first half of the left-hand expression describes the strings that contain the substring ab and the second half describes those that don’t Introduction to Computation5

Nondeterministic Finite Automata Kleene’s Theorem asserts that regular languages are precisely the languages accepted by finite automata To prove this, we introduce a more general “device,” a nondeterministic finite automaton (NFA) –These make it much easier to start with a regular expression and draw a transition diagram for a device that accepts the corresponding language and has an obvious connection to the regular expression –We will show that allowing nondeterminism doesn’t change the languages that can be accepted Introduction to Computation6

Nondeterministic Finite Automata (cont’d.) This NFA closely resembles the regular expression (aa + aab)*b –The top loop is aa –The bottom loop is aab –By following the links we can generate any string in the language This is not the transition diagram for an FA; some nodes have more than one arc leaving them, some have none Introduction to Computation7

Nondeterministic Finite Automata (cont’d.) For this reason, we should not think of an NFA as describing an algorithm for recognizing a language Instead, consider it as describing a number of different sequences of steps that might be followed Introduction to Computation8

Nondeterministic Finite Automata (cont’d.) This is the “computation tree” for aaaabaab –Each level corresponds to a prefix of the input string –Each state on a level is one the machine could be in after processing that prefix –There is an accepting path for the input string (as well as other paths that are not accepting) Introduction to Computation9

Nondeterministic Finite Automata (cont’d.) Definition: A nondeterministic finite automaton (NFA) is a 5-tuple (Q, , q 0, A,  ), where: –Q is a finite set of states, –  is a finite input alphabet –q 0  Q is the initial state –A  Q is the set of accepting states –  : Q  (  ∪ {  })  2 Q is the transition function. (The values of  are not single states, but sets of states) For every element q of Q and every element  of   {  }, we interpret  (q,  ) as the set of states to which the NFA can move from state q on input  Introduction to Computation10

Nondeterministic Finite Automata (cont’d.) Defining  * is a little harder than for an FA, since  *(q, x) is a set, as is  (p,  ) for any p in the first set: ∪ {  (p,  ) | p   *(q, x)) is a first step towards  * We must also consider  -transitions, which could potentially occur at any stage Introduction to Computation11

Nondeterministic Finite Automata (cont’d.) Definition: Suppose M = (Q, , q 0, A,  ) is an NFA, and S  Q is a set of states –The  -closure of S is the set  (S) that can be defined recursively as follows: S   (S) For every q   (S),  (q,  )   (S) Introduction to Computation12

Nondeterministic Finite Automata (cont’d.) As for any finite set that is defined recursively, we can easily formulate an algorithm to calculate  (S): –Initialize T to be S, as in the basis part of the definition –Make a sequence of passes, in each pass considering every q  T and adding every state in  (q,  ) not already there –Stop after the first pass in which T does not change –The final value of T is  (S) Introduction to Computation13

Nondeterministic Finite Automata (cont’d.) Definition: Let M=(Q, , q 0, A,  ) be an NFA Define the extended transition function  * : Q   *  2 Q as follows: –For every q  Q,  *(q,  ) =  ({q}) –For every q  Q, every y   *, and every     *(q, y  ) =  ( ∪ {  (p,  ) | p   *(q, y)}) –A string x   * is accepted by M if  *(q 0, x) ∩ A   (i.e., some sequence of transitions involving the symbols of x and  ’s leads from q 0 to an accepting state) The language L(M) accepted by M is the set of all strings accepted by M Introduction to Computation14

The Nondeterminism in an NFA Can Be Eliminated Two types of nondeterminism have arisen: –Different arcs for the same input symbol, and  -transitions –Both can be eliminated For the second type, introduce new transitions so that we no longer need the  -transitions –When there is no  -transition from p to q but the NFA can go from p to q by using one or more  -transitions as well as , we introduce the  -transition –The resulting NFA may have more nondeterminism of the first type, but it will have no  -transitions Introduction to Computation15

The Nondeterminism in an NFA Can Be Eliminated (cont’d.) Theorem: For every language L   * accepted by an NFA M = (Q, , q 0, A,  ), there is an NFA M 1 with no  -transitions that also accepts L Define M 1 = (Q, , q 0, A 1,  1 ), where for every q  Q,  1 (q,  ) = , and for every q  Q and every  ,  1 (q,  ) =  *(q,  ) Define A 1 = A ∪ {q 0 } if   L, and A 1 = A otherwise We can prove, by structural induction on x, that for every q and every x with |x|  1,  1 *(q, x) =  * (q, x) Introduction to Computation16

The Nondeterminism in an NFA Can Be Eliminated (cont’d.) Theorem: For every language L   * accepted by an NFA M = (Q, , q 0, A,  ), there is an FA M 1 = (Q 1, , q 1, A 1,  1 ) that also accepts L We can assume M has no  -transitions. Let Q 1 = 2 Q (for this reason, this is called the subset construction); q 1 = {q 0 }; for every q  Q 1 and   ,  1 (q,  ) = ∪ {  (p,  ) | p  q}; A 1 = {q  Q 1 | q ∩ A   } M 1 is clearly an FA –It accepts the same language as M because for every x   *,  1 *(q 1, x) =  *(q 0, x) The proof is by structural induction on x Introduction to Computation17

Kleene’s Theorem, Part 1 Theorem: For every alphabet , every regular language over  can be accepted by a finite automaton Because of what we have just shown, it is enough to show that every regular language over  can be accepted by an NFA The proof is by structural induction, based on the recursive definition of the set of regular languages over  Introduction to Computation18

Kleene’s Theorem, Part 1 (cont’d.) The basis cases are easy The machines pictured below accept the languages  and {  }, respectively The next slide shows schematic diagrams of NFAs that accept L(M 1 ) ∪ L(M 2 ), L(M 1 )L(M 2 ), and L(M 1 )* (each FA is shown as having 2 accepting states) Introduction to Computation19

Kleene’s Theorem, Part 1 (cont’d.) Introduction to Computation20

Kleene’s Theorem, Part 1 (cont’d.) By using these constructions, we can create for every regular expression an NFA that accepts the corresponding language Introduction to Computation21

Kleene’s Theorem, Part 2 Theorem: For every finite automaton M=(Q, , q 0, A,  ), the language L(M) is regular Proof: First, for two states p and q, we define the language L(p, q) = {x   * |  *(p, x)=q} If we can show that for every p and q in Q, L(p, q) is regular, then it will follow that L(M) is, because –L(M) = ∪ {L(q 0, q) | q  A} –The union of a finite collection of regular languages is regular We will show that L(p, q) is regular by expressing it in terms of simpler languages that are regular Introduction to Computation22

Kleene’s Theorem, Part 2 (cont’d.) We will consider the distinct states through which M passes as it moves from p to q If x  L(p, q), we say x causes M to go from p to q through a state r if there are non-null strings x 1 and x 2 such that x = x 1 x 2,  *(p, x 1 ) = r, and  *(r, x 2 ) = q –In using a string of length 1 to go from p to q, M does not go through any state –In using a string of length n  2, it goes through a state n - 1 times (but if n > 2, these states may not be distinct) Introduction to Computation23

Kleene’s Theorem, Part 2 (cont’d.) Assume Q has n elements numbered 1 to n For p, q  Q and j  0, we let L(p, q, j) be the set of strings in L(p, q) that cause M to go from p to q without going through any state numbered higher than j Suppose that for some number k  0, L(p, q, k) is regular for every p, q  Q and consider how a string can be in L(p, q, k+1) –The easiest way is for it to be in L(p, q, k) –If not, it causes M to go to k+1 one or more times, but M goes through nothing higher Introduction to Computation24

Kleene’s Theorem, Part 2 (cont’d.) Every string in L(p, q, k+1) can be described in one of those two ways and every string that has one of these two forms is in L(p, q, k+1). This leads to the formula –L(p, q, k+1) = L(p, q, k) ∪ L(p, k+1, k) L(k+1, k+1, k)* L(k+1, q, k) This is the starting point for a proof by induction on k and for an algorithm Introduction to Computation25