This action might not be possible to undo. Are you sure you want to continue?

# Theory of Computation Lecture Notes

**Theory of Computation Lecture Notes
**

Abhijat Vichare August 2005

Contents

● ● ●

1 Introduction 2 What is Computation ? 3 The λ Calculus r 3.1 Conversions: r 3.2 The calculus in use r 3.3 Few Important Theorems r 3.4 Worked Examples r 3.5 Exercises 4 The theory of Partial Recursive Functions r 4.1 Basic Concepts and Definitions r 4.2 Important Theorems r 4.3 More Issues in Computation Theory r 4.4 Worked Examples r 4.5 Exercises 5 Markov Algorithms r 5.1 The Basic Machinery r 5.2 Markov Algorithms as Language Acceptors and Recognisers r 5.3 Number Theoretic Functions and Markov Algorithms r 5.4 A Few Important Theorems r 5.5 Worked Examples r 5.6 Exercises 6 Turing Machines r 6.1 On the Path towards Turing Machines r 6.2 The Pushdown Stack Memory Machine r 6.3 The Turing Machine r 6.4 A Few Important Theorems r 6.5 Chomsky Hierarchy and Markov Algorithms r 6.6 Worked Examples r 6.7 Exercises 7 An Overview of Related Topics r 7.1 Computation Models and Programming Paradigms r 7.2 Complexity Theory 8 Concluding Remarks Bibliography

●

●

●

●

● ●

1 Introduction

http://www.cfdvs.iitb.ac.in/~amv/Computer.Science/courses/theory.of.computation/ (1 of 41) [12/23/2006 1:14:53 PM]

Theory of Computation Lecture Notes

**Theory of Computation Lecture Notes
**

Abhijat Vichare August 2005

Contents

● ● ●

1 Introduction 2 What is Computation ? 3 The λ Calculus r 3.1 Conversions: r 3.2 The calculus in use r 3.3 Few Important Theorems r 3.4 Worked Examples r 3.5 Exercises 4 The theory of Partial Recursive Functions r 4.1 Basic Concepts and Definitions r 4.2 Important Theorems r 4.3 More Issues in Computation Theory r 4.4 Worked Examples r 4.5 Exercises 5 Markov Algorithms r 5.1 The Basic Machinery r 5.2 Markov Algorithms as Language Acceptors and Recognisers r 5.3 Number Theoretic Functions and Markov Algorithms r 5.4 A Few Important Theorems r 5.5 Worked Examples r 5.6 Exercises 6 Turing Machines r 6.1 On the Path towards Turing Machines r 6.2 The Pushdown Stack Memory Machine r 6.3 The Turing Machine r 6.4 A Few Important Theorems r 6.5 Chomsky Hierarchy and Markov Algorithms r 6.6 Worked Examples r 6.7 Exercises 7 An Overview of Related Topics r 7.1 Computation Models and Programming Paradigms r 7.2 Complexity Theory 8 Concluding Remarks Bibliography

●

●

●

●

● ●

1 Introduction

In this module we will concern ourselves with the question:

http://www.cfdvs.iitb.ac.in/~amv/Computer.Science/courses/theory.of.computation/toc.html (1 of 37) [12/23/2006 1:17:43 PM]

Theory of Computation Lecture Notes

We first look at the reasons why we must ask this question in the context of the studies on Modeling and Simulation. We view a model of an event (or a phenomenon) as a ``list'' of the essential features that characterize it. For instance, to model a traffic jam, we try to identify the essential characteristics of a traffic jam. Overcrowding is one principal feature of traffic jams. Yet another feature is the lack of any movement of the vehicles trapped in a jam. To avoid traffic jams we need to study it and develop solutions perhaps in the form of a few traffic rules that can avoid jams. However, it would not be feasible to study a jam by actually trying to create it on a road. Either we study jams that occur by themselves ``naturally'' or we can try to simulate them. The former gives us ``live'' information, but we have no way of knowing if the information has a ``universal'' applicability - all we know is that it is applicable to at least one real life situation. The latter approach - simulation - permits us to experiment with the assumptions and collate information from a number of live observations so that good general, universal ``principles'' may be inferred. When we infer such principles, we gain knowledge of the issues that cause a traffic jam and we can then evolve a list of traffic rules that can avoid traffic jams. To simulate, we need a model of the phenomenon under study. We also need another well known system which can incorporate the model and ``run'' it. Continuing the traffic jam example, we can create a simulation using the principles of mechanical engineering (with a few more from other branches like electrical and chemical engineering thrown in if needed). We could create a sufficient number of toy vehicles. If our traffic jam model characterizes the vehicles in terms of their speed and size, we must ensure that our toy vehicles can have varying masses, dimensions and speeds. Our model might specify a few properties of the road, or the junction - for example the length and width of the road, the number of roads at the junction etc. A toy mechanical model must be crafted to simulate the traffic jam! Naturally, it is required that we be well versed with the principles of mechanical engineering - what it can do and what it cannot. If road conditions cannot be accurately captured in the mechanical model1, then the mechanical model would be correct only within a limited range of considerations that the simulation system - the principles of mechanical engineering, in our example - can capture. Today, computers are predominantly used as the system to perform simulation. In some cases usual engineering is still used - for example the test drive labs that car manufacturers use to test new car designs for, say safety. Since computers form the main system on which models are implemented for simulation, we need to study computation theory - the basic science of computation. This study gives us the knowledge of what computers can and cannot do.

2 What is Computation ?

Perhaps it may surprise you, but the idea of computation has emerged from deep investigation into the foundations of Mathematics. We will, however, motivate ourselves intuitively without going into the actual Mathematical issues. As a consequence, our approach in this module would be to know the Mathematical results in theory of Computation without regard to their proofs. We will treat excursions into the Mathematical foundations for historical perspectives, if necessary. Our definitions and statements will be rigorous and accurate. Historically, at the beginning of the 20 century, one of the questions that bothered mathematicians was about what an algorithm actually is. We informally know an algorithm: a certain sort of a general method to solve a family of related questions. Or a bit more precisely: a finite sequence of steps to be performed to reach a desired result. Thus, for instance, we have an addition algorithm of integers represented in the decimal form: Starting from the least significant place, add the corresponding digits and carry forward to the next place if needed, to obtain the sum. Note that an algorithm is a recipe of operations to be performed. It is an appreciation of the process, independent of the actual objects that it acts upon. It therefore must use the information about the nature (properties) of the objects rather than the objects themselves. Also, the steps are such that no intelligence is required - even a machine2 can do it! Given a pair of numbers to be added, just mechanically perform the steps in the algorithm to obtain the sum. It is this demand of not requiring any intelligence that makes computing machines possible. More important: it defines what computation is! Let me illustrate the idea of an algorithm more sharply. Consider adding two natural numbers3. The process of addition generates a third natural number given a pair of them. A simple way to mechanically perform addition is to tabulate all the pairs and their sum, i.e. a table of triplets of natural number with the first two being the numbers to be added and the third their sum. Of course, this table is infinite and the tabulation process cannot be completed. But for the purposes of mechanical i.e. without ``intelligence'' - addition, the tabulation idea can work except for the inability to ``finish'' tabulation. What we would really like to have is some kind of a ``black box machine'' to which we ``give'' the two numbers to be added, and ``out'' comes their sum. The kind of operations that such a box would essentially contain is given by the addition algorithm above: for integers represented in the decimal form, start from the least significant place, add the corresponding digits and carry forward to the next place if needed, for all the digits, to obtain the sum. Notice that the ``algorithm'' is not limited by issues like our inability to finish the table. Any natural number, howsoever large, is represented by a finite number of digits and the algorithm will eventually stop! Further, the algorithm is not particularly concerned about the pair of numbers that it receives to be processed. For any, and every, pair of natural numbers it works. The algorithm captures the computation process of addition, while the tabulation does not. The addition algorithm that we have presented, is however intimately tied to the representation scheme used to write the natural numbers. Try the algorithm for a

http://www.cfdvs.iitb.ac.in/~amv/Computer.Science/courses/theory.of.computation/toc.html (2 of 37) [12/23/2006 1:17:43 PM]

