Computation with Turing Machines • Computing functions with TMs – The result of the function applied to an input Turing Machines string x, will be left on the tape when the machine halts. • Note: it doesn’t matter if the machine halts in a final Computation and programming state. – Functions with multiple arguments can be placed on the input tape with arguments separated by some character. Computation with Turing Machines Computation with Turing Machines • Turing’s original use of his machine was to • Computing functions with TMs calculate integer valued functions. – Formally, – Integers were represented in unary as blocks of a single • Let M = (Q, Σ , Γ , δ , q 0 , B, F) be a TM and let f be a symbol. partial function on Σ * . We say T computes f if for – Example every x ∈ Σ * where f is defined: • 000000 would represent 6 – q 0 x a * pf(x) • 0000 would represent 4 • And for every other x, T fails to halt on input x. – In our text • 0s are used as the unary symbol • 1s are used to separate arguments Computation with Turing Machines Computation with Turing Machines • Computing functions with TMs • Example – Formally (with multiple arguments) – Proper subtraction: • Let M = (Q, Σ , Γ , δ , q 0 , B, F) be a TM and let f be a • m – n = max (m-n, 0) partial function on ( Σ *) k . We say T computes f if for every (x 1 , x 2 . …, x k ) where f is defined: • Use 0 as unary symbol – q 0 x 1 1x 2 … 1x k a * pf(x 1 , x 2 . …, x k ) • And for every other k-tuple, T fails to halt on input • M will start with 0 m 10 n x. • M will halt with 0 (m-n) on it’s tape 1
Computation with Turing Machines Computation with Turing Machines • Example • Proper subtraction – Proper subtraction: • Basic idea: – Finds leftmost 0 and replaces with blank, – Finds first 1 – Finds first 0 after 1, replaces with a 1. – Repeat until » When searching for first 0 after the 1 it doesn’t find it » Cannot find leftmost 0. Combining Turing Machines Computation with Turing Machines • Questions? • 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 Machines Let’s try a non-context free language • 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. 2
Combining Turing Machines Combining Turing Machines • Useful “subroutines” • Copy TM – Copy TM • Creates a copy of a “block” of 0s to the right of the input • See in action – 0 i 1q 1 0 n 10 j a * 0 i 1q 5 0 n 10 j+n • Basic idea – Marks first 0 with an X – Move right to first blank and write a 0 – Move left until X is found – Repeat until all 0’s are converted to X – When finished, coverts Xs back to 0s. Combining Turing Machines Computation with Turing Machines • Characteristic function of a set: • Useful “subroutines” – For any language L, the characteristic function is – Something to note defined as: • The TM must be set up to be in the correct • 1 if x ∈ L configuration before delete is “called” • 0 otherwise • I.e. the tape head must be at the character to be – If a TM computes the characteristic function of a deleted. language, it will always halt with either a 1 or 0 left on the tape – Questions? • This is stronger than saying that x is accepted by the TM since if x ∉ L, for a TM that accepts L, there is no guarantee that the the machine will halt. Turing Machine Variants Turing Machine Variants • Some variants of the TM – Multitaped TMs • Have multiple tapes • With a multiple tape heads that is read/writing a different position on each tape at any one given time. 3
Turing Machine Variants Multitape TM • Example • Multitape TM – {ww R | w is a string in {a,b} * } – Move of a multitape TM – Even length palandromes • Will depend upon: – The state of the machine – The symbol being read on all of the tape heads – 2-tapes • Result: • Step 1: Copy contents of tape 1 to tape 2 – Each of the tape heads will write a new symbol on the tape • Step 2: position head of tape 1 at beginning of tape – Each of the tape heads will move left, right, or stationery and head of tape 2 at end – Tape heads can move independently. • Step 3: Compare strings character by character Multitape TM Multitape TM • Let’s go to the video tape Turing Machine Variants Turing Machine Variants • Multitape TM • Some other variants of the TM – Thankfully, the multiTape TM can be shown to – Non-deterministic TMs be equivalent to the “vanilla” TM. • More than 1 move is possible from any given configuration. • You can simulate the workings of a multitape TM on a single tape TM. • See Theorem 8.9 in text. 4
Turing Machine Variants Turing Machine Variants • Some variants of the TM • Thankfully, all these variants can be shown to be equivalent to the “basic” TM. – Semi-infinite TM • What some books calls the “basic” TM. – Specifically, non-determinism does not add extra computing power to a TM • Input tape is bounded on the left • Much like FAs • But unlike PDAs – Multitape TMs will be handy in future lectures. • No better or worse than the basic TM. Summary To come • Turing Machines • Next time: • Computation on TMs – The classes of languages associated with TMs • Subroutines – Chomsky Heirarchy. • TM variants – Non-deterministic – Multitape TM • Questions 5
Recommend
More recommend