+ All Categories
Home > Documents > January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

Date post: 16-Dec-2015
Category:
Upload: darrell-goodier
View: 218 times
Download: 0 times
Share this document with a friend
Popular Tags:
38
January 7, 2015 CS21 Lecture 2 1 CS21 Decidability and Tractability Lecture 2 January 7, 2015
Transcript
Page 1: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 1

CS21 Decidability and Tractability

Lecture 2

January 7, 2015

Page 2: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 2

Outline

• Finite Automata

• Nondeterministic Finite Automata

• Closure under regular operations

• NFA, FA equivalence

Page 3: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 3

What is computation?

• the set of strings that lead to “accept” is the language recognized by this machine

• if every other string leads to “reject”, then this language is decided by the machine

machineinput

• accept

• reject

• loop forever

Page 4: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 4

Terminology

• finite alphabet Σ : a set of symbols • language L Σ* : subset of strings over Σ• a machine takes an input string and either

– accepts, rejects, or – loops forever

• a machine recognizes the set of strings that lead to accept

• a machine decides a language L if it accepts x L and rejects x L

Page 5: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 5

What goes inside the box?

• We want the simplest mathematical formalization of computation possible.

• Strategy:– endow box with a feature of computation– try to characterize the languages decided– identify language we “know” real computers can

decide that machine cannot– add new feature to overcome limits

machineinput

• accept

• reject

• loop forever

Page 6: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 6

Finite Automata

• simple model of computation

• reads input from left to right, one symbol at a time

• maintains state: information about what seen so far (“memory”)– finite automaton has finite # of states: cannot

remember more things for longer inputs

• 2 ways to describe: by diagram, or formally

Page 7: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 7

FA diagrams

• read input one symbol at a time; follow arrows; accept if end in accept state

states

(single) start state

(several) accept states

1alphabet Σ = {0,1}

0

0,1

0,1

transition for each symbol

Page 8: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 8

FA operation• Example of FA operation:

1

0

0,1

0,1

input: 0 1 0 1

not accepted

Page 9: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 9

FA operation• Example of FA operation:

1

0

0,1

0,1

input: 1 0 1

accepted

What language does this FA recognize?

L = {x : x {0,1}*, x1 = 1}

Page 10: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 10

Example FA

• What language does this FA recognize?

