Formal Definition of Computation. Formal Definition of Computation p.1/28

Similar documents
Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Implementation of Lexical Analysis

Implementation of Lexical Analysis

Implementation of Lexical Analysis

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

CSE450. Translation of Programming Languages. Automata, Simple Language Design Principles

Theory of Computation Prof. Raghunath Tewari Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

Implementation of Lexical Analysis. Lecture 4

Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

6 NFA and Regular Expressions

CS2 Practical 2 CS2Ah

Theory of Computation

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

3.15: Applications of Finite Automata and Regular Expressions. Representing Character Sets and Files

Lecture 2 Finite Automata

Dr. D.M. Akbar Hussain

Midterm I (Solutions) CS164, Spring 2002

Introduction to Lexical Analysis

lec3:nondeterministic finite state automata

Lexical Analysis. Chapter 2

Lexical Error Recovery

Lexical Analysis. Implementation: Finite Automata

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Computer Sciences Department

Theory of Languages and Automata

Lexical Analysis. Finite Automata. (Part 2 of 2)

Alternation. Kleene Closure. Definition of Regular Expressions

Introduction to Lexing and Parsing

Lexical Analysis. Lecture 2-4

Applications of Finite State Machines

Implementation of Lexical Analysis

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

Equivalence of NTMs and TMs

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

CT32 COMPUTER NETWORKS DEC 2015

CS21 Decidability and Tractability

Formal languages and computation models

Regular Expression Constrained Sequence Alignment

Context Free Grammars. CS154 Chris Pollett Mar 1, 2006.

Kinder, Gentler Nation

Lexical Error Recovery

Introduction to Computers & Programming

Model checking pushdown systems

CS2 Language Processing note 3

Theory of Computation, Homework 3 Sample Solution

Turing Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject.

Implementation of Lexical Analysis

Implementation of Lexical Analysis

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

Definition 2.8: A CFG is in Chomsky normal form if every rule. only appear on the left-hand side, we allow the rule S ǫ.

Solutions to Homework 10

Optimizing Finite Automata

Lexical Analysis. Lecture 3-4

Informatics 1 - Computation & Logic: Tutorial 5

Theory of Computations Spring 2016 Practice Final Exam Solutions

1.7 Limit of a Function

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

Enumerations and Turing Machines

1 Parsing (25 pts, 5 each)

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 5

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

Formal Languages and Compilers Lecture VI: Lexical Analysis

Automating Construction of Lexers

6.045J/18.400J: Automata, Computability and Complexity. Practice Quiz 2

Formal Languages and Automata

Material from Recitation 1

Modeling of Finite State Machines. Debdeep Mukhopadhyay

A Scanner should create a token stream from the source code. Here are 4 ways to do this:

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

ECS 120 Lesson 16 Turing Machines, Pt. 2

Converting a DFA to a Regular Expression JP

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Finite Automata and Scanners

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

CISC 4090 Theory of Computation

Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

Variants of Turing Machines

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

UNIT -2 LEXICAL ANALYSIS

CS52 - Assignment 10

Introduction to Parsing. Lecture 5

The Language for Specifying Lexical Analyzer

Compiler phases. Non-tokens

Chapter 14: Pushdown Automata

CSc 453 Lexical Analysis (Scanning)

Front End: Lexical Analysis. The Structure of a Compiler

14.1 Encoding for different models of computation

Rational subsets in HNN-extensions

Recursively Enumerable Languages, Turing Machines, and Decidability

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console

CS402 - Theory of Automata FAQs By

Multiple Choice Questions

Error-Correcting Codes

Transcription:

Formal Definition of Computation Formal Definition of Computation p.1/28

Computation model The model of computation considered so far is the work performed by a finite automaton Formal Definition of Computation p.2/28

Computation model The model of computation considered so far is the work performed by a finite automaton Finite automata were described informally, using state diagrams, and formally, as a 5-tuple Formal Definition of Computation p.2/28

