1 / 39

CSCI 3130: Formal languages and automata theory

Fall 2011. The Chinese University of Hong Kong. CSCI 3130: Formal languages and automata theory. Turing Machines. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. What is a computer?. computer. program. output. input.

lotta
Download Presentation

CSCI 3130: Formal languages and automata theory

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. Fall 2011 The Chinese University of Hong Kong CSCI 3130: Formal languages and automata theory Turing Machines Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

  2. What is a computer? computer program output input A computer is a machine that manipulates data according to a list of instructions.

  3. What is a computer? void hello( String name) { print( “Hello, “, name); } ? Hello, world world ? E2-E4 deep blue ? computer

  4. Turing Machines control head … ☐ ☐ input blanks a b b Can both read from and write to the tape Head can move both left and right Tape is infinite Has two special states accept and reject

  5. Example L1 = {w#w: w ∈{a, b}*} Strategy: abbaa#abbaa Read and remember the first symbol xbbaa#abbaa Cross it off (x) xbbaa#abbaa Read the first symbol past # If they don’t match, reject xbbaa#xbbaa If they do, cross it off

  6. Example L1 = {w#w: w ∈ {a, b}*} Strategy: Look for the first uncrossed symbol xbbaa#xbbaa Cross it off (x) xxbaa#xbbaa Read the first uncrossed symbol past # xxbaa#xbbaa If they match, cross it off, else reject xxbaa#xxbaa xxxxx#xxxxx At the end, there should be only xs and #s If not, reject; otherwise, accept.

  7. How Turing Machines operate current state a/bL q1 q2 … a b a ☐ Replace a with b, and move head left new state a/bL q1 q2 … a b b ☐

  8. Formal Definition • A Turing Machine is (Q, ,, , q0, qacc, qrej): • Q is a finite set of states; •  is the input alphabet not containing the blank symbol ☐ •  is the tape alphabet (  ) including☐ • q0in Q is the start state; • qacc, qrejin Q are the accepting and rejecting state •  is the transition function d: (Q – {qacc, qrej})   → Q  G  {L, R} Turing Machines are deterministic

  9. Configurations • A configuration consists of the current state, the head position, and tape contents configuration qacc q1 … … a a b b a b ☐ ☐ abq1a a/bR q1 qacc abbqacc

  10. Configurations • We say configuration CyieldsC’ if the TM can go from C to C’ in one step • The start configuration of the TM on input w is q0w • An accepting configuration is one that contains qacc;A rejecting configuration is one that contains qrej abq1a yields abbqacc

  11. The language of a Turing Machine • We say M accepts x if there exists a sequence of configurations C0, C1, ..., Ck where Ci yields Ci+1 Ck is accepting C0 is starting The language recognized by M is the set of all strings that M accepts

  12. Looping • Something strange can happen in a Turing Machine: • Inputs can be divided into three types  = {0, 1} ☐/☐R qacc 0/0R input: e This machinenever halts q0 1/1R qrej qacc qrej accept reject loop

  13. Halting • We say Mhalts on x if there exists a sequence of configurations C0, C1, ..., Ck where Ck is accepting or rejecting Ci yields Ci+1 C0 is starting A TM M is a decider if it halts on every input Language L is decidable if it is recognized by a TM that halts on every input

  14. Programming Turing Machines Description of Turing Machine: L1 = {w#w: w ∈ {a, b}*} Until you reach # xbbaa#xbbaa Read and remember entry xxbaa#xbbaa Writex xxbaa#xbbaa Move right past # and past all xs If this entry is different, reject Otherwise xxbaa#xxbaa Writex Move left past # and to right of first x xxbaa#xxbaa If you see only xs followed by ☐, accept 1 2 3 4 5 6 7 8

  15. Programming Turing Machines L1 = {w#w: w ∈ {a, b}*} a/aR b/bR x/xR #/#R a/aL qa1 qa2 a/aL b/bL a/xL b/bL x/xL x/xR a/xR #/#L #/#R ☐/☐R q0 q1 q2 q3 qrej qacc b/xR b/xL everything else qb1 qb2 #/#R 1 7 2 8 4 4 2 3 5 6 5 6 3 a/aR x/xR b/bR x/xR

  16. Programming Turing Machines input: aab#aab a/aR b/bR x/xR configurations: #/#R a/aL q0aab#aab qa1 qa2 a/aL b/bL a/xL xqa1ab#aab b/bL x/xL x/xR a/xR xaqa1b#aab #/#L #/#R ☐/☐R q0 q1 q2 q3 qacc xabqa1#aab b/xR xab#qa2aab b/xL xabq2#xab qb1 qb2 #/#R xaq3b#xab 4 2 4 1 8 7 2 6 5 6 3 3 5 xq3ab#xab a/aR x/xR b/bR q3xab#xab xq0ab#xab x/xR

  17. Programming Turing Machines L2 = {aibjck: i × j = k and i, j, k > 0} aabbcccc High-level description of TM: For every a: aabbcccc Cross off the same number of bs and cs aabbcccc Uncross the crossed bs (but not the cs) aabbcccc Cross off this a aabbcccc If all as and cs are crossed off, accept. aabbcccc aabbcccc aabbcccc S = {a, b, c} G = {a, b, c, a, b, c, ☐}

  18. Programming Turing Machines L2 = {aibjck: i × j = k and i, j, k > 0} Low-level description of TM: Scan input from left to right to check it looks like aa*bb*cc* Move the head to the first symbol of the tape For every a: how do we know? Cross off the same number of bs and cs how to do this? Restore the crossed of bs (but not the cs) Cross off this a If all as and cs are crossed off, accept.

  19. Programming Turing Machines aabbcccc Implementation details: Move the head to the first symbol of the tape aabbcccc Put a special marker on top of first a  Cross off the same number of bs and cs: aaqbbcccc  aabqbcccc Replace b by b  aabbqcccc Move right until you see a c  aabqbcccc Replace c by c  aabbqcccc Move left just past the last b  aabbcqccc If any bs are left, repeat  aabbqcccc  S = {a, b, c} G = {a, b, c, a, b, c, a, a, ☐}  

  20. Programming Turing Machines L3 = {#x1#x2...#xl : xi∈ {0, 1}* andxi ≠ xj for each i ≠ j} High-level description of TM: #01#0011#1 On input w, For every pair of blocks xi and xj in w, Compare the blocks xi and xj If they are the same, reject. Otherwise, accept.

  21. Programming Turing Machines L3 = {#x1#x2...#xl : xi∈ {0, 1}* andxi ≠ xj for each i ≠ j} Low-level description: #01#0011#1 0. If input is e, or has exactly one #, accept. 1. Place a mark on the leftmost #(i.e. replace # by #) and move right #01#0011#1   2. Place another mark on next unmarked #(If there are no more #, accept) #01#0011#1  

  22. Programming Turing Machines L3 = {#x1#x2...#xl : xi∈ {0, 1}* andxi ≠ xj for each i ≠ j} current state: #01#0011#1   3. Compare the two strings to the rightof marked #. If there are same, reject #01#0011#1    4. Move the right #to the right  #01#0011#1   If not possible, move the left # to the next # and put the right # on the next If not possible, accept   5. Repeat Step 3 #01#0011#1  

  23. Programming Turing Machines L3 = {#x1#x2...#xl : xi∈ {0, 1}* andxi ≠ xj for each i ≠ j} #01#0011#1 3.  Compare the two strings to the rightof marked #. If there are same, reject   #01#0011#1   4. Move the right #to the right  accept If not possible, move the left # to the next # and put the right # on the next If not possible, accept  

  24. How to describe Turing Machines? • Unlike for DFAs, NFAs, PDAs, we rarely give complete state diagrams of Turing Machines • Usually we give a high-level description:A recipe about the workings of the Turing Machine Just like in cooking, practice makes perfect!

  25. Programming Turing Machines L4 = {〈G〉: G is a connected undirected graph} Q: How do we feed a graph into a Turing Machine? A: We represent it by a string, e.g. (1,2,3,4)((1,4),(2,3),(3,4)(4,2)) 1 2 Convention for describing graphs: (nodes)(edges) no node must repeat 3 4 edges are pairs (node1,node2)

  26. Programming Turing Machines L4 = {〈G〉: G is a connected undirected graph} On input 〈G〉, 0. Verify that 〈G〉 is the description of a graph (no vertex repeats; edges only go between nodes) 1. Mark the first node of G x x 1 2 2. Repeat until no new nodes are marked: For each node, mark it if it is attached to an already marked node x x 3 4 3. If all nodes are marked accept, otherwise reject.

  27. Programming Turing Machines L4 = {〈G〉: G is a connected undirected graph} (1,2,3,4)((1,4)(2,3)(3,4)(4,2))  (1,2,3,4)((1,4)(2,3)(3,4)(4,2))  (1,2,3,4)((1,4)(2,3)(3,4)(4,2))  (1,2,3,4)((1,4)(2,3)(3,4)(4,2))   1 2 (1,2,3,4)((1,4)(2,3)(3,4)(4,2))   (1,2,3,4)((1,4)(2,3)(3,4)(4,2))   3 4 (1,2,3,4)((1,4)(2,3)(3,4)(4,2))   (1,2,3,4)((1,4)(2,3)(3,4)(4,2))   (1,2,3,4)((1,4)(2,3)(3,4)(4,2))   etc. (1,2,3,4)((1,4)(2,3)(3,4)(4,2))   

  28. What’s so great about Turing Machines?

  29. Hilbert’s list of 23 problems • Leading mathematician in the 1900s • At the 1900 International Congressof Mathematicians, proposed a list of23 problems for the 20th century • Hilbert’s 10th problem: David Hilbert (1862-1943) Find a method to tell if an equation like xyz – 3xy + 6xz + 2 = 0 has integer solutions

  30. A brief history of computing devices Z3 (Germany, 1941) ENIAC (Pennsylvania, 1945) PC (1980) MacBook Air (2008)

  31. Computation is universal In principle, all these have the same problem-solving ability

  32. The Church-Turing Thesis Turing Machine If an algorithm can be implemented on any realistic computer, then it can be implemented on a Turing Machine.

  33. The Church-Turing Thesis Turing Machine quantum computing cosmic computing DNA computing

  34. Alan Turing • Invented the Turing Test to tellhumans and computers apart • Broke German encryption machines in World War II • The Turing Award is the “Nobel prize of Computer Science” Alan Turing (1912-1954) Turing’s motivation: By studying Turing Machines, we can understand the limitations of real computers.

  35. Undecidability • What Hilbert meant to ask was: • Building on work of Gödel, Church, Turing, Davis, Putnam, Robinson, in 1970 Matijasievič showed: Find a Turing Machine to tell if an equation like xyz – 3xy + 6xz + 2 = 0 has integer solutions There is no such Turing Machine!

  36. Computer program analysis public static void main(String args[]) { System.out.println("Hello World!"); } What does this program do? public static void main(String args[]) { int i = 0; for (j = 1; j < 10; j++) { i += j; if (i == 28) { System.out.println("Hello World!"); } } } How about this one?

  37. Computers cannot analyze programs! No Turing Machine can do this: input: The code of a java program P Accept if P prints “hello, world” Reject if not Significance: It is impossible for computer to predict what a computer program will do!

  38. How do you argue things like that? To argue what computers cannot do, we need to have a precise definitionof what a computer is. Turing’s answer: A computer is just a Turing Machine. 1936: “On Computable Numbers, with an Application to the Entscheidungsproblem” Section 1. Computing Machines

  39. The Church-Turing Thesis All arguments [for the CT Thesis] which can be given are bound to be, fundamentally, appeals to intuition, and for this reason rather unsatisfactory mathematically. The arguments which I shall use are of three kinds: 1. A direct appeal to intuition 2. A proof of the equivalence of two definitions (In case the new definition has greater intuitive appeal) 3. Giving examples of large classes of numbers which are computable. 1936: “On Computable Numbers, with an Application to the Entscheidungsproblem” Section 9. The extent of the computable numbers

More Related