Markov Algorithms. Transformation application. i. `y' and `1' are variables (in the 2. Many models have been developed. calculus The addition process example can be used to illustrate the use of the above syntax of through the following remarks. The final ability that an being applied on the object named . if the transformation generates the square of the number to which it is applied. then we name the transformation as: square. Thus when we want to square a natural number An algorithm is characterized by three abilities: 1.iitb. The following sections. Let us call the resultant object to is written as: . They will be replaced by the actual numbers to be added when the addition process gets ``applied'' to them . and .Theory of Computation Lecture Notes Roman representation of the natural numbers! We now have an intuitive feel of what computation seems to be. In this module we will concern ourselves with four different approaches to modeling the idea of computation.cfdvs. . . This transformation would be the actual ``operational details'' of the algorithm ``black box''. 4. technically known as application. Transformation specification. each such multi-letter name should be treated as one single symbol!) 1. technically the named object is called as a 2. 3. The bound variables is the ``addition process'' of bound variables ``hold the place'' in the transformation to be performed. and Turing Machines. on the right An application means replacing every occurrence of the first bound variable. and .ac. let us consider a very simple ``activity'' that we perform so routinely that we almost forget it's algorithmic nature . Alonzo Church.counting. This . and hence can be named! For example. A logician. The theory of Partial Recursive Functions. the issue was what was calculus in order to understand meant by an algorithm.html (3 of 37) [12/23/2006 1:17:43 PM] . or synonymously . 3. we will try to intuitively motivate them. it's every occurrence in the body This gives us the term: is replaced by due to the application. http://www.of. These three abilities are technically called as terms. Object naming. Historically. 3 The Calculus This is the first systematic attempt to understand Computation. The algorithm would transform this object into something (possibly itself too). in the body of the term be applied (the left term) by the term being applied to (the right term). we write it as . named is written as . Our approach is necessarily introductory and we leave a lot to be done. Observe that this transformation process itself is another object.a computation. technically known as abstraction. and are being developed. . Also the process specification has been done using the usual laws of arithmetic. The Calculus.computation/toc. . 2. `add'. if any. and 3. created the the nature of an algorithm. (To relate better. Note that we concentrate on the process of transforming we have merely created a notation of expressing a transformation.e. We write this as: algorithm needs is that of it's transformation. would need some object to work upon. `x'. The approaches are: 1. a process that can add the value 1 to it's input as ``signalled'' by the bound variable that ``holds the place'' in the processing. is the application of the abstraction in remark to the term . Since the 1920s Mathematics has concerned itself with the task of clearly understanding what computation is. To get a feel of the approach. we name variables with more than one letter words enclosed in single quotes. that try to sharpen our understanding.Science/courses/theory. hence hand side4. calculus sense). being the first bound variable. That there is some rule that transforms to . we need an ability to name an object. An algorithm. Let us call it In other words.See remark .in/~amv/Computer.

in/~amv/Computer. expressions before and after the substitution. it does not matter what name is actually used to refer to their respective places5. Thus as a result of application. This is the heart of capturing computation in the calculus style as this conversion expresses the exact symbol replacement that computation essentially consists of. conversion. the variable does not occur therefore have that must not occur bound in . it is possible for us to substitute while avoiding accidental change As a consequence of conversion is necessary to maintain the equivalence of the in the nature of occurrences. This is the using substitution as: conversion: Iff does not occur in .the computational process .1 Conversions: We have acquired the ability to express the essential features of an algorithm. (neither free nor bound) in expression The conversions are: Since a bound variable in a expression is simply a place holder. it follows that specifies the binding of a variable occurs free in then this state of must occur free in must be preserved are different! Hence we .Science/courses/theory. We first establish a notation to express the act of substituting a variable another variable is replaced by to obtain a new expression ). after substitution .the must demand that if if occurs bound in and the that would be substituting in is to be used to substitute then this state of then it must not occur free in too must be preserved after substitution.Theory of Computation Lecture Notes 4. However.on some ``target'' object. We usually name as `inc' or '1+'.computation/toc.iitb. The renaming of a bound variable that does not occur in is the conversion: conversion: Iff does not occur in . Since the . conversion rule expressed http://www. all that is required is that unique place holders be used to designate the correct places of each bound variable in the expression. And finally. A process involves replacing one set of symbols corresponding to the input with another set of symbols corresponding to the output. if in as: ( in an expression is in by whose every . 3.html (4 of 37) [12/23/2006 1:17:43 PM] .cfdvs. We now present the ``manipulation'' rules of the calculus called the conversion rules. We observe that an application represents the action of an abstraction . As long as the uniqueness is preserved. This freedom to associate any name to a bound variable is expressed by the conversion rule which states the equivalence of expressions whose bound variables have in an expression to a variable been merely renamed. In other words. the ``target'' symbol must replace every occurrence of the bound variable in the abstraction that is being applied on it. We must . Further.ac. it still remains to capture the effect of the computation that a given algorithmic process embodies. Symbol replacement is the essence of computing.of.

Thus: conversion: Iff does not occur in .computation/toc. a term. already occurs bound in the old expression.in/~amv/Computer.cfdvs. Thus we first using conversion to get: by using conversion. then this motivates a term for a ``zero'' as6: http://www. then expression is transformed to an expression by the application of any of the If a above conversion rules.e.html (5 of 37) [12/23/2006 1:17:43 PM] . If is the object that is being counted. Thus we speak of redex. suppose we wish to apply the ( rename the ). then the we have the specification. i. we need to look at their behavioral properties to see their computational nature. For example.1 The Natural Numbers in calculus calculus in use Natural numbers are the set = {0. An expression to which a conversion is applicable is referred to as the corresponding redex (reducible expression). The expression obtained when no more conversions are possible is the ``output'' or the ``answer''.Theory of Computation Lecture Notes Since computation essentially is symbol replacement. But expression to . 1.2.e. i.e. 2. in the old expression to (say) and then substitute every It expresses the fact that the expression that is free of any occurrences of the binding variable in a abstraction is the expression itself. ``executing an algorithm on an input'' is expressed in the calculus as ``performing conversions on applications until no more conversion is possible''. We ``know'' them as a set of values.e. the object does not exist for the purposes of being counted). We associate a natural number with the instances of counting that are being applied to the object being counted. However. If no more conversion rules are applicable to an expression .of. }. we say that reduces to and denote it as . Let us name the counting process by the symbol . 3.ac. then it is said to be in it's normal form. there is only one instance of the object).iitb. If the counting process is applicable to the object just once (i. if the counting process is applied ``zero'' times to the object (i. for the natural number ``zero''. redex etc. For instance. then the function for that process represents the natural number ``one''. We demonstrate this using the counting process.Science/courses/theory.2 The 3. and so on.

2) to get the second even number etc.e.ac. Conventionally.e. but no counting has been applied to it. Contrast: ``I counted ten tables'' with ``I could apply counting ten times to objects that were tables''.html (6 of 37) [12/23/2006 1:17:43 PM] .computation/toc.in/~amv/Computer. Consider http://www. Hence Note that in Eq. we tend to associate numbers with objects rather than the process. any process that can be sensibly applied to an object can be used in place of were the process that generates the double of a number. Hence abstraction. twice (i. A . while in the second case it is associated with the ``counting'' process! We are accustomed to the former way of looking at numbers.of. to present the power of pure symbolic manipulation. 1) . then the above once (i. And finally.e. we observe that the sum of of the counting process addition can be defined as: to which has already been generated by using . In the first case. the expression is applied to the expression . if .Theory of Computation Lecture Notes where the remains as it is in our thoughts. i.Science/courses/theory. The addition of two natural numbers and is simply the total number of applications of the counting process.cfdvs. At this point. or ``three'' are defined as: the body of the forms A look at Eqns. . expressions could be used to generate the even numbers by a simple ``application'' of to get the first even number. To get the expression and is just further applications that captures the addition process. A ``one''. We now present the addition process7 from this calculus view. ``ten'' is associated subconsciously to ``table''.( the application of - ) shows that a natural number is given by the number of occurrences of .iitb. a ``two''.( adding 1 and 2: ).our name for the counting process. but there is no reason to not do it the second way. We have simply used to denote the counting process to get a feel of how the natural number is just applications of (some) to expressions above make sense. we observe that although we have motivated the above expressions of the natural numbers as a result of applying the counting process For example. let us pause for a moment and compare this way of thinking about numbers with the ``conventional'' way.

ac.Theory of Computation Lecture Notes The add expression takes the expression form of two natural numbers and to be added http://www.of.in/~amv/Computer.cfdvs.Science/courses/theory.computation/toc.iitb.html (7 of 37) [12/23/2006 1:17:43 PM] .

iitb. Therefore.2 The Booleans Conventionally. This view of looking at computation from the ``processes'' point of view is referred to as the functional paradigm and this style of programming is called functional programming. True and False are merely symbols.( ).ac. If is True (i.( ) is an abstraction that encodes the behavior of the value True and is thus a very computational view of the value8.( ) is an abstraction that encodes the behavior of the value False. As a terms. . Scheme is often viewed as `` calculus on a computer''.Science/courses/theory. This is also evident when we examine the abstraction for (say) the IF boolean function and apply it to each of the above equations. Note that this and to be supplied when it is to be expression expects two arguments namely expression that we write in the calculus are simply some process applied.e.computation/toc.html (8 of 37) [12/23/2006 1:17:43 PM] .e.e. apply the boolean expression then we must get to and . Scheme. reduces to the term True). In fact. For instance. The specifications including of those objects that we formerly thought of as ``values''.in/~amv/Computer. Accordingly.2. ML and Haskell are based on this kind of view of programming .Theory of Computation Lecture Notes and yields a resulting expression that behaves exactly as the sum of these two numbers. as a result of applying various conversions to Eqn. it can be encoded as the following abstraction: http://www. a (simple!) encoding boolean expression (which we would like to view as a abstractions: of these values is through the following two Note that Eqn. The IF function behaves as: given a boolean expression and two the first term if the expression is `` True'' else return the second is expressed as: term. Programming languages like Lisp. one and only one of each is returned as the ``result''/``value'' of a expression). 3.of.i. we have two ``values'' of the boolean type: True and False. In our notation. From a purely formal point of view. we can say that the above equations indeed capture the behaviors of these ``values'' as ``functions''. We also have the conventional boolean ``functions'' like NOT. return abstraction it i.cfdvs. Similarly Eqn. Since the encodings represent the selection of mutually ``opposite'' expressions from the two that would be given by a particular (function) application. we associate a name ``square'' to the operation ``multiply calculus x (some object) by itself'' as (define square (lambda (x) (* x x))). this would look like . AND and OR. else we must get The AND boolean function behaves as: ``If p then q else false''. expressing ``algorithms'' as expression.

3. two approaches are possible.of. we would like to mention that the calculusis extensively used to mathematically model and study computer programming languages. namely in Eqn.e. a reduction of this the expected output.Science/courses/theory. If we apply it to Eqn. Note that no further reductions are possible.ac. or redex 3. such that and .e. It takes two arguments and . i.Theory of Computation Lecture Notes Note that in Eqn. That is.( ): http://www.4 Worked Examples We apply the IF expression to True i.( ). and Eqn.iitb. will terminate in the normal form.( ) to Eqn. Consider the AND function defined by Eqn.( ) (i.( ) for every occurrence of two arguments. Very exciting and significant developments have occurred.( ).( ) and Eqn.computation/toc.( ) further reductions depend on the actual forms of and . To see that the abstractions indeed behave as our ``usual'' boolean functions and values.with any required conversion.in/~amv/Computer.html (9 of 37) [12/23/2006 1:17:43 PM] . I will try the latter technique. and are occurring. Either work out the reductions in detail for the complete truth tables of both the boolean functions.( AND TRUE FALSE). - it's first argument as the result. Theorem 3 If an expression E has a normal form. in this field. Theorem 1 A function is representable in the Theorem 2 If = then there exists calculus if and only if it is Turing computable.e. we work out an application of Eqn.cfdvs. (intuitively ?) reason out the behavior. or noting the behavioral properties of these functions and the ``values'' that they could take. then the reduction would substitute Eqn.3 Few Important Theorems At this point. then repeatedly reducing the leftmost . This gives us a ) for every occurrence of abstraction to which have been applied and ! This abstraction behaves like TRUE and hence it yields abstraction yields .

We recall the definitions of natural numbers from Eqns. there is little reason to impose any differentiation of the object as a ``value'' or as a ``function''.iitb.html (10 of 37) [12/23/2006 1:17:43 PM] . I also believe that it makes the essentially computational nature of these objects opaque to us. This function will be used in the Partial Recursive Functions model. 2.). The ``valueness'' cannot be captured as is not at all relevant to us from the a ``computational'' process while the behavior can be. ). And if the behavior of the computational process is in every way identical to the value.( .Theory of Computation Lecture Notes which will return the first object of the two to which the IF will actually get applied to (i. Note that Eqns. function that yields the successor of the number Let me also illustrate the construction of the given to it. I cannot stress more that the ``valueness'' of these objects calculus point of view. This is what was used to define the add process in Eqn.5 Exercises 1.ac. 3.computation/toc. Hence the bodies of the corresponding . Construct the expression for the following: 1.cfdvs. ) capture the behavior of the objects that we are accustomed to see as ``values''.of. Thus: to to to some object . the given natural number. The NOT boolean function which behaves as ``If p then False else True''. The succ process is one more application of the counting process to the given natural number. http://www. On the other hand.Science/courses/theory. e. We observe that the natural number is defined by the number of applications of the counting process expressions involve application of of the process ( ). insisting on the ``valueness'' of the objects given by those equations forces us to invent unique symbols to be permanently bound to them.( .in/~amv/Computer. This gives us a way to define the succ as an application . The OR boolean function which behaves as ``If p then true else q''.

perform necessary conversions of the following 1. of natural numbers10.e.ac. . .e. (AND TRUE FALSE) 3. .html (11 of 37) [12/23/2006 1:17:43 PM] . . . .computation/toc.iitb. denotes the number of arguments that the constant function takes and natural numbers . 0 in this case. i. (succ 1) expression. To capture the idea of computation. . we have Definition 3 the projection functions. . we have http://www. . For example.in/~amv/Computer. we will not concern ourselves about the developments that are occurring in this rich field. i.e. (NOT TRUE) 5.Theory of Computation Lecture Notes 2.cfdvs. Thus given natural numbers .of. However. ● ● ● Is the choice of the initial functions unique ? Similarly. . called operators that can generate new processes from the basic ones. 4 The theory of Partial Recursive Functions We now introduce ourselves to another model that studies computation. i. The superscript in for . Our purpose of introducing this view of computation is much immediately followed more philosophical than any practical one that can directly be used in day to day software practice9. (IF FALSE) 2. . . . the subscript is the value of the function. Evaluate. . for and . . The superscript is the number of arguments of the particular projection function and the subscript is the argument to which the particular projection function projects. It then goes on to identify combining techniques. . Thus given . . .1 Basic Concepts and Definitions We define the initial functions and the operators over the set Initial Functions Definition 1 the function. We would like to give a flavor of the questions that are asked for developing the theory of computation further. The choice of the initial functions and the operators is quite arbitrary and we have our first set of questions that can develop the theory of computation further. but we will give an idea of how the developments occur by giving a sample of questions (some of which have already been answered) that are asked. the theory of Partial Recursive Functions asks: Can we view a computational process as being generated by combining a few basic processes ? It therefore tries to identify the basic processes. This approach was pioneered by the logician Kurt Gödel and almost calculus. is the choice of the operators unique ? If different initial functions or operators are chosen will we have a more restricted theory of computation or a more general theory of computation ? 4. In this module. This model appears to be most mathematical of all.Science/courses/theory. Definition 2 the k-ary constant-0 function. called the initial functions. in fact all the models are equally mathematical and exactly equivalent to each other. (OR TRUE FALSE) 4.

We also write http://www. and . we have is used for giving a more . Thus of arguments . Inductive case: This schema is called primitive recursion and is denoted by . Base case: 2.computation/toc.ac. This schema is called function composition and . This schema is denoted by such that and the for is the least natural number and look out for the least of those holds. Thus .of. and each .Theory of Computation Lecture Notes Function forming Operators Definition 4 Generalized Function Composition: Given: Then: a new function .in/~amv/Computer. such that notation a given ``fixed'' is defined and . is obtained by the schema Definition 6 Minimization: Given: Then: a new function is obtained by the schema .iitb. is obtained by the schema: Sometimes the notation compact is denoted as Comp.html (12 of 37) [12/23/2006 1:17:43 PM] . When this schema is applied to a set Definition 5 Primitive Recursion: Given: Then: a new function 1.Science/courses/theory.cfdvs. we vary for which the (k+1)-ary predicate holds.

0. http://www. for instance division. etc. we determine if it is a regular function or not. The is referred to as the least number operator. on the initial functions is called the set of primitive recursive functions. These are all the regular functions that take 2 (1 + . there are computable processes that may not have values for some of the inputs. Conceptually. We have not been able to capture the aspect of computation where results are available partially. until we find an such that Now note that given some function we can check that it is primitive recursive. The initial functions and the function forming operations that we have defined until minimization guarantee a value for every input combination11. we need . then is computable. . If we want an exhaustive system for representing all the computable functions.e. the Consider the set of functions when 1) arguments.if a given function is regular! Accepting this assumption to be true would mean that we are still dealing with only well formed functions and an aspect of the notion of computability is not being taken into account. . The minimization schema is an attempt to capture this intuitive behaviour of computation .Science/courses/theory. Notice that this construction is based on ensuring that whatever existed earlier.1. The set of functions obtained by the use of all the operators except the minimization operator. but will not be a member of the list.Theory of Computation Lecture Notes to mean the least number such that is 0.1 Remarks on Minimization: We are trying to develop a mathematical model of the intuitive idea of computation. Our ability to construct such a computable function is based on the assumption that we can form a list of regular functions.i. After checking that the function is primitive recursive.computation/toc. exists for every . That is the set . given . We can. we can list out all the regular functions and then compare the given function with each member of the list. The next natural question is: can we check that it is recursive too ? But being recursive means that the minimization has been done over regular functions. they may be partial! Note that the inability to determine if is regular makes a partial function since the least may not necessarily exist and hence could be undefined even if is defined! In the interest of having an exhaustive system. we must further check if the minimization has been done over regular functions. This ability to construct the list was required to determine .ac. However. .in/~amv/Computer. we simply make it non-existent! We can surely have computable functions for which the may not exist even if were well defined everywhere. always construct a function that is computable in the intuitive sense. Such an to simply evaluate is said to be regular.of. if an every . therefore. However.iitb. Suppose all the possible regular functions are listed as which means for every such that for monotonically increasing . Note that has the property that an . then we either have to give up the idea that only well defined functions will be represented or we must accept that the class of computable functions that will not be completely representable . The set of functions obtained by the use of three operators on the initial functions is called the set of partially recursive functions or recursive functions.e. A simple way to construct a for the corresponding regular computable function that is not regular is to have function . we can bring this aspect of computability into our mathematical structure. for is monotonically increasing.check . ``Checking'' essentially means exists for that for our ``candidate'' function.html (13 of 37) [12/23/2006 1:17:43 PM] . i. we make the latter choice that the regular functions would not be listed12. .cfdvs. by not assuming an ability to determine the regular nature of a function.that sometimes we may have to deal with computational processes that may not always have a defined result. 4. Since and there is an 's are ordered.

Finally.3. they cannot be computed! To make things more difficult. i. The argument that there cannot exist such an algorithm goes as: If there indeed were such an algorithm. Theorem that this model of computation is exactly equivalent to the Turing model (to be introduced later). Theorem 6 A number theoretic function is partial recursive if and only if it is Turing computable. which is the same as the IF in the calculus.Theory of Computation Lecture Notes End Remarks By the way.we cannot have an algorithm to do the job. The problem is: Can we conceive an algorithm that can tell us whether or not a given algorithm will terminate ? The answer is: NO. For instance. In particular. Alternately.e.cfdvs. now if http://www. the regular functions cannot be listed14. The counting arguments extend to the set of rational numbers which are said to be countable. that would use this algorithm as follows: If (halt). the equivalences between the different perspectives of computation prompted Church and Turing to hypothesize16 that: Any model of computation cannot exceed the Turing model in power. 4. the situation becomes: halts if does not and does not halt if we use is asked to tell us if halts we land up in the following scenario: would does. we may not have a better model of computation. else would itself halt. Theorem 5 There exists a computable function that is total but not primitive recursive. consider the calculus model where Church numerals have been defined by explicitly invoking the counting method over: natural numbers again! Moreover.computation/toc. In general.1 What can and cannot be computed It can be argued in many ways that there are some problems which cannot have an algorithm.iitb.in/~amv/Computer.of. For instance. Now if an algorithm on itself. they cannot be computed. there is no mechanical procedure (an algorithm) that we can use to compute the limit of a given sequence15. can do both: primitive recursion and minimalization. i. 4. succ and zero and the operators as: Comp and Conditional have the same power as the above formulation. note that the partial recursive functions model of computation demonstrates uses natural numbers as the basis set over which computation is defined.2 The Halting Problem The classic demonstration of the fact that there are some processes which cannot have an algorithm comes in the form of the Halting problem. We also know by Theorem that this model of computability is equivalent to the Turing model! Hence it is also equivalent to the partial recursive functions perspective! Thus it appears that natural numbers and operations over them are the basic ``primitives'' of computation. it is also (hopefully) evident that the process that is used to refer to counting can actually be replaced by any procedure that operates over natural numbers. However. when irrationals are introduced into the system.e. we are unable to use the counting arguments to come up with a ``new''/``better'' model of computation! This means that the current model of computation is unable to deal with processes that operate over irrationals. they point out to the possibility that there may be some processes that are uncomputable .3 More Issues in Computation Theory The remarks on minimization in section ( ) give rise to a number of questions. In other words. This choice is due to John McCarthy and is the basis of the LisP programming language along with the calculus. say (unhalt). 4. a different choice of initial functions as: equal. For instance. say is certified to terminate by . the limit of a sequence cannot be computed. then loop infinitely. As yet this hypothesis has neither been mathematically proven. nor have we been able to come up with a better computation model! 4.i.3. reals and so on.html (14 of 37) [12/23/2006 1:17:43 PM] . for example the ``doubling'' procedure.e. then we could construct a process.ac. but infinite since they can be placed in a 11 correspondence with the set of natural numbers.2 Important Theorems Theorem 4 Every Primitive Recursive function is total13. the observations of the above paragraphs lead us to the fact that: there are processes which are not expressible as algorithms .Science/courses/theory. The Conditional.

5 Exercises 1. it might help to examine the consequences of the Mn operator. Notice that the primitive recursive functions .Science/courses/theory. we are required to find the least a given .i.i.of. Notice that the operator is defined using an existential process . 2.in/~amv/Computer. This amongst all possible for may or may not exist! The initial functions and other operators.are decidable.cfdvs.iitb. But this is the primitive recursion schema. The theory of partial recursive functions isolates this peculiar characteristic in the minimization operator Mn.e. Show that the addition function is primitive recursive. In situations when we need to be concerned of the solvability of the problem. may not prove to be so focussed.4 Worked Examples Q. Given the recursive definition of multiplication as: 1. Comp and Pr do not have such a peculiar characteristic! We refer to those problems for which an algorithm can be conceived as being decidable. A. Other models. This contradiction can only be resolved if algorithm that can certify if a given algorithm halts or not. The Halting problem demonstrates that we can imagine processes. In contrast to other models. We express the addition function over 1. Therefore.computation/toc. 4. the theory of partial recursive functions isolates the undecidability issue explicitly in the Mn operator. http://www. .ac. 2.e.Theory of Computation Lecture Notes halt only if would not halt (since makes a ``crooked'' use of ) and would not halt if does not exist . ]] 4. there can not exist an halts.html (15 of 37) [12/23/2006 1:17:43 PM] . mult(n. recursively as: Observing that: also express we can write as as . Hence addition : Pr[ . 0) = 0. though equivalent. Comp[succ. This illustrates that we can use the different models in appropriate situations to most simply solve the problem at hand.the initial functions with the Comp and Pr operators . We Hence we can write the recursive definition of addition as: 1. but that does not mean that we can have an algorithm for them.

cfdvs. The essence of this approach.that produce symbols17. = ``baba''. Consider a two member sequence of productions: 1. The set of all words over is called a language and typically denoted by or . . of alphabets from . 2. Thus. However.quite naturally called as production rules . in it's raw essence replaces one symbol by another. although it is no longer much in use. until it no longer applies.in/~amv/Computer.of. i. m) + n. languages like Perl . use the initial functions to show that multiplication is primitive recursive. first presented by A. 2. Markov. are excellent vehicles to study this approach and I believe that our abilities with Perl can be enhanced by the study of this approach. We will just mention that a language called SNOBOL evolved from this perspective. is that a computation can be looked upon as a specification of the symbol replacements that must be done to obtain the desired result. Hence. a set of (some) characters). m+1) = mult(n.which are very much in use in practice. rewrite rules. A word over is any sequence. We need to first introduce a number of concepts before we can show that Markov Algorithms can (and do) represent the computations of number theoretic functions. Then we repeat the process using the next rule. 5.computation/toc. Consider an input word. However.html (16 of 37) [12/23/2006 1:17:43 PM] . So we start applying the next rule starting from http://www. mult(n. The production rule can no longer be applied to . This is based on the appreciation that a computation process.iitb.e.Theory of Computation Lecture Notes 2. Applying a production rule means substituting it's right hand side for the leftmost occurrence of it's left hand side in the input word.Science/courses/theory. we apply rule to the input word to get as: We keep on applying rule to to obtain . Show the the exponentiation function (over natural numbers) is primitive recursive. 5 Markov Algorithms We now examine the third of our chosen approaches towards developing the idea of a computation .ac.Markov Algorithms. including the empty sequence . along the way we wish to show that the Markov Algorithm view of computation yields another interesting perspective: computation as string processing.1 The Basic Machinery Let be an alphabet (i.e. and the specification is made in terms of rules . By a Markov Algorithm Scheme (MAS) or schema we mean a finite sequence of productions.

If we encounter as terminal production. Note that for a given input.e.in/~amv/Computer. Rule Neither rule nor can be applied to . Note that the MAS captures a certain substitution process . The production rule is not applicable to . We are required to attempt applying it. it is possible that a terminal production rule may not be applicable at all! We repeat: For a terminal production. then we terminate and the resulting string is the output of the MAS.'' (dot) and is called as a terminal production.html (17 of 37) [12/23/2006 1:17:43 PM] . replacing every `b' by ). The substitution process stops at this point. The table below illustrates it's working for a few more input strings.Science/courses/theory.cfdvs. We write this as: ``baba'' effect of the above MAS is to replace every occurrence of `a' in the input by `c' and to eliminate every occurrence of `b' in the input. The string that remains is the output of the MAS. we start the process of applying the MAS again). continue to the next rule. The process that the MAS captures is called as the Markov Algorithm.computation/toc. Hence: it's inapplicability and continue to the next rule. MASs are usually denoted by and the corresponding Markov algorithms are denoted by . In summary. a MAS is applied to an input string as: Start applying from the topmost rule to the string. or if no left hand side matches are successful.e. http://www. There is another way an MAS can terminate for an input: we may have a rule whose application itself terminates the ``substitution process''! Such a rule is expressed by having it's right hand side start with a ``. The above ``cc''18.of.iitb. The general MAS has transformed the input ``baba'' to ``cc''. The substitution process terminates if the attempt to apply the last production rule is unsuccessful. Start from the leftmost substring in the string to find a match with the left hand side of the current production rule.ac.Theory of Computation Lecture Notes the leftmost character of . If a match is found. the substitution process ceases immediately upon successful application even if the production could yet be applied to the resulting word. then replace that substring with the right hand side of the production rule to obtain a new string which is given as the next input to the MAS (i. Worked example illustrates the use of a terminal production. determine is applicable to .that of replacing every `a' by `c' and eliminating `b' (i. If no substring matches the left hand side of the rule.

%. if if .also accepts Definition 10 A MAS (as well as ) accept a language L if accepts all and only the words in L. the words that go as input and emerge at the output of an MAS always come alphabet and the markers only are used to express the substitutions that need to be performed. and .0.cfdvs.iitb. or of the form 5. and a MAS as The MA corresponding to the above MAS appends ``ab'' to any string over . it responds negatively. Definition 9 Let 20. Consider . with . is a finite work alphabet with and is a where finite ordered sequence of production rules either of the form both and are possibly non empty words over .html (18 of 37) [12/23/2006 1:17:43 PM] . What will constitute an affirmative response must be separately stated in advance. $. Note that the output Definition 7 Markov Algorithm Schema: A Markov Algorithm Schema S is any triple where is a non empty input alphabet. string of the above MAS is necessarily a word from We now define a MAS formally.1 Using Marker Symbols in MAS: Sometimes it is useful to have special symbols like #. . then - the corresponding Markov Algorithm .2 Markov Algorithms as Language Acceptors and Recognisers This section mainly preparatory one for the ``machine'' view of computation that will be later useful when discussing Turing machines.Theory of Computation Lecture Notes 5. Since by computation we mean a procedure that is so clearly mechanical that a machine can do it. such as markers in addition to the . Definition 8 A machine19 accepts a language 1. the machine responds ``affirmatively''. or is said to be a recogniser. given an arbitrary word 2. A machine that responds negatively for We conventionally denote a machine state that accepts a word by the symbol 1. we frequently use the word ``machine'' in place of an ``algorithm''.in/~amv/Computer. be a MAS with input alphabet Then accepts a word if and a work alphabet . the machine does not respond affirmatively. A non affirmative response for would mean that either that the machine is unable to respond.Science/courses/theory.1. http://www.ac. The symbol 0 is used to denote the rejection state (for a language recogniser). The set from and forms the work alphabet that is denoted of markers that a particular MAS uses adds to the set by .computation/toc. Such an L is said to be Markov acceptable language.of. If MAS accepts . However.

if is applied to input word does not halt. then 2. we need to fix a scheme to represent a natural number using some symbols. then is also said to be recognise L. Worked example language .html (19 of 37) [12/23/2006 1:17:43 PM] . . or if S does halt. Let a natural number ( say Thus be represented by a string of s. . Then be a MAS with input alphabet recognises over if and work alphabet such that 1. provided that Definition 12 A MAS S computes a k-ary partial number theoretic function 1. http://www.Science/courses/theory. In other words. Thus . Worked example shows an MAS defines the computation of the function. and . 2. Theorem 7 Let f be a number theoretic function. the main theorem. and show a few MASs that compute partial number theoretic functions. where is not defined for . . then it's output is not of the form . then 1. 5. Worked example shows an MAS that recognises a recognizable. L is said to be Markov shows an MAS that accepts a language . (accepting 1) (rejecting 0) If a MAS recognises L.of. If an MAS Exercises exists that computes a number theoretic function. a symbolic representation scheme must be conceived to represent objects of the domain. is defined). A string is the set of non empty strings over ) will be termed as a numeral.4 A Few Important Theorems We state without proof.computation/toc.ac. either 2. 5. . where is defined for (i. To be applicable to a given domain the semantic entities in that domain must be symbolically represented.cfdvs. .Theory of Computation Lecture Notes Definition 11 Let .in/~amv/Computer. A pair of natural numbers. Then f is Markov computable if and only if it is partial recursive. . will be represented by the corresponding numerals separated by . .iitb. To express number theoretic functions.e. then the function is said to be Markov computable. if is applied to input word yields .3 Number Theoretic Functions and Markov Algorithms The MAS point of view of computation views computations as symbol transformations guided by production rules.

= ``baba''.ac. 3.in/~amv/Computer.'') 3.cfdvs. where and and is: http://www. 3. Let . (Note the ``. we have: Given the input word 2. Consider the alphabet and the MAS given by: 1. Let 1.5 Worked Examples 1. 2.Theory of Computation Lecture Notes 5.of.iitb.html (20 of 37) [12/23/2006 1:17:43 PM] . Consider an input word = ``abab''. where and and is: .computation/toc. The above MAS accepts .Science/courses/theory. 2.

cannot recognise a word that is not in .of. Let 1. 5. Consider the MAS given by theoretic function does this MAS compute ? 5.in/~amv/Computer. 2. ``baaa'' and ``abcd''.ac. What partial number theoretic functions do the following MASs compute ? where is: . Check that worked example 3. 3. Apply the MAS in worked example to the input words: ``aaab''. 4. 3. 2. 4.computation/toc.html (21 of 37) [12/23/2006 1:17:43 PM] .cfdvs. Check that worked example can accept a word in as well as reject a word that is not in 4. 5. 6. http://www. The function: This is defined by the MAS and of an be (i) . Consider an input word = ``aba''. where is: . The above MAS recognises .iitb. 2. 4. 7. and . 1. What unary partial number .6 Exercises 1.Theory of Computation Lecture Notes 1. 8.Science/courses/theory. 2.

This view of computation is called as the language recognition perspective of computation. reads the same backwards or forwards) or not. We will draw parallels to the other models of computation if possible.of.e. Note that by a language we simply mean the set of words that are generated from some given alphabet.iitb. Thus a simple machine would recieve an input and produce the set http://www. Turing in the thirties with a view to mathematically define the notion of an algorithm. On the face of it. During this time Gödel had presented his famous Incompleteness theorem and was formulating the partial recursive functions approach to computation.Science/courses/theory.ac. The Turing model.cfdvs. Their interest was more in the foundational problems of Mathematics. 6. The idea is to develop the concept of (abstract) machines starting from ``simple'' ones.computation/toc. as alluded to earlier. say .html (22 of 37) [12/23/2006 1:17:43 PM] .1.a (symbol) transduction view of computation. 4. An algorithm that successfully does this is said to recognize . though a rigourously mathematical model.e. He concretely imagined ``mechanical computation'' being carried out by humans. To get an idea of how the function computation paradigm looks like from this perspective consider the problem of determining if a natural number is a prime number. It was conceived by Alan M. 6 Turing Machines This model is the most popular model of computation and is what is normally presented in most undergraduate and graduate texts on Computation theory. 5. we will meet a number of useful intermediates.1 On the Path towards Turing Machines We develop the notion of a Turing machine in steps. never both. would simply recognize an input from a set and produce an output from . The set of all primes is the language question: ``is prime ?''. i. The calculus was a function computation view. Notice that the algorithm divides all possible words that can be given as input into two sets: the set of palindromes and the set of words that are not palindromes. while the Markov Algorithm approach transformed a given input symbol to an output symbol . Along the way. therefore has a certain ``technological'' appeal that makes it21 attractive as the initial candidate for presenting the theory of Computation22. Interestingly. Our purpose here is to emphasize that there appear to be problems that are not numeric in nature. He viewed those foundational problems in Mathematics in terms of purely mechanical computation that could be carried out by a machine. times. called ``computers''. with a gradual increase in capabilities. 3. We first construct a ``string representation'' of a natural number: will be represented by a string of s. Alan Turing also was motivated by the foundational issues. We will spend some time in it's study as most development in theoretical Computer Science has occurred with this perspective. i. Consider the problem of determining if a given word. is equivalent to asking: ``is it true that ?'' . is a palindrome (i. The algorithm that can tell us if a given word is a palindrome or not is quite straightforward. this model appears to present a view of computation that does not seem anything like computing the value of a function. Turing was working with Church during that time. It appears to ``classify'' the word at input as belonging to either one of these sets. However. His model of computation therefore gives a rather ``materially'' imaginable view of computation. and is written as A natural number for short. neither Church nor Gödel were motivated to consider computation explicitly.e. his approach makes an explicit use of the idea of mechanical computation. The 6. 2. The language recognition view involves determining if an arbitrary word belongs to some language or not. who would perform the steps of the algorithm exactly as specified without using any intelligence. and is given in advance.Theory of Computation Lecture Notes 1.1 Basic Machines A machine at it's simplest. The sets and are finite.in/~amv/Computer.

For instance. a simple machine cannot alogrithmically add two bit numbers. the Once the starting state machine behaviour is defined.Theory of Computation Lecture Notes an output.( ) shows the picture.of.the binary adder. Let be the set of possible configurations of a finite internal memory. in turn. As pointed out above. turn to a more formal description of finite state machines.cfdvs.1. It has no memory to react on the basis of past history. We can pictorially depict the operation of an FSM using a transition graph (also called as a transition diagram or a state diagram). therefore. To do so would require remembering the necessary carry digits.ac. ``Remembering past history'' would mean that the output produced would depend on both . Consider the problem of designing a machine that performs addition of binary numbers . transition graphs become quite unwieldy when the number of states increases. The labelled circles represent (internal) states and the directed arcs labelled represent that the input 23.iitb. a logic gate like (say) the AND gate would be a simple machine. a simple machine looks up a table of finite size. would be used in a future output. A binary adder http://www. The basic machine would be represented by a simple function that maps the input to the output.( ) is called as the machine function and Eqn. we can simply tabulate the output to be produced for a given input. We. For instance. While a picture is worth a thousand words. Figure:Transition Graph for a Binary Adder Machine Fig.in/~amv/Computer.2 Finite State Machines (FSMs) If we add an internal memory to a basic machine then we can build a machine that performs addition algorithmically since now the carry digits can be remembered locally. In essence. a simple machine is unable to do more complicated tasks. It's signature would be: 6.computation/toc. Further. A machine with an internal state is called a Finite State Machine (FSM). A simple machine just responds (as opposed to reacts) to the current input stimuli.html (23 of 37) [12/23/2006 1:17:43 PM] . and are: ) is the state function. But a simple machine has no memory to remember the past history! All it can do is look up a table of the size and emit out the sum for the given input pair of numbers. in the form to state causes an output and the input and shifts the state are given.( machine would be desgined as follows: The sets .Science/courses/theory. As a result. a FSM is described by two functions whose signatures are: Eqn. the given input could change the internal memory state which.the input set and the internal memory state .

the existence of a memory has permitted us to react rather than just respond. all the behaviour is completely deterministic .Theory of Computation Lecture Notes The machine function is: Table:Machine function for the Binary Adder machine. The entries in the table are the values from the set for various combinations of . Also. Note that the finiteness of the sets . However.e.computation/toc.iitb.ac. The state function is: Table:State function for the Binary Adder machine. the machine behaviour can still be tabulated for every possible configuration. consider designing a machine that can check if the natural number at it's input is divisible by three.of. The sets. The entries in the table are the values from the output for various combinations of . and will limit our abilities. As another illustration.i.Science/courses/theory.cfdvs. since the machines are designed using finite sets.in/~amv/Computer. the machine function and the state functions are: http://www. and we will overcome this aspect when we consider Turing machines.html (24 of 37) [12/23/2006 1:17:43 PM] .

and reject others. That is obvious because FSMs are finite and impose an upper limit on the length of the word that can be given at the input.in/~amv/Computer. the empty set) is a regular set. Every finite set of words over (including and are regular sets over . Table:State function for the Divisibility-by-ThreeTester machine. in the present case is just the set of natural numbers . but cannot recognize others. We will take up Turing machines in a short while. Finally. it is possible to construct a MAS that recognizes palindromes. FSMs cannot be used to recognize palindromes of any size. The entries in the table are the values from the output for various combinations of . not otherwise. With being the set of all words generated from . Table:Machine function for the Divisibility-by-ThreeTester machine. The machine recognizes a number that is divisible by three as whenever the machine is finally in state for a given input.1. We have been calling the set as the alphabet set and the numbers that are generated as finite sequences of alphabets as words. 6. In contrast.Theory of Computation Lecture Notes The machine function is given in Table ( ) and the state function is given in Table ( ). The entries in the table are the values from the set for various combinations of .are also regular.cfdvs.html (25 of 37) [12/23/2006 1:17:43 PM] .computation/toc.Science/courses/theory.iitb.ac. 0 otherwise. we observe that a number at the input is a sequence of symbols from the set .3 Regular Sets and Regular Expressions As we have seen in the previous section. We also say that the machine decides if it's input is divisible by three. called regular sets. The Divisibility-by-Three-Tester machine will be in state if the number at it's input is divisible by three. we can surely say that the input is divisible. FSMs can recognize some kinds of sets. Arbitrarily long sequences of symbols can be remembered using an external countably infinite memory. We need not actually examine the machine state! The machine is said to accept numbers that are divisible by three. .of.the concatenation . We face the question: What kinds of sets are recognised by FSMs ? A special class of sets of words over defined recursively as follows: Definition 13 1. If . is recognized by FSMs24and is http://www. and . while the algorithm to recognize a palindrome has to deal with a countably infinitely long sequence of symbols. Adding such a memory to an FSM gives us the Turing machine. Notice that the output is 1 if the number is divisible. then 2. That is because the MAS is not restricted to an upper limit of the word length.

where union operation). given a regular expression. . . and indicates alternation (parallel path. i. The regular expressions are only those that are obtained by using the above three rules. This can also be cast as a (behavioural) language that is used to express regular sets and the FSM. and 25 are regular expressions over .Theory of Computation Lecture Notes The UV = {x 3. .Science/courses/theory. corresponds to the set ). scanners in compilers etc. If . sed. The alphabets.e. grep. then so is it's closure . http://www. The FSMs that correspond to the basic operations of alternation. we can write the regular expression. concatenation and closure are show in Fig. and denotes iteration followed by (closure. . The above definition of regular sets captures the notion of regular behaviour of objects. The operation defines on a set .iitb. then . we can create it's FSM transition graph and given a FSM transition graph. If x = uv. In other words. If and . This conversion forms the basis of programs that manipulate regular expressions.e. then so are or . zero or more of 4. We take a set of alphabets. Every alphabet 3. a derived set having the empty word and all words formed by concatenating a finite number of words in S. .( ). Figure:The basic operations and their FSMs.of.computation/toc. either denotes concatenation (series. No set is regular unless obtained by a finite number of applications of the above three definitions. 2. a set consisting of the empty word.cfdvs. ( is the empty word symbol) and 4. ). is a regular expression over are regular expressions over . for instance the Unix shells sh/csh/bash.ac.html (26 of 37) [12/23/2006 1:17:43 PM] . of two subsets is in U and is in V} and of is defined by: is a regular set over .in/~amv/Computer. The correspondence between regular expressions and regular sets is as follows: Every regular expression over describes a set of words over (i. Notice that these can serve as the ``building blocks'' to convert a regular expression to it's transition graph and vice versa. and define regular behaviour recursively as follows: Definition 14 1. ) as follows: 1. where for .

Hence well formed parentheses . then . . This periodicity results in a useful characterisation of FSMs . we can find a substring near the beginning that may be repeated (pumped) as many times as we like and the resulting string will still be accepted by the FSM. To illustrate this. or produce a sequence of states. A way of overcoming the limitations of FSMs is to introduce infinite memories.in/~amv/Computer.iitb. if 3. every input sequence will end up in some state. then are regular expressions over .4. mere ``inifiniteness'' of the memory is not sufficient.1 Periodicity : FSMs lack of capacity to remember arbitrarily large amounts of information as there are only a finite number of states.1. . All input sequences that reach the same state are grouped as one.4 Impossibility of Palindrome Recognition : A palindrome is a string that is symmetric . a certain ``freedom'' to use the memory is also required. then . an FSM will eventually repeat a state.1.1.it reads the same both ways.1. Also. we introduce a machine called as the Push Down Stack Memory Machine (PDM) that overcomes the limitations of FSMs by using an infinite memory. The lemma simply states that given any sufficiently long string accepted by an FSM. if and . which describe the set of words . However. a machine would need an infinite memory to remember all the alphabets read for later comparison of symmetry.4. In contrast. } and . 6. This is because a FSM is finite and hence a limit is imposed on the length of the product.1.4.html (27 of 37) [12/23/2006 1:17:43 PM] . If 3.cannot be checked. However.cfdvs.Science/courses/theory.5 Impossibility of Checking Well-formed Parentheses : The periodicity of an FSM implies that input sequences whose periodicity is greater or sequences that are not periodic cannot be accepted by a FSM since the FSM just does not have those many states. If 4.the Pumping Lemma.3 Impossibility of Multiplication : It is impossible to carry out multiplication of arbitrarily long sequences of numbers using an FSM. We can classify input sequences in terms of the states they reach.4.4. 6. 6. An FSM thus induces an equivalence class partitioning over the set of input sequences.ac.computation/toc.2 The Pushdown Stack Memory Machine FSMs are limited due to their finite memories.4 Properties of FSMs 6.1.of. concatenation and closure.is possible! Note that multiplication requires remembering the intermediate ``products'' for later addition. 6.2 Equivalence Class of Sequences : Two input sequences and are equivalent if the FSM is in the same state after executing them.balanced brackets . To recognise an arbitrarily long palindrome. If 1. then Remark 1 It is possible to define an enlarged class of regular expressions that have intersection and complementation over and above the operations of union. if 2. This finiteness defines a limit to the length of the sequence that can be remembered. then . Because the number of states are finite in an FSM. 6.Theory of Computation Lecture Notes 2.binary addition . the use of memory is restricted in that the memory must be used as a http://www. addition . then . The finiteness of FSM does not permit such a memory and hence a FSM cannot recognise a palindrome 6. the empty set.

