Part B Finite-state Machines

Similar documents
Animations involving numbers

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

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

(Refer Slide Time: 1:43)

CSC 258 lab notes, Fall 2003

14.1 Encoding for different models of computation

p x i 1 i n x, y, z = 2 x 3 y 5 z

SOFTWARE ENGINEERING DESIGN I

Continuing with whatever we saw in the previous lectures, we are going to discuss or continue to discuss the hardwired logic design.

Informatics 1 - Computation & Logic: Tutorial 5

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

CS402 - Theory of Automata Glossary By

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

6.001 Notes: Section 8.1

Introduction to Computers & Programming

How Computer Mice Work

EC121 Mathematical Techniques A Revision Notes

Recursively Enumerable Languages, Turing Machines, and Decidability

ECS 120 Lesson 16 Turing Machines, Pt. 2

We have already seen the transportation problem and the assignment problem. Let us take the transportation problem, first.

A Small Interpreted Language

A Theory of Parallel Computation The π-calculus

STRAIGHT LINE GRAPHS THE COORDINATES OF A POINT. The coordinates of any point are written as an ordered pair (x, y)

Notes on Turing s Theorem and Computability

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

FSM Simulator. User s Manual Document. Matt Bartyczak, Clayton Kinard, Nick Pierson, Jordan Tallent

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

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

A simple problem that has a solution that is far deeper than expected!

Figure 1: From Left to Right, General Venn Diagrams for One, Two, and Three Sets

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

A Balanced Introduction to Computer Science

BOOLEAN ALGEBRA AND CIRCUITS

Electronics & Control

Projective geometry and the extended Euclidean plane

Recalling the definition of design as set of models let's consider the modeling of some real software.

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms

Turing Machine Languages

CSE Theory of Computing Spring 2018 Project 2-Finite Automata

Mathematics Mathematics Applied mathematics Mathematics

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Physics I : Oscillations and Waves Prof. S Bharadwaj Department of Physics & Meteorology Indian Institute of Technology, Kharagpur

CSE Theory of Computing Spring 2018 Project 2-Finite Automata

An object in 3D space

Lesson 1: Network Communications

(Refer Slide Time: 0:19)

Lecture 5: The Halting Problem. Michael Beeson

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

MITOCW watch?v=kz7jjltq9r4

6.001 Notes: Section 17.5

SETS. Sets are of two sorts: finite infinite A system of sets is a set, whose elements are again sets.

Word: Print Address Labels Using Mail Merge

2. CONNECTIVITY Connectivity

The Intersection of Two Sets

Theory of Programming Languages COMP360

SOME TYPES AND USES OF DATA MODELS

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

GAP CLOSING. Integers. Intermediate / Senior Facilitator s Guide

Stack Machines. Towards Scalable Stack Based Parallelism. 1 of 53. Tutorial Organizer: Dr Chris Crispin-Bailey

Excel Basics: Working with Spreadsheets

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

(Refer Slide Time: 01.26)

ME 365 EXPERIMENT 3 INTRODUCTION TO LABVIEW

Directed Graph for Finite-State Machine

MANAGING YOUR MAILBOX: TRIMMING AN OUT OF CONTROL MAILBOX

Chapter 1.5 Data Transmission and Networking.

CSCI 3130: Formal Languages and Automata Theory Lecture 16 The Chinese University of Hong Kong, Fall 2010

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Formal languages and computation models

6.001 Notes: Section 15.1

2. BOOLEAN ALGEBRA 2.1 INTRODUCTION

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Binary Representation. Jerry Cain CS 106AJ October 29, 2018 slides courtesy of Eric Roberts

UNIT -2 LEXICAL ANALYSIS

Operating system. Hardware

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

Chapter Operation Pinout Operation 35

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

NAME EET 2259 Lab 3 The Boolean Data Type

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

Software Engineering Software Requirements Specification (SRS) Document

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

Analogue vs. Discrete data

4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

1 Parsing (25 pts, 5 each)

(Refer Slide Time 3:31)

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

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

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction

An Introduction to Subtyping

6. Relational Algebra (Part II)

This book is licensed under a Creative Commons Attribution 3.0 License

Hardware Modeling using Verilog Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

The Size of the Cantor Set

CPS122 Lecture: Course Intro; Introduction to Object-Orientation

Multiple Choice Questions

Getting Started with HCA and UPB

Transcription:

