Equivalence of DFA and Regular Expressions CSCI 3130 Formal - - PowerPoint PPT Presentation

equivalence of dfa and regular expressions
SMART_READER_LITE
LIVE PREVIEW

Equivalence of DFA and Regular Expressions CSCI 3130 Formal - - PowerPoint PPT Presentation

Equivalence of DFA and Regular Expressions CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Fall 2018 Chinese University of Hong Kong 1/18 Three ways of doing it q 1 expressions regular NFA DFA (0+1) 1 0 0,1 q 2 q 0 1 0 1


slide-1
SLIDE 1

Equivalence of DFA and Regular Expressions

CSCI 3130 Formal Languages and Automata Theory

Siu On CHAN Fall 2018

Chinese University of Hong Kong 1/18

slide-2
SLIDE 2

Three ways of doing it

L = {x ∈ Σ∗ | x ends in 01} Σ = {0, 1} q0 q1 q2 1 1 1 q0 q1 q2 0,1 1 (0+1)

∗01

DFA NFA regular expressions

2/18

slide-3
SLIDE 3

They are equally powerful

DFA NFA regular expressions regular languages

3/18

slide-4
SLIDE 4

Examples: regular expression → NFA

R1 = 0 q0 q1 R2 = 01 q0 q1 q2 1

4/18

slide-5
SLIDE 5

Examples: regular expression → NFA

R3 = 0+01 NFA3 q0 q1 q2 q2 q3 q4 q5 q6 ε ε ε 1 ε R4 = (0+01)

q′ NFA3 q′

1

ε ε ε ε

5/18

slide-6
SLIDE 6

Regular expressions

In general, how do we convert a regular expression to an NFA? A regular expression over Σ is an expression formed by the following rules

  • The symbols ∅ and ε are regular expressions
  • Every symbol in Σ is a regular expression
  • If Σ = {0, 1}, then 0 and 1 are both regular expressions
  • If R asd S are regular expressions, so are R + S, RS and R∗

6/18

slide-7
SLIDE 7

General method when Σ = {0, 1}

regular expression = ⇒ NFA ∅ q0 ε q0 q0 q1 1 q0 q1 1

7/18

slide-8
SLIDE 8

General method

regular expression = ⇒ NFA RS q0 NFAR NFAS q1 ε ε ε R + S q0 NFAR NFAS q1 ε ε ε ε R∗ q0 NFAR q1 ε ε ε ε

8/18

slide-9
SLIDE 9

Roadmap

regular expressions 2-state GNFA GNFA NFA ✓

9/18

slide-10
SLIDE 10

Simplify the NFA

First we simplify the NFA so that

  • It has exactly one accepting state
  • No arrows come into the start state
  • No arrows go out of the accepting state

q0 q1 q3 q4 q5

10/18

slide-11
SLIDE 11

Simplify the NFA

First we simplify the NFA so that

  • It has exactly one accepting state
  • No arrows come into the start state
  • No arrows go out of the accepting state

q0 q1 q3 q4 q5 ε ε ε

10/18

slide-12
SLIDE 12

Simplify the NFA

q0 q1 q2 q3 1 1

  • It has exactly one accepting state
  • No arrows come into the start state
  • No arrows go out of the accepting state

11/18

slide-13
SLIDE 13

Simplify the NFA

q0 q1 q2 q3 1 1 ε ε

  • It has exactly one accepting state ✓
  • No arrows come into the start state ✓
  • No arrows go out of the accepting state ✓

11/18

slide-14
SLIDE 14

Generalized NFAs

A generalized NFA is an NFA whose transitions are labeled by regular expressions, like q0 q1 q2 ε + 10∗ 0∗1 0∗11 01

12/18

slide-15
SLIDE 15

GNFA state elimination

regular expressions 2-state GNFA GNFA NFA We will eliminate every state but the start and accepting states

13/18

slide-16
SLIDE 16

State elimination

q0 q1 q2 ε + 10∗ 0∗1 0∗11 01 ⇓ q0 q1 q2 (ε + 10∗)(0∗1)∗0∗11 01 ⇓ q0 q1 q2 (ε + 10∗)(0∗1)∗0∗11 + 01

14/18

slide-17
SLIDE 17

State elimination: general method

To eliminate state q, for every pair of states (u, v) such that u → q → v Replace u q v R1 R2 R3 R4 by u q v R1R∗

2R3 + R4

Remember to do this even when u = v

15/18

slide-18
SLIDE 18

Roadmap

regular expressions 2-state GNFA GNFA NFA ✓ ✓ ✓ ✓ q0 q1 R A 2-state GNFA is the same as a regular expression R

16/18

slide-19
SLIDE 19

Conversion example

q0 q1 q2 q3 ε 1 ε 1 After eliminating q1: q0 q1 q2 q3 0 1 00 1 1 After eliminating q2: q0 q1 q2 q3 0 1 00 1 1 Check: 0 1 00 1 1 q1 q2 1 1

17/18

slide-20
SLIDE 20

Conversion example

q0 q1 q2 q3 ε 1 ε 1 After eliminating q1: q0 q1 q2 q3 0∗1 00∗1 + 1 ε After eliminating q2: q0 q1 q2 q3 0∗1(00∗1 + 1)∗ Check: 0 1 00 1 1 q1 q2 1 1

17/18

slide-21
SLIDE 21

Conversion example

q0 q1 q2 q3 ε 1 ε 1 After eliminating q1: q0 q1 q2 q3 0∗1 00∗1 + 1 ε After eliminating q2: q0 q1 q2 q3 0∗1(00∗1 + 1)∗ Check: 0∗1(00∗1 + 1)∗ ? = q1 q2 1 1

17/18

slide-22
SLIDE 22

Check your answer!

q1 q2 1 1 All strings ending in 1 (0+1)

∗1

0 1 00 1 1 Always ends in 1 0 1 0 1 Does every string ending in 1 have this form? Yes

18/18

slide-23
SLIDE 23

Check your answer!

q1 q2 1 1 All strings ending in 1 (0+1)

∗1

0∗1(00∗1 + 1)∗ Always ends in 1 = 0∗1(0∗1)∗ Does every string ending in 1 have this form? Yes

18/18