CIS 262 Automata Computability and Complexity Spring 2019
CIS 262 Automata, Computability, and Complexity Spring 2019 http: //www. seas. upenn. edu/~cse 262/ Instructor: Aaron Roth aaroth@cis. upenn. edu Lecture: January 30, 2019
DFA Example S = {a, b}. L 2 = { w | 2 nd symbol in w equals a } a, b a a b Do we need five states ? b a a, b b Do we need four states ? a, b a b a, b 2
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 | 2 nd 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 3
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*(q 0, u) != d*(q 0, v) Proof by contradiction. Suppose d*(q 0, u) = d*(q 0, 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! 4
Lower Bounds for Number of Automata States Lemma: If S = {w 1, w 2, … 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*(q 0, w 1), d*(q 0, w 2), … d*(q 0, 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! 5
Lower Bound Example S = {a, b}. L = { w | 2 nd 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! 6
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 L k as a function of k ? a, b a, b a b qa qr a, b k-1 transitions 7
Parametric Example S = {a, b}. For each number k, let Lk = { w | kth symbol in w equals a } a, b a, b a b qa qr a, b k-1 transitions For each k, define DFA Mk Q = { q 0, q 1 , … qk-1, qa, qr } Initial state = q 0, 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 8
Lower Bound for Lk S = {a, b}. Lk = { w | kth symbol in w equals a } Consider the set of (k+2) strings { e, b, b 2, …, bk, ak } Every pair of strings in this set is distinguishable w. r. t. L k 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 9
How many states are needed ? S = {a, b}. L = { w | second last symbol in w equals a } a a a b b a b qaa b a qab b a qba b a Is there a DFA with fewer states ? qbb b Are strings a and ba distinguishable ? 10
How many states are needed ? S = {a, b}. L = { w | second last symbol in w equals a } a qaa b a qab Four states are necessary: Strings aa, ab, ba, bb all pairwise distinguishable b a qba b a qbb b 11
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 L k as a function of k ? The DFA needs to “remember” last k symbols: 2 k states Initially, missing symbols are treated like ‘b’ symbols 12
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 = { s 1 s 2 … sk | each si is in { a, b } } Initial state = bk Final states = { s 1 s 2 … sk | s 1 = a } Transition function: d(s 1 s 2 … sk , s) = s 2 … sk s 13
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 2 k states Set of strings: {a, b} k all strings of length k Consider two distinct strings in this set: u=c 1 c 2 … ck and v=d 1 d 2 … 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 14
Nondeterministic Automata a, b q 0 a q 1 a, b q 2 In state q 0, on symbol a, choice of next state is not unique: either q 0 or q 1 In state q 2 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) 15
Execution of Nondeterministic Automata a, b q 0 a q 1 a, b q 0 a q 2 q 0 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 q 1 q 0 q 2 a q 0 q 1 q 2 b Input accepted if at least one of the runs is successful 16
Execution of Nondeterministic Automata a, b q 0 a q 1 a, b q 0 a q 2 q 0 How does the machine process input string aabb ? a q 0 q 1 q 2 b q 0 Input rejected if no run is successful q 1 q 2 b q 0 17
Language of a Nondeterministic Automaton a, b q 0 a q 1 a, b q 2 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 } 18
NFA Example S = { A, C, G, T } A, C, G, T q 0 A A, C, G, T q 1 C q 2 C q 3 Nondeterministic transition function D : Q x S 2 Q D(q 0, A) = {q 0 , q 1}; D(q 0, C) = {q 0}; D(q 1, A) = { }; … What language does this NFA accept ? 19
NFA Example S = { A, C, G, T } A, C, G, T q 0 A A, C, G, T C q 1 C q 2 q 3 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 { q 0 } A {q 0 , q 1 } C C {q 0 , q 2 } C T {q 0 , q 3 } {q 0 } G A {q 0 , q 1 } {q 0 , q 3 } A {q 0 , q 1 , q 3} Accept input if the set of possible states at the end contains a final state 20
Definition: NFA Syntax A nondeterministic finite automaton (NFA) M consists of Ø a finite set Q of states Ø a finite alphabet S Ø an initial state q 0 that belongs to Q Ø a subset F of Q, called accepting/final states Ø a transition function D : Q x S 2 Q (if M reads symbol s in state q, the resulting state is some state chosen from the set D(q, s) ) 21
Definition: NFA Semantics Let M = (Q, S, q 0, F, D) be an NFA. M accepts the string w = w 1 w 2 … wk if there exists a sequence of states q 0 q 1 q 2 … qk such that (1) q 0 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 22
Alternative Definition of Acceptance Let M = (Q, S, q 0, F, D) be an NFA. Define extended transition function D* : Q x S* 2 Q 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 q’ in D*(q, x) D(q’, s) M accepts the input w if and only if the intersection of the sets D*(q 0, w) and F is non-empty 23
NFA Example a, b q 0 a q 1 a, b q 2 a, b q 3 Which strings does the above machine accept ? L(M) = { w | second last symbol of w equal a } 24
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 a, b q 0 a q 1 a, b q 2 a, b q 3 25
Parametric Example S = {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, b a, b k-1 transitions NFA with (k+1) states can accept Lk Recall: DFA must have 2 k states Nondeterminism can lead to succinct descriptions ! 26
- Slides: 26