+ - 0:00:00
Notes for current slide
Notes for next slide

https://web.cs.ucdavis.edu/~gusfield/

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

CS420

Introduction to the Theory of Computation

Lecture 19: Turing Machines

Tiago Cogumbreiro

1 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Today we will learn…

  • Recap exercises
  • TM configuration and configuration history
  • TM acceptance
  • Variants of Turing Machines
    • Multi-tape
    • Nondeterministic

Section 3.1, 3.2, and 3.3

Supplementary material

2 / 38

https://web.cs.ucdavis.edu/~gusfield/

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercises

3 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 1

Convert the following grammar into a PDA

A0A1BA \rightarrow 0A1 \mid B

B1BϵB \rightarrow 1B \mid \epsilon

4 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 1

Convert the following grammar into a PDA

A0A1BA \rightarrow 0A1 \mid B

B1BϵB \rightarrow 1B \mid \epsilon

4 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 2

Show that if L1L2L_1 \cup L_2 is not context-free, then either L1L_1 is not context-free or L2L_2 is not context free.

Proof.

5 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 2

Show that if L1L2L_1 \cup L_2 is not context-free, then either L1L_1 is not context-free or L2L_2 is not context free.

Proof.

  1. We know that if L1L_1 is CF and L2L_2 is CF, then L1L2L_1 \cup L_2 is CF.
  2. Apply the contrapositive to (1) and we conclude our proof.
5 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 3

We know that L2={ww=anbncnw is even}L_2 = \{ w \mid w = a^n b^n c^n \lor |w| \text{ is even} \} is not context free.

Show that L3={anbncnn0}L_3 = \{ a^n b^n c^n \mid n \ge 0 \} is not context-free without using the Pumping Lemma for CF or the Theorem of non-CF from Lecture 11.

Proof.

6 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 3

We know that L2={ww=anbncnw is even}L_2 = \{ w \mid w = a^n b^n c^n \lor |w| \text{ is even} \} is not context free.

Show that L3={anbncnn0}L_3 = \{ a^n b^n c^n \mid n \ge 0 \} is not context-free without using the Pumping Lemma for CF or the Theorem of non-CF from Lecture 11.

Proof.

  1. It is easy to see that L2=L3L4L_2 = L_3 \cup L_4 where L4={w w is even}L_4 = \{ w \mid \ |w| \text{ is even}\}.
6 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 3

We know that L2={ww=anbncnw is even}L_2 = \{ w \mid w = a^n b^n c^n \lor |w| \text{ is even} \} is not context free.

Show that L3={anbncnn0}L_3 = \{ a^n b^n c^n \mid n \ge 0 \} is not context-free without using the Pumping Lemma for CF or the Theorem of non-CF from Lecture 11.

Proof.

  1. It is easy to see that L2=L3L4L_2 = L_3 \cup L_4 where L4={w w is even}L_4 = \{ w \mid \ |w| \text{ is even}\}.
  2. We apply the previous theorem of Exercise 1 and get that either L3L_3 is not context free, or L4L_4 is not-context free.
6 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 3

We know that L2={ww=anbncnw is even}L_2 = \{ w \mid w = a^n b^n c^n \lor |w| \text{ is even} \} is not context free.

Show that L3={anbncnn0}L_3 = \{ a^n b^n c^n \mid n \ge 0 \} is not context-free without using the Pumping Lemma for CF or the Theorem of non-CF from Lecture 11.

Proof.

  1. It is easy to see that L2=L3L4L_2 = L_3 \cup L_4 where L4={w w is even}L_4 = \{ w \mid \ |w| \text{ is even}\}.
  2. We apply the previous theorem of Exercise 1 and get that either L3L_3 is not context free, or L4L_4 is not-context free.
  3. But we know that L4L_4 is regular and therefore context-free.
6 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise 3

We know that L2={ww=anbncnw is even}L_2 = \{ w \mid w = a^n b^n c^n \lor |w| \text{ is even} \} is not context free.

Show that L3={anbncnn0}L_3 = \{ a^n b^n c^n \mid n \ge 0 \} is not context-free without using the Pumping Lemma for CF or the Theorem of non-CF from Lecture 11.

Proof.

  1. It is easy to see that L2=L3L4L_2 = L_3 \cup L_4 where L4={w w is even}L_4 = \{ w \mid \ |w| \text{ is even}\}.
  2. We apply the previous theorem of Exercise 1 and get that either L3L_3 is not context free, or L4L_4 is not-context free.
  3. But we know that L4L_4 is regular and therefore context-free.
  4. Thus, L2L_2 is not CF.
6 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Turing Machine:

configuration & configuration history

7 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Turing Machines

Definition 3.3

