Converting Finite Automata to Regular Expressions



Similar documents
6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

Regular Expressions and Automata using Haskell

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification)

Linear Equations in One Variable

Compiler Construction

Scanner. tokens scanner parser IR. source code. errors

Slope-Intercept Form of a Linear Equation Examples

Implementation of Recursively Enumerable Languages using Universal Turing Machine in JFLAP

Regular Languages and Finite Automata

Chapter 2: Linear Equations and Inequalities Lecture notes Math 1010

SRM UNIVERSITY FACULTY OF ENGINEERING & TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF SOFTWARE ENGINEERING COURSE PLAN

Genetic programming with regular expressions

Course Manual Automata & Complexity 2015

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

Algebra 2: Q1 & Q2 Review

Finite Automata. Reading: Chapter 2

Computer Science Theory. From the course description:

Philadelphia University Faculty of Information Technology Department of Computer Science First Semester, 2007/2008.

Finite Automata. Reading: Chapter 2

3.3. Solving Polynomial Equations. Introduction. Prerequisites. Learning Outcomes

What does the number m in y = mx + b measure? To find out, suppose (x 1, y 1 ) and (x 2, y 2 ) are two points on the graph of y = mx + b.

Computer Architecture Syllabus of Qualifying Examination

Learning Objectives for Section 1.1 Linear Equations and Inequalities

The Method of Partial Fractions Math 121 Calculus II Spring 2015

Automata on Infinite Words and Trees

PARABOLAS AND THEIR FEATURES

CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move.

C H A P T E R Regular Expressions regular expression

Deterministic Finite Automata

a 1 x + a 0 =0. (3) ax 2 + bx + c =0. (4)

Pushdown Automata. International PhD School in Formal Languages and Applications Rovira i Virgili University Tarragona, Spain

1.4. Arithmetic of Algebraic Fractions. Introduction. Prerequisites. Learning Outcomes

CS 301 Course Information

FACTORING QUADRATICS and 8.1.2

1 Determinants and the Solvability of Linear Systems

Partial Fractions. (x 1)(x 2 + 1)

CS5236 Advanced Automata Theory

Increasing Interaction and Support in the Formal Languages and Automata Theory Course

Lecture 2 Matrix Operations

ECE 842 Report Implementation of Elliptic Curve Cryptography

5.4 Solving Percent Problems Using the Percent Equation

Factoring Polynomials: Factoring by Grouping

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile

NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions

Quantum Computers. And How Does Nature Compute? Kenneth W. Regan 1 University at Buffalo (SUNY) 21 May, Quantum Computers

3.6. Partial Fractions. Introduction. Prerequisites. Learning Outcomes

Automata and Computability. Solutions to Exercises

Index support for regular expression search. Alexander Korotkov PGCon 2012, Ottawa

Nonhomogeneous Linear Equations

Section 9.5: Equations of Lines and Planes

Increasing Interaction and Support in the Formal Languages and Automata Theory Course

1.2 GRAPHS OF EQUATIONS. Copyright Cengage Learning. All rights reserved.

Simplifying Algebraic Fractions

Review of Fundamental Mathematics

