Theory of Computation - Module 1

Size: px
Start display at page:

Download "Theory of Computation - Module 1"

Transcription

1

2 Theory of Computation - Module 1 Syllabus Proving techniques- Mathematical induction - Diagonalization principle - Pigeonhole principle - Functions - Primitive recursive and partial recursive functions - Computable and non computable functions - Formal representation of languages - Chomsky classification Contents I Introduction 3 1 Origin of Theory of Computation II Proving Techniques 3 2 Principle of Mathematical Induction Diagonalization Principle Pigeonhole Principle III Recursive Function Theory 10 5 Primitive Recursive Functions Basic Functions Operations Partial Recursive Functions IV Computable and Non-Computable Functions 20 7 Computable Functions Non-Computable Functions V Formal Representation of Languages Formal Definition of a Grammar Formal Definition of a Language Chomsky Classification of Languages

3 3 Part I. Introduction The subject Theory of Computation is a core part of Computer Science. The aim of this subject is 1. to familiarize students with the foundation and principles of computer science, 2. to teach material that is useful in subsequent courses (compiler design, algorithm analysis), 3. to strengthen students ability to carry out formal and rigorous mathematical arguments. This subject includes topics such as automata theory, languages, grammars, computability and complexity. These constitute the theoretical foundation of Computer Science. The field of Computer Science includes a wide range of topics from machine design to programming. But all these have some common underlying principles. To study these principles, we construct abstract models of computers and computation. The ideas we discuss in this subject have some immediate and important applications. For example, the fields of digital design, programming languages and compilers are the important examples. Also it has applications in operating systems to pattern recognition. This subject provides many challenging, puzzle like problems that can lead to many sleepless nights. 1 Origin of Theory of Computation Always man was interested in creating machines to ease human labour. In 16th century, Pascal invented a computing device. In 19th century, Charles Babbage built an analytical engine that performed computations without human intervention. In 1930s, mathematicians and philosophers thought of an ideal model which has features of computation as an intelligent activity. A. M. Turing brought the idea of a machine called Turing Machine. This turing machine is a model of automatic computation. This led turing to propose a thesis called Turing thesis. Turing thesis states that any computable function can be solved by a Turing machine. Then only in 1950, it was able to create a computer based on this model. In 1943, Prof. McCullough brought the model of finite automata. [this will be learned in detail in Module 2]. finite automata has a large number of applications including lexical analysis in compilers, text editors (example: notepad, kwrite), special purpose hardware design, control unit design etc.. Prof. Noam Chomsky proposed a mathematical model to specify the syntax of natural languages. This resulted in formal language theory. A grammar called context free grammar was proposed for programming languages. Languages, Grammars and automata form three fundamental ideas of theory of Computation.

4 4 Part II. Proving Techniques [Pandey2006] An important requirement for learning this subject is the ability to follow proofs. There are three fundamental techniques to proof. They are, 1. Principle of mathematical induction, 2. Pigeonhole principle, 3. Diagonalization principle. 2 Principle of Mathematical Induction Let we want to show that property P holds for all natural numbers. To prove this property, P using mathematical induction, following are the steps: Basic Step: First show that property P is true for 0 or 1. Induction Hypotheis: Assume that property P holds for n. Induction step: Using induction hypothesis, show that P is true for n+1. Then by the principle of mathematical induction, P is true for all natural numbers. Examples Example 1: Prove using mathematical induction, n 4 4n 2 is divisible by 3 for n>=0. Basic step: For n=0, n 4 4n 2 =0, which is divisible by 3. Induction hypothesis: Let n 4 4n 2 is divisible by 3. Induction step: (n + 1) 4 4(n + 1) 2 = [(n + 1) 2 ] 2 4(n + 1) 2 = (n 2 + 2n + 1) 2 (2n + 2) 2 = (n 2 + 2n n + 2)(n 2 + 2n + 1 2n 2) = (n 2 + 4n + 3)(n 2 1) = n 4 + 4n 3 + 3n 2 3 4n n 2 = n 4 + 4n 3 + 2n 2 4n 3 = n 4 + 4n 3 4n 2 + 6n 2 4n 3

5 2 Principle of Mathematical Induction 5 = n 4n 2 + 6n n 3 4n = (n 2 4n 2 ) + (6n 2 ) (3) + 4(n 3 n) (n 2 4n 2 ) is divisible by 3 from our hypothesis. 6n 2, 3 are divisible by 3. We need to prove that 4(n 3 n) is divisible by 3. Again use mathematical induction. Basic step: For n = 0, 4(0-0) = 0 is divisible by 3. Induction hypothesis: Let 4(n 3 n) is divisible by 3. Induction step: 4[(n + 1) 3 (n + 1)] = 4[(n 3 + 3n 2 + 3n + 1) (n + 1)] = 4[n 3 + 3n 2 + 3n + 1 n 1] = 4[n 3 + 3n 2 + 2n] = 4[n 3 n + 3n 2 + 3n] = 4(n 3 n) + 4.3n n 4(n 3 n) is divisible by 3 from our hypothesis. 4.3n 2 is divisible by n is divisible by 3. Thus we can say that = (n 2 4n 2 ) + (6n 2 ) (3) + 4(n 3 n) is divisible by 3. That is, n 4 4n 2 is divisible by 3. Example 2: Prove using mathematical induction: n = n(n+1) 2 Let P (n) = n = n(n+1) 2 Basic Step: For n=1, LHS = 1 RHS = 1(1+1)/2=1 Induction hypothesis; Assume that P(n) is true for n=k, Then, k = k(k+1) 2

6 2 Principle of Mathematical Induction 6 Induction step: Show that P(n) is true for n=k k + (k + 1) = k(k+1) 2 + k + 1 = (k + 1)[ k 2 + 1] = (k + 1)( k+2 2 ) = (k+1)(k+2) 2 That is, P(n) is true for n=k+1. Thus by using the principle of mathematical induction, we proved n = n(n+1) 2 Example 3: Prove using the principle of mathematical induction, n i=0 n2 = n(n+1)(2n+1) 6 Let P (n) = n i=0 n2 = n(n+1)(2n+1) 6 Basic step: For n=1, LHS = 1 2 = 1 RHS = n(n+1)(2n+1) 6 = = 1 P(n) is true for n=1. Induction hypothesis: Assume that result is true for n=k. That is, k 2 = k(k+1)(2k+1) 6 Induction step: Prove that result is true for n=k k 2 + (k + 1) 2 = k(k+1)(2k+1) 6 + (k + 1) 2 = (k + 1)[ k(2k+1) 6 + (k + 1)] = (k + 1)( 2k2 +k+6k+6 6 ) = (k + 1)( 2k2 +7k+6 6 ) = (k + 1)( 2k2 +4k+3k+6 6 ) = (k + 1)( 2k(k+2)+3(k+2) 6 ) = (k+1)(k+2)(2k+3) 6 Thus it is proved. Exercise: 1. Prove the following by principle of induction: a. n k=1 k2 = n(n+1)(2n+1) 6

7 3 Diagonalization Principle 7 b. n i=1 1 i(i+1) = c. 2i>i for all i>1. n n+1 d (3n 2) = n(3n 1) 2 e. 2 x x 2,if x 4 f. 10 2n 1 is divisible by 11 for all n>1 g. 2 n > n, for all n>1. 3 Diagonalization Principle Let s be a non empty set and R any relation on S. Let D = {aɛa (a, a) / r} For each a / A, let R a = {b (a, b) R} Then diagonalization principle states that D is different from each R a. OR Diagonalization principle states that the complement of the diagonal is different from each row. For example, Let S = {a, b, c, d} R = { (a,a), (b,c), (b,d), (c,a), (c,c), (c,d), (d,a), (d,b) } The above relation R is shown in matrix from as follows: Diagonal elements are marked. From the figure, R a = {a} R b = {c, d} R c = {a, c, d} R d = {a, b} Complement of the diagonal is, D = {b, d} That is,

