1/31 Efgicient Turing Machines CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2016
2/31 Undecidability of PCP (optional)
3/31 Undecidability of PCP The language PCP is undecidable We will show that If PCP can be decided, so can A TM We will only discuss the main idea, omitting details PCP = {� T � | T is a collection of tiles contains a top-bottom match }
4/31 M accepts w Undecidability of PCP Idea: Matches represent accepting history T contains a match … T (collection of tiles) � M � �− → ⇐ ⇒ # q 0 ab%ab#x q 1 b%ab#…#xx%x q a x# # q 0 ab%ab#x q 1 b%ab#…#xx%x q a x# ε # q 0 a b a % a b # x q 1 % # q 0 ab%ab #x q 1 b a % a b # x% q 2
5/31 q a x x q a x q a Undecidability of PCP S for each valid window S xq a is forced to be the starting tile: We will assume that the following tile T contains a match M accepts w T (collection of tiles) � M � �− → ⇐ ⇒ ε # q 0 ab%ab On input � M , w � , we construct these tiles for PCP for all x in Γ ∪ { # } � �� � ε # q i x 1 # q a ## x 1 q i x 2 # q 0 w � # x 2 x 3 � # # x 3 x 4 x 5 � �� � with state q i in top middle
6/31 x q a q a x q a xq a Undecidability of PCP x figurations cepts represents initial configuration S tile type purpose ε # q 0 w x 1 q i x 2 represents valid transitions between con- x 3 x 4 x 5 adds blank spaces before # if necessary # q i x 1 # � # x 2 x 3 � # q a ## matching completes if computation ac- #
7/31 Undecidability of PCP Once the accepting state symbol occurs, the last two tiles can “eat up” the rest of the symbols x x xq a q a q a x q a #xx%x q a x#xx%x q a # … # q a ## #xx%x q a x#xx%x q a # … # q a ## q a ## #
8/31 Undecidability of PCP it cannot be matched on top If M loops on w , then matching goes on forever If M rejects on input w , then q rej appears on the bottom at some point, but
9/31 Getting rid of the starting tile “middle tiles” begins with * “starting tile” *a c*c*a* *c b* *b*b b*a* *a*b*a *a* We can simulate this assumption by changing tiles a bit S a cca c b bb ba aba a We assumed that one tile is marked as the starting tile “ending tiles” � * �
10/31 Getting rid of the starting tile only possible starting tile only possible *a c*c*a* *c b* *c b* *b*b b*a* *a*b*a *a* S a cca c b c b bb ba aba a ending tile � * �
11/31 Polynomial time
12/31 Running time We don’t want to just solve a problem, we want to solve it quickly
13/31 Efgiciency decidable Undecidable problems: We cannot find solutions in any finite amount of time Decidable problems: We can solve them, but it may take a very long time • A TM • PCP
14/31 Efgiciency efgicient decidable input For longer inputs, we should allow more time Efgiciency is measured as a function of input size • A TM • PCP The running time depends on the
15/31 If mismatch, reject on any input of length n Example: Running time running time: The running time of a Turing machine M is the function t M ( n ) : t M ( n ) = maximum number of steps that M takes L = { w # w | w ∈ { a , b } ∗ } O ( n ) times M : On input x , until you reach # � Read and cross of first a or b before # O ( n ) steps Read and cross ofg first a or b afuer # O ( n ) steps If all symbols except # are crossed ofg, accept O ( n 2 )
16/31 Another example M : On input x , Until everything is crossed ofg: If everything is crossed ofg, accept running time: L = { 0 n 1 n | n � 0 } O ( n ) steps Check that the input is of the form 0 ∗ 1 ∗ O ( n ) times � Cross ofg the lefumost 0 O ( n ) steps Cross ofg the following 1 O ( n ) steps O ( n 2 )
17/31 If the parities don’t match, reject M : On input x , Until everything is crossed ofg: A faster way running time: If everything is crossed ofg, accept L = { 0 n 1 n | n � 0 } O ( n ) steps Check that the input is of the form 0 ∗ 1 ∗ O ( log n ) times Find parity of number of 0 s Find parity of number of 1 s O ( n ) steps Cross ofg every other 0 and every other 1 O ( n ) steps O ( n log n )
18/31 running time: What if we have a two-tape Turing machine? M : On input x , Running time vs model L = { 0 n 1 n | n � 0 } Check that the input is of the form 0 ∗ 1 ∗ O ( n ) steps O ( n ) steps Copy 0 ∗ part of input to second tape � Until � is reached: O ( n ) steps Cross ofg next 1 from first tape Cross ofg next 0 from second tape If both tapes reach � simultaneously, accept O ( n ) steps O ( n )
19/31 1-tape TM How about a Java program? Running time vs model Java 2-tape TM Running time can change depending on the model L = { 0 n 1 n | n � 0 } M(int[] x) { n = x.len; if (n % 2 == 0) reject(); for (i = 0; i < n/2; i++) { running time: O ( n ) if (x[i] != 0) reject(); if (x[n-i+1] != 1) reject(); } accept(); } O ( n log n ) O ( n ) O ( n )
20/31 Measuring running time What does it mean when we say This algorithm runs in time T One “time unit” in Java Random access machine Turing machine all mean difgerent things! δ ( q 3 , a ) = ( q 7 , b , R ) if (x > 0) write r3 y = 5*y + x;
21/31 Efgiciency and the Church–Turing thesis Church–Turing thesis says all these have the same computing power… Turing machine Java RAM Multitape TM …without considering running time
22/31 Cobham–Edmonds thesis An extension to Church–Turing thesis, stating For any realistic models of computation M 1 and M 2 M 1 can be simulated on M 2 with at most polynomial slowdown So any task that takes time t ( n ) on M 1 can be done in time (say) O ( t 3 ) on M 2
23/31 Efgicient simulation The running time of a program depends on the model of computation 1-tape TM 2-tape TM RAM Java slow fast But if you ignore polynomial overhead, the difgerence is irrelevant Every reasonable model of computation can be simulated efgiciently on any other
24/31 Example of efgicient simulation Recall simulating two tapes on a single tape M S … b a � � … Γ = { a , b , � } a b b � … a # a b b ˙ # b ˙ � # � b , ˙ a , ˙ Γ = { a , b , � , ˙ � , # }
25/31 afuer t steps quadratic single tape TM multi-tape TM t steps of 2-tape Running time of simulation slowdown 1 step of 2-tape TM tape Each move of the multitape TM might require traversing the whole single ⇒ O ( s ) steps of single tape TM s = right most cell ever visited ⇒ s � 2 t + O (1) O ( ts ) = O ( t 2 ) single tape steps ⇒
26/31 Simulation slowdown Java Random access machine 2-tape TM 1-tape TM Cobham–Edmonds thesis: O ( t 2 ) O ( t ) O ( t 2 ) O ( t ) O ( t ) O ( t ) M 1 can be simulated on M 2 with at most polynomial slowdown
27/31 The class P regular context-free efgicient decidable P is the class of languages that can be running time By Cobham–Edmonds thesis, they model of computation e.g. Java, RAM, multitape TM decided on a TM with polynomial can also be decided by any realistic
28/31 Examples of languages in P P is the class of languages that are decidable in polynomial time (in the input length) context-free P (efgicient) decidable L 01 = { 0 n 1 | n � 0 } L G = { w | CFG G generates w } • L 01 • L G PATH = {� G , s , t � | Graph G has a path from node s to node t } • PATH
29/31 a Let L be a context-free language, and G be a CFG for L in Chomsky Normal Form CYK algorithm: B B B Context-free languages in polynomial time i a b b a ℓ 5 If there is a production A → x i 4 Put A in table cell T [ i , 1] 3 For cells T [ i , ℓ ] 2 S | A S | C S | A If there is a production A → BC where B is in cell T [ i , j ] 1 A | C A | C A | C and C is in cell T [ i + j , ℓ − j ] 1 2 3 4 5 Put A in cell T [ i , ℓ ] On input x of length n , running time is O ( n 3 )
30/31 PATH in polynomial time running time: If t is marked, accept Mark the unmarked endpoint If some edge has both marked and unmarked endpoints Scan the edges of G . Repeat until no additional nodes are marked: Place a mark on node s where G is a graph with nodes s and t G has n vertices, m edges PATH = {� G , s , t � | Graph G has a path from node s to node t } M = On input � G , s , t � O ( n ) times O ( m ) steps O ( mn )
31/31 Hamiltonian paths A Hamiltonian path in G is a path that visits every node exactly once s t We don’t know if HAMPATH is in P, and we believe it is not HAMPATH = {� G , s , t � | Graph G has a Hamiltonian path from node s to node t }
Recommend
More recommend