updated: 2022-01-23_12:32:30-05:00
updated: 2021-11-19_09:55:40-05:00
Turing Machine
Simple model of computation
A turing recognizable language is recognized by some turing machine
- recognizable only if it ends in accept state
A turing decidable language is decided by some turing machine
- has to go to accept/reject state, should not loop
- if a language loops, it is not decidable
Definition
A turing machine is a 7-tuple (Q, $\Sigma$, $\rho$,$\delta$, q0, qA, qR)
where Q, $\Sigma$, $\rho$ are finite sets and
- Q is the set of states
- $\Sigma$ is the input alphabet not including blank symbol _
- $\delta$ is the tape symbol where _ $\in$ $\rho$ and $\Sigma \subseteq \rho$
- .... Just gonna take a pic
- .
- .
- .
As a TM computes, changes occur in [Current state|Current Tape|Head location]
Configuration of a TM:
(q,u,i) where
q $\in$ Q
u is a semi-infinite string over $\rho$
i $\in$ Z+ head location starts at 1
Initial Configuration:
(q0,w_, 1)
Accepting Configuration:
(q_accept, ... , ...)
Reject:
(q_reject, ... , ...)
[Turing Machine|Stats|
[<table> S| . |. ||. |. ]
]
[Turing Machine]->[Memory|0|1|...]
Input is stored in an unbounded memory
You can change what's in memory, move left or right
write what you can't remember
DFA $\delta$ (q1,0) = q2
TM $\delta$(q1,0)=(q2,1,L|R) {1 is the symbol, L|R is direction }
if no transition on dfa, go to failure state (reject state)
For a Turing machine, it has to either have transition or be in accept/reject state
Halting states:
{q${accept}$,q${reject}$}
Is there any guarantee that on a given input the TM will enter either qaccept or qreject? No!
This will become the Halting Problem
Eg: Strings of length >=2 and start and end with same symbol
$\Sigma$ = {0,1}
Input:
01101100
Infinite memory, so we need to know end of input (tape symbol)
0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | _ |
---|---|---|---|---|---|---|---|---|
^ |
reject = false;
while(!reject)
if first symbol in tape is _ , reject=true;
else move right, remember first symbol
if symbol is _ reject
else ? something something, once you see one, move left
State diagram
we are at a
a->b,D
a is input reading
changing b to a, move D
[<hidden>Blank]-> [q0]
[q0]->0->R[q1]
[q0]->_[q_reject]
[q1]->_[q_reject]
[q1]->0,1->R[q2]
[q2]->0,1->R[q2]
[q2]->_->L[q3]
[q3]->0[q_accept]
[q0]->1->1,R[q4]
[q4]->_[q_reject]
[q4]->0,1->R[q5]
[q5]->0,1->R[q5]
[q5]->_->L[q6]
[q6]->1[q_accept]
[q3]->1[q_reject]
[q6]->0[q_reject]
An Algorithm is a turing machine that always halts
[TM|[CFL|[RL]]]
Example: a^n b^n c^n
Not CFL, but is TM
aaabbbccc_
replace
Steps:
- Add input to tape
- add _ to end of input
- first symbol _ -> Reject
- first symbol b or c -> Reject
- first symbol a, change to x and move right
- keep moving right until you see a b
- if you see a b, change it to a y
- keep moving right until you see a c
- if you see a c change it to a z
- keep moving left until you see an x
- move right & repeat back to
- ^^here
- check if all a's are marked, b's are marked, c's are marked
- accept or reject
Example: L = {0^2^n | n >= 0}
0's where length is power of 2
mark first element as blank.
add blank at end
mark every other 0 until blank
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | _ |
---|---|---|---|---|---|---|---|---|
_ | x | 0 | x | 0 | x | 0 | x | _ |
_ | x | x | x | 0 | x | x | x | _ |
_ | x | x | x | x | x | x | x | _ |
Example L = {w # w| w in 0,1}
Multitape Turing Machine
3 Tape
Theorem: Every Multitape TM has an equivalent single tape TM
- Need to store all tapes input into a single tape
- Each tape has to be noted
Deliminator here is chosen to be #
# | a | a | b | _ | _ | _ | # | x | y | x | x | _ | _ | _ | # | 1 | 0 | 0 | 1 | 0 | _ | _ | _ | # |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
^ | ^ | ^ |
we could keep track of various heads with underline
to make more space, move all characters right of #
transition
by1 -> ax0, RLR
2 Stack
- Put data into two stacks
- What does the transititon mean (L,R)
- Keep track of head position
Top of stack 2 is current head
Left...
- replace ai+1 with whatever transition says
Queue
- Pop from front, push to back
Pop is bottom most element, push to end
Nondeterministic FA as a turing machine
L = {0$^{k}$| k is a composite number (non prime)}
- pick 2 numbers n1 and n2 such that 2 < n1 ... n2 ... < k
- write n1 number of 0's and n2 number of 1's to TM tape
- check if n1 * n2 = k; if yes accept; else reject
How do we do multiplication on a Turing Machine?
at some point we have n1 = 3 and n2 = 5
k number of 0s ; # ; n1 (000) # n2 (11111) #
mark first 0 as b;
copy
Nondeterminism comes from picking n1 and n2