Übung - 8 - Musterlösung

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Hochschule Deggendorf

Prof. Dr. Peter Jüttner

Vorlesung: Semantik, Komplexitätstheorie SS 2020


und Berechenbarkeit
Übung 8 Termin

Computability

1. Proof that all loop-programs terminate.

A loop-program consists of a finite number of loops. Each loop has a finite number of
executions. I.e. the execution terminates after a finite time.

2. Proof that all loop-computable functions f: n are total functions.

As all loop-computable programs terminate, there is no input where the execution


does not terminate.

3. What is the consequence of exercise 2 concerning the computability of functions


using a Turing Machine and functions using a loop program?

As Turing Machines can compute partial functions, not all functions that can be
computed by Turing Machines can be computed by loop-programs

4. Simulate if (v==0) {P1;} else {P2;} using a loop program with a variable v

then-Zweig: z=1-v; for (x=1; x<=z; x = x+1){P1}


else-Zweig: z = v-(v-1); for (x=1; x<=z; x=x+1) {P2}

5. Simulate xi + xj for two variables xi and xj by a loop program

for (z=1; z<=xj; z++) {v0 = xi + 1; }

6. Simulate xi * xj for two variables xi and xj by a loop program

Same as 6, used the simulated + to simulate *

7. Simulate a loop-program using a while-program

for(y=1; y <= x; y= y+1) { P; }

y := x;
While (y != 0) { y := y - 1; P; } condition: y is a new variable not used in P
8. Transform the following Goto-program in a corresponding While-program using only
one While-loop. The value of variable x0 is the final result.

x1 = read(); // the values of x1 and x2 shall be read from console.


x2 = read();
M1: if (x1>=x2) goto M2;
x0 = x1; //
halt;
M2: x1 = x1 - x2;
goto M1;

You might also like