We introduced the PDA as a special case (albeit nondeterministic) of the URM, with a single number-type read/write variable—the stack variable. Actually, we viewed this variable as a string-type variable suppressing a detailed look into how a URM can effect string operations such as “pop” and “push”, until now. As in Section 2.11 , we can identify strings over a finite alphabet of m symbols with natural numbers—the latter written in notation base -( m + 1). The correct way to do this (cf. 2.11.0.32, III) is to fix an order of the alphabet and identify its members { a 1 , a 2 , . . . , a m } with the “digits” 1, 2, ... , m (i.e., a i with i ). Thus a non-empty string
is uniquely represented by (and represents ) the number
j r ( m + 1) r + j r −1 ( m + 1) r −1 + ... j 1 ( m + 1) + j 0
0 corresponds to the string ∊.
Assume now that the stack variable is x, and that its contents is the string γ, which, in detail, is the string in (1). Moreover, let us have the stack top located at the right end of γ rather than the left end.
Pause. Why is this not an about face of any significance vis à vis our earlier conventions?
Then we can do a pop—and assign the popped symbol in the variable z , if we wish—as follows
The stack (contents) change corresponds to the effect of
Both operations can be simulated by simpler URM operations (as the right hand sides are calls to primitive recursive functions).
To push the one-digit contents of a variable w into x one simply does
That is, a URM, despite being inherently a “number-processing” device (read: program), can perform all the string operations that are associated with stacks. Clearly, a URM can be written to handle several stack variables.
The converse is an important question: Is it possible to simulate any URM with one that only has stack variables and its primary instructions 138 are restricted to be “push” and “pop” (and checking for empty stack)? And if so, how many stacks are needed?
Suppose now that we add a second stack to a PDA. What more can such a turbo-charged PDA do with its two stacks?
Well, we will show that a URM with just two stacks—of string type—can simulate the operation of any number-processing URM! Here is how [cf. Minsky (1967) and Tourlakis (1984)]:
5.1.0.29 Example. To prepare for the justification of the above claim, let us see first that we can perform x ← a x in a URM, using just one extra variable y, where a > 0. The following fits the specification:
1 : y ← 0
2 : x ← x
1
3 : y ← y + a { NB. This is y ← y + 1, a times}
4 : if x = 0 goto 7 else goto 2
5 : y ← y
1
6 : x ← x + 1
7 : if y = 0 goto 8 else goto 5
8 : stop
5.1.0.30 Example. We next see how to do
x ← if rem (x, a ) = 0 then ⌊x/ a ⌋ else x
in a URM with just two variables, where a > 0. Below we present a pseudo URM program for the task. For the simulation of “goto L” see 2.1.1.8.
y ← 0
Loop : if x = 0 goto L 0 {case of rem = 0}
x ← x
1
if x = 0 goto L 1 {case of rem = 1}
⋮
x ← x
1
if x = 0 goto L a −1 {case of rem = a − 1}
x ← x
1
y ← y + 1
goto Loop
At this point
L 0 : x ← a y
goto L
Cases where rem ( x, a ) ≠ 0; we need to restore x .
L 1 : y ← a y
y ← y + 1
x ← y
goto L
⋮
L k : y ← a y
y ← y + k
x ← y
goto L
⋮
L a −1 : y ← a y
y ← y + a − 1
x ← y
L : stop
5.1.0.31 Example. We can now show how two number-type variables are sufficient to simulate the function of a URM M that contains more than two variables,
where m > 1. We build (in outline) a URM N that employs just two variables, x and y. The first stores the values of all the variables in (1) using a modified prime power coding,
where p 1 = 2, p 2 = 3, etc.
To simplify matters, assume that M has only z 0 as its input/output variable. The simulator N will have x as its only input variable , but it will “read” an input a encoded as the number 2 a —this means that the coding phase, going from a to 2 a is not part of the simulation. By our conventions on non-input variables, all of z 1 , . . . , z m are “implicitly” set to 0, that is why the correct initial value of x is indeed just 2 a . Furthermore, without loss of generality, we restrict M so that it has no instructions of the type w ← s .
Pause. Why “without loss of generality”?
Once (2) has been initialized, an instruction such as z i , ← z i , + 1 is simulated by N doing x ← p i x . On the other hand, z i ← z i
1 will require N do x ← if rem ( x , p i ) = 0 then ⌊x/ p i ⌋ else x. Finally, the instruction if z i = 0 goto L′ else goto L″ of M is simulated by N by, in a first approximation, the instruction if rem ( x , p i ) = 0 goto L′ else goto L″. This can be implemented by a modification of the URM in 5.1.0.30 , where the instructions under labels L 1 , . . . , L Pi transfer to L″ (rather than to the label of stop ), and the instructions under label L 0 transfer to L′ rather than to L .
5.1.0.32 Remark. We can easily do what the previous three examples did with two string-type stack variables—“two stacks” as we say. Let us call these variables L and R . They will be utilized as a simple counters . This means that the length of the stored string represents the number stored—no matter what the actual symbols in the stack may be.
Pause. Therefore a stack alphabet Γ of any one symbol, say, Γ = {#}, will work.
Thus, “L ↓ (push)” implements L ← L + 1 and “if L ≠ ∊ 139 then L ↑ (pop)” implements L ← L
1. We also note that in the simulation in Examples 5.1.0.29 , 5.1.0.30 , and 5.1.0.31 we employed the variables x and y in what can be termed push-pull 140 mode, that is, when one popped (“pulled”), the other pushed—since we paired instructions
with
We have abstracted in the above observation the detail that sometimes we had a “ + a” paired with a “
1”, e.g., simulation of x ← a x . This is legitimate since a “push” like “ + a” can be thought of as one push, rather than a consecutive pushes, if we allow groups of symbols to be pushed at once. In the context of this simulation this can be “hardwired” into the simulating program since there are only a finite number of different “a” : 2, 3, 5, ... , p m .
Thus two string-type stacks—even if they are restricted to not work independently but rather are constrained to work in push-pull mode—give the 2-stack PDA formalism at least as much power as that of the URM.
Conversely, and rather trivially, a URM can simulate any deterministic program written in this new formalism, since as we know (e.g., preamble of Section 5.1 ) the number-theoretic URM can pop, push, and check for empty stack (equal to 0, number-theoretically).
What about nondeterminism? Does it give more computing power to the 2-stack PDA formalism vs. that of the URM?
It turns out that it does not.
This can be seen in at least one straightforward way. On one hand, a nondeterministic URM—which we will not define formally—is one that allows choice for next instruction. By preceding remarks, such a URM subsumes the new formalism completely.
On the other hand, a nondeterministic URM can be simulated by a deterministic URM—by one of our standard URM, that is. Why? Because we can do this:
-
Recast Definition 2.3.0.5 for nondeterministic URM.
-
Define acceptance of an input
to be equivalent to input
leads to at least one terminating computation. -
Define that a relation R (
) is URM-acceptable iff, for some nondeterministic URM M , “ R (
)” is equivalent to “
is accepted by M ”. -
Do the arithmetization of the nondeterministic URM, by trivially modifying all the work that we did following 2.3.0.5 , which led to the normal form theorem.
-
Prove a new “Kleene Normal Form Theorem” for nondeterministic URM, namely:
For any nondeterministic URM M of code z, we have that M accepts input
iff (∃ y )
( z ,
, y )— where, for every n ,
is a primitive recursive “Kleene predicate” for nondeterministic URMs.
After all this work, which is tedious but easy, we have that the sets that are (nondeterministic) URM-acceptable are precisely the c.e. sets. Therefore, nondeterminism bought us nothing in terms of power in the URM formalism. 141 This is analogous with the situation of FA vs. NFA.
5.1.1 Turing Machines
Let us now carefully define the Turing machine —acronym TM —formalism of Turing (1936, 1937), since we want to prove a metatheorem about it. We will essentially identify the Turing machine with the 2-stack PDA but will offer some simplifications in the eventual definition—in particular, we will join the two stacks into a single variable of type “string”. Let us make a few additional observations before we embark on definitions.
First, we adhere to the traditional point of view according to which “automata”—whether these are FA, NFA, PDA, or the 2-stack PDA—are string-processing programs where concatenation rather than “+ 1” or “
1” are the primitive operations in the formalism. Each such automaton has an input alphabet Σ over which its string inputs are formed. For the 2-stack PDA, an instantaneous description of its computation is partly determined by the contents of the two stacks, L and R , by the current instruction number or state that the program is at, and by the symbol on top of the stack.
Pause. Which one of the two stacks?
Since the stacks operate in push-pull, we imagine the ID as the quadruple
where l and r are the contents of L and R, respectively, q is the current state, and a is the current symbol , which we arrange always to be the top symbol of R.
The top of L is its rightmost symbol, while the top of R is its leftmost symbol.
This ID ignores the input stream that is read via the input, read-only, variable of digit-type (single-symbol-type). The reason is that it turns out that the presence or absence of a read-only input variable, provably , does not add or subtract to the power of the model. Thus, without loss of generality we will henceforth assume that there is no input variable and that the input appears in the stack R initially .
We will not offer the proof that this simplification of the model indeed is “without loss of generality”. It is well known that the TM (the 2-stack PDA) is quite oblivious to large variations in its definition, including the one we mentioned. Several startlingly different but equipotent variants of the TM are presented in, for example, Hoperoft et al. (2007). In particular, the reader can find in Tourlakis (1984) a full account of how the TM that we outlined earlier—that is, the PDA with two stacks that are implemented as counters—can be modified, still within the TM model as it is defined in 5.1.1.1 below, to simulate a URM, including the part of transforming the input from a to 2 a (the “input format” 2 a was used in 5.1.0.31 ), this being done explicitly this time as part of the computation.
At long last, we collect what we have said so far in this chapter, and define the TM by actually “gluing” together the two stacks, top to top , an operation that makes sense due to their push-pull operation: Thus we have just one read-write string variable in a TM, to which the literature most often refers as the “ tape ” [a notable exception is Papadimitriou (1994)].
5.1.1.1 Definition. (The Turing Machine) A Turing machine (abbreviation TM ) is a collection of tools, M =
Q, T , Σ, Γ, q 0 , F ,
, as follows: Q is a finite set of states, that is, instruction labels. T is the only variable, a string-type variable with special access mode (cf. 5.1.1.2 below). Most of the literature refers to is as “the tape ” of the TM.
Γ = { B ,...} is a finite alphabet over which the contents of the tape are formed. The symbol B occurs in all TM alphabets, is called the blank symbol , and is special. More on it later ( 5.1.1.2 ).
Σ is the input alphabet; it satisfies Σ ⊆ Γ − { B }. q 0 is the label of the instruction that must be executed first—the start state. F is a possibly empty, finite set of accepting states.
Finally,
is a finite set of instructions of the forms (1)–(3) below, where our notation adheres to the rules that a , b , c , possibly with primes or subscripts, denote generically members of Γ; p , q , r , possibly with primes or subscripts, denote members of Q. The TM can access at any one step of the computation (“computation” to be defined in 5.1.1.2 ) one symbol of the string stored in T — any one symbol—which is referred to as the “current” symbol.
(1) “ qabq ′ →”; this instruction is applicable only if the current instruction is (labeled) q and the current symbol is a. The execution of the instruction causes the symbol a to change to b . Note that a and b may denote the same symbol!
It also causes q′ to be the next instruction. Note that q and q′ may denote the same state! The new scanned symbol will be the one immediately to the right of a (which has changed to b ).
(2) “ qabq ′ ←”; this instruction is applicable only if the current instruction is q and the current symbol is a . The execution of the instruction causes the symbol a to change to b. It also causes q′ to be the next instruction. The new scanned symbol will be the one immediately to the left of a (which has changed to b ).
(3) “ qabq ′”; this instruction is applicable only if the current instruction is q and the current symbol is a . The execution of the instruction causes the symbol a to change to b . It also causes q′ to be the next instruction. The new scanned symbol will be the b , which is in the place of the original a .
If there are no two distinct instructions in
that start with the same state and symbol pair, “ qa” , then the TM is deterministic; otherwise, it is nondeterministic.
It is immediate that every deterministic TM is also nondeterministic, but not vice versa. (This does not mean that we cannot simulate any nondeterministic TM by a deterministic TM. This is only a comment about the structure of Turing machines.)
5.1.1.2 Definition. (IDs and Computations) Given a TM M as in 5.1.1.1 . An instantaneous description or ID of a computation of M 142 is a string
tqau
where a is the scanned symbol, q is the current instruction label (state) and tau is the string stored in the variable T —the total “tape contents”.
Connecting with the discussion that led us here, t is the content of the stack variable L (top at the right end of t ) and au is the content of the stack variable R (top at the left end of au ).
Two IDs, tqau and t′ q′ a′ u′ are related via the relation ⊢,
tqau ⊢ M t′ q′ a′ u′ , where M is omitted if it is understood from the context (1)
in words, tqau yields t′ q′ a′ u′ , iff one of (i)–(iii) holds:
(i) t = t′, u = u′, a′ = b and qabq′ is an instruction
(ii) This is “push in L , pull (pop) from R ”
- t′ = tb, u = a ′ u′ , with a′ ∈ Γ, and qabq′ → is an instruction
- t′ = tb, u = ∊, u′ = ∊, a′ = B , and qabq′ → is an instruction
(iii) This is “push in R, pull from L”
- t = t′ a′, u′ = bu , with a′ ∈ Γ, and qabq′ ← is an instruction
- t′ = B , t = ∊, a′ = B , u′ = bu , and qabq′ ← is an instruction
The second bullet in each of (ii) and (iii) shows the special nature of the blank symbol B. Intuitively each bullet formalizes how each half of the “tape”—that was obtained by joining two stacks, top to top, as you recall—can be extended when the computation reaches either of the two extremes and “wants” to go further. In stack terms, the two stacks never “ underflow ”. 143
An ID of the form q 0 x , where x ∈ Σ + is the input string, is called initial. An ID tqau that has no next IDs , that is, ¬(∃ J )( tqau ⊢ M J ), is called terminal or final. An ID tqau is called accepting if it is terminal and q ∈ F.
A computation of M —an M -computation—is a finite sequence of IDs J i , for i = 0, . . . , m , such that
(1) J 0 is initial
(2) J m , is terminal
(3) J i ⊢ M J i + 1 , for i = 0, . . . , m − 1
A subsequence
is a subcomputation iff it satisfies (3) for all pairs of consecutive terms.
A computation accepts the input x iff its initial ID is q 0 x and its terminal ID is accepting. The symbol L ( M ), where M is a TM, denotes the language accepted by M , that is, { x ∈ Σ + : x is accepted by M }.
The complexity or run time of a computation J 0 , . . . , J m is the number m —which equals the number of “steps”, ⊢ M , applied in (3) above.
Since TMs can write on their tape (string variable) they do not need accepting states to indicate acceptance of a string—for example, just prior to halting, they may erase the contents of the variable, and replace them with the word “accept”, or the word “true”, or the number 1, to indicate that the input was accepted. Nevertheless, the presence of accepting states makes arguments about the behavior of TMs—such as the proof of Cook’s theorem in this section—easier.
Turing machines can do more than produce yes/no output. They can compute functions just like the URM does. Indeed, the two formalisms have the same computing power ( Examples 5.1.0.31 and 5.1.0.32 ).
However, we will not explore the Turing machine in its function-computer role. All our Turing machines will be acceptors.
The reader who wants to see how computability can be founded on the TM formalism may consult Davis (1958) and Tourlakis (1984).
5.1.1.3 Definition. (The Classes
and
) Given a function ⋋ n . T ( n ). We say that the language L has deterministic T ( n )- time complexity iff there is a deterministic TM M such that L = L ( M ) and the run time of every computation of M is bounded by T (| x |), where | x | is the length of the input x .
We say that the language L′ has nondeterministic T ( n )- time complexity iff there is a nondeterministic TM N such that L′ = L ( N ) and every acceptable input x of N has at least one computation of run time ≤ T (| x |).
We often use the terminology “ M (respectively, N ) accepts x within time T | x |)”. We say that L has deterministic polynomial-time (or poly-time) complexity iff it has deterministic T ( n )-time complexity for some polynomial T ( n ). We say that L′ has nondeterministic poly-time complexity iff it has nondeterministic T ( n )-time complexity for some polynomial T ( n ).
The class of all languages that have deterministic poly-time complexity is denoted by
. The class of all languages that have nondeterministic poly-time complexity is denoted by
.
What the nondeterministic machine does when it does not accept x —it might even compute forever for some rejected x —has no bearing on the complexity of L′ .
In essence, a nondeterministic machine recognizes just the positive instances of a relation of the form
by accepting all x that make (1) true—but no other inputs. We may imagine that this is done as follows:
- It first nondeterministically “writes down” (“guesses”) a value of y that works for the given x
- It then deterministically verifies the truth of R ( x, y ).
In other words, the machine works precisely as a mathematician does, when the latter approaches the task of proving (1) for a given y .
The run time of the task described by the two bullets equals the time it takes to write down y , plus the time it takes for the verification.
Pause. But surely deterministic and nondeterministic steps in a computation are in general intertwined? How can (1) be the “general” case?
It is. Every set S ∈
that is acceptable by a nondeterministic URM (or TM) is c.e.
Cf. the discussion in the
-passage on p. 329 . Thus the relation x ∈ S is equivalent to (∃ y ) Q ( x, y ) for some primitive recursive Q , by the projection theorem. Thus, χ Q can be computed by a a loop program.
Consider two examples:
Suppose first that we want to (nondeterministical1y 144 ) prove that some given x is a composite number.
If such a claim about x is true, then we would probably want to guess a factor y and then verify that it works, by computing rem ( x, y ) and making sure that its value is 0.
The next example addresses the question of how the “problem-template” (1) can represent a problem where multiple “guessed values” are needed: Suppose that we want to prove that a given Boolean formula
—whose Boolean variables are (in metanotation) υ 1 , . . . , υ n —is satisfiable. We can use as a single guessed value y an appropriate coding of n appropriate truth values, which—when assigned into the υ i —will make
true. Of course, if we hope to “solves” the problem in poly-time with respect to the input size, |
|, we will need to use a coding/decoding scheme that can pack/unpack the truth-values into/from a single y , and do so within time that is a polynomial function of |
|—the length of the formula. One such fast coding/decoding scheme is to form a string formed by concatenating all the guessed truth-values together. See also 5.1.2.13 below.
5.1.1.4 Remark. In 5.1.1.3 we have quoted run time as a function of input length. This is a natural choice in complexity theory that deals with a large variety of problems that involve non-numerical inputs. For example, problems about graphs —such as the clique problem: “given a graph G and a number k ; does G have a clique of size k ?”—and problems about formulae—such as the SAT problem: “given a Boolean formula
; is it satisfiable?”
Of course, every set of strings over an alphabet Σ of k elements can be viewed as a set of numbers, written base- k , as we already have remarked (e.g., Section 2.11 ). However, quoting run time in terms of input value is not , in general, the same as quoting time in terms of input length, unless k = 1. Here is why:
Each language L discussed in this and the next subsection is assumed to be over some alphabet Σ L of k ≥ 2 elements. The length of a string x over Σ L —viewed as a number base- k —essentially equals the logarithm base- k of x . Indeed, if
x = a n k n + a n − 1 k n − 1 + ... + a 0
then
k n ≤ x ≤ ( k − 1) k n + ( k − 1) k n − 1 + ... + ( k − 1)
therefore,
Now, n + 1 = | x | and, by (1), | x | − 1 ≤ log k x < | x |. That is, | x | =
log k x
.
Often we take our time bound functions T ( n ) from some class of functions,
, e.g., the class of polynomials, or the class
. Obviously, if a TM runs within time n c for some constant c (a polynomial run time) it makes a world of difference if we are quoting run time as a function of the input value or of the input size, when k ≥ 2: because x (the input value) is equal to about k | x | and thus a TM that runs within time x c —a polynomial bound with respect to input value —runs within time ( k | x | ) c , which is an exponential bound with respect to input size ( length ).
Therefore, for time bounds from the class of polynomials we must be clear how we quote run time! In this case we invariably do so with respect to input length .
On the other hand, if T ( n ) comes from a class that contains exponentials, e.g., T is in
or in the class
of Section 5.2 , then it is irrelevant how we quote run time, whether with respect to input value or input size, since ⋋ n . k T ( n ) ∈
as well.
5.1.1.5 Remark. Since every deterministic TM is also a nondeterministic TM, Definition 5.1.1.3 yields at once
⊇
The converse inclusion, and therefore the question “
=
?” of Cook (1971) is a major open problem of complexity theory. In words, it asks: can we eliminate guessing from a program that accepts in polynomial time to obtain a new, equivalent, program that also runs in polynomial time? We turn now to concepts on which this question hinges.
5.1.1.6 Definition. (Feasible Computations) That the computations of a TM are feasible means that they are poly-time bounded, the bound being quoted with respect to input length.
5.1.1.7 Remark. (I) Thus, unfeasible or intractable —these are technical terms!—computations are those that require exponential run time or more. The distinction is fairly natural, but not totally. It leads to a nice theory, however. From a practical standpoint, a TM that runs within time n 350000 has no computations that are any more “feasible” than one that runs within time 2 n . The former is as bad with an input of length 2 as the latter is with an input of length 350000.
Cobham (1964) has given a machine-independent characterization of the class of feasibly computable functions.
(II) Machine-independent? How can this be possible? Are all machines as “fast” (or as “slow”)? Do the URM and the TM, for example, spend the same amount of time for every problem that one throws at them and for every input thereof?
Well, not the same , and “all machines” is a rather loose concept. However, it is a known fact that if we equip the URM with the proper set of primitive instructions and choose the concept of “step” carefully, so that it is mindful of the length of the number stored in a variable x , then any URM that has computations running within time t ( n ) ( n being the length of input) can be simulated by some TM within time p ( t ( n )), for some polynomial p of very small degree. That the converse simulation, TM by URM, also entails negligible run time loss—a multiplicative constant overall, in fact—is rather immediate, once one notes that the TM is essentially a a 2-variable URM ( Subsection 5.1.1 ) with the instructions x ← m × x and x ←
x/ m
built in as primitives, and executable in one step each. 145 Thus, for polynomial time bounds it does not matter if we compute with URMs or with TMs
as long as the URM programming language that is called upon to compute functions f : Σ * → Σ * , for some fixed Σ of m > 1 elements, is properly equipped—in the interest of efficiency of computations—as follows: We add to the basic model of 2.1.1, the instructions x ← x * d, 146 where d ∈ Σ, and x ←
x / m
as primitives (cf. also the preamble of Section 5.1 ). Failing to do so would result in “charging” an inordinate amount of steps to just add or delete a single digit at the right end of the number (string!) stored in a variable (least significant location) despite the obvious fact that such a string operation ought not to depend on the size of the stored number.
Thus, for a string-processing URM one will charge |x| steps for each of
x ← x + 1
x ← x
1
x ← a
and will charge one step for each of
if x = 0 goto M else goto R
x ← x * d , where d ∈ Σ
x ←
x / m
The wisdom for the assigned charge, for example, to the first instruction above stems from the fact that to add 1 to 2 n – 1 will necessitate to flip n binary digits, from 1 to 0.
(III) Cobham’s main theorem is that the class of functions,
Σ , that can be computed feasibly is the closure of the set below,
under substitutions (2.1.2.6)— including the case of substituting any constant into a variable—and bounded (right) recursion on m -adic notation , the latter meaning the schema
where the functions h , ( gd ) d ∈Σ, and B are given. Cf. 1.7.0.30.
Cobham prefers m-adic (Exercise 1.8.47) [over the more common ( m + 1)- ary] notation for integers n > 0, which—unlike the latter that allows digits 0, . . . , m — only allows the digits 1, . . . , m. Wherever concatenation is used in his paper, it is concatenation of m-adic notations of numbers.
The notation in (1) and in the bounded recursion schema above should be read number-theoretically! Thus, x | y | in (1) is ordinary (number-theoretic) exponentiation but the exponent is the m -adic length of the y -argument, while x * d —a right successor of x —has value the number m × x + d and length | x | + 1. The base m of the m -adic notation is the number of elements in Σ. Note that we identify ∊ with 0, as m -adic notation does not apply to 0.
Cobham’s theorem is independent of the choice of alphabet Σ as long as the latter has at least two elements—thus his class can be unambiguously named
.
As an example, notice the simple recursion on notation that defines | x |:
Pause. “Simple”, yes; but only if we know that ⋋ x.x and ⋋ x.x + 1 are in
!
Well, here is how to obtain ⋋ x.x + 1 by bounded recursion in terms of functions known to be in
:
0 + 1 = 1
x * d + 1 = x * ( d + 1), for d = 1, 2, ... , m − 1
x * m + 1= ( x + 1) * 1
| x + 1| ≤ | x * 1|
For more on Cobham’s feasibly computable functions (and relations) see Exercises 5.3.1 – 5.3.11 , where you are asked to verify the membership in
of ⋋ x .1, ⋋ x .0, and ⋋ x.x as well as that of many other more complex functions.
Cobham’s result is retold (and proved 147 ) in full detail in Tourlakis (1984).
5.1.2
-Completeness
There are some languages (sets) 148 in
that have maximal complexity, just as there are maximally complex c.e. sets, such as K .
5.1.2.1 Definition. (
- Hard and
- Complete Sets ) A set L is
- hard iff for every L′ ∈
we have L′ ≤ m L , where the reduction is effected by a function that is computable by some URM in a number of steps that is a polynomial function of input length.
We say that we have a polynomial-time or poly-time reduction and write L′ ≤ p _L (p for polynomial)._
A language L is called
- complete iff it is
-hard and , moreover, is a member of
.
5.1.2.2 Remark. The Turing formalism, as we have already noted, is well positioned to be used in the proof of Cook’s theorem. Thus we have introduced it here as an acceptor device.
On the other hand, we have not developed the very primitive Turing machine formalism as a basis of computability. Thus our reduction functions are computed by URMs.
Another way to state this, in a machine-independent manner, is that these poly-time reductions are effected using feasibly computable functions from Cobham’s class
(cf. discussion in 5.1.1.7 ).
5.1.2.3 Definition. (Big-O Notation) Given g :
→
. O ( g ( n )) is the set of all f :
→
such that, for some constant C , we have f ( n ) ≤ Cg ( n ) a.e. (cf. 2.4.2.8). The notation f ( n ) = O ( g ( n )), introduced by the number-theorist E. Landau, means f ( n ) ∈ O ( g ( n )) and is called big-O notation.
Expressions in big-O notation are read from left to right. In particular, O ( h ( n )) = O ( g ( n )) is abuse of notation for O ( h ( n )) ⊆ O ( g ( n )). Thus, it means that “for every f , if f ( n ) = O ( h ( n )), then it is also the case that f ( n ) = O ( g ( n ))”.
Some operations defined : f ( n ) ∈ O ( h ( n )) + O ( g ( n )) iff f ( n ) ≤ f′ ( n ) + f″ ( n ) a.e., with f′ ( n ) ∈ O ( h ( n )) and f″ ( n ) ∈ O ( g ( n )).
f ( n ) ∈ O ( h ( n )) × O ( g ( n )) iff f ( n ) ≤ f′ ( n ) × f″ ( n ) a.e., with f′ ( n ) ∈ O ( h ( n )) and f″ ( n ) ∈ O ( g ( n )).
f ( n ) ∈ O ( h ( n )) O ( g ( n )) iff f ( n ) ≤ f′ ( n ) f″ ( n ) a.e., with f′ ( n ) ∈ O ( h ( n )) and f″ ( n ) ∈ O ( g ( n )).
5.1.2.4 Example. It is readily verifiable that O ( n ) = O ( n 2 ). But it is not true that O ( n 2 ) = O ( n ). Recall, “ Expressions in big-O notation are read from left to right”. Also, O ( n ) + O ( n 2 ) = O ( n 2 ) and O ( n ) O ( n 2 ) = O ( n 3 ). Incidentally, writing f ( n ) = O (1) means that f ( n ) is bounded a.e. by a constant.
5.1.2.5 Exercise. It is immediate that
. Is it also
?
5.1.2.6 Example. If p ( n ) is a polynomial of degree k , then p ( n ) = O ( n k ). The reader will recall that the degree of a polynomial in the variable n is the highest exponent of n that occurs in the polynomial. Indeed, let
p ( n ) = a k n k + a k − 1 n k − 1 + . . . + a 0 ,, where a k > 0
Without loss of generality, all the integer coefficients a i are natural numbers; if not, we replace them all by their absolute values and work instead with the so obtained p′ ( n ) that obviously satisfies p ( n ) ≤ p′ ( n ) for all n . We next note that
Taking n > max{ a i : i = 0, . . . , k − 1} we get a i / n k − i < 1, for i = 0, . . . , k − 1. Thus, if we set C = a k + k we have p ( n ) ≤ Cn k , a.e.
5.1.2.7 Remark. In view of 5.1.2.6 , we replace every statement of the form “ . . . within poly-time T ( n ) . . .” by “ . . . within time O ( n k ), for some k . . . ”, where “within time O ( n k )” means “within time f ( n ) in O ( n k )”.
5.1.2.8 Remark. We note here that if ⋋ x.f ( x ) is computable by a URM—as this was modified in 5.1.1.7 —within time t (| x |), then | f ( x )| ≤ t (| x |) + | x |. For in the worst case, all instructions (besides stop ) are x ← x * d. In one step we have the length of x increase by 1 in such an instruction. Thus, in t (| x |) steps the length of any variable increases by t (| x |), at most.
The following is fundamental but easy. It is the counterpart of Proposition 2.7.2.3 .
5.1.2.9 Proposition. If L′ ≤ p L and L ∈
, then also L′ ∈
.
Proof. Let x ∈ L′ iff f ( x ) ∈ L , where f is polynomial-time computable—say, within time O ( n m ), for some m —where n = | x |. By assumption on L, z ∈ L is verified or rejected by a deterministic TM within O ( n k ) steps, for some k , where n = | z |.
The polynomial-time algorithm for the verification or rejection of the claim x ∈ L′ then is:
(1) we compute f ( x ). As this runs within time O ( n m ), we have that
| f ( x )| = O ( n m ), where n = | x | (*)
cf. 5.1.2.8 and note that n + O ( n m ) = O ( n m );
(2) we run the algorithm for “ z ∈ L ”, using z = f ( x ). This will conclude the verification/rejection of x ∈ L′ within time
The proof outline above should suffice. The suppressed (tedious) details include “reprogramming” the computation of f in the TM “language”, and then composing (combining) this TM with the one that deterministically solves “ z ∈ L? ”
5.1.2.10 Corollary.
=
iff
contains some
- complete language L .
Proof We will see soon that
-complete languages exist.
The only if is trivial, since every
-complete language is in
. The if part is just as trivial: If L ∈
is
-complete, then consider an arbitrary L′ ∈
. By definition, L′ ≤ p L. Thus, by 5.1.2.9 , L′ ∈
, proving
⊆
.
The following is the counterpart of 2.10.0.12.
5.1.2.11 Proposition. A set L in
is
- complete iff S ≤ p L, where S is known to be
- complete.
Proof. For the if let B be in
. Then B ≤ p S; say, via f ( x ) that runs within time O ( n k ) ( n = | x |) on some URM M. Let also g effect S ≤ p L within time O ( n r ) (computed by some URM N ). Thus,
x ∈ B iff f ( x ) ∈ S iff g ( f ( x )) ∈ L
Note that g ( f ( x )) is computed by the concatenation of M and N (in that order) within time O ( n k ) + O (| f ( x )| r ). By 5.1.2.8 , | f ( x )| = O ( n k ). Thus the concatenation of M and N runs within time O ( n k ) + O (| f ( x )| r ) = O ( n kr ).
The only if is immediate since L is
-complete and S is in
.
At the beginning of Section 3.4 we (re)defined—via BNF—the set of Boolean formulae over the variables-set
p , p′ , p″ , p‴ , . . .
employing only two connectives, ¬ and ∨. Their semantics was given in Definition 1.1.1.26 —a point where we circumvented an explicit definition of Boolean formulae, and defined instead the concept of tautology directly, for any mathematical formula. For the record,
5.1.2.12 Definition. (Satisfiable Boolean Formulae; SAT ) A Boolean formula,
, as defined in Section 3.4 , is satisfiable iff there is at least one truth assignment to its variables that renders
true ( t ; cf. 1.1.1.14).
is a tautology iff every truth assignment to its variables renders it true.
We denote by SAT the set of all Boolean formulae—as defined in Section 3.4 —that are satisfiable. We denote by T AUT the set of all Boolean formulae that are tautologies.
5.1.2.13 Proposition. SAT ∈
P .
Proof [Outline; cf. the discussion surrounding (1) on p. 334 .] A nondeterministic TM that will accept precisely all the x ∈ S AT will operate as follows:
(1) It will “guess” and write down a string y (over { t , f }) of truth assignments to the variables
p ( n 1 ) , p ( n 2 ) , . . . , p ( n r ) 149
of x —these truth assignments are guessed so that they will work! As we have no more variables than | x |, writing down y is doable within O (| x |) steps.
(2) Deterministically , the TM will verify that the “guess” indeed works by evaluating x for said truth assignment. It is easy to see that this verification is doable in O ( n c ) steps, for a very small c ( n = | x |). The timing of the overall computation, (1) plus (2), is thus O ( n c ).
The reader will recall—from first year programming courses, for example—the nomenclature infix notation meaning that non-atomic formulae are written as (¬
) or (
∨
). An important alternative notation is postfix notation , also named reverse Polish notation. An easy way to define it is to do so recursively:
Let us denote the postfix notation of a formula
by post (
). Then, for atomic formulae
(these are the Boolean variables!), post (
) is just
. On the other hand,
post
(¬
)
is post (
)¬
and
post
(
∨
)
is post (
) post (
) ∨
For example, post ( p‴ ) is p‴ ; post (((¬ p‴ ) ∨ p )) is p‴ ¬ p ∨.
Postfix notation neither utilizes (nor needs) brackets.
Another folklore item from a first year programming course is how to program algorithms, one designed to convert an infix formula to its postfix equivalent, the other to evaluate a postfix expression, given a set of values for all its variables. Both of these algorithms, which we will not describe here, use a stack and, in a URM-like language (like Pascal, Algol, C, etc.) they will run in O ( n ) steps each, where n is the length of the given infix input. A TM then can do almost as well, that is, finish the task within time O ( n c ) for a very small (integer) c > 0 (cf. 5.1.1.7 ).
5.1.3 Cook’s Theorem
Cook’s theorem [cf. Cook (1971)] is that S AT is
-complete. He proved this by simulating nondeterministic poly-time bounded accepting TM computations by Boolean formulae, which were satisfiable iff the TM accepted its input. Before we embark on details, we willssume some restrictions— without loss of generality , to be sure!—for our TM model.
Restriction 1. The nondeterministic TMs of this subsection have a “ 1-way infinite tape ”, which is folkloric jargon for: “ the TM will never extend its string variable contents to the left by adding a B symbol ”—that is, the second bullet of (iii) in 5.1.1.2 will never apply. This can be accommodated simply by modifying the TM, if necessary, so that if it need to so add, it will rather first shift the contents of its string variable to the right, and add a B as a leftmost symbol. This is legitimate and only “adds” a polynomial number of steps, by Cobham’s theorem and the fact that ⋋ x.B * x is in Cobham’s class
Γ (cf. 5.3.1 )—Γ being the TMs total tape alphabet.
Restriction 2. Once the TM reaches the unique accepting state, q f , the TM computation continues forever without changing the ID! This is entirely analogous with the behavior of URM computations once the stop instruction has been reached.
Both the uniqueness and the trivial continuation of the computation upon acceptance can be easily incorporated in a given TM. For example, starting with an accepting state q f that has no moves, we modify the TM by adding the moves q f aaq f , for all a ∈ Γ.
5.1.3.1 Theorem. (Cook’s Theorem; Cook (1971)) SAT is
- complete.
Proof So, let L ∈
, accepted by a nondeterministic TM, M , which is restricted as above. The TM is accepting within time p ( n ), where p is a polynomial and n is the length of input w . Our task is to construct the function f that effects the reduction
L ≤ p S AT
Thus, f ( w ) must be a formula in SAT iff w is acceptable. We must make sure that f ( w ) is constructed in O ( n r ) time, for some r —which will result in | f ( w )| = O ( n r ).
Let M =
Q , T , Σ, Γ q 0 , F ,
, where Q = { q 0 , q 1 , . . . , q f }, Γ = { a 1 , a 2 , . . . , a m } with F = { q f } and B = a 1 . We proceed as follows:
(1) Consider the (accepting) computation
I 0 ⊢ I 0 ⊢ I 1 ⊢ ... ⊢ I l (1)
where l ≤ p ( n ), n = | w |, I 0 = q 0 w and I l contains q f .
By the second restriction adopted for our TMs, we may assume l = p ( n ).
(2) In p ( n ) steps, and starting the computation with the ID q 0 w , no ID—of the form tqau (cf. 5.1.1.2)—can be longer than p ( n ) + 1. Thus, we will let all IDs, I j , have the same length, equal to p ( n ) + 1, since we can pad them with B -symbols as needed. This allows us to utilize an ID-template , that is, an array of p ( n ) + 1 locations —0, 1, . . . , p ( n )—and also several Boolean variables, one for each location , that will “say” something characteristic about these locations for every point in “time” as the latter is measured by i .
(3) We will construct, for each ID I i , a Boolean formula
i that will be satisfiable iff I i has the correct structure as the i -th ID.
The formula
i “knows” that it refers to time step i by virtue of the fact that all its Boolean variables have i as their first subscript—see below. This subscript denotes “time” as it is measured along the computation (1).
(4) We define several mnemonic names that will be the Boolean variables of f ( w ):
(a)
—for j = 1, . . . , m and 0 ≤ i , s ≤ p ( n )—is a variable that is true (it is assigned t) if the s -th location of I i holds a j .
We have m ( p ( n ) 2 ) = O ( p ( n ) 2 ) S -variables.
(b)
—for j = 0, . . . , f , 0 ≤ i ≤ p ( n ) and 0 ≤ s ≤ p ( n ) −1—is a variable that is true (it is assigned t ) iff the s -th location of I i holds q j .
Note that a state cannot be in the last location ( p ( n )) since the ID must have the form tqau , with a ∈ Γ. We have ( f + 1) p ( n )( p ( n ) + 1) = O ( p ( n ) 2 ) Q -variables.
Thus,
i that says “ I i has the correct form at time i, namely, tqau ” is the formula that “says”, specifically:
(i) The ID-template has no empty locations.
(ii) Only one location, s , contains a state q j —i.e.,
is t —all other locations, t , containing some a k from Γ—i.e.,
is t .
(iii) No location holds more than one Q -symbol or one Γ-symbol.
(iv) The p ( n )-th location contains a Γ-symbol.
Thus, the abbreviation
i stands for the following Boolean formula that we divide into four parts that implement (i)–(iv), respectively.
Below we are using the notation
and
Note the brackets! We will also use more complicated ranges, such as
an expression that expands into an ∨-chain of formulae
, for all j ∈ T and all i such that s ≤ i ≤ t. The order of participating formulae in ∨- and ∧-chains is, of course, immaterial. For exposition purposes, we use
∧
as an abbreviation for ¬(¬
∨ ¬
).
this is (i):
this is (ii):
this is (iii):
this is (iv):
We next define subformulae
i of f ( w ). For each i , satisfiability of
i will be tantamount to I i ⊢ I i +1 . Thus,
i stands for the formula
In the above
says that for all k and t , the two symbols in location t before and after the move are the same (≡ is “Boolean equality”). Of course,
≡
is short for (¬
∨
) ∧ (¬
∨
).
Putting all this together, f ( w ) is the formula below, where w = a i 1 a i 2 ... a i n .
The structure of f ( w ) is straightforward and thus the formula f ( w ) can be constructed (“written down”) in time that is a polynomial function of its length. Note that p ( n ) itself is an important parameter of the formula structure, as it determines the range of certain subscripts and the ID-template length. By 5.1.2.6 , p ( n ) is in O ( n a ), where a is its degree. Thus, we can assume without loss of generality that p ( n ) is Cn a + C ′, for appropriate constants C and C ′.
In the most unsophisticated manner Cn a + C ′ can be computed by a − 1 multiplications each operating with operands of length O (log n ). 152 This requires a total time of O ((log n ) 2 ) = O ( n ) steps, using the standard “school method”, digit by digit, multiplication algorithm. On the other hand, n = | w | can be obtained from w in polynomial time with respect to | w |, for example, due to the fact that λ w .| w |
( 5.1.1.7 ).
Next, by inspection, the length of f ( w ) is estimated as follows:
(a) A subformula
i has length O ( p ( n ) 2 )—due to case (ii)
(b) A subformula
i has length O ( p ( n ) 2 )
(c) Thus | f ( w )| = O ( p ( n ) 3 )
The above estimate is based on a simplifying first-order approximation that all the Boolean variables
and
each have length equal to one. If the super/subscripts are displayed in base-2 notation, then each variable needs space O (log 2 ( p ( n ))) = O (log 2 n ) = O ( n ) to be written down. 153 Thus | f ( w )| = O ( np ( n ) 3 ) = O ( p ( n ) 4 ). It flows directly from the construction of f ( w ) that w
L iff f ( w )
SAT .
5.1.3.2 Example. ( CSAT ) In preparation for identifying our next
-complete problem we review the concept of conjunctive normal form ( CNF ). A formula is in conjunctive normal form iff it has the form below.
, where each
is a Boolean variable p ( n ) or a negation thereof
We call each conjunct
a clause of the CNF. We call each
a literal.
It is easy to see that for every Boolean formula
there is another one,
, that is in CNF and they are either both in SAT or neither is. We outline how to construct
given
.
This can be seen by induction on the number of occurrences of ∨ and ∧ connectives in the formula. We assume that Boolean formulae are defined as at the onset of Section 3.4 , but this time we will allow all three of ¬, ∨, and ∧ as primitives.
Prior to the induction, we preprocess
by “pushing” all negations as close to variables as possible. We then replace any maximal odd-length string of ¬ symbols by a single one; we eliminate any maximal even-length string of ¬ symbols. This is achieved by repeated use of the two de Morgan laws ( 1.1.1.18 ) and of the well-known provable identity ¬¬
≡
. Once this is done, in every subformula of the (fully parenthesized) form (¬
),
is a variable.
For the basis, if
is a literal, then it is already in CNF.
For the induction step, let first
be
∧
. The I.H. yields that
and
have associated CNF formulae
′ and
′ as above. A CNF associated with
then is
′ ∧
′: If
is satisfiable, then so are
and
and hence
′ and
′ by the I.H. The same is true of
′ ∧
′. The converse is as easy.
The other induction step deals with the case where
is
∨
. Again, by the I.H. we have associated CNF formulae
′ and
′. Let us invoke Exercise 1.8.2:
The special case where
and
are literals is of import for our I.S. Let p be a new variable —i.e., not occurring in
′ or
′. Then we have, by (1),
where “ p ∨ ¬ p →” is eliminated from the right hand side of ⊢ in (2) since p ∨ ¬ p is a tautology. It follows that
Note that, conversely, whenever we satisfy
′ ∨
′ with some array of truth assignments s to its variables, then there is a truth assignment to p that when we append it to the array s yields a truth assignment that satisfies the left hand side of ⊢ in (3).
This appending can happen without conflicts because p is new!
Indeed, if
′ ∨
′ is t due to
′ being t , then we extend s by letting p to be t . If we know instead that
′ is t , then we extend s by letting p to be f .
This can be summarized as
′ ∨
′ is satisfiable iff (¬ p ∨
′) ∧ ( p ∨
′) is
Distributing the two ∨ over the CNF forms
′ and
′ above we get the required CNF and we are done with the proof.
The reader can propose an algorithm that implements the above on a string-processing URM and verify that going from
to a CNF, tracking the above proof, can be done within time O (|
| a ) for some a > 0 (cf. Exercise 5.3.12 ).
With these preliminaries out of the way, we can now show that CSAT , that is, the set of all satisfiable formulae in CNF, is
-complete. To this end, note that to prove that CSAT
we argue exactly as in the case of SAT ( 5.1.3.1 ). For the
-hardness part we show that
SAT ≤ p CSAT
(cf. 5.1.2.11 ). But this is achieved by the algorithm of Exercise 5.3.12 .
5.1.3.3 Example. Here is a problem, CP , that we can show
-complete by effecting the reduction CSAT ≤ p CP .
The reader has encountered the concept of a graph in discrete math courses. For completeness, let us recall that a directed graph , or digraph , is, mathematically, a relation E : V → V. We call the members of V nodes or vertices , and the members of E —the pairs 〈 a , b 〉 where { a , b } ⊆ V — edges. A digraph is finite iff V is finite. It is habitual to identify a finite digraph with a physical object , a drawing, where each node is depicted by a dot or a small circle and each edge 〈 a , b 〉 is depicted by an arrow that starts on the (physical depiction of) node a and ends (that is where the arrowhead touches) on the node b. Flow-diagrams of FA and PDA are (labeled) digraphs.
A digraph is complete iff all possible edges are present, except those of the type 〈 a , a 〉. That is, E : V → V is complete, iff E = V × V − 1 V , where 1 V is the identity (or diagonal ) relation on V , namely, {〈 a , a 〉 : a
V } (cf. 1.2.0.20 ).
If the relation E is symmetric , that is, whenever aEb it is also true that bEa , then the graph is called undirected. One usually says “graph” implying undirected graph and says “digraph” otherwise. In the physical depiction, we draw
rather than
A digraph C : A → A is a subgraph of E : V → V iff A ⊆ V and C = E ∩ ( V × V )—that is, C uses some of the nodes of E and all the edges that E uses to interconnect said nodes.
A graph ( undirected !) C is a clique in E iff it is a complete subgraph of E. The clique C is a k-clique if it has k nodes.
The clique problem, CP, is the question “ given a graph (undirected!) E and a number k; does E have a k-clique?”
Before we discuss the reduction, let us settle that CP
. We need to establish that given a graph E : V → V and a number k , every instance where there is a positive answer to the question “does E have a k -clique?” can be verified as follows:
(I) We “correctly” choose ( nondeterministically ) a set of k nodes, A , from V ; this is accomplished in O ( k ) steps, and hence in linear time with respect to input length—the input being 〈 k , E 〉.
We then proceed deterministically to verify that
(II) These nodes define a complete subgraph of E (one checks that A × A − 1 A ⊆ E ); to do so we check k 2 − k pairs of (distinct) nodes.
Pause. How is a graph (and a number) given ?
We can code 〈 k , E 〉 “linearly” as a sequence k , e 1 , . . . , e r where the e i are the edges—〈 a , b 〉—of E. Of course, the edges implicitly include the node information (set V ). Without loss of generality, since V is finite, we assume that V ⊆
.
A particularly efficient coding that does not involve exponentiation and can be easily decoded using string operations is the Quine-Smullyan coding [cf. Smullyan (1961), Tourlakis (1984)]: Given the alphabet Σ = {1,2,3, . . ., m }, where m > 1. A sequence of strings (which can be viewed as integers written in m -adic notation) in Σ + ,
a 1 , a 2 , . . . , a s
can be coded as follows:
First, locate the maximum length string over the alphabet {1}— tally of ones—that occurs as a substring in some of the a i . Say it is
Then form the “glue” -string g = 2 * x * 1 * 2. Finally, code the sequence by gluing the a i in order:
c = g * a 1 * g * a 2 * g * a 3 * g . . . g * a s * g
Decoding is easy: Find the maximum length tally of ones in c —this will be x * 1. Now the glue g = 2 * x * 1 * 2 is known, and the a i can easily be recovered.
Let us now establish the reduction CSAT ≤ p CP , which proves that CP is
-hard and along with the preceding discussion settles its
-completeness.
We need to find a poly-time computable function f that converts the question w
CSAT to f ( w )
CP. So, we are given a Boolean CNF formula w :
We build an undirected graph, f ( w ), that will have a k -clique (for appropriate k ) iff w
CSAT . The graph has nodes arranged in t rows. Row i has nodes labeled
There are no horizontal edges , that is, edges connecting nodes that have the same first component, i , in their labels. An edge connects nodes
and
, where i ≠ j , iff the literals
and
are compatible, that is, one is not the negation of the other.
It is immediate that the constructed undirected graph has a t -clique iff at least one literal in each row can be assigned t , without conflicts; and this is so iff w is satisfiable. On the other hand, it is also easy to see that the graph, f ( w ), is constructible within poly-time with respect to | w |.
There is a huge library of known
-complete problems. A good start point for the reader who wants to explore it is Papadimitriou (1994).