Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions

Similar documents
Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Automata and Formal Languages - CM0081 Algebraic Laws for Regular Expressions

Regular Expressions. Definitions Equivalence to Finite Automata

Lecture 2: Regular Expression

Finite Automata and Formal Languages

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Automata and Formal Languages - CM0081 Determinist Finite Automata

DFA to Regular Expressions

Parsing Regular Expressions and Regular Grammars

Equivalence of Regular Expressions and FSMs

Regular Expressions and Language Properties

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Formal Models in NLP

CS 154, Lecture 3: DFA NFA, Regular Expressions

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

Outline. Theorem 1. For every regular expression E, there exists an ε-nfa A such that L(E)=L(A).

Deterministic Finite Automaton (DFA)

Equivalence of DFAs and NFAs

Sri vidya college of engineering and technology

Finite Automata and Formal Languages TMV026/DIT321 LP4 2012

TDDD65 Introduction to the Theory of Computation

CS311 Computational Structures Regular Languages and Regular Expressions. Lecture 4. Andrew P. Black Andrew Tolmach

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

Nondeterministic Finite Automata. Nondeterminism Subset Construction

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Theory of Computation (I) Yijia Chen Fudan University

CS 121, Section 2. Week of September 16, 2013

Finite Automata. Theorems - Unit I SUSAN ELIAS. Professor Department of Computer Science & Engineering Sri Venkateswara College of Engineering

Inf2A: Converting from NFAs to DFAs and Closure Properties

COMP4141 Theory of Computation

Finite Automata and Regular Languages

2. Elements of the Theory of Computation, Lewis and Papadimitrou,

Theory of Computation

Closure under the Regular Operations

CS 275 Automata and Formal Language Theory

CMPSCI 250: Introduction to Computation. Lecture #23: Finishing Kleene s Theorem David Mix Barrington 25 April 2013

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Chapter 2: Finite Automata

Java II Finite Automata I

What we have done so far

Harvard CS 121 and CSCI E-207 Lecture 6: Regular Languages and Countability

Extended transition function of a DFA

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Tasks of lexer. CISC 5920: Compiler Construction Chapter 2 Lexical Analysis. Tokens and lexemes. Buffering

Introduction to Finite-State Automata

Computer Sciences Department

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

CS 455/555: Finite automata

Lexical Analysis. DFA Minimization & Equivalence to Regular Expressions

CS 322 D: Formal languages and automata theory

Finite Automata and Regular Languages (part III)

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

3515ICT: Theory of Computation. Regular languages

This Lecture will Cover...

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Discrete Structures - CM0246 Cardinality

UNIT II REGULAR LANGUAGES

Nondeterministic Finite Automata

Finite Automata. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

CMSC 330: Organization of Programming Languages

Regular Expressions [1] Regular Expressions. Regular expressions can be seen as a system of notations for denoting ɛ-nfa

Theory of Computation (II) Yijia Chen Fudan University

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

Discrete Structures - CM0246 Mathematical Induction

Computational Models Lecture 2 1

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Foundations of

Kleene Algebras and Algebraic Path Problems

CMSC 330: Organization of Programming Languages

Computational Models: Class 3

CS243, Logic and Computation Nondeterministic finite automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Lecture 4 Nondeterministic Finite Accepters

Nondeterministic Finite Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Regular Expressions Kleene s Theorem Equation-based alternate construction. Regular Expressions. Deepak D Souza

CS 154 Formal Languages and Computability Assignment #2 Solutions

CS 208: Automata Theory and Logic

Chapter 5. Finite Automata

September 7, Formal Definition of a Nondeterministic Finite Automaton

How do regular expressions work? CMSC 330: Organization of Programming Languages

Nondeterminism and Epsilon Transitions

Computational Models #1

FS Properties and FSTs

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Transcription:

Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions Andrés Sicard-Ramírez Universidad EAFIT Semester 2018-2

Introduction Equivalences DFA NFA -NFA RE Finite Automata and Regular Expressions 2/40

Theorem (3.4) If L = L(D) for some DFA D, then there is a regular expression R such that L = L(R). Finite Automata and Regular Expressions 3/40

Inductive proof on the number of states of the automaton Let the states of D be {1, 2,, n} with 1 the start state. Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.2). Finite Automata and Regular Expressions 4/40

