Chapter 6 Computablity
Chapter 6 Computablity
1 if n = 0
n!= (recursive solution)
(n-1)!*n if n > 0
1 if n = 0
n!= (closed form solution)
1*2*3*…*(n-1)*n if n > 0
Coding the factorial function
Base case
A case that is not recursive and directly obtainable.
Will have a value of 1 or 0 or null or something
having some kind of discrete value…
Recursive case
A case that is ultimately defined in terms of base case.
Stated equivalently:
Complex case
. Must be defined in terms of a "simpler" case
. Plus the base case must be:
. a directly solvable, non-recursive trivial
case
We develop solutions using the assumption that the simpler
case has already been solved.
SIMULATING RECURSION
• Some languages do not support recursion.
• It is often very common to be able to come up with a recursive
solutions to a problem.
• Since some compilers do not support recursion, we need to be able to
come up with non-recursive solutions. (Iterative Routines)
Note That:
M’ accepts iff M does not, M’ always halts since M always halts
Note That:
L(M’) = L(M1) L(M2)
L(M’) is a subset of L(M1) U L(M2)
L(M1) U L(M2) is a subset of L(M’)
M’ always halts since M1 and M2 always halt
L L1 L2
It follows from this that3 is recursive.
• Theorem 3: The recursive enumerable languages are closed with
respect to union, i.e., if L1 and L2 are recursively enumerable
languages, then so is L3 L1 L2
w
yes
M2
Note That:
L(M’) = L(M1) U L(M2)
L(M’) is a subset of L(M1) U L(M2)
L(M1) U L(M2) is a subset of L(M’)
M’ halts and accepts iff M1 or M2 halts and accepts
L3 L1 L2
It follows from this that is recursively enumerable.
Question: How do you run two TMs in parallel?
• Suppose, M1 and M2 had outputs for “no” in the previous
construction, and these were transferred to the “no” output for M’
M’ yes yes
M1
no
w
yes
M2 no
no
w
yes
M2 no
Note That:
L(M’) = L
L(M’) is a subset of L
L is a subset of L(M’)
M’ is TM for L
M’ always halts since either M1 or M2 halts for any given string
M’ shows that L is recursive
ItLfollows from this that L (and therefore its’
complement) is recursive.
So, is also recursive (we proved it before).
In terms of the hierarchy: (possibility #1)
L L
Recursive Languages
In terms of the hierarchy: (possibility #2)
L L
Recursive Languages
In terms of the hierarchy: (possibility #3)
L L
Recursive Languages
In terms of the hierarchy: (Impossibility #1)
L L
Recursive Languages
In terms of the hierarchy: (Impossibility #2)
Recursive Languages
In terms of the hierarchy: (Impossibility #3)
Recursive Languages
• Note: This gives/identifies three approaches to show
that a language is not recursive.
• Show that the language’s complement is not recursive, in
one of the two ways:
• Show that the language’s complement is recursively enumerable but not
recursive
• Show that the language’s complement is not even recursively enumerable
The Halting Problem - Background
Definition: A decision problem is a problem having a yes/no answer (that
one presumably wants to solve with a computer). Typically, there is a list
of parameters on which the problem is based.
Given a list of numbers, is that list sorted?
Given a number x, is x even?
Given a C program, does that C program contain any syntax errors?
Given a TM (or C program), does that TM contain an infinite loop?
From a practical perspective, many decision problems do not seem all
that interesting. However, from a theoretical perspective they are for the
following two reasons:
Decision problems are more convenient/easier to work with when proving complexity results.
Non-decision counter-parts can always be created & are typically at least as difficult to
solve.
Notes:
The following terms and phrases are analogous:
Algorithm - A halting TM program
Decision Problem - A language (will show shortly)
(un)Decidable - (non)Recursive
• We want to f i n d a language t h a t is not Recursively
Enumerable
••
•
Consider Turing Machines
that accept languages over alphabet {a}
1
Example language accepted by Mi
L ( M i ) ==
{aa,aaaa,aaaaaa}
2 4 6
L(Mi)=={a ,a ,a}
Alternative representation
4 as a6 a7
a ...
0 1 0 1 0 ···
a 2 •••
L(M1) 1 0 1 •••
0
0 0 1 •••
L(M 2 ) 1
1 1 1 •
••
L(M3) 0
L(M4) 0 0 0 1 ••
•
Consider the
language
.
.
E L(Mi)}
L =={al:al
L(M1) 0 1 0 1 ...
L(M2 ) 1 0 0 1 ...
I 1 1 ...
L(M 3 ) 0
0 0 1 ...
3 4
L = = { a , a , . .}
1 5
Consider the language L
.
E L(Mi)}
L =={al:
a 1
L == : al
{a L(Mi)}
-
L consists of the O'sin the diagonal
• •
•
L(M1) 0 1 0 1 ...
L(M 2 ) 1 0 0 1 ...
1 1 1 ...
L(M3) 0
0 1 ...
- 1
L={a 2
a, ...}
,
Theorem:
Language L is not recursively enumerable
Proof: Assume for contradiction that
i.t recursively enumerable
L(M1) 0 1 0 1 ...
0 1 ...
L(M 2 ) 1 0
1 1 1 ...
L(M3) 0
L(M4) 0 0 0 1 ...
•
••
L(M1) 0 1 0 1 ...
0 1 ...
L(M 2 ) 1 0
1 1 1 ...
L(M3) 0
0 1 ...
•
••
L(M1) 0 1 0 1 ...
0 1 ...
L(M 2 ) 1 0
1 1 1 ...
L(M3) 0
L(M4) 0 0 0 1 ...
•
••
L(M1) 0 1 0 1 ...
0 1 ...
L(M 2 ) 1 0
1 1 1 ...
L(M3) 0
0 1
...
a 22 L(M2 )
•
••
L(M1) 0 1 0 1 ...
0 1 ...
L(M 2 ) 1 0
1 1 1 ...
L(M3) 0
L(M4) 0 0 0 1 ...
Question: Mic=M 3 ?
•
••
L(M1) 0 1 0 1 ...
0 1 ...
L(M2 ) 1 0
L(M3) 0 1 1 1 ...
0 1
...
3
Similarly:
Because either:
or
Therefore, the machine Mk cannot exist
Therefore, the language L
is not recursively enumerable
Observation:
L
Recursively Enumerable
Recursive
A Language which is
Recursively Enumerable
and not Recursive
We want to find a language which
Is But not
recursively recursi ve
•
enumerable
L(M1) 0 1 0 1 ...
L(M2 ) 1 0 0 1 ...
I 1 1 ...
L(M 3 ) 0
0 0 1 ...
3 4
L = = { a , a , . .}
3 3
Theorem:
. .
The language L == { a : a
1 1
E L(Mi)}
is recursively enumerable
Proof:
We will give a Turing Machine that
accepts L
Turing Machine that accepts L
For any input string w
.
·Compute i, which w == al
for
·Find Turing machine Mi
(using an enumeration procedure
for Turing Machines)
.
·Simulate Mi on input al
·If Mi accepts, then accept w
End of
Observation:
Recursively enumerable
. .
L =={al: al E L(Mi)}
L =={al: al L(Mi)}
. .
The language L == { a : a
1 1
E L(Mi)}
is not recursive
Proof
:Assume for contradiction that L is recursive
Then L 1s •
L is recursive
But we know:
CONTRADICTION!!!!
Therefore, L is not recursive
End of
Proof
Non Recursively Enumerable
L
Recursively Enumerable
L
Recursive
Turing acceptable languages
and
Enumeration Procedures
We will prove:
(weak result)
·If a language is recursive then
there is an enumeration
procedure for
it
(strong result)
• A language is recursively enumerable
if and only if
there is an enumeration procedure for it
Theorem:
if a language L is recursive then
there is an enumeration procedure for it
Proof:
Enumeration Machine
..
-
M
, - ...,,;
M -.
p
p
. .
.
t
'
Enumerates all
Accepts L
strings of input alphabet
If,...._ the alphabet is {a,b}
Mn enumerate strings as follows:
then
,
a
b
aa
ab
ba
b
aaa
b
aa
b
••••••
Enumeration procedure
Repeat:
M
,-....;
generates a string w
M checks if w E L
YES:print vt,to output
NO:ignore w
End of
Proof
Example:L
=={b,ab,bb,aaa.,...}
,... . Enumeration
M
,
L(M Output
a )
b b b
aa
ab a a
b b b
a
b b b
aa aa aa
ab b
a
b
a
aa •••••• ••••••
Theorem:
Enumeration Machine
-
'" .
r
•
M .
M r
I .
+
-
Enumerates all
Accepts L
strings of input alphabet
If,...._ the alphabet is {a,b}
Mn enumerate strings as follows:
then
,
a
b
aa
ab
ba
b
aaa
b
aa
b
NAIVE APPROACH
Enumeration procedure
Problem: If w L
machine M may loop forever
BETTER
APPROACH
M Generates first string w1
,-..
.._;
M
,-..
Generates second string
.._;
W2
M executes first step on w2
second step on w1
M Generates third string w3
M executes f i r s t step on w3
second step on w2
third step on w1
And so on............
1 - ------- 1 1
1--.
Step
,n
• 2 2
string
3 3 3 3
•••
If for any string wi
machine M halts in a final s t a t e
then it prints wi on the output
End of
Theorem:
If for language L
there is an enumeration procedure
then L is recursively enumerable
Proof
Input Tape
:
w
Machine that
accepts L
Enumerator Compar
for L ..
e
.
Turing machine that accepts L
For input string w
Repeat:
·Using the enumerator,
generate the next string of
L
·Compare generated string with
w
We have proven: