200 likes | 640 Views
Combining Turing Machines. Reading: 9.2-10.4. Combining TMs. We can string together Turing Machine computations in order to compute more complicated functions. f(x) = x+y if x >= y 0 if x < y Answer: Use Comparer calculation to end up in qx or qy. qx begins the adder computation
E N D
Combining Turing Machines Reading: 9.2-10.4
Combining TMs • We can string together Turing Machine computations in order to compute more complicated functions. • f(x) = x+y if x >= y 0 if x < y • Answer: Use Comparer calculation to end up in qx or qy. • qx begins the adder computation • qy erases all other ones and puts a zero at the end.
If - else • We now can do some if-else constructions • If a then qj else qk • Read an a, then go to qj without writing or moving the head (that is, move right, then left) • If the symbol was not an a, go to qk without changing anything.
Subroutines • Call a subroutine in a Turing Machine. • Want to stop computation A, go to a separate part of the tape, and do computation B. Then return to computation A in the same place on the tape. • How it works: • Before calling B, A copies inputs into a shared tape space (indicated by a separator) • A transitions into the initial state of B • B uses its tape space to compute • B writes relevant output to the shared space • B’s final state now points back into a state in A.
Example: x times y • Initially, the tape should have leading zeroes, ones denoting x, a zero, then ones denoting y. • At the end, it should have ones denoting xy at the beginning of the input. • 1. Repeat until there are no more 1’s in x: • Find a 1 in x and replace it with another symbol, a • Replace the leftmost 0 by 0y. • 2. Replace all a’s with 1’s.
Turing’s Thesis • Can Turing Machines do anything computers can do? • Hmm - depends on the definition of “computer”! • Turing’s thesis(mid-30’s): Any computation carried out by mechanical means can be carried out by a Turing Machine.
Turing’s thesis: true or false? • Can’t prove it, because we can’t foresee what “mechanical means” people might come up with in the future. • Could disprove it with one counterexample...
Evidence Supporting Turing’s thesis • Anything that can be done on an existing digital computer can be done on a Turing Machine • We can prove this - just write a TM for each machine instruction. • No one has been able to suggest a problem solvable by an algorithm but not a TM • Many alternative models of digital computers have been proposed - but none are more powerful than TMs
Algorithm definition • An algorithm for a function is a Turing Machine that halts with the correct answer on the tape for any input in the domain.
Other types of automata • Given another type of automata, how do you know which is more powerful? • Simulation - show how anything done with one type of automata can be done with the other • Example: I can simulate with a PDA any FSA. Therefore PDAs as powerful (maybe more) than FSAs.
Example: • Any FSA can be written as a PDA: • So PDAs are at least as powerful.
Variations on TMs • Add a stay-option • Tape is only unbounded in one direction • Separate read-only tape for input (off-line TM) • Multiple storage tapes • Multi-dimensional tape (extends infinitely in 2 dimensions) • Non-deterministic TMs (not presently possible with today’s computers) All these are equivalent automata to Turing Machines!
Non-deterministic TMs • An interesting class of TMs... • Equivalent in power to TMs (so everything computable by a ND-TM is computable by a TM) • BUT, it takes more steps on a TM than a ND-TM. We think it takes exponentially more steps... • This is where the classes P and NP come from... • P: set of all problems computable by a TM in polynomial time • NP: set of all problems computable by a ND-TM in polynomial time • P = NP? Unknown...
Detour into 331... • NP-Complete: set of all problems in NP that are polynomial-time reducible to ALL problems in NP. • Meaning, if you can solve 1 NPC problem in polynomial time, you can solve ALL NP problems in polynomial time, and P = NP • Cook’s Theorem: SAT is NP-Complete • How did this work? He showed that every ND-TM has an equivalent SAT expression!! • From that it is easy to reduce other NP-problems to SAT to prove that they too are NPC: • Hamiltonian paths (Traveling salesman) • Cliques
Universal Turing Machines • Are computers more powerful because they are programmable? • Universal Turing Machine: takes its own specification as input. • Are Universal Turing Machines more powerful?
Universal TMs • Universal TMs have been constructed from multi-tape TMs. One tape gives the input, one gives the internal storage, one tape is the “program” telling the machine what to do next. • Since multi-tape TMs are equivalent to TMs, Universal TMs are equivalent to TMs!