8 3 Diagonalization Principle 8 If we compare each of the above R a, R b, R c, R d with D, we can see that D is different from each R a. Thus complement of the diagonal is distinct from each row. Note: Following information is needed to solve the example given below: 9 s complement of a number 9 s complement of 276 is s complement of 425 is s complement of 793 is 206. Example 1: Prove that the set of real numbers between 0 and 1 is uncountable. An example for a real number between 0 and 1 is Let we represent a real number between 0 and 1 as x =.x 0 x 1 x 2 x 3... where each x i is a decimal digit. Let f(k) be an arbitrary function from natural numbers to the set [0,1]. We can arrange the elements in a 2d array as, f(0):. x 00 x 01 x 02 x 03 _ f(1):. x 10 x 11 x 12 x 13 _ f(2):. x 20 x 21 x 22 x 23 _ f(n):. x n0 x n1 x n2 x n3 _ where x ni is the ith digit in the decimal expansion of f(n). Next we find the complement of the diagonal (9 s complement) as follows: Y =.y 0 y 1 y 2... where y i =9 s complement of x ii [Find out the 9 s complement of x 00, x 11, x 22, x 33...x nn ]

9 4 Pigeonhole Principle 9 From the diagonalisation principle, it is clear that the complement of the diagonal is different from each row. Here it is clear that Y is different from each f(i) in at least one digit. Y f(i). Hence Y cannot be present in the above array. This means that the set of real numbers between 0 and 1 is countably infinite or not countable. For instance suppose we arrange the real numbers as, f(0): _ f(1): _ f(2): _ f(3) _ f(n): _ Here the diagonal is The complement (9 s complement) of the diagonal is The real number is not in the above table. Thus It is clear that this value is distinct from each row, f(0), f(1), f(2)...f(n). 4 Pigeonhole Principle A pigeonhole is a hole for pigeons to nest. From the above diagram, it is clear that if 10 pigeons are put into 9 pigeonholes, then one pigeonhole must contain

10 10 more than one item. The pigeonhole principle states that if n pigeons are put into m pigeonholes with n>m, then at least one pigeonhole must contain more than one pigeon. Thus if S1 and S2 are two non empty finite sets and S1 > S2, then there is no one-to-one function from S1 to S2. Pigeonhole principle can be used to show that certain languages are not regular. We will use pigeonhole principle in the topic pumping lemma later. Part III. Recursive Function Theory Functions The concept of a function is a fundamantal topic in mathematics. A function or a total function f : X Y is a rule that assigns to all the elements of one set, X, a unique element of another set, Y. The first set, X is called the domain of the function, and the second set, Y is called its range. For example, f(x) = 2x + 1 is a function defined on one variable, x. Imagine we say that f is over all natural numbers only. Then the following diagram shows the function: Here the domain of f is {1, 2, 3, 4,...} Range of f is {3, 5, 7, 9,...}. f(x, y) = x 2 + 2y is a function on 2 variables, x and y.

11 11 f(x, y, z) = x + 2y 3 + 7z is a function on 3 variables, x, y and z. Total Function The above three examples were total functions. A total function from X to Y is a rule that assigns to every element of X, a unique element of Y. f : X Y For example, f(x) = 2x 3 In all our discussions, we assume that f is over all natural numbers, then Here the domain of f is {1, 2, 3, 4...}. That is, the domain contains all the elements of x. So f is a total function. Partial Function Here, to extend the class of computable functions, we use partial functions. A partial function, f : X Y is a rule that assigns to some elements of X, a unique element of Y. For other elements, there may not be any corresponding element in Y. For example, Example 1: f(x) = x 2 Suppose f is defined over natural numbers. Then f is a partial function. this can be seen from the following diagram.

12 12 In the above diagram, domain of f is {2, 4, 6, 8,...} Here the domain is not equal to the set X. So f is a partial function. Example 2: f(x, y) = x y f is defined over N. f is a partial function. This is because when x=6, y=8, f(x,y) = -2-2 is not a natural number. So f is not defined for x=6, y=8. f is a partial function. Recursive Functions Consider the example, f(n) = n Here, given any value for n, multiply that value by itself and then add one. Here function is defined in a recursive way. Value of f can be computed in a mechanical fashion. Example 2: Factorial of a number is defined as, n! = n (n-1) (n-2) This is an explicit definition. Another way to define factorial is, 0! = 1 n! = n (n-1)! for nɛn

13 5 Primitive Recursive Functions 13 This definition is recursive because to find the factorial at an argument n, we need to find the factorial at some simpler argument (n-1). Example 3: Exponentiation can be defined as, x n = x.x.x.x...x (n times) This exponentiation function can be recursively defined as, x 0 = 1 x n = x.x n 1 for nɛn. This is a recursive definition for exponentiation. In all our discussions, a function, f is defined over natural numbers (N) only. 5 Primitive Recursive Functions A function, f is called a primitive recursive function, i) If it is one of the three basic functions, or, ii) If it can be obtained by applying operations such as composition and recursion to the set of basic functions. The basic functions and operations are explained below; 5.1 Basic Functions We define three basic functions. They are, Zero function, Successor function, and Projector function. Zero Function Z(x) = 0 is called Zero function. Example: We may write Z(8) = 0. Successor Function The successor function is S(x), defined as S(x) = x+1

14 5 Primitive Recursive Functions 14 Thus the value of S(x) is the integer next in sequence to x. For example, S(4) = 5 S(29) = 30 Projector Function Projector function, P k is defined as, P k (x 1, x 2,...x k,...x n ) = x k For example, P 3 (8, 5, 6, 4) = 6 P 6 (6, 34, 7, 2, 45, 23, 22) = Operations We can build complicated functions from the above basic functions by performing operations such as, composition, and recursion. Composition If functions, f 1, f 2 and g are given, then the composition of g with f 1, f 2 is given by, h = g(f 1, f 2 ). In general, If functions f 1, f 2...f k and g are given, then the composition of g with f 1, f 2...f k is h = g(f 1, f 2, f 3...f k ) Example 1: Let g(n) = n 2 h(n) = n + 3 Find the composition of h with g. The composition of h with g is, f(n) = h[g(n)] = h[n 2 ] = n Example 2: Let

15 5 Primitive Recursive Functions 15 g(n) = n 2 h(n) = n + 3 Find the composition of g with h. f(n) = g[h(n)] = g[n + 3] = (n + 3) 2 Example 3: Let f 1 (x, y) = x + y f 2 (x, y) = 2x f 3 (x, y) = xy, and g(x, y, z) = x + y + z be functions over N. Find the composition of g with f 1, f 2, f 3. h(x, y) = g(f 1, f 2, f 3 ) = g (x + y, 2x, xy) = x + y + 2x + xy = 3x + y + xy Recursion A function f can be constructed using recursion from the functions g and h as, f(x, 0) = g(x) f(x, y + 1) = h [x, y, f(x, y)] In the above, f is of two variables. g is of one variable and h is of 3 variables. In general, a function of n+1 variables is defined by recursion if there exists a function g of n variables and a function h of n+2 variables. f is defined as, f(x 1, x 2,...x n, 0) = g(x 1, x 2,...x n ) f(x 1, x 2,...x n, y + 1) = h [x 1, x 2,...x n, y, f(x 1, x 2,...x n, y) ] Example 1: Addition of integers can be defined using recursion as, add(x, 0) = x add(x, y + 1) = add(x, y) + 1

