Upcoming SlideShare
×

# Theory of Computation: Deterministic Finite Automata (DFA), Finite Automaton for Robotic Camera & Arm, DFA Transition Functions, Regular Languages, DFA Problems, DFAs in Java

1,237
-1

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
1,237
On Slideshare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
34
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Theory of Computation: Deterministic Finite Automata (DFA), Finite Automaton for Robotic Camera & Arm, DFA Transition Functions, Regular Languages, DFA Problems, DFAs in Java

1. 1. Theory of Computation Deterministic Finite Automata Vladimir Kulyukin www.vkedco.blogspot.com
2. 2. Outline ● Blocks World Problem: A DFA for a Robotic Camera & Arm ● How DFAs Work ● DFA Transition Function ● Formal Languages Accepted by DFAs ● Sample DFA Problems ● Sample DFA Implementation www.vkedco.blogspot.com
3. 3. Outline ● Deterministic Finite Automata (DFA) ● How DFAs Work ● DFA Transition Function ● Formal Languages Accepted by DFAs ● Sample DFA Problems ● Sample DFA Implementation www.vkedco.blogspot.com
4. 4. Blocks World Problem www.vkedco.blogspot.com
5. 5. A B Suppose we want to design a control system for a robotic camera & arm unit that should build two-block towers: a on b or b on a. Blocks World Problem www.vkedco.blogspot.com
6. 6. A B Goal State 01: A on B www.vkedco.blogspot.com
7. 7. B A Goal State 02: B on A www.vkedco.blogspot.com
8. 8. Robotic Arm & Camera Operations • puton(X, Y) – put A on top of Y • clear(X) – verify that X's top is clear • on(X, Y) – verify that X is on top of Y www.vkedco.blogspot.com
9. 9. Finite Automaton for Blocks World Problem on(A, T) on(B, T) clear(A) clear(B) on(A, B) on(B, T) clear(A) on(B, A) on(A, T) clear(B) puton(A, B) puton(A, T) puton(B, A) puton(B, T) www.vkedco.blogspot.com
10. 10. Back to Automata & Languages www.vkedco.blogspot.com
11. 11. Deterministic Finite Automata • A DFA can be informally defined as a directed graph whose nodes are states and whose edges are transitions on specific symbols • A DFA has a unique start state and a set (possibly empty) of final or accepting states • A DFA processes the input string one symbol at a time. When the last symbol is read, the DFA reaches a state which is either final or not. If the state is final, the DFA accepts (recognizes) the string. If the state is not final, the DFA rejects the string www.vkedco.blogspot.com
12. 12. DFA: Formal Definition ( ) states.(final)acceptingofsettheis state;starttheis ;:function;ntransitioais alphabet;anis states;ofsetfiniteais :where ,,,,,i.e.tuple,-5aisDFAA 0 0 F Qq QQ Q FqQMM ∈ →Σ× Σ Σ= δδ δ www.vkedco.blogspot.com
13. 13. Example 1: DFA M q1q0 a b b a q0 is the start state. q1 is the final state. www.vkedco.blogspot.com
14. 14. Example 1: DFA M ( ) { } { } { } ( ) ( ) ( ) ( ) 01 100010 1 10 0 , ;,;,;,.4 ;.3 ;,.2 ;,1. where,,,,, qbq qaqqbqqaq qF ba qqQ FqQM = === = =Σ = Σ= δ δδδ δ www.vkedco.blogspot.com
15. 15. How DFAs Work www.vkedco.blogspot.com
16. 16. Example: DFA M a b q0 q1 q0 q1 q1 q0 The transition function, δ, can be represented as a table: www.vkedco.blogspot.com
17. 17. How DFA M Works q0 b a a b a www.vkedco.blogspot.com
18. 18. How DFA M Works q0 b a a b a www.vkedco.blogspot.com
19. 19. How DFA M Works q1 b a a b a www.vkedco.blogspot.com
20. 20. How DFA M Works q1 b a a b a
21. 21. How DFA M Works q0 b a a b a www.vkedco.blogspot.com
22. 22. How DFA M Works q1 b a a b a www.vkedco.blogspot.com
23. 23. How DFA M Works q1 b a a b a ecognizedaccepted/risThus, baaba www.vkedco.blogspot.com
24. 24. Observations on DFA Definition ● Q may not be empty: a DFA must have at least one state, i.e., the start state ● δ is a function, i.e., it must be for every state in Q and every symbol in Σ ● F may be empty, in which case the DFA accepts the empty language ● F can be equal to Q, in which case the DFA accepts Σ* www.vkedco.blogspot.com
25. 25. δ* :DFA Transition Function www.vkedco.blogspot.com
26. 26. The δ* Function ( ) ( ) ( )( )axqxaq qq ,,,.2 ;,.1 :statestostringsmaps ** * * δδδ εδ δ = = www.vkedco.blogspot.com
27. 27. Back to Example DFA M ( ) ( )( ) ( )( )( ) ( )( )( )( ) ( )( )( ) ( )( ) ( ) Fqaqabq abbqabbq abbqabbqbbaq bba ∈== == === 100 00 * 0 * 0 * 0 * ,,, ,,,,,,, ,,,,,, accepted?itIs.isinputtheSuppose δδδ δδδεδδδδ δδδδδδ www.vkedco.blogspot.com
28. 28. Languages Accepted by DFAs www.vkedco.blogspot.com
29. 29. DFA String Acceptance ( ) ( ) FxqFqQM x ∈Σ= Σ∈ ,ifonlyandif,,,, DFAabyecognizedaccepted/risstringA 0 * 0 * δδ www.vkedco.blogspot.com
30. 30. DFA’s Language: L(M) ( ) ( ) ( ){ }.,|Then .,,,,such thatDFAabeLet 0 ** 0 FxqxML FqQMM ∈Σ∈= Σ= δ δ www.vkedco.blogspot.com
31. 31. Regular Languages A language L is regular if and only if there exits a DFA M such that L(M) = L. www.vkedco.blogspot.com
32. 32. Sample DFA Problems www.vkedco.blogspot.com
33. 33. Typical DFA Problems ● Given a DFA M and a set of strings, determine which strings are in the language of M, i.e. L(M)? ● Given a DFA M, state in the set former notation, state L(M)? ● Draw a DFA diagram given the formal definition of the DFA www.vkedco.blogspot.com
34. 34. Problem 01 q0 q1 a a b Which of the following strings are in L(M)? 1. b 2. ε 3. ab 4. abba 5. ababaaaaba b www.vkedco.blogspot.com
35. 35. Solution 01 ( ) ( ) ( ) ( )( ) ( ) ( ) ( ) ( )( ) ( )( )( ) ( )( )( )( ) ( )( )( ) ( )( ) ( ) ( ) Fqababaaaabaq Fqaqabqabbq abbaq ababq aabbqabbaq MLab Fqbqbaqabq ML MLb ∈= ∉=== = = == ∈ ∈=== ∉ ∉ 10 * 0111 0 * 0 * 0 * 0 * 110 * 0 * ,.5 ,,,,,, ,,,, ,,, ,,,.4 So,.,,,,.3 .2 .1 δ δδδδδδ δδδδ δδδ δδδ δδδδ ε www.vkedco.blogspot.com
36. 36. Problem 02 q0 q1 a,b a,b What is the language accepted by this DFA M? www.vkedco.blogspot.com
37. 37. Solution 02 { } ( ) { }{ }.,12and,| :answerFormal odd.islengthwhose,overstringsAll :answerInformal * NnnxbaxxML ba ∈+=∈= www.vkedco.blogspot.com
38. 38. Problem 03 q0 q1 b a a b What is the language accepted by this DFA M? www.vkedco.blogspot.com
39. 39. Solution 03 { } ( ) { }{ }* ,and| :answerFormal inendthat,overstringsAll :answerInformal bayyaxxML aba ∈== www.vkedco.blogspot.com
40. 40. Problem 04 { }{ } { }{ }oddisins'ofnumber|,.2 ,|1. :itacceptsthat DFAadrawlanguages,followingtheofeachFor * * xabax baxx ∈ ∈ www.vkedco.blogspot.com
41. 41. Solution 04.1 q0 a,b www.vkedco.blogspot.com
42. 42. Solution 04.2 q0 q1 b b a a www.vkedco.blogspot.com
43. 43. Problem 05 { } { } { }( ) ( ) ( ) ( ) ( ) 01 01 10 10 1010 , ;, ;, ;, ,,,,,,, :DFAthisDraw qbq qaq qbq qaq qqbaqq = = = = δ δ δ δ δ www.vkedco.blogspot.com
44. 44. Solution 05 q0 q1 a,b a,b www.vkedco.blogspot.com
45. 45. Sample DFA Implementation www.vkedco.blogspot.com
46. 46. A DFA: Odd Numbers of Zeros q0 q1 0 0 www.vkedco.blogspot.com
47. 47. Java Implementation: Part 1 import java.io.*; public class OddNumZeros {    private static final int q0 = 0;    private static final int q1 = 1;    private static final int q2 = 2; // this is the sink    private int state; // current state … } www.vkedco.blogspot.com
48. 48. Java Implementation: Part 2 static private int delta(int s, char c) {        switch (s) {            case q0: switch (c) {                case '0': return q1;                default: return q2; // go to the sink            }            case q1: switch (c) {                case '0': return q0;                default: return q2; // go to the sink            }            default: return q2; // go to the sink        } } www.vkedco.blogspot.com
49. 49. Java Implementation: Part 3 public void deltaStar(String instr) {        char c;        for(int i = 0; i < instr.length(); i++) {            c = instr.charAt(i);            state = delta(state, c);        }    }    public boolean isInputAccepted() {        return state == q1;    } www.vkedco.blogspot.com
50. 50. Java Implementation: Part 4 public void reset() { state = q0; } public static void main(String[] args) throws IOException {        OddNumZeros dfa = new OddNumZeros();        BufferedReader in =                new BufferedReader(new InputStreamReader(System.in));        String instr = in.readLine();        while ( instr != null )        {            dfa.reset();            dfa.deltaStar(instr);            if ( dfa.isInputAccepted() ) {                System.out.println(instr + " accepted");            }            else {                System.out.println(instr + " rejected");            }            instr = in.readLine();        } } www.vkedco.blogspot.com
51. 51. References & Reading Suggestions ● A. Brooks Weber. Ch. 2 Formal Language: A Practical Introduction, Franklin, Beedle & Associates, Inc ● Davis, Weyuker, Sigal. Ch. 9. Computability, Complexity, and Languages, 2nd Edition, Academic Press www.vkedco.blogspot.com