Introduction to Turing Machine, Summaries of Compilers

Introduction to Turing Machine

Typology: Summaries

2020/2021

Uploaded on 02/28/2022

ashenafibelay
ashenafibelay 🇪🇹

5

(1)

17 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MicroLink Information Technology College
Department of Computer Science
Introduction to Complexity
Theory
Student Handout
(Chapter 1)
Course Title: Introduction to Complexity Theory
Course Code: CSSE-364
Credit Hr: 3 [ 3 Lecture ]
June 2020
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Introduction to Turing Machine and more Summaries Compilers in PDF only on Docsity!

Department of Computer Science

Introduction to Complexity

Theory

Student Handout

(Chapter 1)

Course Title: Introduction to Complexity Theory

Course Code: CSSE-

Credit Hr: 3 [ 3 Lecture ]

June 2020

Chapter One

Turing Machine (TM)

Introduction

 Grammars o RGs: RLs: FSA o CFGs: CFLs: PDA  Turing Machine In 1936 British mathematician Alan Turing proposed the idea of a machine that could process equations without human direction. The machine (now known as a Turing machine) resembled an automatic typewriter that used symbols for math and logic instead of letters. Turing intended the device to be a “universal machine” that could be used to duplicate or represent the function of any other existing machine. Turing’s machine was the theoretical precursor to the modern digital computer. The Turing machine model is still used by modern computational theorists. o 1936 by Alan Turing o Recognizer and compute o Fore runner for digital computers

Basics of Turing Machine (TM)

 Has tape infinite to right and divided into cells

 Each cell accepts a symbol at a time from the input alphabet  Has tape head that moves right/left one cell at a time of scanning  The scanned symbol might be replaced or left as it is.

Cell

Tape Head

i. q = F, TM halts. ii. q 2 = λ , the tape head is on B If δ(q , B) = (ql^ , b , R), then M enters state ql^ replacing B by b and moving right.

iii. q 2 = aq3 , q 3 Є г*, a Є г and δ(q , a) = (qll^ , x , L), then M enters state qll^ replacing a by x

and moving left.

 Let a 1 a 2 a 3 ………….. qai ai+1ai+2…………..anB be configuration

i. δ (q , ai) = (q^1 , b , R) is a move, then

a 1 a 2 a 3 ………..bq^1 ai+1ai+2………..anB be the configuration

a 1 a 2 a 3 …..qaiai+1ai+2….anB |▬ a 1 a 2 a 3 ….. bql^ ai+1ai+2….anB

ii. δ (q , ai) = (q1l, c , L) is a move, then

a 1 a 2 a 3 ………..q1l^ ai-1cai+1 ai+2………..anB be the configuration

a 1 a 2 a 3 …..qaiai+1ai+2….anB |▬ a 1 a 2 a 3 ……….. q1l^ ai-1c ai+1 ai+2………..anB

 In general a move from one configuration to another is denoted by: a) q 1 qq 2 |▬ q^11 q^1 q^12 single move b) q 1 qq 2 |▬* q^11 qq^12 zero or more moves c) q 1 qq 2 |▬+ q^11 q^1 q^12 at least one move

 TM M = ( Q , ∑ , г , q 0 , B , F ) – recognizer and has comp.

Def:

  1. Let w Є r* then w is accepted by M. If qowBB |▬* q 1 fg 2 , q 1 ,q 2 Є r*, f Є F
  2. A language accepted by M is denoted by L(M) and L(M) = {w : w Є * | qowB |▬ q 1 fg 2 , where q 1 ,q 2 Є r*, f Є F} Example

Let TM M = ( Q , ∑ , г , δ , q 0 , B , F ) where

Q = {qo , q 1 , q 2 , q 3 }  = {a} r = {a , B} F = {q 2 } δ is given by the following table

Tape Symbol State δ (q , x ) a q 0 (q 1 , a , R) a q 1 (q 2 , a , R) B q 1 (q 3 , a , R) B q 3 (q 1 , a , R)

 Check whether the following strings are accepted a) w = a

≡ q 0 aB |▬ a q 1 B |▬ a a q 3 B |▬ a a a q 3 B |▬ a a a ……q 3 B w = a is not accepted b) q 0 aaB |▬ aq 1 aB |▬ aaq 2 B (q 2 is final state) w = aa is accepted c) q 0 abaB |▬ aq 1 baB (q 1 , b) is not defined M hangs, δ (q 1 , b) is undefined

TM state Diagram

Which is equivalent to δ (q , a) = (q1 , y , L )

a B B (^)

a / y , L

q 0

q q 1

Represents a state

Represents Initial States

Represents Halt States Transition and Label as follows

To perform the above one:

  1. In state q 0 , TM replace a by x and enters state q 1 move right
  2. In state q1, TM search right for b, when found it replace it by y and enters another q 2 moving left.
  3. In state q 2 , TM search left for right most x when found enters state q 0 moving right. If it encounters a then TM starts all over again from Step1. If a y is found it enters state q 3 and moving right.
  4. In state q 3 , a TM search right over y, when B is found enters a halt state.
  1. Construction M= ( Q ,  , r , δ , q 0 , B , F ) Q = { q 0 , q 1 , q 2 , q 3 , q 4 }  = {a,b} r = { a , b , x , y , B } q 0 = q 0 F = q 4 δ is given by the following table

