Top Banner
83

BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Jul 10, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

BBM401-Lecture 6: Turing Machines

Lecturer: Lale Özkahya

Resources for the presentation:https://courses.engr.illinois.edu/cs373/fa2010/lectureshttps://courses.engr.illinois.edu/cs498374/lectures.html

Page 2: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

David  Hilbert  •  Early  1900s  –  crisis  in  math  founda@ons  – a[empts  to  formalize  resulted  in  paradoxes,  etc.  

•  1920,    Hilbert’s  Program:        “mechanize”  mathema@cs  

•  Finite  axioms,  inference  rules  turn  crank,  determine  truth  needed:  axioms  consistent  &  complete  

This  slide  recycled  from  Lecture  1  

Page 3: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Kurt  Gödel  

•  German  logician,  at  age  25  (1931)  proved:  “There  are  true  statements  that  can’t  be  proved”      

 (i.e.,  “no”  to  Hilbert)  

•  Shook  the  founda@ons  of  – mathema@cs  – philosophy  – science  – everything  

This  slide  recycled  from  Lecture  1  

Page 4: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Alan  Turing  

•  Bri@sh  mathema@cian  – cryptanalysis  during  WWII  

– arguably,  father  of  AI,  Theory  – several  books,  movies  

•  Defined  “computer”,  “program”  

and  (1936)  provided  founda@ons  for  inves@ga@ng  fundamental  ques@on  of  what  is  computable,  what  is  not  computable.    

This  slide  recycled  from  Lecture  1  

Page 5: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

•  DFA  with  (infinite)  tape.  •  One  move:      read,  write,  move,  change  state.  

Page 6: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing Machines

X1 X2 · · · Xn t t

finite-statecontrol

tape

head

Unrestricted memory: an infinite tape

A finite state machine that reads/writes symbols on the tapeCan read/write anywhere on the tapeTape is infinite in one direction only (other variants possible)

Initially, tape has input and the machine is reading (i.e., tapehead is on) the leftmost input symbol.Transition (based on current state and symbol under head):

Change control stateOverwrite a new symbol on the tape cell under the headMove the head left, or right.

Agha-Viswanathan CS373

Page 7: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing Machines

X1 X2 · · · Xn t t

finite-statecontrol

tape

head

Unrestricted memory: an infinite tapeA finite state machine that reads/writes symbols on the tape

Can read/write anywhere on the tapeTape is infinite in one direction only (other variants possible)

Initially, tape has input and the machine is reading (i.e., tapehead is on) the leftmost input symbol.Transition (based on current state and symbol under head):

Change control stateOverwrite a new symbol on the tape cell under the headMove the head left, or right.

Agha-Viswanathan CS373

Page 8: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing Machines

X1 X2 · · · Xn t t

finite-statecontrol

tape

head

Unrestricted memory: an infinite tapeA finite state machine that reads/writes symbols on the tapeCan read/write anywhere on the tape

Tape is infinite in one direction only (other variants possible)

Initially, tape has input and the machine is reading (i.e., tapehead is on) the leftmost input symbol.Transition (based on current state and symbol under head):

Change control stateOverwrite a new symbol on the tape cell under the headMove the head left, or right.

Agha-Viswanathan CS373

Page 9: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing Machines

X1 X2 · · · Xn t t

finite-statecontrol

tape

head

Unrestricted memory: an infinite tapeA finite state machine that reads/writes symbols on the tapeCan read/write anywhere on the tapeTape is infinite in one direction only (other variants possible)

Initially, tape has input and the machine is reading (i.e., tapehead is on) the leftmost input symbol.Transition (based on current state and symbol under head):

Change control stateOverwrite a new symbol on the tape cell under the headMove the head left, or right.

Agha-Viswanathan CS373

Page 10: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing Machines

X1 X2 · · · Xn t t

finite-statecontrol

tape

head

Unrestricted memory: an infinite tapeA finite state machine that reads/writes symbols on the tapeCan read/write anywhere on the tapeTape is infinite in one direction only (other variants possible)

Initially, tape has input and the machine is reading (i.e., tapehead is on) the leftmost input symbol.

Transition (based on current state and symbol under head):Change control stateOverwrite a new symbol on the tape cell under the headMove the head left, or right.

Agha-Viswanathan CS373

Page 11: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing Machines

X1 X2 · · · Xn t t

finite-statecontrol

tape

head

Unrestricted memory: an infinite tapeA finite state machine that reads/writes symbols on the tapeCan read/write anywhere on the tapeTape is infinite in one direction only (other variants possible)

Initially, tape has input and the machine is reading (i.e., tapehead is on) the leftmost input symbol.Transition (based on current state and symbol under head):

Change control stateOverwrite a new symbol on the tape cell under the headMove the head left, or right.

Agha-Viswanathan CS373

Page 12: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example

Let M1 be a Turing machine that tests if an input string is in the

language B, where B = {w#w |w ∈ {0, 1}∗}.M1 zig-zags across the tape: if no # is found, reject. Cross o�

symbols as they are checked to keep track.

When all symbols to the left of the # have been crossed o�, check

for any remaining symbols to the right of the #. If any symbol

remained, reject, otherwise accept.

Page 13: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 14: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 15: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 16: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 17: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 18: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 19: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 20: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Turing MachinesFormal Definition

A Turing machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q is a finite set of control states

Σ is a finite set of input symbols

Γ ⊇ Σ is a finite set of tape symbols. Also, a blank symbolt ∈ Γ \ Σ

q0 ∈ Q is the initial state

qacc ∈ Q is the accept state

qrej ∈ Q is the reject state, where qrej 6= qacc

δ : Q × Γ→ Q × Γ× {L,R} is the transition function.Given the current state and symbol being read, the transitionfunction describes the next state, symbol to be written anddirection (left or right) in which to move the tape head.

Agha-Viswanathan CS373

Page 21: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Transition Function

q1 q2

X → Y , L

δ(q1,X ) = (q2,Y , L): Read transition as “the machine when instate q1, and reading symbol X under the tape head, will move tostate q2, overwrite X with Y , and move its tape head to the left”

In fact δ : (Q \ {qacc, qrej})× Γ→ Q × Γ× {L,R}. Notransition defined after reaching qacc or qrej

Transitions are deterministic

Convention: if δ(q,X ) is not explicitly specified, it is taken asleading to qrej, i.e., say δ(q,X ) = (qrej,t,R)

Agha-Viswanathan CS373

Page 22: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Transition Function

q1 q2

X → Y , L

δ(q1,X ) = (q2,Y , L): Read transition as “the machine when instate q1, and reading symbol X under the tape head, will move tostate q2, overwrite X with Y , and move its tape head to the left”

In fact δ : (Q \ {qacc, qrej})× Γ→ Q × Γ× {L,R}.

Notransition defined after reaching qacc or qrej

Transitions are deterministic

Convention: if δ(q,X ) is not explicitly specified, it is taken asleading to qrej, i.e., say δ(q,X ) = (qrej,t,R)

Agha-Viswanathan CS373

Page 23: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Transition Function

q1 q2

X → Y , L

δ(q1,X ) = (q2,Y , L): Read transition as “the machine when instate q1, and reading symbol X under the tape head, will move tostate q2, overwrite X with Y , and move its tape head to the left”

In fact δ : (Q \ {qacc, qrej})× Γ→ Q × Γ× {L,R}. Notransition defined after reaching qacc or qrej

Transitions are deterministic

Convention: if δ(q,X ) is not explicitly specified, it is taken asleading to qrej, i.e., say δ(q,X ) = (qrej,t,R)

Agha-Viswanathan CS373

Page 24: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Transition Function

q1 q2

X → Y , L

δ(q1,X ) = (q2,Y , L): Read transition as “the machine when instate q1, and reading symbol X under the tape head, will move tostate q2, overwrite X with Y , and move its tape head to the left”

In fact δ : (Q \ {qacc, qrej})× Γ→ Q × Γ× {L,R}. Notransition defined after reaching qacc or qrej

Transitions are deterministic

Convention: if δ(q,X ) is not explicitly specified, it is taken asleading to qrej, i.e., say δ(q,X ) = (qrej,t,R)

Agha-Viswanathan CS373

Page 25: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Transition Function

q1 q2

X → Y , L

δ(q1,X ) = (q2,Y , L): Read transition as “the machine when instate q1, and reading symbol X under the tape head, will move tostate q2, overwrite X with Y , and move its tape head to the left”

In fact δ : (Q \ {qacc, qrej})× Γ→ Q × Γ× {L,R}. Notransition defined after reaching qacc or qrej

Transitions are deterministic

Convention: if δ(q,X ) is not explicitly specified, it is taken asleading to qrej, i.e., say δ(q,X ) = (qrej,t,R)

Agha-Viswanathan CS373

Page 26: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Configurations

The configuration (or “instantaneous description”) contains all theinformation to exactly capture the “current state of thecomputation”

X1X2 · · ·Xi−1qXi · · ·Xn

Includes the current state: q

Position of the tape head: Scanning i th symbol Xi

Contents of all the tape cells till the rightmost nonblanksymbol. This is will always be finitely many cells. Thosesymbols are X1X2 · · ·Xn, where Xn 6= t unless the tape headis on it.

Agha-Viswanathan CS373

Page 27: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Configurations

The configuration (or “instantaneous description”) contains all theinformation to exactly capture the “current state of thecomputation”

X1X2 · · ·Xi−1qXi · · ·Xn

Includes the current state

: q

Position of the tape head: Scanning i th symbol Xi

Contents of all the tape cells till the rightmost nonblanksymbol. This is will always be finitely many cells. Thosesymbols are X1X2 · · ·Xn, where Xn 6= t unless the tape headis on it.

Agha-Viswanathan CS373

Page 28: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Configurations

The configuration (or “instantaneous description”) contains all theinformation to exactly capture the “current state of thecomputation”

X1X2 · · ·Xi−1qXi · · ·Xn

Includes the current state: q

Position of the tape head: Scanning i th symbol Xi

Contents of all the tape cells till the rightmost nonblanksymbol. This is will always be finitely many cells. Thosesymbols are X1X2 · · ·Xn, where Xn 6= t unless the tape headis on it.

Agha-Viswanathan CS373

Page 29: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Configurations

The configuration (or “instantaneous description”) contains all theinformation to exactly capture the “current state of thecomputation”

X1X2 · · ·Xi−1qXi · · ·Xn

Includes the current state: q

Position of the tape head

: Scanning i th symbol Xi

Contents of all the tape cells till the rightmost nonblanksymbol. This is will always be finitely many cells. Thosesymbols are X1X2 · · ·Xn, where Xn 6= t unless the tape headis on it.

Agha-Viswanathan CS373

Page 30: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Configurations

The configuration (or “instantaneous description”) contains all theinformation to exactly capture the “current state of thecomputation”

X1X2 · · ·Xi−1qXi · · ·Xn

Includes the current state: q

Position of the tape head: Scanning i th symbol Xi

Contents of all the tape cells till the rightmost nonblanksymbol. This is will always be finitely many cells. Thosesymbols are X1X2 · · ·Xn, where Xn 6= t unless the tape headis on it.

Agha-Viswanathan CS373

Page 31: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Configurations

The configuration (or “instantaneous description”) contains all theinformation to exactly capture the “current state of thecomputation”

X1X2 · · ·Xi−1qXi · · ·Xn

Includes the current state: q

Position of the tape head: Scanning i th symbol Xi

Contents of all the tape cells till the rightmost nonblanksymbol. This is will always be finitely many cells.

Thosesymbols are X1X2 · · ·Xn, where Xn 6= t unless the tape headis on it.

Agha-Viswanathan CS373

Page 32: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Configurations

The configuration (or “instantaneous description”) contains all theinformation to exactly capture the “current state of thecomputation”

X1X2 · · ·Xi−1qXi · · ·Xn

Includes the current state: q

Position of the tape head: Scanning i th symbol Xi

Contents of all the tape cells till the rightmost nonblanksymbol. This is will always be finitely many cells. Thosesymbols are X1X2 · · ·Xn, where Xn 6= t unless the tape headis on it.

Agha-Viswanathan CS373

Page 33: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Special Configurations

Start configuration: q0X1 · · ·Xn, where the input is X1 · · ·Xn

Accept and reject configurations: The state q is qacc or qrej,respectively . These configurations are halting configurations,because there are no transitions possible from them.

Agha-Viswanathan CS373

Page 34: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Special Configurations

Start configuration: q0X1 · · ·Xn, where the input is X1 · · ·Xn

Accept and reject configurations: The state q is qacc or qrej,respectively

. These configurations are halting configurations,because there are no transitions possible from them.

Agha-Viswanathan CS373

Page 35: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Special Configurations

Start configuration: q0X1 · · ·Xn, where the input is X1 · · ·Xn

Accept and reject configurations: The state q is qacc or qrej,respectively . These configurations are halting configurations,because there are no transitions possible from them.

Agha-Viswanathan CS373

Page 36: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 37: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then

qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 38: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 39: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then

X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 40: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 41: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 42: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then

X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 43: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Single Step

Definition

We say one configuration (c1) yields another (c2), denoted asc1 ` c2, if one of the following holds.

If δ(q,Xi ) = (p,Y , L) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−2pXi−1YXi+1 · · ·Xn

Boundary Cases:

If i = 1 then qX1X2 · · ·Xn ` pYX2 · · ·Xn

If i = n and Y = t then X1 · · ·Xn−1qXn ` X1 · · · pXn−1

If δ(q,Xi ) = (p,Y ,R) then

X1X2 · · ·Xi−1qXiXi+1 · · ·Xn ` X1X2 · · ·Xi−1YpXi+1 · · ·Xn

Boundary Case:

If i = n then X1 · · ·Xn−1qXn ` X1 · · ·Xn−1Ypt

Agha-Viswanathan CS373

Page 44: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Computations

Definition

We say c1`∗c2 if the machine can move from c1 to c2 in zero ormore steps.

i.e., c1 = c2 or there exist c′1, . . . ,c′n such that

c1 = c′1, c2 = c′n and c′i ` c′i+1

Agha-Viswanathan CS373

Page 45: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Computations

Definition

We say c1`∗c2 if the machine can move from c1 to c2 in zero ormore steps. i.e., c1 = c2 or there exist c′1, . . . ,c

′n such that

c1 = c′1, c2 = c′n and c′i ` c′i+1

Agha-Viswanathan CS373

Page 46: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Acceptance and Recognition

Definition

A Turing machine M accepts w iff q0w`∗α1qaccα2, where α1, α2

are some strings. In other words, the machine M when started inits intial state and with w as input, reaches the accept state.

Note: The machine may not read all the symbols in w . It maypass back and forth over some symbols of w several times. Finally,w may have been completely overwritten.

Definition

For a Turing machine M, define L(M) = {w |M accepts w}. M issaid to accept or recognize a language L if L = L(M).

Agha-Viswanathan CS373

Page 47: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Acceptance and Recognition

Definition

A Turing machine M accepts w iff q0w`∗α1qaccα2, where α1, α2

are some strings. In other words, the machine M when started inits intial state and with w as input, reaches the accept state.

Note: The machine may not read all the symbols in w . It maypass back and forth over some symbols of w several times. Finally,w may have been completely overwritten.

Definition

For a Turing machine M, define L(M) = {w |M accepts w}. M issaid to accept or recognize a language L if L = L(M).

Agha-Viswanathan CS373

Page 48: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Acceptance and Recognition

Definition

A Turing machine M accepts w iff q0w`∗α1qaccα2, where α1, α2

are some strings. In other words, the machine M when started inits intial state and with w as input, reaches the accept state.

Note: The machine may not read all the symbols in w . It maypass back and forth over some symbols of w several times. Finally,w may have been completely overwritten.

Definition

For a Turing machine M, define L(M) = {w |M accepts w}.

M issaid to accept or recognize a language L if L = L(M).

Agha-Viswanathan CS373

Page 49: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Acceptance and Recognition

Definition

A Turing machine M accepts w iff q0w`∗α1qaccα2, where α1, α2

are some strings. In other words, the machine M when started inits intial state and with w as input, reaches the accept state.

Note: The machine may not read all the symbols in w . It maypass back and forth over some symbols of w several times. Finally,w may have been completely overwritten.

Definition

For a Turing machine M, define L(M) = {w |M accepts w}. M issaid to accept or recognize a language L if L = L(M).

Agha-Viswanathan CS373

Page 50: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

Design a TM to accept the language L = {0n1n | n > 0}

High level description

On input string w

while there are unmarked 0s, do

Mark the left most 0

Scan right till the leftmost unmarked 1;

if there is no such 1 then crash

Mark the leftmost 1

done

Check to see that there are no unmarked 1s;

if there are then crash

accept

Agha-Viswanathan CS373

Page 51: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

Design a TM to accept the language L = {0n1n | n > 0}

High level description

On input string w

while there are unmarked 0s, do

Mark the left most 0

Scan right till the leftmost unmarked 1;

if there is no such 1 then crash

Mark the leftmost 1

done

Check to see that there are no unmarked 1s;

if there are then crash

accept

Agha-Viswanathan CS373

Page 52: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 53: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 `

Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 54: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 `

A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 55: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 `

Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 56: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `

q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 57: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 `

Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 58: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 `

AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 59: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 `

AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 60: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 `

AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 61: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `

Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 62: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB `

AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 63: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB `

AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 64: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B `

AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 65: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t `

AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 66: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacct

Rejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 67: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t `

A0 t qrejt

Agha-Viswanathan CS373

Page 68: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 1: TM for {0n1n | n > 0}

q0 q1 q2

q3 qacc

0→ A,R

0 → 0,RB → B,R

1→ B, L

B → B, L0→ 0, L

A→ A,R

B → B,R

B → B,R

t → t,R

Accepts input 0011: q00011 ` Aq1011 ` A0q111 ` Aq20B1 `q2A0B1 ` Aq00B1 ` AAq1B1 ` AABq11 ` AAq2BB `Aq2ABB ` AAq0BB ` AABq3B ` AABBq3t ` AABBtqacctRejects input 00: q000 ` Aq10 ` A0q1t ` A0 t qrejt

Agha-Viswanathan CS373

Page 69: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example: {0n1n | n > 0}Formal Definition

The machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q = {q0, q1, q2, q3, qacc, qrej}Σ = {0, 1}, and Γ = {0, 1,A,B,t}δ is given as follows

δ(q0, 0) = (q1,A,R) δ(q0,B) = (q3,B,R)δ(q1, 0) = (q1, 0,R) δ(q1,B) = (q1,B,R)δ(q1, 1) = (q2,B, L) δ(q2,B) = (q2,B, L)δ(q2, 0) = (q2, 0, L) δ(q2,A) = (q0,A,R)δ(q3,B) = (q3,B,R) δ(q3,t) = (qacc,t,R)

In all other cases, δ(q,X ) = (qrej,t,R). So for example,δ(q0, 1) = (qrej,t,R).

Agha-Viswanathan CS373

Page 70: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example: {0n1n | n > 0}Formal Definition

The machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q = {q0, q1, q2, q3, qacc, qrej}

Σ = {0, 1}, and Γ = {0, 1,A,B,t}δ is given as follows

δ(q0, 0) = (q1,A,R) δ(q0,B) = (q3,B,R)δ(q1, 0) = (q1, 0,R) δ(q1,B) = (q1,B,R)δ(q1, 1) = (q2,B, L) δ(q2,B) = (q2,B, L)δ(q2, 0) = (q2, 0, L) δ(q2,A) = (q0,A,R)δ(q3,B) = (q3,B,R) δ(q3,t) = (qacc,t,R)

In all other cases, δ(q,X ) = (qrej,t,R). So for example,δ(q0, 1) = (qrej,t,R).

Agha-Viswanathan CS373

Page 71: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example: {0n1n | n > 0}Formal Definition

The machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q = {q0, q1, q2, q3, qacc, qrej}Σ = {0, 1}, and

Γ = {0, 1,A,B,t}δ is given as follows

δ(q0, 0) = (q1,A,R) δ(q0,B) = (q3,B,R)δ(q1, 0) = (q1, 0,R) δ(q1,B) = (q1,B,R)δ(q1, 1) = (q2,B, L) δ(q2,B) = (q2,B, L)δ(q2, 0) = (q2, 0, L) δ(q2,A) = (q0,A,R)δ(q3,B) = (q3,B,R) δ(q3,t) = (qacc,t,R)

In all other cases, δ(q,X ) = (qrej,t,R). So for example,δ(q0, 1) = (qrej,t,R).

Agha-Viswanathan CS373

Page 72: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example: {0n1n | n > 0}Formal Definition

The machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q = {q0, q1, q2, q3, qacc, qrej}Σ = {0, 1}, and Γ = {0, 1,A,B,t}

δ is given as follows

δ(q0, 0) = (q1,A,R) δ(q0,B) = (q3,B,R)δ(q1, 0) = (q1, 0,R) δ(q1,B) = (q1,B,R)δ(q1, 1) = (q2,B, L) δ(q2,B) = (q2,B, L)δ(q2, 0) = (q2, 0, L) δ(q2,A) = (q0,A,R)δ(q3,B) = (q3,B,R) δ(q3,t) = (qacc,t,R)

In all other cases, δ(q,X ) = (qrej,t,R). So for example,δ(q0, 1) = (qrej,t,R).

Agha-Viswanathan CS373

Page 73: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example: {0n1n | n > 0}Formal Definition

The machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q = {q0, q1, q2, q3, qacc, qrej}Σ = {0, 1}, and Γ = {0, 1,A,B,t}δ is given as follows

δ(q0, 0) = (q1,A,R) δ(q0,B) = (q3,B,R)δ(q1, 0) = (q1, 0,R) δ(q1,B) = (q1,B,R)δ(q1, 1) = (q2,B, L) δ(q2,B) = (q2,B, L)δ(q2, 0) = (q2, 0, L) δ(q2,A) = (q0,A,R)δ(q3,B) = (q3,B,R) δ(q3,t) = (qacc,t,R)

In all other cases, δ(q,X ) = (qrej,t,R).

So for example,δ(q0, 1) = (qrej,t,R).

Agha-Viswanathan CS373

Page 74: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example: {0n1n | n > 0}Formal Definition

The machine is M = (Q,Σ, Γ, δ, q0, qacc, qrej) where

Q = {q0, q1, q2, q3, qacc, qrej}Σ = {0, 1}, and Γ = {0, 1,A,B,t}δ is given as follows

δ(q0, 0) = (q1,A,R) δ(q0,B) = (q3,B,R)δ(q1, 0) = (q1, 0,R) δ(q1,B) = (q1,B,R)δ(q1, 1) = (q2,B, L) δ(q2,B) = (q2,B, L)δ(q2, 0) = (q2, 0, L) δ(q2,A) = (q0,A,R)δ(q3,B) = (q3,B,R) δ(q3,t) = (qacc,t,R)

In all other cases, δ(q,X ) = (qrej,t,R). So for example,δ(q0, 1) = (qrej,t,R).

Agha-Viswanathan CS373

Page 75: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}Design a TM to accept the language L = {0n1n2n | n > 0}

High level description

On input string w

while there are unmarked 0s, do

Mark the left most 0

Scan right to reach the leftmost unmarked 1;

if there is no such 1 then crash

Mark the leftmost 1

Scan right to reach the leftmost unmarked 2;

if there is no such 2 then crash

Mark the leftmost 2

done

Check to see that there are no unmarked 1s or 2s;

if there are then crash

accept

Agha-Viswanathan CS373

Page 76: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}Design a TM to accept the language L = {0n1n2n | n > 0}

High level description

On input string w

while there are unmarked 0s, do

Mark the left most 0

Scan right to reach the leftmost unmarked 1;

if there is no such 1 then crash

Mark the leftmost 1

Scan right to reach the leftmost unmarked 2;

if there is no such 2 then crash

Mark the leftmost 2

done

Check to see that there are no unmarked 1s or 2s;

if there are then crash

accept

Agha-Viswanathan CS373

Page 77: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}

q0 q1 q2 q3

q4 qacc

0→A,R

0→0,RB→B,R

1→B,R

1→1,RC→C ,R

2→C , L

C→C , L1→1, LB→B, L0→0, L

A→A,R

B→B,R

B→B,RC→C ,R

t→t,R

e.g.: q0001122`∗A0Bq31C2 `∗q3A0B1C2 ` Aq00B1C2`∗AAq0BBCC `∗AABBCCq4t ` AABBCCtqacct

Agha-Viswanathan CS373

Page 78: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}

q0 q1 q2 q3

q4 qacc

0→A,R

0→0,RB→B,R

1→B,R

1→1,RC→C ,R

2→C , L

C→C , L1→1, LB→B, L0→0, L

A→A,R

B→B,R

B→B,RC→C ,R

t→t,R

e.g.: q0001122`∗A0Bq31C2

`∗q3A0B1C2 ` Aq00B1C2`∗AAq0BBCC `∗AABBCCq4t ` AABBCCtqacct

Agha-Viswanathan CS373

Page 79: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}

q0 q1 q2 q3

q4 qacc

0→A,R

0→0,RB→B,R

1→B,R

1→1,RC→C ,R

2→C , L

C→C , L1→1, LB→B, L0→0, L

A→A,R

B→B,R

B→B,RC→C ,R

t→t,R

e.g.: q0001122`∗A0Bq31C2 `∗q3A0B1C2

` Aq00B1C2`∗AAq0BBCC `∗AABBCCq4t ` AABBCCtqacct

Agha-Viswanathan CS373

Page 80: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}

q0 q1 q2 q3

q4 qacc

0→A,R

0→0,RB→B,R

1→B,R

1→1,RC→C ,R

2→C , L

C→C , L1→1, LB→B, L0→0, L

A→A,R

B→B,R

B→B,RC→C ,R

t→t,R

e.g.: q0001122`∗A0Bq31C2 `∗q3A0B1C2 ` Aq00B1C2

`∗AAq0BBCC `∗AABBCCq4t ` AABBCCtqacct

Agha-Viswanathan CS373

Page 81: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}

q0 q1 q2 q3

q4 qacc

0→A,R

0→0,RB→B,R

1→B,R

1→1,RC→C ,R

2→C , L

C→C , L1→1, LB→B, L0→0, L

A→A,R

B→B,R

B→B,RC→C ,R

t→t,R

e.g.: q0001122`∗A0Bq31C2 `∗q3A0B1C2 ` Aq00B1C2`∗AAq0BBCC

`∗AABBCCq4t ` AABBCCtqacct

Agha-Viswanathan CS373

Page 82: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}

q0 q1 q2 q3

q4 qacc

0→A,R

0→0,RB→B,R

1→B,R

1→1,RC→C ,R

2→C , L

C→C , L1→1, LB→B, L0→0, L

A→A,R

B→B,R

B→B,RC→C ,R

t→t,R

e.g.: q0001122`∗A0Bq31C2 `∗q3A0B1C2 ` Aq00B1C2`∗AAq0BBCC `∗AABBCCq4t

` AABBCCtqacct

Agha-Viswanathan CS373

Page 83: BBM401-Lecture 6: Turing Machinesozkahya/classes/... · Turing Machines X 1 X 2 X n t t nite-state control tape head Unrestricted memory: an in nite tape A nite state machine that

Example 2: TM for {0n1n2n | n > 0}

q0 q1 q2 q3

q4 qacc

0→A,R

0→0,RB→B,R

1→B,R

1→1,RC→C ,R

2→C , L

C→C , L1→1, LB→B, L0→0, L

A→A,R

B→B,R

B→B,RC→C ,R

t→t,R

e.g.: q0001122`∗A0Bq31C2 `∗q3A0B1C2 ` Aq00B1C2`∗AAq0BBCC `∗AABBCCq4t ` AABBCCtqacct

Agha-Viswanathan CS373