MTH237: Weeks 2 5 (22) Part Finite-state Machines Text: ooper Notes, hapters 4 7 hapter4 hapter 4 Introduction to finite-state machines (printed notes) Section4. 4. yclops, the simplest possible omputer (page 67 of printed notes) We now begin our study of the Theory of omputation. Here we are not interested in the latest software or hardware, knowledge that changes by the month and which becomes obsolete after only a few years. Instead we are going to ask some rather deep questions about the nature of computation. While it is clear that this should be valuable background knowledge for the professional computer scientist, it should be pointed out that it also has relevance for the student of mathematics. fter all, a large part of mathematics involves computation, and algorithms procedures for computing something have been around for thousands of years. Questions about the fundamental nature of computation were asked, not by computer scientists, but by mathematicians; and when such questions began to be asked (in the first half of the 2th century) there were no such people as computer scientists and no such machines as computers. Indeed it was the pioneering work of mathematicians such as lan Turing that helped to give birth to the computer. Now a modern computer is an exceedingly complicated machine. In order to understand its essential nature we must strip away all this complexity and consider the simplest possible computer. We shall call this simplest-of-all-possible-computers, yclops. yclops was the name given to a character from Greek mythology with only one eye, placed in the middle of his forehead. You will shortly see why this name is quite appropriate for this most primitive machine. There are four essential features of any computing device: Ì a mechanism for input Ì a mechanism for output

