102
CSE 135: Introduction to Theory of Computation Closure Properties Sungjin Im University of California, Merced 02-24-2014

CSE 135: Introduction to Theory of Computation Closure Properties

Embed Size (px)

Citation preview

Page 1: CSE 135: Introduction to Theory of Computation Closure Properties

CSE 135: Introduction to Theory of ComputationClosure Properties

Sungjin Im

University of California, Merced

02-24-2014

Page 2: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

I Recall that we can carry out operations on one or morelanguages to obtain a new language

I Very useful in studying the properties of one language byrelating it to other (better understood) languages

I Most useful when the operations are sophisticated, yet areguaranteed to preserve interesting properties of the language.

I Today: A variety of operations which preserve regularityI i.e., the universe of regular languages is closed under these

operations

Page 3: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

I Recall that we can carry out operations on one or morelanguages to obtain a new language

I Very useful in studying the properties of one language byrelating it to other (better understood) languages

I Most useful when the operations are sophisticated, yet areguaranteed to preserve interesting properties of the language.

I Today: A variety of operations which preserve regularityI i.e., the universe of regular languages is closed under these

operations

Page 4: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

I Recall that we can carry out operations on one or morelanguages to obtain a new language

I Very useful in studying the properties of one language byrelating it to other (better understood) languages

I Most useful when the operations are sophisticated, yet areguaranteed to preserve interesting properties of the language.

I Today: A variety of operations which preserve regularityI i.e., the universe of regular languages is closed under these

operations

Page 5: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

I Recall that we can carry out operations on one or morelanguages to obtain a new language

I Very useful in studying the properties of one language byrelating it to other (better understood) languages

I Most useful when the operations are sophisticated, yet areguaranteed to preserve interesting properties of the language.

I Today: A variety of operations which preserve regularity

I i.e., the universe of regular languages is closed under theseoperations

Page 6: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

I Recall that we can carry out operations on one or morelanguages to obtain a new language

I Very useful in studying the properties of one language byrelating it to other (better understood) languages

I Most useful when the operations are sophisticated, yet areguaranteed to preserve interesting properties of the language.

I Today: A variety of operations which preserve regularityI i.e., the universe of regular languages is closed under these

operations

Page 7: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

DefinitionRegular Languages are closed under an operation op on languagesif

L1, L2, . . . Ln regular =⇒ L = op(L1, L2, . . . Ln) is regular

Example

Regular languages are closed under

I “halving”, i.e., L regular =⇒ 12L regular.

I “reversing”, i.e., L regular =⇒ Lrev regular.

Page 8: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

DefinitionRegular Languages are closed under an operation op on languagesif

L1, L2, . . . Ln regular =⇒ L = op(L1, L2, . . . Ln) is regular

Example

Regular languages are closed under

I “halving”, i.e., L regular =⇒ 12L regular.

I “reversing”, i.e., L regular =⇒ Lrev regular.

Page 9: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Properties

DefinitionRegular Languages are closed under an operation op on languagesif

L1, L2, . . . Ln regular =⇒ L = op(L1, L2, . . . Ln) is regular

Example

Regular languages are closed under

I “halving”, i.e., L regular =⇒ 12L regular.

I “reversing”, i.e., L regular =⇒ Lrev regular.

Page 10: CSE 135: Introduction to Theory of Computation Closure Properties

Operations from Regular Expressions

Proposition

Regular Languages are closed under ∪, ◦ and ∗.

Proof.(Summarizing previous arguments.)I L1, L2 regular =⇒ ∃ regexes R1, R2 s.t. L1 = L(R1) and

L2 = L(R2).I =⇒ L1 ∪ L2 = L(R1 ∪ R2) =⇒ L1 ∪ L2 regular.I =⇒ L1 ◦ L2 = L(R1 ◦ R2) =⇒ L1 ◦ L2 regular.I =⇒ L∗1 = L(R∗1 ) =⇒ L∗1 regular. �

Page 11: CSE 135: Introduction to Theory of Computation Closure Properties

Operations from Regular Expressions

Proposition

Regular Languages are closed under ∪, ◦ and ∗.

Proof.(Summarizing previous arguments.)I L1, L2 regular =⇒ ∃ regexes R1, R2 s.t. L1 = L(R1) and

L2 = L(R2).I =⇒ L1 ∪ L2 = L(R1 ∪ R2) =⇒ L1 ∪ L2 regular.

I =⇒ L1 ◦ L2 = L(R1 ◦ R2) =⇒ L1 ◦ L2 regular.I =⇒ L∗1 = L(R∗1 ) =⇒ L∗1 regular. �

Page 12: CSE 135: Introduction to Theory of Computation Closure Properties

Operations from Regular Expressions

Proposition

Regular Languages are closed under ∪, ◦ and ∗.

Proof.(Summarizing previous arguments.)I L1, L2 regular =⇒ ∃ regexes R1, R2 s.t. L1 = L(R1) and

L2 = L(R2).I =⇒ L1 ∪ L2 = L(R1 ∪ R2) =⇒ L1 ∪ L2 regular.I =⇒ L1 ◦ L2 = L(R1 ◦ R2) =⇒ L1 ◦ L2 regular.I =⇒ L∗1 = L(R∗1 ) =⇒ L∗1 regular. �

Page 13: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Under Complementation

Proposition

Regular Languages are closed under complementation, i.e., if L isregular then L = Σ∗ \ L is also regular.

Proof.

I If L is regular, then there is a DFA M = (Q,Σ, δ, q0,F ) suchthat L = L(M).

I Then, M = (Q,Σ, δ, q0,Q \ F ) (i.e., switch accept andnon-accept states) accepts L. �

What happens if M (above) was an NFA?

Page 14: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Under Complementation

Proposition

Regular Languages are closed under complementation, i.e., if L isregular then L = Σ∗ \ L is also regular.

