言語理論とコンパイラ
第十二回: Turing Machine
2015 年 6 月 26 日
http://www.sw.it.aoyama.ac.jp/2014/Compiler/lecture12.html
Martin J. Dürst

© 2005-15 Martin
J. Dürst 青山学院大学
今日の予定
  - 前回のまとめ
- bison の宿題の正解例
- Turing Machine
前回のまとめ
  - 演算子の優先度と結合規則が文法の書き換え規則の形で決定
- 文法の書き換え規則ではパターンに注意
- 構文解析のエラー処理では要点が多く、対応が困難
- bisonでは- errorトークンを含む規則でエラーに対応可能
 
bison の宿題の正解例
(紙にて配布)
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
  - Alan Turing, British Mathematician, 1912-1954
- "On computable numbers, with an application to the Entscheidungsproblem"
    published in 1936
- Turing worked on en/decription during World War II
- Turing Prize: Most famous prize in Computer Science
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: 
    
      - Adding/carry
- Move to left
- 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)
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
Extensions
  - Nondeterminism (非決定性)
- Parallel tapes (平行なテープ)
- 2-dimensional tape (2次元テープ)
- Subroutines
It can be shown that all these extensions can be simulated on a plain
Touring 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)
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 rationalreal 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
 
宿題
提出: 来週の木曜日 (7 月 2日) 19 時 00 分、O 棟 529
号室の前
あるチューリング機器の遷移表:
  
  
  
  
  
  
    
      | 現状態 | 現記号 | 新記号 | 移動方向 | 新状態 | 
    
      | →1 | 0 | 1 | L | 2 | 
    
      | →1 | 1 | 0 | L | 3 | 
    
      | →1 | _ | _ | L | 4* | 
    
      | 2 | 0 | 1 | L | 2 | 
    
      | 2 | 1 | 0 | L | 3 | 
    
      | 3 | 0 | 0 | L | 3 | 
    
      | 3 | 1 | 1 | L | 3 | 
    
      | 3 | _ | _ | R | 5 | 
    
      | 5 | 0 | _ | R | 5 | 
    
      | 5 | 1 | 1 | L | 4* | 
  
  - この機器の遷移表を書きなさい
- この機器の ..._1100100_... に対する動作を示しなさい
- テープの記号が 0, 1, _
    のみでスタートする場合、どのような計算をするのか推測し、説明しなさい