1 / 35

Controlling My Office Temperature

Controlling My Office Temperature. ?. In Off. In On. What info represents the current state?. ?. Whether I’m in my office. Timer status. Out Off. Out On. Let’s model when I’m happy with my office temperature. Duncan Hall office thermostats are attached to count-down dial timer.

anevay
Download Presentation

Controlling My Office Temperature

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Controlling My Office Temperature ? In Off In On What info represents the current state? ? • Whether I’m in my office. • Timer status. Out Off Out On 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.

  2. Controlling My Office Temperature Up ? Timeout In Off In On What are the possible actions? Timeout Up ? Error ? Move Move Move Move Up Timeout Out Off Out On Move, Timeout, Up Timeout Up 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.

  3. Controlling My Office Temperature Up ? Timeout In Off In On What state do we start in? Timeout Up ? Error ? • In this example, it’s arbitrary. • At beginning of workday, • I’m out of the office, AND • the A/C is off. Move Move Move Move Up Timeout Out Off Out On Move, Timeout, Up Timeout Up 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.

  4. Controlling My Office Temperature Up Timeout In Off In On Timeout Up Error ? Move Move Move Move Up Timeout Out Off Out On Move, Timeout, Up Timeout Up 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.

  5. Controlling My Office Temperature ? Up Timeout What is the end state for… In Off In On ? Timeout Up Error ? Move Move Move Move Up Timeout Out Off Out On Move, Timeout, Up Timeout Up 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

  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. 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. DFAs: Formal Definition DFA M = (Q, S, d, q0, F) Q = states a finite set S = alphabet a finite set d = transition function a total function in Q S Q q0 = initial/starting state q0 Q F = final states F  Q

  9. DFAs: Example 1 Up Timeout In Off In On Timeout Up Error ? Move Move Move Move Up Timeout Out Off Out On Move, Timeout, Up Timeout Up Let Qme = {In,Out}, Qtimer = {Off,On}. Q = Qme Qtimer {Error} S = {Move, Up, Timeout} d = {(([Out,Off],Move),[In,Off]), …} q0 = [Out,Off] F = {[a,On] | a  Qme}  {[Out,b] | b  Qtimer}

  10. DFAs: Definition Pragmatics DFA definitions are presented via diagrams or tuple notation. The most interesting part is the transitions (d). Defining d effectively defines the states (Q), too. Want an easily understandable presentation of d: • 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. DFAs: Example 2 b b b S 0 a a 1 a a 2 a a 3+ a strings over {a,b} with at least 3 a’s

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

  13. DFAs: Example 3 S 0 1 2 S S strings over {a,b} with length mod 3 = 0

  14. DFAs: Example 3 Lesson ? ? Example uses? 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

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

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

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

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

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

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

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

  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. Nondeterministic Finite Automata “Nondeterminism” implies having a choice. Multiple possible transitions from a state on a given symbol. d(q,a) is a set of states d : Q S 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: d : Q  (S {e})  Pow(Q)

  24. NFAs: Formal Definition NFA M = (Q, S, d, q0, F) Q = states a finite set S = alphabet a finite set d = transition function a total function in Q  (S {e})  Pow(Q) q0 = initial/starting state q0 Q F = final states F  Q

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

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

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

  28. NFAs: Example 2 Formal definition: Q = {…,…a,…aS} S = {a,b} • = q0 = … F = {…aS} State

  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. NFAs: Example 3 0 0s 2 e e 2s e 1 e e 1s 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

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

  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. Transducers (= Mealy Machines) DFA + output on transitions M = (Q, S, D, d, l, q0) Q,S,d,q0 same as in regular DFA. No F: Output is more general than Yes/No acceptance. D = output alphabet • = output mapping l: QSD Output string is of same length as input string. Very simple extension.

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

  35. Example: A Tiny Tokenizer b e b e a e a ab abb abba Sp 1 Sp 2 a e Sp 3 e Sp 4 Sp e S = {a,b,c,Sp} c ca cab c e a e b e Tokens must be separated by Sp. States = All valid prefixes of tokens. All other transitions to an error state.

More Related