Proof.

I If L is regular, then there is a DFA M = (Q,Σ, δ, q0,F ) suchthat L = L(M).

I Then, M = (Q,Σ, δ, q0,Q \ F ) (i.e., switch accept andnon-accept states) accepts L. �

What happens if M (above) was an NFA?

Page 15: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Under Complementation

Proposition

Regular Languages are closed under complementation, i.e., if L isregular then L = Σ∗ \ L is also regular.

Proof.

I If L is regular, then there is a DFA M = (Q,Σ, δ, q0,F ) suchthat L = L(M).

I Then, M = (Q,Σ, δ, q0,Q \ F ) (i.e., switch accept andnon-accept states) accepts L. �

What happens if M (above) was an NFA?

Page 16: CSE 135: Introduction to Theory of Computation Closure Properties

Closure Under Complementation

Proposition

Regular Languages are closed under complementation, i.e., if L isregular then L = Σ∗ \ L is also regular.

Proof.

I If L is regular, then there is a DFA M = (Q,Σ, δ, q0,F ) suchthat L = L(M).

I Then, M = (Q,Σ, δ, q0,Q \ F ) (i.e., switch accept andnon-accept states) accepts L. �

What happens if M (above) was an NFA?

Page 17: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under ∩

Proposition

Regular Languages are closed under intersection, i.e., if L1 and L2are regular then L1 ∩ L2 is also regular.

Proof.Observe that L1 ∩ L2 = L1 ∪ L2. Since regular languages are closedunder union and complementation, we have

I L1 and L2 are regular

I L1 ∪ L2 is regular

I Hence, L1 ∩ L2 = L1 ∪ L2 is regular. �

Is there a direct proof for intersection (yielding a smaller DFA)?

Page 18: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under ∩

Proposition

Regular Languages are closed under intersection, i.e., if L1 and L2are regular then L1 ∩ L2 is also regular.

Proof.Observe that L1 ∩ L2 = L1 ∪ L2.

Since regular languages are closedunder union and complementation, we have

I L1 and L2 are regular

I L1 ∪ L2 is regular

I Hence, L1 ∩ L2 = L1 ∪ L2 is regular. �

Is there a direct proof for intersection (yielding a smaller DFA)?

Page 19: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under ∩

Proposition

Regular Languages are closed under intersection, i.e., if L1 and L2are regular then L1 ∩ L2 is also regular.

Proof.Observe that L1 ∩ L2 = L1 ∪ L2. Since regular languages are closedunder union and complementation, we have

I L1 and L2 are regular

I L1 ∪ L2 is regular

I Hence, L1 ∩ L2 = L1 ∪ L2 is regular. �

Is there a direct proof for intersection (yielding a smaller DFA)?

Page 20: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under ∩

Proposition

Regular Languages are closed under intersection, i.e., if L1 and L2are regular then L1 ∩ L2 is also regular.

Proof.Observe that L1 ∩ L2 = L1 ∪ L2. Since regular languages are closedunder union and complementation, we have

I L1 and L2 are regular

I L1 ∪ L2 is regular

I Hence, L1 ∩ L2 = L1 ∪ L2 is regular. �

Is there a direct proof for intersection (yielding a smaller DFA)?

Page 21: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under ∩

Proposition

Regular Languages are closed under intersection, i.e., if L1 and L2are regular then L1 ∩ L2 is also regular.

Proof.Observe that L1 ∩ L2 = L1 ∪ L2. Since regular languages are closedunder union and complementation, we have

I L1 and L2 are regular

I L1 ∪ L2 is regular

I Hence, L1 ∩ L2 = L1 ∪ L2 is regular. �

Is there a direct proof for intersection (yielding a smaller DFA)?

Page 22: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under ∩

Proposition

Regular Languages are closed under intersection, i.e., if L1 and L2are regular then L1 ∩ L2 is also regular.

Proof.Observe that L1 ∩ L2 = L1 ∪ L2. Since regular languages are closedunder union and complementation, we have

I L1 and L2 are regular

I L1 ∪ L2 is regular

I Hence, L1 ∩ L2 = L1 ∪ L2 is regular. �

Is there a direct proof for intersection (yielding a smaller DFA)?

Page 23: CSE 135: Introduction to Theory of Computation Closure Properties

Cross-Product Construction

Let M1 = (Q1,Σ, δ1, q1,F1) and M2 = (Q2,Σ, δ2, q2,F2) be DFAsrecognizing L1 and L2, respectively.Idea: Run M1 and M2 in parallel on the same input and accept ifboth M1 and M2 accept.

Consider M = (Q,Σ, δ, q0,F ) defined as follows

I Q = Q1 × Q2

I q0 = 〈q1, q2〉I δ(〈p1, p2〉, a) = 〈δ1(p1, a), δ2(p2, a)〉I F = F1 × F2

M accepts L1 ∩ L2 (exercise)What happens if M1 and M2 where NFAs? Still works! Setδ(〈p1, p2〉, a) = δ1(p1, a)× δ2(p2, a).

Page 24: CSE 135: Introduction to Theory of Computation Closure Properties

Cross-Product Construction

Let M1 = (Q1,Σ, δ1, q1,F1) and M2 = (Q2,Σ, δ2, q2,F2) be DFAsrecognizing L1 and L2, respectively.Idea: Run M1 and M2 in parallel on the same input and accept ifboth M1 and M2 accept.

Consider M = (Q,Σ, δ, q0,F ) defined as follows

I Q = Q1 × Q2

I q0 = 〈q1, q2〉I δ(〈p1, p2〉, a) = 〈δ1(p1, a), δ2(p2, a)〉I F = F1 × F2

M accepts L1 ∩ L2 (exercise)What happens if M1 and M2 where NFAs? Still works! Setδ(〈p1, p2〉, a) = δ1(p1, a)× δ2(p2, a).

