55
CS/ECE 374: Algorithms & Models of Computation, Fall 2019 DFA to Regular Expressions, Language Transformations Lecture 7 September 17, 2019 Chandra Chekuri (UIUC) CS/ECE 374 1 Fall 2019 1 / 29

DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

  • Upload
    others

  • View
    21

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

CS/ECE 374: Algorithms & Models of

Computation, Fall 2019

DFA to Regular Expressions,Language TransformationsLecture 7September 17, 2019

Chandra Chekuri (UIUC) CS/ECE 374 1 Fall 2019 1 / 29

Page 2: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Regular Languages, DFAs, NFAs

TheoremLanguages accepted by DFAs, NFAs, and regular expressions are thesame.

DFAs are special cases of NFAs (trivial)

NFAs accept regular expressions (we saw already, relative easy)

DFAs accept languages accepted by NFAs (subset construction)

Regular expressions for languages accepted by DFAs (sketchtoday, again later in the course)

Chandra Chekuri (UIUC) CS/ECE 374 2 Fall 2019 2 / 29

Page 3: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Regular Languages, DFAs, NFAs

TheoremLanguages accepted by DFAs, NFAs, and regular expressions are thesame.

DFAs are special cases of NFAs (trivial)

NFAs accept regular expressions (we saw already, relative easy)

DFAs accept languages accepted by NFAs (subset construction)

Regular expressions for languages accepted by DFAs (sketchtoday, again later in the course)

Chandra Chekuri (UIUC) CS/ECE 374 2 Fall 2019 2 / 29

Page 4: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Part I

DFA to Regular Expressions

Chandra Chekuri (UIUC) CS/ECE 374 3 Fall 2019 3 / 29

Page 5: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

DFA to Regular Expressions

TheoremGiven a DFA M = (Q,Σ, δ, s,A) there is a regular expression rsuch that L(r) = L(M). That is, regular expressions are as powerfulas DFAs (and hence also NFAs).

Simple algorithm but formal proof is technical. See notes.

A different algorithm with an easier formal proof later in thecourse.

Chandra Chekuri (UIUC) CS/ECE 374 4 Fall 2019 4 / 29

Page 6: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 0: Input

A B

C

a

ba

a, b

b

Chandra Chekuri (UIUC) CS/ECE 374 5 Fall 2019 5 / 29

Page 7: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 1: Normalizing

A B

C

a

ba

a, b

b

2: Normalizing it.

init A B

C AC

ǫ ab

a

a+ b

b

ǫ

Chandra Chekuri (UIUC) CS/ECE 374 6 Fall 2019 6 / 29

Page 8: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 2: Remove state A

init A B

C AC

ǫ ab

a

a+ b

b

ǫ

init A B

C AC

ǫ ab

a

a+ b

b

ǫ

a

b

Chandra Chekuri (UIUC) CS/ECE 374 7 Fall 2019 7 / 29

Page 9: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 4: Redrawn without old edges

init B

C AC

b

a

a+ b

ǫ

a

b

Chandra Chekuri (UIUC) CS/ECE 374 8 Fall 2019 8 / 29

Page 10: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 4: Removing B

init B

C AC

b

a

a+ b

ǫ

a

b

init B

C AC

b

a

a+ b

ǫ

a

b

ab∗a

Chandra Chekuri (UIUC) CS/ECE 374 9 Fall 2019 9 / 29

Page 11: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 5: Redraw

init

C AC

a+ b

ǫ

ab∗a+ b

Chandra Chekuri (UIUC) CS/ECE 374 10 Fall 2019 10 / 29

Page 12: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 6: Removing C

init

C AC

a+ b

ǫ

ab∗a+ b

init

C AC

a+ b

ǫ

ab∗a+ b

(ab∗a+ b)(a+ b)∗ ǫ

Chandra Chekuri (UIUC) CS/ECE 374 11 Fall 2019 11 / 29

Page 13: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 7: Redraw

init AC(ab∗a+ b)(a+ b)∗

Chandra Chekuri (UIUC) CS/ECE 374 12 Fall 2019 12 / 29

Page 14: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 8: Extract regular expression

init AC(ab∗a+ b)(a+ b)∗

Thus, the automata is equivalent to the regular expression(ab∗a + b)(a + b)∗.

States can be eliminated in any order

Can start with NFA

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2019 13 / 29

Page 15: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Stage 8: Extract regular expression

init AC(ab∗a+ b)(a+ b)∗

Thus, the automata is equivalent to the regular expression(ab∗a + b)(a + b)∗.

States can be eliminated in any order

Can start with NFA

