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 28, 2019

2 Administrivia Registration:
Nick Mancuso should be in the process of granting permits to everyone on the waitlist in “category 2” Recitation: First Recitation is today after class (4:30-5:30) in the Wu and Chen auditorium in Levine. DFA review/practice before the first problem set is due (Weds)

3 Recap DFA M = (states Q, alphabet S, initial state q0, final states F,
transition function d : Q x S  Q ) Extended transition function: d* : Q x S*  Q L(M) = { w | d*(q0, w) is in F }

4 Syntax vs Semantics Syntax of DFA M: listing of its states, alphabet symbols, transitions, initial state, and final states Syntactic questions: How many states does M have? Is the set of final states empty? Semantics of DFA: the language L(M) Mathematical set that captures what it computes/solves Semantic questions: Is a particular string w in L(M)? Is the set L(M) empty? Is the set L(M) finite? Such distinction holds in all of computer science: Syntax of a program: text corresponding to its code Semantics of a program: Mathematical function it computes

5 Regular Languages A language L is called regular if there exists a DFA M such that L(M)=L That is: the problem encoded by the language L can be solved by a finite-state machine Examples of regular languages: { w | w contains an even number of a’s } { w | w ends with the symbol a } { w | w contains the substring “ACC” } Examples of non-regular languages: { w | count(w, a) = count(w, b) } { w | w encodes a graph where m has max number of connections }

6 Why Study DFAs and Regular Languages ?
Introduction to mathematical theory of computation Precise definition of syntax and semantics Operations on models, variations, extensions Beautiful and robust theory dating back to 1960s Solvable decision problems Questions such as “are two machines semantically equivalent” are solvable for DFAs, but are unsolvable for general programs Applications Regular expressions for pattern matching in documents (supported by all modern programming languages) Modeling and verification of finite-state controllers/protocols

7 Another Example What language does this DFA accept? DFA M:
L(M) = { w | w contains at least two a’s } q0 q1 a b q2 a,b

8 Does your DFA accept the correct language ?
S = { a, b }, L = { w | w contains an even number of a’s } DFA M: How do you prove that M is correct, that is, M accepts exactly L ? b b a q0 q1 a

9 Proof of Correctness S = { a, b }, L = { w | count(w,a) is even }
DFA M: To prove: For all strings w, M accepts w if and only if count(w,a) is even To prove: For all strings w, d*(q0, w) = q0 iff count(w,a) is even b b a q0 q1 a

10 Proof of Correctness q0 q1 a b To prove: For all strings w, d*(q0, w) = q0 iff count(w,a) is even Proof by induction on string length/structure: Base case : Prove the claim for w = e Inductive case: Assume that claim holds for an arbitrary string x Prove the claim for w = x.s, where s is a symbol (either a or b) Recall: d*(q, e) = q d*(q, x. s) = d ( d* (q, x), s)

11 Proof of Correctness: Base Case
q0 q1 a b To prove: For all strings w, d*(q0, w) = q0 iff count(w,a) is even Base case : Prove the claim for w = e By definition of d*, d*(q0, e) = q0 The empty string has 0 number of a’s, which is an even number So the claim holds

12 Proof of Correctness: Inductive Case
q0 q1 a b To prove: For all strings w, d*(q0, w) = q0 iff count(w,a) is even Assume that the claim holds for an arbitrary string x: that is, assume: d*(q0, x) = q0 iff count(x,a) is even Need to show the claim for w = x. s, where s is a symbol in { a, b } d*(q0, x) can be q0 or q1, and s can be a or b Gives four cases to consider. Let us consider the case d*(q0, x) = q0 and s = b, rest three are similar

13 Proof of Correctness: Inductive Case
q0 q1 a b By induction hypothesis, d*(q0, x) = q0 iff count(x,a) is even To prove, for s in {a,b}, d*(q0, x. s) = q0 iff count(x. s,a) is even Case d*(q0, x) = q0 and s = b: In this case, by induction hypothesis, count(x,a) is even To prove: d*(q0, x.b) = q0 iff count(x.b,a) is even d*(q0, x.b) = d ( d* (q0, x), b) by defn. of d* = d (q0, b) = q0 by defn. of transition function of M Adding b to a string does not change the number of a’s it contains, so count(x.b, a) equals count(x, a), which is even in this case. QED

14 Another Example What language does this DFA accept? DFA M:
Claim: L(M) = { w | w contains at least two a’s } q0 q1 a b q2 a,b

15 Proof of Correctness q0 q1 a b q2 a,b To prove: For all strings w, d*(q0, w) = q2 iff count(w,a) is at least 2 Proof by induction on string w: Base case : To prove: d*(q0, e) = q2 iff count(e,a) is at least 2 d*(q0, e) = q0 by definition of d* count(e,a) is 0 Thus, both “d*(q0, e) = q2 “ and “count(e,a) is at least 2” are false, and claim holds

