The Programming Language L

Slides:



Advertisements
Similar presentations
November 19, 2009Theory of Computation Lecture 19: Calculations on Strings IV 1 Numerical Representation of Strings Correspondingly, we define the following:
Advertisements

1 Turing Machines and Equivalent Models Section 13.2 The Church-Turing Thesis.
October 13, 2009Theory of Computation Lecture 11: A Universal Program III 1 Coding Programs by Numbers Gödel numbers are usually very large, even for small.
Simulating a modern computer by a Turing machine and vice versa CS 6800 Instructor: Dr. Elise de Doncker By Shweta Gowda Saikiran Ponnam.
1 Section 14.1 Computability Some problems cannot be solved by any machine/algorithm. To prove such statements we need to effectively describe all possible.
October 27, 2009Theory of Computation Lecture 12: A Universal Program IV 1Universality Then we append the following instruction: [C]IF K = Lt(Z) + 1 
November 10, 2009Theory of Computation Lecture 16: Computation on Strings I 1Diagonalization Another example: Let TOT be the set of all numbers p such.
December 8, 2009Theory of Computation Lecture 22: Turing Machines IV 1 Turing Machines Theorem 1.1: Any partial function that can be computed by a Post-
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Data Flow Analysis Compiler Design Nov. 8, 2005.
October 8, 2009Theory of Computation Lecture 10: A Universal Program II 1 Pairing Functions and Gödel Numbers This way the equation  x, y  = z defines.
September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 1 Macros Now we want to use macros of the form: W  f(V 1, …,
Introduction to C Programming
Theory of Computation. Computation Computation is a general term for any type of information processing that can be represented as an algorithm precisely.
Chapter 4: A Universal Program 1. Coding programs Example : For our programs P we have variables that are arranged in a certain order: Y 1 X 1 Z 1 X 2.
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
December 1, 2009Theory of Computation Lecture 21: Turing Machines II 1 Simulation of L n in T We will now construct a Post-Turing program Q that simulates.
Program Design. The design process How do you go about writing a program? –It’s like many other things in life Understand the problem to be solved Develop.
Theory of Computation Automata Theory Dr. Ayman Srour.
General Discussion of “Properties” The Pumping Lemma Membership, Emptiness, Etc.
CST 1101 Problem Solving Using Computers
CSE202: Introduction to Formal Languages and Automata Theory
Applied Discrete Mathematics Week 2: Functions and Sequences
INTRODUCTION TO PROBLEM SOLVING
ARITHMETIC IN C Operators.
Theory of Computation Lecture 4: Programs and Computable Functions II
Chapter 2 - Introduction to C Programming
Theory of Computation Lecture 12: A Universal Program III
Diagonalization and Reducibility
Pushdown Automata.
Introduction To Flowcharting
Theory of Computation Lecture 23: Turing Machines IV
Theory of Computation Lecture 14: A Universal Program V
Numerical Representation of Strings
Theory of Computation Lecture 22: Turing Machines III
Chapter 2 - Introduction to C Programming
Turing Machines Acceptors; Enumerators
11/10/2018.
Theory of Computation Lecture 5: Programs and Computable Functions III
Theory of Computation Lecture 6: Primitive Recursive Functions I
Copyright © Cengage Learning. All rights reserved.
Chapter 2 - Introduction to C Programming
Fundamentals of Programming
Chapter 2 - Introduction to C Programming
Coding Concepts (Basics)
Theory Of Computer Science
Introduction to Algorithms and Programming
Faculty of Computer Science & Information System
Chapter 2 - Introduction to C Programming
The Programming Language L
Chapter 8. General LP Problems
P.V.G’s College of Engineering, Nashik
Theory of Computation Lecture 21: Turing Machines II
Chapter 2 - Introduction to C Programming
Diagonalization and Reducibility
Chapter 8. General LP Problems
Instructor: Aaron Roth
Theory of Computation Lecture 5: Programs and Computable Functions III
Numerical Representation of Strings
Theory of Computation Lecture 4: Programs and Computable Functions II
Chapter 13 Conditional Repetition
Pairing Functions and Gödel Numbers
Chapter 8. General LP Problems
Theory of Computation Lecture 22: Turing Machines II
Theory of Computation Lecture 17: Calculations on Strings II
Theory of Computation Lecture 12: A Universal Program IV
Theory of Computation Lecture 11: A Universal Program III
Theory of Computation Lecture 23: Turing Machines III
Presentation transcript:

The Programming Language L We will explore computability theory using an extremely simple programming language called L. Let us take a look at this language. L uses variables holding numbers. Throughout the course, ‘number’ will refer to a nonnegative integer. The variables named X1, X2, X3, … are the input variables of L, Y is the output variable of L, and Z1, Z2, Z3, … are the local variables of L. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

The Programming Language L We do not have to write the subscript 1, so instead of X1 or Z1 we can write X or Z. L also includes labels. These labels are named A1 B1 C1 D1 E1 A2 B2 C2 D2 E2 … … … … … Again, the subscript 1 can be omitted. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

The Programming Language L A program of L consists of a list (a finite sequence) of instructions. What do the instructions look like? There are only three types of instructions in L: increment decrement conditional branch January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

The Programming Language L In the following list of instructions, the letter V stands for any variable in the program, and L stands for a label: V  V+1 increase by 1 the value of the variable V V  V-1 If the value of V is 0, leave it unchanged; otherwise decrease by 1 the value of the variable V. If V0 GOTO L If the value of V is nonzero, perform the instruction with label L next; otherwise proceed to the next instruction in the list. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

The Programming Language L These are the only three instructions in our language L. You will be surprised how powerful this extremely simple programming language is. We just need two more conventions: The output variable Y and the local variables Zi initially have the value 0. A program halts when it attempts to move to a nonexistent instruction (beyond the end of the list) or branch to a nonexistent label. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

The Programming Language L Note that we have an unlimited supply of variables and labels. Moreover, there is no upper limit on the value that a variable can contain. Therefore, the language L is not a practical language, but it is well-suited for the theoretical evaluation of algorithms. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs Consider the following program: [A] X  X-1 Y  Y+1 IF X0 GOTO A What function does this program compute? f(x) = 1, if x = 0 = x, otherwise. What would we have to change if we wanted to compute the function f(x) = x? January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs The following program computes f(x) = x: [A] IF X0 GOTO B Z  Z+1 IF Z0 GOTO E [B] X  X-1 Y  Y+1 IF X0 GOTO B January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs In the previous example, the lines Z  Z+1 IF Z0 GOTO L were used to implement an instruction that we could call GOTO L First, we make sure that Z has a nonzero value, and then the conditional branch (actually, here it is an unconditional branch) is executed. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs From now on we will use the macro GOTO L in our programs. We know that we could always replace GOTO L with its macro expansion to obtain a valid L program. Now remember the program computing the function f(x) = x. Although it computes its output correctly, it deletes (sets to zero) the original input. This is an undesirable behavior, so we should come up with an improved program. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs [A] IF X0 GOTO B GOTO C [B] X  X-1 Y  Y+1 Z  Z+1 GOTO A [C] IF Z0 GOTO D GOTO E [D] Z  Z-1 X  X+1 January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs The previous program justifies the introduction of a macro VV’ The execution of this macro will replace the contents of variable V by those of variable V’ without changing the contents of V’. However, there is one problem: The previous program could rely on the initial condition Y = 0, which is not guaranteed for any variable V. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs To solve this problem, we introduce the macro V0 Its macro expansion is: [L] V  V-1 IF V0 GOTO L Of course, the label L has to be chosen to be different from any other label in the program. Now we can write down the macro expansion of VV’: January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs V  0 [A] IF V’0 GOTO B GOTO C [B] V’  V’-1 V  V+1 Z  Z+1 GOTO A [C] IF Z0 GOTO D GOTO E [D] Z  Z-1 V’  V’+1 January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I Sample Programs Another example: f(x1, x2) = x1 + x2 Y  X1 Z  X2 [B] IF Z0 GOTO A GOTO E [A] Z  Z-1 Y  Y+1 GOTO B January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L We will now develop a precise mathematical description of the programming language L. The symbols X1, X2, X3, … are called input variables, Z1, Z2, Z3, … are called local variables, and Y is called the output variable of L. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L The symbols A1, B1, C1, D1, E1, A2, B2, C2, … are called labels of L. For variables and labels, the subscript 1 can always be omitted. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L A statement is one of the following: V  V+1 V  V-1 V  V IF V0 GOTO L Here, V may be any variable and L may be any label. Note that the statement V  V leaves all values unchanged, so it is a “dummy” command. We will later see why it is useful to have V  V in our set of statements. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L An instruction is either a statement (unlabeled instruction) or [L] followed by a statement (instruction labeled L) A program is a list (i.e., a finite sequence) of instructions. The length of this list is called the length of the program. We also include the empty program – the program of length 0 – in the set of all programs. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L While a program is being executed, its variables assume different numerical values. This motivates the concept of the state of a program: A state of a program P is a list of equations of the form V = m, where V is a variable and m is a number, including exactly one equation for each variable that occurs in P (and possibly equations for other variables). January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L Consider the following program P : [A] IF X0 GOTO B Z  Z+1 IF Z0 GOTO E [B] X  X-1 Y  Y+1 IF Z0 GOTO A Is the list X = 4, Y = 3, Z = 3 a state of P ? Yes. How about X1 = 4, X2 = 5, Y = 4, Z = 4? Yes. And X = 3, Z = 3? No. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L Let  be a state of P and let V be a variable that occurs in . The value of V at  is then the unique number q such that the equation V = q is one of the equations in . For example, the value of X at the state X = 4, Y = 3, Z = 3 is 4. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L Consider a machine that can execute programs of L. During program execution, this machine needs to store the state of a program, i.e., keep track of the values of variables. Is there anything else that needs to be stored? Yes, we also need to store which instruction is to be executed next. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L Therefore, we define a snapshot or instantaneous description of a program P of length n to be a pair (i, ) where 1  i  (n + 1), and  is a state of P. The number i indicates the number of the instruction that is to be executed next. i = n + 1 corresponds to a “stop” instruction. A snapshot (i, ) of a program P of length n is called terminal if i = n + 1. If s = (i, ) is a snapshot of P and V is a variable of P , then the value of V at s just means the value of V at . January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L If (i, ) is a nonterminal snapshot of P , we define the successor of (i, ) to be the snapshot (j, ) defined as follows: Case 1: The i-th instruction of P is V  V+1 and  contains the equation V = m. Then j = i + 1 and  is obtained from  by replacing the equation V = m with V = m + 1 (the value of V at  is m + 1). January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L Case 2: The i-th instruction of P is V  V-1 and  contains the equation V = m. Then j = i + 1 and  is obtained from  by replacing the equation V = m with V = m – 1 if m  0. If m = 0, then  = . Case 3: The i-th instruction of P is V  V. Then j = i + 1 and  = . January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I

Theory of Computation Lecture 2: Programs and Computable Functions I The Syntax of L Case 4: The i-th instruction of P is IF V0 GOTO L. Then  =  and there are two subcases: Case 4a:  contains the equation V = 0. Then j = i + 1. Case 4b:  contains the equation V = m where m  0. Then, if there is an instruction of P labeled L, j is the least number such that the j-th instruction of P is labeled L. Otherwise, j = n + 1. January 31, 2019 Theory of Computation Lecture 2: Programs and Computable Functions I