Chandra Chekuri (UIUC) CS/ECE 374 13 Fall 2019 13 / 29

Page 16: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Part II

Closure Properties and LanguageTransformations

Chandra Chekuri (UIUC) CS/ECE 374 14 Fall 2019 14 / 29

Page 17: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Closure propeties

Definition(Informal) A set A is closed under an operation op if applying op toany elements of A results in an element that also belongs to A.

Examples:

Integers: closed under +, −, ∗, but not division.

Positive integers: closed under + but not under −Regular languages: closed under union, intersection, Kleene star,complement, difference, homomorphism, inverse homomorphism,reverse, . . .

Chandra Chekuri (UIUC) CS/ECE 374 15 Fall 2019 15 / 29

Page 18: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Closure propeties

Definition(Informal) A set A is closed under an operation op if applying op toany elements of A results in an element that also belongs to A.

Examples:

Integers: closed under +, −, ∗, but not division.

Positive integers: closed under + but not under −Regular languages: closed under union, intersection, Kleene star,complement, difference, homomorphism, inverse homomorphism,reverse, . . .

Chandra Chekuri (UIUC) CS/ECE 374 15 Fall 2019 15 / 29

Page 19: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Closure properties of Regular Languages

Question: How do we prove that regular languages are closed undersome new operation?

Three broad approaches

Use existing closure properties

L1, L2, L3, L4 regular implies (L1 − L2) ∩ (L̄3 ∪ L4)∗ is regular

Transform regular expressions

Transform DFAs to NFAs — versatile technique and shows thepower of nondeterminism

Chandra Chekuri (UIUC) CS/ECE 374 16 Fall 2019 16 / 29

Page 20: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Closure properties of Regular Languages

Question: How do we prove that regular languages are closed undersome new operation?

Three broad approaches

Use existing closure properties

L1, L2, L3, L4 regular implies (L1 − L2) ∩ (L̄3 ∪ L4)∗ is regular

Transform regular expressions

Transform DFAs to NFAs — versatile technique and shows thepower of nondeterminism

Chandra Chekuri (UIUC) CS/ECE 374 16 Fall 2019 16 / 29

Page 21: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Closure properties of Regular Languages

Question: How do we prove that regular languages are closed undersome new operation?

Three broad approaches

Use existing closure properties

L1, L2, L3, L4 regular implies (L1 − L2) ∩ (L̄3 ∪ L4)∗ is regular

Transform regular expressions

Transform DFAs to NFAs — versatile technique and shows thepower of nondeterminism

Chandra Chekuri (UIUC) CS/ECE 374 16 Fall 2019 16 / 29

Page 22: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Closure properties of Regular Languages

Question: How do we prove that regular languages are closed undersome new operation?

Three broad approaches

Use existing closure properties

L1, L2, L3, L4 regular implies (L1 − L2) ∩ (L̄3 ∪ L4)∗ is regular

Transform regular expressions

Transform DFAs to NFAs — versatile technique and shows thepower of nondeterminism

Chandra Chekuri (UIUC) CS/ECE 374 16 Fall 2019 16 / 29

Page 23: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Closure properties of Regular Languages

Question: How do we prove that regular languages are closed undersome new operation?

Three broad approaches

Use existing closure properties

L1, L2, L3, L4 regular implies (L1 − L2) ∩ (L̄3 ∪ L4)∗ is regular

Transform regular expressions

Transform DFAs to NFAs — versatile technique and shows thepower of nondeterminism

Chandra Chekuri (UIUC) CS/ECE 374 16 Fall 2019 16 / 29

Page 24: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Example: REVERSE

Given string w , wR is reverse of w .For a language L define LR = {wR | w ∈ L} as reverse of L.

TheoremLR is regular if L is regular.

Infinitely many regular languages!

Proof technique:

take some finite representation of L such as regular expression rDescribe an algorithm A that takes r as input and outputs aregular expression r ′ such that L(r ′) = (L(r))R .

Come up with A and prove its correctness.

Chandra Chekuri (UIUC) CS/ECE 374 17 Fall 2019 17 / 29

Page 25: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Example: REVERSE

Given string w , wR is reverse of w .For a language L define LR = {wR | w ∈ L} as reverse of L.

TheoremLR is regular if L is regular.

Infinitely many regular languages!

Proof technique:

take some finite representation of L such as regular expression rDescribe an algorithm A that takes r as input and outputs aregular expression r ′ such that L(r ′) = (L(r))R .

Come up with A and prove its correctness.

Chandra Chekuri (UIUC) CS/ECE 374 17 Fall 2019 17 / 29