16 5 Primitive Recursive Functions 16 Example 2: The function multiplication can be defined using recursion operation as, prod(x, 0) = 0 prod(x, y + 1) = add [x, prod(x, y) ] Above examples show how recursion operation is applied to a set of functions. Primitive Recursive functions Now we learned basic functions such as zero function, successor function and projector function, and operations such as composition and recursion. Again, a function, f is a primitive recursive function if either, i. it is one of the basic functions, or ii. it is produced by performing operations such as composition and recursion to the basic functions. Example 1: The addition function, add(x,y) is a primitive recursive function because, add(x, 0) = x = P 1 (x) add(x, y + 1) = add(x, y) + 1 = S[add(x, y)] = S[P 3 (x, y, add(x, y))] Thus add(x, y) is a function produced by applying composition and recursion to basic functions, P k and S. Example 2: The multiplication function mult(x, y) is a primitive recursive function because, mult(x, 0) = 0 = Z(x) mult(x, y + 1) = add [x, mult(x, y) ] = add[p 1 (x, y, mult(x, y)), P 3 (x, y, mult(x, y))] From the previous example, add() is a primitve recursive function. From the above, mult(x,y) is produced by performing operations on basic functions and add() function. So mult(x,y) is a primitive recursive function. Example 3: The factorial function, f(n) = n! is a primitive recursive function. This can be proved using mathematical induction. Basic Step:

17 5 Primitive Recursive Functions 17 For n = 0, f(0) = 0! = 1 = P 1 (1) Induction Hypothesis: Assume that f(p) is a primitive recursive function. Induction Step: f(p+1) = (p+1)! = p! (p+1) = f(p) (p+1) = mult [ f(p), p+1 ] = mult [ f(p), S(p) ] In the above, f(p) is primitive recursive from induction hypothesis. S(p) is primitive recursive, since it is the successor function. mult() is primitve recursive from the previous example. So we can conclude that f(n) = n! is primitive recursive. Example 4: Show that function f 1 (x, y) = x + y is primitive recursive. f 1 (x, 0) = x + 0 = x = P 1 (x) f 1 (x, y + 1) = x + (y + 1) = (x + y) + 1 = f 1 (x, y) + 1 = S[f 1 (x, y)] = S[P 3 (x, y, f 1 (x, y))] Since f 1 (x, 0) and f 1 (x, y + 1) are primitive recursive, f 1 (x, y) = x + y is primitive recursive. Example 5: Show that the function, f 1 (x, y) = x y is primitive recursive. f 2 (x, 0) = x 0 = 0 = Z(x) f 1 (x, y + 1) = x (y + 1) = (x y) + x = f 2 (x, y) + x

18 6 Partial Recursive Functions 18 = f 1 [f 2 (x, y), x] from Example 4. = f 1 [P 3 (x, y, f 2 (x, y)), P 1 (x, y, f 2 (x, y))] Since f 2 (x, 0) and f 2 (x, y + 1) are primitive recursive, f 2 (x, y) = x y is primitive recursive. Example 6: Show that the function, f(x, y) = x y is a primitive recursive function. f(x, 0) = x 0 = 1 = P 1 (1) f(x, y + 1) = x y+1 = x y.x 1 = x.x y = x.f(x, y) = P 1 (x, y, f(x, y)) P 3 (x, y, f(x, y)) = mult [P 1 (x, y, f(x, y)), P 3 (x, y, f(x, y)) ] mult() is a primitive recursive function as we found earlier. Since f(x, 0) and f(x, y + 1) are primitive recursive, f(x, y) = x y is primitive recursive. 6 Partial Recursive Functions A function, f is a partial recursive function if either, i. it is one of the basic functions, or ii. it is produced by performing operations such as composition, recursion and minimization to the basic functions. Basic Functions We learned three basic functions such as, Zero function, Z(x), Successor function, S(x), and Projector function, P k. Operations We learned the operations composition and recursion earllier. A new operation now comes, minimization. Minimization µ is the minimization operator. Let a function g(x,y) is defined over two variables, x and y.

19 6 Partial Recursive Functions 19 Then minimization operator, µ is defined over g (x, y) is as follows: µ y [g(x, y)] =smallest y such that g (x, y) = 0. Using the minimization operation, a function f(x) can be defined for some y; we can write, f(x) = µ y [g(x, y)] Example 1: Let g(x,y) is given in the following table: g(0,0)=5 g(1,0)=5 g(2,0)=8 g(3,0)=1 g(0,1)=4 g(1,1)=6 g(2,1)=5 g(3,1)=2 g(0,2)=6 g(1,2)=0 g(2,2)=undefined g(3,2)=0 g(0,3)=0 g(1,3)=3 g(2,3)=0 g(3,3)=4 g(0,4)=1 g(1,4)=0 g(2,4)=7 g(3,4)=undefined Then, f(0) = 3, f(1) = 2 f(2) = Not defined f(3) = 2 [ because g(0,3) = 0] Minimization operation is denoted by µ[g(0, 3) = 0] = 3 [ 2 is the minimum y that g(1,2)=0; Though g(1,4)=0 also; ] Minimization operation is denoted by µ[g(1, 2) = 0] = 2 [ because g(2,3)=0, but g(2,2) is undefined, where y=2 < y=3 ] [because g(3,2)=0, though g(3,4) is undefined for y=4, but 4<2 ] Minimization operation is denoted by µ[g(3, 2) = 0] = 2 For some values g(x,y) is undefined, but we can define minimization operation. Partial Recursive Functions A function, f is a partial recursive function if either, i. it is one of the basic functions, or ii. it is produced by performing operations such as composition, recursion and minimization to the basic functions. From the definition, we can say that, primitive recursive functions are a subset of partial recursive functions. This is shown below:

20 6 Partial Recursive Functions 20 Thus all primitive recursive functions are partial recursive functions. Note that all partial recursive functions are computable functions. Example 1: Show that f(x) = x 2 is a partial recursive function over N. f(x) = x 2 We may write y = x 2 Then, x = 2y 2y x = 0 Let g(x, y) = 2y x Let g(x, y) = 0, for some x and y. Let f 1 (x) = µ[ 2y x = 0] Only for even values of x, f 1 (x) is defined. When x is odd, f 1 (x) is not defined. So f 1 is partial recursive. Since, f(x) = x 2 = f 1(x), f is a partial recursive function.

21 21 Part IV. Computable and Non-Computable Functions 7 Computable Functions Computable functions are the basic objects of study in Theory of Computation. Computable functions are the functions that can be calculated using a mechanical calculation device given unlimited time and memory space. Also any function that has an algorithm is computable. Each computable function f takes a fixed finite number of natural numbers as arguments. The computable function f returns an output for some inputs. For some inputs, it may not return an output. Due to this, a computable function is a paertial recursive function. If the computable function is defined for all possible arguments, it is called a total computable function or total recursive function. The notation f(x 1, x 2,...x k ) indicates that the partial function f is defined on arguments x 1, x 2,...x k. We say that a function f on a certain domain is said to be computable, if there exists a Turing machine that computes the value of f for all arguments in its domain. A function is uncomputable if no such Turing machine exists. The basic characteristic of a computable function is that there is a finite procedure or algorithm telling how to compute the function. The characterisitics of a computable function are as follows: 1. There must be exact instructions (ie, a program, finite in length). 2. If the procedure is given a k tuple x in the domain of f, then after a finite number of steps, the procedure must terminate and produce f(x). 3. If the procedure is given a k-tuple x which is not in the domain of f, then the procedure must never halt, or it may get stuck at some point. Following are some examples for computable functions: 1. Each function with a finite domain. eg. Any finite sequence of natural numbers. 2. Each constant function f : N k N, f(n 1, n 2,...n k ) = n. 3. Addition f : N 2 N, f(n 1, n 2 ) = n 1 + n The function which gives the list of prime factors of a number. 5. The gcd of two numbers is a computable function. 8 Non-Computable Functions The rela numbers are uncountable so most real numbers are not computable. Most subsets of natural numbers are not countable. A non-computable function corresponds to an undecidable problem and it consists of a family of instances for which there is no computer program that given any problem instance as input terminates and outputs the required answer after a finite number of steps.

