Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial.

Similar presentations


Presentation on theme: "1 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial."— Presentation transcript:

1 1 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial timer. –Assume it’s always hot enough to want A/C on when in office. Whether I’m in my office. Timer status. In Off In On Out Off Out On What info represents the current state? ? ?

2 2 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial timer. –Assume it’s always hot enough to want A/C on when in office. I move in/out of my office. I turn timer up. Timer times out. In Off In On Out Off Out On Move Up Timeout ? Error Move, Timeout, Up What are the possible actions? ? ?

3 3 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial timer. –Assume it’s always hot enough to want A/C on when in office. In Off In On Out Off Out On Move Up Timeout ? In this example, it’s arbitrary. At beginning of workday, I’m out of the office, AND the A/C is off. Error Move, Timeout, Up What state do we start in? ? ?

4 4 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial timer. –Assume it’s always hot enough to want A/C on when in office. By the problem definition, I’m happy if I’m out of the office, OR the A/C is on. In Off In On Out Off Out On Move Up Timeout ? Error Move, Timeout, Up

5 5 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial timer. –Assume it’s always hot enough to want A/C on when in office. Input 1, a typical workday: Move, Up, Timeout, Up, Move, Timeout, Move, Up Input 2, “arbitrary”: Move, Move, Timeout, Up, Up In Off In On Out Off Out On Move Up Timeout ? Error Move, Timeout, Up What is the end state for… ? ?

6 6 Deterministic Finite Automata Controllers like this are common examples of deterministic finite automata (DFAs). Example of machines, describing a relatively simple form of computation.

7 7 DFAs as Programming Defining a DFA is a kind of programming. Problem definition –Includes defining possible actions & accepting condition. States  structure of program –Includes designating which are initial, which final. Transitions  program Learn programming techniques by example & by theory.

8 8 DFAs: Formal Definition DFA M = (Q, , , q 0, F) Q= statesa finite set  = alphabeta finite set  = transition functiona total function in Q    Q q 0 = initial/starting stateq 0  Q F= final statesF  Q

9 9 DFAs: Example 1 Let Q me = {In,Out}, Q timer = {Off,On}. Q= Q me  Q timer  {Error}  = {Move, Up, Timeout}  = {(([Out,Off],Move),[In,Off]), …} q 0 = [Out,Off] F= {[a,On] | a  Q me }  {[Out,b] | b  Q timer } In Off In On Out Off Out On Move Up Timeout ? Error Move, Timeout, Up

10 10 DFAs: Definition Pragmatics DFA definitions are presented via diagrams or tuple notation. The most interesting part is the transitions (  ). Defining  effectively defines the states (Q), too. Want an easily understandable presentation of  : –It’s easy to accidentally omit info in diagrams. –Small examples: usually show as a table or diagram. –Large examples: usually show as quantified equations.

11 11 DFAs: Example 2 strings over {a,b} with at least 3 a’s 1 a2 a 3+ a 0 a aaa bbb 

12 12 DFAs: Example 2 Lessons DFAs can count or recognize up to a fixed number. Useful to name states mnemonically.

13 13 DFAs: Example 3 strings over {a,b} with length mod 3 = 0 12 0  

14 14 DFAs: Example 3 Lesson DFAs can count or recognize up to a fixed number. –Can combine with modular counting. –Can combine with approximation, e.g., 0, 1, 2, 3, many. A few: error-checking and -correcting codes, including parity length of grocery store lines # of cars waiting at traffic light elevator floor counter ? Example uses? ?

15 15 DFAs: Example 4 strings over {a,b} without 3 consecutive a’s A simple example of “strings not of the form …”. 1 a2 a Has aaa 0 a aaa b b b 

16 16 DFAs: Example 4 Lessons Often useful to have an “error state”. Can swap final/nonfinal status to complement described language.

17 17 DFAs: Example 5 strings over {a,b} with next-to-last symbol = a …aa…ab a …ba…bb  a b b a b b b a a a a a b b b

18 18 DFAs: Example 5 Lesson DFAs can have a fixed-size “memory”.

19 19 DFAs: Acceptance Early letters used for symbol meta-variables. Later letters used for string meta-variables. Defined inductively on length of string: (q,  ) = q (q,aw) = (  (q,a),w)  q  Q,  a  ,  w   * Definition of DFA acceptance: DFA M accepts x   path labeled x, from initial state to some final state: DFA (Q, , ,q 0,F) accepts x  (q 0,x)  F. Most easily defined using : Q   *  Q Set of all strings over alphabet. Must use all of x.

