Uploaded by Мекан Курбанов

14994049

advertisement
Theory of
Computation
Turing Machines
Computer
Science
Turing Machines: Origin
• In the 40s, a mathematician called David Hilbert proposed a question
– Known as his 10th problem
Is it true that 𝑥 2 + 𝑦 2 + 1 = 0 has roots which are whole numbers?
• This was a decision problem
– The solution was either yes or no
• Alan Turing was intrigued by this problem
2
Theory of Computation: Turing Machines
Turing Machines: Origin
• From this question, Turing devised an abstract model of computation
– Originally aimed solely at solving this problem
• He defined an effective procedure for solving this problem
– A more rigorous definition of an algorithm
• He based this procedure on how human computers carried out
algorithms
– People which calculated values
3
Theory of Computation: Turing Machines
Turing Machines: Origin
• The procedure involves a few things
– An infinitely long one-dimensional piece of tape (with equally-sized spaces
on it)
– An instrument for writing/reading spaces on the tape
– A mechanism for moving to different spaces on the tape
4
Theory of Computation: Turing Machines
Turing Machines: Origin
• Each space on the tape can contain
– Either nothing at all (an empty space)
– OR a specific symbol (chosen from an Alphabet)
• These symbols are usually restricted (i.e. 0 and 1)
– As we can easily create any other symbol as a
combination of base symbols
– As shown in the table
5
Theory of Computation: Turing Machines
N
Series
1
1
2
11
3
111
4
1111
5
11111
Turing Machine: Origins
• Finally, the behaviour of the machine was determined solely by
– The current state-of-mind (or just ‘state’) of the machine, and
– The observed symbols in the current space on the tape
• While there may by infinite spaces on the tape, the machine can only
observe one at a time
• The same also applies to the different state the machine can be in
– The machine has a finite number of them, and can only be in one at a time
6
Theory of Computation: Turing Machines
Turing Machines: Origins
• Turing devised this idea for human computers
• Turing also thought that anything that is computable can be broken
into its smallest computations
– And represented in one of these machines
– For any computer/program we’ve made so far, that is correct!
7
Theory of Computation: Turing Machines
Worked Example
• Here is the problem we need to ‘solve’
Can we test if an input string has 𝑛 0s, followed by 𝑛 1s?
• This is another decision problem
– Which we are going to solve using a Turing machine
• To ‘set up’ this machine, we need
– To put any starting symbols on the tape
– To work out what are states are (and how to transition between them)
8
Theory of Computation: Turing Machines
Worked Example
• Let’s start by getting the tape set up
– The tape is infinite
– Giving us as much space as we want to work with
• We’re going to have three symbols in our alphabet for this machine
– #, 0, 1
• Then let’s start with an example input like so:
#
9
0
0
1
1
Theory of Computation: Turing Machines
#
Worked Example
• For this machine, we either accept or reject the input based on
– The symbols between the two #s
• If there are no symbols between these #s, then the input is accepted
• If there are symbols left over, the input is rejected
#
10
0
0
1
1
Theory of Computation: Turing Machines
#
Worked Example
• With the state of the tape set up, the next thing we need to work out
is a bit trickier
– What states and transitions will the machine use?
• You may recognise both these terms from Finite-State Machines
– That’s because a Turing Machine uses the same concepts
– It has states that it is currently on
– And can transition between states based off of an input
11
Theory of Computation: Turing Machines
Worked Example
• We need to create states and transitions so that the following happens
–
–
–
–
Start at the left-most #
Remove the first 0 that is found, then move to the right-most #
Remove the first 1 that is found, then move to the left-most #
Repeat this until no 0 or 1 is found, at which point the machine stops
• The transitions that go with these states need
– An input (the possible symbol we could read under the ‘read head’)
– An output (where the ‘read head’ will move, and what it could write in the current
space)
12
Theory of Computation: Turing Machines
Worked Example
• Here is the state transition diagram for this Turing Machine
• Each transition is a directional
arrow
– From one state to another
• Each label on a transition is the
input/output
– Input goes on the left of the bar (|)
– Output goes on the right
13
Theory of Computation: Turing Machines
Worked Example
• Any input for a transition is what must be read from the tape in the
current position
• Any output for a transition is
what will be written to on that
space
• The arrows show the direction of
movement for the read head
14
Theory of Computation: Turing Machines
• Create a Turing Machine that answers the following problem
Can we test if an input string only contains 0s (and no 1s at all)?
• You will need to show the starting tape (including any symbols)
• And you will need to create the state transition diagram
• Once done, state what possible tape symbols your Turing Machine may end with
– And what those mean
15
Theory of Computation: Turing Machines
Transition Rules Reminder
• Remember (from our look at Finite State Machines) that transition
rules have different representations
• They are commonly seen in state transition diagrams
– As labels on directed arrows
• However, we can represent them mathematically using a specific
symbol
– Can you remember what that symbol is?
16
Theory of Computation: Turing Machines
Transition Rules Reminder
• We use the symbol 𝛿 (delta)!
– The input goes inside brackets after it
– The output goes after the equal sign
• Here is an example: 𝛿 1, 0 = ☐, →
• This means “if 1 or 0 is in the current space under the read/write
head, replace it with a blank space and move the read/write head to
the right”
17
Theory of Computation: Turing Machines
Tracking Turing Machine Execution
• A handy thing to be able to do is track the execution of a Turing
Machine
• This means keep track of all the states of the tape as the Turing
Machine executes its states/transitions
• We can then show all these tape states in something like a table
18
Theory of Computation: Turing Machines
Tracking Turing Machine Execution
• However, we first need to know the notation we’re going to use
• We’ll consider the tape as three different sections
– Everything to the left of the read/write head
– The cell under the read/write head
– Everything to the right of the read/write head
• We will show that using something like this: ☐, 1, 00☐1
19
Theory of Computation: Turing Machines
Tracking Turing Machine Execution
• Staying on this example: #, 1, 00☐1
• The first value in the brackets means there is only one cell to the left of the
read/write head
– And it contains #
• Then the read/write head is currently looking at the symbol 1
• Finally, there are four spaces to the right of the read/write head
– And the order of them in the brackets is their order, from left-to-right
– The tape is infinite, meaning we ignore any blank spaces to the left/right of any written
symbols
20
Theory of Computation: Turing Machines
Tracking Turing Machine Execution
• Let’s use the same 0s as 1s machine from the worked example earlier
• With a tape of #0011#, here is the machine’s execution
21
Execution of Machine
Execution of Machine
Execution of Machine
(, #, 0011#)
(#☐01, 1, #)
(#☐☐, 1, ☐#)
(#, 0, 011#)
(#☐01, ☐, #)
(#☐☐1, ☐, #)
(#, ☐, 011#)
(#☐0, 1, ☐#)
(#☐☐, 1, ☐#)
(#☐, 0, 11#)
(#☐, 0, 1☐#)
(#☐☐, ☐, ☐#)
(#☐0, 1, 1#)
(#, ☐, 01☐#)
(#☐, ☐, ☐☐#)
(#☐01, 1, #)
(#☐, 0, 1☐#)
(#☐011, #, )
(#☐, ☐, 1☐#)
Theory of Computation: Turing Machines
• Copy down the execution of the machine you made for an earlier
exercise
– Which tests if an input string only contains 0s (and no 1s)
• Make two executions for these inputs
– 0000
– 0100
• Feel free to add any other symbols your Turing Machine requires
– And lay out the inputs at any position on the tape
22
Theory of Computation: Turing Machines
Turing Machines and Computation
• Turing Machines are very important to the idea of computation
– And whether a solution is computable
• It is enough to know that a specific result can be found by following a specific
algorithm
• However, we cannot show that a result is not computable
• We can show the ‘computability’ of a solution by seeing if we can make a Turing
Machine for it
– If one exists, then an algorithm for its solution exists too
– If not, then no computable solution exists
23
Theory of Computation: Turing Machines
Turing Machines and Computation
• A program can be represented by a Turing Machine
• Saying that a solution to a problem is computable only if a Turing Machine exists is
correct
– However, we can reverse that logic
• We can better say if a Turing Machine exists, there exists a computable solution
– This means every algorithm we can create/think of can also exist as a Turing Machine
• This concept is known as the Church-Turing thesis
24
Theory of Computation: Turing Machines
Turing Machines and Computation
• This ultimately means that anything a computer can compute, a
Turing Machine can compute as well!
– So, any limitations a Turing Machine has, a computer has as well
• A Turing Machine is the most basic of operations
– It cannot be broken down further
• However, other computers can be reduced
– Which means no computer can be more powerful than a Turing Machine
25
Theory of Computation: Turing Machines
Turing Machines and Computation
• We can simulate more complex calculations by connecting together
multiple Turing Machines
– Which use the result as one as the input of another
• When thinking about the computability of solutions, using larger
computers/devices would be bad
– Take a processor, which changes every few years
– If we base our idea on computability on one of these processors, we would need
to re-evaluate these thoughts for every new processor
• However, basing our thoughts on a Turing Machine, which doesn’t
change, means we don’t need to re-evaluate our ideas of computability
26
Theory of Computation: Turing Machines
Universal Turing Machine
• The idea of connecting multiple Turing Machines together gave
Turing an idea
– Can a universal machine be created that can ‘simulate’ other machines?
– This machine is known as a Universal Turing Machine
• This machine would have three bits of information for the machine it
is simulating
– A basic description of the machine
– The contents of the machine’s tape
– The internal state of the machine
27
Theory of Computation: Turing Machines
Universal Turing Machine
• The universal machine would simulate the machine in question by
looking at the input on the tape
– And the state of the machine
• It would then control the machine
by changing its state based off
the input
• This leads to the idea of a “computer running other computers”
28
Theory of Computation: Turing Machines
Universal Turing Machine
• This concept of computers running other computers actually gave
John von Neumann the idea of the stored program
• And even gave way to the idea of interpreters
– As they are programs that run other programs
• Without this idea of a Universal Turing Machine, modern computers
wouldn’t be a thing
– Or they would be drastically different
29
Theory of Computation: Turing Machines
Download