4-computation (1)
4-computation (1)
Theory of computation
• Which problems can we solve
– With some (any given) type of machine
– In the broadest possible meaning
• At first sight the question seems too general:
– What do we mean by “problem”?
A mathematical computation; taking a decision in a meeting
of people; cash withdrawal from an ATM …?
– Which abstract machines should we consider?
– What does it mean to be able to solve a problem:
If I am not able to solve the problem by some means I might
be able to solve it by some other one.
2
L {x$ y | y ( x)}
– Assuming that I can recognize L using some machine, then, for a fixed x, I could
enumerate all possible strings y over the output alphabet and for each of them ask the
machine if x$y Lt: soon or late, if t(x) is defined, I will find the string for which
the machine answers positively: this is a way to compute y= (x).
The procedure is “a bit long” but at the moment we are not concerned about the
length of computations
3
HENCE
there is a ultimate generalization:
4
q0 ⊥ ⊥ ⊥ q0 (q0,0,L) ⊥ ⊥
MT2 0 1 _
q0 (q0,0,R) ⊥ ⊥ ...
MT999 0 1 _
q0 ⊥ ⊥ ⊥ q0 (q0,0,L) ⊥ ⊥
q1 ⊥ ⊥ ⊥ q1 ⊥ ⊥ ⊥
...
10
( x y )( x y 1)
6 d ( x, y ) x
3 2
1 4
0 2 5
12
$ q a q’ a’ S $ .. ..
# 0 1 0 .. 1 q 1 1 0 #
NB: The special symbols #, $ and other ones are coded as binary strings
At the end the UTM leaves on the tape fy(x) if and only if My terminates on x
13
Answer: NO
• That’s why a computer (which is a program) cannot
warn us that the program we just wrote will run into an
endless execution on a given input datum (while it
easily signals a missing “}”):
• Determining if an arithmetic expression is well
parenthesized is a solvable (decidable) problem;
• Determining if a given program will run into an endless
execution on a given input is an algorithmically
unsolvable (undecidable) problem [we will see many
more ones: there are many things that a computer
cannot do]
18
Proof
• It employs a typical diagonal technique (adopted also in the Cantor theorem to show
that 0 < 20 )
• Let us assume (by contradiction) that the total function :
g(y,x) = 1 if fy(x) , g(y,x) = 0 if fy(x) =
is computable
• Then also the partial function
h(x) = 1 if g(x,x) = 0 (i.e., if fx(x) =),
if g(x,x) = 1 (i.e., if fx(x) )
is computable
NB: we went on the diagonal y=x, we changed the no answer (g(x,x) = 0) into a yes
answer (h(x)=1), and we turned the yes (g(x,x) = 1) into a nontermination (h(x)=),
which can always be easily done by modifying the TM that (supposedly) computes g
• If h is computable then h = fx’ for some x’.
19
RECALL h(x) = 1 if g(x,x) = 0 (i.e., if fx (x) =), h(x) = if g(x,x) = 1 (i.e., if fx (x) )
• From a practical viewpoint, this problem is perhaps even more relevant than the
halting problem:
• given a program, one wants to know if it will terminate the execution for every input
datum or if it may, for some datum, run into an endless execution.
• In the problem of termination, instead, one was interested to know if a given program
with some given input datum would terminate.
• NB: this result is a trivial consequence of the coming Rice Theorem, because function
k is a predicate characterizing total computable functions
22
• NB: it is a problem similar to but different from the previous one. Here we have a
quantification w.r.t. all possible input data.
• For this problem, testing is useless: In some cases one could be able to establish, for a
large set of values of variabile x, that fy(x) , without however being able to answer
the question “is fy a total function?” (Obviously, if one finds an x such that fy(x) =,
one can conclude that fy is not total, but what if one does not find it?)
• Vice versa, one could be able to conclude that fy is not total and however be unable to
decide whether fy(x) for a given single x.
• (However, if one was able to conclude that fy is total there would be no doubt on
whether fy(x) for a given x)
23
Proof
• Standard technique: diagonal + contradiction, with some more technical
detail.
• Hypothesis: k(y) = 1 if fy is total, i.e., if fy(x) xN; otherwise k(y) = 0
is computable and obviously, by definition, total
• Then define g(x) = w = index (Goedel number) of the x-th TM (in E) that
computes a total function.
• If k is computable and total, then so is g:
– compute k(0), k(1), …, let w0 the first value such that k(w0) = 1, then let g(0) = w0;
– then let g(1) = w1, w1 being the second value such that k(w1) = 1; …
– the procedure is algorithmic; furthermore, being total functions infinite in number,
g(x) is certainly defined for each x, hence it is total.
• g is also strictly monotonic: wx+1 > wx;
• hence g-1 is also a function, strictly monotonic too, though not total: g-1(w) is
defined only if w is the Goedel number of a total function.
24
Next define
(a) h(x) = fg(x)(x) + 1 = fw(x) + 1:
fw is computable and total hence so is h
(b) h = fw0 for some w0;
since h is total, g-1(w0) , let g-1(w0) = x0 (hence w0= g(x0))
• What is the value of h(x0) ?
– h(x0) = fg(x0)(x0) + 1 = fw0(x0) + 1 (from (a))
– h = fw0 hence h(x0) = fw0(x0) (from (b))
• Contradiction!
25
A crucial remark: knowing that a problem is solvable
does not mean being able to solve it!
• In mathematics we often have non-constructive proofs: one shows that a
mathematical object exists without providing a way to actually find (and
exhibit) it
• In our case:
– a problem is solvable if there exists a TM that solves it
– for some problems we can reach the conclusion that there exists a TM that solves
them, but, despite our knowledge of this, we are unable to find (build) it or we do not
know which one it is in a set of TM that certainly includes the “right one”
• Let us start with a trivial case
– The “problem” consists of answering a question with a yes/no answer (a so-called
closed question, whose answer does not depend on an input value/parameter):
10
• Is it true that the number of atoms in the universe is 10 101010 ?
• Is it true that the “perfect chess game” will end in parity?
• ….
26
• In such cases one knows a priori that the answer is either Yes or No, though one does
not know (or did not until some point in time) which one it is
• This fact is less surprising if we consider that
Problem = function; solve a problem = compute a function
What function can one associate to the above problems?
If one encodes TRUE=1; FALSE=0, all the above problems are expressed by one of
the following two functions: f1(x) = 1 x, or f0(x) = 0 x
Both functions are trivially computable (all constant functions are…), hence
Whatever the answer is, it is computable, though not necessarily known.
• More abstractly, considering for instance function g(y, x) of the halting problem:
g(10,20) = 1 if f10(20) , g(10,20) = 0 if f10(20) =;
g(100,200) = 1 if f100(200) , g(100,200) = 0 if f100(200) =; ...
Hence g(10,20) (i.e.: does TM M10 stop on input 20?), g(100,200), g(7,28) etc. are all
solvable problems, though we do not necessarily know the solution (i.e., the value of g
for those arguments).
27
Decidability and semidecidability
Or: 1/2 + 1/2 = 1
• Let us focus on the problems stated in such a way that the answer is binary:
Problem = “given set S N and xN, x S?”
(NB: all problems can be (re)phrased in such a way,
because they can all be viewed as a language)
• characteristic function or characteristic predicate of a set S: it is the
predicate characterizing the set
cS (x) = 1 if x S, cS (x) = 0 if x S
(NB: cS is total by definition)
• A set S is recursive (R) or decidable if and only if its characteristic function
is computable
– Note on terminology: It is also customary to say that solvable problems are decidable
28
Theorem
• A) If S is recursive, it is also RE
(i.e., decidable is more than –not less than- semidecidable)
• B) S is recursive if and only if both S itself and its
complement S^ = N - S are RE
(two “semidecidabilities” make a “decidability”; or, when
answering NO is equivalent to (i.e., it is equally difficult
as) answering Yes
• (Corollary: the class of decidable sets (languages,
problems, …) is closed under complement)
• Proof:
30
But S S^ = N, S S^ =
hence x N , x belongs to exactly one of the two enumerations
The following enumeration
{g S (0), g S ^ (0), g S (1), g S ^ (1), g S (2), g S ^ (2), g S (3), g S ^ (3),...}
certainly includes any x in exactly one position: if x is at an odd
position, then x S, if it is at an even position then x S^. Hence cS
can be computed.
32
Other very important results
• S is RE S = Dh, with h computable and partial: S = Dh = {x| h(x) }
and
S is RE S = Ig, with g computable and partial: S = Ig = {x| y N : x = g(y)}
• The above theorem allows us to view RE sets as characterizing precisely
the languages recognized/accepted by the Turing Machines
(NB not decided : decide and recognize/accept differ slightly)
• It can also serve as a Lemma to prove that:
• There exist semidecidable sets that are not decidable:
K = {x| fx(x) } is semidecidable because K = Dh with h(x) = fx(x).
We know however that the characteristic function of K, (cK(x) = 1 if fx(x) , 0 else) is
not computable K is not decidable
• Conclusion:
33
(N )
RE sets
Recursive sets
K K^
S S^
of previous slide
Problem reduction
• If one has an algorithm to solve problem P one can use it to solve
problem P’:
– TRIVIAL EXAMPLE: One can compute the product of two numbers a and b if
one can compute the operations: sum, difference, division by 2, square. It suffices
to use the formula ab=((a+b)2-a2-b2)/2. Hence multiplication is reduced to {sum,
difference, division by 2, square}
– In general if there is an algorithm that, given a instance of a problem P’ builds its
solution by producing (algorithmically) an instance of another problem P that is
solvable, and such that from the solution of P one can obtain algorithmically that
of P’, then P’ has been reduced to P.
– Using the set inclusion formulation of a problem:
• I want to solve x S’
• I can solve y S for all possible y
• If I have a computable, total function t such that x S’ t(x) S
then I can answer algorithmically the question x S’
• i.e., I have reduced the problem x S’ to the problem y S ( DecS DecS’ )
37
• The method can work also in the opposite way:
– I want to know if I can solve x S
– I know I cannot solve y S’ (S’ is not decidable, DecS’ )
– If I reduce S’ to S, that is, ( DecS DecS’ )
I find a computable total function t such that y S’ t(y) S
then I can conclude that x S is not solvable (otherwise I could show that xS’ is
solvable by reducing it to xS) ( DecS DecS’ hence DecS’ DecS)
• In fact, we already used implicitly this way of reasoning several times:
– From the undecidability of the halting problem for the TM we derived in general
the undecidability of the problem of termination of any computation on any
computer; for instance, concerning the termination of C programs:
• Consider a TM My and an integer x
• I can build a C program, P, that simulates My and I can store x in an input file f
• program P terminates its computation on file f if and only if fy(x)
• If I could decide if P terminates its computation on f then I could solve also the halting
problem for the TM.
38
Reduction is a general, powerful technique
• Is the problem “does a generic program P access an uninitialized
variable?” decidable?
– Let us assume (by contradiction) that it is decidable and let us show by
reduction that in that case the halting problem would be decidable
– We can consider an instance P of the halting problem and reduce it to the
following “uninitialized variable access” problem P^:
• P^:
begin var x, y: …
P;
y := x
end
making sure that identifiers x and y are “fresh variables”, not used in P
• It is clear that the assignment statement y := x results in accessing an uninitialized
variable, because x and y do not occur in P
• Hence the uninitialized variable x is accessed in P^ if and only if P terminates.
– Then if I could solve the problem of “diagnosis of uninitialized variable access”
then I could solve also the termination problem, which cannot be.
39
input argument z
3
0 n. of steps
1 2 3 4
This way, if z s.t. fx(z) , eventually I find it because eventually I will simulate enough
computation steps of fx(z) to terminate
42