CS 334: HW 0

Reading

Problems

1. Computing Environment (0 points)

In preparation for the semester, please do the following:

  1. Carefully read the syllabus and the submission instructions at the bottom of this pabe.

  2. You will recieve an email about setting up your account on Gradescope. Please log in and complete that process. You will submit work through Gradescope.

  3. Set up the recommended software from the software page.

  4. Your answers must be submitted as a single PDF each week. There are many ways to prepare a PDF:

    • Latex
    • Markdown
    • GoogleDoc
    • Word
    • Write by hand and scan/photograph your answers

    All of these are fine. Even plain text would work reasonably well, although some basic formatting would make your life easier. You will likely want to include figures in problem sets some weeks --- for this you can use a drawing program or just draw by hand and take pictures.

    Here are a few resources if you'd like to use latex or markdown:

2. Partial and Total Functions (10 points)

For each of the following function definitions, give the graph of the function. Say whether this is a partial function or a total function on the integers. If the function is partial, say where the function is defined and undefined.

For example, the graph of \tt f(x) = if\ x>0\ then\ x+2\ else\ x/0 is the set of ordered pairs \{ \langle x, x+2\rangle \,|\, x>0\}. This is a partial function. It is defined on all integers greater than 0 and undefined on integers less than or equal to 0.

Functions:

  1.    \tt f(x) = if\ x+2>3\ then\ x*5\ else\ x/0

  2.    \tt f(x) = if\ x<0\ then\ 1\ else\ f(x-2)

  3.    \tt f(x) = if\ x=0\ then\ 1\ else\ f(x-2)

3. Deciding Simple Properties of Programs (10 points)

Suppose you are given the code for a function {\tt Halt0} that can determine whether a program P requiring no input halts. Can you solve the halting problem using {\tt Halt0}?

To be more precise, suppose I give you a Java function

boolean Halt0(String program)

where calling the function with the source code for program P has the following behavior. Halt0(P) returns:

  • true if program P will halt without reading any input when executed; and
  • false if program P will not halt when executed.

You should not make any assumptions about the behavior of Halt0 on arguments that do not consist of a syntactically correct program.

Can you write a Java program Halt that reads a program text P as input, reads an integer n as input, and then decides whether P halts when it reads n as input? Such a Halt program would have the following form, and it would print "yes" if P halts when it runs and reads input n a nd "no" if P does not halt when it runs and reads input n:

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

You may assume that any program P read by your program begins with a statement that reads a single integer from standard input, and then performs operations Q. That is, all programs P read at the start of your Halt function will have the form

String x = readInteger();
Q

where Q is the rest of the program text, and Q does not perform any input.

If you believe that the halting problem can be solved if you are given Halt0, then explain your answer by describing how a program solving the halting problem would work. To do this, just describe what replaces  \ldots  in the Halt program definition above. If you believe that the halting problem cannot be solved using Halt0, then explain briefly why you think not.

Submitting Your Work

Submit your homework via GradeScope by the beginning of class on the due date.

Written Problems

Submit your answers to the Gradescope assignment named, for example, "HW 1". It should:

  • be clearly written or typed,
  • include your name and HW number at the top,
  • list any students with whom you discussed the problems, and
  • be a single PDF file, with one problem per page.

You will be asked to resubmit homework not satisfying these requirements. Please select the pages for each question when you submit.

Programming Problems

If this homework includes programming problems, submit your code to the Gradescope assignment named, for example, "HW 1 Programming". Also:

  • Be sure to upload all source files for the programming questions, and please do not change the names of the starter files.
  • If you worked with a partner, only one of each pair needs to submit the code.
  • Indicate who your partner is when you submit the code to gradescope. Specifically, after you upload your files, there will be an "Add Group Member" button on the right of the Gradescope webpage -- click that and add your partner.

Autograding: For most programming questions, Gradescope will run an autograder on your code that performs some simple tests. Be sure to look at the autograder output to verify your code works as expected. We will run more extensive tests on your code after the deadline. If you encounter difficulties or unexpected results from the autograder, please let us know.