Turing Machines
(チューリング機械)
12th lecture, July 5, 2019
Language Theory and Compilers
http://www.sw.it.aoyama.ac.jp/2019/Compiler/lecture12.html
Martin J. Dürst
© 2005-19 Martin
J. Dürst 青山学院大学
Today's Schedule
- Summary of last lecture
- Example solution for
bison
homework
- Remaining schedule, final exam
- 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 the error
token
- The output of a parser includes the symbol table and an
abstract parse tree as intermediate representations
- Semantic analysis is mainly concerned with type
checking and type inference
Example Solution for bison
Homework
(paper only)
Remaining Schedule
- July 5: Turing machines
- July 12: Code generation
- July 19: Optimization
- July 26: Executing environment: virtual machines, garbage
collection,...
- August 2:, 11:10-12:35: Term final exam
Final Exam
- Past problems and example solutions (85'): 2018, 2017, 2016, 2015, 2014, 2013 (60'), 2012, 2011 (45'), 2010, 2009, 2008, 2007, 2006, 2005
- How to view example solutions:
- Use buttons in upper left corner (blue area)
- Use 's' and 'p' keys
- Solutions are only examples; other solutions may be possible; sometimes,
solutions are missing
- Best way to use:
- Simulate actual exam: Solve a full set of problems in 85'
- Check solutions
- Find weak areas and review content
- Repeat
- Concentrate on understanding, not rote learning
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: State Transition Table
Current state |
Current tape symbol |
New tape symbol |
Movement direction |
Shortcut |
Next state |
→1 |
0 |
1 |
R |
0/1;R |
2 |
→1 |
1 |
0 |
L |
1/0;L |
1 |
→1 |
_ |
1 |
R |
_/1;R |
2 |
2 |
0 |
0 |
R |
0/0;R |
2 |
2 |
1 |
1 |
R |
1/1;R |
2 |
2 |
_ |
_ |
L |
_/_;L |
3* |
Explanations for Example
- Function: Adding 1 to a binary number
- Tape symbols: 0, 1 (+blank)
- Three states:
- Add/carry
- Move back to right
- Accept
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)
Using Turing Machines for Input Recognition
- Finite state automata and pushdown automata recognize input which is
separate from overall machine state
- Turing machines can be used for input recognition
- Input is written in a particular area of the tape
- Input symbols and other symbols on the tape are not necessarily
separate
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 (and many more) 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
Wolfram's 2,3 Turing Machine
- Turing machine with 2 states and 3 symbols
- Powerful (complicated) enough to simulate an Universal Turing Machine
Current state |
Current tape symbol |
New tape symbol |
Movement direction |
Shortcut |
Next state |
→1 |
a |
b |
L |
a/b;L |
1 |
→1 |
b |
a |
L |
b/a;L |
1 |
→1 |
_ |
b |
R |
_/b;R |
2 |
2 |
b |
a |
R |
b/a;R |
2 |
2 |
a |
_ |
R |
a/_;R |
1 |
2 |
_ |
a |
L |
_/a;L |
1 |
See proof of
universality and other details
Computability is Everywhere
It turns out that there are many other mechanisms that can simulate an
(universal) Turing machine:
- Wolfram's 2,3 Turing machine
- Lambda calculus (everything is a function; invented by Alonzo Church)
- Partial recursive functions
- SKI Combinator Calculus
- ι (iota) Calculus
- (Cyclic) tag systems
- Conway's game of life
- Wolfram's Rule 110 cellular automaton
All these mechanisms can simulate each other, and have the same power.
All these mechanisms are very simple, but simulation is very slow.
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.
Turing Completeness
- A mechanism (or programming language,...) is called Turing
complete if it can be shown to have computing power equivalent to a
Turing machine
- Any serious programming language is Turing complete
- Future programming languages will not be substantially more powerful that
current ones
- But future programming languages may be more convenient and/or faster
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 11, 2019 (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 (this
Turing machine always starts on the rightmost non-blank symbol):
Current state |
Current tape symbol |
New tape symbol |
Movement direction |
Next state |
→1 |
0 |
1 |
L |
1 |
→1 |
1 |
0 |
R |
2 |
→1 |
_ |
_ |
L |
3* |
2 |
0 |
0 |
R |
2 |
2 |
1 |
1 |
R |
2 |
2 |
_ |
_ |
L |
3* |
- Draw the state transition diagram for this machine
- Show in detail how this machine processes the input ..._1101000_...
- Explain what kind of calculation this machine does if the tape contains
only a single contiguous sequence of '0'es and '1'es (surrounded by
blanks), and the leftmost non-blank symbol is a '1'
Glossary
- rote learning
- 暗記
- commonalities
- 共通点
- nondeterminism
- 非決定性
- universal turing machine
- 万能チューリング機械
- mechanism
- 機構、仕組み
- lambda calculus
- ラムダ計算
- partial recursive function
- 部分再帰関数
- unary numbers
- 一進法 (1, 11, 111, 1111,...)
- Entscheidungsproblem
- ヒルベルトの決定問題
- Turing complete(ness)
- チューリング完全 (性)
- computable number
- 計算可能数
- halting problem
- 停止性問題