22 22 For an undecidable problem, it is impossible to construct a single algorithm that always leads to a correct yes/ no answer. We say that a function f on a certain domain is said to be non-computable, if no Turing machine exists that computes the value of f for all arguments in its domain. Examples for undecidable problems (non-computabel functions) are halting problem, post correspondence problem. Part V. Formal Representation of Languages [Kavitha2004] Here we introduce the concept of formal languages and grammars. We know that a grammar is specified for a natural language such as English. To define valid sentences and to give structural descriptions of sentences a grammar is used. Linguistics is a branch to study the theory of languages. Scientists in this branch of study have defined a formal grammar to describe English that would make language translation using computers very easy. English Grammar First we will consider how grammars can be specified for English language. Then we will extend this model to our programming language grammar specification. An example for grammar is, ARTICLE a an the NOUN_PHRASE ARTICLE NOUN NOUN boy apple ε Productions The above are called productions or rules of the grammar. Two productions are given above. First production is, ARTICLE a an the It can also be written as, ARTICLE a ARTICLE an ARTICLE the Second production is, NOUN_PHRASE ARTICLE NOUN Third production is,

23 23 NOUN boy apple ε It can also be written as, NOUN boy NOUN apple NOUN ε Non-terminals In the above, ARTICLE, NOUN_PHRASE, NOUN are called non-terminal symbols. A non-terminal is specified using upper case letters. Note that the left hand side of a production always contains a single non-terminal. Terminals In the above, a, an, the, boy, apple are called terminal symbols. A terminal is written using lowercase letters. ε means an empty string. Start Symbol In a grammar specification, one non-terminal symbol is called the start symbol. Here, NOUN_PHRASE is the start symbol. Thus a grammar consists of a set of productions, terminals, non-terminals and start symbol. If the matching left hand side of a certain rule can be found to occur in a string, it may be replaced by the corresponding right hand side. 8.1 Formal Definition of a Grammar A grammar is (V N,, P, S) where V N is a finite non empty set whose elements are called non-terminals. is a finite non empty set whose elements are called terminals. V N = φ S is a special non terminal called start symbol. P is a finite set whose elements are α β, whose α and β are terminals or non terminals. Elements of P are called productions or production rules. For example, Consider the productions, S ab ba A as baa a B bs abb b where S is the start symbol. For the above productions the grammar is defined as, V N = {S, A, B}

24 24 = {a, b} Sis the start symbol S P = {S ab ba, A as baa a, B bs abb b} Derivations Productions are used to derive various sentences. Example 1: Consider the grammar given below: SENTENCE NOUN_PHRASE VERB_PHRASE NOUN_PHRASE ARTICLE NOUN VERB_PHRASE VERB NOUN_PHRASE ARTICLE a an the NOUN boy apple VERB apple where SENTENCE is the start symbol. Using this grammar, the sentence the boy ate an apple is derived as shown below: Example 2: Consider the grammar given below: S baas baa In the above, S is the start symbol, S is a non-terminal and a, b are terminals. To derive a sentence, we begin with the start symbol, S.

25 25 From the above, we can rewrite, S as baa. Thus the sentence, baa is a valid sentence according to the grammar. From the above rule, rewrite S as baas. Then rewrite S in baas as baas. Then we get baabaas. Again rewrite S as baa. We get baabaabaa. Thus baabaabaa is a valid sentence. Example 3: Following is a grammar for expressions: Expr Expr Op num num Op + - * / In the above grammar, Expr, Op are non-terminals. num, +, -, *, / are terminals. Using the above grammar, a large set of expressions can be derived. Example 4: The following is a grammer for if..else construct in C. Stmt if ( Expr ) Stmt else Stmt if ( Expr ) Stmt Example 5: The following is a grammar for a set of statements in C.

26 26 Stmt id = Expr; if (Expr) Stmt if (Expr) Stmt else Stmt while (Expr) stmt do Stmt while (Expr); { Stmts } Stmts Stmts Stmt ε 8.2 Formal Definition of a Language The language generated by a grammar G is L(G) is defined as L(G) = { wɛ S = G w } The elements of L(G) are called sentences. In a simple way, L(G) is the set of all sentences derived from the start symbol S. For example, for the grammar S baas baa L(G) = {baa, baabaa, baabaabaa, } Example 1: Consider the grammar given below: ARTICLE a an the NOUN_PHRASE ARTICLE NOUN NOUN boy apple where NOUN_PHRASE is the start symbol. Find the language L(G) generated by the grammar. i) NOUN_PHRASE ARTICLE NOUN = a boy ii) NOUN_PHRASE ARTICLE NOUN = an apple iii) NOUN_PHRASE ARTICLE NOUN = the boy iv) NOUN_PHRASE ARTICLE NOUN = the apple v) NOUN_PHRASE ARTICLE NOUN

27 9 Chomsky Classification of Languages 27 = a apple NOUN_PHRASE ARTICLE NOUN = an boy Hence L(G) = { a boy, an apple, the apple, the boy, a apple, an boy} Note that a apple and an boy are in the set even if they are not valid English phrases. Exercises: 1. Let grammar G = [ {S,C}, {a,b}, P, S ] where P consists of S aca C aca b. Find L(G). 2. Let G = [{S, A 1, A 2 }, {a, b}, P, S], where P consists of S aa 1 A 2 a A 1 baa 1 A 2 b A 2 A 1 ab aa 1 baa ba 2 b abab Check whether w = baabbabaaabbaba is in L(G). 2. Let grammar G = [ {S}, {0,1}, {S 0S1, S ɛ}, S ]. Find L(G). 9 Chomsky Classification of Languages [Kavitha2004] A number of language families are there. Noam Chomsky, a founder of formal language theory, provided an initial classification into four language types, type 0 to type 3. A grammar represents the structure of a language as we saw earlier. Four types of languages and their associated grammars are defined in Chomsky Hierarchy (defined by Noam Chomsky). The languages are Type- 0 languages or Unrestricted languages, Type- 1 languages or Context sensitive languages, Type- 2 languages or Context free languages, Type- 3 languages or regular languages. Each language family is a proper subset of another one. The following figure shows the relationship.

28 9 Chomsky Classification of Languages 28 Type-0 languages are generated by Type-0 grammars, Type-1 languages by Type-1 grammars, Type-2 languages by Type-2 grammars and Type-3 languages by Type-3 grammars. Thus the corresponding grammars are Type- 0 grammars or Unrestricted grammars, Type- 1 grammars or Context sensitive grammars, Type- 2 grammars or Context free grammars, Type- 3 grammars or regular grammars. Type- 0 or Unrestricted languages vs Type- 0 grammars Type- 0 languages are defined by arbitrary grammars (Type-0). Type- 0 grammars have productions of the form, α β, such that α ε. Type- 0 languages are recognized using Turing Machines (TM). The following is an example for an Unrestricted grammar: S ACaB Ca aac CB DB ad Da ae Ea AE ε Type- 1 or Context- sensitive languages vs Type- 1 grammars Type- 1 languages are described by Type- 1 grammars. LHS of a Type- 1 grammar is not longer than the RHS. Type- 1 grammars are represented by the productions α β, such that α β.

29 9 Chomsky Classification of Languages 29 Type- 1 languages are recognized using Linear Bounded Automata (LBA). The following is an example for a Context Sensitive grammar: S SBC S ac B a CB BC Ba aa C b Type- 2 or Context- free languages vs Type- 2 grammars Type- 2 languages are described by Type- 2 grammars or context free grammars. LHS of a Context free grammar (Type-2) is a single non-terminal. The RHS consists of an arbitrary string of terminals and non-terminals. Context free grammars are represented by the productions A β. Type 2 languages are recognized using Pushdown Automata (PDA). The following is an example for a Context free grammar: S asb S ε The English grammar given below is a context free grammar. ARTICLE a an the NOUN_PHRASE ARTICLE NOUN NOUN boy apple Type- 3 or Regular languages vs Type- 3 grammars Type- 3 languages are described by Type- 3 grammars. The LHS of a Type- 3 grammar is a single non-terminal. The RHS is empty, or consists of a single terminal or a single terminal followed by a non- terminal. Type- 3 grammars are represented by the productions A ab or A a. Type- 3 languages are recognized using Finite State Automata (FA). The following is an example for a regular grammar: A aa A ε A bb B bb B ε A c Following figure shows the relation between the four types of languages and machines.