Inductive proof on the number of states of the automaton Let the states of D be {1, 2,, n} with 1 the start state. Rij k : Regular expression describing the set of labels of all paths in D from state i to state j such that the path has no intermediate node whose number is greater than k. Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.2). Finite Automata and Regular Expressions 5/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i j Finite Automata and Regular Expressions 6/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i j No transition from state i to state j i j R 0 ij = Finite Automata and Regular Expressions 7/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i j No transition from state i to state j i j Rij 0 = One transition from state i to state j a i j Rij 0 = a Finite Automata and Regular Expressions 8/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i j No transition from state i to state j i j Rij 0 = One transition from state i to state j a i j Rij 0 = a Various transitions from state i to state j i a 1 j R 0 ij = a 1 + + a n a n Finite Automata and Regular Expressions 9/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j Finite Automata and Regular Expressions 10/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops i R 0 ii = Finite Automata and Regular Expressions 11/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops One loop i R 0 ii = a i R 0 ii = + a Finite Automata and Regular Expressions 12/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops One loop i R 0 ii = a i R 0 ii = + a Question Why do not to define R 0 ii = a? Finite Automata and Regular Expressions 13/40

Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops One loop i R 0 ii = a i R 0 ii = + a Question Why do not to define R 0 ii = a? Various loops a 1 i a n R 0 ii = + a 1 + + a n Finite Automata and Regular Expressions 14/40

Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. Finite Automata and Regular Expressions 15/40

Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. The path does not go through state k at all i k j R k ij = Rk 1 ij Finite Automata and Regular Expressions 16/40

Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. The path does not go through state k at all i k j R k ij = Rk 1 ij The path goes through state k at least once i k k k j R k ij = Rk 1 ik (Rk 1 kk ) Rkj k 1 Finite Automata and Regular Expressions 17/40

Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. The path does not go through state k at all i k j R k ij = Rk 1 ij The path goes through state k at least once i k k k j From the previous cases: R k ij = Rk 1 ik (Rk 1 kk ) Rkj k 1 R k ij = Rk 1 ij + R k 1 ik (Rk 1 kk ) Rkj k 1 Finite Automata and Regular Expressions 18/40

Given that the states of D are {1, 2,, n} with 1 the start state, then L(D) = L(R n 1f 1 + + R n 1f m ) with f i F. Finite Automata and Regular Expressions 19/40

Example To convert the DFA D to a regular expression. 1 0 start 1 2 0, 1 L(D) = {w {0, 1} w has at least one 0}. Finite Automata and Regular Expressions 20/40

Example (cont.) 1 0 start 1 2 0, 1 R 0 ij R 0 ij Regexp R11 0 + 1 R12 0 0 R 0 21 R 0 22 + 0 + 1 Finite Automata and Regular Expressions 21/40

Example (cont.) R 1 ij = R0 ij + R0 i1 (R0 11 ) R 0 1j R 0 ij Regexp R11 0 + 1 R12 0 0 R 0 21 R 0 22 + 0 + 1 R 1 ij Regexp R11 1 ( + 1) + ( + 1)( + 1) ( + 1) R12 1 0 + ( + 1)( + 1) 0 R21 1 + ( + 1) ( + 1) R22 1 + 0 + 1 + ( + 1) 0 Finite Automata and Regular Expressions 22/40

Example (cont.) Some simplifications for regular expressions Let L and M be regular expression variables. ( + L) = L ( + L)L = L L + M L = M L L = L = L + = + L = L ( is the annihilator for concatenation) ( is the identity for union) Finite Automata and Regular Expressions 23/40

Example (cont.) Rij 1 = R0 ij + R0 i1 (R0 11 ) R1j 0 Rij 1 Regexp Simplified R11 1 ( + 1) + ( + 1)( + 1) ( + 1) 1 R12 1 0 + ( + 1)( + 1) 0 1 0 R21 1 + ( + 1) ( + 1) R22 1 + 0 + 1 + ( + 1) 0 + 0 + 1 Finite Automata and Regular Expressions 24/40

Example (cont.) R 2 ij = R1 ij + R1 i2 (R1 22 ) R 1 2j Rij 1 R11 1 Regexp 1 R 1 12 1 0 R 1 21 R 1 22 + 0 + 1 Rij 2 R11 2 Regexp 1 + 1 0( + 0 + 1) R 2 12 1 0 + 1 0( + 0 + 1) ( + 0 + 1) R 2 21 + ( + 0 + 1)( + 0 + 1) R 2 22 + 0 + 1 + ( + 0 + 1)( + 0 + 1) ( + 0 + 1) Finite Automata and Regular Expressions 25/40

