Turing Machine as Transducer Turing Computation and programming Transducer -- any device that converts a signal from one form to another Turning machine Converts input to output Start with string on the tape After acceptance string left on the tape Computing functions with TMs The result of the function applied to an input string x, will be left on the tape when the machine accepts. Functions with multiple arguments can be placed on the input tape with arguments separated by some character. Turing s original use of his machine was to calculate integer valued functions. Integers were represented in unary as blocks of a single symbol. Example 111111 would represent 6 1111 would represent 4 In our text 1s are used as the unary symbol 0s are used to separate arguments Computing functions with TMs Formally, Let M = (Q, Σ, Γ, δ, q 0,, F) be a TM and let f be a partial function on Σ *. We say T computes f (or f is Turing-computable) if for every x Σ * where f is defined: q 0 x a * pf(x) Where p F And for every other x, T rejects on input x. Computing functions with TMs Formally (with multiple arguments) Let M = (Q, Σ, Γ, δ, q 0,, F) be a TM and let f be a partial function on (Σ*) k. We say T computes f (or f is Turing-computable) if for every (x 1, x 2., x k ) where f is defined: q 0 x 1 0x 2 0x k a * pf(x 1, x 2., x k ) Where p F And for every other k-tuple, T rejects on input x. 1
Example Addition x + y Create a machine that will perform the computation q 0 1 x 01 y a * p1 x 1 y Where p F Example Addition x + y q 0 1 x 01 y a * p1 x 1 y Basic idea: Simply remove the 0 between the two sets of ones. Read all 1s up to 1st 0 Replace 0 with 1 Remove last 1 Example Addition (JFLAP) Another example Copy routine Copies its input and concatenates a copy of itself on the tape q 0 1 x a * p1 x 1 x Another example copy routine Basic idea: count number of 1 s by replacing with X Go back and re-read all Xs and as you re-read each X, add a 1 to the end of the tape. Repeat until all Xs are converted back to 1s Another example copy routine 2
One more example One more example A simple if statement Create a TM that will accept in one state if a condition is true (e.g. x y) and another if the condition is false. q 0 1 x 01 y a * p1 x 01 y if x > y q 0 1 x 01 y a * r1 x 01 y if x y Note that contents of tape is the same after computation. Simple if statement Basic idea: similar to 0 i 1 i example Match 1 s before 0 with 1 s after. Will either exhaust all initial 1s or trailing 1 s. Go to target state based on cases above MUST return tape to initial input when done. If statement Reality check Turing Machine as transducer Converts input to output Turing-Computable functions Combining Turing Suppose an algorithm has a number of tasks to perform Each task has its own TM Much like subroutines or functions They can be combined into a single TM T 1 T 2 is the composite TM T 1 T 2 Combining Turing Composite TMs T 1 T 2 Start at start state of T 1 For any move that causes T 1 to enter the halt state, have T 1 move to the start state of T 2. So T 2 will get executed immediately after T 1 as long as T 1 will halt on a given input. Allows one to define subroutines. 3
TMs and subroutines Each TM subroutine must define Start state The final state (with conditions) Contents of tape after acceptance Position of tape head after acceptance TMs and subroutines Example " f (x, y) = # x + y if x > y $ 0 otherwise TMs and subroutines Now we have TMs for doing the following Logical compare of x with y Addition of x with y We could easily write one: Erasing all 1s TM and Subroutines The Eraser TM building blocks " f (x, y) = # x + y if x > y $ 0 otherwise TM and subroutines Modified if 4
Building TM from blocks Example L = { xx x { a, b } * } Basic idea Find and mark the middle of the string Compare characters starting from the start of the string with characters starting from the middle of the string. Example L = { xx x { a, b } * } Three subroutines Find and mark the middle of the string Convert the 1 st half of the string back to lower case. Match and compare Example L = { xx x { a, b } * } Finding the middle of the string Convert first character to it s upper case equiv. Move all the way to the right to the last lower case character and change it to upper case. Move all the way back left to the first lower case character and change it to upper case And so on. Example L = { xx x { a, b } * } Finding the middle of the string Start with tape head at first symbol on tape End with tape head at the last character of the 1st half of string Will reject if string is not even. Middle 5
Once you ve found the middle, Convert the 1 st half of the string back to lower case. Start from current tape position and change read backwards to end converting characters along the way. Leaves tape at start of input when done. Tolower Once you ve found the middle and converted to lower case Start from the left of the tape Match lower case chars in 1 st half with upper case chars in the 2 nd. Replace a matched upper case char with blanks Repeat until only 1st half remains Assumes string of form lluu Match The routine will leave the repeated string on the tape Questions? Putting it together 6
Summary Turing Computation on TMs Subroutines To come Next time: TM Variants Languages associated with TMs. Questions 7