Chapter 7. Matrices. Definition. An m n matrix is an array of numbers set out in m rows and n columns. Examples. (

Reading 13 : Finite State Automata and Regular Expressions

Higher Education Math Placement

Solution of Linear Systems

Finite Automata and Regular Languages

ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear:

Modeling of Graph and Automaton in Database

Abstract.Weproposetimed(nite)automatatomodelthebehaviorofrealtimesystemsovertime.Ourdenitionprovidesasimple,andyetpowerful,wayto

Informatique Fondamentale IMA S8

6 EXTENDING ALGEBRA. 6.0 Introduction. 6.1 The cubic equation. Objectives

Algebra I. In this technological age, mathematics is more important than ever. When students

Partial Fractions. p(x) q(x)

MAT12X Intermediate Algebra

Systems of Linear Equations

Section 13.5 Equations of Lines and Planes

1.3 Algebraic Expressions

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

Decomposing Rational Functions into Partial Fractions:

Abstract: We describe the beautiful LU factorization of a square matrix (or how to write Gaussian elimination in terms of matrix multiplication).

is identically equal to x 2 +3x +2

Algebra 2 PreAP. Name Period

1 Introduction to Matrices

Kevin James. MTHSC 102 Section 1.5 Exponential Functions and Models

3515ICT Theory of Computation Turing Machines

To add fractions we rewrite the fractions with a common denominator then add the numerators. = +

Turing Machines: An Introduction

Algebra Bridge Project Cell Phone Plans

Hint 1. Answer (b) first. Make the set as simple as possible and try to generalize the phenomena it exhibits. [Caution: the next hint is an answer to

Solving Rational Equations and Inequalities

Section 2.4: Equations of Lines and Planes

Torgerson s Classical MDS derivation: 1: Determining Coordinates from Euclidean Distances

Click on the links below to jump directly to the relevant section

1 = (a 0 + b 0 α) (a m 1 + b m 1 α) 2. for certain elements a 0,..., a m 1, b 0,..., b m 1 of F. Multiplying out, we obtain

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

Lecture 2. Marginal Functions, Average Functions, Elasticity, the Marginal Principle, and Constrained Optimization

Understanding Basic Calculus

Solving Quadratic Equations

Algebra 1 If you are okay with that placement then you have no further action to take Algebra 1 Portion of the Math Placement Test

Algebraic Properties and Proofs

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

Brief Introduction to Vectors and Matrices

Transcription:

Converting Finite Automata to Regular Expressions Alexander Meduna, Lukáš Vrábel, and Petr Zemek Brno University of Technology, Faculty of Information Technology Božetěchova 1/2, 612 00 Brno, CZ http://www.fit.vutbr.cz/ {meduna,ivrabel,izemek} Supported by the FRVŠ MŠMT FR271/2012/G1 grant, 2012. Converting Finite Automata to Regular Expressions 1 / 23

Outline Introduction Basic terms Why? Methods Transitive Closure Method State Removal Method Brzozowski Algebraic Method Comparison Converting Finite Automata to Regular Expressions 2 / 23

Basic Terms Finite automata (NFAs, DFAs) Regular expressions (REGEXPs)... Converting Finite Automata to Regular Expressions 3 / 23

Why? Two possible transformations: Regular expression Finite automaton Finite automaton Regular expression Uhm... Why? Converting Finite Automata to Regular Expressions 4 / 23

Transitive Closure Method Rather theoretical approach. ab q a 1 q bc 2 q 3 Sketch of the method: 1 Let Q = {q 1, q 2,...,q m} be the set of all automatons states. 2 Suppose that regular expression R ij represents the set of all strings that transition the automaton from q i to q j. 3 Wanted regular expression will be the union of all R sf, where q s is the starting state and q f is one the final states. The main problem is how to construct R ij for all states q i, q j. Converting Finite Automata to Regular Expressions 5 / 23

How to construct R ij? Suppose R k ij represents the set of all strings that transition the automaton from q i to q j without passing through any state higher than q k. We can construct R ij by successively constructing R 1 ij, R2 ij,...,r Q ij = R ij. R k ij is recursively defined as: R k ij = R k 1 ij + R k 1 ik (R k 1 kk Assuming we have initialized R 0 ij to be: ) R k 1 kj r if i j and r transitions NFA from q i to q j Rij 0 = r +ε if i = j and r transitions NFA from q i to q j otherwise Converting Finite Automata to Regular Expressions 6 / 23

Example (1/5) Transform the following NFA to the corresponding REGEXP using Transitive Closure Method: 1 q 0 1 q 2 0, 1 Converting Finite Automata to Regular Expressions 7 / 23

Example (2/5) 1) Initialize R 0 ij : 1 q 0 1 q 2 0, 1 R11 0 ε+1 R12 0 0 R21 0 ε+0+1 R 0 22 Converting Finite Automata to Regular Expressions 8 / 23

Example (3/5) 2) Compute R 1 ij : 1 q 0 1 q 2 0, 1 By direct substitution 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 Converting Finite Automata to Regular Expressions 9 / 23

Example (4/5) 3) Compute R 2 ij : 1 q 0 1 q 2 0, 1 By direct substitution 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) Converting Finite Automata to Regular Expressions 10 / 23

