(チューリング機械)

http://www.sw.it.aoyama.ac.jp/2018/Compiler/lecture12.html

© 2005-18 Martin J. Dürst 青山学院大学

- Summary of last lecture
- Example solution for
`bison`

homework - Turing Machines
- How a Turing Machine works
- Universal Turing Machine
- Computability is everywhere

- 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 mostly concerned with type checking and type inference

Please ask questions now!

Additional hint:

Order is important when making `YYSTYPE`

a `struct`

that can represent dates, numbers of days, and integers:

`typedef`

...`#define YYSTYPE`

...`#include "calc.tab.h"`

- July 6: Turing machines
- July 13: Code generation
- July 20: Optimization
- July 24 (
**Friday lectures on Tuesday**): Executing environment: virtual machines, garbage collection,... - July 27, 11:10-12:35: Term final exam

- Past problems and example solutions (85'): 2017, 2016, 2015, 2014, 2013 (60'), 2012, 2011 (45'), 2010, 2009, 2008, 2007, 2006, 2005
- How to view example solutions (recent exams):
- Use buttons in upper left corner (blue area)
- Use '
**s**' and '**p**' keys

- How to view example solutions (older exams):
- 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

(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 |

- 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 test: test whether a machine can 'think', 1950
- Turing Prize: Most famous prize in Computer Science

- (finite set of) states
- (finite set of) transitions between states
- Start state
- Accepting state(s)
- Deterministic or nondeterministic

- 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)

- '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)

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* |

- Function: Adding 1 to a binary number
- Tape symbols: 0, 1 (+blank)
- Three states:
- Add/carry
- Move back to right
- Accept

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`)

- 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)

- Nondeterminism
- Parallel tapes
- 2-dimensional tape
- Subroutines

It can be shown that all these extensions can be simulated on a plain 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

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.

All these mechanisms are very simple, but simulation is very slow.

- 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.

- A mechanism (or programming language,...) is called Turing complete if it can be shown to have computing power equivalent to a Turing machine
- Future programming languages will not be substantially more powerful that
current ones,

but they may be more convenient and/or faster

- 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

- 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

Deadline: July 16, 2017 (**Monday**), 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 | 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_...
- 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 (surrounded by blanks) and where the leftmost non-blank symbol is a '1'

(this Turing machine always starts on the rightmost non-blank symbol)

- commonalities
- 共通点
- nondeterminism
- 非決定性
- universal turing machine
- 万能チューリング機器
- mechanism
- 機構、仕組み
- lambda calculus
- ラムダ計算
- partial recursive function
- 部分再帰関数
- unary numbers
- 一進法 (1, 11, 111, 1111,...)
- Entscheidungsproblem
- ヒルベルトの決定問題
- Turing complete(ness)
- チューリング完全 (性)
- halting problem
- 停止性問題