Top Banner
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org. Permissions beyond the scope of this license may be available at
21

CSE 105 Theory of Computation

Feb 24, 2016

Download

Documents

Maren

CSE 105 Theory of Computation. Alexander Tsiatas Spring 2012. Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution- NonCommercial - ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSE 105 Theory of Computation

CSE 105Theory of

Computation

Alexander TsiatasSpring 2012

Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Based on a work at http://peerinstruction4cs.org.Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org.

Page 2: CSE 105 Theory of Computation

CLOSURE PROOFSREVIEWING OUR EXAMPLE

Guaranteed to be on exams

Page 3: CSE 105 Theory of Computation

From last time

• Are regular languages closed under union?

• a) True• b) False

Page 4: CSE 105 Theory of Computation

Union of two regular languages• L1 = {w | b’s never appear after a’s}

• L2 = {w | length(w) is odd}

• L1 U L2 = {w | b’s never appear after a’s OR length(w) is odd}

Regular because there’s a DFA

Page 5: CSE 105 Theory of Computation

Union of two regular languages

• L1 U L2 = {w | b’s never appear after a’s OR length(w) is odd}

• Does this prove that regular languages are closed under union?– (a) True or (b) False

It’s just one example

Page 6: CSE 105 Theory of Computation

Thm. The class of regular languages is closed under the union operation.

• Proof:• Given: Two regular languages L1, L2.

• Want to show: L1 U L2 is regular.

• Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct a DFA M = (Q,Σ,δ,q0,F), s.t.:– Q = Q1 x Q2

– δ((x,y),c) = (δ1(x,c), δ2 (y,c)), for c in Σ and (x,y) in Q– q0 = (q01, q02)– F = {(x,y) in Q | x in F1 or y in F2}

• M recognizes L1 U L2.• Correctness: ___________________________________• A DFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages

is closed under union. Q.E.D.

Final form for your homework/test:

Could you come up with this, and write it correctly, in a short amount of time on an exam??

Page 7: CSE 105 Theory of Computation

NONDETERMINISTIC FINITE AUTOMATANFA

They’re really good guessers!

What is deterministic?

Page 8: CSE 105 Theory of Computation

DFA or NFA?

a) DFAb) NFAc) Both DFA and NFA

Page 9: CSE 105 Theory of Computation

DFA or NFA?

a) DFAb) NFAc) Both DFA and NFA

Page 10: CSE 105 Theory of Computation

Tracing in an NFA• What are the two sequences of

states on the input “100”?a) (q0,q0,q1,q2[accept]),

(q0,q1,q2[accept]) Final: Accept

b) (q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Accept

c) (q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Reject

d) (q0,q0,q1,q2[reject]), (q0,q1,q2[reject]) Final: Reject

“100”

b

Page 11: CSE 105 Theory of Computation

DFAs vs. NFAs

DFAs• For each character in the

alphabet, exactly one transition leaving every state

• Computation is “deterministic,” i.e. determined by the input, i.e., the same every time for a given input

NFAs• There may be 0, 1, or many

transitions leaving a single state for the same input character

• Transition function defined on “epsilon” in addition to alphabet characters

• There may be several different ways to reach an accept state for a single string—the computation may not determined by the input (“nondeterministic”)

Page 12: CSE 105 Theory of Computation

12

Formal Definition of an NFA

• An NFA M1 is defined as a 5-tuple as follows:

• M1 = (Q, Σ, δ, q0, F), where:– Q is a finite set of states– Σ is a finite set of characters, the alphabet– δ: Q x Σ -> P(Q), the transition function– q0, a member of Q, the start state– F, a subset of Q, the accept state(s)

NEED TO USE THIS FOR PROOFS---CANNOT MAKE GENERAL STATEMENTS BY DRAWING SPECIFIC

EXAMPLES!

WHAT IS the POWER SET?

Page 13: CSE 105 Theory of Computation

13

Nondeterminism