Page 25: CSE 135: Introduction to Theory of Computation Closure Properties

Cross-Product Construction

Let M1 = (Q1,Σ, δ1, q1,F1) and M2 = (Q2,Σ, δ2, q2,F2) be DFAsrecognizing L1 and L2, respectively.Idea: Run M1 and M2 in parallel on the same input and accept ifboth M1 and M2 accept.

Consider M = (Q,Σ, δ, q0,F ) defined as follows

I Q = Q1 × Q2

I q0 = 〈q1, q2〉I δ(〈p1, p2〉, a) = 〈δ1(p1, a), δ2(p2, a)〉I F = F1 × F2

M accepts L1 ∩ L2 (exercise)

What happens if M1 and M2 where NFAs? Still works! Setδ(〈p1, p2〉, a) = δ1(p1, a)× δ2(p2, a).

Page 26: CSE 135: Introduction to Theory of Computation Closure Properties

Cross-Product Construction

Let M1 = (Q1,Σ, δ1, q1,F1) and M2 = (Q2,Σ, δ2, q2,F2) be DFAsrecognizing L1 and L2, respectively.Idea: Run M1 and M2 in parallel on the same input and accept ifboth M1 and M2 accept.

Consider M = (Q,Σ, δ, q0,F ) defined as follows

I Q = Q1 × Q2

I q0 = 〈q1, q2〉I δ(〈p1, p2〉, a) = 〈δ1(p1, a), δ2(p2, a)〉I F = F1 × F2

M accepts L1 ∩ L2 (exercise)What happens if M1 and M2 where NFAs?

Still works! Setδ(〈p1, p2〉, a) = δ1(p1, a)× δ2(p2, a).

Page 27: CSE 135: Introduction to Theory of Computation Closure Properties

Cross-Product Construction

Let M1 = (Q1,Σ, δ1, q1,F1) and M2 = (Q2,Σ, δ2, q2,F2) be DFAsrecognizing L1 and L2, respectively.Idea: Run M1 and M2 in parallel on the same input and accept ifboth M1 and M2 accept.

Consider M = (Q,Σ, δ, q0,F ) defined as follows

I Q = Q1 × Q2

I q0 = 〈q1, q2〉I δ(〈p1, p2〉, a) = 〈δ1(p1, a), δ2(p2, a)〉I F = F1 × F2

M accepts L1 ∩ L2 (exercise)What happens if M1 and M2 where NFAs? Still works! Setδ(〈p1, p2〉, a) = δ1(p1, a)× δ2(p2, a).

Page 28: CSE 135: Introduction to Theory of Computation Closure Properties

An Example

q00

q01

0 0

1

1

× =q10 q11

1

1

0 0 q00 q01

q10 q11

1

1

1

1

0 0 0 0

Page 29: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism

DefinitionA homomorphism is function h : Σ∗ → ∆∗ defined as follows:

I h(ε) = ε and for a ∈ Σ, h(a) is any string in ∆∗

I For a = a1a2 . . . an ∈ Σ∗ (n ≥ 2), h(a) = h(a1)h(a2) . . . h(an).

I A homomorphism h maps a string a ∈ Σ∗ to a string in ∆∗ bymapping each character of a to a string h(a) ∈ ∆∗

I A homomorphism is a function from strings to strings that“respects” concatenation: for any x , y ∈ Σ∗,h(xy) = h(x)h(y). (Any such function is a homomorphism.)

Example

h : {0, 1} → {a, b}∗ where h(0) = ab and h(1) = ba. Thenh(0011) = ababbaba

Page 30: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism

DefinitionA homomorphism is function h : Σ∗ → ∆∗ defined as follows:

I h(ε) = ε and for a ∈ Σ, h(a) is any string in ∆∗

I For a = a1a2 . . . an ∈ Σ∗ (n ≥ 2), h(a) = h(a1)h(a2) . . . h(an).

I A homomorphism h maps a string a ∈ Σ∗ to a string in ∆∗ bymapping each character of a to a string h(a) ∈ ∆∗

I A homomorphism is a function from strings to strings that“respects” concatenation: for any x , y ∈ Σ∗,h(xy) = h(x)h(y). (Any such function is a homomorphism.)

Example

h : {0, 1} → {a, b}∗ where h(0) = ab and h(1) = ba. Thenh(0011) = ababbaba

Page 31: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism

DefinitionA homomorphism is function h : Σ∗ → ∆∗ defined as follows:

I h(ε) = ε and for a ∈ Σ, h(a) is any string in ∆∗

I For a = a1a2 . . . an ∈ Σ∗ (n ≥ 2), h(a) = h(a1)h(a2) . . . h(an).

I A homomorphism h maps a string a ∈ Σ∗ to a string in ∆∗ bymapping each character of a to a string h(a) ∈ ∆∗

I A homomorphism is a function from strings to strings that“respects” concatenation: for any x , y ∈ Σ∗,h(xy) = h(x)h(y).

(Any such function is a homomorphism.)

Example

h : {0, 1} → {a, b}∗ where h(0) = ab and h(1) = ba. Thenh(0011) = ababbaba

Page 32: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism

DefinitionA homomorphism is function h : Σ∗ → ∆∗ defined as follows:

I h(ε) = ε and for a ∈ Σ, h(a) is any string in ∆∗

I For a = a1a2 . . . an ∈ Σ∗ (n ≥ 2), h(a) = h(a1)h(a2) . . . h(an).

I A homomorphism h maps a string a ∈ Σ∗ to a string in ∆∗ bymapping each character of a to a string h(a) ∈ ∆∗

I A homomorphism is a function from strings to strings that“respects” concatenation: for any x , y ∈ Σ∗,h(xy) = h(x)h(y). (Any such function is a homomorphism.)

Example

h : {0, 1} → {a, b}∗ where h(0) = ab and h(1) = ba. Thenh(0011) =