Page 26: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Example: REVERSE

Given string w , wR is reverse of w .For a language L define LR = {wR | w ∈ L} as reverse of L.

TheoremLR is regular if L is regular.

Infinitely many regular languages!

Proof technique:

take some finite representation of L such as regular expression rDescribe an algorithm A that takes r as input and outputs aregular expression r ′ such that L(r ′) = (L(r))R .

Come up with A and prove its correctness.

Chandra Chekuri (UIUC) CS/ECE 374 17 Fall 2019 17 / 29

Page 27: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Example: REVERSE

Given string w , wR is reverse of w .For a language L define LR = {wR | w ∈ L} as reverse of L.

TheoremLR is regular if L is regular.

Infinitely many regular languages!

Proof technique:

take some finite representation of L such as regular expression rDescribe an algorithm A that takes r as input and outputs aregular expression r ′ such that L(r ′) = (L(r))R .

Come up with A and prove its correctness.

Chandra Chekuri (UIUC) CS/ECE 374 17 Fall 2019 17 / 29

Page 28: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

Suppose r is a regular expression for L. How do we create a regularexpression r ′ for LR?

Inductively based on recursive definition of r .

r = ∅ or r = a for some a ∈ Σ

r = r1 + r2

r = r1 · r2

r = (r1)∗

Chandra Chekuri (UIUC) CS/ECE 374 18 Fall 2019 18 / 29

Page 29: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

Suppose r is a regular expression for L. How do we create a regularexpression r ′ for LR? Inductively based on recursive definition of r .

r = ∅ or r = a for some a ∈ Σ

r = r1 + r2

r = r1 · r2

r = (r1)∗

Chandra Chekuri (UIUC) CS/ECE 374 18 Fall 2019 18 / 29

Page 30: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = r

r = r1 + r2. If r ′1, r′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 31: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ =

r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 32: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2

r = r1 · r2. If r ′1, r′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 33: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ =

r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 34: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1

r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 35: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 36: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ =

1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 37: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 38: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via regular expressions

r = ∅ or r = a for some a ∈ Σr ′ = rr = r1 + r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′1 + r ′2r = r1 · r2. If r ′1, r

′2 are reg expressions for (L(r1))R, (L(r2))R

then r ′ = r ′2 · r ′1r = (r1)∗. If r ′1 is reg expressions for (L(r1))R then r ′ = (r ′1)∗

r = (0 + 10)∗(001 + 01)1 then r ′ = 1(100 + 10)(0 + 01)∗

Proof for each identity: tedious case analysis based on definitions ofunion, concatenation, Kleene star and reverse.

Chandra Chekuri (UIUC) CS/ECE 374 19 Fall 2019 19 / 29

Page 39: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via machine transformation

Given DFA M = (Q,Σ, δ, s,A) want NFA N such thatL(N) = (L(M))R .

N should accept wR iff M accepts w

M accepts w iff δ∗M(s,w) ∈ A

Idea: N reverses transitions of M and starts at a final state of M .

Which one? Non-deterministically guesses and accepts if it reaches s.

Chandra Chekuri (UIUC) CS/ECE 374 20 Fall 2019 20 / 29

Page 40: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via machine transformation

Given DFA M = (Q,Σ, δ, s,A) want NFA N such thatL(N) = (L(M))R .

N should accept wR iff M accepts w

M accepts w iff δ∗M(s,w) ∈ A

Idea: N reverses transitions of M and starts at a final state of M .Which one?

Non-deterministically guesses and accepts if it reaches s.

Chandra Chekuri (UIUC) CS/ECE 374 20 Fall 2019 20 / 29

Page 41: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via machine transformation

Given DFA M = (Q,Σ, δ, s,A) want NFA N such thatL(N) = (L(M))R .

N should accept wR iff M accepts w

M accepts w iff δ∗M(s,w) ∈ A

Idea: N reverses transitions of M and starts at a final state of M .Which one? Non-deterministically guesses and accepts if it reaches s.

Chandra Chekuri (UIUC) CS/ECE 374 20 Fall 2019 20 / 29

Page 42: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via machine transformation

q1

q2

q3

q4

q1

q2

q3

q4

s′

ε

ε

Caveat: Reversing transitions may create an NFA.Chandra Chekuri (UIUC) CS/ECE 374 21 Fall 2019 21 / 29

Page 43: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

REVERSE via machine transformation

Models of Computation Lecture �: Nondeterministic Automata [Sp’��]

