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

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
Lecture 6 Nondeterministic Finite Automata (NFA)
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.
Reducibility A reduction is a way of converting one problem into another problem in such a way that a solution to the second problem can be used to solve.
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
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 ? ?
Programming the TM qa  (,q) (,q) q1q1 0q1q1 R q1q1 1q1q1 R q1q1  h  Qa  (,q) (,q) q1q1 0q2q2  q1q1 1q3q3  q1q1  h  q2q2 0q4q4 R q2q2 1q4q4.
Turing Machines.

CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
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 8: Automata Theory VI (PDA, PDA = CFG)
CS5371 Theory of Computation Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)
Chapter 9 Turing Machine (TMs).
AUTOMATA THEORY VIII.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
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.
Chapter 7 PDA and CFLs.
TM Design Universal TM MA/CSSE 474 Theory of Computation.
Introduction to CS Theory Lecture 15 –Turing Machines Piotr Faliszewski
Lecture 18UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 18.
Computability Construct TMs. Decidability. Preview: next class: diagonalization and Halting theorem.
Turing Machines Chapter 17. Languages and Machines SD D Context-Free Languages Regular Languages reg exps FSMs cfgs PDAs unrestricted grammars Turing.
1 More About Turing Machines “Programming Tricks” Restrictions Extensions Closure Properties.
Computability Chapter 5. Overview  Turing Machine (TM) considered to be the most general computational model that can be devised (Church-Turing thesis)
 2005 SDU Lecture13 Reducibility — A methodology for proving un- decidability.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
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 -
1 Section 13.1 Turing Machines A Turing machine (TM) is a simple computer that has an infinite amount of storage in the form of cells on an infinite tape.
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.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
1 Turing Machines. 2 The Language Hierarchy Regular Languages Context-Free Languages ? ?
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 3 The Church-Turing Thesis Contents Turing Machines definitions, examples,
THE CONVENTIONS 2 simple rules: Rule # 1: Rule # 2: RR “move to the right until you find  “ Note: first check. Then move (think of a “while”) “Never.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Umans Complexity Theory Lectures Lecture 1b: Turing Machines & Halting Problem.
Turing Machines Sections 17.6 – The Universal Turing Machine Problem: All our machines so far are hardwired. ENIAC
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 ? ?
Universal Turing Machine
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Chapters 11 and 12 Decision Problems and Undecidability.
CSCI 2670 Introduction to Theory of Computing
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
CSE 105 theory of computation
COSC 3340: Introduction to Theory of Computation
Turing Machines 2nd 2017 Lecture 9.
CSE 105 theory of computation
Turing Machines Acceptors; Enumerators
COSC 3340: Introduction to Theory of Computation
Turing Machines Chapter 17.
CS21 Decidability and Tractability
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation
CSE 105 theory of computation
Lecture 5: Turning Machine
Variants of Turing machines
CSE 105 theory of computation
Presentation transcript:

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

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 7: Turning Machines 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. – (legal) – (illegal) Writing a C program to do so.

q0q0 q1q1 q2q2 q3q Examples: Finite State Machine

q0q0 q1q1 q2q2 q3q state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 q1q1 q0q0 q3q3 q2q2 q2q2 q3q3 q0q0 q1q1 ok err The Parser

Implementation (I) state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 q1q1 q0q0 q3q3 q2q2 q2q2 q3q3 q0q0 q1q1 ok err The Parser #defineq00 #defineq11 #defineq22 #defineq33 #definefini4 #defineq00 #defineq11 #defineq22 #defineq33 #definefini4

Implementation (I) state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 q1q1 q0q0 q3q3 q2q2 q2q2 q3q3 q0q0 q1q1 ok err The Parser int parser[4][3]={ q1, q2,fini, q0,q3,fini, q3,q0,fini, q2,q1,fini }; intstate=q0; intevent; char* str; int parser[4][3]={ q1, q2,fini, q0,q3,fini, q3,q0,fini, q2,q1,fini }; intstate=q0; intevent; char* str;

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