L = {x : x {0,1}*, x has even # of 1s}

• illustrates fundamental feature/limitation of FA: – “tiny” memory– in this example only “remembers” 1 bit of info.

10

0

1

oddeven

Page 11: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 11

Try:

AC

CBCC

AA

BBBBBBB

CCBC

Example FAΣ = {A,B,C}

5 10 15

20 3025 35

rej

AC

B

C

B

A

A

C

B A,B,C

C

B

A C

B

A

B

A,C

BC

A

“35 cents”

{Q,N,D}

A,B,C

Page 12: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 12

FA formal definition

A finite automaton is a 5-tuple

(Q, Σ, δ, q0, F)

– Q is a finite set called the states– Σ is a finite set called the alphabet– δ:Q x Σ → Q is a function called the transition

function

– q0 is an element of Q called the start state

– F is a subset of Q called the accept states

Page 13: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 13

FA formal definition

• Specification of this FA in formal terms:– Q = {even, odd}– Σ = {0,1}

– q0 = even

– F = {even}

10

0

1

oddeven

function δ:

δ(even, 0) = even

δ(even, 1) = odd

δ(odd, 0) = odd

δ(odd, 1) = even

Page 14: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 14

Formal description of FA operation

finite automaton

M = (Q, Σ, δ, q0, F)

accepts a string

w = w1w2w3…wn Σ*

if sequence r0,r1,r2,…,rn of states for which

– r0 = q0

– δ(ri, wi+1) = ri+1 for i = 0,1,2, …, n-1

– rn F

Page 15: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 15

What now?

• We have a model of computation(Maybe this is it. Maybe everything we can do

with real computers we can do with FA…)

• try to characterize the languages FAs can recognize– investigate closure under certain operations

• show that some languages not of this type

Page 16: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 16

Characterizing FA languages

• We will show that the set of languages recognized by FA is closed under:– union “C = (A B)”– concatenation “C = (A B)”– star “ C = A* ”

• Meaning: if A and B are languages recognized by a FA, then C is a language recognized by a FA

Page 17: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 17

Characterizing FA languages

• union “C = (A B)”(A B) = {x : x A or x B or both}

• concatenation “C = (A B)”(A B) = {xy : x A and y B}

• star “ C = A* ” (note: ε always in A*)A* = {x1x2x3…xk: k ≥ 0 and each xi A}

Page 18: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 18

Concatenation attempt

(A B) = {xy : x A and y B}

A B

What label do we put on the new transitions?

Page 19: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 19

Concatenation attempt

• Need it to happen “for free”: label with ε (?)• allows construct with multiple transitions with the

same label (!?)

1 1

ε

=1 1A B

Page 20: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 20

Nondeterministic FA

• We will make life easier by describing an additional feature (nondeterminism) that helps us to “program” FAs

• We will prove that FAs with this new feature can be simulated by ordinary FA– same spirit as programming constructs like

procedures

• The concept of nondeterminism has a significant role in TCS and this course.

Page 21: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 21

NFA diagrams

states

(single) start state

(several) accept statestransitions:

• may have several with a given label (or none)

• may be labeled with ε

• At each step, several choices for next state

Page 22: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 22

NFA operation

• Example of NFA operation:

0,ε1 1

0,1 0,1

alphabet Σ = {0,1}

input: 0 1 0

not accepted

Page 23: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 23

NFA operation

• Example of NFA operation:

0,ε1 1

0,1 0,1

alphabet Σ = {0,1}

input: 1 1 0

accepted

Page 24: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 24

NFA operation

• One way to think of NFA operation:

• string x = x1x2x3…xn accepted if and only if

– there exists a way of inserting ε’s into x

x1εεx2 x3…εxn

– so that there exists a path of transitions from the start state to an accept state

Page 25: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 25

NFA formal definition

A nondeterministic FA is a 5-tuple

(Q, Σ, δ, q0, F)

– Q is a finite set called the states– Σ is a finite set called the alphabet– δ:Q x (Σ {ε}) → (Q) is a function called the

transition function

– q0 is an element of Q called the start state

– F is a subset of Q called the accept states

transitions labeled with

alphabet symbols or ε

“powerset of Q”: the set of all subsets of Q

Page 26: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 26

NFA formal definition

• Specification of this NFA in formal terms:– Q = {s1, s2, s3, s4}

– Σ = {0,1}

– q0 = s1

– F = {s4}

0,ε1 1

0,1 0,1

s1 s2 s3 s4

δ(s1, 0) = {s1}

δ(s1, 1) = {s1, s2}

δ(s1, ε) = { }

δ(s2, 0) = {s3}

δ(s2, 1) = { }

δ(s2, ε) = {s3}

δ(s3, 0) = { }

δ(s3, 1) = {s4}

δ(s3, ε) = { }

δ(s4, 0) = {s4}

δ(s4, 1) = {s4}

δ(s4, ε) = { }

Page 27: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 27

Formal description of NFA operation

NFA M = (Q, Σ, δ, q0, F)

accepts a string w = w1w2w3…wn Σ*

if w can be written (by inserting ε’s) as:

y = y1y2y3…ym (Σ {ε})*

and sequence r0,r1,…,rm of states for which

– r0 = q0

– ri+1 δ(ri, yi+1) for i = 0,1,2, …, m-1

– rm F

Page 28: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 28

Closures

• Recall: want to show the set of languages recognized by NFA is closed under:

– union “C = (A B)”

– concatenation “C = (A B)”

– star “ C = A* ”

Page 29: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 29

Closure under unionC = (A B) = {x : x A or x B}

A

B

A

B

ε

ε

C

Page 30: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 30

Closure under concatenationC = (A B) = {xy : x A and y B}

A B

A B

ε

ε

C

Page 31: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 31

Closure under star

C = A* = {x1x2x3…xk: k ≥ 0 and each xi A}

A

A

ε

εε

C

Page 32: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 32

NFA, FA equivalence

Theorem: a language L is recognized by a FA if and only if L is recognized by a NFA.

Must prove two directions:() L is recognized by a FA implies L is

recognized by a NFA.() L is recognized by a NFA implies L is

recognized by a FA.(usually one is easy, the other more difficult)

Page 33: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 33

NFA, FA equivalence

() L is recognized by a FA implies L is recognized by a NFA

Proof: a finite automaton is a nondeterministic finite automaton that happens to have no ε-transitions, and for which each state has exactly one outgoing transition for each symbol.

Page 34: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 34

NFA, FA equivalence

() L is recognized by a NFA implies L is recognized by a FA.

Proof: we will build a FA that simulates the NFA (and thus recognizes the same language).– alphabet will be the same– what are the states of the FA?

Page 35: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 35

NFA, FA equivalence

– given NFA M = (Q, Σ, δ, q0, F)

– construct FA M’ = (Q’, Σ’, δ’, q0’, F’)

– same alphabet: Σ’ = Σ– states are subsets of M’s states: Q’ = (Q)

– if we are in state RQ’ and we read symbol aΣ’, what is the new state?

0,ε1 1

0,1 0,1

Page 36: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 36

NFA, FA equivalence

– given NFA M = (Q, Σ, δ, q0, F)

– construct FA M’ = (Q’, Σ’, δ’, q0’, F’)

Helpful def’n: E(S) = {q Q : q reachable from S by traveling along 0 or more ε-transitions}

– new transition fn: δ’(R, a) = rR E(δ(r, a))

= “all nodes reachable from R by following an

a-transition, and then 0 or more ε-transitions”

0,ε1 1

0,1 0,1

Page 37: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 37

NFA, FA equivalence

– given NFA M = (Q, Σ, δ, q0, F)

– construct FA M’ = (Q’, Σ’, δ’, q0’, F’)

– new start state: q0’ = E({q0})

– new accept states:

F’ = {R Q’ : R contains an accept state of M)

0,ε1 1

0,1 0,1

Page 38: January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.

January 7, 2015 CS21 Lecture 2 38

NFA, FA equivalence

• We have proved () by construction.

Formally we should also prove that the construction works, by induction on the number of steps of the computation.

– at each step, the state of the FA M’ is exactly the set of reachable states of the NFA M…


Recommended