Understanding Turing Machines: Introduction, Transition Rules, and Examples, Study notes of Computer Science

An introduction to turing machines, an abstract model of a computer designed by alan turing. It covers the concept of a turing machine, its components, and the rules of transition. The document also includes examples of turing machines and their traces, as well as an explanation of how turing machines can be used as acceptors.

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-xzy
koofers-user-xzy 🇺🇸

10 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
18 Turing Machines
1. Turing Machines
2. Nondeterministic Turing Machines
415
18.1 Turing Machines
Introduced by Alan Turing
Abstract machine with many features of computer
Designed before the stored program computer!
No memory limit!
An infinite tape, and a tape reader, that reads one
symbol at a time.
416
Turing Machines (2)
0 1 2 3 4 5 6 ...
...
A quintuple M= (Q, Σ,Γ, δ, q0)
A finite set of states Q.
A finite set Γ, the tape alphab et, which includes blank
B
A subset ΣΓ {B}called the input alphabet
A partial transition function δ:Q×ΓQ×Γ× {L, R}
Astart state q0Q
417
pf3
pf4
pf5
pf8

Partial preview of the text

Download Understanding Turing Machines: Introduction, Transition Rules, and Examples and more Study notes Computer Science in PDF only on Docsity!

∞ 18 Turing Machines

  1. Turing Machines
  2. Nondeterministic Turing Machines

415

∞ 18.1 Turing Machines

  • Introduced by Alan Turing
  • Abstract machine with many features of computer
  • Designed before the stored program computer!
  • No memory limit!
  • An infinite tape, and a tape reader, that reads one symbol at a time.

416

∞ Turing Machines (2)

0 1 2 3 4 5 6 ...

...

A quintuple M = (Q, Σ, Γ, δ, q0)

  • A finite set of states Q.
  • A finite set Γ, the tape alphabet, which includes blank B
  • A subset Σ ⊆ Γ − {B} called the input alphabet
  • A partial transition function δ : Q × Γ → Q × Γ × {L, R}
  • A start state q 0 ∈ Q

∞ 18.1.1 Turing Machines: Initial

0 1 2 n

...

q

c1 c2 ... cn B B ...

...

B

Computation begins with

  • An input string s = c 1 · · · cn in Σ∗^ on the tape from position 1 to n
  • The remaining tape blank (filled with B)
  • Initial state q 0

418

∞ 18.1.2 Turing Machines: Transition

... ...

q

x ... y ...

q’

  • Machine in state q reading tape symbol x ∈ Γ
  • δ(q, x) = [q′, y, d]
  • Transitions have three parts:
    • Change the state to q′
    • Write symbol y on square scanned by tape head
    • Move head left or right (depending on direction d)

419

∞ 18.1.3 Turing Machines: Final

... ...

q

x

  • Machine halts if in state q reading tape symbol x ∈ Γ there is no δ(q, x) = [q′, y, d]
  • Remember δ is a partial function.
  • Output is the result remaining on the tape.
  • Machine halts abnormally if the head moves off the left end of the tape.

∞ 18.1.7 Turing Machines: Another Example

Machine to add 1 to a binary number

q0 B/B R q1 B/B L q

0/0 R 1/1 R

0/1 R q

1/0 L

B/1 R

q 0 B 001 B q 0 B 11 B Bq 1001 B Bq 111 B B 0 q 101 B B 1 q 11 B B 00 q 11 B B 11 q 1 B B 001 q 1 B B 1 q 21 B B 00 q 21 B Bq 210 B B 0 q 200 B q 2 B 00 B B 01 q 30 B 1 q 300 B

424

∞ 18.1.8 Turing Machines as Acceptors

0 1 2 3 4 5 6 ...

...

A sextuple M = (Q, Σ, Γ, δ, q 0 , F )

  • F is the set of final states.
  • If M halts in a state q ∈ F then the input is accepted
  • If M halts in a state q 6 ∈ F the input is rejected.
  • L(M ) is the set of strings accepted by M.

425

∞ Turing Machines as Acceptors (2)

q

0/0 R 1/1 R

B/B R (^) q1 0/B R

1/B R

0/0 R 1/1 R

q

q

q

q

B/B L

B/B L

0/B L (^) q

0/0 L 1/1 L

1/B L

B/B R

A machine that accepts a string which is an even length palindrome of 0’s and 1’s. e.g 00 , 0110 , 0001001000 ∈ L(M )

∞ Exercise

Modify the even length palendrome machine to accept odd length palindromes too e.g. 101

q

0/0 R 1/1 R

B/B R (^) q1 0/B R

1/B R

0/0 R 1/1 R

q

q

q

q

B/B L

B/B L

0/B L (^) q

0/0 L 1/1 L

1/B L

B/B R

427

∞ 18.1.9 Turing Machines in Prolog

  • given delta(State,Sym,NewState,NewSym,LR)
  • (maybe) given accepting(State) for accepting states
  • We can write a Turing machine simulator in Prolog
  • So Prolog can do anything a Turing machine can delta(q0, ’B’, q1, ’B’, right). delta(q1, ’B’, q2, ’B’, left). delta(q1, a, q1, b, right). delta(q1, b, q1, a, right). delta(q2, a, q2, a, left). delta(q2, b, q2, b, left).

initial(q0).

428

∞ Main Code

run(Input, Output, State) :- initial(State0), tape_list_position(Tape0, Input, 0), run(State0, Tape0, State, Tape), tape_list_position(Tape, Output, _).

recognize(Input) :- run(Input, _, State), accepting(State).

∞ Example

q0 B/B R^ q1 c/c R

c/c L

q

q

q

q

a/a R

b/b L

b/b R (^) q

a/a L

a/a R b/b R c/c R

A machine which accepts strings of a’s, b’s and c’s where there is a c followed by or preceded by ab.

433

∞ Example (2)

q 0 BacabB 1 q 0 BacabB 1 q 0 BacabB 2 Bq 1 acabB 1 Bq 1 acabB 1 Bq 1 acabB 2 Baq 1 cabB 1 Baq 1 cabB 1 Baq 1 cabB 3 Bacq 1 abB 1 Bacq 2 abB 2 Bq 3 acabB Bacaq 1 bB 1 Bacaq 4 bB 1 Bacabq 1 B ` Bacabq 6 B

First and third do not accept, but second does That’s good enough: the machine accepts

434

436

437