CMPS 3223 Theory of Computation

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

CMPS 3223 Theory of Computation
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.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Finite Automata with Output
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
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 Lecture3: Regular Expressions Prof. Amos Israeli.
1 Languages and Finite Automata or how to talk to machines...
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.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided.
Finite State Machines Chapter 5. Languages and Machines.
Deterministic Finite State Machines Chapter 5. Languages and Machines 2.
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
TM Design Universal TM MA/CSSE 474 Theory of Computation.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
MA/CSSE 474 Theory of Computation DFSM Canonical Form Proof of NDFSM  DFSM ALGORITHM (as much as we have time for) This version includes the "answers"
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
Pushdown Automata Part I: PDAs Chapter Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2)
MA/CSSE 474 Theory of Computation Decision Problems DFSMs.
Turing Machines Chapter 17. Languages and Machines SD D Context-Free Languages Regular Languages reg exps FSMs cfgs PDAs unrestricted grammars Turing.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
Copyright © Curt Hill Finite State Automata Again This Time No Output.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
MA/CSSE 474 Theory of Computation Minimizing DFSMs.
Computing Machinery Chapter 4: Finite State Machines.
Modeling Computation: Finite State Machines without Output
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Lecture 16: Modeling Computation Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output.
Lecture Notes 
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Nondeterministic Finite State Machines Chapter 5.
Finite State Machines Chapter 5. Languages and Machines.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
Lecture 14: Theory of Automata:2014 Finite Automata with Output.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Theory of Computation Automata Theory Dr. Ayman Srour.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Lexical analysis Finite Automata
Properties of Regular Languages
Chapter 2 Finite Automata
Pushdown Automata.
Deterministic Finite Automata
Deterministic Finite Automata
Hierarchy of languages
Turing Machines Chapter 17.
4b Lexical analysis Finite Automata
Chapter Five: Nondeterministic Finite Automata
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation
4b Lexical analysis Finite Automata
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation Nondeterminism NFSMs.
NFAs and Transition Graphs
More About Nondeterminism
What is it? The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled.
Presentation transcript:

CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for use by MSU Department of Computer Science – R. Halverson

Finite State Machines & Regular Languages Chapter 5A Pages 54-71

Homework for 5A Page 121+ Exercises 1 – 6 (all parts) #2 – may need to develop non-deterministic first #6 – can be deterministic or non-deterministic More will be assigned in 5B.

Languages and Machines

Regular Languages Regular Language Regular Expression Regular Grammar Defines Regular Expression Accepts Regular Grammar Finite State Machine

Finite State Machine (FSM) Non-technical definition Computational device having a string as input and having one of 2 possible outputs – Accept or Reject

Finite State Machine (FSM) Non-technical Description of Operation There is a designated Start state Reads 1 character at a time, left to right (Current State, Character)  New State Repeat Stop when no more characters OR no defined New State Every state is designated as either an Accepting or Rejecting state Ending state designation determines if string is Accepted or Rejected

Example Finite State Machine Incoming arrow indicates start state Double Circles  Accepting state Single Circles  Rejecting state Note: time required <= |string|

Finite State Machine Example Drinks in a machine cost 25¢ Accepts Nickels, Dimes, Quarters only Insert coins, push “Soda” button, drink is dispensed if “Enough Money” LANGUAGE: String of coin sequences adding to 25¢ (or more) allowing drink to be dispensed {Q,DDN, NNND, DNNN,DND, etc…} Actually, S can be inserted within any string What about extra money (change)? Look at one final product!

FSM for Drink Machine An FSM to accept $.25 in change for a drink Note that states are “labeled” for clarity Machine has ERRORS!! Can you find them?? But you get the idea! Should there be a “50” state? Why or why not?

Formal Definition of a DFSM MEMORIZE!!! Deterministic Finite State Machine (DFSM) is M: M = (K, , , s, A), where: K is a finite set of states  is an alphabet s  K is the initial state A  K is the set of accepting states, and  is the transition function from (K  ) to K *The set of ALL strings accepted by M form the Language defined by the DFSM.

Configurations of DFSMs A Configuration of a DFSM M is an element of K  * Configuration captures the two things that make a difference to M’s future behavior: • its current state • the input that remains to be read. The Initial Configuration of a DFSM M, on input w, is (sM, w) , where sM is start state of M

