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.

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Regular Expressions and DFAs COP 3402 (Summer 2014)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
YES-NO machines Finite State Automata as language recognizers.
January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
CS21 Decidability and Tractability
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
1 Languages and Finite Automata or how to talk to machines...
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.1: DFA’s) David Martin With some modifications.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
Topics Automata Theory Grammars and Languages Complexities
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
Theory of Computing Lecture 22 MAS 714 Hartmut Klauck.
Regular Expressions and Automata Chapter 2. Regular Expressions Standard notation for characterizing text sequences Used in all kinds of text processing.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
Great Theoretical Ideas in Computer Science.
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 Chapter 3 Scanning – Theory and Practice. 2 Overview Formal notations for specifying the precise structure of tokens are necessary –Quoted string in.
Cs3102: Theory of Computation Class 4: Nondeterminism Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
REGULAR LANGUAGES.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Theory of Languages and Automata
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Theory of computing, part 3. 1Introduction 2Theoretical background Biochemistry/molecular biology 3Theoretical background computer science 4History of.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CHAPTER 1 Regular Languages
Finite State Machines Concepts DFA NFA.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
using Deterministic Finite Automata & Nondeterministic Finite Automata
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
Finite-State Machines Fundamental Data Structures and Algorithms Peter Lee March 11, 2003.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Lexical Analysis Uses formalism of Regular Languages Uses formalism of Regular Languages Regular Expressions Regular Expressions Deterministic Finite.
Deterministic Finite Automata Nondeterministic Finite Automata.
Lecture #5 Advanced Computation Theory Finite Automata.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lexical analysis Finite Automata
Non Deterministic Automata
CSE 105 theory of computation
Chapter 2 FINITE AUTOMATA.
Principles of Computing – UFCFA3-30-1
4b Lexical analysis Finite Automata
Chapter Five: Nondeterministic Finite Automata
4b Lexical analysis Finite Automata
Lexical Analysis Uses formalism of Regular Languages
Presentation transcript:

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 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 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 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 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 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, , , 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 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 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 DFAs: Example 2 strings over {a,b} with at least 3 a’s 1 a2 a 3+ a 0 a aaa bbb 

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

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

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 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 DFAs: Example 4 Lessons Often useful to have an “error state”. Can swap final/nonfinal status to complement described language.

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 DFAs: Example 5 Lesson DFAs can have a fixed-size “memory”.

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 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 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 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.  (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 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 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 NFAs: Example 1 Lesson Nondeterminism isn’t always useful.

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 NFAs: Example 2 Formal definition: Q= {…,…a,…a  }  = {a,b}  = q 0 = … F= {…a  } Input ab  …{…,…a}{…}{…}  …a {…a  }  …a  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 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 NFAs: Example 3 Lesson Problem decomposition:  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, , , ,, 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 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 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.