Download presentation
Presentation is loading. Please wait.
Published byMeghan Moody Modified over 9 years ago
1
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011
2
THE 4011… First model of a program: DFA / Regexp Solvable Problems: Regular Languages Unsolvable Problems: { 0 n 1 n | n ≥ 0 } Next model of a program: PDA / CFG Solvable Problems: Context-Free Languages Unsolvable Problems: { w#w | w ∈ * } def is_duplicate(s): n = int(len(s)/2) if (s[n]!= ‘#’: return False return s[:n] == s[n+1:]
3
TURING MACHINE FINITE STATE CONTROL UNBOUNDED TAPE INPUT q0q0 q1q1 A
4
0 → 0, R readwritemove → , R q accept q reject 0 → 0, R → , R 0 → 0, R → , L A TM can loop forever!
5
TMs VERSUS FINITE AUTOMATA TM can both write to and read from the tape The head can move left and right The string doesn’t have to be read entirely Accept and Reject take immediate effect
6
Testing membership in B = { w#w | w {0,1}* } STATE 011# 0 11 q 0, FIND # q GO LEFT 0 q 1, FIND # q #, FIND #1 q 0, FIND 0 q 1, FIND 1 x x x
7
Definition: A Turing Machine is a 7-tuple T = (Q, Σ, Γ, , q 0, q accept, q reject ), where: Q is a finite set of states Γ is the tape alphabet, where Γ and Σ ⊂ Γ q 0 Q is the start state Σ is the input alphabet, where Σ : Q Γ → Q Γ {L,R} q accept Q is the accept state q reject Q is the reject state, and q reject q accept
8
CONFIGURATIONS 11010q 7 00110 q7q7 10 000 011 1 1
9
0 → , R → , R q accept q reject 0 → x, R x → x, R → , R x → x, R 0 → 0, L x → x, L x → x, R → , L → , R 0 → x, R 0 → 0, R → , R x → x, R { 0 | n ≥ 0 } 2n2n q0q0 q1q1 q2q2 q3q3 q4q4
10
0 → , R → , R q accept q reject 0 → x, R x → x, R → , R x → x, R 0 → 0, L x → x, L x → x, R → , L → , R 0 → x, R 0 → 0, R → , R x → x, R { 0 | n ≥ 0 } 2n2n q0q0 q1q1 q2q2 q3q3 q4q4 q 0 0000 q 1 000 xq 3 00 x0q 4 0 x0xq 3 x0q 2 x xq 2 0x q 2 x0x q 2 x0x
11
EXAMPLES Give TM state diagrams for: { a n b n a n | n ≥ 0 } { w | w = w R }
12
ADD = {1 i #1 j #1 k | i+j = k} 11#111#11111 x1#111#z1111 xx#111#zz111 xx#x11#zzz11 xx#xx1#zzzz1 xx#xxx#zzzzz
13
q 0 : 0 # FIND-1-L # →#,R q 4 : 1 # FIND-1-L q 1 : 0 # FIND-1-R 1→x,R q 3 : 1 # FIND-1-R # →#,R 1→1,R q 6 : 2 # REJ-1-R # →#,R z→z,R q R : REJECT 1 →1,R # →#,L 1→x,R q a : ACCEPT □ → □,L q 7 : 2 # FIND-1-R □ → □,L # →#,L z→z,R q 8 : 2 # FIND-x-L # →#,R 1→z,L q 5 : 1 # FIND-x-L # →#,L Z→z,L x→x,R 1→1,L q 2 : 0 # FIND-x-L # →#,L 1→1,L x→x,R 1→1,R
14
MUL = {1 i #1 j #1 k | ij = k and i, j, k ≥ 1} 11#111#111111 x1#111#111111 x1#yyy#zzz111 x1#111#zzz111 xx#yyy#zzzzzz
15
LUP = {1 i #x 1 #...#x n | n ≥ i and x i = x 1 } 111#101#11#101 x11#101#11#101 xx1#101#11#101 xxx#101#11#101......
16
A TM decides a language if it accepts all strings in the language and rejects all strings not in the language A language is called decidable or recursive if some TM decides it A TM recognizes language L if it accepts all and only the strings in L.
17
Theorem: If L is decidable then so is its negation. Proof: Let M = (Q, , ,δ,q 0,q accept,q reject ) decide L. We construct M’ that decides ¬L. M’ = (Q, , ,δ,q 0,q reject,q accept ), i.e. M with q reject and q accept swapped. Suppose that w ∈ L. Then M’ rejects w, since M will go to q accept on w. Suppose that w L. Then M’ accepts w, since M will go to q reject on w.
18
Theorem: If L 1 and L 2 are decidable then so is L 1 ∩ L 2 = { w | w ∈ L 1 and w ∈ L 2 }. Proof: Let M 1 decide L 1 and M 2 decide L 2. We build a two-tape TM M’ to decide L 1 ∩ L 2.
19
MULTITAPE TURING MACHINES : Q Γ k → Q Γ k {L,R,S} k FINITE STATE CONTROL
20
Theorem: If L 1 and L 2 are decidable then so is L 1 ∩ L 2 = { w | w ∈ L 1 and w ∈ L 2 }. Proof: Let M 1 decide L 1 and M 2 decide L 2. We build a two-tape TM M’ to decide L 1 \ L 2. M’ works as follows: 1. Copy the input to tape 2 and move to left edge 2. Run M 1 on tape 1 and M 2 on tape 2. If either M 1 or M 2 reject, go to q reject If both M 1 and M 2 accept, go to q accept
21
Formally, let M i = (Q i, , i, i,q s i,q a i,q r i ). Then M’ = (Q, , , ,q 0,q a,q r ), where: Q = Q 1 Q 2 ∪ Q cp, = 1 ∪ 2 ∪ cp, ((q 1,q 2 ),s 1,s 2 ) = (q r,s 1,s 2,S,S), if q 1 ’ = q 1 r or q 2 ’ = q 2 r (q a,s 1,s 2,S,S), if q 1 = q 1 a and q 2 = q 2 a ((q 1 ’,q 2 ’),s 1 ’,s 2 ’,d 1,d 2 ), else ((q 1,q 2 ’),s 1,s 2 ’,S,d 2 ), if q 1 =q 1 a ((q 1 ’,q 2 ),s 1 ’,s 2,d 1,S), if q 2 =q 2 a where (q i ’,s i ’,d i ) = i (q i,s i )
22
Theorem: multi-tape TMs are equivalent to ordinary TMs: ⇐ : a multi-tape TM can run a single-tape TM by ignoring its extra tapes. L is decided by a multi-tape TM ⇔ L is decided by a single-tape TM. ⇒ : Next Lecture…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.