Example (5/5) 4) Get the resulting regular expression: 1 q 0 1 q 2 0, 1 R 2 12 = R 12 = 1 0(0+1) is the REGEXP corresponding to the NFA. Converting Finite Automata to Regular Expressions 11 / 23

State Removal Method Based on a transformation from NFA to GNFA (generalized nondeterministic finite automaton). Identifies patterns within the graph and removes states, building up regular expressions along each transition. Sketch of the method: 1 Unify all final states into a single final state using ε-trans. 2 Unify all multi-transitions into a single transition that contains union of inputs. 3 Remove states (and change transitions accordingly) until there is only the starting a the final state. 4 Get the resulting regular expression by direct calculation. The main problem is how to remove states correctly so the accepted language won t be changed. Converting Finite Automata to Regular Expressions 12 / 23

Example (1/3) Transform the following NFA to the corresponding REGEXP using State Removal Method: e a q 1 q 2 d b c q 3 Converting Finite Automata to Regular Expressions 13 / 23

Example (2/3) 1) Remove the middle state: e a q 1 q 2 d b c q 3 ae d ae b ce b q 1 q 3 ce d Converting Finite Automata to Regular Expressions 14 / 23

Example (3/3) 2) Get the resulting regular expression r: ae d q 1 ae b ce d ce b q3 r = (ae d) ae b(ce b+ce d(ae d) ae b). Converting Finite Automata to Regular Expressions 15 / 23

Brzozowski Algebraic Method Janusz Brzozowski, 1964 Utilizes equations over regular expressions. Sketch of the method: 1 Create a system of regular equations with one regular expression unknown for each state in the NFA. 2 Solve the system. 3 The regular expression corresponding to the NFA is the regular expression associated with the starting state. The main problem is how to create the system and how to solve it. Converting Finite Automata to Regular Expressions 16 / 23

Example (1/5) Transform the following NFA to the corresponding REGEXP using Brzozowski Method: a b q 1 q 2 c b Converting Finite Automata to Regular Expressions 17 / 23

Example (2/5) 1) Create a characteristic regular equation for state 1: a b q 1 q 2 c b X 1 = ax 1 + bx 2 Converting Finite Automata to Regular Expressions 18 / 23

Example (3/5) 2) Create a characteristic regular equation for state 2: a a q 1 q 2 c b X 2 = ε + bx 1 + cx 2 Converting Finite Automata to Regular Expressions 19 / 23

Example (4/5) 4) Solve the arisen system of regular expressions: X 1 = ax 1 + bx 2 X 2 = ε + bx 1 + cx 2 Converting Finite Automata to Regular Expressions 20 / 23

Example (5/5) Solution: X 1 = (a + bc b) bc X 2 = c [ε+b(a + bc b) bc ] a b q 1 q 2 c X 1 is the REGEXP corresponding to the NFA. b Converting Finite Automata to Regular Expressions 21 / 23

Comparison of presented methods Transitive Closure Method + clear and simple implementation - tedious for manual use - tends to create very long regular expressions State Removal Method + intuitive, useful for manual inspection - not as straightforward to implement as other methods Brzozowski Algebraic Method + elegant + generates reasonably compact regular expressions Converting Finite Automata to Regular Expressions 22 / 23

References J. Brzozowski. Derivatives of regular expressions. Journal of the ACM, 11(4):481 494, 1964. J. E. Hopcroft and J. D. Ullman. Introduction to Automata Theory, Languages, and Computation. Addison-Wesley, 1979. P. Linz. An introduction to Formal Languages and Automata. Jones and Bartlett Publishers, 3rd edition, 1979. C. Neumann. Converting deterministic finite automata to regular expressions. Available on URL: http://neumannhaus.com/christoph/papers/2005-03-16.dfa to RegEx.pdf. M. Češka, T. Vojnar, and A. Smrčka. Studijní opora do předmětu teoretická informatika. Available on URL: https://www.fit.vutbr.cz/study/courses/tin/public/texty/oporatin.pdf. Converting Finite Automata to Regular Expressions 23 / 23

Discussion