Turing Machines as Transducers 1 Turing-computable Functions • • • • Function f with domain D is computable if There exists TM M= (Q, D, , , q0, B, F) Such that for all w D q0w ├* qff(w) for some qf F 2 Create TMs for the following • f(w) = cwc (w {0,1}*) • Input a string w {0,1,c}* – If w = ca1a2a3…anc (ai {0,1}) then accept with output a1a2…an/2ccan/2+1…an – Otherwise, reject the input string. • Input a string w {0,1,c}* – If w =a1a2…anccb1b2…bm (ai,bi {0,1}) then accept with output a1a2…ancb1b2…bm – Otherwise, reject the input string. • {ww | w {0,1}*} 3 f1(w) = cwc (w {0,1}*) 0/0,⇾ 1/1,⇾ q10 0/0,⇽ 1/1, ⇽ B/c,⇽ q11 B/c,⇽ q12 B/B,⇾ q1f 4 f2(ca1a2a3…anc) = a1a2…an/2ccan/2+1…an c/c,⇾ q220 c/0,⇾ 0/0,⇾ 1/1,⇾ 0/c,⇾ 0/c,⇽ q2 c/c,⇾ q2 0 1 q23 c/0,⇽ q24 q26 1/c,⇽ c/0,⇾ c/c,⇽ 0/0,⇽ 1/1,⇽ c/c,⇽ q250 1/c,⇾ 0/0,⇽ 1/1,⇽ c/c,⇽ q27 c/0,⇽ q251 q2 21 q28 B/B,⇾ 2 qf 5 f3(a1a2…anccb1b2…bm) =a1a2…ancb1b2…bm 0/0,⇾ 0/B,⇾ q3 q310 c/0,⇾ 1/0,⇾ q32 0 1/B, ⇾ 0/0,⇾ 1/1,⇾ c/c,⇾ q33 B/B,⇽ 0/0,⇽ 1/1, ⇽ c/c, ⇽ q33 B/B,⇾ q3f 0/1,⇾ q3 c/1,⇾ 11 1/1,⇾ 6 Create TMs for the following • f(w) = cwc (w {0,1}*) • Input a string w {0,1,c}* – If w = ca1a2a3…anc (ai {0,1}) then accept with output a1a2…an/2ccan/2+1…an – Otherwise, reject the input string. • Input a string w {0,1,c}* – If w =a1a2…anccb1b2…bm (ai,bi {0,1}) then accept with output a1a2…ancb1b2…bm – Otherwise, reject the input string. • {ww | w {0,1}*} 7 Programming Techniques Programming Techniques for TMs • Storage in the State • Multiple Tracks on the Tape • Subroutines Example - L = { wcw | w {0,1}* } Repeat Sweep right past all marked 0s and 1s Mark next 0 or 1 and store in Sweep right passed the ‘c’ (reject if no ‘c’ found) Sweep right past all marked 0s and 1s Mark next 0 or 1 check that it equals (reject if not) Sweep left to beginning of input Until no unmarked 0s and 1s to the left of ‘c’ Reject if there are unmarked 0s and 1s to the right of ‘c’ Remembering symbols seen • • • • Finite amount of data stored in state A different state for each possible value Storage in state TM states contain: – Position in program – Finite amount of stored data In Example • States need to remember: – Symbol to match – Whether ‘c’ has been seen or not Marking Symbols • Can replace value with special marker. • Sometimes need to read value several times • Split tape into multiple ‘tracks’ Example – input 010c010 Initial Configuration: After first iteration: After second iteration: ... ... B 0 1 0 c 0 1 0 B ... B B B B B B B B B ... ... ... B 0 1 0 c 0 1 0 B ... B B B B B B B ... ... ... B 0 1 0 c 0 1 0 B ... B B B B B ... TM only has 1 track tape • Simulate multi-track tape using one track • Add symbols to the tape alphabet – Equate B with – Equate 0 with – Equate 1 with – Equate c with – Add 1 and 0 B B 0 B 1 B c B Example – input 010c010 Initial Configuration: ... B 0 1 0 c 0 1 0 B ... After first iteration: ... B ... B After second iteration: 0 1 0 c 0 1 0 c 0 1 0 B ... 0 1 0 B ... Subroutines • Break problem into small pieces • Create ‘subroutine’ to solve sub-problem – Uses subset of states of entire TM (QS Q) – Has a unique entry state (r0) – States in QS only reachable through r0 – Well defined exit states – Has a well-defined function Example 2 • Input: integers i, j and k • Output: yes, if i = j k