Lecture 5: Turning Machine

Slides:



Advertisements
Similar presentations
Turing Machines Memory = an infinitely long tape Persistent storage A read/write tape head that can move around the tape Initially, the tape contains only.
Advertisements

Lecture 16 Deterministic Turing Machine (DTM) Finite Control tape head.
Variants of Turing machines
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Foundations of (Theoretical) Computer Science Chapter 3 Lecture Notes (Section 3.2: Variants of Turing Machines) David Martin With.
主講人:虞台文 大同大學資工所 智慧型多媒體研究室
CS605 – The Mathematics and Theory of Computer Science Turing Machines.
CS5371 Theory of Computation Lecture 11: Computability Theory II (TM Variants, Church-Turing Thesis)
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Turing Machines.
CS5371 Theory of Computation Lecture 10: Computability Theory I (Turing Machine)
Computability and Complexity 3-1 Turing Machine Computability and Complexity Andrei Bulatov.
CS5371 Theory of Computation Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)
Chapter 9 Turing Machine (TMs).
Turing Machines A more powerful computation model than a PDA ?
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
TM Design Universal TM MA/CSSE 474 Theory of Computation.
Turing Machines Chapter 17. Languages and Machines SD D Context-Free Languages Regular Languages reg exps FSMs cfgs PDAs unrestricted grammars Turing.
Lecture 1: A Formal Model of Computation 虞台文 大同大學資工所 智慧型多媒體研究室.
Computability Chapter 5. Overview  Turing Machine (TM) considered to be the most general computational model that can be devised (Church-Turing thesis)
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
Lecture 3: Count Programs, While Programs and Recursively Defined Functions 虞台文 大同大學資工所 智慧型多媒體研究室.
Theorem: Turing decidable languages are closed under intersection.
Lecture 5: Finite Automata 虞台文 大同大學資工所 智慧型多媒體研究室.
1 Turing machines Chapter 4, Smith and Kimber. A Turing machine is an abstraction of a human “computer”. Consists of - control, in the form of states -
Lecture 2: Limiting Models of Instruction Obeying Machine 虞台文 大同大學資工所 智慧型多媒體研究室.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
Lecture 24UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 24.
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Umans Complexity Theory Lectures Lecture 1b: Turing Machines & Halting Problem.
Lecture 6: Context-Free Languages
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 8.4 Extensions to the Basic TM Extended TM’s to be studied: Multitape Turing machine Nondeterministic Turing machine The above extensions make no increase.
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Lecture 7: Turning Machines 虞台文 大同大學資工所 智慧型多媒體研究室.
Theory of Computation Automata Theory Dr. Ayman Srour.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Chapters 11 and 12 Decision Problems and Undecidability.
Turing’s Thesis Costas Busch - LSU.
CSCI 2670 Introduction to Theory of Computing
COSC 3340: Introduction to Theory of Computation
Busch Complexity Lectures: Turing Machines
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
Turing Machines Chapter 17.
CSE 105 theory of computation
COSC 3340: Introduction to Theory of Computation
Theory of Computation Lecture 22: Turing Machines III
Turing Machines 2nd 2017 Lecture 9.
CSE 105 theory of computation
Turing Machines Acceptors; Enumerators
COSC 3340: Introduction to Theory of Computation
Chapter 3: The CHURCH-Turing thesis
Jaya Krishna, M.Tech, Assistant Professor
Turing Machines Chapter 17.
Decidable Languages Costas Busch - LSU.
CS21 Decidability and Tractability
CS21 Decidability and Tractability
MA/CSSE 474 Theory of Computation
COSC 3340: Introduction to Theory of Computation
Decidability and Tractability
MA/CSSE 474 Theory of Computation
Instructor: Aaron Roth
CSE 105 theory of computation
Variants of Turing machines
More Undecidable Problems
Theory of Computation Lecture 23: Turing Machines III
Lecture 6: Computational Complexity
CSE 105 theory of computation
Presentation transcript:

Lecture 5: Turning Machine 虞台文 大同大學資工所 智慧型多媒體研究室

Content An Overview on Finite State Machine The Definition of Turing Machine Computing with Turing Machine Turing-Machine Programming Some Examples of Powerful TMs Extensions of the TM Nondeterministic Turing Machine

Lecture 5: Turning Machine An Overview on Finite State Machine 大同大學資工所 智慧型多媒體研究室

Example Input a 0/1 sting. If the numbers of 0 and 1 in the string are both even, then it is legal; otherwise, it is illegal. 0011001001(legal) 11001001001(illegal) Writing a C program to do so.

Finite State Machine Examples: q0 q1 q2 q3 1 00100011<CR> 1 Examples: 00100011<CR> 01101011<CR> 001010101<CR> 0010010101<CR>

