Lab 7 - TM

Lab Session #7 #

Agenda #

  • Turing Machine
    • Formal definition
    • Example
    • Exercices

Turing Machine #

Formal definition #

A Turing Machine (TM) with k-tapes is a tuple

T=Q,I,Γ,δ,q0,Z0,F T = ⟨Q, I, Γ, δ, q_0, Z_0, F⟩

where:

  • QQ is a finite set of states;

  • II is the input language;

  • ΓΓ is the memory alphabet;

  • δδ is the transition function;

  • q0Qq_0 \in Q is the initial state;

  • Z0ΓZ_0 \in Γ is the initial memory symbol;

  • FQF \subseteq Q is the set of final states.


Transition Function #

The transition function is defined as

δ:(QF)×(I{_})×(Γ{_})kQ×(Γ{_})k×{R,L,S}k+1δ : (Q - F)×(I \cup \{\_\})×(Γ \cup \{\_\})^k → Q×(Γ \cup \{\_\})^k×\{R, L, S\}^{k+1}

where elements of {R,L,S}\{R, L, S\} indicate “directions” of the head of the TM:

  • RR : move the head one position to the right;

  • LL : move the head one position to the left;

  • SS : stand still.

Remarks:

  • the transition function can be partial;

  • the transition function can be partial;

  • the transition function can be partial;


Moves #

Moves are based on

  • one symbol read from the input tape,

  • k symbols, one for each memory tape,

  • state of the control device.

Actions

  • Change state.

  • Write a symbol replacing the one read on each memory tape.

  • Move the k+1k+1 heads.


Moves: Graphically #

Moves Graphically

  • qQFq \in Q − F and qQq′ \in Q

  • ii is the input symbol,

  • AjA_j is the symbol read from the jthjth memory tape,

  • AjA′_j is the symbol replacing AjA_j ,

  • M0M_0 is the direction of the head of the input tape,

  • MjM_j is the direction of the head of the jthjth memory tape.where 1jk1 \leq j \leq k


Configuration #

A configuration (a snapshot) cc of a TM with kk memory tapes is the following (k+2)(k+2) -tuple:

c=q,xy,α1β1,...,αkβkc = ⟨q, x↑y, α_1↑β_1, . . . , α_k ↑β_k ⟩

where:

  • qQq \in Q
  • x(I{_}),y=y._x \in (I \cup \{\_\})^∗, y = y'.\_ with yIy' \in I^∗
  • αr(Γ{_})α_r \in (Γ \cup \{\_\})^∗ and βr=βr._ β'_r = β'_r.\_ with βrΓβ'_r \in Γ^∗ and 1rk1 \leq r \leq k
  • IΓ\uparrow \notin I \cup Γ

Acceptance Condition #

If T=Q,I,Γ,δ,q0,Z0,FT = ⟨Q, I, Γ, δ, q_0, Z_0, F⟩ is a TM and sI,ss \in I^∗, s is accepted by TT if c0cFc_0⊢∗c_F

where:

  1. c0c_0 is an initial configuration defined as c0=q0,s,Z0,...,Z0c_0 = ⟨q_0, ↑s, ↑Z_0, . . . , ↑Z_0⟩ where

    • x=ϵx = ϵ
    • y=s_y = s_\_
    • αr=ϵ,βr=Z0α_r = ϵ, β_r = Z_0 , for any 1rk.1 \leq r \leq k.
  2. cFc_F is a final configuration defined as cF=q,sy,α1β1,...,αkβkc_F = ⟨q,s′↑y, α_1↑β_1, . . . , α_k ↑β_k ⟩ where

    • qFq \in F
    • x=sx = s^′

L(T)={sIxL(T) = \{s \in I∗| x is accepted by T}T\}


Example #

A TM TT that recognises the language AnBnCn={anbncnn>0}A^nB^nC^n=\{a^nb^nc^n | n > 0\}

Turing Machine Example


Exercices #

Build TMs that recognise the following languages:

  • L1={wcww{a,b}+}L_1 = \{wcw | w \in \{a, b\}^+\}
  • L2={wcwRw{a,b}+}L_2 = \{wcw^R | w \in \{a, b\}^+\} , where wRw^R is the reversed string ww .
  • L3={ww{a,b}}L_3 = \{w | w \in \{a, b\}^∗\} , where ww is a palindrome.
  • L4={anbnn0}{anb2nn0}L_4 = \{a^nb^n | n \ge 0\} \cup \{a^nb^{2n} | n \ge 0\}

Solutions:


Homework Exercices #

Build TMs that recognise the following languages:

  • L5={(ab)n,n0}L_5 = \{(ab)^n, n \ge 0\}
  • L6={anb2nc3n,n0}L_6 = \{a^nb^{2n}c{3n}, n \ge 0\}