A Turing machine is a 7-tuple (Q,Σ,Γ,δ,q0,qaccept,qreject)(Q, \Sigma, \Gamma, \delta, q_0, q_{accept}, q_{reject})

  1. QQ set of states
  2. Σ\Sigma input alphabet not containing the blank symbol ␣
  3. Γ\Gamma the tape alphabet, where Γ␣ \in \Gamma and ΣΓ\Sigma \subseteq \Gamma
  4. δ:Q×ΓQ×Γ×{L,R}\delta: Q \times \Gamma \rightarrow Q \times \Gamma \times \{\mathsf{L},\mathsf{R}\} transition function
  5. q0Qq_0 \in Q is the start state
  6. qacceptq_{accept} is the accept state
  7. qrejectq_{reject} is the reject state (qrejectqacceptq_{reject} \neq q_{accept})

To ponder..

  • What is the minimum number of states?
  • Can the input and the tape alphabets be the same?
  • Write a Turing machine with the minimum number of states that recognizes \emptyset
  • Write a Turing machine with the minimum number of states that recognizes Σ\Sigma^\star
8 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Configuration

A configuration is a snapshot of a computation. That is, it contains all information necessary to resume (or replay) a computation from any point in time.

A configuration consists of

  • the tape
  • the head of the tape
  • the current state
9 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Example 2

State Tape
SS 0011
BB X011
BB X011
CC X0Y1
10 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Example 2

State Tape
SS 0011
BB X011
BB X011
CC X0Y1
State Tape
CC X0Y1
SS X0Y1
BB XXY1
BB XXY1
10 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Example 2

State Tape
SS 0011
BB X011
BB X011
CC X0Y1
State Tape
CC X0Y1
SS X0Y1
BB XXY1
BB XXY1
State Tape
CC XXYY
CC XXYY
SS XXYY
DD XXYY
10 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Example 2

State Tape
SS 0011
BB X011
BB X011
CC X0Y1
State Tape
CC X0Y1
SS X0Y1
BB XXY1
BB XXY1
State Tape
CC XXYY
CC XXYY
SS XXYY
DD XXYY
State Tape
DD XXYY

Accept!

Simulate

10 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Example 1 configuration

State Tape Configuration
SS 01110 S 01110
BB x1110 x B 1110
BB xy110 xy B 110
BB xyy10 xyy B 10
BB xyyy0 xyyy B 0
BB xyyyx_ xyyyx B
11 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Configuration history

The configuration history (sequence of configurations), describes all configurations from the initial state until a current state.

Definition

We say that C1C_1 yields C2C_2

Example

Configuration history
S 01110
x B 1110
xy B 110
xyy B 10
xyyy B 0
xyyyx B
12 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Acceptance

A Turing machine

  • accepts a string if there is a configuration history that reaches the accept state.
  • rejects a string if there is a configuration history that reaches the reject state.
  • rejects a string if it never reaches an accept or reject states
    This means that for any configuration of any length, there is no accept nor a reject state.

The acceptance algorithm

  • halts when the machine is in an accept or reject state
    This is different than NFAs/PDAs which can enter and leave the accept state.
13 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise

Give a Turing Machine that recognizes words of an even length.

NFA

14 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

TM that recognizes words of an even length

(online)

15 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Exercise

What language does this TM recognize? (online)

16 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

The Church-Turing thesis

17 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Alan Turing and the Turing Machine

  • No computers at the time (1936)
  • Alan Turing was researching into the foundations of mathematics
  • Original intent: capture all possible processes which can be carried out in computing a number^\dagger
  • What about non-numerical problems?
  • How do Turing machines capture all general and effective procedures which determine whether something is the case or not.

Section 3.3


^\dagger: Devise an algorithm that tests whether a polynomial has an integral root.

18 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

The Church-Turing thesis

  • Any algorithm can be represented by an equivalent Turing machine

  • A problem is computable if, and only if, there exists a Turing Machine that recognizes it.

  • Turing Machines are equivalent to λ\lambda-terms

19 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

The Universal Turing Machine

Or, How do we study the limits of computability

20 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

The Universal Turing Machine

A Turing Machine that is capable of simulating any other Turing Machine

  • Let UU be a TM.
  • Given some TM MM and some input ww, we can encoded as an input string, which we represent as M,w\langle M,w \rangle
U accepts M,w iff M accepts wU \text{ accepts } \langle M,w \rangle \text{ iff } M \text{ accepts }w

Note that the Universal TM is a regular TM. This computability model is expressive enough to simulate itself.

21 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Alan Turing's impact on modern computers

  • Modern computers: von Neumann’s EDVAC design
  • Fundamental idea of the EDVAC design: stored-programs
    Manipulation of programs as data
  • Universal Turing Machines pioneer the idea of stored programs

TM are used to reflect on the limits and potentials of general-purpose computers by engineers, mathematicians and logicians (Module 3)

A single machine simulates all possible machine designs!

Without this idea, computers would have limited scope.

