CSCI 341 Theory of Computation

Fall 2025, with Schmid
← church turing thesis

Reducing One Problem to Another

The title of this section is likely something you do all the friggin time: take a solution to a problem that you already know how to solve, and then re-use it later when you are solving a more difficult problem. A reduction of one problem to another, in the formal sense that we are just about to introduce, is not much more complicated than that. In any case, it helps to see this happen in real time via an example.

We are going to start with the tasks of representing \(S(n) = n + 1\) and \(P(n) = \max(0, n - 1)\), i.e., successor and predecessor, in binary.

For predecessor, in pseudocode, one way to proceed would be to do the following.

  1. If the only digit is \(0\), then halt.
  2. If the only digit is \(1\), then flip it to a \(0\) and halt.
  3. Move to the end of the string of \(0\)s and \(1\)s.
  4. If the last digit is \(1\), flip it to a \(0\) and halt.
  5. If the last digit is \(0\), then we change it to a \(1\) and move left.
  6. If there are no digits to the left and the current digit is \(1\), erase the \(1\) and halt.
  7. Otherwise, return to Step 4.
So, for example, if our number in binary is \(10000\), then it should go through the following changes: \[\begin{array}{c c c c c} \triangledown & & & & \\ 1 & 0 & 0 & 0 & 0 \\ & & & & \triangledown & Step~3 \\ 1 & 0 & 0 & 0 & 0 \\ & & & \triangledown & & Step~5, 7\\ 1 & 0 & 0 & 0 & 1 \\ & & \triangledown & & & Step~5, 7\\ 1 & 0 & 0 & 1 & 1 \\ & \triangledown & & & & Step~5, 7\\ 1 & 0 & 1 & 1 & 1 \\ \triangledown & & & & & Step~5, 7\\ 1 & 1 & 1 & 1 & 1 \\ \triangledown & & & & & Step~6\\ & 1 & 1 & 1 & 1 \\ \end{array}\]

(Formally Subtracting) Design an actual Turing machine that carries out the pseudocode above.
(Greg the Egg Returns) Design a Turing machine \(\mathcal T\) with a state \(x_{\mathtt{succ}}\) such that \[\mathcal T_{x_{\mathtt{succ}}}(\mathsf{bin}(n)) = \mathsf{bin}(n + 1)\] We will call this function \(\mathtt{succ}\) for successor.

Next, we are going to represent addition, by reducing it to successor and predecessor. Let \(\rho \colon \mathbb N \times \mathbb N \to \{0, 1, \#\}^*\) be the string representation \[ \rho(n, m) = \mathsf{bin}(n)~\#~\mathsf{bin}(m) \] We would like to find a Turing machine \(\mathcal T\) with a state \(x_+\) such that \[ \mathcal T_{x_+}(\rho(n,m)) = \mathsf{bin}(n + m) \] The pseudocode looks like this:

  1. If the string before the \(\#\) is just \(0\), erase \(\#\) and everything to the left of it.
  2. Subtract one from the string of \(0\)s and \(1\)s using the predecessor function, then add \(1\) to the string of \(0\)s and \(1\)s after the \(\#\). Return to Step 1.

(Unravelling Addition) Actually write out the full Turing machine that represents our procedure for computing addition. How many states does it have?

Arithmetic is nice, because everything somehow reduces to the successor function. Give it a try!

(They're multiplying!) Write out some pseudocode for a binary representation of multiplication by reducing it to predecessor and addition. Give an estimate of how many states are in the machine.
(One Further Step) Show that exponentiation, \(f(n,m) \colon \mathbb N \times \mathbb N \to \mathbb N\), is a computable function by reducing it to multiplication.

In general, reducing one problem to another can broadly be construed as stating that if P is solvable, then Q is solvable. Today, we saw that we could reduce the problem of multiplication to addition, which itself could be reduced to successor and predecessor.

← church turing thesis
Top