16 Proof: Inductive Case q0 q1 a b q2 a,b Induction hypothesis, d*(q0, x) = q2 iff count(x,a) is at least 2 To prove, for s in {a,b}, d*(q0, x. s) = q2 iff count(x. s,a) is at least 2 Case d*(q0, x) = q0 and s = a: In this case, by induction hypothesis, count(x,a) < 2 To prove: d*(q0, x.a) = q2 iff count(x.a,a) is at least 2 The proof fails!! count(x,a)=1 and d*(q0, x) = q0 is consistent with the assumptions In such a case, count(x.a,a) = 2 but d*(q0, x.a) = d(q0, a) = q1 Claim does not hold. How to fix the proof ??

17 Stronger Claim For all strings w, d*(q0, w) = q0 if count(w,a) = 0
b q2 a,b For all strings w, d*(q0, w) = q0 if count(w,a) = 0 = q1 if count(w,a) = 1 = q2 if count(w,a) >= 2 This claim is stronger than the original claim: if we prove this, it follows that d*(q0, w) = q2 iff count(w,a) >= 2 Instead of just saying “strings in L lead to a final state and strings not in L lead to a non-final state”, we have strengthened the claim by identifying, for each state, which strings lead to that state

18 Correctness Proof q0 q1 a b q2 a,b To prove: For all strings w, d*(q0, w) = q0 if count(w,a) = 0 = q1 if count(w,a) = 1 = q2 if count(w,a) >= 2 Proof by induction on string w Base case: prove claim for w = e d*(q0, e) = q0 and count(e,a) is 0. The claim follows

19 Correctness Proof: Inductive case
q0 q1 a b q2 a,b Assume that d*(q0, x) equals q0 if count(x,a) = 0, equals q1 if count(x,a) = 1, and equals q2 if count(x,a) >= 2 Prove that, for each s in {a, b}, d*(q0, x. s) equals q0 if count(x. s,a) = 0, equals q1 if count(x. s,a) = 1, and equals q2 if count(x. s,a) >= 2 Proof by cases: d*(q0, x) can be q0 or q1 or q2, and s can be a or b Case d*(q0, x) = q0 and s=a: count(x,a)=0 by induction hypothesis. count(x.a, a) = 1 d*(q0, x.a) = d(q0, a) by definition of d* = q1 by definition of d for the machine Remaining five cases are similar

20 Recipe for Proving Correctness of Automata
Given a language L described by a mathematical constraint and a DFA M = ({q0, q1, … qn }, S, q0, F, d ), to prove that L(M) = L: Find a precise descriptions of the sets T0, T1, … Tn of strings that take the machine from initial state to the corresponding states Language L should match sets corresponding to final states Prove by induction on string w: For all w, d*(q0, w) = qi if w is in set Ti, for i=0, 1, … n Base case: prove claim for w = e Assume: d*(q0, x) = qi if x is in set Ti, for i=0, … n To prove: for each s in S, d*(q0, x.s) = qi if x.s is in set Ti, for i=0, … n Proof by case analysis on what s is and what d*(q0, x) is

21 Another Example = { a, b }, L = { w | either count(w,a) is even
or w ends with b } DFA M: Prove: M accepts w if and only if w is in L q0 q1 a b q3 q2

22 Correctness Proof To prove: For all strings w,
q0 q1 a b q3 q2 Correctness Proof To prove: For all strings w, d*(q0, w) = q0 if count(w,a) is even and w does not end with b = q1 if count(w,a) is odd and w does not end with b = q2 if count(w,a) is even and w ends with b = q3 if count(w,a) is odd and w ends with b The cases corresponding to final states cover the language L: that is, above claim implies that d*(q0, w) is in F iff either count(w,a) is even or w ends with b Prove the claim by induction on string w

23 Correctness Proof To prove: For all strings w,
q0 q1 a b q3 q2 Correctness Proof To prove: For all strings w, d*(q0, w) = q0 if count(w,a) is even and w does not end with b = q1 if count(w,a) is odd and w does not end with b = q2 if count(w,a) is even and w ends with b = q3 if count(w,a) is odd and w ends with b Base Case: d*(q0, e) = q0 Count(e,a) = 0, which is even and e Does not end in a b.

24 Correctness Proof To prove: For all strings w,
q0 q1 a b q3 q2 Correctness Proof To prove: For all strings w, d*(q0, w) = q0 if count(w,a) is even and w does not end with b = q1 if count(w,a) is odd and w does not end with b = q2 if count(w,a) is even and w ends with b = q3 if count(w,a) is odd and w ends with b Inductive case (one example): w = x.a and d*(q0, x) = q2 Count(x,a) is even and x ends in a b. d*(q0, x.a) = d(q2, a) = q1. Count(x.a,a) is odd and x.a does not end in a b.


Download ppt "Instructor: Aaron Roth"

Similar presentations


Ads by Google