Textually.that can appear on the tape. And secondly. we need to evolve notation to describe the details like the symbols .( )). onto a cell of an external tape (Fig. the machine halts.3 The Turing Machine Figure:The Basic Turing Machine. Note that the starting position is merely one of the states. to move .g. The symbols are first laid out on the tape starting from the left. in advance. To actually work with the machine scheme in the previous paragraph. we wish to describe the instantaneous configuration of the machine which is made up of the head position on the tape and the alphabets on the tape. If the head encounters a blank cell. As a result of reading the alphabet on the tape.alphabet . the starting position of the head. These machines are routinely applied to recognise context free grammars26 of programming languages and are not as powerful as TMs. It may then move one cell either to the left or to the right27.cfdvs. The Turing machine operates as follows: the each cell can contain one and only one symbol from head reads the symbol from the cell currently under it and responds to that symbol by either writing another symbol at the cell or not writing anything at all. the response of . the machine may write back or move it's head or do both. we wish to indicate that some interesting and useful intermediates after FSMs but before TMs are possible.e. http://www.iitb. We are required to specify. we would invite you to explore and find out the properties of PDMs.). For instance. The tape is an infinite sequence of cells. we can have Table: responses of a Turing machine for an alphabet with symbols.i. the next questions could be like: what other kinds of ``restrictions'' on memory use are possible and what are the properties of the machines they give rise to ? 6. The external tape is initially blank. By state of the machine.the head to every symbol that it reads.Science/courses/theory.computation/toc. This behaviour is described as Last In First Out and abbreviated as LIFO. where His the head. The machine response thus takes the machine into the next state which could be identical to the earlier one or a new one. what to write and where.Theory of Computation Lecture Notes stack. a detailed tabulation of the responses etc. Our purpose in mentioning them here is two fold: on the one hand. if at all. A stack is a structure where the removal of objects from the memory is performed in the reverse order of their arrival into the memory. .ac. Given a set responses as follows: of alphabets.of. The Turing machine is pictured as being composed of a head that reads and writes symbols from a set of alphabet. the above figure would be represented as: BHaaaB.html (28 of 37) [12/23/2006 1:17:43 PM] . . Could a PDM solve it ? What problems would not be solved even by a PDM ? Naturally.in/~amv/Computer. FSMs were known to be unable to solve certain problems (balanced parentheses e.

iitb.in/~amv/Computer. Note that the initial tape contents and the initial head position are specified by . is the set of states. For . and at least one of those states is a distinguished state the start state . . Thus we also write: the above quadruple.ac.that takes in the state and the alphabet being for scanned and returns the action and the new state. Figs. usually. This is to be interpreted as: the machine must write a and then enter state .cfdvs. Each circle represents a state of the machine. The ``arcs'' of the state diagram (look like straight lines here) are labelled by the instructions of the machine. where an argument. The machine goes to the state pointed to by the arc when it recieves the instruction labelled by the arc when in state from which the arc originates. This quadruple is called as an instruction (of view an instruction as a function .computation/toc. The machine state - blank B it is currently scanning with the symbol has been specified in advance to be a head over some cell of an entirely blank tape. Since captures the ``motion'' from one state to another it is referred to as the transition function.Theory of Computation Lecture Notes The operation of a Turing machine is read as: If state instance the right and enter state reading symbol can be described by a quadruple: then perform action and enter state . . we can . . Alternately. The first arc in Fig.html (29 of 37) [12/23/2006 1:17:44 PM] . Consider the following figures that describe a Turing machine.denoted by or . The starting state is denoted by ) is labelled and points to state and is drawn to the far left. This would mean that if in state reading symbol .Science/courses/theory.of. . Figure:Turing machine in state Figure:Turing machine in state Figure:Turing machine in state Figure:Turing machine in state Figure:Turing machine in state . is not a number theoretic function since it takes state/symbol pair as . then move head one cell to ). Figure:Transition diagram of a Turing machine . http://www.( ) pictorially depict the machine in each of the above states. It's domain is therefore.denoted by .( .

