Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Aaron Roth

Similar presentations


Presentation on theme: "Instructor: Aaron Roth"— Presentation transcript:

1 Instructor: Aaron Roth aaroth@cis.upenn.edu
CIS 262 Automata, Computability, and Complexity Spring Instructor: Aaron Roth Lecture: January 30, 2019

2 DFA Example S = {a, b}. L2 = { w | 2nd symbol in w equals a }
Do we need five states ? a,b a b Do we need four states ?

3 Distinguishable Strings
Two strings u and v are distinguishable with respect to a language L if there exists a string w such that only one of u.w and v.w is in L Example: L = { w | 2nd symbol in w equals a } e and a Distinguishable: e.ba (= ba) is in L, but a.ba is not a and b Indistinguishable: for all w, a.w is in L iff b.w is in L ab and ba Distinguishable: ab.e is not in L, but ba.e is abb and abbb Indistinguishable: for all w, abb.w is not in L, and abbb.w is also not in L

4 Automata States and Distinguishability
Two strings u and v are distinguishable with respect to a language L if there exists a string w such that only one of u.w and v.w is in L Note: Definition depends on the language L, but not any specific machine for L Lemma: If L(M) = L and strings u and v are distinguishable w.r.t. L, then d*(q0, u) != d*(q0, v) Proof by contradiction. Suppose d*(q0, u) = d*(q0, v) = q for two distinguishable strings u and v By definition, there is a string w such that only one u.w and v.w is in L But state of M on input u.w is same as on input v.w, namely d*(q, w) So M either accepts both u.w and v.w or rejects both. Contradiction!

5 Lower Bounds for Number of Automata States
Lemma: If S = {w1, w2, … wk } is a set of k pairwise distinguishable strings (i.e. for i != j, strings wi and wj are distinguishable w.r.t. L), then a DFA for L must have at least k states Proof: Suppose M is a DFA such that L(M) = L Consider the states d*(q0, w1), d*(q0, w2), … d*(q0, wk) By previous lemma, all these states have to be distinct It follows that M must have at least k states To show that every DFA for L must have at least k states (i.e. k is a lower bound), find a set of k pairwise distinguishable strings!

6 Lower Bound Example S = {a, b}. L = { w | 2nd symbol in w equals a }
Consider the set of strings { e, a, ab, aa } Every pair of strings in this set is distinguishable w.r.t. above language Every DFA for this language must have at least four states We have found a DFA with four states, so that must be optimal!

7 Parametric Example S = {a, b}. For each number k, let Lk = { w | kth symbol in w equals a } How many states are necessary and sufficient to accept Lk as a function of k ? a, b a qa a,b qr b k-1 transitions

8 Parametric Example S = {a, b}. For each number k, let Lk = { w | kth symbol in w equals a } For each k, define DFA Mk Q = { q0, q1 ,… qk-1, qa, qr } Initial state = q0, Final states = { qa } Transition function: d(qi, s) = qi+1 for i=0,1, … k-2, for s in { a, b } d(qk-1, a) = qa , d (qk-1, b) = qr, d(qa, s) = qa , d(qr, s) = qr for s in {a, b} For each k, L(Mk ) = Lk a, b a qa a,b qr b k-1 transitions

9 Lower Bound for Lk S = {a, b}. Lk = { w | kth symbol in w equals a }
Consider the set of (k+2) strings { e, b, b2, …,bk, ak } Every pair of strings in this set is distinguishable w.r.t. Lk For 0<=i<j<=k, bi and bj are distinguishable: bi bk-i-1 a is in Lk (its k-th symbol is a) but bj bk-i-1 a is not in Lk (its k-th symbol is b) For 0<=i<=k, bi and ak are distinguishable: bi bk-i is not in Lk (its k-th symbol is b) but ak bk-i is in Lk (its k-th symbol is a) Every DFA for Lk must have at least (k+2) states

10 How many states are needed ?
S = {a, b}. L = { w | second last symbol in w equals a } a qaa a a a b b b qab a b a b qba b a qbb Is there a DFA with fewer states ? b Are strings a and ba distinguishable ?

11 How many states are needed ?
S = {a, b}. L = { w | second last symbol in w equals a } a qaa a b Four states are necessary: Strings aa, ab, ba, bb all pairwise distinguishable qab b a qba b a qbb b

12 Another Parametric Example
For each number k, let Lk = { w | kth symbol from end in w equals a } How many states are necessary and sufficient to accept Lk as a function of k ? The DFA needs to “remember” last k symbols: 2k states Initially, missing symbols are treated like ‘b’ symbols

