RAM Computable Functions and Interpreter Implementation, Assignments of Theory of Computation

The RAM computability of two functions and provides instructions for implementing a RAM program interpreter. The functions involve reversing a string and concatenating it with itself. The interpreter implementation involves assuming instructions with five fields and opcodes such as add, tail, clr, assign, gotoa, gotob, jmpa, jmpb, and continue. The program should output the input RAM program, input strings, computed function value, and memory contents. The document also provides a sample Matlab program for the interpreter implementation.

Typology: Assignments

2020/2021

Uploaded on 05/11/2023

pierc
pierc 🇺🇸

4.3

(4)

220 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Fall 2021 CIS 511
Introduction to the Theory of Computation
Jean Gallier
Homework 5
November 10 2021; Due November 24, 2021
Problem B1 (40 pts). (1) Prove that the function, f: ΣΣ, given by
f(w) = wR
is RAM computable. = {a1, . . . , aN}).
(2) Prove that the function, f: ΣΣ, given by
f(w) = www
is RAM computable. = {a1, . . . , aN}).
For simplicity, you may assume that N= 2.
You must run your interpreter from B2 on these two RAM programs for a few inputs.
Show the two RAM programs as specified in the syntax of your interpreter in B2.
Problem B2 (80 pts). Write a computer program implementing a RAM program inter-
preter. You may want to assume that the instructions have five fields
N X opcode j Y
N X opcode j N 1
with j {1, . . . , k}, where kis the number of symbols in Σ, and that the opcodes are
add tail clr assign gotoa gotob jmpa jmpb continue
where gota corresponds to jump above, gotob to jump below, jpma corresponds to jump
above if condition is satisfied, and jmpb to to jump below if condition is satisfied. Depending
on the opcode, some of the fields may be irrelevant (set them to 0).
The number of input registers is n(so your memory must have at least nregisters), and
the total number of registers is p. The number k, n p are input to your interpreter, as well
as the program to be executed (a sequence of instructions). Assume that line numbers are
integers. Also, to simplify matters, you may assume that you only consider alphabets of size
at most 10, so that a1, . . . , ak(k10) are represented by the digits 0,1,...,9.
Your program should output.
1
pf3
pf4

Partial preview of the text

Download RAM Computable Functions and Interpreter Implementation and more Assignments Theory of Computation in PDF only on Docsity!

Fall 2021 CIS 511

Introduction to the Theory of Computation

Jean Gallier

Homework 5

November 10 2021; Due November 24, 2021

Problem B1 (40 pts). (1) Prove that the function, f : Σ∗^ → Σ∗, given by

f (w) = wR

is RAM computable. (Σ = {a 1 ,... , aN }).

(2) Prove that the function, f : Σ∗^ → Σ∗, given by

f (w) = www

is RAM computable. (Σ = {a 1 ,... , aN }).

For simplicity, you may assume that N = 2. You must run your interpreter from B2 on these two RAM programs for a few inputs. Show the two RAM programs as specified in the syntax of your interpreter in B2.

Problem B2 (80 pts). Write a computer program implementing a RAM program inter- preter. You may want to assume that the instructions have five fields

N X opcode j Y N X opcode j N 1

with j ∈ { 1 ,... , k}, where k is the number of symbols in Σ, and that the opcodes are

add tail clr assign gotoa gotob jmpa jmpb continue

where gota corresponds to jump above, gotob to jump below, jpma corresponds to jump above if condition is satisfied, and jmpb to to jump below if condition is satisfied. Depending on the opcode, some of the fields may be irrelevant (set them to 0). The number of input registers is n (so your memory must have at least n registers), and the total number of registers is p. The number k, n p are input to your interpreter, as well as the program to be executed (a sequence of instructions). Assume that line numbers are integers. Also, to simplify matters, you may assume that you only consider alphabets of size at most 10, so that a 1 ,... , ak (k ≤ 10) are represented by the digits 0, 1 ,... , 9.

Your program should output.

  1. The input RAM program P
  2. The input strings w 1 ,... , wn to the RAM program P.
  3. The value of the function being computed.
  4. The sequence consisting of the memory contents and the current program counter as your interpreter executes the RAM program.

Test your interpreter on several RAM programs (and input strings), including the programs of B1.

To give you an idea of an implementation of this interpreter in Matlab here is the begin- ning of my program.

% % RAM interpreter % % opcodes are coded numerically as follows: % % add = 1; tail = 2; clr = 3; assign = 4; gotoa = 5; gotob = 6; jmpa = 7; % jpmb = 8; continue = 9 % % Instructions have 5 fields % N X opcode j Y % N X opcode j N % where j corresponds to symbol a_j % There are n input registers, a total number of p registers, and the % alphabet size is k; symbols are coded as 1, 2, ..., k % line numbers are nonnegative; unused line numbers are negative % The registers are numbers 1, 2, ..., p % The input RAM progrm is in RAMprog % The program counter is pc % input is a list indata containing the n input strings % % function [res, pc, regs, counter] = RAMinterp(RAMprog, n, p, k, indata) lenprog = size(RAMprog, 1); % % insert your code here %

To run this program I used the following input file.

%

Problem B3 (30 pts). (1) Prove that the extended pairing function 〈x 1 ,... , xn〉n defined in the notes (see Definition 3.2 of the notes) satisfies the equation

〈x 1 ,... , xn, xn+1〉n+1 = 〈x 1 , 〈x 2 ,... , xn+1〉n〉.

Compute 〈 2 , 5 , 7 , 17 〉 4 (this integer has 10 digits). (2) Prove that 〈x, 0 〉 = 〈x, 0 ,... , 0 〉n for all n ≥ 2 and all x ∈ N. (3) Prove that 〈Π(1, n, z),... , Π(n, n, z)〉n = z

for all n ≥ 1 and all z ∈ N.

Problem B4 (30 pts). Ackermann’s function A is defined recursively as follows:

A(0, y) = y + 1, A(x + 1, 0) = A(x, 1), A(x + 1, y + 1) = A(x, A(x + 1, y)).

Prove that

A(0, x) = x + 1, A(1, x) = x + 2, A(2, x) = 2x + 3, A(3, x) = 2x+3^ − 3 ,

and

A(4, x) = 2^2

···

x − 3 ,

with A(4, 0) = 16 − 3 = 13. Equivalently (and perhaps less confusing)

A(4, x) = 2^2

···

x+ − 3.

Problem B5 (10 pts). Let f : N → N be a total computable function. Prove that if f is a bijection, then its inverse f −^1 is also (total) computable.

TOTAL: 190 points.