30 9 Chomsky Classification of Languages 30

31 9 Chomsky Classification of Languages 31 Questions (from Old syllabus of S7CS TOC) MGU/Nov What is meant by a formal proof? (4marks). 2. a. Differentiate between primitive recursive and partial recursive functions with examples (12marks). OR b. Write notes on: ii) diagonalization principle. (12marks) MGU/April What is a primitive recursive function (4marks)? 3. a. Show that ii) For n is an integer >=0, n 3 + 2n is divisible by 3 (12marks). OR b. i) Show that a problem whose language is recursive is undecidable. ii) If Z is the decimal expansion of pi, then show that the function f(x) = 1 for exactly x consecutive 3 s in z and f(x) = 0, otherwise (12marks). MGU/Nov What is meant by computable and non-computable? (4marks) 2. Define a grammar and what are various types of grammars (4marks). 3 a. show that factorial of a number is a primitive recursive function. OR b. i) Show that multiplication is a computable function on the set of natural numbers. ii). Discuss the computability of f(x) = 1 for xth digit of Z = 3 and f(x) = 0 otherwise Z is a decimal expansion of π = (12marks) MGU/May Define primitive recursive function (4marks). 2. Differentiate cmputable function from non-computable function (4marks). 3 a. Explain what is meant by the following statements:- i) f: N1N is a total recursive (TR) function. ii) The sequence {f n : N1N }n2n of TR functions of a single variable is recursively enumerable. iii) Show that no recursive enumeration can include the set of all TR functions of a single variable (12marks). MGU/Nov What does it mean for a subset s of the set N of natural numbers to be register machine decidable? (4marks). 2. What is diagonalisation principle? (4marks) 3a. Prove that the union and intersection of two recursive languages are also recursive. OR b. Discuss the proof that the closure properties of regular sets are closed (12mraks). MGU/Nov Give the formal definition of context sensitive grammar (4marks). 2. Show that Σ n k=0 k = n(n+1) 2. (4marks)

32 9 Chomsky Classification of Languages 32 3a. Prove that 2 n is uncountable using diagonalisation principle (12marks). OR b. Compare recursive function, primitive recursive function and partial recursive function (12marks). 4a ii) Show that f(r) = x 2 is a partial recursive function (12marks). MGU/May What is primitive recursive function (4marks). 2. Show that Σ n i=0 i = n(m+1) 2 by induction (4marks). 3a i) For any finite set A, 2 A = 2 A, is cardinality of any power set a is 2 raised to a power equal to cardinality of A. OR b ii) Explain Chomsky classification (12marks). MGU/JDec a i) Check whether the language L = {a n b n /n 1} is regular or not. Justify your answer. ii) Explain diagonalization principle (12marks). OR b ii) Explain primitive recursive and partial recursive function (12marks). MGU/July Define primitive recursive function (4marks). 2. Explain composition of functions (4marks). 3a. i) Prove that the function f add (x, y) = x + y is primitive recursive. ii) Prove that the function g(x, y) = x y is primitive recursive (12marks). OR b. ii) Explain the significance of Theory of Computation in computer science (12marks). MGU/Jan Prove that for any set A having n>=0 elements, the power set of a has 2 n elements (4marks). 2. Explain the types of functions- injection, surjection, bijection and invertible function (4marks). 3b. i) Explain the Chomsky hierarchy of formal languages. ii) Define formal language. Give examples for finite and infinite languages (12marks). MGU/July Define a partial recursive function (4marks). 2. Differentiate between deterministic and non deterministic algorithms (4marks). 4a. i) ii) Define context sensitive and regular grammars. Give examples. OR b. i) Find a function f(x) such that f(2) = 3, f(4) = 5, f(7) =2 and f(x). assume any arbirtrary value for other arguments. Show that f(x) is primitive recursive. MGU/Nov Give the formal definition of a grammar (4marks).

33 9 Chomsky Classification of Languages 33 2b. i) Show that f(x) = x/2 is a partial recursive function. ii) Explain the different types of grammars with suitable examples (12marks). References. Linz, P (2006). An Introduction to Formal Languages and Automata. Narosa. Moret, B, M (2007). The Theory of Computation. Pearson Education. Mishra, K, L, P; Chandrasekaran, N (2009). Theory of Computer Science. PHI. Pandey, A, K (2006). An Introduction to automata Theory and Formal Languages. Kataria & Sons. Kavitha,S; Balasubramanian,V (2004). Theory of Computation. Charulatha Pub. website:

THEORY OF COMPUTATION

THEORY OF COMPUTATION THEORY OF COMPUTATION UNIT-1 INTRODUCTION Overview This chapter begins with an overview of those areas in the theory of computation that are basic foundation of learning TOC. This unit covers the introduction

More information