Computation model The model of computation considered so far is the work performed by a finite automaton Finite automata were described informally, using state diagrams, and formally, as a 5-tuple Informal description is easier to grasp first, but the formal definition is useful for making this notion precise, resolving any ambiguities that may occur in formal description Formal Definition of Computation p.2/28

Formal definition of computation Let be a finite automaton and be a string over Formal Definition of Computation p.3/28

Formal definition of computation Let Then exist in be a finite automaton and be a string over accepts if a sequence of states such that the following hold: Formal Definition of Computation p.3/28

Formal definition of computation Let Then exist in 1. be a finite automaton and be a string over accepts if a sequence of states such that the following hold: Formal Definition of Computation p.3/28

Formal definition of computation Let Then exist in 1. be a finite automaton and be a string over accepts if a sequence of states such that the following hold: 2. for Formal Definition of Computation p.3/28

Formal definition of computation Let Then exist in 1. be a finite automaton and be a string over accepts if a sequence of states such that the following hold: 2. for 3. Formal Definition of Computation p.3/28

Interpretation Condition (1) says that the machine starts its computation in the start state Formal Definition of Computation p.4/28

Interpretation Condition (1) says that the machine starts its computation in the start state Condition (2) says that as long as input is available the machine goes from state to state according to its transition function Formal Definition of Computation p.4/28

Interpretation Condition (1) says that the machine starts its computation in the start state Condition (2) says that as long as input is available the machine goes from state to state according to its transition function Condition (3) says that the machine accepts its input if it ends up in an accept state Formal Definition of Computation p.4/28

Interpretation Condition (1) says that the machine starts its computation in the start state Condition (2) says that as long as input is available the machine goes from state to state according to its transition function Condition (3) says that the machine accepts its input if it ends up in an accept state Can you translate this interpretation into the computation performed by a program? Formal Definition of Computation p.4/28

Translation A program behaves like a finite automaton: Formal Definition of Computation p.5/28

Translation A program behaves like a finite automaton: Its start state is a function mapping program variables to their initial values Formal Definition of Computation p.5/28

Translation A program behaves like a finite automaton: Its start state is a function mapping program variables to their initial values Program execution goes from state to state by transitions performed according to program control flow Formal Definition of Computation p.5/28

Translation A program behaves like a finite automaton: Its start state is a function mapping program variables to their initial values Program execution goes from state to state by transitions performed according to program control flow The language of this machine is the class of problems solved by program execution Formal Definition of Computation p.5/28

Difference A program computation differs from FA computation because: Formal Definition of Computation p.6/28

Difference A program computation differs from FA computation because: A program may have a potential infinite set of states and can run forever Formal Definition of Computation p.6/28

Difference A program computation differs from FA computation because: A program may have a potential infinite set of states and can run forever During execution a program may interact with its environment Formal Definition of Computation p.6/28

Difference A program computation differs from FA computation because: A program may have a potential infinite set of states and can run forever During execution a program may interact with its environment The accepting state of the program has a larger interpretation Formal Definition of Computation p.6/28

Note We say that a machine recognizes the language if How is this interpreted in terms of a program execution? Formal Definition of Computation p.7/28

Regular language Definition 1.7 A language is called a regular language if some finite automaton recognizes it Formal Definition of Computation p.8/28

Example computation from Example 1.5 and Formal Definition of Computation p.9/28 Take the machine Figure 1: Finite automaton

Running accepts according to the formal definition of computation because the sequence of states it enters when computing on is : Formal Definition of Computation p.10/28

Running accepts according to the formal definition of computation because the sequence of states it enters when computing on is : is the first state by definition Formal Definition of Computation p.10/28

Running accepts according to the formal definition of computation because the sequence of states it enters when computing on is : is the first state by definition,, Formal Definition of Computation p.10/28

Running accepts according to the formal definition of computation because the sequence of states it enters when computing on is : is the first state by definition,,,, Formal Definition of Computation p.10/28

Running accepts according to the formal definition of computation because the sequence of states it enters when computing on is : is the first state by definition,,,,,, Formal Definition of Computation p.10/28

