Nondeterminism

In the figure below, we show an ASCII map:

 
       ---- C3 --- dst --- C4 --- cliff
      /     |              |
     /      |              |
  src  >>-- C1 ----------- C2 --- cliff

Suppose a robot starts from position src, and would like to reach dst. On the map we have four crossroads denoted by Ci with i from 1 to 4.

Now, suppose the robot starts in the direction indicated by » but had a temporary sensor damage, and does not know if he missed the left turn. In fact, the robot has imperfect information regarding his current state: he might be at point C1 as well as at point C2 in the map.

To model imperfect information, we consider that the current position of the robot is {C1,C2}:

  • one could read this as the robot is in both C1 and C2 at the same time or,
  • as the robot cannot distinguish C1 from C2, thus he considers them equally likely

What happens after the robot takes the left-turn?

  • if the current position is C1, then the robot is now at C3
  • if the current position is C2, then the robot is now at C4

As before, after the left-turn, the robot cannot distinguish C3 from C4, thus his current position is {C3,C4}. We can represent the view which the robot has of the map after the sensor damage, as a finite-state machine:

Action\State q0 (initial state) C1 C2 C3 C4
straight C1, C2 C2 cliff - -
left - C3 C4 src dst
right - - - dst cliff

The matrix-like specification of the state-machine is very similar to that of the Turing Machine:

  • states correspond to positions
  • symbols correspond to actions which the robot can take
  • transitions correspond to robot movements
  • the tape contains a plan (e.g. straight,left,right) which may or may not end in a final state.
  • we may view cliff as a no-state (the robot falls from a cliff), and dst - as a final state.
  • there is no concept of writing on the tape, and the head always moves to the right.

Note however that, when the actions straight has been read (i.e. executed), the state-machine can nondeterministically move to both C1 and C2.

Formally, the transition function $ \delta$ can no longer be a function, as it requires assigning two different next-states when straight is read in state $ q_0$ .

Questions:

  • when the state-machine reaches a final-state, what does this say about the plan?

Remark (state-machines):

A state-machine, as informally described above is a non-deterministic automaton. These computing devices will be studied in more details in the Formal Languages and Automata Lecture.

In the previous section, we have informally introduced the concept of nondeterminism as imperfect-information, to make it more illustrative and easy-to-understand.

Next, we need to explore nondeterminism from a computational perspective, and to see how this concept is useful for classifying problems according to their hardness.

Boolean Satisfiability (SAT)

In this section, we introduce the Boolean Satisfiability Problem, and use it as a motivating example to drive our discussion.

$ SAT$ is the problem of determining if there exists an interpretation that satisfies a given Boolean formula.

$ SAT$ takes as input a boolean formula $ \psi$ in Conjunctive Normal Form (CNF):

$ \psi = C_1 \wedge C_2 \wedge \ldots \wedge C_n$

where, for each $ i:1 \leq i \leq n$ we have

$ C_i = L_{i1} \vee L_{i2} \vee \ldots \vee L_{im_i}$

and, for each $ j:1 \leq j \leq m_i$ we have

$ L_{ij} = x$ or $ L_{ij}=\neg x$

where $ x$ is a variable, and outputs $ 1$ iff there exists a interpretation $ I$ , such that under interpretation $ I$ the formula $ \psi$ is true.

An interpretation is a function that maps each variable(propositional symbol) to one of the truth values true and false.

SAT can be solved in exponential time

How can we solve SAT?

Given a formula $ \psi$ , we take the following steps:

  • 1. Compute the number of variables from $ \psi$ (henceforth referred to as $ n$ ) | Requires polynomial time
  • 2. We generate every interpretation for the variables in $ \psi$ | We have $ 2^n$ interpretations possible
  • 3. We check every interpretation against $ \psi$ . | Requires polynomial time $ O(n*k)$ , where $ k$ is the number of clauses in $ \psi$

Therefore $ SAT$ can be solved in exponential time, hence $ SAT \in EXPTIME$ . The major source of complexity consists in generating all possible interpretations on which a verification is subsequently done.

Let's assume that $ SAT$ would be solvable in polynomial time. Could we find problems (possibly related to $ SAT$ ) which are still solvable in exponential time under our assumption? The answer is yes: Let $ \gamma$ be the formula:

$ \gamma = \forall x_1 \forall x_2 \ldots \forall x_k \psi$

