Docsity

CS 581 Assignment 9: Self-Printing Programs and Recursion Theorem - Prof. James G. Hook, Assignments of Computer Science

Toggle sidebar
bg1
CS 581: Theory of Computation
James Hook
Assignment 9
Due at the final class meeting.
1. Argue that your favorite programming language is an Acceptable Pro-
gramming System.
2. In Kozen’s text Theory of Computation he gives applications of the Re-
cursion Theorem as Lecture 34. In that Lecture he gives an example of a
self-printing program. Such programs are called ā€œquinesā€. I have adapted
Kozen’s quine for C to work on my computer as follows:
#include<stdio.h>
char *s="%cinclude<stdio.h>%cchar *s=%c%s%c;%cmain(){printf(s,35,10,34,s,34,10,10);}%c";
main(){printf(s,35,10,34,s,34,10,10);}
Note that the decimal numbers 10, 34, and 35 represent the ASCII char-
acters newline, double quote, and sharp sign.
Write a ā€œquineā€ (a self-printing program) for another programming lan-
guage.
3. This problem follows Kozen’s formation, but it is not necessary to read
Kozen’s text to solve the problem.
Kozen illustrates the application of the recursion theorem by consider-
ing the following program transformation, which takes a program P and
returns a new program that contains P:
P7→ Ī»x. 1,if x= 0
xĀ·P(xāˆ’1),otherwise.
(Note: In this example λis being used as a generic notation for anonymous
functions. This is not an official Ī»-calculus program.)
Adapt this fixed-point construction to your favorite programming lan-
guage. Use this construction and the fixed-point version of the recursion
theorem presented in class to justify that the factorial function is defin-
able in your favorite programming language. (This should be the same
language you previously showed was an acceptable programming system.)
Pay careful attention to when you are generating and/or transforming a
program and when you are executing the program.
Note that your solution will not directly define the factorial function, but
it will prove that, as a consequence of the recursion theorem, the factorial
function can be defined in your favorite programming language.
1

Partial preview of the text

Download CS 581 Assignment 9: Self-Printing Programs and Recursion Theorem - Prof. James G. Hook and more Assignments Computer Science in PDF only on Docsity!

CS 581: Theory of Computation

James Hook

Assignment 9

Due at the final class meeting.

  1. Argue that your favorite programming language is an Acceptable Pro- gramming System.
  2. In Kozen’s text Theory of Computation he gives applications of the Re- cursion Theorem as Lecture 34. In that Lecture he gives an example of a self-printing program. Such programs are called ā€œquinesā€. I have adapted Kozen’s quine for C to work on my computer as follows:

#include<stdio.h> char *s="%cinclude<stdio.h>%cchar *s=%c%s%c;%cmain(){printf(s,35,10,34,s,34,10,10);}%c"; main(){printf(s,35,10,34,s,34,10,10);}

Note that the decimal numbers 10, 34, and 35 represent the ASCII char- acters newline, double quote, and sharp sign. Write a ā€œquineā€ (a self-printing program) for another programming lan- guage.

  1. This problem follows Kozen’s formation, but it is not necessary to read Kozen’s text to solve the problem. Kozen illustrates the application of the recursion theorem by consider- ing the following program transformation, which takes a program P and returns a new program that contains P:

P 7 → Ī»x.

1 , if x = 0 x Ā· P (x āˆ’ 1), otherwise.

(Note: In this example Ī» is being used as a generic notation for anonymous functions. This is not an official Ī»-calculus program.) Adapt this fixed-point construction to your favorite programming lan- guage. Use this construction and the fixed-point version of the recursion theorem presented in class to justify that the factorial function is defin- able in your favorite programming language. (This should be the same language you previously showed was an acceptable programming system.) Pay careful attention to when you are generating and/or transforming a program and when you are executing the program. Note that your solution will not directly define the factorial function, but it will prove that, as a consequence of the recursion theorem, the factorial function can be defined in your favorite programming language.