Solutions to Selected Miscellaneou s Exercises 373
satisfied. This only involves counting the distance from each # out to a
distance of j in each configuration, remembering three symbols in the
finite control, then moving to the next #, counting a distance j from
there, and comparing symbols. Each machine requires only O(n
k
) states
to do the counting.
30. First we show that if P = NP, then every deterministic polynomial-
time-computable length-preserving map f :Σ
∗
→ Σ
∗
is invertible.
Please note that the following solution is incorrect.
In NP, we can guess x and verify that f(x)=y. Because
P = NP, we can do the same thing deterministically.
This is incorrect because you have not shown how to produce x deter-
ministically when it exists.
Assume the alphabet is binary, say {0, 1}.Let≤ denote the prefix order
on strings; thus u ≤ x iff there exists v such that x = uv.Theset
{(x, y, u) ||x| = |y |,f(x)=y, and u ≤ x}
is in P, because all three conditions can be checked deterministically in
polynomial time; therefore the set
B = {(y,u) |∃x |x| = |y |,f(x)=y, and u ≤ x}
is in NP. By the assumption P = NP,thesetB is in P.Usingthisfact,
given y of length n we can do a binary search on strings of length n to
find x such that f(x)=y. First ask whether (y,ε) ∈ B.Ifnot,thenno
such x exists; halt and report failure. If so, ask whether (y,0) ∈ B.If
yes, there is an x with f(x)=y whose first bit is 0, and if no, all such
x have first bit 1. Now depending on the previous answer, ask whether
(y, 00) ∈ B or (y, 10) ∈ B as appropriate. The answer determines the
second bit of x. Continue in this fashion until all the bits of some x with
f(x)=y have been determined.
For the other direction, let ϕ denote a Boolean formula, say with m vari-
ables, and let t be a bit string of length m denoting a truth assignment
to the variables of ϕ. Consider the function
f(ϕ#t)=
ϕ#1
|t |
, if ϕ(t)=1,
ϕ#0
|t |
, if ϕ(t)=0.
Let f (y)=y for y not of the form ϕ#t.Thenf is length-preserving and
computable in polynomial time: first determine whether the input is of
the form ϕ#t, and if so, evaluate ϕ on t.Iff is invertible, then P = NP,
because ϕ is satisfiable iff there exists x such that f(x)=ϕ#1
|t |
.