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

2 Course Logistics Homework 1: Posted on Piazza/Class website
Due next Wednesday Before Class Construct DFAs using AutomataTutor. (Note – by demonstration, determining if two finite automata accept the same language must be solvable! Not so for general computer programs..)

3 Recap Alphabet S : Finite set of symbols/characters used for encoding
A string w over an alphabet S is a finite sequence of symbols in S A language L over an alphabet S is a subset of S* Inputs are encoded as strings and (decision) problems correspond to languages

4 Example Language S = All English text characters
String w then corresponds to a text document L1 = { w | each of the vowels a, e, i, o, u occurs at least once in w } = { w | count(w,a)>0 and count(w,e)>0 and count(w,i)>0 and count(w,o)>0 and count(w,u)>0 } notation: count(w,s) = the number of times the symbol s occurs in w L2 = { w | count(w,a) = count(w,e) }

5 Encoding Graph Problems
Problem: Given the graph of Facebook friends connections, find the person with the highest number of connections Decision version: Given a graph of connections among n people (numbered 1 through n) and person identifier m (between 1 and n), check if person m has the highest number of connections

6 Encoding Graph Problems
In this graph over 4 people, does person 2 have max number of connections? S = { 0, 1, # } 1 2 4 3 1 0 0 # 1 0 # 1 # 1 0 # 1 # 1 1 # 1 # # 1 0 # 1 1 # 1 1 # # Number of People 4 Person identifier 2 Edge between 1 and 2 Edge between 1 and 3

7 Graph Problems as Languages
L = { w | w encodes a graph over n people such that person m has the highest number of connections } Example string in the language: Example string not in the language: We don’t need to worry about such low-level encoding of problems, but the high-level point is that it can be done! 1 0 0 # 1 1 # 1 # 1 0 # 1 # 1 1 # 1 # # 1 0 # 1 1 # 1 1 # # 1 0 0 # 1 0 # 1 # 1 0 # 1 # 1 1 # 1 # # 1 0 # 1 1 # 1 1 # #

8 Machines for Languages
Machine M for a language L: Given an input string w, machine M scans w from left to right, processing one symbol in each step After reading the entire string w, M should either accept or reject w, depending on whether or not w is in L

9 Finite-state Machines
Machine M has some fixed (finite) number of states q0 a One of these states is the initial state b q1 q2 Behavior specified by transitions: for each state, based on symbol being processed, what should the next state be q4 q3 Some states marked as accept/final states: after reading the entire input w, if M ends up in a final state, then accept w, else reject w

10 Designing Finite Automaton: Example 1
Construct machine M for L = { w | w contains an even number of a’s }, where S = { a, b } Start with the initial state b b a q0 q1 Figure out transitions out of q0 on a and b a Key question: can we reuse an existing state or need a new state? Figure out transitions out of q1 on a and b

11 Designing Finite Automaton: Example 1
Construct machine M for L = { w | w contains an even number of a’s }, where S = { a, b } b b a q0 q1 a Execution or “run” of the machine on input string w = abbab a q1 b q1 b q1 a q0 b q0 q0 Which states should be final/accepting ?

12 Designing Finite Automaton: Example 2
Construct machine M for L = { w | w ends with a }, where S = { a, b } b a a q0 q1 b After reading a string w, the machine is in state q1 if w ends with a, and in state q0 otherwise In particular, after reading the empty string e, M is in state q0, and thus rejects e

13 Designing Finite Automaton: Example 3
Construct machine M for L = { w | w contains the substring “ACC” }, where S = { A, C, G, T } C, G,T A A,C, G,T A C C q0 q1 q2 q3 G,T A G,T Precisely describe the set of strings w such that the machine is in state q2 after reading w { w | w does not contain the substring “ACC” and ends with “AC” }

14 Designing Finite Automaton: Example 4
Construct machine M for L = { w | count(w,a) = count(w,b) }, where S = { a, b } a a a a q0 q1 q2 q3 q4 String aa leads to q2 and aaa leads to q3. String aabb should be accepted but aaabb should be rejected. So states q2 and q3 have to be distinct (otherwise M cannot possibly make the correct decision if what follows is string “bb”). By similar logic, all the states q1, q2, q3, q4, … have to be pairwise distinct. There does not exist a finite-state machine for L. Rigorous proof based on a general technique in a couple of lectures …

15 Designing Finite Automaton: Example 5
Construct machine M for L = { w | decimal number corresponding to w is divisible by 3 }, where S = { 0,1,2,…,9 } 0,3,6,9 0,3,6,9 1,4,7 q0 q1 2,5,8 1,4,7 2,5,8 2,5,8 1,4,7 q2 0,3,6,9

16 Formal Definition A deterministic finite automaton (DFA) 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  Q (if M reads symbol s in state q, the resulting state is d(q, s) )

17 Example Automaton Q = { q0, q1 } S = { a, b } Initial state = q0
F = { q0 } Transition function: d(q0,a) = q1, d(q0,b) = q0, d(q1,a) = q0, d(q1,b) = q1 b b a q0 q1 a

18 Language of a DFA Let M = (Q, S, q0, F, d) be a DFA.
L(M) = The set of strings w over S such that M accepts w Let us capture acceptance using a more mathematical notation that will be useful later in some proofs and constructions

19 Extended Transition Function
Let M = (Q, S, q0, F, d) be a DFA. d is one-step transition function: Maps a state and a single symbol to a state d(q, s): if machine starting in state q reads the single symbol s, where will it be d* : multi-step transition function (reflexive-transitive closure of d) Maps a state and a string w to a state d*(q,w): if the machine starting in state q processes the entire string w, where will it be ?

20 Definition: Extended Transition Function
How to define d* in terms of d ? Inductive definition based on definition of strings A string w is either the empty string e or is of the form x s, where x is a string (of length one shorter than w) and s is a symbol d*(q, e) = q d*(q, x s) = d ( d* (q, x), s) Basically, first clause says how strings of length 0 are processed and second clause says how strings of length n+1 are processed by relying on processing of strings of length n Exercise: Prove: for all q, for all strings u,v, d*(q, u.v) = d*(d*(q, u), v) q x s

21 Definition: Language of a DFA
Let M = (Q, S, q0, F, d) be a DFA. Definition: M accepts w if d*(q0, w) is in F L(M) = { w | d*(q0, w) is in F } If F = Q, what is L(M) ? The set of all strings: S* If F is the empty set F, what is L(M)? The empty set of strings: F If F = { q0 }, what is L(M)? L(M) contains the empty string e, but can’t say much more


Download ppt "Instructor: Aaron Roth"

Similar presentations


Ads by Google