The language except that the sum of the symbols in resets the count to 0 is 0 modulo 3, Since is a finite automaton is a regular language Formal Definition of Computation p.11/28

Designing finite automata Whether it be of automata or artwork, design is a creative process Formal Definition of Computation p.12/28

Designing finite automata Whether it be of automata or artwork, design is a creative process Consequently it cannot be reduced to a simple recipe or formula Formal Definition of Computation p.12/28

Designing finite automata Whether it be of automata or artwork, design is a creative process Consequently it cannot be reduced to a simple recipe or formula However, for a given design task one can find a particular approach useful; here we consider a useful approach for designing various types of automata Formal Definition of Computation p.12/28

The approach Be yourself the machine you are trying to design! Formal Definition of Computation p.13/28

The approach Be yourself the machine you are trying to design! As the machine you try to design, answer the question: how would you go about performing the machine s task? Formal Definition of Computation p.13/28

The approach Be yourself the machine you are trying to design! As the machine you try to design, answer the question: how would you go about performing the machine s task? Pretending that you are the machine is a psychological trick that helps engage your whole mind in the design process Formal Definition of Computation p.13/28

Using the approach Suppose that you are given some language and want to design a finite automaton that recognizes it Remember: a language is a set of strings over a given alphabet! Formal Definition of Computation p.14/28

Pretending to be the automaton Pretending that you are the automaton, you receive an input string and must determine whether it belongs to the language Formal Definition of Computation p.15/28

Pretending to be the automaton Pretending that you are the automaton, you receive an input string and must determine whether it belongs to the language You got to see the symbols in the string one by one. After each symbols you must decide whether the string seen so far is in the language. Formal Definition of Computation p.15/28

Pretending to be the automaton Pretending that you are the automaton, you receive an input string and must determine whether it belongs to the language You got to see the symbols in the string one by one. After each symbols you must decide whether the string seen so far is in the language. The reason is that you, like the machine, don t know when the end of the string is coming; so you must always be ready with the answer. Formal Definition of Computation p.15/28

Making decisions In order to make decisions, you have to figure out what you need to remember about the input string as you are reading it Formal Definition of Computation p.16/28

Making decisions In order to make decisions, you have to figure out what you need to remember about the input string as you are reading it Bear in mind that as you are pretending to be a finite automaton, you have a finite number of states and thus a finite memory, say a single sheet of paper Formal Definition of Computation p.16/28

Making decisions In order to make decisions, you have to figure out what you need to remember about the input string as you are reading it Bear in mind that as you are pretending to be a finite automaton, you have a finite number of states and thus a finite memory, say a single sheet of paper Fortunately, you don t need to remember entire input, you only need to remember certain crucial information Formal Definition of Computation p.16/28

Note Which information is crucial depends on the particular language considered Formal Definition of Computation p.17/28

Example design Suppose and the language consists of all strings with an odd number of 1s. You want to construct a finite automaton to recognize this language Formal Definition of Computation p.18/28

Constructing the states Start getting an input string of 0s and 1s symbol by symbol Formal Definition of Computation p.19/28

Constructing the states Start getting an input string of 0s and 1s symbol by symbol Remember whether the number of 1s seen so far is even or odd; Formal Definition of Computation p.19/28

Constructing the states Start getting an input string of 0s and 1s symbol by symbol Remember whether the number of 1s seen so far is even or odd; Represent the information you need as a finite list: (1) even so far, (2) odd so far Formal Definition of Computation p.19/28

Constructing the states Start getting an input string of 0s and 1s symbol by symbol Remember whether the number of 1s seen so far is even or odd; Represent the information you need as a finite list: (1) even so far, (2) odd so far Assign a state to each possibility, Figure 2 Formal Definition of Computation p.19/28

Constructing transitions To construct transitions you need to observe the way of going between possibilities while reading the input Example: the transition to flip state on a 1 and stay put on 0 is shown in Figure 3 Figure 3: Adding the start and accept state Formal Definition of Computation p.20/28