ababbaba

Page 33: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism

DefinitionA homomorphism is function h : Σ∗ → ∆∗ defined as follows:

I h(ε) = ε and for a ∈ Σ, h(a) is any string in ∆∗

I For a = a1a2 . . . an ∈ Σ∗ (n ≥ 2), h(a) = h(a1)h(a2) . . . h(an).

I A homomorphism h maps a string a ∈ Σ∗ to a string in ∆∗ bymapping each character of a to a string h(a) ∈ ∆∗

I A homomorphism is a function from strings to strings that“respects” concatenation: for any x , y ∈ Σ∗,h(xy) = h(x)h(y). (Any such function is a homomorphism.)

Example

h : {0, 1} → {a, b}∗ where h(0) = ab and h(1) = ba. Thenh(0011) = ababbaba

Page 34: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism as an Operation on Languages

DefinitionGiven a homomorphism h : Σ∗ → ∆∗ and a language L ⊆ Σ∗,define h(L) = {h(w) | w ∈ L} ⊆ ∆∗.

Example

Let L = {0n1n | n ≥ 0} and h(0) = ab and h(1) = ba. Thenh(L) = {(ab)n(ba)n | n ≥ 0}Exercise: h(L1 ∪ L2) = h(L1) ∪ h(L2). h(L1 ◦ L2) = h(L1) ◦ h(L2),and h(L∗) = h(L)∗.

Page 35: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism as an Operation on Languages

DefinitionGiven a homomorphism h : Σ∗ → ∆∗ and a language L ⊆ Σ∗,define h(L) = {h(w) | w ∈ L} ⊆ ∆∗.

Example

Let L = {0n1n | n ≥ 0} and h(0) = ab and h(1) = ba. Thenh(L) = {(ab)n(ba)n | n ≥ 0}

Exercise: h(L1 ∪ L2) = h(L1) ∪ h(L2). h(L1 ◦ L2) = h(L1) ◦ h(L2),and h(L∗) = h(L)∗.

Page 36: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism as an Operation on Languages

DefinitionGiven a homomorphism h : Σ∗ → ∆∗ and a language L ⊆ Σ∗,define h(L) = {h(w) | w ∈ L} ⊆ ∆∗.

Example

Let L = {0n1n | n ≥ 0} and h(0) = ab and h(1) = ba. Thenh(L) = {(ab)n(ba)n | n ≥ 0}Exercise: h(L1 ∪ L2) = h(L1) ∪ h(L2).

h(L1 ◦ L2) = h(L1) ◦ h(L2),and h(L∗) = h(L)∗.

Page 37: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism as an Operation on Languages

DefinitionGiven a homomorphism h : Σ∗ → ∆∗ and a language L ⊆ Σ∗,define h(L) = {h(w) | w ∈ L} ⊆ ∆∗.

Example

Let L = {0n1n | n ≥ 0} and h(0) = ab and h(1) = ba. Thenh(L) = {(ab)n(ba)n | n ≥ 0}Exercise: h(L1 ∪ L2) = h(L1) ∪ h(L2). h(L1 ◦ L2) = h(L1) ◦ h(L2),and h(L∗) = h(L)∗.

Page 38: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Homomorphism

Proposition

Regular languages are closed under homomorphism, i.e., if L is aregular language and h is a homomorphism, then h(L) is alsoregular.

Proof.We will use the representation of regular languages in terms ofregular expressions to argue this.

I Define homomorphism as an operation on regular expressions

I Show that L(h(R)) = h(L(R))

I Let R be such that L = L(R). Let R ′ = h(R). Thenh(L) = L(R ′). ··→

Page 39: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Homomorphism

Proposition

Regular languages are closed under homomorphism, i.e., if L is aregular language and h is a homomorphism, then h(L) is alsoregular.

Proof.We will use the representation of regular languages in terms ofregular expressions to argue this.

I Define homomorphism as an operation on regular expressions

I Show that L(h(R)) = h(L(R))

I Let R be such that L = L(R). Let R ′ = h(R). Thenh(L) = L(R ′). ··→

Page 40: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Homomorphism

Proposition

Regular languages are closed under homomorphism, i.e., if L is aregular language and h is a homomorphism, then h(L) is alsoregular.

Proof.We will use the representation of regular languages in terms ofregular expressions to argue this.

I Define homomorphism as an operation on regular expressions

I Show that L(h(R)) = h(L(R))

I Let R be such that L = L(R). Let R ′ = h(R). Thenh(L) = L(R ′). ··→

Page 41: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Homomorphism

Proposition

Regular languages are closed under homomorphism, i.e., if L is aregular language and h is a homomorphism, then h(L) is alsoregular.

Proof.We will use the representation of regular languages in terms ofregular expressions to argue this.

I Define homomorphism as an operation on regular expressions

I Show that L(h(R)) = h(L(R))

I Let R be such that L = L(R). Let R ′ = h(R). Thenh(L) = L(R ′). ··→

Page 42: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Homomorphism

Proposition

Regular languages are closed under homomorphism, i.e., if L is aregular language and h is a homomorphism, then h(L) is alsoregular.

Proof.We will use the representation of regular languages in terms ofregular expressions to argue this.

I Define homomorphism as an operation on regular expressions

I Show that L(h(R)) = h(L(R))

I Let R be such that L = L(R). Let R ′ = h(R). Thenh(L) = L(R ′). ··→

Page 43: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism as an Operation on Regular Expressions

DefinitionFor a regular expression R, let h(R) be the regular expressionobtained by replacing each occurence of a ∈ Σ in R by the stringh(a).

Example

If R = (0 ∪ 1)∗001(0 ∪ 1)∗ and h(0) = ab and h(1) = bc thenh(R) = (ab ∪ bc)∗ababbc(ab ∪ bc)∗