Example (cont.) Rij 2 = R1 ij + R1 i2 (R1 22 ) R2j 1 Rij 2 Regexp Simplified R11 2 1 + 1 0( + 0 + 1) 1 R12 2 1 0 + 1 0( + 0 + 1) ( + 0 + 1) 1 0(0 + 1) R21 2 + ( + 0 + 1)( + 0 + 1) R22 2 + 0 + 1 + ( + 0 + 1)( + 0 + 1) ( + 0 + 1) (0 + 1) Finite Automata and Regular Expressions 26/40

Example (cont.) The regular expression equivalent to the automaton D is R 2 12 = 1 0(0 + 1). Finite Automata and Regular Expressions 27/40

From Regular Expressions to Finite Automata Theorem (3.7) Every language defined by a regular expression is also defined by a finite automaton. Finite Automata and Regular Expressions 28/40

From Regular Expressions to Finite Automata Theorem (3.7) Every language defined by a regular expression is also defined by a finite automaton. Inductive proof For each regular expression R we construct an -NFA E such that L(R) = L(E) with: 1. exactly one accepting state, 2. no arcs into the initial state and 3. no arcs out of the accepting state. Finite Automata and Regular Expressions 29/40

struct and ɛ-nfa A, s.t. L(A) = L(R). From Regular Expressions to Finite Automata Proof: By structural induction: Basis step: Automata for (a), (b) and a (c). Basis: Automata for ɛ,, and a. (a) (b) a (c) 73 Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.16). Finite Automata and Regular Expressions 30/40

From Regular Expressions to Finite Automata 3.2. Inductive FINITE step: AUTOMATA AutomatonAND for R REGULAR + S. EXPRESSIONS 105 R S (a) R S (b) Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.17). Finite Automata and Regular Expressions 31/40

From Regular Expressions to Finite Automata S Inductive step: Automaton for RS. (a) R S (b) R (c) Figure 3.17: The inductive step in the regular-expression-to--nfa construction Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.17). Finite Automata and Regular Expressions 32/40

From Regular Expressions R to Finite Automata S Inductive step: Automaton for R. (b) R (c) Figure 3.17: The inductive step in the regular-expression-to--nfa construction automaton of Fig. 3.17(c). That automaton allows us to go either: (a) Directly from the start state to the accepting state along a path labeled. That path lets us accept, whichisinl(r ) no matter Figure from whathopcroft, expression Motwani R is. and Ullman (2007, Fig. 3.17). Finite Automata and Regular Expressions 33/40

From Regular Expressions to Finite Automata Example Convert the regular expression R = (0 + 1) 1(0 + 1) to an -NFA E such L(R) = L(E). Finite Automata and Regular Expressions 34/40

From Regular Expressions to Finite Automata Example Convert the regular expression R = (0 + 1) 1(0 + 1) to an -NFA E such L(R) = L(E). 1. -NFA for 0 + 1: start 0 1 Finite Automata and Regular Expressions 35/40

From Regular Expressions to Finite Automata Example (cont.) 2. -NFA for (0 + 1) : start 0 1 Finite Automata and Regular Expressions 36/40

From Regular Expressions to Finite Automata Example (cont.) 3. -NFA for (0 + 1) 1: start 0 1 1 Finite Automata and Regular Expressions 37/40

From Regular Expressions to Finite Automata Example (cont.) 4. -NFA for (0 + 1) 1(0 + 1): start 0 1 1 0 1 Finite Automata and Regular Expressions 38/40

From Regular Expressions to Finite Automata Exercise (3.2.7) There are some simplifications to the constructions of Theorem 3.7, where we converted a regular expression to an -NFA. Here are three: 1. For the union operator, instead of creating new start and accepting states, merge the two start states into one state with all the transitions of both start states. Likewise, merge the two accepting states, having all transitions to either go to the merged state instead. 2. For the concatenation operator, merge the accepting state of the first automaton with the start state of the second. 3. For the closure operator, simply add -transitions from the accepting state to the start state and vice-versa. Each of these simplifications, by themselves, still yield a correct construction; that is, the resulting -NFA for any regular expression accepts the language of the expression. Which subsets of changes (1), (2) and (3) may be made to the construction together, while still yielding a correct automaton for every regular expression? Finite Automata and Regular Expressions 39/40

References Hopcroft, J. E., Motwani, R. and Ullman, J. D. (2007). Introduction to Automata theory, Languages, and Computation. 3rd ed. Pearson Education (cit. on pp. 4, 5, 30 33). Finite Automata and Regular Expressions 40/40