It has been instructed that if in this state it scans a blank. then it must since there are no instructions! Also. Finally. then it writes a .iitb. if it reads a to the left and enters state . Here if it reads (i. it moves one cell to the right and enters state . we will use a textual notation to describe the machine configuration. as suggested in the caption to Fig. and the current head position. We say that the tape configuration is to be completely blank initially.cfdvs. it writes an .Science/courses/theory.1 Formal Definitions 6. it writes the word ``ab'' and halts scanning the symbol ``a''.Theory of Computation Lecture Notes The working of the machine can now be described. There are no further instructions. and the machine starts scanning a non-black symbol. It starts from a state where the head is positioned on some cell of an entirely blank tape. then it is to write an and enters state and enters state on that cell and enter state .of. scans) a blank (it does). Since it does scan a blank. Now in this state.in/~amv/Computer. In this state.3. In general.( is halt immediately in state ). 6. Hence the machine halts in state In summary.1.ac.1 Basic Definition: http://www. . Note that if the tape configuration at is not completely blank.html (30 of 37) [12/23/2006 1:17:44 PM] . the state often abbreviated to just in state diagrams. the contents of the tape together with the location of the head for a given Turing machine is referred to as the tape configuration. when it scans and reads an . the machine behavior is: When started scanning a cell on a completely blank tape.3. The tape configuration and the current machine state is referred to as the machine configuration.computation/toc.which it does .e.then it moves one cell .