Start state and final states Set the start state to the state corresponding to the possibility associated with having seen far (i.e., the empty string ) symbols so Formal Definition of Computation p.21/28

Start state and final states Set the start state to the state corresponding to the possibility associated with having seen far (i.e., the empty string ) symbols so In our example this correspond to Formal Definition of Computation p.21/28

Start state and final states Set the start state to the state corresponding to the possibility associated with having seen far (i.e., the empty string ) symbols so In our example this correspond to Set the accept states to be those corresponding to possibilities where you want to accept the input Formal Definition of Computation p.21/28

Start state and final states Set the start state to the state corresponding to the possibility associated with having seen far (i.e., the empty string ) symbols so In our example this correspond to Set the accept states to be those corresponding to possibilities where you want to accept the input In our example this is the set Formal Definition of Computation p.21/28

The result The result of the example considered above is in Figure 4 Figure 4: Adding the start and accept state Formal Definition of Computation p.22/28

Example 1.9 This example shows how to design a finite automaton recognize the regular language of all strings over the alphabet substring Example: that contain the string as a strings 0010, 1001, 001, 11111110011111 are in that language to Formal Definition of Computation p.23/28

Pretending to be As symbols come in, you would initially skip over all 1s Formal Definition of Computation p.24/28

Pretending to be As symbols come in, you would initially skip over all 1s If you come to a, you note that you may have just seen the first of the three symbols in the pattern Formal Definition of Computation p.24/28

Pretending to be As symbols come in, you would initially skip over all 1s If you come to a, you note that you may have just seen the first of the three symbols in the pattern If after the first 0 you see a 1, then there were too few 0s so you back to skipping over 1s Formal Definition of Computation p.24/28

Pretending to be As symbols come in, you would initially skip over all 1s If you come to a, you note that you may have just seen the first of the three symbols in the pattern If after the first 0 you see a 1, then there were too few 0s so you back to skipping over 1s If after the first 0 you see another 0 then you should remember that you have seen two symbols of the pattern Formal Definition of Computation p.24/28

Pretending to be As symbols come in, you would initially skip over all 1s If you come to a, you note that you may have just seen the first of the three symbols in the pattern If after the first 0 you see a 1, then there were too few 0s so you back to skipping over 1s If after the first 0 you see another 0 then you should remember that you have seen two symbols of the pattern Once you have seen two symbols of the pattern you need to scan the input until you see a 1; if you find it, remember that you succeeded to find the pattern Formal Definitionand of Computation p.24/28

The list of possibilities 1. Haven t see any symbol of the pattern 2. Have just seen a 0 3. Have just seen 00 4. Have seen the entire pattern 001 Formal Definition of Computation p.25/28

Designing states and transitions Assign the states to the four possibilities Formal Definition of Computation p.26/28

Designing states and transitions Assign the states to the four possibilities In state you move to : while reading 1 remain in, but reading 0 Formal Definition of Computation p.26/28

Designing states and transitions Assign the states to the four possibilities In state you move to : while reading 1 remain in, but reading 0 In state you transit to : reading 0 you transit to but reading 1 Formal Definition of Computation p.26/28

Designing states and transitions Assign the states to the four possibilities In state you move to : while reading 1 remain in, but reading 0 In state you transit to In state : reading 0 you transit to you remain in state : reading 1 you move to but reading 1 while reading 0 Formal Definition of Computation p.26/28

Designing states and transitions Assign the states to the four possibilities In state you move to : while reading 1 remain in, but reading 0 In state you transit to In state : reading 0 you transit to you remain in state : reading 1 you move to but reading 1 while reading 0 In state : whatever you read remain in. Formal Definition of Computation p.26/28

0 Start and final states Start state is The result is in Figure 5 Figure 5: Accepting strings containing 001 Formal Definition of Computation p.27/28

Another example Design a DFA that recognizes the languages: begins with 1 and ends with 0 is any string except a and b Formal Definition of Computation p.28/28