13 Another Parametric Example
For each number k, let Lk = { w | kth symbol from end in w equals a } State q = vector of length k where each entry is either a or b Q = { s1 s2 … sk | each si is in { a, b } } Initial state = bk Final states = { s1 s2 … sk | s1 = a } Transition function: d(s1 s2 … sk , s) = s2 … sk s

14 Lower Bound for Lk For each number k, let Lk = { w | kth symbol from end in w equals a } Prove that a DFA for Lk must have at least 2k states Set of strings: {a, b} k all strings of length k Consider two distinct strings in this set: u=c1 c2 … ck and v=d1 d2 … dk We want to prove that u and v are distinguishable: find a string w such that exactly one of u.w and v.w is in Lk Since u != v, there is index i such that ci != di Choose w to be ai-1 k-th symbol from end of u.w is ci and of v.w is di, only one of them is a, and so only one of them is in Lk

15 Nondeterministic Automata
In state q0, on symbol a, choice of next state is not unique: either q0 or q1 In state q2 cannot process additional symbols (no next state) Deterministic transition function: processing symbol s in state q leads to the unique next state d(q, s) Nondeterministic transition function D maps a state and a symbol to a set of states: if current state is q and symbol is s, next state is chosen from the set D(q, s) a,b a a, b q0 q1 q2

16 Execution of Nondeterministic Automata
a,b q0 a a, b a q0 q1 q2 q0 q1 b How does the machine process input string abab ? Many possible executions/runs corresponding paths in this tree Successful run: All of input processed, and Resulting state is accepting Input accepted if at least one of the runs is successful q0 q2 a q0 q1 b q0 q2

17 Execution of Nondeterministic Automata
a,b q0 a a, b a q0 q1 q2 q0 q1 a How does the machine process input string aabb ? Input rejected if no run is successful q0 q1 q2 b q0 q2 b q0

18 Language of a Nondeterministic Automaton
NFA M accepts a string w if and only if there exists a successful execution of M on w Which strings does the above machine accept ? L(M) = { w | second last symbol of w equal a } a,b a a, b q0 q1 q2

19 NFA Example S = { A, C, G, T } A, C, G,T A,C, G,T A C C q0 q1 q2 q3 Nondeterministic transition function D : Q x S  2Q D(q0, A) = {q0 , q1}; D(q0, C) = {q0}; D(q1, A) = { }; … What language does this NFA accept ?

20 NFA Example S = { A, C, G, T } A, C, G,T A,C, G,T A C C q0 q1 q2 q3 Execution of the machine on input ACTACCGA: Alternative to tree of all possible runs: compute the set of possible states after processing each input symbol A {q0 , q1 } C {q0 , q2 } T {q0 } A {q0 , q1 } { q0 } C {q0 , q2 } C {q0 , q3 } G {q0 , q3 } A {q0 , q1 , q3} Accept input if the set of possible states at the end contains a final state

21 Definition: NFA Syntax
A nondeterministic finite automaton (NFA) M consists of a finite set Q of states a finite alphabet S an initial state q0 that belongs to Q a subset F of Q, called accepting/final states a transition function D : Q x S  2Q (if M reads symbol s in state q, the resulting state is some state chosen from the set D(q, s) )

22 Definition: NFA Semantics
Let M = (Q, S, q0, F, D) be an NFA. M accepts the string w = w1 w2 … wk if there exists a sequence of states q0 q1 q2 … qk such that (1) q0 is the initial state, (2) for each i=0, 1, … (k-1), state qi+1 is in D(qi, wi), and (3) state qk is in F. L(M) = set of strings w such that M accepts w

23 Alternative Definition of Acceptance
Let M = (Q, S, q0, F, D) be an NFA. Define extended transition function D* : Q x S*  2Q D *(q, w) = set of all possible states where machine can be after processing the string w starting in state q D*(q, e) = { q } D*(q, x. s) = U D(q’, s) M accepts the input w if and only if the intersection of the sets D*(q0, w) and F is non-empty q’ in D*(q,x)

24 NFA Example Which strings does the above machine accept ?
L(M) = { w | second last symbol of w equal a } a,b a a, b a, b q0 q1 q2 q3

25 NFA Example Draw an NFA that accepts { w | third last symbol of w equal a } Recall: A DFA for this language must have 8 states q0 q1 a a, b q2 a,b q3

26 Parametric Example = {a, b}. For each k, let Lk = { w | kth symbol from end in w equals a } How many states does an NFA need to accept Lk as a function of k ? a a,b a, b k-1 transitions NFA with (k+1) states can accept Lk Recall: DFA must have 2k states Nondeterminism can lead to succinct descriptions !


Download ppt "Instructor: Aaron Roth"

Similar presentations


Ads by Google