(a) Give inductive definitions of the relations M N and M N of single-step and many-step β-reduction between λ-terms M and N. (You may assume the

(a) Give inductive definitions of the relations M N and M N of single-step and many-step β-reduction between λ-terms M and N. (You may assume the COMPUTER SCIENCE TRIPOS Part IB 205 Paper 6 4 (AMP) (a) Give inductive definitions of the relations M N and M N of single-step and many-step β-reduction between λ-terms M and N. (You may assume the definition

More information

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

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np Chapter 1: Introduction Introduction Purpose of the Theory of Computation: Develop formal mathematical models of computation that reflect real-world computers. Nowadays, the Theory of Computation can be

More information

CT32 COMPUTER NETWORKS DEC 2015

CT32 COMPUTER NETWORKS DEC 2015 Q.2 a. Using the principle of mathematical induction, prove that (10 (2n-1) +1) is divisible by 11 for all n N (8) Let P(n): (10 (2n-1) +1) is divisible by 11 For n = 1, the given expression becomes (10

More information

UNIT I PART A PART B

UNIT I PART A PART B OXFORD ENGINEERING COLLEGE (NAAC ACCREDITED WITH B GRADE) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS YEAR/SEM: III/V STAFF NAME: Dr. Sangeetha Senthilkumar SUB.CODE: CS6503 SUB.NAME:

More information

Compiler Construction

Compiler Construction Compiler Construction Exercises 1 Review of some Topics in Formal Languages 1. (a) Prove that two words x, y commute (i.e., satisfy xy = yx) if and only if there exists a word w such that x = w m, y =

More information

Section 1.7 Sequences, Summations Cardinality of Infinite Sets

Section 1.7 Sequences, Summations Cardinality of Infinite Sets Section 1.7 Sequences, Summations Cardinality of Infinite Sets Definition: A sequence is a function from a subset of the natural numbers (usually of the form {0, 1, 2,... } to a set S. Note: the sets and

More information

Multiple Choice Questions

Multiple Choice Questions Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Formal Language and Automata Theory Subject Code: CS 402 Multiple Choice Questions 1. The basic limitation of an FSM

More information

Section 2.4 Sequences and Summations

Section 2.4 Sequences and Summations Section 2.4 Sequences and Summations Definition: A sequence is a function from a subset of the natural numbers (usually of the form {0, 1, 2,... } to a set S. Note: the sets and {0, 1, 2, 3,..., k} {1,

More information

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory Proof Techniques Alphabets, Strings, and Languages Foundations of Computer Science Theory Proof By Case Enumeration Sometimes the most straightforward way to prove that a property holds for all elements

More information

Slides for Faculty Oxford University Press All rights reserved.

Slides for Faculty Oxford University Press All rights reserved. Oxford University Press 2013 Slides for Faculty Assistance Preliminaries Author: Vivek Kulkarni vivek_kulkarni@yahoo.com Outline Following topics are covered in the slides: Basic concepts, namely, symbols,

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016 Lecture 15 Ana Bove May 23rd 2016 More on Turing machines; Summary of the course. Overview of today s lecture: Recap: PDA, TM Push-down

More information

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

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar Code No: R05310501 Set No. 1 III B.Tech I Semester Regular Examinations, November 2008 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science & Engineering) Time: 3 hours Max Marks: 80 Answer any FIVE

More information

Reflection in the Chomsky Hierarchy

Reflection in the Chomsky Hierarchy Reflection in the Chomsky Hierarchy Henk Barendregt Venanzio Capretta Dexter Kozen 1 Introduction We investigate which classes of formal languages in the Chomsky hierarchy are reflexive, that is, contain

More information

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : III Year, V Semester Section : CSE - 1 & 2 Subject Code : CS6503 Subject

More information

Decision Properties for Context-free Languages

Decision Properties for Context-free Languages Previously: Decision Properties for Context-free Languages CMPU 240 Language Theory and Computation Fall 2018 Context-free languages Pumping Lemma for CFLs Closure properties for CFLs Today: Assignment

More information

TAFL 1 (ECS-403) Unit- V. 5.1 Turing Machine. 5.2 TM as computer of Integer Function

TAFL 1 (ECS-403) Unit- V. 5.1 Turing Machine. 5.2 TM as computer of Integer Function TAFL 1 (ECS-403) Unit- V 5.1 Turing Machine 5.2 TM as computer of Integer Function 5.2.1 Simulating Turing Machine by Computer 5.2.2 Simulating Computer by Turing Machine 5.3 Universal Turing Machine 5.4

More information

CHAPTER 4. COMPUTABILITY AND DECIDABILITY

CHAPTER 4. COMPUTABILITY AND DECIDABILITY CHAPTER 4. COMPUTABILITY AND DECIDABILITY 1. Introduction By definition, an n-ary function F on N assigns to every n-tuple k 1,...,k n of elements of N a unique l N which is the value of F at k 1,...,k

More information

Problems, Languages, Machines, Computability, Complexity

Problems, Languages, Machines, Computability, Complexity CS311 Computational Structures Problems, Languages, Machines, Computability, Complexity Lecture 1 Andrew P. Black Andrew Tolmach 1 The Geography Game Could you write a computer program to play the geography

More information

COMPUTABILITY THEORY AND RECURSIVELY ENUMERABLE SETS

COMPUTABILITY THEORY AND RECURSIVELY ENUMERABLE SETS COMPUTABILITY THEORY AND RECURSIVELY ENUMERABLE SETS JOSHUA LENERS Abstract. An algorithm is function from ω to ω defined by a finite set of instructions to transform a given input x to the desired output

More information

Languages and Compilers

Languages and Compilers Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 3. Formal Languages, Grammars and Automata Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office:

More information

CS402 - Theory of Automata Glossary By

CS402 - Theory of Automata Glossary By CS402 - Theory of Automata Glossary By Acyclic Graph : A directed graph is said to be acyclic if it contains no cycles. Algorithm : A detailed and unambiguous sequence of instructions that describes how

More information

LANGUAGE PROCESSORS. Presented By: Prof. S.J. Soni, SPCE Visnagar.

LANGUAGE PROCESSORS. Presented By: Prof. S.J. Soni, SPCE Visnagar. LANGUAGE PROCESSORS Presented By: Prof. S.J. Soni, SPCE Visnagar. Introduction Language Processing activities arise due to the differences between the manner in which a software designer describes the

More information

Theory and Compiling COMP360

Theory and Compiling COMP360 Theory and Compiling COMP360 It has been said that man is a rational animal. All my life I have been searching for evidence which could support this. Bertrand Russell Reading Read sections 2.1 3.2 in the

More information

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

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and Computer Language Theory Chapter 4: Decidability 1 Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

More information

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table. Code No: XXXXX JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY, HYDERABAD B.Tech II Year I Semester Examinations (Common to CSE and IT) Note: This question paper contains two parts A and B. Part A is compulsory

More information

1. [5 points each] True or False. If the question is currently open, write O or Open.

1. [5 points each] True or False. If the question is currently open, write O or Open. University of Nevada, Las Vegas Computer Science 456/656 Spring 2018 Practice for the Final on May 9, 2018 The entire examination is 775 points. The real final will be much shorter. Name: No books, notes,

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 11 Ana Bove April 26th 2018 Recap: Regular Languages Decision properties of RL: Is it empty? Does it contain this word? Contains

More information

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

QUESTION BANK. Formal Languages and Automata Theory(10CS56) QUESTION BANK Formal Languages and Automata Theory(10CS56) Chapter 1 1. Define the following terms & explain with examples. i) Grammar ii) Language 2. Mention the difference between DFA, NFA and εnfa.

More information

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 The entire examination is 925 points. The real final will be much shorter. Name: No books, notes, scratch paper, or calculators. Use pen

More information

Turing Machine Languages

Turing Machine Languages Turing Machine Languages Based on Chapters 23-24-25 of (Cohen 1997) Introduction A language L over alphabet is called recursively enumerable (r.e.) if there is a Turing Machine T that accepts every word

More information

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

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? R1 SET - 1 1. a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? 2. a) Design a DFA that accepts the language over = {, 1} of all strings that

More information

Material from Recitation 1

Material from Recitation 1 Material from Recitation 1 Darcey Riley Frank Ferraro January 18, 2011 1 Introduction In CSC 280 we will be formalizing computation, i.e. we will be creating precise mathematical models for describing

More information

Decidable Problems. We examine the problems for which there is an algorithm.

Decidable Problems. We examine the problems for which there is an algorithm. Decidable Problems We examine the problems for which there is an algorithm. Decidable Problems A problem asks a yes/no question about some input. The problem is decidable if there is a program that always

More information

To illustrate what is intended the following are three write ups by students. Diagonalization

To illustrate what is intended the following are three write ups by students. Diagonalization General guidelines: You may work with other people, as long as you write up your solution in your own words and understand everything you turn in. Make sure to justify your answers they should be clear

More information

Source of Slides: Introduction to Automata Theory, Languages, and Computation By John E. Hopcroft, Rajeev Motwani and Jeffrey D.

Source of Slides: Introduction to Automata Theory, Languages, and Computation By John E. Hopcroft, Rajeev Motwani and Jeffrey D. Source of Slides: Introduction to Automata Theory, Languages, and Computation By John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman And Introduction to Languages and The by J. C. Martin Basic Mathematical

More information

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

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur Finite Automata Dr. Nadeem Akhtar Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur PhD Laboratory IRISA-UBS University of South Brittany European University

More information

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course) *4459255* [4459] 255 Seat No. T.E. (Computer Engineering) (Semester I) Examination, 2013 THEY OF COMPUTATION (2008 Course) Time : 3 Hours Max. Marks : 100 Instructions : 1) Answers to the two Sections

More information

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

MIT Specifying Languages with Regular Expressions and Context-Free Grammars MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Language Definition Problem How to precisely

More information

AUBER (Models of Computation, Languages and Automata) EXERCISES

AUBER (Models of Computation, Languages and Automata) EXERCISES AUBER (Models of Computation, Languages and Automata) EXERCISES Xavier Vera, 2002 Languages and alphabets 1.1 Let be an alphabet, and λ the empty string over. (i) Is λ in? (ii) Is it true that λλλ=λ? Is

More information

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Massachusetts Institute of Technology Language Definition Problem How to precisely define language Layered structure

More information

Automata Theory CS S-FR Final Review

Automata Theory CS S-FR Final Review Automata Theory CS411-2015S-FR Final Review David Galles Department of Computer Science University of San Francisco FR-0: Sets & Functions Sets Membership: a?{a,b,c} a?{b,c} a?{b,{a,b,c},d} {a,b,c}?{b,{a,b,c},d}

More information

QUESTION BANK. Unit 1. Introduction to Finite Automata

QUESTION BANK. Unit 1. Introduction to Finite Automata QUESTION BANK Unit 1 Introduction to Finite Automata 1. Obtain DFAs to accept strings of a s and b s having exactly one a.(5m )(Jun-Jul 10) 2. Obtain a DFA to accept strings of a s and b s having even

More information

Cardinality of Sets. Washington University Math Circle 10/30/2016

Cardinality of Sets. Washington University Math Circle 10/30/2016 Cardinality of Sets Washington University Math Circle 0/0/06 The cardinality of a finite set A is just the number of elements of A, denoted by A. For example, A = {a, b, c, d}, B = {n Z : n } = {,,, 0,,,

More information

Phil 320 Chapter 1: Sets, Functions and Enumerability I. Sets Informally: a set is a collection of objects. The objects are called members or

Phil 320 Chapter 1: Sets, Functions and Enumerability I. Sets Informally: a set is a collection of objects. The objects are called members or Phil 320 Chapter 1: Sets, Functions and Enumerability I. Sets Informally: a set is a collection of objects. The objects are called members or elements of the set. a) Use capital letters to stand for sets

More information

Lecture 5: The Halting Problem. Michael Beeson

Lecture 5: The Halting Problem. Michael Beeson Lecture 5: The Halting Problem Michael Beeson Historical situation in 1930 The diagonal method appears to offer a way to extend just about any definition of computable. It appeared in the 1920s that it

More information

2. Functions, sets, countability and uncountability. Let A, B be sets (often, in this module, subsets of R).

2. Functions, sets, countability and uncountability. Let A, B be sets (often, in this module, subsets of R). 2. Functions, sets, countability and uncountability I. Functions Let A, B be sets (often, in this module, subsets of R). A function f : A B is some rule that assigns to each element of A a unique element

More information

A B. bijection. injection. Section 2.4: Countability. a b c d e g

A B. bijection. injection. Section 2.4: Countability. a b c d e g Section 2.4: Countability We can compare the cardinality of two sets. A = B means there is a bijection between A and B. A B means there is an injection from A to B. A < B means A B and A B Example: Let

More information

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1 Introduction to Automata Theory BİL405 - Automata Theory and Formal Languages 1 Automata, Computability and Complexity Automata, Computability and Complexity are linked by the question: What are the fundamental

More information

Normal Forms for CFG s. Eliminating Useless Variables Removing Epsilon Removing Unit Productions Chomsky Normal Form

Normal Forms for CFG s. Eliminating Useless Variables Removing Epsilon Removing Unit Productions Chomsky Normal Form Normal Forms for CFG s Eliminating Useless Variables Removing Epsilon Removing Unit Productions Chomsky Normal Form 1 Variables That Derive Nothing Consider: S -> AB, A -> aa a, B -> AB Although A derives

More information

CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia

CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia Gabriel Robins Please start solving these problems immediately, and work in study groups. Please prove

More information

Theory of Programming Languages COMP360

Theory of Programming Languages COMP360 Theory of Programming Languages COMP360 Sometimes it is the people no one imagines anything of, who do the things that no one can imagine Alan Turing What can be computed? Before people even built computers,

More information

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

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which: P R O B L E M S Finite Autom ata. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which: a) Are a multiple of three in length. b) End with the string