Finite State Machine state q0 q1 q2 q3 symbol (event) 1 <CR> q0 1 <CR> q0 q1 q2 q3 1 q1 q2 ok q0 q3 err q3 q0 err q2 q1 err The Parser

Implementation (I) state q0 q1 q2 q3 symbol (event) 1 <CR> ok 1 <CR> ok err The Parser #define q0 0 #define q1 1 #define q2 2 #define q3 3 #define fini 4

Implementation (I) int parser[4][3]={ q1, q2, fini, q0, q3, fini, }; int state=q0; int event; char* str; state q0 q1 q2 q3 symbol (event) 1 <CR> ok err The Parser

Implementation (I) void ToEvent(char c) { if(c == ’0’) event = 0; else if(c == ’1’) event = 1; else event = 2; } Event (or Message) Encoding

Implementation (I) Event (or Message) Loop void main() { // Ask user to input a 0/1 string // Store the string into str state = q0; //initialization while(state!=fini){ ToEvent(*str++); EventHandler(event); } Event (or Message) Loop

Implementation (I) Event Handler void EventHandler(int event) { int next_state = parser[state][event]; switch(next_state){ case fini: printf(”%s\n”, state==q0 ? ”ok” : ”err”); default: state = next_state; //change state } Event Handler

Implementation (II) state q0 q1 q2 q3 symbol (event) 1 <CR> q0 1 <CR> q0 q1 q2 q3 1 pq1 pq2 ok pq0 pq3 err pq3 pq0 err pq2 pq1 err The Parser

Implementation (II) state q0 q1 q2 q3 symbol (event) 1 <CR> pq1 1 <CR> pq1 pq0 pq3 pq2 ok err The Parser #define q0 0 #define q1 1 #define q2 2 #define q3 3 #define fini 4 void pq0(), pq1(), pq2(), pq3(); void ok(), err();

Implementation (II) state q0 q1 q2 q3 symbol (event) 1 <CR> pq1 1 <CR> pq1 pq0 pq3 pq2 ok err The Parser void pq0() { state = q0; } void pq1() state = q1; void pq2() { state = q2; } void pq3() state = q3;

Implementation (II) void ok() { printf(”ok\n”); state = fini; } void err() printf(”error\n”); state q0 q1 q2 q3 symbol (event) 1 <CR> pq1 pq0 pq3 pq2 ok err The Parser

Implementation (II) typedef void (*FUNCTION)(); FUNCTION parser[4][3]={ pq1, pq2, ok, pq0, pq3, err, pq3, pq0, err, pq2, pq1, err }; Implementation (II) state q0 q1 q2 q3 symbol (event) 1 <CR> pq1 pq0 pq3 pq2 ok err The Parser

Implementation (II) Event (or Message) Loop void main() { // Ask user to input a 0/1 string // Store the string into str state = q0; //initialization while(state!=fini){ ToEvent(*str++); (*parser[state][event])(); } Event (or Message) Loop

Lecture 5: Turning Machine The Definition of Turing Machine 大同大學資工所 智慧型多媒體研究室

Definition A Turing machine is a quadruple # Head Hang A Turing machine is a quadruple K: finite set of states, hK. : alphabet, #, L, R. : transition function s: sK, initial state.

The Transition Function Change state from q to p. b  print b; b{L, R}  Move head in the direction of b.

The Transition Function K   . . . . . . . a . . . . . q

Memory Configuration w a # u  # or Head u  # or The configuration of a Turing machine is a member of

Halt Configuration w a # u  # or Head u  # or The configuration of a Turing machine is a member of

Lecture 5: Turning Machine Computing with Turing Machine 大同大學資工所 智慧型多媒體研究室

Yields in One Step├M Let Then, if and only if , where such that Used to trace the computation sequence. Yields in One Step├M Let ├M Then, if and only if , where such that w1 a1 u1 w1=w2a2 a1 u1 w1 a1 u1=a2u2 w2=w1 a2 u2=u1 w2 a2 u2=a1u1 w2=w1a1 a2 u2

Yields ├ Let is the reflexive, transitive closure of ├M , i.e., if, for some n  0, ├ ├M (1) where Ci denotes the configuration of M. We say that computation sequence (1) is of length n or has n steps.

Turing Computable Functions Let 0, 1  {#}, and let . f is said to be a Turing computable function if such that, for any , ├ M is, then, said to compute f.

Turing Computable Functions w Head # u Head #

Example Head # 1 1 1 1 1 1 1 1 1 # Head # Y #

Example Head # 1 1 1 1 1 1 1 1 1 1 # Head # N #

Example > q0 q1 q11 q2 q21 q3 q31 q7 q6 q4 q5 h L / # / 1 R / # Y / N / R / 0 / 0

Exercise > Write the state transition table. q0 q1 q11 q2 q21 q3 # / 1 R / # Y / N / R / 0 / 0

Discussion Three main usages of machines: Compute Decision Accept See textbooks for the definitions of Turing decidability Turing acceptability

Lecture 5: Turning Machine Turing-Machine Programming 大同大學資工所 智慧型多媒體研究室

Simplified Notation >L #L 1 # RYR RNR

Basic Turing-Machine > > > || symbol-writing machines: Head-moving machines q0 h > a/ q0 h > L/ q0 h > R/

Combining Rules > > > > > >M1 >M3 >M2 q10 h ?/? q1m > >M3 q30 h > ?/? q3p >M2 q20 h ?/? q2n > 1. >M1 M2  >M1M2 q20 h ?/? q2n q10 q1m > 2. a b q10 q1h ?/? q1m > q20 h q2n a/a q30 q3p b/b

Lecture 5: Turning Machine Some Example of Powerful TMs 大同大學資工所 智慧型多媒體研究室

Some Powerful TMs 1. 3. >R >L 2. 4. >R >L

Abbreviation >R R a b c # >R R a, b, c, # >RR

Example: (Copier) ├ Head # a b c Head # a b c

Example: (Copier) ├ >L# R #R# R#sL# L#s R# # a b c # # a b c #

Example: (Left-Shift) ├ Head # a b c Head a b c #

Example: (Left-Shift) ├ Example: (Left-Shift) # a b c # # a b c # # a b c # # a b c # >L# R LsR L# # a a b c # a a b c # a a b c # a b b c # …

Example: (Palindrome) ├ Head # a b Head Y #

Example: (Palindrome) ├ Head # a b Head N #

Example: (Palindrome) ├ Example: (Palindrome) # a b b a # # # a b b a # (SR) # # a b b a # a # a b b a # >SRL# LaRR #R# L #L# L# #RYR L# #RNR #L # a # a b b a # a # a b b a # a # # b b a # a # # b b a # a # # b b a # a # # b b # # a # # b b # # …

Exercises ├ 1. ├ 2.

Lecture 5: Turning Machine Extensions of the TM 大同大學資工所 智慧型多媒體研究室

Extensions of the TM Standard TM 1-way TM 2-way TM k-tape (1-way) TM Deterministic TM’s 2-way TM k-tape (1-way) TM Nondeterministic TM

Two-Way Infinite Tape w a u Head Memory Configuration

Lemma 1. ├ ├ 2. M1 does not halt M2 does not halt. a two-way TM one-way TM that simulates M1 as follows: 1. ├ ├ 2. M1 does not halt M2 does not halt.

Proof   # # # M1 M2 3 2 1 1 2 3 $ 1 1 2 2 3 3 4 simulates 3 2 1 1 2 3  M1 # # # $  1 1 2 2 3 3 4 M2

Proof simulates

Proof simulates E.g.,

Mark halt configuration Proof simulates Head on lower track Head on upper track Mark halt configuration Final Operations Mark left end

Proof simulates E.g.,

Proof M2 simulates the input for M1 into M2 in the following way: a b c M1 # Head g $ a # M2 b c Head s2

Proof M2 simulates the input for M1 into M2 in the following way: Simulate the operations of M1 on M2. When M2 would halt, restore the tape to “single track” format by M1. a b c M1 # Head g $ a # M2 b c Head

Proof M1 M2 Simulate the operations of M1 on M2. Determine # M1 # Head 2 3 4 1 2 $ 1 M2 # Head 1. Simulate M1 on upper track:

Proof M1 M2 Simulate the operations of M1 on M2. Determine # M1 # Head 2 3 4 1 2 3 $ 1 M2 # Head 2. Simulate M1 on lower track:

Proof M2 M2 Simulate the operations of M1 on M2. Determine $ 1 M2 # Head $ 1 M2 # Head 3. Change track:

Proof M2 Simulate the operations of M1 on M2. Determine $ 1 M2 # Head 4. Extend the tape to the right:

Proof M2 Simulate the operations of M1 on M2. Determine # # $ 1 M2 # Head # # 4. Extend the tape to the right:

Proof M2 Simulate the operations of M1 on M2. Determine $ 1 M2 # Head 5. Halt and record head position:

Proof M2 M2 Simulate the operations of M1 on M2. Determine # # Head $ 1 1 1 # M2 1 1 # # $ 1 1 1 # M2 1 1 # # Head 5. Halt and record head position:

Proof M2 simulates the input for M1 into M2 in the following way: Simulate the operations of M1 on M2. When M2 would halt, restore the tape to “single track” format by M1. a b c M1 # Head g $ a # M2 b c Head

Proof M2 simulates the input for M1 into M2 in the following way: Simulate the operations of M1 on M2. When M2 would halt, restore the tape to “single track” format by M1. $ 1 M2 # Head a b c M1 # Head g # M2 1 Head $ a # M2 b c Head

Lemma 1. ├ ├ 2. M1 does not halt M2 does not halt. a two-way TM one-way TM that simulates M1 as follows: 1. ├ ├ 2. M1 does not halt M2 does not halt.

Theorem Any function that is computed or language that is decided or accepted by a two-way Turing Machine is also computed, decided or accepted by a standard Turing Machine.

k-Tape TM . . . Memory Configuration Head Usually for I/O Usually for        . . . Usually for I/O Usually for working memory Memory Configuration

Example (Duplicate) w # w # w # w # w #

Lemma M1: k-tape TM, k > 0 : alphabet of M1  Standard TM s1: initial state such that 1. M1 halts on input w, i.e., ├ Then, for M2, ├ 2. M1 hangs on w  M2 too. 3. M1 neither halts nor hangs on w  M2 too.

Theorem Any function that is computed or language that is decided or accepted by a k-tape Turing machine is also computed, decided or accepted by a standard Turing machine.

Lecture 5: Turning Machine Nondeterministic Turing Machine 大同大學資工所 智慧型多媒體研究室

NTM Definition A Turing machine is a quadruple K: finite set of states, hK. The same as standard TM. : alphabet, #, L, R. s: sK, initial state. : transition function

Transition Function  a  K q p1 p2 q pr E.g., a a a . . . . . . .

Language Acceptance by an NTM NTM is usually used as a language acceptor. A language, say, L can be accepted by an NTM if, given any input w  L, there exists a computation sequence which can lead the NTM to a halt state.

Example   a regular language There is a terminating path. Head #  a b There is a terminating path. Head #  a b There is no a terminating path.

Example a regular language a, b b a # b, # a, #

Example n is a composite number iff

>GGPE Example L can be accepted by the NTM Generate p  2 Compare m and n Compute m = pq Generate p  2 Generate q  2

Example L can be accepted by the NTM >GGPE # I Head n = 10

>GGPE Example >RIR IR # L can be accepted by the NTM G: generate a random number larger than 2. Example >RIR IR # L can be accepted by the NTM >GGPE # I Head n = 10

>GGPE Example >RIR IR # L can be accepted by the NTM G: generate a random number larger than 2. Example >RIR IR # L can be accepted by the NTM >GGPE n = 10 Head # I I I I I I I I I I # I I # p = 2

>GGPE Example >RIR IR # L can be accepted by the NTM G: generate a random number larger than 2. Example >RIR IR # L can be accepted by the NTM >GGPE n = 10 Head # I I I I I I I I I I # I I # I I I I I # q = 5 p = 2

>GGPE Example P: product L can be accepted by the NTM n = 10 q = 5 Head # I I I I I I I I I I # I I # I I I I I # q = 5 p = 2

>GGPE Example P: product L can be accepted by the NTM n = 10 m = pq = 10 Head # I I I I I I I I I I # I I I I I I I I I I #

>GGPE Example P: product L can be accepted by the NTM n = 10 m = pq = 10 Head # I I I I I I I I I I # I I I I I I I I I I #

>GGPE Example E: equivalence L can be accepted by the NTM n = 10 m = pq = 10 Head # I I I I I I I I I I # I I I I I I I I I I #

>GGPE Example L can be accepted by the NTM n is a composite number iff Example L can be accepted by the NTM >GGPE n = 10 m = pq = 10 Head # I I I I I I I I I I # I I I I I I I I I I #

Lemma For every NTM , we can construct a standard TM such that for any if M1 halts on w, then M2 is also so; if M1 does not halts on w, then M2 is also not.

Proof 1  a K1 q p1 p2 q p3 Numbering: a 1 2 3, 4, …,10 . . . . . . .

Proof Computation path indexing > d1 d2 d3 d4

Proof An computation path (#d2d1d4#) > d1 d2 d3 d4

Proof … … … … … G : computation path generation ## #d1# #d2# #dr# #drdr# #d2d1# #d1d1d1# #d1d1d2# #d1drdr# … #drdrdr# #d2d1d1# #d1d1d1d1# #d1d1d1d2# #d1drdrdr# … #drdrdrdr# #d2d1d1d1#

Proof M Head Head 2 # w # w $ 1st tape: never changed. 2nd tape: simulate the computation of M1. 3rd tape: computation path.

Proof >$(2)R(2)R(3)C M1’ G #(3) Copy tape1 to tape 2.

Generate computation path. Proof >$(2)R(2)R(3)C M1’ G #(3) Simulate M1 on tape 2 according to the computation path depicted on tape 3. halt Copy tape1 to tape 2. Generate computation path.

Lemma For every NTM , we can construct a standard TM such that for any if M1 halts on w, then M2 is also so; if M1 does not halts on w, then M2 is also not.