# CS172: “Computability & Complexity” Wim van Dam Soda 665

## Presentation on theme: "CS172: “Computability & Complexity” Wim van Dam Soda 665"— Presentation transcript:

1 CS172: “Computability & Complexity” Wim van Dam Soda 665

2 Today Chapter 0: set notation and languages Chapter 1: deterministic finite automata (DFA) nondeterministic FA (NFA)

3 Standard Set Theory: Conditional: A = { x | x  N, f(x)=0 } Union: A  B Intersection: A  B Complement: Cartesian Product: A  B Power set: P (A)

4 Some Examples L <6 = { x | x  N, x<6 } L <6  L prime = {2,3,5}  = {0,1}  = {(0,0), (0,1), (1,0), (1,1)} Formal: A  B = { x | x  A and x  B}

5 Powerset Formal: P (A) = { S | S  A} Example: A = {x,y} P (A) = { {}, {x}, {y}, {x,y} } Note the different sizes: | P (A)| = 2 |A| |A  A| = |A| 2

6 Languages Given an alphabet , we can make a word or string by concatenating the letters of . Concatenation of “x” and “y” is “xy” Typical example:  ={0,1}, the possible words over  are the finite bit strings. A language is a set of words.

7 More about Languages The empty string  is the unique string with zero length. Concatenation of two langauges: AB = { xy | x  A and y  B } Typical examples: L = { x | x is a bit string with two zeros } L = { a n b n | n  N } L = {1 n | n is prime}

8 A Word of Warning Do not confuse the concatenation of languages with the Cartesian product of sets. For example, let A = {0,00} then AA = { 00, 000, 0000 } with |AA|=3, A  A = { (0,0), (0,00), (00,0), (00,00) } with |A  A|=4

9 Recognizing Languages Let L be a language  S a machine M recognizes L if M xSxS “accept” “reject” if and only if x  L if and only if x  L

10 Finite Automaton The most simple machine that is not just a finite list of words. “Read once”, “no write” procedure. Typical is its limited memory. Think cell-phone, elevator door, etc.

11 A Simple Automaton (0) q1q1 q2q2 q3q3 10 0,1 01 statestransition rules starting state accepting state

12 A Simple Automaton (1) q1q1 q2q2 q3q3 10 0,1 01 on input “0110”, the machine goes: q 1  q 1  q 2  q 2  q 3 = “reject” start accept

13 A Simple Automaton (2) q 1  q 2  q 3  q 2 = “accept” q1q1 q2q2 q3q3 10 0,1 01 on input “101”, the machine goes:

14 A Simple Automaton (3) 010: reject 11: accept : accept : reject  : reject q1q1 q2q2 q3q ,1

15 Finite Automaton (def.) A deterministic finite automaton (DFA) M is defined by a 5-tuple M=(Q, , ,q 0,F) –Q: finite set of states –  : finite alphabet –  : transition function  :Q  Q –q 0  Q: start state –F  Q: set of accepting states

16 M = (Q, , ,q,F) states Q = {q 1,q 2,q 3 } alphabet  = {0,1} start state q 1 accept states F={q 2 } transition function  : q1q1 q2q2 q3q ,1

17 Recognizing Languages (def) A finite automaton M = (Q, , ,q,F) accepts a string/word w = w 1 …w n if and only if there is a sequence r 0 …r n of states in Q such that: 1) r 0 = q 0 2)  (r i,w i+1 ) = r i+1 for all i = 0,…,n–1 3) r n  F

18 Regular Languages The language recognized by a finite automaton M is denoted by L(M). A regular language is a language for which there exists a recognizing finite automaton.

19 Two DFA Questions Given the description of a finite automaton M = (Q, , ,q,F), what is the language L(M) that it recognizes? In general, what kind of languages can be recognized by finite automata? (What are the regular languages?)

20 Union of Two Languages Theorem 1.12: If A 1 and A 2 are regular languages, then so is A 1  A 2. (The regular languages are ‘closed’ under the union operation.) Proof idea: A 1 and A 2 are regular, hence there are two DFA M 1 and M 2, with A 1 =L(M 1 ) and A 2 =L(M 2 ). Out of these two DFA, we will make a third automaton M 3 such that L(M 3 ) = A 1  A 2.

21 Proof Union-Theorem (1) M 1 =(Q 1, ,  1,q 1,F 1 ) and M 2 =(Q 2, ,  2,q 2,F 2 ) Define M 3 = (Q 3, ,  3,q 3,F 3 ) by: Q 3 = Q 1  Q 2 = {(r 1,r 2 ) | r 1  Q 1 and r 2  Q 2 }  3 ((r 1,r 2 ),a) = (  1 (r 1,a),  2 (r 2,a)) q 3 = (q 1,q 2 ) F 3 = {(r 1,r 2 ) | r 1  F 1 or r 2  F 2 }