Formally h(R) is defined inductively as follows.

h(∅) = ∅ h(R1R2) = h(R1)h(R2)h(ε) = ε h(R1 ∪ R2) = h(R2) ∪ h(R2)h(a) = h(a) h(R∗) = (h(R))∗

Page 44: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism as an Operation on Regular Expressions

DefinitionFor a regular expression R, let h(R) be the regular expressionobtained by replacing each occurence of a ∈ Σ in R by the stringh(a).

Example

If R = (0 ∪ 1)∗001(0 ∪ 1)∗ and h(0) = ab and h(1) = bc thenh(R) = (ab ∪ bc)∗ababbc(ab ∪ bc)∗

Formally h(R) is defined inductively as follows.

h(∅) = ∅ h(R1R2) = h(R1)h(R2)h(ε) = ε h(R1 ∪ R2) = h(R2) ∪ h(R2)h(a) = h(a) h(R∗) = (h(R))∗

Page 45: CSE 135: Introduction to Theory of Computation Closure Properties

Homomorphism as an Operation on Regular Expressions

DefinitionFor a regular expression R, let h(R) be the regular expressionobtained by replacing each occurence of a ∈ Σ in R by the stringh(a).

Example

If R = (0 ∪ 1)∗001(0 ∪ 1)∗ and h(0) = ab and h(1) = bc thenh(R) = (ab ∪ bc)∗ababbc(ab ∪ bc)∗

Formally h(R) is defined inductively as follows.

h(∅) = ∅ h(R1R2) = h(R1)h(R2)h(ε) = ε h(R1 ∪ R2) = h(R2) ∪ h(R2)h(a) = h(a) h(R∗) = (h(R))∗

Page 46: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe thath(R) = h(R1) ∪ h(R2) andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)). Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 47: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).

For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe thath(R) = h(R1) ∪ h(R2) andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)). Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 48: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe thath(R) = h(R1) ∪ h(R2) andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)). Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 49: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe that

h(R) = h(R1) ∪ h(R2) andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)). Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 50: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe thath(R) = h(R1) ∪ h(R2)

andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)). Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 51: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe thath(R) = h(R1) ∪ h(R2) andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)).

Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 52: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe thath(R) = h(R1) ∪ h(R2) andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)). Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))

Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 53: CSE 135: Introduction to Theory of Computation Closure Properties

Proof of Claim

ClaimFor any regular expression R, L(h(R)) = h(L(R)).

Proof.By induction on the number of operations in R

I Base Cases: For R = ε or ∅, h(R) = R and h(L(R)) = L(R).For R = a, L(R) = {a} andh(L(R)) = {h(a)} = L(h(a)) = L(h(R)). So claim holds.

I Induction Step: For R = R1 ∪ R2, observe thath(R) = h(R1) ∪ h(R2) andh(L(R)) = h(L(R1) ∪ L(R2)) = h(L(R1)) ∪ h(L(R2)). Byinduction hypothesis, h(L(Ri )) = L(h(Ri )) and soh(L(R)) = L(h(R1) ∪ h(R2))Other cases (R = R1R2 and R = R∗1 ) similar. �

Page 54: CSE 135: Introduction to Theory of Computation Closure Properties

Nonregularity and Homomorphism

If L is not regular, is h(L) also not regular?

I No! Consider L = {0n1n | n ≥ 0} and h(0) = a and h(1) = ε.Then h(L) = a∗.

Applying a homomorphism can “simplify” a non-regular languageinto a regular language.

Page 55: CSE 135: Introduction to Theory of Computation Closure Properties

Nonregularity and Homomorphism

If L is not regular, is h(L) also not regular?

I No! Consider L = {0n1n | n ≥ 0} and h(0) = a and h(1) = ε.Then h(L) = a∗.

Applying a homomorphism can “simplify” a non-regular languageinto a regular language.

Page 56: CSE 135: Introduction to Theory of Computation Closure Properties

Nonregularity and Homomorphism

If L is not regular, is h(L) also not regular?

I No! Consider L = {0n1n | n ≥ 0} and h(0) = a and h(1) = ε.Then h(L) = a∗.

Applying a homomorphism can “simplify” a non-regular languageinto a regular language.

Page 57: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

DefinitionGiven homomorphism h : Σ∗ → ∆∗ and L ⊆ ∆∗,h−1(L) = {w ∈ Σ∗ | h(w) ∈ L}h−1(L) consists of strings whose homomorphic images are in L

Σ∗ ∆∗

h

h−1(L)

L

Page 58: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

DefinitionGiven homomorphism h : Σ∗ → ∆∗ and L ⊆ ∆∗,h−1(L) = {w ∈ Σ∗ | h(w) ∈ L}

h−1(L) consists of strings whose homomorphic images are in L

Σ∗ ∆∗

h

h−1(L)

L

Page 59: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

DefinitionGiven homomorphism h : Σ∗ → ∆∗ and L ⊆ ∆∗,h−1(L) = {w ∈ Σ∗ | h(w) ∈ L}h−1(L) consists of strings whose homomorphic images are in L

Σ∗ ∆∗

h

h−1(L)

L

Page 60: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

DefinitionGiven homomorphism h : Σ∗ → ∆∗ and L ⊆ ∆∗,h−1(L) = {w ∈ Σ∗ | h(w) ∈ L}h−1(L) consists of strings whose homomorphic images are in L

Σ∗ ∆∗

h

h−1(L)

L

Page 61: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

Example

Let Σ = {a, b}, and ∆ = {0, 1}. Let L = (00 ∪ 1)∗ and h(a) = 01and h(b) = 10.

I h−1(1001) = {ba}, h−1(010110) = {aab}I h−1(L) = (ba)∗

