Turing Machines
(チューリング機械)
12rd lecture, June 23, 2017
Language Theory and Compilers
http://www.sw.it.aoyama.ac.jp/2017/Compiler/lecture12.html
Martin J. Dürst
© 2005-17 Martin
J. Dürst 青山学院大学
Today's Schedule
- Summary of last lecture
- Example solution for
bison
homework
- Turing Machines
- How a Turing Machine works
- Universal Turing Machine
- Computability is everywhere
Summary of Previous Lecture
- Error processing in a parser has many requirements and difficulties
- In
bison
, errors can be caught with an error
token
- The output of a parser includes the symbol table and an abstract parse
tree as intermediate representations
- Semantic analysis is mostly concerned with type checking and type
inference
Example Solution for bison
Homework
(paper only)
Formal Language Hierarchy
(Chomsky hierarchy)
Grammar |
Type |
Language (family) |
Automaton |
phrase structure grammar (psg) |
0 |
phrase structure language |
Turing machine |
context-sensitive grammar (csg) |
1 |
context-sensitive language |
linear bounded automaton |
context-free grammar (cfg) |
2 |
context-free language |
pushdown automaton |
regular grammar (rg) |
3 |
regular language |
finite state automaton |
Historic Background
Automata Commonalities
- (finite set of) states
- (finite set of) transitions between states
- Start state
- Accepting state(s)
- Deterministic or nondeterministic
Automata Differences
- Finite state automaton: No memory
- Pushdown automaton: Memory stack
- (Linear bounded automaton: Finite-length tape)
- Turing machine: Infinite length tape
(can be simulated with two stacks)
How a Turing Machine Works
- 'Infinite' tape with symbols
- Special 'blank' symbol (␣ or _),
used outside actual work area
- Start at first non-blank symbol from the right
(or some other convenient position)
- Read/write head:
- Reads a tape symbol from present position
- Decides on symbol to write and next state
- Writes symbol at present position
- Moves to the right (R) or to the left (L)
- Changes to new state
- Start state and accept state(s)
Turing Machine Example
- Adding 1 to a binary number
- Tape symbols: 0, 1 (+blank)
- Three states:
- Add/carry
- No carry
- Accept
State Transition Table for Example
Current state |
Current tape symbol |
New tape symbol |
Movement direction |
Next state |
→1 |
0 |
1 |
L |
2 |
→1 |
1 |
0 |
L |
1 |
→1 |
_ |
_ |
R |
3* |
2 |
0 |
0 |
L |
2 |
2 |
1 |
1 |
L |
2 |
2 |
_ |
_ |
R |
3* |
Turing Machine Definition
6-tuple:
- Finite, non-empty set of states Q
- Finite, non-empty set of tape symbols Σ
- Transition function
- Blank symbol (∈Σ)
- Initial state (∈Q)
- Set of final states (⊂Q)
Techniques and Tricks for Programming
- Interleave data fields and control fields
- Use special symbols as markers
- Use special states to move across tape to different locations
- Build up functionality from primitives (e.g. plus 1 → addition →
multiplication → exponentiation)
Extensions
- Nondeterminism
- Parallel tapes
- 2-dimensional tape
- Subroutines
It can be shown that all these extensions can be simulated on a plain Turing
machine
Universal Turing Machine
- It is possible to design a Turing machine that can simulate any Turing
machine (even itself)
- Encode states (e.g. as binary or unary numbers)
- Encode tape symbols (e.g. as binary or unary numbers)
- Create different sections on tape for:
- Data (encoded tape symbols)
- State transition table (program)
- Internal state
- Main problems:
- Construction is tedious
- Execution is very slow
Computability is Everywhere
It turns out that there are many other mechanisms that can simulate an
(universal) Turing machine:
- Lambda calculus (everything is a function)
- Partial recursive functions
- SKI Combinator Calculus
- ι (iota) Calculus
- (Cyclic) tag systems
- Conway's game of life
- Wolfram's Rule 110 cellular automaton
- Wolfram's 2,3 Turing machine
(Turing machine with only 2 states and three symbols)
All these mechanisms can simulate each other and have the same power.
A mechanism (or programming language,...) is called Turing-complete if it
can be shown to have computing power equivalent to a Turing machine
Church-Turing Thesis
- Anything (any function on natural numbers) that can be calculated can be
calculated by a Turing machine
- Anything that cannot be calculated by a Turing machine cannot be
calculated
It is unclear whether this applies to Physics in general.
Other Contributions
- Von Neumann style architecture: Current computer architecture closely
follows Turing machine
(main difference: Random Acccess Memory)
- Entscheidungsproblem: There are some Mathematical facts that cannot be
proven
- Computable numbers: There are real numbers that cannot be computed
- Halting problem: There is no general way to decide whether a program will
terminate (halt) or not
Bibliography
- The Annotated Turing, Charles Petzold, Wiley, 2008
- Understanding Computation, Tom Stuart, O'Reilly, 2013 (also available in
Japanese)
- A New Kind of Science, Stephen Wolfram, Wolfram Media, 2002
- To Mock a Mockingbird, Raymond M. Smullyan, Oxford University Press,
2000
Homework
Deadline: July 6, 2017 (Thursday), 19:00
Where to submit: Box in front of room O-529 (building O, 5th floor)
Format: A4 single page (using both sides is okay; NO cover page, staple in
top left corner if more than one page is necessary), easily readable
handwriting (NO printouts), name (kanji and kana) and student number at the top
right
For the Turing machine given by the following state transition table:
Current state |
Current tape symbol |
New tape symbol |
Movement direction |
Next state |
→1 |
0 |
1 |
L |
1 |
→1 |
1 |
0 |
L |
2 |
→1 |
_ |
_ |
L |
4* |
2 |
0 |
0 |
L |
2 |
2 |
1 |
1 |
L |
2 |
2 |
_ |
_ |
R |
3 |
3 |
0 |
_ |
R |
3 |
3 |
1 |
1 |
L |
4* |
- Draw the state transition diagram for this machine
- Show in detail how this machine processes the input ..._1100100_...
- Guess and explain what kind of calculation this machine does if the tape
contains only a single contiguous sequence of '0'es and '1'es with at least
one '1'(surrounded by blanks)
(this Turing machine always starts on the rightmost non-blank symbol)
Glossary
- commonalities
- 共通点
- nondeterminism
- 非決定性
- universal turing machine
- 万能チューリング機器