Transition Function -  Defines the DFSM, one state at a time  is set of all pairs of states in M & characters in ∑ (Current State, Current Character)  New State Note: we often reduce the set  to those pairs that are “useful” or to only those that can lead to an Accepting state

Complete vs. Incomplete FSM A transition is defined for every possible state and every possible character in the alphabet Note: Can cause FSM to be larger than necessary, but ALWAYS processes the entire string Incomplete FSM One which defines a transition for every possible state & every possible character in the alphabet which can lead to an accepting state Note: If no transition is defined, the string is Rejected

Complete vs. Incomplete Example ∑ = {a, b, c} L = {strings beginning with c & followed by only a’s & b’s, at least 1} C a S q1 b

The Yields Relations The yields-in-one-step relation |-M (q, w) |-M (q', w') iff • w = a w' for some symbol a  , and •  (q, a) = q' |-M * is the reflexive, transitive closure of |-M. Transitions defined by processing ONE character M refers to the particular machine, so can leave it off, usually.

Computations Using FSMs A Computation by M is a finite sequence of configurations C0, C1, …, Cn for some n  0 such that: *C0 is an initial configuration, *Cn is of the form (q, ), for some state q  KM  indicates empty string, entire string is processed & implies a complete DFSM *C0 |-M C1 |-M C2 |-M … |-M Cn. However, M Halts when the last character has be processed or a next transition is not defined

Accepting and Rejecting A DFSM M Accepts a string w iff (s, w) |-M * (q, ), for some q  AM. A DFSM M Rejects a string w iff (s, w) |-M* (q, ), for some q  AM. The language accepted by M, denoted L(M), is the set of all strings accepted by M. Theorem: Every DFSM M, on input s, halts in |s| steps.

Example Language L = {x | x is an odd integer} Is 3456 L? How will we develop a machine to answer the question? Process characters left to right Assume the current character is the LAST character What are the necessary states?

An Example Computation An FSM to accept odd integers: even odd even q0 q1 odd On input 235, the configurations are: (q0, 235) |- (q0, 35) (q0, 35) |- (q1, 5) (q1, 5) |- (q1,  ) Accept Thus (q0, 235) |-* (q1, ) [* means 0 or more steps]

Developing a DFSM Heuristic – a generality, a recommendation List or Label the possible states of a machine based upon the language or problem definition Determine the transitions between the states

Developing DFSM Examples L = {x | x contains an even number of a’s} What would the states of the DFSM be? What would the transitions be? L = {x | x contains an even number of a’s & odd number of b’s}

Even a’s Odd b’s Let L = {w  {a, b}* : w contains an even number of a’s and an odd number of b’s}

5.2 - 5.3 Regular Languages A language is regular iff it is accepted by some FSM. We have defined several regular languages…

Regular Examples L = {w  {a,b}*| every region of a’s is of even length} L = {w  {a,b}*| w contains at most 1 b } L = {w  {a,b}*| no 2 consecutive characters are the same } L = {w  {a,b}*| anbn, n>=1}

A Very Simple Example followed by a b}. The Existence Problem L = {w  {a, b}* | every a is immediately followed by a b}. The Existence Problem Does the definition imply the existence of any characters? Is the empty string a member of the language?

Parity Checking Example L = {w  {0, 1}* : w has odd parity}. Complete or incomplete DFSM?

No More Than One b L = {w  {a, b}* : w contains no more than 1 b} Complete or incomplete DFSM?

Error States or Dead States An Error State or Dead State is a rejecting state from which the string can never go back to an Accepting State. Some DFSM can have, others cannot!

Error States or Dead States ∑ = {a, b, c} L = {strings beginning with c & followed by only a’s & b’s, at least 1} C a S q1 a,b b d a, b

Checking Consecutive Characters L = {w  {a, b}*| no two consecutive characters are the same}. ERROR – d is not an accepting state d is Dead State; once in that state string cannot be accepted.

DFSM Example L = {w  {a, b}* : every a region in w is of even length} d is a Dead State – Can Be Removed!

The Language of Floating Point Numbers is Regular Example strings: +3.0, 3.0, 0.3E1, 0.3E+1, -0.3E+1, -3E8 The language is accepted by the DFSM:

A Simple Communication Protocol

Controlling a Soccer-Playing Robot

A Simple Controller

Vowels in Alphabetical Order L = {w  {a - z}* : all five vowels, a, e, i, o, and u, occur in w in alphabetical order}.