More information

Comparing sizes of sets

Comparing sizes of sets Comparing sizes of sets Sets A and B are the same size if there is a bijection from A to B. (That was a definition!) For finite sets A, B, it is not difficult to verify that there is a bijection from A

More information

chapter 14 Monoids and Automata 14.1 Monoids GOALS Example

chapter 14 Monoids and Automata 14.1 Monoids GOALS Example chapter 4 Monoids and Automata GOALS At first glance, the two topics that we will discuss in this chapter seem totally unrelated. The first is monoid theory, which we touched upon in Chapter. The second

More information

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions) By the end of this course, students should CIS 1.5 Course Objectives a. Understand the concept of a program (i.e., a computer following a series of instructions) b. Understand the concept of a variable

More information

Computer Sciences Department

Computer Sciences Department 1 Reference Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER 3 D E C I D A B I L I T Y 4 Objectives 5 Objectives investigate the power of algorithms to solve problems.

More information

Ambiguous Grammars and Compactification

Ambiguous Grammars and Compactification Ambiguous Grammars and Compactification Mridul Aanjaneya Stanford University July 17, 2012 Mridul Aanjaneya Automata Theory 1/ 44 Midterm Review Mathematical Induction and Pigeonhole Principle Finite Automata

More information

Week 2: Syntax Specification, Grammars

Week 2: Syntax Specification, Grammars CS320 Principles of Programming Languages Week 2: Syntax Specification, Grammars Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Week 2: Syntax Specification, Grammars 1/ 62 Words and Sentences

More information

Math 302 Introduction to Proofs via Number Theory. Robert Jewett (with small modifications by B. Ćurgus)

Math 302 Introduction to Proofs via Number Theory. Robert Jewett (with small modifications by B. Ćurgus) Math 30 Introduction to Proofs via Number Theory Robert Jewett (with small modifications by B. Ćurgus) March 30, 009 Contents 1 The Integers 3 1.1 Axioms of Z...................................... 3 1.

More information

Notions of Computability

Notions of Computability Notions of Computability Many notions of computability have been proposed, e.g. (Type 0 a.k.a. Unrestricted or context sensitive) Grammars Partial Recursive Functions Lambda calculus Markov Algorithms

More information

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars CMSC 330: Organization of Programming Languages Context Free Grammars Where We Are Programming languages Ruby OCaml Implementing programming languages Scanner Uses regular expressions Finite automata Parser

More information

Formal languages and computation models

Formal languages and computation models Formal languages and computation models Guy Perrier Bibliography John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman - Introduction to Automata Theory, Languages, and Computation - Addison Wesley, 2006.

More information

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

I have read and understand all of the instructions below, and I will obey the Academic Honor Code. Midterm Exam CS 341-451: Foundations of Computer Science II Fall 2014, elearning section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand all

More information

HW 1 CMSC 452. Morally DUE Feb 7 NOTE- THIS HW IS THREE PAGES LONG!!! SOLUTIONS THROUGOUT THIS HW YOU CAN ASSUME:

HW 1 CMSC 452. Morally DUE Feb 7 NOTE- THIS HW IS THREE PAGES LONG!!! SOLUTIONS THROUGOUT THIS HW YOU CAN ASSUME: HW 1 CMSC 452. Morally DUE Feb 7 NOTE- THIS HW IS THREE PAGES LONG!!! SOLUTIONS THROUGOUT THIS HW YOU CAN ASSUME: The union of a finite number of countable sets is countable. The union of a countable number

More information

Formal Languages and Automata

Formal Languages and Automata Mobile Computing and Software Engineering p. 1/3 Formal Languages and Automata Chapter 3 Regular languages and Regular Grammars Chuan-Ming Liu cmliu@csie.ntut.edu.tw Department of Computer Science and

More information

Chapter 3. Describing Syntax and Semantics

Chapter 3. Describing Syntax and Semantics Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings of Programs:

More information

This Lecture. We will first introduce some basic set theory before we do counting. Basic Definitions. Operations on Sets.

This Lecture. We will first introduce some basic set theory before we do counting. Basic Definitions. Operations on Sets. Sets A B C This Lecture We will first introduce some basic set theory before we do counting. Basic Definitions Operations on Sets Set Identities Defining Sets Definition: A set is an unordered collection

More information

Context Free Languages and Pushdown Automata

Context Free Languages and Pushdown Automata Context Free Languages and Pushdown Automata COMP2600 Formal Methods for Software Engineering Ranald Clouston Australian National University Semester 2, 2013 COMP 2600 Context Free Languages and Pushdown

More information

MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability)

MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability) MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability) Last modified: September 16, 2004 Reference: Apostol, Calculus, Vol. 2, section 13.19 (attached). The aim

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages Syntactic Analysis Dr. Hyunyoung Lee 1 What Is a Programming Language? Language = syntax + semantics The syntax of a language is concerned with the form of a program: how

More information

Languages and Strings. Chapter 2

Languages and Strings. Chapter 2 Languages and Strings Chapter 2 Let's Look at Some Problems int alpha, beta; alpha = 3; beta = (2 + 5) / 10; (1) Lexical analysis: Scan the program and break it up into variable names, numbers, etc. (2)