22 Proof Union-Theorem (2) The automaton M 3 = (Q 3, ,  3,q 3,F 3 ) runs M 1 and M 2 in ‘parallel’ on a string w. In the end, the final state (r 1,r 2 ) ‘knows’ if w  L 1 (via r 1  F 1 ?) and if w  L 2 (via r 2  F 2 ?) The accepting states F 3 of M 3 are such that w  L(M 3 ) if and only if w  L 1 or w  L 2, for: F 3 = {(r 1,r 2 ) | r 1  F 1 or r 2  F 2 }.

23 Concatenation of L 1 and L 2 Definition: L 1 L 2 = { xy | x  L 1 and y  L 2 } Example: {a,b} {0,11} = {a0,a11,b0,b11} Theorem 1.13: If L 1 and L 2 are regular langues, then so is L 1 L 2. (The regular languages are ‘closed’ under concatenation.)

24 Proving Concatenation Thm. Consider the concatenation: {1,01,11,001,011,…} {0,000,00000,…} (That is: the bit strings that end with a “1”, followed by an odd number of 0’s.) Problem is: given a string w, how does the automaton know where the L 1 part stops and the L 2 substring starts? We need an M with ‘lucky guesses’.

25 Nondeterminism Nondeterministic machines are capable of being lucky, no matter how small the probability. A nondeterministic finite automaton has transition rules/possibilities like q1q1 q2q2  q1q1 q2q2 1 q3q3 1

26 A Nondeterministic Automaton q1q1 q2q2 q3q3 1 0,  0,1 This automaton accepts “0110”, because there is a possible path that leads to an accepting state, namely: q 1  q 1  q 2  q 3  q 4  q 4 q4q4 1 0,1

27 A Nondeterministic Automaton q1q1 q2q2 q3q3 1 0,  0,1 The string 1 gets rejected: on “1” the automaton can only reach: {q 1,q 2,q 3 }. q4q4 1 0,1

28 Nondeterminism ~ Parallelism For any (sub)string w, the nondeterministic automaton can be in a set of possible states. If the final set contains an accepting state, then the automaton accepts the string. “The automaton processes the input in a parallel fashion. Its computational path is no longer a line, but a tree.” (Fig. 1.16)

29 Nondeterministic FA (def.) A nondeterministic finite automaton (NFA) M is defined by a 5-tuple M=(Q, , ,q 0,F), with –Q: finite set of states –  : finite alphabet –  : transition function  :Q    P (Q) –q 0  Q: start state –F  Q: set of accepting states

30 Nondeterministic  :Q    P (Q) The function  :Q    P (Q) is the crucial difference. It means: “When reading symbol “a” while in state q, one can go to one of the states in  (q,a)  Q.” The  in   =  {  } takes care of the empty string transitions.

31 Recognizing Languages (def) A nondeterministic FA M = (Q, , ,q,F) accepts a string w = w 1 …w n if and only if we can rewrite w as y 1 …y m with y i   and there is a sequence r 0 …r m of states in Q such that: 1) r 0 =q 0 2) r i+1   (r i,y i+1 ) for all i=0,…,m–1 3) r m  F

32 Exercises (1:3) [Sipser 0.3]: Let A = {x,y,z} and B = {x,y}, answer: 1.Is A a subset of B? 2.Is B a subset of A? 3.What is A  B? 4.What is A  B? 5.What is A  B? 6.What is P (Q)?

33 Exercises (2:3) [Sipser 1.5]: Give NFAs with the specified number of states that recognize the following languages over the alphabet  ={0,1}: 1.{ w | w ends with 00}, three states 2.{0}; two states 3.{ w | w contains even number of 0s, or exactly two 1s}, six states 4.{0 n | n  N }, one state

34 Exercises (3:3) Proof the following result: “If L 1 and L 2 are regular languages, then is a regular language too.” Describe the language that is recognized by this nondeterministic automaton: q1q1 q2q2 q3q3 1 0,  1 q4q4 1 0,1 

35 Additional Practice Problems [Sipser 0.2]: Write the formal descriptions of the sets containing 1.… the numbers 1,10 and … all integers greater than 5 3.… all natural numbers less than 5 4.… the string “aba” 5.… the empty string 6.… nothing Give a formal description of this NFA: Give DFA state diagrams for the following languages over  ={0,1}: 1.{ w | w begins with 1 and ends with 0} 2.{ w | w does not contain substring 110} 3.{} 4.all strings except the empty string q1q1 q2q2 q3q3 1 0,  1 

Similar presentations