but halts scanning a 0 on an otherwise blank tape if . where .we will separate the arguments by a single blank. is the initial state of M. then M ultimately halts scanning a 1 on an otherwise blank tape is . and only the words w in L. If w is an arbitrary nonempty word over tape that contains w and is otherwise blank.g. M ultimately halts scanning a 1 on an otherwise blank tape.3.cfdvs. .2 Turing machines as language recognizers: We define the notion of language acceptance and rejection to introduce the language recognition paradigm for Turing machines. When we need to design a machine for functions that take more than one argument .in/~amv/Computer. If M started scanning the leftmost 1 of an unbriken string of followed by an unbroken string of unbroken string of 1s followed by a single blank followed by an 1s followed by a single blank 1s followed by a single blank on an otherwise blank tape. Definition 17 A Deterministic Turing machine M accepts a language L. 2. . then M ultimately halts scanning a 1 on an otherwise blank tape if . A Deterministic Turing machine M and M is started scanning the leftmost symbol of w on a 1.of. 6.Theory of Computation Lecture Notes Definition 15 A deterministic Turing machine M is anything of the form where and is a non empty finite set.ac. but halts scanning a 0 on an otherwise blank tape if . when started scanning the leftmost symbol of w on an input tape that contains w and is otherwise blank. Definition 19 A Deterministic Turing machine M computes a k-ary partial number theoretic function f with provided that: 1. when started scanning a blank on a completely blank tape. 6. M ultimately halts scanning a 1 on an otherwise blank tape. and illustrate the construction of Turing machines for this paradigm.1. It accepts an empty word is.3. is the input alphabet of M and is its tape alphabet (or auxilliary alphabet) and is the transition function. . is a (partial) function with domain and codomain given by Q is the set of states of M. then M halts scanning the leftmost 1 of happens to be defined for arguments http://www.Science/courses/theory.computation/toc. we need to decide a scheme to represent natural numbers of a tape. If M is started scanning a cell on a comlpetely blank tape. Worked examples .iitb. and are non empty finite alphabets with . A language L is said to be Turing acceptable if there exists some deterministic Turing machine M that accepts L28. Definition 18 Let L be a language over alphabet recognizes language L if: 29. Definition 16 A Deterministic Turing machine M accepts a nonempty word w if. if M accepts all.1. A language L is termed Turing recognizable if there exists a Turing machine M that recognizes L. addition . As discussed in section ( ).e. . We represent a natural number by a string of s.html (31 of 37) [12/23/2006 1:17:44 PM] .3 Turing machines as function computers: We define computation of partial functions to introduce the function computation paradigm for Turing machines.