Implementation (I) 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); } 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) 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 } 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) q0q0 q1q1 q2q2 q3q state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 pq 1 pq 0 pq 3 pq 2 pq 3 pq 0 pq 1 ok err The Parser

Implementation (II) state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 pq 1 pq 0 pq 3 pq 2 pq 3 pq 0 pq 1 ok err The Parser #defineq00 #defineq11 #defineq22 #defineq33 #definefini4 #defineq00 #defineq11 #defineq22 #defineq33 #definefini4 void pq0(), pq1(), pq2(), pq3(); void ok(), err(); void pq0(), pq1(), pq2(), pq3(); void ok(), err();

Implementation (II) state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 pq 1 pq 0 pq 3 pq 2 pq 3 pq 0 pq 1 ok err The Parser void pq0() { state = q0; } void pq1() { state = q1; } void pq0() { state = q0; } void pq1() { state = q1; } void pq2() { state = q2; } void pq3() { state = q3; } void pq2() { state = q2; } void pq3() { state = q3; }

Implementation (II) state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 pq 1 pq 0 pq 3 pq 2 pq 3 pq 0 pq 1 ok err The Parser void ok() { printf(”ok\n”); state = fini; } void err() { printf(”error\n”); state = fini; } void ok() { printf(”ok\n”); state = fini; } void err() { printf(”error\n”); state = fini; }

Implementation (II) state q0q0 q1q1 q2q2 q3q3 symbol (event) 01 pq 1 pq 0 pq 3 pq 2 pq 3 pq 0 pq 1 ok err The Parser typedef void (*FUNCTION)(); FUNCTION parser[4][3]={ pq1, pq2, ok, pq0, pq3, err, pq3, pq0, err, pq2, pq1, err }; typedef void (*FUNCTION)(); FUNCTION parser[4][3]={ pq1, pq2, ok, pq0, pq3, err, pq3, pq0, err, pq2, pq1, err };

Implementation (II) 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])(); } 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

Exercise 1. Write a C Program to recognize floating- point string. The syntax of the floating- point string is defined the same as that defined in C language.

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

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

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

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

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

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

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

Yields in One Step ├ M Let Then, ├M├M if and only if, where such that w1w1 a1a1 u1u1 w2=w1w2=w1 a2a2 u2=u1u2=u1 w1=w2a2w1=w2a2 a1a1 u1u1 w2w2 a2a2 u2=a1u1u2=a1u1 w1w1 a1a1 u1=a2u2u1=a2u2 w2=w1a1w2=w1a1 a2a2 u2u2 Used to trace the computation sequence.

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

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 ##

Example Head # # # Y #

Example Head # # # N # 1

Example q0q0 q1q1 q 11 q2q2 q 21 q3q3 q 31 q7q7 q6q6 q4q4 q5q5 h > L /# / 1L /# / 1L /# / 1 R / # Y / R / # N / R / 0 / 0 L /

Exercise q0q0 q1q1 q 11 q2q2 q 21 q3q3 q 31 q7q7 q6q6 q4q4 q5q5 h > L /# / 1L /# / 1L /# / 1 R / # Y / R / # N / R / 0 / 0 L / 2.Write the state transition table.

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

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

Simplified Notation >L>L#L#L 1 #L#L 1 # 1 RYR # RNR # #

Basic Turing-Machines 1. |  | symbol-writing machines: 2. Head-moving machines q0q0 h > a/a/ q0q0 h > L/L/ q0q0 h > R/R/

Combining Rules >M 1 >M 2 >M 3 q 10 h ?/? q1mq1m > q 30 h > ?/? q3pq3p 1. >M 1  M 2  >M 1 M 2 q 20 h ?/? q2nq2n q 10 ?/? q1mq1m > q 20 h ?/? q2nq2n > 2. a b q 10 q1hq1h ?/? q1mq1m > q 20 h ?/? q2nq2n a/a q 30 ?/? q3pq3p b/b

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

