Lecture 5 - Turing Machine¶
Turing Machine¶
A Turing machine is a mathematical model of computation that defines an abstract machine. It was invented by Alan Turing in 1936. A Turing machine can simulate the logic of any computer algorithm, and is therefore the theoretical foundation of all modern computers.
A Turing machine is a 5-tuple
is a finite set of states. is a finite set of symbols.- s
is the start state. is the halt state. is the transition function, which maps to .
The transition function
for some . , then . -- Do something.
leftend
blank symbol
configuration¶
A configuration of a Turing machine is a member of
is the last symbol that is not- {e} represents the following all symbols are
.
We say
-
writing :
and and . -
moving left :
and and .
M halts if it reaches a halting configuration
Acceptance and Rejection¶
A Turing machine M accepts a string w if
A Turing machine M rejects a string w if
Given a Turing machine M, we can define the language accepted by M as
- M seme-decides L
- But M does not decide L
- Adding a condition: If M halts on all inputs, then M decides L.
M decides a language
M semi-decides a language
Reccursive Language¶
A language
Every recursive language is recursively enumerable.
- Explanation: A language
is recursively enumerable if there exists a Turing machine that semi-decides .
Multi-tape Turing Machine¶
A multi-tape Turing machine is a Turing machine with multiple tapes. Each tape has its own head and can move independently.
Two-way Infinite Tape¶
Multi-head Turing Machine¶
A multi-head Turing machine is a Turing machine with multiple heads on a single tape.
2D-Tape Turing Machine¶
- Simulate a 2D-Tape Turing machine with a 1D-Tape Turing machine.
Random Access Turing Machine¶
- A Turing machine which can move to any position on the tape in a single step.
Example¶
can be decided by a Turing machine.
Turing Machine Construction¶
Here is a high-level description of a Turing machine that can decide
-
Check if the string consists of only
's, 's, and 's: - The TM scans the input tape to ensure that it only contains 's, 's, and 's in that order. If any other character is found, the machine rejects the string. -
Match
's, 's, and 's: - Start by marking the leftmost and replace it with a special symbol (say ). - Then, scan the tape to find the leftmost . If one is found, mark it with a different special symbol (say ). - Next, scan to find the leftmost , and mark it with another symbol (say ). - Now, go back to the left end of the tape and repeat the process, continuing to match one , one , and one at a time, until either:- All
's, 's, and 's are matched, or - A mismatch is found (i.e., a character cannot be found when needed).
- All
-
Verify the end condition: - Once all the symbols have been marked, check the tape:
- If all symbols are marked and the tape only contains
's, 's, and 's, then the string is in the language . - If there are any unmarked
's, 's, or 's remaining, or if the order of 's, 's, and 's is incorrect, the string is rejected.
- If all symbols are marked and the tape only contains
-
Empty string check: - The empty string
is trivially in , as it satisfies the condition where .
Non-deterministic Turing Machine (NTM)¶
- Deterministic TM: At each step, there is one possible next state, symbols to be written and direction to move the head, or the TM may halt.
- Nondeterministic TM: At each step, there are finitely many possibilities.
- So formally,
, where are the same as in a deterministic TM.
Decides¶
- If there is a computation path that leads to
, then accepts . - If every computation path leads to
, then rejects .
M decides a language
- Fir all
, there is a integer , depending on and such that every branch halts in at most N steps. - If
, then there exists a branch that halts in an accepting state. - If
, then every branch halts in a rejecting state.
Semi-decides¶
M semi-decides a language
- If
, then there exists a branch that halts in an accepting state. - If
, then no branch halts in a accepting state. -- No branch accepts .
Example¶
Let
Theorem¶
Theorem 1¶
Every NTM can be simulated by a DTM.
A NTM semi-decides a language
if and only if there exists a DTM that semi-decides .
-
A NTM semi-decides a language
There exists a DTM that semi-decides . -
Use a three-tape DTM to simulate a NTM.
Church-Turing Thesis¶
- Every algorithm can be simulated by a Turing machine.
- Intuition of Algorithm is equivalent to Turing machine.
Description of a Turing Machine¶
A Turing machine can be described by high-level pseudocode.
Fact¶
- Any Finite Set can be encoded.
- Any Finite Tuple whose elemnets are finite stes can be encoded.
Example¶
is a graph. is a finite set of vertices and is a finite set of edges.
M on input
- If the input is illegal (not a graph), reject.
- select a node of G and mark it.
- repeat the following until no new nodes are marked: * For each marked node, mark all its neighbors.
- If all nodes are marked, accept; otherwise, reject.
Exercise¶
¶
Input:
Output: Accept if
Solution:Construct a Turing machine that simulates the DFA
on input .
- run D on input
. - If D accepts
, accept; otherwise, reject.
¶
Input:
Output: Accept if
Solution: Construct a Turing machine that simulates the NFA
on input .
- Convert NFA
to a DFA . - run
on input . - If
accepts, accept; otherwise, reject.
This involves the process of reduction.
¶
Input:
Output: Accept if
Solution: Construct a Turing machine that simulates the NFA
on input .
- A REX can be converted to a NFA.
- Use
to simulate the NFA.
- Convert REX
to a NFA . - run
on input . - If
accepts, accept; otherwise, reject.
¶
Input:
Output: Accept if
Solution: Construct a Turing machine that simulates the DFA
on input .
- Run DFS on the state diagram of
. - If there is a path from the start state to an accepting state, reject; otherwise, accept.
¶
Input:
Output: Accept if
Solution: Construct a Turing machine that simulates the DFA
on input .
- Symmetric difference --
- Convert the problem to whether the symmetric difference is empty.
- Construct a DFA
that recognizes the symmetric difference of and . - Run
on input .
¶
Input:
Output: Accept if
Chonsky Normal Form¶
A CFG
B and C are non-terminal symbols. BC .
So if final
¶
Input:
Output: Accept if
¶
Input:
Output: Accept if
¶
Input:
Output: Accept if
创建日期: 2024年10月16日 00:17:47