Inf2A: Turing Machines and Linear Bounded Automata Lecture 26 Stuart Anderson
Turing Machines Read/write head each tape cell contains a symbol from a finite alphabet Tape: unbounded in both directions Finite-state control Transitions determined by state and symbol being read, transitions labelled with symbol read, symbol written and direction of head movement
Turing Machines Unbounded state model: the tape has an unbounded number of cells each filled with a symbol drawn from some finite alphabet. The head reads the next input symbol, the head can move left one cell, right one cell, or remain stationary on each transition of the finite state control. The finite state control governs the manipulation of the tape. Final states in the control have no transitions leaving them one we enter a final state the machine has halted. p (a,b,d) q If we are in state p and the tape head is reading a, write b in the tape cell and move in direction d, d can be L(eft), R(ight) or meaning don t move
Languages Type 3: regular languages, recognised by FSMs Type 2: context-free languages, recognised by DPAs Type 1: context-sensitive languages, recognised by Linear-bounded automata (see later) Type 0: unrestricted L(M) the language recognised by M is those strings such that if we write them one symbol at a time into adjacent tape cells and start M with the tape head at the leftmost end of the string then eventually M reaches a final state. Tape cells that have never been used before are filled with a special symbol b representing a blank cell.
Recursive Enumerability Another name for Type 0 languages is the recursively enumerable languages. If M is a TM that recognises some language L there are three possibilities for what might happen if we run M on some string α: 1. M will halt in an accepting state so α is in L. 2. M will halt in some non accepting state and so α is not in L. 3. M will loop forever and so α is not a member of L but we have to wait an infinite amount of time to know it isn t So if a string a is not in L it may never be rejected explicitly by M.
Recursive Languages An important subclass of the Type 0 language is the recursive languages. A language L is recursive if there is a TM M which for any string α either halts accepting α or halts rejecting α. One interesting question is whether there are languages that are recursively enumerable but are not recursive (see later).
Recursively Enumerable Languages Any recursively enumerable language L whose complement ~L is also recursively enumerable is a recursive language. To see this: we know we have two machines M that accepts L and ~M that recognises ~L run M and ~M concurrently one or other of M and ~M will halt accepting eventually so we have a way of deciding whether or not a string is in the language. So, if there is a recursively enumerable language L that is not recursive, then the language ~L is not recursively enumerable and so there is no Turing machine that recognises ~L.
Example Consider the following two machines, M inc and M dec both of which use the alphabet {0,1,#}. M inc given a sequence of 1s and 0s with a # at the right-hand end adds one to the sequence of 1s and 0s if we read it as a binary number M dec given a sequence of 1s and 0s with a # at the right-hand end subtracts one from the sequence of 1s and 0s if we read it as a binary number. Once we have these two machines we can compose them to build an adder.
Example Final states are red. 5 (1,1,R) (0,0,R) 1 2 (#,#,L) (1,0,L) (0,1,R) (b,1,r) (1,1,R) (0,0,R) 1 (#,#,L) 2 (#,#,R) (0,1,L) (1,0,R) 4 (#,#,-) 3 M inc (0,0,R) (1,1,R) 4 (#,#,-) 3 M dec (0,0,R) (1,1,R)
Example: Composing Machines M dec 5 Input is n#m# with (0,0,L) The head initially anywhere (#,#,R) 4 (1,1,L) in the binary number m (#,#,-) The machine computes n+m M inc 4
More formally A Turing Machine M = (Q,Σ,Γ,δ,q 0,b,F) is a 7-tuple, where: Q is the stateset of the finite-state controller Σ is the finite input alphabet Γ is the finite tape alphabet Σ is a subset of Γ δ: is the transition function, mapping from state,tapealphabet pairs to state, tape alphabet, direction triples q 0 is the intitial state of the system b is the blank tape symbol that fills tape cells that have never been written by the machine F is the collection of final states
Definitions Continued For M, a configuration is a triple: (a 1 a m,q,a m+1 a n ) where the whole tape is a 1... a n, q is the current state and a m+1 is the currently read symbol. An initial configuration with input t is: (ε,q 0,t) We can define a computation relation for M in the following way: if δ(q,a) = (q,a,r) and a=a m+1 then we have (a 1 a m,q,a m+1 a n ) = (a 1 a m,a,q, a m+2 a n ), similarly for different directions of head movement, if we reach the end of either of the strings we extend them by adding b characters to the string (so configurations are always finite but may grow in an unbounded way). A string t is accepted by M iff (ε,q 0,t) = * (t,q,t ) where q is a final state of M. The language of M, L(M) is just {t t is accepted by M}
Context Sensitive Languages Type 1 languages in the Chomsky Hierarchy are also called Context-Sensitive languages. All productions in Context sensitive languages have the form α -> β where α β The acceptor corresponding to context-sensitive grammars is called a linear-bounded automaton which is a restriction of the Turing machine model. A Turing machine M is an LBA if: There is a linear function f such that for all inputs t, in accepting or rejecting t, M always uses fewer than f( t ) tape cells.
Linear-Bounded Automata What are the possibilities when we run an LBA M on some input t? Halt rejecting Halt accepting Use more space than is permitted by the linear function reject Loop in this case we know that we have a fixed amount of space we can use so that eventually the current configuration of the machine will be identical to some earlier configuration so we would loop forever and so the input is rejected. So, LBAs always either accept or reject the input. Caution: our machine could be non-deterministic
Question Closure Properties of LBAs Are LBAs closed under (don t just think about deterministic LBAs): Union? Concatenation? Intersection? Complement (tricky 1988)?
Question - Nondeterminism Is there a non-deterministic LBA M, such that for all deterministic LBAs D: L(D) L(M)?
Context-Sensitive Grammars - Recognising Given a context-sensitive grammar G with top symbol S, we know that because for each production of G, α -> β we have α β, then the lengths of the sentential forms in a derivation from S are nondecreasing. This means that if we want to decide whether some terminal string t is in L(G) then we just need to consider all derivations from S to strings of length t +1 or less. If t appears in that list then it is in L(G), otherwise it is not.
Constructing Context-Sensitive Grammars Consider the language L = {a n b m #b n c m m,n 0} How do we construct a Context-Sensitive Grammar for the language? L is not context-free (why? try the pumping lemma with string a k b k #b k c k ) We can use context-free rules to generate sentential forms with the right number of symbols in them: S -> A#C A -> aab ε C -> BCc ε In a sentential form the number of Bs to the left of the # is the same as the number of as, and right of the # the numbers of Bs and cs are equal. We use context sensitive rules to permute symbols: Bb -> bb bb -> Bb
Constructing Context-Sensitive Grammars Finally we want to get rid of remaining non-terminals using rules that make the Bs swap sides of the # (and convert them to bs so they can t swap back): B# -> #b #B -> b# Consider a derivation: S => A#C => aab#c => aaabb#c => aabb#c => aabb#bcc => aabb#bbccc => aabb#bbbcccc => aabb#bbbccc => aab#bbbbccc => aa#bbbbbccc => aa#bbbbbccc => aa#bbbbbccc => aab#bbbbccc => aab#bbbbccc => aab#bbbbccc => aabb#bbbccc => aabb#bbbccc => aabb#bbbccc => aabbb#bbccc For many context-sensitive languages, this approach to developing the production rules can be helpful.
Summary We have seen the definition of Turing Machine and Linear-Bounded Automaton. We have considered some basic results for Turing Machines, e.g. the undecidability of the Halting Problem. We have considered closure properties and issues on non-determinism for LBAs. We have seen that CSGs and LBAs are closely related but have not seen the proof of their equivalence.