I What is h(h−1(L))? (1001)∗ ( L

Note: In general h(h−1(L)) ⊆ L ⊆ h−1(h(L)), but neithercontainment is necessarily an equality.

Page 62: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

Example

Let Σ = {a, b}, and ∆ = {0, 1}. Let L = (00 ∪ 1)∗ and h(a) = 01and h(b) = 10.

I h−1(1001) = {ba}, h−1(010110) = {aab}

I h−1(L) = (ba)∗

I What is h(h−1(L))? (1001)∗ ( L

Note: In general h(h−1(L)) ⊆ L ⊆ h−1(h(L)), but neithercontainment is necessarily an equality.

Page 63: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

Example

Let Σ = {a, b}, and ∆ = {0, 1}. Let L = (00 ∪ 1)∗ and h(a) = 01and h(b) = 10.

I h−1(1001) = {ba}, h−1(010110) = {aab}I h−1(L) =

(ba)∗

I What is h(h−1(L))? (1001)∗ ( L

Note: In general h(h−1(L)) ⊆ L ⊆ h−1(h(L)), but neithercontainment is necessarily an equality.

Page 64: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

Example

Let Σ = {a, b}, and ∆ = {0, 1}. Let L = (00 ∪ 1)∗ and h(a) = 01and h(b) = 10.

I h−1(1001) = {ba}, h−1(010110) = {aab}I h−1(L) = (ba)∗

I What is h(h−1(L))? (1001)∗ ( L

Note: In general h(h−1(L)) ⊆ L ⊆ h−1(h(L)), but neithercontainment is necessarily an equality.

Page 65: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

Example

Let Σ = {a, b}, and ∆ = {0, 1}. Let L = (00 ∪ 1)∗ and h(a) = 01and h(b) = 10.

I h−1(1001) = {ba}, h−1(010110) = {aab}I h−1(L) = (ba)∗

I What is h(h−1(L))?

(1001)∗ ( L

Note: In general h(h−1(L)) ⊆ L ⊆ h−1(h(L)), but neithercontainment is necessarily an equality.

Page 66: CSE 135: Introduction to Theory of Computation Closure Properties

Inverse Homomorphism

Example

Let Σ = {a, b}, and ∆ = {0, 1}. Let L = (00 ∪ 1)∗ and h(a) = 01and h(b) = 10.

I h−1(1001) = {ba}, h−1(010110) = {aab}I h−1(L) = (ba)∗

I What is h(h−1(L))? (1001)∗ ( L

Note: In general h(h−1(L)) ⊆ L ⊆ h−1(h(L)), but neithercontainment is necessarily an equality.

Page 67: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Inverse Homomorphism

Proposition

Regular languages are closed under inverse homomorphism, i.e., ifL is regular and h is a homomorphism then h−1(L) is regular.

Proof.We will use the representation of regular languages in terms ofDFA to argue this.Given a DFA M recognizing L, construct an DFA M ′ that acceptsh−1(L)

I Intuition: On input w M ′ will run M on h(w) and accept if Mdoes.

··→

Page 68: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Inverse Homomorphism

Proposition

Regular languages are closed under inverse homomorphism, i.e., ifL is regular and h is a homomorphism then h−1(L) is regular.

Proof.We will use the representation of regular languages in terms ofDFA to argue this.

Given a DFA M recognizing L, construct an DFA M ′ that acceptsh−1(L)

I Intuition: On input w M ′ will run M on h(w) and accept if Mdoes.

··→

Page 69: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Inverse Homomorphism

Proposition

Regular languages are closed under inverse homomorphism, i.e., ifL is regular and h is a homomorphism then h−1(L) is regular.

Proof.We will use the representation of regular languages in terms ofDFA to argue this.Given a DFA M recognizing L, construct an DFA M ′ that acceptsh−1(L)

I Intuition: On input w M ′ will run M on h(w) and accept if Mdoes.

··→

Page 70: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Inverse Homomorphism

I Intuition: On input w M ′ will run M on h(w) and accept if Mdoes.

Example

L = L ((00 ∪ 1)∗). h(a) = 01, h(b) = 10.

q0 q1

q2

1

0, 1

0

0

1

Page 71: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Inverse Homomorphism

I Intuition: On input w M ′ will run M on h(w) and accept if Mdoes.

Example

L = L ((00 ∪ 1)∗). h(a) = 01, h(b) = 10.

q0 q1

q2

1

0, 1

0

0

1a bb

a

a, b

Page 72: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Inverse HomomorphismFormal Construction

I Let M = (Q,∆, δ, q0,F ) accept L ⊆ ∆∗ and let h : Σ∗ → ∆∗

be a homomorphismI Define M ′ = (Q ′,Σ, δ′, q′0,F

′), whereI Q ′ = QI q′0 = q0I F ′ = F , andI δ′(q, a) = δ̂M(q, h(a)); M ′ on input a simulates M on h(a)

I M ′ accepts h−1(L)

I Because ∀w . δ̂M′(q0,w) = δ̂M(q0, h(w))

Page 73: CSE 135: Introduction to Theory of Computation Closure Properties

Closure under Inverse HomomorphismFormal Construction

I Let M = (Q,∆, δ, q0,F ) accept L ⊆ ∆∗ and let h : Σ∗ → ∆∗

be a homomorphismI Define M ′ = (Q ′,Σ, δ′, q′0,F

′), whereI Q ′ = QI q′0 = q0I F ′ = F , andI δ′(q, a) = δ̂M(q, h(a)); M ′ on input a simulates M on h(a)

I M ′ accepts h−1(L)

I Because ∀w . δ̂M′(q0,w) = δ̂M(q0, h(w))

Page 74: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-Regularity

ProblemShow that L = {anban | n ≥ 0} is not regular

Proof.Use pumping lemma!

Alternate Proof: If we had an automaton M accepting L then wecan construct an automaton accepting K = {0n1n | n ≥ 0}(“reduction”)More formally, we will show that by applying a sequence of“regularity preserving” operations to L we can get K . Then, sinceK is not regular, L cannot be regular. ··→

Page 75: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-Regularity

ProblemShow that L = {anban | n ≥ 0} is not regular

Proof.Use pumping lemma!Alternate Proof: If we had an automaton M accepting L then wecan construct an automaton accepting K = {0n1n | n ≥ 0}(“reduction”)

More formally, we will show that by applying a sequence of“regularity preserving” operations to L we can get K . Then, sinceK is not regular, L cannot be regular. ··→

Page 76: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-Regularity

ProblemShow that L = {anban | n ≥ 0} is not regular

Proof.Use pumping lemma!Alternate Proof: If we had an automaton M accepting L then wecan construct an automaton accepting K = {0n1n | n ≥ 0}(“reduction”)More formally, we will show that by applying a sequence of“regularity preserving” operations to L we can get K .

Then, sinceK is not regular, L cannot be regular. ··→

Page 77: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-Regularity

ProblemShow that L = {anban | n ≥ 0} is not regular

Proof.Use pumping lemma!Alternate Proof: If we had an automaton M accepting L then wecan construct an automaton accepting K = {0n1n | n ≥ 0}(“reduction”)More formally, we will show that by applying a sequence of“regularity preserving” operations to L we can get K . Then, sinceK is not regular, L cannot be regular. ··→

Page 78: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-RegularityUsing Closure Properties

Proof (contd).

To show that by applying a sequence of “regularity preserving”operations to L = {anban | n ≥ 0} we can get K = {0n1n | n ≥ 0}.

I Consider homomorphism h1 : {a, b, c}∗ → {a, b, c}∗ definedas h1(a) = a, h1(b) = b, h1(c) = a.

I L1 = h−11 (L) = {(a ∪ c)nb(a ∪ c)n | n ≥ 0}I Let L2 = L1 ∩ L(a∗bc∗) = {anbcn | n ≥ 0}I Homomorphism h2 : {a, b, c}∗ → {0, 1}∗ is defined as

h2(a) = 0, h2(b) = ε, and h2(c) = 1.‘I L3 = h2(L2) = {0n1n | n ≥ 0} = K

I Now if L is regular then so are L1, L2, L3, and K . But K is notregular, and so L is not regular. �

Page 79: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-RegularityUsing Closure Properties

Proof (contd).

To show that by applying a sequence of “regularity preserving”operations to L = {anban | n ≥ 0} we can get K = {0n1n | n ≥ 0}.I Consider homomorphism h1 : {a, b, c}∗ → {a, b, c}∗ defined

as h1(a) = a, h1(b) = b, h1(c) = a.I L1 = h−11 (L) = {(a ∪ c)nb(a ∪ c)n | n ≥ 0}

I Let L2 = L1 ∩ L(a∗bc∗) = {anbcn | n ≥ 0}I Homomorphism h2 : {a, b, c}∗ → {0, 1}∗ is defined as

h2(a) = 0, h2(b) = ε, and h2(c) = 1.‘I L3 = h2(L2) = {0n1n | n ≥ 0} = K

I Now if L is regular then so are L1, L2, L3, and K . But K is notregular, and so L is not regular. �

Page 80: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-RegularityUsing Closure Properties

Proof (contd).

To show that by applying a sequence of “regularity preserving”operations to L = {anban | n ≥ 0} we can get K = {0n1n | n ≥ 0}.I Consider homomorphism h1 : {a, b, c}∗ → {a, b, c}∗ defined

as h1(a) = a, h1(b) = b, h1(c) = a.I L1 = h−11 (L) = {(a ∪ c)nb(a ∪ c)n | n ≥ 0}

I Let L2 = L1 ∩ L(a∗bc∗) = {anbcn | n ≥ 0}

I Homomorphism h2 : {a, b, c}∗ → {0, 1}∗ is defined ash2(a) = 0, h2(b) = ε, and h2(c) = 1.‘

I L3 = h2(L2) = {0n1n | n ≥ 0} = K

I Now if L is regular then so are L1, L2, L3, and K . But K is notregular, and so L is not regular. �

Page 81: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-RegularityUsing Closure Properties

Proof (contd).

To show that by applying a sequence of “regularity preserving”operations to L = {anban | n ≥ 0} we can get K = {0n1n | n ≥ 0}.I Consider homomorphism h1 : {a, b, c}∗ → {a, b, c}∗ defined

as h1(a) = a, h1(b) = b, h1(c) = a.I L1 = h−11 (L) = {(a ∪ c)nb(a ∪ c)n | n ≥ 0}

I Let L2 = L1 ∩ L(a∗bc∗) = {anbcn | n ≥ 0}I Homomorphism h2 : {a, b, c}∗ → {0, 1}∗ is defined as

h2(a) = 0, h2(b) = ε, and h2(c) = 1.‘I L3 = h2(L2) = {0n1n | n ≥ 0} = K

I Now if L is regular then so are L1, L2, L3, and K . But K is notregular, and so L is not regular. �

Page 82: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Non-RegularityUsing Closure Properties

Proof (contd).

To show that by applying a sequence of “regularity preserving”operations to L = {anban | n ≥ 0} we can get K = {0n1n | n ≥ 0}.I Consider homomorphism h1 : {a, b, c}∗ → {a, b, c}∗ defined

as h1(a) = a, h1(b) = b, h1(c) = a.I L1 = h−11 (L) = {(a ∪ c)nb(a ∪ c)n | n ≥ 0}

I Let L2 = L1 ∩ L(a∗bc∗) = {anbcn | n ≥ 0}I Homomorphism h2 : {a, b, c}∗ → {0, 1}∗ is defined as

h2(a) = 0, h2(b) = ε, and h2(c) = 1.‘I L3 = h2(L2) = {0n1n | n ≥ 0} = K

I Now if L is regular then so are L1, L2, L3, and K . But K is notregular, and so L is not regular. �

Page 83: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity

For a language L, define head(L) to be the set of all prefixes ofstrings in L. Prove that if L is regular, so is head(L).

We canprove this by

I constructing a DFA/NFA that accepts head(L); or

I giving a regular expression for head(L); or

I by applying a sequence of regularity-preserving operations.

Page 84: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity

For a language L, define head(L) to be the set of all prefixes ofstrings in L. Prove that if L is regular, so is head(L). We canprove this by

I constructing a DFA/NFA that accepts head(L); or

I giving a regular expression for head(L); or

I by applying a sequence of regularity-preserving operations.

Page 85: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity

For a language L, define head(L) to be the set of all prefixes ofstrings in L. Prove that if L is regular, so is head(L). We canprove this by

I constructing a DFA/NFA that accepts head(L); or

I giving a regular expression for head(L); or

I by applying a sequence of regularity-preserving operations.

Page 86: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity

For a language L, define head(L) to be the set of all prefixes ofstrings in L. Prove that if L is regular, so is head(L). We canprove this by

I constructing a DFA/NFA that accepts head(L); or

I giving a regular expression for head(L); or

I by applying a sequence of regularity-preserving operations.

Page 87: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity

For a language L, define head(L) to be the set of all prefixes ofstrings in L. Prove that if L is regular, so is head(L). We canprove this by

I constructing a DFA/NFA that accepts head(L); or

I giving a regular expression for head(L); or

I by applying a sequence of regularity-preserving operations.

Page 88: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity via Regularity-preserving Operations

I For simplicity, assume∑

= {0, 1}; the proof easliy extends toa general alphabet set.

I Define a homomorphism h whereh(0) = 0, h(1) = 1, h(a) = 0, h(b) = 1. Then h−1(L) isregular.

I (0 ∪ 1)∗(a ∪ b)∗) is regular, so is (0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L).

I Define a homomorphism g whereg(0) = 0, g(1) = 1, g(a) = ε, g(b) = ε. Then

g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

is regular.

I Do you see head(L) = g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

?

Page 89: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity via Regularity-preserving Operations

I For simplicity, assume∑

= {0, 1}; the proof easliy extends toa general alphabet set.

I Define a homomorphism h whereh(0) = 0, h(1) = 1, h(a) = 0, h(b) = 1. Then h−1(L) isregular.

I (0 ∪ 1)∗(a ∪ b)∗) is regular, so is (0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L).

I Define a homomorphism g whereg(0) = 0, g(1) = 1, g(a) = ε, g(b) = ε. Then

g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

is regular.

I Do you see head(L) = g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

?

Page 90: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity via Regularity-preserving Operations

I For simplicity, assume∑

= {0, 1}; the proof easliy extends toa general alphabet set.

I Define a homomorphism h whereh(0) = 0, h(1) = 1, h(a) = 0, h(b) = 1. Then h−1(L) isregular.

I (0 ∪ 1)∗(a ∪ b)∗) is regular, so is (0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L).

I Define a homomorphism g whereg(0) = 0, g(1) = 1, g(a) = ε, g(b) = ε. Then

g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

is regular.

I Do you see head(L) = g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

?

Page 91: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity via Regularity-preserving Operations

I For simplicity, assume∑

= {0, 1}; the proof easliy extends toa general alphabet set.

I Define a homomorphism h whereh(0) = 0, h(1) = 1, h(a) = 0, h(b) = 1. Then h−1(L) isregular.

I (0 ∪ 1)∗(a ∪ b)∗) is regular, so is (0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L).

I Define a homomorphism g whereg(0) = 0, g(1) = 1, g(a) = ε, g(b) = ε. Then

g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

is regular.

I Do you see head(L) = g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

?

Page 92: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity via Regularity-preserving Operations

I For simplicity, assume∑

= {0, 1}; the proof easliy extends toa general alphabet set.

I Define a homomorphism h whereh(0) = 0, h(1) = 1, h(a) = 0, h(b) = 1. Then h−1(L) isregular.

I (0 ∪ 1)∗(a ∪ b)∗) is regular, so is (0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L).

I Define a homomorphism g whereg(0) = 0, g(1) = 1, g(a) = ε, g(b) = ε. Then

g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

is regular.

I Do you see head(L) = g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

?

Page 93: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity via Regularity-preserving Operations

I For simplicity, assume∑

= {0, 1}; the proof easliy extends toa general alphabet set.

I Define a homomorphism h whereh(0) = 0, h(1) = 1, h(a) = 0, h(b) = 1. Then h−1(L) isregular.

I (0 ∪ 1)∗(a ∪ b)∗) is regular, so is (0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L).

I Define a homomorphism g whereg(0) = 0, g(1) = 1, g(a) = ε, g(b) = ε. Then

g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

is regular.

I Do you see head(L) = g(

(0 ∪ 1)∗(a ∪ b)∗ ∩ h−1(L))

?

Page 94: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 95: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 96: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 97: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 98: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 99: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 100: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 101: CSE 135: Introduction to Theory of Computation Closure Properties

Proving Regularity and Non-Regularity

Showing that L is not regular

I Use the pumping lemma

I Or, show that from L you can obtain a known non-regularlanguage through regularity preserving operations.

I Note: Non-regular languages are not closed under theoperations discussed.

Showing that L is regular

I Construct a DFA or NFA or regular expression recognizing L

I Or, show that L can be obtained from known regularlanguages L1, L2, . . . Lk through regularity preservingoperations

I Note: Do not use pumping lemma to prove regularity!!

Page 102: CSE 135: Introduction to Theory of Computation Closure Properties

A list of Regularity-Preserving Operations

Regular languages are closed under the following operations.

I Regular Expression operations

I Boolean operations: union, intersection, complement

I Homomorphism

I Inverse Homomorphism

(And several other operations...)