20 20 DFAs: A Property of Base case, |x| = 0: By induction on length of x: adjacency represents concatenation of strings Prove (q,xy) = ( (q,x),y).  q  Q,  x,y  * x = , and xy = y.Definition of empty string (q,x) = qDefinition of = ( (q,x),y)Plugging in q= (q,x) Conclusion holds. (q,xy) = (q,y)Pluging in x= 

21 21 DFAs: A Property of By induction on length of x: Inductive case, |x| = n+1: Prove (q,xy) = ( (q,x),y).  q  Q,  x,y  * x = aw, for some a  and w  *. |w| = n. = (  (q,a),wy)Definition of = ( (  (q,a),w),y)Induction (q,xy) = (q,awy)Plugging in x=aw = ( (q,aw),y)Definition of Conclusion holds.

22 22 DFAs: Additional Notes These DFAs are not the only solutions to these problems. Just like computer programs are not unique solutions. Illustrated the most straightforward solutions. These DFAs only accept or reject. Most real-world uses rely on having output. Will look other kinds later.

23 23 Nondeterministic Finite Automata “Nondeterminism” implies having a choice. Multiple possible transitions from a state on a given symbol.  (q,a) is a set of states  : Q    Pow(Q) Can be empty, so no need for error/nonsense state. Acceptance: exist path to a final state? I.e., try all choices. Often used with different view of computation: Guess result (path taken), and check if possible with given input. Also allow transitions on no input:  : Q  (   {  })  Pow(Q)

24 24 NFAs: Formal Definition NFA M = (Q, , , q 0, F) Q= statesa finite set  = alphabeta finite set  = transition functiona total function in Q  (   {  })  Pow(Q) q 0 = initial/starting stateq 0  Q F= final statesF  Q

25 25 NFAs: Example 1 strings over {a,b} with at least 3 a’s 1 a2 a 3+ a 0 a aaa bbb  Same as the DFA for this problem.

26 26 NFAs: Example 1 Lesson Nondeterminism isn’t always useful.

27 27 NFAs: Example 2 strings over {a,b} with next-to-last symbol = a Loop until we “guess” which is the next-to-last a. a   …a  …a …

28 28 NFAs: Example 2 Formal definition: Q= {…,…a,…a  }  = {a,b}  = q 0 = … F= {…a  } Input ab  …{…,…a}{…}{…}  …a {…a  }  …a  State

29 29 NFAs: Example 2 Lessons Some problems can be solved by a much simpler NFA than DFA. NFAs don’t need a transition from every state for each input.

30 30 NFAs: Example 3 strings over {0,1,2} having (either 0-or-more 0’s or 0-or-more 1’s) followed by 0-or-more 2’s  0  2s2s 1 2    0s0s 1s1s

31 31 NFAs: Example 3 Lesson Problem decomposition:  transitions can separate subparts of NFA into easy chunks.

32 32 DFAs with Output Have seen FAs with Yes/No output. –Convenient for theory. –Practical uses include Parity checking Error detection Single-bit control signal generation Pattern matching Circuit verification Pragmatically, often want more general output. Multi-bit control signal generation Tokenization of input for parsing Pattern matching with grep -like output Circuits for bit-wise operations Communicating automata Communication protocols

33 33 Transducers (= Mealy Machines) DFA + output on transitions M = (Q, , , ,, q 0 ) Q, , ,q 0 same as in regular DFA. No F: Output is more general than Yes/No acceptance.  = output alphabet = output mapping : Q    Output string is of same length as input string. Very simple extension.

34 34 Many Variations Possible Moore machines DFA + output on states : Q   Mealy outputs |x| symbols – each transition. Moore outputs |x|+1 symbols – each state. More flexible output –Output comes from  {  } or  *. –As in upcoming example. Output can represent external action. –E.g., Increment_Counter. –Action not seen by FA.

35 35 Example: A Tiny Tokenizer InputToken a1 ab2 abba3 cab4 States = All valid prefixes of tokens. All other transitions to an error state.  aababb ccacab abba a  b  a  c  a  b  Sp 4 Sp 3 Sp 2 Sp 1 Sp   = {a,b,c,Sp} Tokens must be separated by Sp.


Download ppt "1 Controlling My Office Temperature Let’s model when I’m happy with my office temperature. –Duncan Hall office thermostats are attached to count-down dial."

Similar presentations


Ads by Google