2 urrentvalue[filename] Ì memory Ì programs. Input can come through a variety of devices such as -ROMs or broadband modems, but the most familiar input device is the keyboard. We will provide yclops with a keyboard with just one key with the numeral engraved on it. So a typical input to yclops can only be a string of s, such as. This means that we cannot use binary notation for numbers. Instead, to input the number n we will have to press the key n times. Output can also come through a variety of channels, but probably the most familiar is the video display unit, or computer screen. Our simplest-of-all-possible computers will have to have a monochrome display. On a typical L screen there are many thousands of tiny pixels points that can be either on or off (lit or dark). yclops will have to be content with a single pixel screen or equivalently, a single light bulb which can either be or. In all computers a part of the RM (random access memory) is devoted to providing the screen output. (In the early days of home computers when there was very limited memory programmers were forced to make use of this memory for their calculations and so while the program was running all sorts of garbage would appear on the screen until the final output was displayed. Today memory is measured in gigabytes and each gigabyte consists of a very large number of tiny units of memory called bits. One bit is the amount of memory contained in a light switch that remembers whether it is or. In order to create the simplest-of-all-possible-computers we will insist that the single light bulb that yclops has for its display has to double up as a one-bit memory. Finally there is the program. Normally computers use part of their memory to store a program, but this is a bit much to ask of our single-bit midget! Instead we will hard-wire the program into yclops in much the same way that there is a program hard-wired into the micro-processor that controls an automatic washing machine. This means, of course, that unless we rewire him, yclops will be a single-program computer.

urrentvalue[filename] 3 So our minimal computer is a one-bit, single-program machine with just one key and a single lightbulb as the display! t any given stage the light bulb is either on or off. s the key is pressed, the program will determine whether the bulb should be on or off. programming yclops Since our intention is to make yclops a deterministic machine, the decisions made by the program must be determined solely by two things: () which key has been pressed, and (2) what state the machine is currently in. The decision rule can be set out in a table of the following form:?? Each of these two cells needs to contain the name of the next state into which the machine goes; that is, each is either an or an. Since there are two possibilities for each cell there are 4 combinations altogether. Each of these can be thought of as a program that can be hard-wired into yclops. Example4. Example Here is one such program. When the light is a key-press will turn it. When it is, pressing the key turns it. This program will cause yclops to repeatedly switch the output bulb on and off every time the key is pressed. This very simple computer, running this very simple program, is in fact actually manufactured though not as a computing device. Rather it is a toggle light switch such as you get on many desk lamps. Push the button, and if the light is off it then goes on. Push it again and the light goes off. Many years ago such switches were connected to long cords from the ceiling and each time you pulled on the cord the ceiling light would change its state. yclops as a computer Now you may never have thought of such a mechanism as a primitive computer, but it can in fact compute. We can use it to compute whether a given number n is odd or even, by examining the effect of n pushes of the key. Ù We first reset the machine by switching the light off. Ù Then we push the button n times.

4 urrentvalue[filename] Ù If, when we have finished, the light is, then n is odd. Ù If it ends up being, then the number is even. other programs for yclops ltogether there are 4 different programs that yclops can be given. One was given in Example. The other three are: These three are not nearly so useful as the light-switch model. In the first one the input has no effect whatsoever, just as if the key was a dummy one not connected to anything. The other two can change the state once, but the effect cannot be reversed. The buttons on a lift work like this last one. Once they are they cannot be switched until they are reset when you reach the required floor. We have learnt all there is to know about -input 2-state machines, which is not much! So let us generalise yclops to a machine with m input keys and n states. Section4.2 4.2 Finite-State Machines (page 69 of printed notes) finite state machine, FSM finite-state machine (FSM) consists of the following: () a set I called the input alphabet; (2) a set S whose elements are called states; (3) a function T : S µ I Ø S called the transition function;

urrentvalue[filename] 5 (3) a function T : S I S called the transition function; (4) a particular element, s œ S called the initial state. The functioning of the machine is as follows: Ù The machine starts in the initial state s. Ù The input is a string of characters from the input alphabet which are read one at a time (from the left). Ù t each stage the machine is in some state s œ S. Ù If the machine is in state s, and the next input character is c œ I, the machine moves to state THs, cl and awaits the next input character. Ù The process continues in this way until all the input characters have been processed. Example4.2 Example 2: I = 8, 2<, S = 8,,, <, s = and T is given by the table: Ø 2 Suppose the input to this machine is 2 22 2. The successive transitions of the machine are: Ø Ø Ø 2 Ø Ø 2 Ø 2 Ø Ø Ø 2 Ø lthough we described it abstractly, this particular machine can have a very familiar interpretation. Imagine that you are the operator of an amusement park ride and you have to fill four-seater cars from a succession of couples and single customers. Your instructions are to wait until the car is full before letting it go. However if a couple arrives, rather than splitting them, you let the car go with just 3 passengers and put the couple in the next one. Ï The input consists of the customers who arrive in s and 2s. Ï The four states, to, correspond to the four possible situations you can have with the current car. Ï State is where you have a completely empty car and states, and are where there are one, two or three passengers waiting in the car. Examine the state table to see that you agree that it accurately describes the situation. discussion oth Examples and 2 serve some purpose other than computation. The fact that a light switch can distinguish between odd and even numbers is not the purpose for which it was made, and the operator of the ghost train ride certainly does not see himself as a cog in some giant (but rather feeble) computer. In what follows we shall concentrate on finite-state machines as devices to perform some sort of computation. The physical nature of the states will not concern us, only the abstract movement from state to

6 urrentvalue[filename] state. In practice, finite-state machines are implemented electronically in one of two ways. Ì We can build an electronic chip, incorporating the logic of the machine. This is done where the machine is part of a piece of equipment that is designed to react to external input in some definite way. Ì Or we can incorporate the finite-state machine within some computer program, where the computer simulates the machine. In fact a computer itself is a finite-state machine. The set of states is the set of all possible combinations of bits of internal memory. This is huge, but finite. Section4.3 4.3 Mealy Machines (page 7 of printed notes) To be of any use in computation a finite-state machine must have some form of output. There are several ways we can provide that output. n obvious way is to have the machine print it (on a screen, or on paper, or perhaps as a sequence of tones). output alphabet We need an output alphabet, O, that may or may not be the same as the input alphabet. Every time the machine reads a character from the input, it outputs a character as well as changing its state. output character To describe the output of such a machine we can have an additional function that assigns to each combination of state and input character, an output character. output function In other words we have a function P : S µ I Ø O. When the machine is in state s and reads the character c, the output is PHs, cl. Mealy machine machine of this type is known as a Mealy Machine.(Wikipedia, George H. Mealy) We can describe a Mealy machine by a pair of tables. The state table provides the new state, for each combination of state and character and the output table provides the character that is output at each stage. The initial state is indicated by putting a short arrow in front of that state in the left-hand column. Example4.3 Example 3 The following Mealy machine echoes the input after a two-step delay. Ù The first two output characters are both s. Ù Thereafter the output at each stage is the input from two steps earlier. Ù The last two input characters are ignored. I = O = 8, <, S = 8,,, < with s =.

urrentvalue[filename] 7 The meaning of these states will be as follows: means next two output characters are to be:,. means next two output characters are to be:,. means next two output characters are to be:,. means next two output characters are to be:,. Giving an interpretation to the states is not a part of the description of the machine. One can operate the machine mindlessly without such knowledge. However when designing finite-state machines, and understanding their function, it is quite useful to be able to attach a meaning to each state. The transition and output tables for this machine are as follows (we indicate the fact that is the initial state by putting an arrow in front of it): Ø State Output So if the input is the output will be as shown below: input states output Ø Ø Ø Ø Ø Ø Ø Ø Ø The effect is to print two initial s and then to repeat the input with a two-step delay. Of course because the output has the same length as the input the last two input characters will be ignored. Section4.4 4.4 Moore Machines (page 7 of printed notes) n alternative arrangement for output is to have the machine print a certain output character as it enters a state. Moore machine These machines are called Moore machines. The output is attached to the states rather than to the transitions. (Wikipedia, Edward F. Moore) Formally, the output of a Moore machine is described by a function P : S Ø O, where as before, O is the output alphabet.

8 urrentvalue[filename] Example4.4 Example 4 The following Moore machine is also a two-step delay machine, behaving equivalently to the Mealy machine in Example 3. I = O = 8, <, S = 8,,,, E, F, G, H< with s =. Ø E F G H T P E F G H E F G H Interpretation last 3 inputs Using the same input string as before we get the same output of. The difference is that the output responds only to the state being entered. input states output Ø Ø Ø H Ø G Ø E Ø Ø Ø H Ø H It is a relatively routine task to convert a Mealy machine to a Moore machine and vice versa. Section4.5 4.5 Finite-state cceptors (page 72 of printed notes) Even the Moore machine is more than we need here. Our focus on finite-state machines will be as acceptors for languages. Given a language, on a given alphabet, we would like to find a machine that decides whether or not a given string belongs to the language.

urrentvalue[filename] 9 Here the output is a simple YES or NO. We are not interested in partial results. We wait for the machine to read the entire input string, and only then are we interested in the answer. FS In a finite-state acceptor (FS) the output is determined by selecting a subset of states as the accepting states. If the machine ends in an accepting state, after having read the entire string, we say that the string has been accepted by the machine. Otherwise it is rejected. Every Moore machine with output set 8, < can be considered as an FS by taking the accepting states to be those for which the output is a "". nd every FS can be considered as a Moore machine simply by assuming that the machine prints a "" whenever it enters an accepting state and "" when it enters any other state. The slight modification to the way we present it as a finite state acceptor is to replace the s in the final column by s and the s by blanks, so that the accepting states are those with an star (asterisk) against them. Example4.5 Example 5 Writing the Moore machine in Example 4 as a finite state acceptor we have: Ø E F G H E G E G F H F H HL HL HL HL HL HL HL HL accepting a language s we said earlier, our main focus will be on finite state acceptors. Now corresponding to every FS there is a language the set of all input strings that are accepted by the machine. accepts a language We say that an FS accepts a language, L, if it accepts every string in L and rejects all others. n important question is can every language be accepted by an FS? The answer is no. Only for certain languages does there exist a corresponding FS. Which ones? We shall have to wait till a later chapter for an answer.

urrentvalue[filename] Example4.6 Example 6 The language accepted by the above FS is the set of all strings whose third last symbol is a "". This language can be described by the regular expression H + L * H + + + L. Section4.6 4.6 State iagrams (page 73 of printed notes) It is often convenient to depict a finite-state machine pictorially. This is done by drawing a small circle for each state, with the name of the state inside, and drawing arrows connecting the states to depict the transitions. The input character that gives rise to a transitions is written beside the corresponding arrow. We indicate the initial state by drawing a short arrow pointing to it. Output is depicted in the following ways: Mealy Machines The output is written beside the input character for each transition as follows: Out[2]= ê G This indicates that if the machine is in state and receives input "", it then outputs a "" and moves to state G. Moore Machines The output is attached to the name of the state as follows: compatibility-yes Out[23]= Gê This indicates that if the machine is in state and receives input "", it moves to state G and outputs a "". FSs The accepting states are distinguished by drawing a double ring around them as follows:

urrentvalue[filename] compatibility-yes Out[27]= G This indicates that if the machine is in state and receives input "", then it it moves to state G. If that was the last character of the input string, the string would be accepted. Example4.7 Example 7 The following table and diagram represent the same Mealy machine. T P Ø compatibility-yes ê ê Out[3]= ê ê ê ê ê ê Example 8 Example 8 The following table and diagram represent the same Moore machine.

2 urrentvalue[filename] Ø T P ê ê Out[462]= ê ê Example 9 Example 9 The following table and diagram represent the same FS. Ø

urrentvalue[filename] 3 Out[46]= Section4.7 4.7 lack Holes (page 74 of printed notes) Exercises4 Exercises for hapter 4 Solutions4 Solutions for hapter 4 (page 75 79 of printed notes) (page 79 84 of printed notes) hapter5 hapter 5 Reduction of finite-state machines (printed notes) hapter6 hapter 6 Non-deterministic Finite-State cceptors (printed notes) hapter7 hapter 7 FSs and Regular Languages (printed notes)