State a b x y B q 0 ( q 1 , x , R ) - - ( q 3 , y , R ) - q 1 ( q 1 , a , R ) ( q 2 , y , L ) - ( q 1 , y , R ) - q 2 ( q 2 , a , L ) - ( q 0 , x , R ) ( q 2 , y , L ) - q 3 - - - ( q 3 , y , R ) ( q 4 , B , L ) q 4 - - - - -

Demonistration

a a a a a b b b b b B B B B...

x a a a a y b b b b B B B B...

State Diagram

 Check the following for acceptance by TM a) w = aabb q 0 aabbB |▬ xq 1 abbB |▬ xaq 1 bbB |▬ xq 2 aybB |▬ q 2 xaybB |▬ xq 0 aybB |▬ xxq 1 ybB |▬ xxyq 1 bB |▬ xxq 2 yyB |▬ xq 2 xyyB |▬ xxq 0 yyB |▬ xxyq 3 yB |▬ xxyyq 3 B |▬ xxyq 4 yB Hence w = aabb is accepted by TM Exercises b) w = aaabb c) w = aab

Modular Construction of TM

Let M 1 ,M 2 be two TMs

i) a) →M 1 →M 2 ≡ →M 1 M 2

(M 1 simulates until normal halts and then simulate M 2 )

b) → M 1 M 2 ≡

(Simulates M 1 until it Scans a or b then M 2 Simulates)

a,b

a/a,L

b/y,L^ y/y,L y/y,R a/a,R

B/B,R

y/y,R

y/y,R

q 0 q 1 q 2

q 3

a/x,R

q 4

x/x,R

Apply SL SL

SL:

Apply SL into the following a) BcdaB |▬ BcdaB |▬ ccdab |▬ cddaB |▬ cdaaB |▬ cdaBB b) BcdaB No string on the right of B so we should: LBSL (Search Blank left and apply SL) The result is the same as above cdaB b) Shift right (SR) : Shifts a non-blank string from left of the current position to the right.

SR

Apply LBSLxRByL to the following: BaBcda B Solution: BaBcda B |▬ Ba B cdaB……………LB |▬ Bacda B B…………….SL |▬ Bacda x B…………….x |▬ Bacdax B ……………..RB |▬ Bacdax y ……………..y |▬ Bacda x y……………...L

B B a b c B x y B B a b c B B x y B

B a b c B B B a b c B

LB

B

→R rB^ L r R

The Erase Machine ( E ): Erases non-blank string BwB B

E

Backup Machine (B): The B transform BUBWB ,U and W are non-empty, into BWB.

B

B : → L^2 B E S^3 L

Copy machine ( C ): The C transforms BWB into BWBWB

C

C : LBR BR^2 BrL^2 Br

Example: Revisit the machine the accepts the language L= { anbn^ | n>1} Convert the TM using building blocks primitives Solution

B a b c B B B B …….

B a b B c d e B ……. (^) B c d e B …..

B a b B B B a b B a b B

y

a a,y^ b^ a,y x

B

y

rB

Stop

B

B B

E

→R

R

R

R

x R y^ L

3- Multiple Tapes A k-tape, TM has k heads, i.e. M = ( Q ,  , r , δ , q 0 , B , F ) δ (Q x rK^ → Q x rk^ x {L , R}K Example : Let k = 2 B a 1 a 2 B B B

x 1 x 2 x 3 B B B

To simulate a 2-tape TM on a single tape  Use 4 tracks, 2 tracks for each tape, the first track represent the tape symbols the second track the head for the tape Track Track Track Track

δ(q 0 ,(a2 , x 1 )) or δ (q 0 , az , x 1 ) δ(q0 , a 2 , x 1 ) = (q2 ,c 1 , c 3 , L , R) (The currently scanned symbols a 2 ,x 1 are replaced by c 1 and c 3 respectively moving left and right) Thus multiple tapes also don’t increase the power of TM.

4- Non- deterministic TM (NDTM) A NDTM M = (Q ,  , r , δ , q 0 , B , F ) Where Q ,,r,δ,q 0 ,B and F are similarly define in DTM. But δ: Q x r → 2 Qxrx{L,R} A language accepted by NDTM M is denoted by L (M) is given by L(M)={w Є * | q 0 w |▬ q 1 fq 2 , f Є F, q 1 and q 2 Є r*} Let M be a NDTM, we want to simulate on a DTM D.

B a 1 a 2 B B B B 1 B B x 1 x 2 x 3 B B 1 B B B B

q 0

Head is a 2

Head is x 1

D will have three tapes: Tape 1: Contains the input Tape 2: Possible sequence of transition of M Tape 3: Working tape (the input from tape 1 is copied on this and the simulation is carried out using tape 2) If the simulation leads to a halt state of M so is D. Otherwise, erase the content of tape 2 and generate another sequence and simulate tape 3. Repeat this until M halts, Hence, L(M) = L(D). Example: If the TM has Transitions δ(q 0 ,a)={(q1,b,R),(q 2 ,c,L)} It is non deterministic. The moves q 0 aaa |▬ bq 1 aa and q 0 aaa |▬ q 2 Bcaa are both possible