07 Turing Machine
Cromsky Hierarchy¶
Turing Machine¶
NFA + Read/Write Capability
- Read/write happens from/to an ‘infinite tape’
- Read-write head can move left and right
-
Initially, all cells of the tape have special blank symbol , except where the input string exists
-
FSMs always halt after steps, where is the length of the input. At that point, they either accept or reject.
- PDAs don't always halt, but there is an algorithm to convert any PDA into one that does halt.
- Turing machines can do one of the following
- Halt and accept
- Halt and reject
- Not halt If a turing machine loops forever algorithm to solve the problem
Symbol | Meaning |
---|---|
Finite set of states | |
Finite set of input alphabet | |
Finite set of tape alphabet, such that | |
Start state | |
Accepting state | |
Rejecting state | |
\(\delta\) | Transition function \(Q \times \Gamma \to Q \times \Gamma \times \text{\{L, R\}}\) |
Transition in Expression form¶
represents a transition with
- Current state
- is current tape input character
- New state
- is new tape input character
- is the direction that read-write head moves
Transition in Diagram Form¶
<tape_input>/<tape_write>, <direction>
Uses¶
- Language decider/recognizer
- Yes/No output
- Halts for correct input
- May not halt for wrong inputs
- Compute functions
- Reverse string
- Computing systems
Hailstone Sequence¶
For example, for a starting number of 7, the sequence is 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, .... Such sequences are called hailstone sequences because the values typically rise and fall, somewhat analogously to a hailstone inside a cloud.
Suppose we have
(Code not required to be studied)
#include <stdio.h>
int main()
{
unsigned int n;
printf("Pl. enter no :");
scanf("%d", &n);
while ( n > 0 )
{
printf( "%d ", n);
if (n == 1)
break;
if (!(n & 1))
n /= 2;
else
n = 3*n + 1;
}
printf("Done \n");
return 0;
}
Is there any n for which the program does not terminate, ie does not converge to 1? It is inconclusive, as we do not know.
Hence, the turing machine may not halt for this problem.
Questions¶
\(0^n 1^n, n \ge 1\)¶
\(w w\)¶
Kinda complicated
\(w w^r\)¶
Kinda complicated
Balanced Parantheses¶
We first look for closing bracket; The opening bracket for a given closed bracket is always the first one on its left; converse statement is not true.
\(w\#w: 011\#011\)¶
Add \(b\) to match \(a\), such that \(a^n b^n\)¶
Convert \(w \to w w^r\)¶
Pretty complicated
Multiplication¶
Pretty complicated