Conference: Week 0

Table Of Contents

Welcome!

Computability

The most important item from lecture:

Thought Question

Suppose you are given the code for a function \({\tt Crashes}\):

boolean Crashes(String program, String n) { ... }

This function can determine whether a program \(P\) crashes with an error on input \(n\).
Specifically, a call Crashes(P,n) returns:

You can assume \(P\) looks like a function body in Java or a sequence of statements in Python, and that the only errors that can occur are division by 0. For example, if \(P\) is:

if (n > 0) {
  n = n - 1;
} else {
  print 10 / n;
}

Then Crashes(P, "10") returns false, but Crashes(P, "0") returns true.

Write a Java function Halt that reads a program text \(P\) as input, reads a String \(n\) as input, and then decides whether \(P\) halts on input \(n\). Such a Halt program would have the following form, and it would

void Halt() {
  String P = readString();
  String n = readString();
  ...
}

To do this, just describe what replaces  \(\ldots\)  in the Halt program definition above.

Solution
void Halt() {
  String P = readString();
  String n = readString();
  String P';
  P' = P with "print 10/0;" inserted right before each
     "return" statement;
  return Crashes(P', n);
}