where $ \psi$ is a formula in CNF containing variables $ x_1,\ldots,x_k$ , and $ k \in \mathbb{N}$ is arbitrarly fixed. Checking if $ \gamma$ is satisfiable is the problem $ \forall SAT$ . An algorithm for $ \forall SAT$ must build all combinations of 0/1 values for each $ x_i$ with $ i:1 \leq i \leq k$ and for each one, must solve an instance of the $ SAT$ problem. In total, we have $ 2^k$ combinations, and since $ k$ is part of the input, the algorithm runs in exponential time, provided that we have an algorithm for $ SAT$ which runs in polynomial time.

Definition (Non-deterministic TM):

A non-deterministic Turing Machine ($ NTM$ short) is a tuple $ M=(K,F,\Sigma,\delta,s_0)$ over alphabet $ \Sigma$ with $ K$ , $ \Sigma$ and $ s_0$ defined as for (conventional) Turing Machines, $ F=\{s_{yes},s_{no}\}$ and $ \delta \subseteq K \times \Sigma \times K \times \Sigma \times \{L,H,R\}$ is a transition relation.

A $ NTM$ terminates iff it reaches a final state. A $ NTM$ $ M$ decides a function $ f:\mathbb{N} \rightarrow \{0,1\}$ iff

  • $ f(n^w)=0 \Longrightarrow M(w)$ reaches state $ s_{no}$ on all possible sequences of transitions and
  • $ f(n^w)=1 \Longrightarrow M(w)$ reaches state $ s_{yes}$ on at least one sequence of transitions.

We say the running time of a $ NTM$ $ M$ is $ T$ iff, for all $ w \in \Sigma$ :

  • the shortest successful sequence of transitions has at most $ T(\mid w\mid)$ steps - if it exists or,
  • the longest unsuccessful sequence of transitions has at most $ T(\mid w\mid)$ steps.

We start with a few technical observations. First note that the $ NTM$ is specifically tailored for decision problems. It has only two final states, which correspond to yes/no answers. Also, the machine does not produce an output, and the usage of the tape is merely for internal computations. In essence, these “design choices” for the $ NTM$ are purely for convenience, and alternatives are possible.

Whereas the conventional Turing Machine assigned, for each combination of state and symbol, a unique next-state, overriding symbol and head movement, a nondeterministic machine assigns a collection of such elements.

  • The current configuration of a conventional Turing Machine was characterized by the current contents of the tape, and by the head position.
  • A configuration of the nodeterministic machine corresponds to a set of conventional $ TM$ configurations.

The intuition is that the $ NTM$ can simultaneously process a set of conventional configurations, in one single step. While the execution of a Turing Machine can be represented as a sequence, that of the $ NTM$ can be represented as a tree. A path in the tree corresponds to one sequence of transions which the $ NTM$ performs.

Now, notice the conditions under which a $ NTM$ decides a function: if at least one sequence of transitions leads to $ s_{yes}$ , we can interpret the answer of the $ NTM$ as yes. Conversely, if all sequences of transitions lead to $ s_{no}$ , then the machine returns no.

Finally, when accounting for the running time of a $ NTM$ , we do not count all performed transitions (as it would seem reasonable), but only the length of the longest transition sequence performed by the machine. The intuition is that all members of the current configuration are processed in parallel, during a single step.

