1 / 26

Modeling algorithms

Modeling algorithms. Neither the class of DFAs nor the class of PDAs are sufficiently general to model the informal notion of an algorithm. For example, no DFA or PDA can check membership in {0 n 1 n 2 n | n > 0}. There are several formalisms that attempt to model this informal notion.

ehren
Télécharger la présentation

Modeling algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modeling algorithms • Neither the class of DFAs nor the class of PDAs are sufficiently general to model the informal notion of an algorithm. • For example, no DFA or PDA can check membership in {0n1n2n | n > 0}. • There are several formalisms that attempt to model this informal notion. • The Turing machine is one of the simplest • it generalizes of DFAs and PDAs fairly naturally

  2. Turing machines (informally) • A Turing machine (TM) is a DFA equipped with a tape, infinite in both directions. • The tape is divided into squares. • At any point in a TM computation, the TM is scanning exactly one of the squares. • At each move of a TM computation, the TM • may change state • may rewrite the current tape square, and • must move to the tape square to the left or right

  3. Turing machine input and acceptance • The input to a TM appears at a designated position of the tape. • It remains on the tape unless it is rewritten. • When the TM enters an accepting state, it accepts the entire input string. • There's no notion of having to read the entire input.

  4. Turing machine computations • TMs may compute forever on a given input • So one of three things may happen in a TM computation. It may • never halt, • halt in an accepting state • halt (crash) by being in a nonaccepting state with no legal move • Only in the second case does the TM accept its input.

  5. Liberalized definitions • The definition of Turing machines can be liberalized in many ways • without changing the languages accepted • In each case, one shows this by showing that a TM of the more liberal type may be simulated by a TM of a less liberal type.

  6. Sample liberalized definitions • For example, TMs may be allowed: • to have multiple tracks on their tape • to have multiple tapes • to check off symbols • to shift a string on the tape • subroutines

  7. The power of Turing machines • By proceeding in this way, one may show that TMs have the power of any existing processor or high-level language. • More precisely, for any existing programming language (high or low level), TMs can accept any language that can be recognized by a program in the language.

  8. Turing machines as computers of functions • A TM's tape allows it to have more general output than "yes" or "no". • So a TM can be used to compute functions • these functions needn’t be Boolean valued • When computing functions, a TM can compute no more and no fewer functions that existing programming languages can • if they were somehow given unbounded memory

  9. Turing machines and algorithms • An algorithm corresponds to TM that halts on all inputs. • This notion of an algorithm is one version of what is known as Turing's thesis • or Church’s thesis, or the Church-Turing thesis.

  10. Justifying Turing’s thesis • Turing's thesis cannot be proved, since it necessarily deals with an unformalized notion of an algorithm. • It would be fatally weakened, though, if someone were to find a language or machine that could compute more than a TM can. • So far no one has.

  11. Nondeterministic TMs • Nondeterministic TMs can be shown to have no more power than ordinary deterministic TMs. • And quantum computing gives no more power than nondeterministic TMs have

  12. Universal TMs • Real computers are universal • they aren't limited to a particular algorithm. • They can take and run different programs • representing different algorithms • A universal TM would be a TM that takes another TM M and a string x as input, and runs M on x. Such a TM can be defined • once we decide what its alphabet should be • In this sense, TMs model computers, and not just algorithms.

  13. Unsolvable problems • Universal TMs make it easier to investigate the question of whether there are problems that can't be solved. • In the language of TMs, this would correspond to languages that can't be recognized.

  14. Sample unsolvable problems • For example, there's no solution algorithm to the problem of whether a given TM M accepts a given input x. • Here the input to a solution algorithm would be an encoding of the pair (M,x). • The set of such pairs could not be recognized by a TM. • There's not even an algorithm to decide whether M halts on x.

  15. Turing machines -- formally • A Turing machine (TM) has components • Q, S, q0, and F, as for DFAs and PDAs • a tape alphabetG containing S as a subset, • a special blank symbol □, which is in G - S, and • a transition function d: Q x G → Q x G x {L, R}

  16. Turing machines and computations • The input appears on the TM's tape • starting at a designated square 0 • one symbol per square • with blanks in all other squares • TM computations begin in state q0, with the read/write head at square 0. • d determines the new state and tape symbol, and whether to move left or right on the tape • after the tape symbol is updated

  17. A sample TM • A TM to recognize L((a+b)*b) could have states q0, q1, and qf, with F = {qf} • Its transition function could be defined by • d(q0, a) = (q0,a,R) d(q0,b) = (q1,b,R) • d(q1, a) = (q0,a,R) d(q1,b) = (q1,b,R) • d(q1, □) = (qf, □,R) • Here q1 represents a state where b was last read, and q0 a state in which it wasn't

  18. Diagrams for TMs • Transition diagrams may be used for TMs • one for our sample DFA is shown below • Each edge is labeled with • the old & new tape symbols for the current square • and the direction of movement on the tape

  19. Instantaneous descriptions of TMs • An ID for TMs needs to specify at least • the state, • the (nonblank) tape contents, and • which tape square the is being scanned • This can be done by listing the tape contents, and inserting the state before the currently scanned tape symbol. We may assume that • Q and G are disjoint • only finitely many tape symbols are nonblank • The initial ID for an input of 012 is q0012

  20. TM computations • Again we may define computation in terms of a ├ relation on IDs • If d(qi, c) = (qk,e,R), then aqicb ├ aeqkb • If d(qi, c) = (qk,e,L), then adqicb ├ aqkdeb

  21. Acceptance by TMs • We use as before the symbol ├* for the transitive closure of the ├ relation • Then a TM M accepts x iff q0x |*- aqb • for some a,b in G* and q ε F • L(M) is again { x | M accepts x} • A language that is accepted by a TM is called recursively enumerable (r.e.).

  22. A sample accepting computation • The accepting computation for ab for the TM of p. 232 of Linz is • q0ab ├ xq1b ├ q2xy ├ xq0y ├ xyq3 ├ xy□q4 • The intuition is that • q0 looks for a's and checks them off • q1 looks for b's and checks them off • q2 moves leftward looking for the leftmost remaining a • q3 checks that no b's remain if q0 finds no a

  23. A sample nonaccepting computation • A TM rejects its input if the computation crashes • that is, halts because there is no legal move • A nonaccepting computation for the TM above is • q0abb ├ xq1bb ├ q2xyb ├ xq0yb ├ xyq3b • Here q3 is not expecting the symbol b

  24. Another example • An accepting computation for our first sample TM (shown below) is • q0abb ├ aq0bb ├ abq1b ├ abbq1 ├ abb□q2

  25. Halting by TMs • A given TM M may fail to halt on a given input string x • In this case, x is not in L(M) • It's not always possible to find an equivalent TM for L(M) that halts on all input. • A language that is accepted by a TM that halts on all input is called recursive. • The Church-Turing thesis says that a language is recursive iff there's an algorithm for deciding membership in the language.

  26. Recursive and r.e. languages • The r.e. languages are those for which there's a procedure • that correctly answers "yes" whenever a string is in the language • but may compute forever if the answer is "no". • In particular, every recursive language is r.e. • It follows from a recent assertion that not every r.e. language is recursive

More Related