• Because NFAs are non-deterministic, the outcome (accept/reject) of the computation may be different from run to run (i.e., isn’t determined by the input)

a) TRUEb) FALSE

Page 14: CSE 105 Theory of Computation

REG. LANGS. CLOSED UNDER UNION(WHY NFAS ARE SO USEFUL IN PROOFS)

A different (easier!) way to prove what we just proved

Page 15: CSE 105 Theory of Computation

Thm. The class of regular languages is closed under the union operation.

• Proof:• Given: Two regular languages L1, L2.

• Want to show: L1 U L2 is regular.

• Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct a DFA M = (Q,Σ,δ,q0,F), s.t.:– Q = Q1 x Q2

– δ((x,y),c) = (δ1(x,c), δ2 (y,c)), for c in Σ and (x,y) in Q– q0 = (q01, q02)– F = {(x,y) in Q | x in F1 or y in F2}

• M recognizes L1 U L2.• Correctness: ___________________________________• A DFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages

is closed under union. Q.E.D.

Final form for your homework/test:

Could you come up with this, and write it correctly, in a short amount of time on an exam??

Page 16: CSE 105 Theory of Computation

Thm. The class of regular languages is closed under the union operation.

• Proof:• Given: Two regular languages L1, L2.

• Want to show: L1 U L2 is regular.

• Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFA M = (Q,Σ,δ,q0,F), s.t.:– Q =– δ(x,c) =– q0 =– F =

• M recognizes L1 U L2.• Correctness: ___________________________________• An NFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular

languages is closed under union. Q.E.D.

Final form for your homework/test:

Could you come up with this, and write it correctly, in a short amount of time on an exam??

Page 17: CSE 105 Theory of Computation

Back to our working example

Page 18: CSE 105 Theory of Computation

Thm. The class of regular languages is closed under the union operation.

• Proof:• Given: Two regular languages L1, L2.

• Want to show: L1 U L2 is regular.

• Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFA M = (Q,Σ,δ,q0,F), s.t.:– Q = – δ(x,c) =– q0 is a new state not in Q1 or Q2

– F =

• M recognizes L1 U L2.• Correctness: ___________________________________• An NFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular

languages is closed under union. Q.E.D.

Final form for your homework/test:

Discrepancy here NFA vs DFA

Page 19: CSE 105 Theory of Computation

Thm. The class of regular languages is closed under the union operation.

• Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFA M = (Q,Σ,δ,q0,F), s.t.:– Q = ?– δ(x,c) =– q0 is a new state not in Q1 or Q2

– F = ?

– a) Q = Q1 X Q2, F = F1 X F2

– b) Q = Q1 X Q2, F = {(x,y) in Q | x in F1 or y in F2}

– c) Q = Q1 U Q2, F = F1 U F2

– d) Q = Q1 U Q2 U {q0}, F = F1 U F2

Why q0 in {}?

Page 20: CSE 105 Theory of Computation

Thm. The class of regular languages is closed under the union operation.

• Proof:• Given: Two regular languages L1, L2.

• Want to show: L1 U L2 is regular.

• Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFA M = (Q,Σ,δ,q0,F), s.t.:– Q = Q1 U Q2

– δ(x,c) = ?– q0 is a new state not in Q1 or Q2

– F = F1 U F2

• M recognizes L1 U L2.• Correctness: ___________________________________• An NFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular

languages is closed under union. Q.E.D.

Final form for your homework/test:

Discrepancy here NFA vs DFA

Page 21: CSE 105 Theory of Computation

Thm. The class of regular languages is closed under the union operation.

– Q = Q1 U Q2

– δ(x,c) = • δ1(x,c) if x in Q1

• δ2(x,c) if x in Q2

• {q01,q02} if x = q0 and c = ε• { } if x = q0 and c != ε

– q0 is a new state not in Q1 or Q2

– F = F1 U F2

Almost done: we have shown there is an NFA accepting L1 U L2. Does this mean it’s regular? Next class!

Zoomed in

Discrepancy here NFA vs DFA