turing machines
play

Turing machines Turing Machines (TMs), configurations, yield relation - PowerPoint PPT Presentation

Turing machines Turing Machines (TMs), configurations, yield relation Decidable, recognizable and co-recognizable languages Computable Functions TM Example Reference: Sipser, Chapter 3 Mihir Bellare, UCSD 1 CSE 200: Computability and Complexity


  1. Turing machines Turing Machines (TMs), configurations, yield relation Decidable, recognizable and co-recognizable languages Computable Functions TM Example Reference: Sipser, Chapter 3 Mihir Bellare, UCSD 1 CSE 200: Computability and Complexity

  2. You are probably familiar with several programming languages Examples: Python, JavaScript, Java, C#, C, C++, Go, Rust, Assembly, machine code, … Turing Machines (TMs) are just a new programming Why do we need yet another language programming language? few instructions, few features TMs are a very LOW LEVEL programming language + TMs can be precisely and easily mathematically formalized + TMs make it easier to pose and answer questions ABOUT programs. - Hard to write programs! Mihir Bellare, UCSD 2 CSE 200: Computability and Complexity

  3. You are probably familiar with several programming languages Examples: Python, JavaScript, Java, C#, C, C++, Go, Rust, Assembly, machine code, … Turing Machines (TMs) are just a new programming Why do we need yet another language programming language? few instructions, few features TMs are a very LOW LEVEL programming language + TMs can be precisely and easily mathematically formalized + TMs make it easier to pose and answer questions ABOUT programs. + We will write our programs in high-level pseudo-code, invoking Church’s Thesis to say this can be turned into a TM Mihir Bellare, UCSD 3 CSE 200: Computability and Complexity

  4. At any point, the machine Turing machine schematic — Is in some state , and q — Its tape head is at some square control In one move, the machine: q — Reads symbol in square under tape head σ head current state moves across tape — Writes, replacing with some symbol σ τ — Moves the tape head one step either left or right — Transitions to another state p The choice of . . . ⊔ ⊔ — What symbol to write 0 1 1 0 1 1 0 τ — the state to transition into p infinite tape — In what direction to move blank symbol is made as a function of , in a way specified by the q , σ configuration transition function of a particular machine. δ 01101 q 10 The machine begins in a special start state . q 0 It halts, either accepting or rejecting, by entering special associated states . This is the only way to halt. q a , q r Mihir Bellare, UCSD 4 CSE 200: Computability and Complexity

  5. Formal definition of a Turing machine A Turing machine (TM) is a 7-tuple , M = ( Q , Σ , Γ , δ , q 0 , q a , q r ) where are finite sets and Q , Σ , Γ 1. is the set of states, with Q ∩ Γ = ∅ Q 2. is the input alphabet, with Σ ⊔ ∉ Σ 3. is the tape alphabet, with Γ Σ ∪ { ⊔ } ⊆ Γ 4. is the transition function δ : Q × Γ → Q × Γ × { L , R } 5. is the start state q 0 ∈ Q 6. is the accept state q a ∈ Q 7. is the reject state q r ∈ Q ∖ { q a } Mihir Bellare, UCSD 5 CSE 200: Computability and Complexity

  6. A simple way to describe how a TM executes is by writing code that runs it The following code executes TM on input : M = ( Q , Σ , Γ , δ , q 0 , q a , q r ) w ∈ Σ * EXEC ( Array stores the content of the tape ) T M , w Variable stores the current state q Parse as ( Q , Σ , Γ , δ , q 0 , q a , q r ) M Variable stores the current position of the tape head i q ← q 0 For do Copy input into first part of tape array j = 1,…, | w | T [ j ] ← w [ j ] w T ; T [ | w | + 1] ← ⊔ i ← 1 While do ( q ∉ { q a , q r }) Loop until current state is or q a q r ; ; ( p , τ , D ) ← δ ( q , T [ i ]) T [ i ] ← τ q ← p Write to tape and update current state Move tape head If then else i ← max(1, i − 1) i ← i + 1 ( D = L ) j ← 1 We get here only if the computation halted While do ( T [ j ] ≠ ⊔ ) ; y [ j ] ← T [ j ] j ← j + 1 Return y In that case, we return the output of the computation y Later, we will view this as a universal TM, writing for the above EXEC( ) U ( ⟨ M , w ⟩ ) M , w For now, it is a way to describe/understand the semantics of TM execution Mihir Bellare, UCSD 6 CSE 200: Computability and Complexity

  7. Formal definition of a Turing machine The computation of is a sequence of configurations M The starting configuration , on input , is w ∈ Σ * q 0 w A Turing machine (TM) is a 7-tuple , M = ( Q , Σ , Γ , δ , q 0 , q a , q r ) where are finite sets and Q , Σ , Γ We say is an accepting configuration if uqv q = q a 1. is the set of states, with Q ∩ Γ = ∅ Q is a rejecting configuration if We say uqv q = q r 2. is the input alphabet, with Σ ⊔ ∉ Σ 3. is the tape alphabet, with Γ Σ ∪ { ⊔ } ⊆ Γ 4. is the transition function δ : Q × Γ → Q × Γ × { L , R } For , and u , v ∈ Γ * a , b , c ∈ Γ p , q ∈ Q 5. is the start state q 0 ∈ Q 6. is the accept state if q a ∈ Q uqbv ⇒ M ucpv δ ( q , b ) = ( p , c , R ) 7. is the reject state q r ∈ Q ∖ { q a } if uaqbv ⇒ M upacv δ ( q , b ) = ( p , c , L ) if ε qbv ⇒ M ε pcv for the configuration of δ ( q , b ) = ( p , c , L ) For and , we write u , v ∈ Γ * q ∈ Q uqv in which M is called the yield relation ⇒ M — tape contents is uv — current state is q — tape head is scanning first symbol of v Mihir Bellare, UCSD 7 CSE 200: Computability and Complexity

  8. We write if there is an integer and a sequence of configurations such that: C ⇒ * M C ′ n ≥ 1 C 1 , …, C n +1 — C 1 = C — and C n +1 = C ′ — for C i ⇒ M C i +1 i = 1,…, n We refer to as the number of steps. n We also write if , in which case the number of steps is 0. C ⇒ * M C ′ C = C ′ We say accepts if there is an accepting configuration such that C ′ q 0 w ⇒ * M C ′ M ( w ) We say rejects if there is a rejecting configuration such that C ′ q 0 w ⇒ * M C ′ M ( w ) We say halts if it either accepts or rejects M ( w ) We say loops if it doesn’t halt M ( w ) That’s a lot of definitions … Hang in there, just a few more … ! Mihir Bellare, UCSD 8 CSE 200: Computability and Complexity

  9. Recall … A language over is a subset Σ L ⊆ Σ * Decision problem associated to language : L Input: x Question: Is ? x ∈ L Examples of languages L = { x ∈ {0,1}* : MSB ( x ) = 1 and LSB ( x ) = 0 } is the language of binary representations of the even positive integers L = { ⟨ M , x ⟩ : M is a TM that halts on input x } is the language of the Halting Problem. L = { ⟨ G ⟩ : G = ([ n ], E ) is a graph over vertex set [ n ] with a path from 1 to n } is the language of the Reachability Problem. Mihir Bellare, UCSD 9 CSE 200: Computability and Complexity

  10. Recall … decides language if for all We say that TM we have: w ∈ Σ * M L — If then accepts w ∈ L M ( w ) — If then rejects A language over is a subset w ∉ L M ( w ) Σ L ⊆ Σ * We say that language is decidable (or recursive ) if there exists a TM L M Decision problem associated to language : L that decides L Input: x Question: Is ? x ∈ L recognizes language if for all We say that TM we have: w ∈ Σ * M L — If then accepts w ∈ L M ( w ) — If then does not accept w ∉ L M ( w ) So what does it do? Reject? 10 Possibly, but that is not the interesting case. The interesting case is that it DOES NOT HALT. That is, it LOOPS. We say that language is recognizable (or recursively enumerable ) if there exists a TM that recognizes L M L We say that language is co-recognizable (or co-ecursively enumerable ) if is recognizable L L Mihir Bellare, UCSD CSE 200: Computability and Complexity

  11. Computability of Functions We say that has output if accepts and its final configuration is M ( w ) y M ( w ) q a y When this happens, we write M ( w ) = y We say that TM computes function if for all we have: f : Σ * → Σ * w ∈ Σ * M M ( w ) = f ( w ) is computable if there exists a TM We say that function that computes f : Σ * → Σ * M f Mihir Bellare, UCSD 11 CSE 200: Computability and Complexity

  12. TM Example Once in your life, you should write a TM program. It is OK if you don’t do it more than once Let L = { x ∈ {0,1}* : MSB ( x ) = 1 and LSB ( x ) = 0 } be the language of binary representations of the even positive integers Claim: The language is decidable. L q σ δ ( q , σ ) Proof: We give a TM that decides M = ( Q , Σ , Γ , δ , q 0 , q a , q r ) L q 0 ( q r ,0, R ) 0 Q = { q 0 , q 1 , q 2 , q a , q r } 0 → 0, R 1 → 1, R q 0 ( q 1 ,1, R ) 1 q 0 ( q r , ⊔ , R ) ⊔ Γ = {0,1, ⊔ } ⊔ → ⊔ , L 1 → 1, R q 1 ( q 1 ,0, R ) 0 Σ = {0,1} q 1 ( q 1 ,1, R ) 1 q 0 q 1 q 1 q 2 ( q 2 , ⊔ , L ) ⊔ 0 → 0, R 0 → 0, R ⊔ → ⊔ , R 1 → 1, R q r q a ⊔ → ⊔ , R Example: q 0 110 ⇒ M 1 q 1 10 ⇒ M 11 q 1 0 ⇒ M 110 q 1 ⇒ M 11 q 2 0 ⇒ M 110 q a Mihir Bellare, UCSD 12 CSE 200: Computability and Complexity

  13. On the Internet, one can find many Turing machine simulators. You can write Turing machines and watch them run. Snapshots of a few of the webpages follow. (The URL is shown on the snapshot.) But there are many more. Try it, could be fun! Mihir Bellare, UCSD 13 CSE 200: Computability and Complexity

  14. Mihir Bellare, UCSD 14 CSE 200: Computability and Complexity

  15. Mihir Bellare, UCSD 15 CSE 200: Computability and Complexity

  16. Mihir Bellare, UCSD 16 CSE 200: Computability and Complexity

Recommend


More recommend