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, …,

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.
Primitive Recursive Functions (Chapter 3)
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.
Mu-Recursive Functions
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-
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.
Computability and Complexity 10-1 Computability and Complexity Andrei Bulatov Gödel’s Incompleteness Theorem.
September 24, 2009Theory of Computation Lecture 6: Primitive Recursive Functions II 1 Homework Questions Question 1: Write a program P that computes 
Describing Syntax and Semantics
October 1, 2009Theory of Computation Lecture 8: Primitive Recursive Functions IV 1 Primitive Recursive Predicates Theorem 6.1: Let C be a PRC class. If.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
November 3, 2009Theory of Computation Lecture 14: A Universal Program VI 1 Recursively Enumerable Sets Definition: We write: W n = {x  N |  (x, n) 
1 10. Joint Moments and Joint Characteristic Functions Following section 6, in this section we shall introduce various parameters to compactly represent.
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.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 20 By Herbert I. Gross and Richard A. Medeiros next.
Computability Turing machines for functions. Recursive functions. Homework: Modify class example for addition to produce contiguous 1s. Construct TM for.
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.
Universidad Nacional de ColombiaUniversidad Nacional de Colombia Facultad de IngenieríaFacultad de Ingeniería Departamento de Sistemas- 2002Departamento.
Lecture 1: A Formal Model of Computation 虞台文 大同大學資工所 智慧型多媒體研究室.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Recursive Algorithms &
1 Section 13.2 The Church-Turing Thesis The Church-Turing Thesis: Anything that is intuitively computable can be be computed by a Turing machine. It is.
Mathematical Preliminaries
Lecture # 12. Nondeterministic Finite Automaton (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label.
September 29, 2009Theory of Computation Lecture 7: Primitive Recursive Functions III 1 Some Primitive Recursive Functions Example 3: h(x) = x! Here are.
Theory of Computation Lecture 5: Primitive Recursive Functions I
Computability Go over homework problems. Godel numbering. Homework: prepare for midterm.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
October 4, 2016Theory of Computation Lecture 9: A Universal Program I 1Minimalization Example 15: R(x, y) R(x, y) is the remainder when x is divided by.
Another Word on PRC Classes
Theory of Computation Lecture 10: A Universal Program I
Theory of Computation Lecture 4: Programs and Computable Functions II
Theory of Computation Lecture 12: A Universal Program III
Theory Of Computer Science
Theory of Computation Lecture 14: A Universal Program V
Recursively Enumerable Sets
Numerical Representation of Strings
Theory of Computation Lecture 22: Turing Machines III
Theory of Computation Lecture 16: A Universal Program VII
Theory of Computation Lecture 5: Programs and Computable Functions III
Copyright 2013, 2009, 2005, 2001, Pearson Education, Inc.
Theory of Computation Lecture 6: Primitive Recursive Functions I
Theory Of Computer Science
The Programming Language L
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 21: Turing Machines II
Numerical Representation of Strings
Diagonalization and Reducibility
Recursively Enumerable Sets
Primitive Recursive Predicates
Theory of Computation Lecture 5: Programs and Computable Functions III
The Programming Language L
Numerical Representation of Strings
Theory of Computation Lecture 4: Programs and Computable Functions II
Numerical Representation of Strings
Theory of Computation Lecture 9: A Universal Program I
Pairing Functions and Gödel Numbers
Theory of Computation Lecture 6: Primitive Recursive Functions I
Some Primitive Recursive Functions
Theory of Computation Lecture 22: Turing Machines II
Theory of Computation Lecture 13: A Universal Program V
Recursively Enumerable Sets
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
12 Chapter Chapter 2 Exponential and Logarithmic Functions.
Presentation transcript:

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, …, V n ) in our programs, where W, V 1, …, V n can be any variables; W could be among V 1, …, V n. We expand the macro as follows: Zm  0Zm  0Zm  0Zm  0 Z m+1  V 1 Z m+2  V 2 : Z m+n  V n Z m+n+1  0 Z m+n+2  0 : Z m+n+k  0 QmQmQmQm [E m ]W  Z m

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 2 Macros Whenever we expand a macro, the number m has to be chosen large enough so that none of the variables or labels in Q m occur in the main program. Note that in the expansion the output and local variables are set to zero, although at the start of the main program they are set to zero anyway. This is necessary because the macro expansion may be part of a loop in the main program.

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 3 Macros Obviously, if f(V 1, …, V n ) is undefined (  ), the program Q m will never terminate. So if f is not total, and the macro W  f(V 1, …, V n ) is encountered when V 1, …, V n have values for which f is not defined, the main program will never terminate. Example: Z  X 1 – X 2 Y  Z + X 3 This program computes f(x 1,x 2,x 3 ), where f(x 1,x 2,x 3 ) = (x 1 - x 2 ) + x 3, if x 1  x 2 = , if x 1 < x 2 = , if x 1 < x 2

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 4 Macros Now let us introduce macros of the form IF P(V 1, …,V n ) GOTO L, where P(x 1, …,x n ) is a computable predicate. This will be based on the convention that TRUE = 1, FALSE = 0. According to this convention, predicates are just total functions whose values are always either 0 or 1.

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 5 Macros Let P(x 1, …,x n ) be a computable predicate. Then we expand the macro IF P(V 1, …,V n ) GOTO L to Z  P(V 1, …,V n ) IF Z  0 GOTO L As usual, the variable Z has to be chosen to create no conflicts with the main program.

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 6 Macros Example: How can we expand the macro IF V=0 GOTO L ? V = 0 corresponds to the following predicate P(x): P(x) = TRUE, if x = 0 = FALSE, otherwise = FALSE, otherwise This can be computed by the following program: IF X  0 GOTO E Y  Y+1

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 7 (Partially) Computable Functions By introducing macros, we have seen that it is possible to compute complex functions with our very simple programming language L. Notice that macros do not change the specification of the language, but they just simplify writing down programs. As you know, we can always replace macros with actual code. So what are the limitations of the language L ? In order to find out, we need to do some mathematics.

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 8 Composition Let us combine computable functions in such a way that the output of one becomes an input to another. For example, we could combine the functions f and g to obtain a new function h: h(x) = f(g(x)) Let us now take a more general view: Definition: Let f be a function of k variables and let g 1, …, g k be functions of n variables. Let h(x 1, …, x n ) = f(g 1 (x 1, …, x n ), …, g k (x 1, …, x n )). Then h is said to be obtained from f and g 1, …, g k by composition.

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 9 Composition Theorem 1.1: If h is obtained from the (partially) computable functions f, g 1, …, g k by composition, then h is (partially) computable. Proof: The following program obviously computes h: Z 1 ← g 1 (X 1, …, X n ) : Z k ← g k (X 1, …, X n ) Y ← f(Z 1, …, Z k ) If f, g 1, …, g k are not only partially computable but are also total, then so is h. ■

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 10 Composition Example: We know that f(x 1, x 2 ) = x 1 + x 2 is a computable function. We also know that g 1 (x) = x 2 and g 2 (x) = 3x are computable functions. According to Theorem 1.1, the following function h(x) must then also be computable: h(x) = f(g 1 (x), g 2 (x)) = f(x 2, 3x) = x 2 + 3x

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 11 Recursion Let k be some fixed number and h(0) = k h(t + 1) = g(t, h(t)), where g is some given total function of two variables. Then we say that h is obtained from g by primitive recursion, or simply recursion. Theorem 2.1: Let h be obtained as shown above, and let g be computable. Then h is also computable.

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 12RecursionProof: Obviously, the function f(x) = k is computable. The program computing f(x) simply consists of k times the instruction Y ← Y+1. This gives us the macro Y ← k. Now we can write a program that computes h(x): This is your homework question 1!

September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 13 More Homework Questions Question 2: Let P be the following program: IF X ≠ 0 GOTO A Z ← Z + 1 IF Z ≠ 0 GOTO B [A] X ← X – 1 Y ← Y + 1 IF X ≠ 0 GOTO A [B] Y ← Y + 1 Y ← Y + 1 What is the function f(x) computed by P ? Question 3: Write a program in L that computes f(x) = 2x without using any macros. After the program terminates, the variable X must contain its initial value (the input).