We build the $ NTM$ $ M_{SAT}$ which solves the $ SAT$ problem discussed previously. First, we assume the existence of $ M_{chk}(I,\psi)$ which takes an interpretation and a formula, both encoded as a unique string, and checks if $ I \models \psi$ . $ M_{chk}$ is a conventional $ TM$ , thus upon termination it leaves $ 0$ or $ 1$ on the tape.

  • Step 1: $ M_{SAT}$ computes the number of variables from $ \psi$ (henceforth referred to as $ n$ ), and pretends the encoding of $ \psi$ with the encoding of $ n$ in unary (as a sequence of $ 1$ 's). This step takes $ O(n)$ transitions.
  • Step 2: During the former step, $ M_{SAT}$ has created a context for generating interpretations. In this step, $ M_{SAT}$ goes over each cell from the encoding of $ n$ , and non-deterministically places $ 0$ or $ 1$ in that cell. Thus, after 1 such transition, there are 2 possible conventional configurations. In the first, bit $ 0$ is placed on the first cell of the encoding of $ n$ . In the second, bit $ 1$ is placed in the same position. After $ i$ transitions, we have $ 2^i$ possible configurations. At the end of this step, we have $ 2^n$ possible configurations, and in each one, we have a binary word of length $ n$ at the beginning of the tape, which corresponds to one possible interpretation. All sequences of transitions have the same length, thus, the execution of this part of $ M_{SAT}$ takes $ O(n)$ .
  • Step 3: At the end of each sequence illustrated above, we run $ M_{chk}(I,\psi)$ , where $ I$ and $ \psi$ are already conveniently on the tape. This step takes $ O(n*k)$ where $ k$ is the number of clauses in $ \psi$ .

If we add up all running times of the three steps, we obtain $ O(n*k)$ .

NTMs definitely seem faster thus better at solving problems than their conventional counterparts. However:

  • just like TMs, NTMs are formal models - this time for algorithms with embedded paralelism
  • NTMs cannot be implemented in practice (they can only be implemented if the branching of computations has an upper limit. Recall that, in SAT, each branching is done per variable, and the number of variables depends on the input.

However, are NTMs more expressive - e.g. able to solve problems which are not recursive? The following proposition answers this question:

Proposition:

Every function which is decidable by an $ NTM$ in polynomial running time, is also by a $ TM$ which runs in exponential time.

Can you think of a way to prove the proposition?

We have already seen:

  • the formal definition of NTMs (extensions of TMs where the transition function becomes a relation)
  • the intuition underlying them
  • the notion of acceptance and execution time of NTMs
  • the relation to TMs in terms of expressive power

However, the usefulness of NTMs may still be unclear. To convincingly motivate NTMs, let us recall the notion of acceptance of a Turing Machine:

  • although not a practical way of solving a problem - acceptance serves the purpose of describing (via the TM) a certain type of problem hardness, one in which the algorithm cannot do better than enumerate elements of an infinite set;
  • via the concept of acceptance, we are able to define a degree of hardness - the class RE.

The NTM serves exactly the same kind of purpose, regarding complexity:

  • problems which are solved by the NTM require:
    • iterating over an exponential number of elements (e.g. interpretations),
    • but each element can be built incrementally, in a tree-like fashion, just like SAT interpretations, in polynomial time. This is possible by exploiting the nondeterminism;
    • each element can be verified to be a yes/no answer in polynomial time

Thus, nondeterminism is used to identify a very specific pattern of complexity, just like acceptance is used to identify a specific pattern of undecidability.

It is important to note that:

  • not all problems which are (at best) exponentially solvable exhibit this pattern:
    • it is possible that the generation of all elements is not incremental (see the Towers of Hanoi problem) - hence exploring all elements is no longer nondeterministically polynomial;
    • that the verification of a candidate is not polynomial (see extensions of SAT - QSAT).

Convention for describing $ NTM$ in pseudocode

In the previous chapters, we often resorted to traditional pseudocode in order to describe algorithms - that is, Turing Machines. It is occasionaly useful to be able to do the same thing for $ NTM$ s. With this in mind, we introduce some notational conventions. The instruction:

$ v = choice(A)$

where $ v$ is a variable and $ A$ is a set of values, behaves as follows:

  • the current (non-deterministic) configuration of the $ NTM$ shall contain $ \mid A \mid$ conventional configuration.
  • each conventional configuration corresponds to a distinct value $ a \in A$ , and it should be interpreted that $ v=a$ , in that particular configuration.
  • the running time of the instruction is $ O(1)$ .

We also note that, it is not possible to achieve some form of “communication” between conventional configurations. Thus, it is intuitive to think that the processing (execution of a transition) of a conventional configuration is done independently of all other conventional configurations.

We add two aditional instructions: success and fail. They correspond to a transitions into states $ s_{yes}$ and $ s_{no}$ , respectively.

We illustrate $ NTM$ pseudocode, by re-writing the $ SAT$ algorithm described above. We adopt the same representational conventions from the first Chapter, and also re-use the procedure CHECK.

Example (Pseudocode):

$ SolveSAT(\phi)$

Let $ n$ be the number of variables in $ \varphi$ .

Let $ I$ be a vector with $ n$ components which are initialised with $ 0$ .

$ \mathbf{for} \mbox{ } i=\overline{0,n-1} \mbox{ :}$

$ \quad I \lbrack i \rbrack = choice(\{0,1\})$

$ \mathbf{if} \mbox{ } CHECK(\varphi,I)=0$

$ \quad fail$

$ \mathbf{else} \mbox{ } succes$