22 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Multi-tape Turing Machine

23 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

The TM tape only grows to the right

  • An important thing to note is that TMs have a tape that grows only to the right
  • In turingmachine.io, the tape actually grows both ways

Are Turing machines that grow both sides more expressive?

Generalizing, are TM with multi-tapes more expressive?

24 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Multi-tape Turing Machine

  • A variation of the Turing Machine with multiple tapes
  • The control may issue each head to move: forward, backward, or skip

25 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Are Turing Machines less expressive

than Multitape Turing Machines?

26 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Turing Machines     \iff Multitape Turing Machines

  • (\Leftarrow) Multitape Turing Machines trivially recognize the same language as Turing Machine
    (let the number of tapes be 1)

  • (\Rightarrow) How can a single tape encode multitape?

27 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Simulating a multitape

Tape encoding

  • Concatenate the three tapes together
  • Delimit each tape with a character that is not in the alphabet \sharp
  • "Tag" the character to encode each tape head (virtual heads), eg a\cdot\text{a}
  • The tape head always sits in the beginning of the tape

28 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Simulating a multitape

Operation

  • To move the ii-th head, read the tape from the beginning until you read \sharp a total of ii times and then seek until you find the marked character

  • If the virtual head ii hits the end of the tape \sharp, then shift the rest of the tape to the right and insert a blank character

29 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Nondeterministic Turing Machines

30 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Nondeterministic Turing Machines (NTM)

A machine can follow more than one transitions for the same input:

δ ⁣:Q×ΓP(Q×Γ×{L,R})\delta \colon Q \times \Gamma \rightarrow {\color{red}\mathcal{P}}(Q\times \Gamma \times \{\mathsf{L},\mathsf{R}\})

Consequence

Deterministic can only have one outgoing edge per character read, a nondeterministic machine can have multiple edges

31 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Configurations in a TM

In a deterministic TM, a configuration history is linear

abc q1 aac -> abcx q2 ac -> abcxa q2 c -> abcx q2 ay

32 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Configurations in a NTM

In a nondeterministic TM, a configuration history is a tree!

33 / 38

https://youtu.be/eMchSJaJJVU?t=340

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Nondeterministic Turing Machines

  • Accept: when any branch reaches qstartq_{start}

  • Reject: when all branches reach qrejectq_{reject}

  • To find a single acceptance state we need to search the computation tree

34 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Are Turing Machines less expressive

than Nondeterministic Turing Machines?

35 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

TM     \iff NTM

  • Given an NTM, say NN we show how to construct a TM, say DD
  • If NN accepts on any branch, then DD halts and accepts
  • If NN rejects on every branch, then DD halts and rejects

Intuition

Simulate all branches of the computation; search for any node with an accept state.

Attention!

Question: If we are searching a search tree, and there may exist infinite branches (due to loops), how should we search the tree: DFS or BFS?

36 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

TM     \iff NTM

  • Given an NTM, say NN we show how to construct a TM, say DD
  • If NN accepts on any branch, then DD halts and accepts
  • If NN rejects on every branch, then DD halts and rejects

Intuition

Simulate all branches of the computation; search for any node with an accept state.

Attention!

Question: If we are searching a search tree, and there may exist infinite branches (due to loops), how should we search the tree: DFS or BFS?

Bread-First Search will ensure our search is not caught in a never-ending branch.

36 / 38

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Addressing configuration history

  • We can use a sequence of numbers to uniquely identify each node of the configuration history

Unique paths

  • 11
  • 223
  • 2221
  • 221
  • 21
  • 2311
  • 31
37 / 38

https://youtu.be/eMchSJaJJVU?t=897

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Using a TM to simulate a NTM

Use 3 tapes

  1. Initial input: One tape for the input
  2. Simulation tape: Where we will be executing an address
  3. Address tape: An ever growing number that uniquely identifies where we are in the tree

How many choices at each step?

  1. Copy tape 1 to tape 2
  2. Simulate TM with address from the address tape; if it reaches an accepted state, then ACCEPT, otherwise continue
  3. Increment address (next BFS-wise) and go to 1
38 / 38
  • at every node the number of outgoing edges is bounded by the total number of states
  • let BB be the maximum number of outgoing edges of all states
  • there is a finite number of symbols we can use to represent the choice^\dagger

^\dagger: Recall that the alphabet must always be a finite set, if the number of choices was unbounded, then we would not be able to encode as a value being stored in the tape.

CS420  ☽  Turing Machines  ☽  Lecture 19  ☽  Tiago Cogumbreiro

Today we will learn…

  • Recap exercises
  • TM configuration and configuration history
  • TM acceptance
  • Variants of Turing Machines
    • Multi-tape
    • Nondeterministic

Section 3.1, 3.2, and 3.3

Supplementary material

2 / 38

https://web.cs.ucdavis.edu/~gusfield/

Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow