Document 7850318

Download Report

Transcript Document 7850318

Giorgi Japaridze
Theory of Computability
The Church-Turing Thesis
Episode 1
1.1.a
Giorgi Japaridze
Components of a Turing machine (TM)
a
•
•
•
•
•
Theory of Computability
a
b a
b
b
-
-
-
-
-
-
(Q,,,,start,accept,reject)
Q is thefinite set of states
 is the input alphabet not containing the blank symbol  is the tape alphabet, where - and 
 is the transition function of the type Q Q{L,R}
start,accept,reject Q, where rejectaccept; the states
accept and reject are called halting states.
There are no transitions from the halting states, and they immediately take effect!
xy,R
q1
q2
If the current tape symbol is x, replace it with y, move the head right and go to
q2. The label xx,R is simply written as xR.
If we here have L instead of R, then the head is moved left, unless it was on the
first cell, in which case it remains where it was.
1.1.b
Giorgi Japaridze
Theory of Computability
How a Turing machine works
0L
xL
xR
start
-R
-L
q2
0 -,R
-R
xR
q5
0x,R
-R
reject
0 0
q4
-R
0
0
-
-
-
-
-
-
-
xR
0 x,R
0R
accept
start0000
q3
xR
Configuration:
1. Current state;
2. Tape contents;
3. Head position
1.1.c1
Giorgi Japaridze
Theory of Computability
Main Definitions
A TM accepts an input string iff, on that input, sooner or later it enters
the accept state. Otherwise the string is considered rejected.
Thus, the input is rejected in two cases:
1) the machine enters the reject state at some point (“explicitly rejects”),
2) or the machine never halts (“non-explicitly rejects”).
A Turing machine is said to be a decider iff it halts on every input.
The set recognized by a TM M is the set of the strings that M accepts.
If such an M is a decider, then we say that it not only recognizes, but
also decides that set.
• A set is said to be decidable (可判定的) iff some TM decides it.
• A set is said to be recognizable (可识别的) iff some TM recognizes it.
Synonyms of “recognizable” are semidecidable (半可判定的) and
recursively enumerable (递归可枚举的).
1.1.c2
Giorgi Japaridze
Theory of Computability
Recognizing vs. deciding
start
0R
-R
-R
accept
-R
0 R
0R
reject
What set does the above machine recognize?
Does it decide that set?
No.
start
-R
0R
-R
{0}
accept
0R
reject
What set does the above machine recognize?
Yes.
Does it decide that set?
{0}
1.1.d
Giorgi Japaridze
Theory of Computability
Diagrams without the reject state
0L
xL
xR
-R
start
0 -,R
q2
-R
q5
-L
q3
0x,R
0R
xR
0 x,R
accept
q4
xR
The reject state can be safely removed.
It will be understood that all the missing transitions lead to the reject state.
1.1.e1
Giorgi Japaridze
Theory of Computability
Designing TM: Example 1
Design a TM that recognizes (better – decides) {#n =m | n=m}
1. Sweep left to right across the tape, testing if the input has the form
#*=*; if not, reject; if yes, go back to the beginning of the tape
and go to step 2 (state q3).
R
start
# R
q1
#L
q3
R
= R
q2
- L
q9
L
= L
x L
- L
1.1.e2
Giorgi Japaridze
Theory of Computability
Designing TM: Example 1
2. Keep going to the right, replace the first  you see before = with
x and go to step 3 (state q5);
if you reach = without seeing a , go to step 4 (state q6).
xR
q3
# R
q4
x,R
q5
= R
q6
1.1.e3
Giorgi Japaridze
Theory of Computability
Designing TM: Example 1
3. Keep going to the right, pass = and then replace the first  you see
with x and go to the beginning of the tape, step 2 (this can be
done by going to state q9);
if you reach a blank without seeing a , reject.
q9
x,R
R
q5
= R
q7
xR
1.1.e4
Giorgi Japaridze
Theory of Computability
Designing TM: Example 1
4. Keep going to the right as long as you see x. If you see a  before
reaching a blank, reject; otherwise accept.
xR
q6
- R
accept
1.1.e4
Giorgi Japaridze
Designing TM: Example 1
R
start
# R
R
= R
q1
q2
- L
#L
# R
q4
q9
L
= L
x L
- L
x,R
R
xR
q3
Theory of Computability
x,R
q5
= R
q7
xR
xR
= R
q6
- R
accept
#     =    
-
-
-
1.1.f
Giorgi Japaridze
Theory of Computability
Designing TM: Example 2
Design a TM that decides {#n <m | n<m}
R
start
# R
R
< R
q1
q2
- L
#L
# R
q4
x,R
R
xR
q3
q9
L
< L
x L
- L
x,R
q5
< R
q7
xR
< R
R
q6
accept
xR
1.1.g
Giorgi Japaridze
Theory of Computability
Designing TM: Example 3
Design a TM that decides {#n +m = k | n+m=k}
R
R
start
# R
q0
+ R
R
= R
q1
q2
- L
#L
# R
q4
x,R
R
+R
xR
+R
q3
q9
+ L
L
= L
x L
- L
x,R
q5
= R
q7
xR
= R
q6
- R
accept
xR
1.1.h
Giorgi Japaridze
Theory of Computability
Designing TM: Example 4
Design a TM that decides {#n m = k | nm=k}
Step 1: Check if the string has the form #* * = * . If not, reject;
If yes, go back to the beginning of the tape, step 2.
Step 2: Find the first  between # and , delete it and go to step 3;
If no such  was found, go to step 5.
Step 3: Find the first  between  and =, delete it and go to step 4;
If no such  was found, go to the beginning of the tape, restoring on
the way back all the deleted  between  and =, and go to step 2.
Step 4: Find the first  after =, delete it, go back to , and go to step 3;
If no such  was found before seeing a blank, reject.
Step 5: Go right past = ; if no  is found there before reaching a blank,
accept; otherwise reject.
#  




= 





-
1.1.i
Giorgi Japaridze
Theory of Computability
Testing whether the head is at the beginning of the tape
Design a fragment of a TM that, from a state “Beg?”, goes to a state “Yes” or “No”,
depending on whether you are at the beginning of the tape or not,
without corrupting the contents of the tape.
Tape alphabet: {x1,…,xn}
1.
2.
Add a new tape symbol: $
Read the current symbol, remember it, type $, and move left;
Read the current symbol.
If it is $, restore the remembered symbol and go to “Yes”.
If it is not $, move right, restore the remembered symbol and go to “No”.
a1
x1,…,xn R
b1
$ x1,L
x1,R
x1 $,L
Beg?
…
Yes
Temp
xn $,L
$ xn,L
an
x1,…,xn R
xn,R
bn
L
No
1.1.j
Giorgi Japaridze
Theory of Computability
Implementing the “go to the beginning of the tape” operation
Design a fragment of a TM that, from a state “Go to the beginning”,
goes to the beginning of the tape and state “Done”.
Move left and test if you are at the beginning of the tape.
If yes, go to “Done”.
If not, repeat the step.
R
No
L
Go to the beginning
L
Done
Beg?
Yes
R
L
1.1.k
Giorgi Japaridze
Theory of Computability
Shifting tape contents
Design a fragment of a TM that, beginning from the current cell, shifts the contents of
the tape right, typing in the current cell a 0. Assume the tape alphabet is {0,1,-}.
Additionally assume that every cell after the leftmost blank cell is also blank.
1.
2.
3.
4.
If the current symbol is blank, type 0 and you are done.
Read the current symbol, remember it, type 0 and move right.
While the current symbol is not -, remember it, type
the previously remembered symbol and move right.
Once you see a blank, type the remembered symbol
and you are done.
00,R
00,R
Shift
Remembered 0
- 0,R
- 0,R
Done
01,R
10,R
10,R
- 1,R
Remembered 1
11,R
1.1.l
Giorgi Japaridze
Theory of Computability
A TM for the element distinctness problem
Design a TM that decides the set
E={#x1#x2#…#xn | each xi{0,1}* and xixj for each ij}
# x1 # x2 # x3 # x4 # x5
x1
#
0
1
x2
1
#
0
1
x3
0
#
0
x4
#
1
1
0
-
1.2.a
Giorgi Japaridze
Theory of Computability
Turing machines with the “stay put” option
A transition of this type of machine may have either L (move left),
Or R (move right), or S (stay put).
ab,S
q1
q2
“Replace a with b and go to state q2 without moving the head”
This does not increase the power of the machine, because the above
transition can be simulated with the ordinary TM as follows:
q1
ab,R
L
q2
1.2.b
Giorgi Japaridze
Theory of Computability
Multitape Turing machines
A multitape TM has k tapes, each with its own read/write head.
Initially, the input is written on the first tape, and all the other tapes
are blank, with each head at the beginning of the corresponding tape.
For a 3-tape TM, a transition will look like
0,1,11,0,1,R,R,L
q1
q2
“If you are in state q1 and see 0 on Tape1, 1 on Tape2 and 1 on Tape3,
• type 1 on Tape1, 0 on Tape2 and 1 on Tape3;
• move Head1 right, Head2 right and Head3 left;
• go to state q2.”
1.2.c
Giorgi Japaridze
Theory of Computability
Multitape Turing machines: Example
Design a fragment of a 2-tape TM that swaps the contents of the tapes,
from the position where the heads are at the beginning and there are
no blanks followed by non-blank symbols. Tape alphabet: {0,1,-}
0,00,0,R,R
0,11,0,R,R
0,-  -,0,R,R
1,00,1,R,R
1,11,1,R,R
1,-  -,1,R,R
-,00,-,R,R
-,11,-,R,R
Tape1
1
1
0
-
Tape2
0
0
-
-
-,- - ,-,L,L
Swap
Done
1.2.d
Giorgi Japaridze
Theory of Computability
Simulating multitape TM with ordinary TM
Theorem 1.1: Every multitape TM M has an equivalent single-tape TM S.
Proof idea: The contents and the head positions of M can be represented
on the single tape of S and correspondingly updated as shown on the
following example for a 3-tape M; S follows the steps of M and accepts
iff M accepts.
M:
S:
#
Tape1
1
1
1
-
Tape2
0
-
-
-
Tape3
1
0 -
-
.
1
1
1
#
0
q2
.
-
#
1
0
#
-
-
-
-
1.2.e
Turing machines with an outputGiorgi Japaridze
(not in the textbook!)
Theory of Computability
The only difference with ordinary TM is that a TM with an output
(TMO) has a state halt instead of accept and reject; if and when such a
machine reaches the halt state, the contents of the tape (up to the first
blank cell) will be considered its output.
Example: Design a machine that, for every input w{0,1}*, returns w0.
0R
1R
- 0,R
halt
1.2.f
Giorgi Japaridze
Theory of Computability
Computable functions
A function g: * * is said to be computable, iff there is a TMO
M such that for every input w* M returns the output u with u=g(w).
In this case we say that M computes g.
Example: Let f: {0,1}* {0,1}* be the function defined by
f(w)=w0,
so that f()=0, f(0)=00, f(1)=10, f(00)=000, f(01)=010, etc.
Then obviously f is computable.
The graph of a function g: * * is the set
{(w,u) | w*, u=g(w)}
E.g., the graph of the above function f is
{(,0), (0,00), (1,10), (00,000), (01,010), …},
i.e.
{(w,u) | w{0,1}*, u=w0}
1.2.g
Giorgi Japaridze
Theory of Computability
Computability vs. decidability
Theorem 1.2: A function is computable iff its graph is decidable.
Proof sketch. Let g: * * be a function.
(): Suppose C is a TMO that computes g. Construct a TM D that works as follows:
D = “On input t:
1. If t does not have the form (w,u), where w,u*, then reject. Otherwise,
2. Simulate C for input w. If it returns u, accept; otherwise reject.”
(): Suppose a TM D decides the graph of g. Let s1,s2,s3,… be the lexicographic list of
all strings over the alphabet . Construct a TMO C that works as follows:
C =“On input t:
Simulate D for each of the inputs (t,s1), (t,s2),(t,s3),… until you find si
suct that (t,si) is accepted, and return this si”
1.3.a
Giorgi Japaridze
Theory of Computability
Algorithms
The intuitive notion of algorithms: An algorithm (procedure, recipe)
is a collection of simple instructions for carrying out some task.
Examples:
• The elementary school algorithms for adding, subtracting, multiplying,
etc.;
• Calculating students’ average grades;
• Sorting algorithms;
• Any other procedures that you’ve learned in the Algorithms course.
To carry out an algorithm, you only need to mechanically (blindly)
follow its instructions. No understanding of the objects you are
manipulating, no understanding of what you are doing is needed!
We need a strict mathematical definition of an algorithm. The above
“definition” obviously does not qualify.
1.3.b
Giorgi Japaridze
Theory of Computability
Algorithms should deal with strings
The structure of an algorithm:
Input(s)
Output
Input(s)
Yes (accept) or No (reject)
or
The attempt to formalize the notion of algorithm should start from
strictly specifying what kind of objects can be inputs/outputs.
These are going to be strings only.
No loss of generality: non-string objects can be easily represented with
strings. A tuple of such objects can also be represented with a
(one single) string.
After all, computers exclusively deal with strings --- strings over the
alphabet {0,1} !
1.3.c
Giorgi Japaridze
Theory of Computability
Encoding
Encoding --- representing objects as strings in some standard way.
There are usually many ways to encode; as one encoding can be
easily (algorithmically) converted into another, it does not matter
which encoding we choose.
Encoding numbers: 0,1,2,3,…,34,…, or 0,1,10,11,…,100010,…
Encoding pairs of numbers: (4,2), (1,3), …, or 4#2, 1#3,…, or aaaabb, abbb, …
Encoding people: “David Stewart”, “Dongfei Wei”, …, or
“Stewart, David”, “Wei, Dungfei”, or 315-21-5541, 326-11-1521…
Encoding assembly language instructions: Their machine language equivalents.
If O is an object, <O> will stand for a (the) encoding of O.
1.3.d
Giorgi Japaridze
Theory of Computability
Encoding graphs
1
2
4
5
3
G=
<G> = (1,2,3,4,5)((1,4),(1,5),(2,3),(4,5))
Algorithm M for checking if a graph is connected:
M = “On input <G>, the encoding of a graph G:
1. Select the first node of G and mark it.
2. Repeat the following stage until no new nodes are marked:
3. For each node in G, mark it if it is attached by an edge to a
node that is already marked.
4. Scan all the nodes of G to determine whether they all are
marked. If they are, accept; otherwise reject.”
1.3.e
Giorgi Japaridze
Theory of Computability
The Church-Turing thesis
The Church-Turing thesis:
(the intuitive notion of) Algorithm = Turing machine
It can never be mathematically proven!
Importance: Without the Church-Turing thesis, you can never prove
that a certain problem has no algorithmic solution.
Example - Hilbert’s 10th problem .
1.3.f
Giorgi Japaridze
Theory of Computability
The three levels of TM descriptions
1. Formal description:
The TM is fully described, say, by giving a transition diagram, or
list of states, input/tape alphabets, a table for the transition function.
Examples: Slides 1.1.b, 1.1.f, etc.
2. Implementation description:
English is used to describe the way that the machine moves its
head and stores data on its tape. Details of states or transition
functions are not given.
Example: Slide 1.1.h.
3. High-level description:
English is used to describe the algorithm, without worrying about
implementation-level details. There is no mention of head, tape etc.
Example: Slide 1.3d.
All the algorithms taught in an Algorithms course.