.i.computation/toc.iitb. the computation process generated by a Turing machine Theorem 10 It is not possible to decide . .0. Definition 20 A partial number theoretic function a Turing machine M that computes . 1s followed by a single blank followed by an 2. Since we have already mentioned that the other perspectives of computation are equivalent to the Turing view.cfdvs. is said to the Turing computable if there exists Worked example illustrates the construction of Turing machines that compute functions. have an algorithm . It is a self reproducing machine. In other words.Science/courses/theory. 6.asserts this to be true. If M started scanning the leftmost 1 of an unbriken string of followed by an unbroken string of unbroken string of 1s followed by a single blank 1s followed by a single blank on an otherwise blank tape.a universal machine .Theory of Computation Lecture Notes an unbroken string of 1s on an otherwise blank tape.to which we describe our desired machine as a program.4. we present the notion of a Universal Turing machine. we do not state any theorem of equivalence at this point. can write it's own description. then M does not halt scanning the leftmost happens to be not defined for arguments 1 of an unbroken string of 1s on an otherwise blank tape. 6.3. Theorem 11 It is not possible to decide if two Turing machines with the same alphabet are equivalent or not. This is why we can have a computer .4 Turing machines as transducers: Worked example illustrates the construction of a Turing machine that works according to the transduction view of computation.whether a Turing machine will ever print a given symbol . In particular. .of.1 The Universal Turing Machine (UTM) Theorem 12 There exists a Universal Turing machine. where . http://www. we can have a single machine to which we merely provide descriptions of the Turing machines we want it to behave like. this means that we cannot decide the equivalence of two arbitrary programs.in/~amv/Computer.ac. 6. Note that: computes some unary partial Remark 2 Every Turing machine with input alphabet number theoretic function.e. This connection with program equivalence is possible because of the notion of an UTM discussed below. An UTM would behave exactly as the Turing machine that has been described to it. The question is: is it possible to have a Turing machine describe other Turing machines ? The following theorem . Theorem 9 The Halting problem: There does not exist a Turing machine that can decide if will halt. Observe that the formal definition of a Turing machine is simply a scheme of describing machines.1. Instead.html (32 of 37) [12/23/2006 1:17:44 PM] .due to Alan Turing .4 A Few Important Theorems Theorem 8 The Blank Tape Theorem: There exists a Turing machine which when started on a blank tape.

in/~amv/Computer. mark it and search for the companion symbol.ac. number of s in of s in number of s in . If no more pairs exist and no more symbols exist. i. for an initial machine configuration .6 Worked Examples 1. The grammars of most programming languages that we use are CFGs and hence their parsers are PDMs. and does not appear on the right hand side of a production. Such grammars are called as Context Free Grammars (CFGs) and PDMs recognise the sentences generated by such grammars. It is known that Panini.e. 4. If we place gradual restrictions on the way production rules are to be ``designed'' we have a correspondence between the grammar and the machine that recognises the grammar. then it must again be replaced by the same marker. These grammars are identical to regular expression languages and FSMs recognise the sentences they generate. Start symbol is allowed to appear in the RHS of the rule. the machine is required to halt in Solution: To design the machine. If the companion symbol is found.( )) would be required to operate as follows: to halt with http://www. Because the replacement as prefix and as suffix. 6. [Type 0] No restrictions on the production rules. The basic idea is to eliminate s and s in pairs until either: (i) every symbol has been eliminated. then our machine has told us that the given input had the same number of s and s. This is the kind of grammar that we have studied in Markov Algorithms. or (ii) some symbol is eliminated for which no companion is found. Markov Algorithms are equivalent to Turing Machines! 2. There are four classes of grammars: 1. [Type 3] The productions of this class of grammars have a non terminal on the LHS and at most one non terminal on the RHS. it tells us that the number of s was different from the number of s. To find a pair of and . These classes of grammars was first proposed by Noam Chomsky and is called as the Chomsky hierarchy. 3.Theory of Computation Lecture Notes 6.of. we also see that the various machines that we have encountered while developing the Turing machine view of Computation correspond to certain restrictions on the production rules of Markov Algorithm Schema. the grammar is said to is dependent on the occurrence of be Context Sensitive Grammars (CSGs). Then for a word . This process must be repeated over every pair30. The machine (Fig.Science/courses/theory.in other words.html (33 of 37) [12/23/2006 1:17:44 PM] . TMs are required to recognise sentences generated by these grammars . the configuration . i. Notice that the tape of the machine will contain only the marker symbol and blanks if and only if the number of s and s are same! Let us use the as the marker. [Type 1] Two restrictions are imposed: (i) production rules are of the form (ii) the start symbol of by . the production rules are of the form . the Sanskrit grammarian has defined the Sanskrit language in terms of formal production rules in the same spirit as the above formal language theory[3]. the Turing machine halts scanning a single on is equal to the number of s in . an otherwise blank tape if and only if the number of s in For instance. From the description above.5 Chomsky Hierarchy and Markov Algorithms The Markov Algorithm view of Computation was in terms of production rules that specify the output symbol to replace an input symbol.computation/toc. A class of machines called Linearly Bounded Machines (LBMs) are required to recognise sentences generated by these grammars. They are called Regular Grammars.cfdvs. Same number of s and s: consisting of This machine behaves as: When starting scanning the leftmost symbol of word an unbroken string of s and s in any order. [Type 2] The left hand side of each production rule is a non terminal symbol. number of s in number . Otherwise. we first ``think'' of an algorithm. we must have the machine scan a symbol.iitb.e. we want the machine .

