Theory of Computation CS 3102 Spring 2014 A



























- Slides: 27
Theory of Computation CS 3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer Science University of Virginia www. cs. virginia. edu/~njb 2 b/theory
Spring Break Extra Credit Assignment Read Chapter 3 of Sipser. One sentence in there is the most bogus sentence in the entire book. Correctly guessing which sentence is bogus earns extra credit.
Turing Machine FSM … Infinite tape: Γ* Tape head: read current square on tape, write into current square, move one square left or right FSM: like PDA, except: transitions also include direction (left/right) final accepting and rejecting states
Turing Machine Acceptance FSM δ*: Γ* Q Γ* Does this cover all possibilities? … u A string w is in the language of Turing Machine T if δ*(ε, q 0, w) = (u, qaccept, v) A string w is not in the language of Turing Machine T if δ*(ε, q 0, w) = (u, qreject, v) v
Machine Termination • DFAs, DPDAs: • Consume one input symbol each step • Must terminate • NFAs: • Equivalent to DFA: must terminate • Turing Machine: • Can move left and right: no “progress” guarantee
Infinite Loops Some Turing machines have infinite loops: While(true){ Twiddle. Thumbs(); } Is this good or bad? Yes.
Infinite Loops Programs we want to halt: Your 2150 Homework Programs we want to run forever:
Turing Machine Outcomes 1. Running TM M on input w eventually leads to qaccept. • Result: Accept 2. Running TM M on input w eventually leads to qreject. • Result: Reject 3. Running TM M on input w runs forever (never terminates). • Result: Reject
Recognizing vs. Deciding Turing-recognizable: A language L is “Turing-recognizable” if there exists a TM M such that for all strings w: If w L eventually M enters qaccept If w L either M enters qreject or M never terminates Turing-decidable: A language L is “decidable” if there exists a TM M such that for all strings w: If w L, M enters qaccept. If w L, M enters qreject.
Turing -Recognizable vs. -Decidable √ w→ Input Accept & halt Never runs forever Reject & halt Def: A language is Turing-decidable iff it is exactly the set of strings accepted by some always-halting TM. w Σ* = a b aa ab ba bb aaa aab aba abb baa bab bba bbb aaaa M(w)Þ L(M) = √ √ { a, aa, √ aaa, Note: M must always halt on every input. … √ … aaaa …}
Turing -Recognizable vs. -Decidable √ w→ Input Accept & halt Reject & halt ≡ ∞ Run forever Def: A language is Turing-recognizable iff it is exactly the set of strings accepted by some Turing machine. w Σ* = a b aa M(w)Þ L(M) = √ √ ∞ ∞ √ ∞ ∞ { a, ab ba bb aaa aab aba abb baa bab bba bbb aaaa aaa, ∞ … √ … aaaa …} Note: M can run forever on an input, which is implicitly a reject (since it is not an accept).
Famous Deciders “A wrong decision is better than indecision. ” “I'm the decider, and I decide what is best. ”
Famous Deciders
Revised Hierarchy Recognizable Languages Decidable Languages finite Languages Regular Languages Deterministic CFLs
Turing Machine “Enhancements” • Here we have some helpful modifications to Turing Machines • Does not change language class • Helpful for describing machines
Turing Machine “Enhancements” Larger alphabet: old: Σ={0, 1} new: Σ’ ={a, b, c, d} Idea: Encode larger alphabet using smaller one. Encoding example: a=00, b=01, c=10, d=11 b a d c a old: δ b 0 1 0 0 1 1 1 0 0 0 new: δ' 0 1
Turing Machine “Enhancements” Double-sided infinite tape: 1 0 1 1 0 0 1 Idea: Fold into a normal single-sided infinite tape 1 0 1 1 0 1 old: δ L/R new: δ' L/R R/L
Turing Machine “Enhancements” Multiple heads: b b a a Idea: Mark heads locations on tape and simulate b B b A a a Modified δ' processes each “virtual” head independently: • Each move of δ is simulated by a long scan & update • δ' updates & marks all “virtual” head positions
Turing Machine “Enhancements” Multiple tapes: 1 1 0 1 0 1 1 0 0 Idea: Interlace multiple tapes into a single tape Modified δ' processes each “virtual” tape independently: • Each move of δ is simulated by a long scan & update • δ' updates R/W head positions on all “virtual tapes”
Turing Machine “Enhancements” Two-dimensional tape: 1 1 0 1 0 1 1 0 0 Idea: Flatten 2 -D tape into a 1 -D tape $ $ Modified 1 -D δ' simulates the original 2 -D δ: • Left/right δ moves: δ' moves horizontally • Up/down δ moves: δ' jumps between tape sections This is how compilers implement 2 D arrays! $
Turing Machine “Enhancements” Non-determinism: 1 1 0 1 1 1 0 1 Idea: Parallel-simulate non-deterministic threads $ $ $ Modified deterministic δ' simulates the original ND δ: • Each ND move by δ spawns another independent “thread” • All current threads are simulated “in parallel”
Turing Machine “Enhancements” Combinations: ND 3. 1 4 1 5 9 H e l l o W o r l d ! Π λ α τ ω ν Idea: “Enhancements” are independent (and commutative with respect to preserving the language recognized). Theorem: Combinations of “enhancements” do not increase the power of Turing machines.
Closure Properties of Decidable Languages Theorem: The decidable langs are closed under complement. Modify the machine to exchange the accept state for reject state. A string w is in the language of Turing Machine T if δ*(ε, q 0, w) = (u, qaccept, v) A string w is not in the language of Turing Machine T if δ*(ε, q 0, w) = (u, qreject , v)
Closure Properties of Decidable Languages Theorem: The decidable languages are closed under union. 1. Copy input 2. Run machine 1 on copy of input (never cross $) 1. If accept then move into accept state M 1 M 2 3. Erase everything to right of $ 4. Run machine 2 a b input b a $ a b copy b a
Closure Properties of Decidable Languages Theorem: The decidable languages are closed under Ç. 1. Copy input 2. Run machine 1 on copy of input (never cross $) 1. If reject then move into reject state M 1 M 2 3. Erase everything to right of $ 4. Run machine 2 a b input b a $ a b copy b a
Closure Properties of Decidable Languages Theorem: The decidable langs are closed under concatenation. Use a 3 -tape machine: Tape 1: save input remember factor attempts a b b a input Tape 2: tape for Machine 1 Tape 3: tape for Machine 2 b a b 10 index a b a $ a
Closure Properties of Decidable Languages Theorem: The decidable langs are closed under Kleene star. Similar to concatenation, but now we also try all possible numbers of concatenations. Tape 1: a b b input a $ 0 index $ Number of concatenations