Developing FSMs Sometimes, it is “easier” to develop the FSM for the complement of the language, then reverse the Accept & Reject states Do you believe this would work??? L = {w  {a, b}* : w does not contain the substring aab}. Start by building an FSM for not L. Then swap accepting and nonaccepting states. Note that this foreshadows the claim that we will make later that the regular languages are closed under complement.

Complement of FSMs L = {w  {a, b}* : w does not contain the substring aab}. Start with a machine for L How must it be changed?

A Building Security System L = {event sequences such that the alarm should sound}

FSMs Predate Computers The Prague Orloj, originally built in 1410.

The Abacus

The Missing Letter Language Let  = {a, b, c, d}. Let LMissing = {w : there is a symbol ai   not appearing in w}. Try to make a DFSM for Lmissing First develop machine for set of strings containing ALL 4 characters, then reverse. Try it deterministically.

5.4 Definition of an NDFSM A Non-deterministic Finite State Machine Memorize A Non-deterministic Finite State Machine M = (K, , , s, A), where: K is a finite set of states  is an alphabet s  K is the initial state A  K is the set of accepting states,  is the transition relation, a finite subset of (K  (  {})) to K Non-deterministic if there is at least one state from which there are 2 or more transitions defined for a single character.

NDFSM Example

*NDFSM – Accepting a String A NDFSM M accepts a string w iff there exists some path along which w drives M to some Accepting state. The language accepted by M, denoted L(M), is the set of all strings accepted by M. NOTE: significant difference between deterministic & non-deterministic

*NDFSM – Rejecting a String A NDFSM M rejects a string w iff all paths along which w drives M lead to an Rejecting state. NOTE: significant difference between deterministic & non-deterministic

DFSM vs. NDFSM Time Complexity of determining accept/reject for string w DFSM – O(n) where n = |w| NDFSM – O(X) where X = ???? X stated in terms of what?? How does complete vs. incomplete machine affect time?

NDFSM Time Complexity Given a string w with |w| = 2, how many possible paths to determine accept or reject? What if |w| is larger? What if the FSM gets larger?

Epsilon () Transitions An Epsilon () Transition Is one that does not consume a character of the input string. Allows movement from one state to another without consuming a character of the input string. 

Sources of Non-determinism 2 Types Epsilon transition 2+ transitions for a single character Which path should be taken???

Use of Epsilon Transitions Optional Substrings L = {w  {a, b}* : w is made up of an optional a followed by aa followed by zero or more b’s} L = {aa, aaa, aab, aaab, aabb, aaabb, … }

Use of Epsilon Transitions Multiple Sublanguages L = {w  {a, b}* : w = aba or |w| is even}

Pattern Matching L = {w  {a, b, c}* : x, y  {a, b, c}* (w = x abcabb y)}. An NDFSM: But how do you know when to take the a-transition to q1? Strategically, First time, take it on first a, Second time, take it on second a, etc… Until all a’s are exhausted or you accept the string.

NDFSM to DFSM Try again –develop a Deterministic Machine There is an algorithm that allows you to convert NDFSM to DFSM ** but more on that later

Pattern Matching L = {w  {a, b, c}* : x, y  {a, b, c}* (w = x abcabb y)}. A DFSM:

Multiple Keywords L = {w  {a, b}* : x, y  {a, b}* (w = x abbaa y or w = x baba y)}.

Checking from the End L = {w  {a, b}* : the fourth to the last character is a} Try it with aabaaa.

Another Pattern Matching Example L = {w  {0, 1}* : w is the binary encoding of a positive integer that is divisible by 16 or is odd} How can you rewrite as a string problem?

Another Pattern Matching Example L = {w  {0, 1}* : w is the binary encoding of a positive integer that is (1) divisible by 16, or (2) is odd} How can you rewrite as a string problem? 5th character from end is a 1 last character is 1

Another NDFSM Do for Homework! L1= {w  {a, b}*: aa occurs in w} L2= {x  {a, b}*: bb occurs in x} L3= {y :  L1 or L2 } M1 = M2= M3=

Analyzing Nondeterministic FSMs Does this FSM accept: baaba Remember: we just have to find one accepting path.

Homework for 5A Pages 53-71 Page 121+ Exercises 1 – 6 (all parts) #2 – may need to develop non-deterministic first #6 – can be deterministic or non-deterministic More will be assigned in 5B.