computation/toc.Science/courses/theory. we replace it by a blank and move right.cfdvs.( ). etc. The states 0. If on the other hand. then we must take the machine state into a completely different ``cycle''. That is what is essentially done in Fig.of. Strings like should not http://www. . 1 and 2 accept the word if it is in . replaced it by a blank and moved right. else the machine operates in the other states. we do not care as it is just an acceptor machine. These are strings of the form be accepted. then we must have the machine in the same state. 2.ac.iitb. Machine that accepts : The problem is to design a Turing machine that accepts words from the language . 3. This other ``cycle'' may or may not halt the machine. A state with a pair of concentric circles denotes the endstate. If we have read an . in this example is the end state. i.html (34 of 37) [12/23/2006 1:17:44 PM] . the machine reads anything but an .Theory of Computation Lecture Notes Figure:Turing machine that detects same number of s and s in an input word. Solution: As long as we are reading an . 4 and 5.e.in/~amv/Computer. .

3. then we must have the machine in the same state. we must have this other ``cycle'' terminate in a rejecting state. while the others reject it if otherwise. 1 and 2 accept a valid word in . . That is what is essentially done in Fig. however.cfdvs. The states 0. If we have read an .of.in/~amv/Computer. we replace it by a blank and move right.computation/toc. The succ function computer: Design a Turing machine that computes the successor of a natural number given on it's tape. For a recognizer machine.Theory of Computation Lecture Notes Figure:Turing machine that accepts . Machine that recognizes : The problem is to design a Turing machine that recognizes words from the language .ac. then we must take the machine state into a completely different ``cycle''. If on the other hand. where the machine ends up writing a 0 on the tape.Science/courses/theory. 4.iitb. replaced it by a blank and moved right. Solution: Starting from the leftmost of the number.( ). http://www. Strings like should be rejected. A natural number is represented as an unbroken sequence of s (as in an MAS). the machine reads anything but an . etc. Solution: As long as we are reading an .html (35 of 37) [12/23/2006 1:17:44 PM] . These are strings of the form . we keep moving to the right until we scan a blank. Figure:Turing machine that recognizes .

7 An Overview of Related Topics A number of other models of computation exist. although I know of no evidence that the theory of computation was known to the ancients.a contemporary of Newton. Design a Turing machine that multiplies two natural numbers. Register machines and the Abacus.in/~amv/Computer. for instance Prolog which is based on Logic with Horn clauses.html (36 of 37) [12/23/2006 1:17:44 PM] . the diagram is incomplete.computation/toc.Theory of Computation Lecture Notes At this point. Solution: See Fig. Attempts at understanding the nature of algorithms has a long history too.iitb.Science/courses/theory. Some have even been ancient. and others are used to develop hardware concepts. for instance the Register machine. Some models have been used to construct programming languages. Leibnitz . By the way. attempted to understand it too. The Copying machine: The Copying machine problem is to design a Turing machine that given a string on the tape. Figure:Turing machine that copies it's input word. for example. The state diagram of the machine is shown in Fig. we may consider the act of writing programs as designing specific machines. Design a Turing machine that adds two natural numbers.ac. Logic with Horn clauses. writes a copy of the string after the string separated by a blank. (Hint: Use the copying machine and the representation scheme. we simply write a in place of the blank and stop.of. Figure:Turing machine that computes the succfunction. Thus if the copying machine receives as input. http://www.( ). like the Abacus. it outputs .cfdvs. we have a variety of approaches to solve programming problems. 6. In fact. Please complete it. Given the variety of different models.7 Exercises 1. The Russian mathematician. 5.( ). 2.

iitb. Finally. This view gives us the functional paradigm of programming.ac. we ought to select the paradigm that best suits the problem at hand. On the other hand. R.Science/courses/theory.iitb.dcs.cfdvs.in/~amv/Computer.1 Computation Models and Programming Paradigms The calculus approach views computation through an explicit consideration of the behavioural aspects of objects that can undergo computation.ac. 7.html. a view that gives us the transduction (of input symbols to output symbols) paradigm. in © Abhijat Vichare Disclaimer Last Site Update: Nov. gives us the procedural view of programming. Oxford University Press.of.html (37 of 37) [12/23/2006 1:17:44 PM] . Gregory Taylor. We know that all these approaches are equivalent and there should be no reason to prefer one over the other. Abhijat Vichare 2005-11-09 Email: amv[at]cfdvs. 1983.Theory of Computation Lecture Notes 7. Krishnamurthy. 2 Introductory Theory of Computer Science. 3 http://www-groups.st-and. 09. the explicit consideration of the actions involved in computation the Turing approach. 1998. practice deviates from such ``ideal'' considerations and we find the procedural style dominantly used in software development.2 Complexity Theory 8 Concluding Remarks Bibliography 1 Models of Computation and Formal Languages. the Markov algorithm perspective views computation as symbol transformations explicitly.ac.uk/ history/Mathematicians/Panini. V. East-West Press. 2005 http://www.computation/toc. However. E. Indeed.