• Suppose R = A+ B. The inductive hypothesis implies that there are regular expressionsA0 and B0 such that L(A0) = L(A)R and L(B0) = L(B)R. Let R0 = A0 + B0. Then L(R0) =L(A0)[ L(B0) = L(A)R [ L(B)R = (L(A)[ L(B))R = LR.

• Suppose R = A • B. The inductive hypothesis implies that there are regular expressionsA0 and B0 such that L(A0) = L(A)R and L(B0) = L(B)R. Let R0 = B0 • A0. Then L(R0) =L(B0) • L(A0) = L(B)R • L(A)R = (L(A) • L(B))R = LR.

• Finally, suppose R= A⇤. The inductive hypothesis implies that there is a regular expression A0

such that L(A0) = L(A)R. Let R0 = (A0)⇤. Then L(R0) = L(A0)⇤ = (L(A)R)⇤ = (L(A)⇤)R = LR.

In all cases, we have constructed a regular expression R0 such that L(R0) = LR. We conclude thatLR is regular. É

Careful readers may be unsatisfied with the previous proof, because it assumes several“obvious” properties of string and language reversal. Specifically, for all strings x and y and alllanguages L and L0, we assumed the following:

• (x • y)R = yR • xR

• (L · L0)R = (L0)R · LR.

• (L [ L0)R = LR [ (L0)R.

• (L⇤)R = (LR)⇤.

All of these claims are all easy to prove by inductive definition-chasing.

Proof (DFA to NFA): Let M = (⌃,Q, s, A,�) be an arbitrary DFA that accepts L. We constructan NFA MR = (⌃,QR, sR, AR,�R) with "-transitions that accepts LR, intuitively by reversing everytransition in M , and swapping the roles of the start state and the accepting states. BecauseM does not have a unique accepting state, we need to introduce a special start state sR, with"-transitions to each accepting state in M . These are the only "-transitions in MR.

QR =Q [ {sR}AR = {s}

�R(sR,") = A

�R(sR, a) = ? for all a 2 ⌃�R(q,") = ? for all q 2Q

�R(q, a) =�

p�� q 2 �(p, a)

for all q 2Q and a 2 ⌃

Routine inductive definition-chasing now implies that the reversal of any sequence q0�q1� · · ·�q`of transitions in M is a valid sequence q`�q`�1� · · ·�q0 of transitions in MR. Because thetransitions retain their labels (but reverse directions), it follows that M accepts any string w ifand only if MR accepts wR.

We conclude that the NFA MR accepts LR, so LR must be regular. É

Lemma �.�. For any regular language L, the language half(L) := {w | ww 2 L} is also regular.

Proof: Let M = (⌃,Q, s, A,�) be an arbitrary DFA that accepts L.Intuitively, we construct an NFA M 0 that reads its input string w and simulates the original

DFA M reading the input string ww. Our overall strategy has three parts:

��

Chandra Chekuri (UIUC) CS/ECE 374 22 Fall 2019 22 / 29

Page 44: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

A more complicated example: CYCLE

CYCLE(L) = {yx | x, y ∈ Σ∗, xy ∈ L}

TheoremCYCLE(L) is regular if L is regular.

Example: L = {abc, 374a}

CYCLE(L) =

Chandra Chekuri (UIUC) CS/ECE 374 23 Fall 2019 23 / 29

Page 45: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

A more complicated example: CYCLE

CYCLE(L) = {yx | x, y ∈ Σ∗, xy ∈ L}

TheoremCYCLE(L) is regular if L is regular.

Example: L = {abc, 374a}

CYCLE(L) =

Chandra Chekuri (UIUC) CS/ECE 374 23 Fall 2019 23 / 29

Page 46: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

A more complicated example: CYCLE

CYCLE(L) = {yx | x, y ∈ Σ∗, xy ∈ L}

TheoremCYCLE(L) is regular if L is regular.

Given DFA M for L create NFA N that accepts CYCLE(L).

N is a finite state machine, cannot know split of w into xy andyet has to simulate M on x and y .

Exploit fact that M is itself a finite state machine. N only needsto “know” the state δ∗M(s, x) and there are only finite numberof states in M

Chandra Chekuri (UIUC) CS/ECE 374 24 Fall 2019 24 / 29

Page 47: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

A more complicated example: CYCLE

CYCLE(L) = {yx | x, y ∈ Σ∗, xy ∈ L}

TheoremCYCLE(L) is regular if L is regular.

Given DFA M for L create NFA N that accepts CYCLE(L).

N is a finite state machine, cannot know split of w into xy andyet has to simulate M on x and y .

Exploit fact that M is itself a finite state machine. N only needsto “know” the state δ∗M(s, x) and there are only finite numberof states in M

Chandra Chekuri (UIUC) CS/ECE 374 24 Fall 2019 24 / 29

Page 48: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Construction for CYCLE

Let w = xy and w ′ = yx .

N guesses state q = δ∗M(s, x) and simulates M on w ′ withstart state q.

N guesses when y ends (at that point M must be in an acceptstate) and transitions to a copy of M to simulate M onremaining part of w ′ (which is x)

N accepts w ′ if after second copy of M on x it ends up in theguessed state q

Chandra Chekuri (UIUC) CS/ECE 374 25 Fall 2019 25 / 29

Page 49: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Construction for CYCLE

q1

q2

q3

q4

q1

q2

q3

q4

q1

q2

q3

q4

ε

ε

q1

q2

q3

q4

q1

q2

q3

q4

ε

ε

q1

q2

q3

q4

q1

q2

q3

q4

ε

ε

q1

q2

q3

q4

q1

q2

q3

q4

ε

ε

s′

ε

ε

ε

ε

Chandra Chekuri (UIUC) CS/ECE 374 26 Fall 2019 26 / 29

Page 50: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Proving correctness

Exercise: Write down formal description of N in tuple notationstarting with M = (Q,Σ, δ, s,A).

Need to argue that L(N) = CYCLE(L(M))

If w = xy accepted by M then argue that yx is accepted by NIf N accepts w ′ then argue that w ′ = yx such that xyaccepted by M .

Chandra Chekuri (UIUC) CS/ECE 374 27 Fall 2019 27 / 29

Page 51: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Application of closure properties to non-regularity

L1 = {0n1n | n ≥ 0}L2 = {w ∈ {0, 1}∗ | #0(w) = #1(w)}L3 = {0i1j | i 6= j}

L1 is not regular. Can we use that fact to prove L2 and L2 are notregular without going through the fooling set argument?

L1 = L2 ∩ 0∗1∗ hence if L2 is regular then L1 is regular, acontradiction.

L1 = L̄3 ∩ 0∗1∗ hence if L3 is regular then L1 is regular, acontradiction

Chandra Chekuri (UIUC) CS/ECE 374 28 Fall 2019 28 / 29

Page 52: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Application of closure properties to non-regularity

L1 = {0n1n | n ≥ 0}L2 = {w ∈ {0, 1}∗ | #0(w) = #1(w)}L3 = {0i1j | i 6= j}

L1 is not regular. Can we use that fact to prove L2 and L2 are notregular without going through the fooling set argument?

L1 = L2 ∩ 0∗1∗ hence if L2 is regular then L1 is regular, acontradiction.

L1 = L̄3 ∩ 0∗1∗ hence if L3 is regular then L1 is regular, acontradiction

Chandra Chekuri (UIUC) CS/ECE 374 28 Fall 2019 28 / 29

Page 53: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Application of closure properties to non-regularity

L1 = {0n1n | n ≥ 0}L2 = {w ∈ {0, 1}∗ | #0(w) = #1(w)}L3 = {0i1j | i 6= j}

L1 is not regular. Can we use that fact to prove L2 and L2 are notregular without going through the fooling set argument?

L1 = L2 ∩ 0∗1∗ hence if L2 is regular then L1 is regular, acontradiction.

L1 = L̄3 ∩ 0∗1∗ hence if L3 is regular then L1 is regular, acontradiction

Chandra Chekuri (UIUC) CS/ECE 374 28 Fall 2019 28 / 29

Page 54: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Application of closure properties to non-regularity

L1 = {0n1n | n ≥ 0}L2 = {w ∈ {0, 1}∗ | #0(w) = #1(w)}L3 = {0i1j | i 6= j}

L1 is not regular. Can we use that fact to prove L2 and L2 are notregular without going through the fooling set argument?

L1 = L2 ∩ 0∗1∗ hence if L2 is regular then L1 is regular, acontradiction.

L1 = L̄3 ∩ 0∗1∗ hence if L3 is regular then L1 is regular, acontradiction

Chandra Chekuri (UIUC) CS/ECE 374 28 Fall 2019 28 / 29

Page 55: DFA to Regular Expressions, Language Transformations · 2019-09-19 · DFA to Regular Expressions Theorem Given a DFA M = (Q; ; ;s;A) there is a regular expression r such that L(r)

Jeff’s reminder about exam

Following topics not on the upcoming midterm exam

Transforming DFA/NFA into regular expressions (covered today)

Minimizing DFA

Chandra Chekuri (UIUC) CS/ECE 374 29 Fall 2019 29 / 29