Some Powerful TMs >R >L

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

Example: (Copier) ├ Head #abc# # # abcabc#

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

Example: (Shift-Left) ├ Head #abc# abc#

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

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

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

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

Exercises 3. 4.

Exercises where w and v are strings of decimal numbers such that

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

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

Two-Way Infinite Tape wau Head Memory Configuration

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

# Proof simulates 33 22 1  $ 0 11 1 22 2 33 3 44 ## M1M1 M2M2

Proof simulates

Proof simulates E.g.,

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

Proof simulates E.g.,

Proof 1.M 2 simulates the input for M 1 into M 2 in the following way: abcbbcb M1M1 # Head $ a # M2M2 b # c # b # b # c # b # # # g s2s2

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

Proof M1M1 # Head 11 22 $ 1 0 M2M # 0 # 1 # # 1. Simulate M 1 on upper track: Simulate the operations of M 1 on M 2. Determine

Proof $ 1 0 M2M # 1 # Head # 2. Simulate M 1 on lower track: Simulate the operations of M 1 on M 2. Determine M1M1 # Head 11 22 1 33

Proof $ 1 0 M2M # 1 # Head # 3. Change track: Simulate the operations of M 1 on M 2. Determine $ 1 0 M2M # 1 # Head #

Proof 4. Extend the tape to the right: Simulate the operations of M 1 on M 2. Determine $ 1 0 M2M # 1 # Head # $ 1 0 M2M # 1 # #

Proof 4. Extend the tape to the right: Simulate the operations of M 1 on M 2. Determine $ 1 0 M2M # 1 # Head # $ 1 0 M2M # 1 # # # # # #

Proof 5. Halt and record head position: Simulate the operations of M 1 on M 2. Determine $ 1 0 M2M # 1 # Head # $ 1 0 M2M # 1 # #

Proof 5. Halt and record head position: Simulate the operations of M 1 on M 2. Determine $ 1 0 M2M # 1 # Head # $ 1 0 M2M # 1 # #

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

Proof 1.M 2 simulates the input for M 1 into M 2 in the following way: 2.Simulate the operations of M 1 on M 2. 3.When M 2 would halt, restore the tape to “single track” format by M 1. abcbbcb M1M1 # Head $ a # M2M2 b # c # b # b # c # b # # # g $ 1 0 M2M # 1 # # # M2M2 #

Lemma a two-way TM  one-way TM that simulates M 1 as follows: 1. ├ ├ 2. M 1 does not halt M 2 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 Usually for I/O Usually for working memory Head                                       ... Memory Configuration

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

Lemma M 1 : k -tape TM, k > 0  : alphabet of M 1 s 1 : initial state  Standard TM such that 1. M 1 halts on input w, i.e., ├ Then, for M 2, ├ 2. M 1 hangs on w  M 2 too. 3. M 1 neither halts nor hangs on w  M 2 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 7: Turning Machines Nondeterministic Turing Machine 大同大學資工所 智慧型多媒體研究室

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

Transition Function E.g., K   a..... q p1p1 p2p2 prpr a a a q

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 Head #  ab# ba b Head #  ab# aa a There is a terminating path. There is no a terminating path.

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

Example n is a composite number iff

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

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

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

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

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

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

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

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

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

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

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

Proof K1K1 11  a..... q Numbering: p1p1 p2p2 p3p3 a a a q 1 2 3, 4, …,10

Proof Computation path indexing > d1d1 d2d2 d3d3 d1d1 d2d2 d1d1 d2d2 d3d3 d4d4

Proof An computation path ( #d 2 d 1 d 4 # ) > d1d1 d2d2 d3d3 d1d1 d2d2 d1d1 d2d2 d3d3 d4d4

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

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

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

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

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