More information

MA651 Topology. Lecture 4. Topological spaces 2

MA651 Topology. Lecture 4. Topological spaces 2 MA651 Topology. Lecture 4. Topological spaces 2 This text is based on the following books: Linear Algebra and Analysis by Marc Zamansky Topology by James Dugundgji Fundamental concepts of topology by Peter

More information

2 Review of Set Theory

2 Review of Set Theory 2 Review of Set Theory Example 2.1. Let Ω = {1, 2, 3, 4, 5, 6} 2.2. Venn diagram is very useful in set theory. It is often used to portray relationships between sets. Many identities can be read out simply

More information

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1 Chapter Seven: Regular Expressions Formal Language, chapter 7, slide The first time a young student sees the mathematical constant π, it looks like just one more school artifact: one more arbitrary symbol

More information

CS3102 Theory of Computation Solutions to Problem Set 1, Spring 2012 Department of Computer Science, University of Virginia

CS3102 Theory of Computation Solutions to Problem Set 1, Spring 2012 Department of Computer Science, University of Virginia CS3102 Theory of Computation Solutions to Problem Set 1, Spring 2012 Department of Computer Science, University of Virginia Gabriel Robins Please start solving these problems immediately, and work in study

More information

Elementary Recursive Function Theory

Elementary Recursive Function Theory Chapter 6 Elementary Recursive Function Theory 6.1 Acceptable Indexings In a previous Section, we have exhibited a specific indexing of the partial recursive functions by encoding the RAM programs. Using

More information

JNTUWORLD. Code No: R

JNTUWORLD. Code No: R Code No: R09220504 R09 SET-1 B.Tech II Year - II Semester Examinations, April-May, 2012 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science and Engineering) Time: 3 hours Max. Marks: 75 Answer any five

More information

Cantor s Diagonal Argument for Different Levels of Infinity

Cantor s Diagonal Argument for Different Levels of Infinity JANUARY 2015 1 Cantor s Diagonal Argument for Different Levels of Infinity Michael J. Neely University of Southern California http://www-bcf.usc.edu/ mjneely Abstract These notes develop the classic Cantor

More information

Formal Grammars and Abstract Machines. Sahar Al Seesi

Formal Grammars and Abstract Machines. Sahar Al Seesi Formal Grammars and Abstract Machines Sahar Al Seesi What are Formal Languages Describing the sentence structure of a language in a formal way Used in Natural Language Processing Applications (translators,

More information

Recursive Functions. Recursive functions are built up from basic functions by some operations.

Recursive Functions. Recursive functions are built up from basic functions by some operations. Recursive Functions Recursive functions are built up from basic functions by some operations. The Successor Function Let s get very primitive. Suppose we have 0 defined, and want to build the nonnegative

More information

Functions. How is this definition written in symbolic logic notation?

Functions. How is this definition written in symbolic logic notation? functions 1 Functions Def. Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b is the unique element of B assigned by

More information

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

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal. Regular Languages (14 points) Problem 1 (6 points) inimize the following automaton Show that the resulting DFA is minimal. Solution: We apply the State Reduction by Set Partitioning algorithm (särskiljandealgoritmen)

More information

The set consisting of all natural numbers that are in A and are in B is the set f1; 3; 5g;

The set consisting of all natural numbers that are in A and are in B is the set f1; 3; 5g; Chapter 5 Set Theory 5.1 Sets and Operations on Sets Preview Activity 1 (Set Operations) Before beginning this section, it would be a good idea to review sets and set notation, including the roster method

More information

Recursive Functions. 6.1 Primitive Recursive Functions

Recursive Functions. 6.1 Primitive Recursive Functions 6 Recursive Functions The intuitive notion of an effectively computable function is the notion of a function for which there are definite, explicit rules, following which one could in principle compute

More information

Discrete Structures. Fall Homework3

Discrete Structures. Fall Homework3 Discrete Structures Fall 2015 Homework3 Chapter 5 1. Section 5.1 page 329 Problems: 3,5,7,9,11,15 3. Let P(n) be the statement that 1 2 + 2 2 + +n 2 = n(n + 1)(2n + 1)/6 for the positive integer n. a)

More information

COP 3402 Systems Software Syntax Analysis (Parser)

COP 3402 Systems Software Syntax Analysis (Parser) COP 3402 Systems Software Syntax Analysis (Parser) Syntax Analysis 1 Outline 1. Definition of Parsing 2. Context Free Grammars 3. Ambiguous/Unambiguous Grammars Syntax Analysis 2 Lexical and Syntax Analysis

More information

Final Exam 2, CS154. April 25, 2010

Final Exam 2, CS154. April 25, 2010 inal Exam 2, CS154 April 25, 2010 Exam rules. he exam is open book and open notes you can use any printed or handwritten material. However, no electronic devices are allowed. Anything with an on-off switch

More information

Chapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.

Chapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal. Chapter 8 out of 7 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal 8 Matrices Definitions and Basic Operations Matrix algebra is also known

More information

TOPOLOGY, DR. BLOCK, FALL 2015, NOTES, PART 3.

TOPOLOGY, DR. BLOCK, FALL 2015, NOTES, PART 3. TOPOLOGY, DR. BLOCK, FALL 2015, NOTES, PART 3. 301. Definition. Let m be a positive integer, and let X be a set. An m-tuple of elements of X is a function x : {1,..., m} X. We sometimes use x i instead

More information

Theory of Computations Spring 2016 Practice Final Exam Solutions

Theory of Computations Spring 2016 Practice Final Exam Solutions 1 of 8 Theory of Computations Spring 2016 Practice Final Exam Solutions Name: Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try

More information

Regular Expressions. Chapter 6

Regular Expressions. Chapter 6 Regular Expressions Chapter 6 Regular Languages Generates Regular Language Regular Expression Recognizes or Accepts Finite State Machine Stephen Cole Kleene 1909 1994, mathematical logician One of many

More information

CpSc 421 Final Solutions

CpSc 421 Final Solutions CpSc 421 Final Solutions Do any eight of the ten problems below. If you attempt more than eight problems, please indicate which ones to grade (otherwise we will make a random choice). This allows you to

More information

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters : Organization of Programming Languages Context Free Grammars 1 Architecture of Compilers, Interpreters Source Scanner Parser Static Analyzer Intermediate Representation Front End Back End Compiler / Interpreter

More information

Final Course Review. Reading: Chapters 1-9

Final Course Review. Reading: Chapters 1-9 Final Course Review Reading: Chapters 1-9 1 Objectives Introduce concepts in automata theory and theory of computation Identify different formal language classes and their relationships Design grammars

More information

English for Computer Science

English for Computer Science English for Computer Science Mohammad Farshi Department of Computer Science, Yazd University 1388-1389 (CS Dept. Yazd U.) Yazd Univ. English4CS 1388-1389 1 / 15 Azmoone 1389(CS) Azmoone 1389(CS) (CS Dept.

More information

CSE 20 DISCRETE MATH. Fall

CSE 20 DISCRETE MATH. Fall CSE 20 DISCRETE MATH Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse20-ab/ Final exam The final exam is Saturday December 16 11:30am-2:30pm. Lecture A will take the exam in Lecture B will take the exam

More information

The Turing Machine. Unsolvable Problems. Undecidability. The Church-Turing Thesis (1936) Decision Problem. Decision Problems

The Turing Machine. Unsolvable Problems. Undecidability. The Church-Turing Thesis (1936) Decision Problem. Decision Problems The Turing Machine Unsolvable Problems Motivating idea Build a theoretical a human computer Likened to a human with a paper and pencil that can solve problems in an algorithmic way The theoretical machine

More information

Question Bank. 10CS63:Compiler Design

Question Bank. 10CS63:Compiler Design Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a

More information

The Further Mathematics Support Programme

The Further Mathematics Support Programme Degree Topics in Mathematics Groups A group is a mathematical structure that satisfies certain rules, which are known as axioms. Before we look at the axioms, we will consider some terminology. Elements

More information