Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.

Similar presentations


Presentation on theme: "CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American."— Presentation transcript:

1 CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American

2 Chapter Three Turing Machines

3 The Language Hierarchy of FA and PA is not RL nor CFL. But L is very simple and can be accepted by a simple program CF Languages Regular Languages

4 Turing Machines (TM) Δ a b a a … Read/write head Finite control Tape (input and working) Actions: Depending on its current symbol and current state, Enter another state Either - write a symbol - move read/write head one square right or left.

5 Formal Definition A Turing machine is a quintuple: M = (K, , , S, H), where  K is a finite set of states   is an alphabet, containing the blank symbol |_| and the left end symbol Δ, but not containing the symbols  and   s  K is the initial state.  H  K is the set of halting states.  , the transition function, is a function from (K – H) X  to K X (  U { ,  } ) such that: (a)  q  K – H, if  (q, Δ) = (p, b), then b =  (b)  q  K – H and a  , if  (q, a) = (p, b) then b  Δ Explain  (q, a) = (p, b).

6 Examples Consider M = (K, , , s, {h} ), where  - What does this does? - Show examples.

7 Examples Consider M = (K, , , s, {h} ), where - What does this machine do? - Show examples.

8 Configurations Definition. Given M = (K, , , s, H), a configuration of M is a member of  K X  * X (  * (  - {Ц} ) U {e} ) Content of a configuration:  current state  read/write head position  all symbols to the left of the r/w head  all symbols to the right of the r/w head (may be empty)

9 Configuration Examples Find a configuration for the following snap shot of the TM Δ a a b a _ _ …

10 Configuration Examples Find a configuration for the following snap shot of the TM Δ _ _ _ _ a _ …

11 Configuration Examples Find a configuration for the following snap shot of the TM Δ _ a _ _ _ _ …

12 A Simple Notation of Configurations (q,  a a b a)  the current state is q  the current string is  aaba  the current symbol is the second a The underline indicates the current symbol, or The r/w head position Want more examples?

13 The Yield Relation Let TM M = (K, , , s, H). Consider two configurations  (q1,  1 a1 u1) and  (q2,  2 a2 u2) where a1, a2,  , then (q1,  1 a1 u1) |  (q2,  2 a2 u2) if and only if, for some b   U { ,  },  (q1, a1) = (q2, b) and either  b  ,  1 =  2, u1 = u2, a2 = b,  b = ,  1 =  2 a2, and either u2 = a1 u1 if a1  Ц or u1  e or u2 = e, if a = Ц and u1 = e  b = ,  2 = w1 a1, and either u1 = a1 u2, or  u1 = u2 = e, and a2 = Ц

14 Cases of Yield Relation Let , u   *, where u does not end with a Ц, and let a, b  . Case 1:  (q1, a) = (q2, b)  Example: (q1,  a u) |  (q2,  b u) Case 2:  (q1, a) = (q2,  )  Example  (q1,  bau) |  (q2,  bau)

15 Cases of Yield Relation Case 3:  (q1, a) = (q2,  )  Example:  (q1,  abu) |  (q2,  abu)  (q1,  a) |  (q2,  aЦ)

16 The Closure of Yield Relation Let |  * the reflexive transitive closure of |  |  describes one step of computation of TM M |  * describes a sequence of zero or a finite number steps of computation of TM M In other words, a computation by M is a sequence of configurations for some such that   the length of the computation is n or we write

17 Example Δ table is given below (, Δaaaa) |   Finish the above computation.

18 Basic TM Machines Symbol-writing machines:  a   U { ,  } – {Δ} is defined as follows:  if a  , then writes a and then halts  if a  { ,  }, then moves r/w head according to the direction of a and then halt.

19 Better Notations a =, for a  , a-writing machine  Write an a R =, right-moving machine,  move one square right L =, left-moving machine  move one square left.

20 Combining Rules a b Semantics: Start at the initial state of M1; operate as M1 would operate until M1 would halt; then if the current symbol is a, start M2; otherwise if the current symbol is b, start M3.

21 TM Construction Examples Examples 1 R R a b Δ |_| RR a, b, Δ, |_|

22 TM Construction Examples Example 2 L R |_| R L

23 TM Construction Examples Example 3 L R Џ R Џ L Џ Џ

24 The Copying Machine C If C starts with input w, which contains only nonblank symbols but possibly empty and is put on an otherwise blank tape with one blank square to its left, and the head is put on the blank square to the left of w, then the machine C will eventually stop with w Ц w on an otherwise blank tape. We say that C transforms  Ц ω Ц into Ц ω Ц ω Ц

25 The Left-Shift Machine S transforms  Ц w Ц to w Ц, where w is a nonblank string Џ L a R R L a ≠ Џ ЏЏ Џ Џ

26 The a-Erasing Machine This machines erase the a’s in its input tape RЏ a

27 Computing with TM’s Input representation of a TM M = (K, , , s, H) Given   (  - {Ц, Δ })*, the input representation is Δ Ц  The initial configuration is (s, ΔЦ  )

28 Definitions Let M = (K, , , s, H), H = {y, n}  Accepting configurations: Any halting configuration with the halting state y.  Rejecting configurations: Any halting configuration with the halting state n.  M accepts  if (s,  Ц  ) yields an accepting configuration  M rejects  if (s,  Ц  ) yields a rejecting configuration

29 Definitions  Let  =  - { , Ц} be the input alphabet. Given a language over , M decides L if the following is true:     *, M accepts w if and only if   L.  A language L   * is recursive if and only if there is a TM M that decides L. 0 0 0 0

30 Examples The language is recursive  Recall that L is not regular nor CF. Construct a TM to accept Џ n R d R y Џ ab b, d d L Џ c a, dd b, c c, Џ a, Џ

31 Recursive Functions TM’s as computing device Definition: Let M = (K, , , s, H),  0 =  - { , Ц}, let    *. Suppose that M halts on input , and that  (s, ΔЦ  ) |  (h,  Цy) for some y   *. Then y is called the output of M on input , and is denoted as M(  ). M(  ) is defined if and only if M halts on .  In other words, (s,  Ц  ) |  (h,  Цy) for some h  H and y   *. 0 0

32 Recursive Functions TM’s as computing device Let be a function. A TM M computes f if and only if  A function is recursive if and only if there is a TM computing f.

33 Examples The doubling function d :  *  * such that   w  , d(  ) =  d is recursive  The following TM computes d  C S First make a copy of w to get w_w from _w, and then shift the copy to form _ww

34 Computing Numeric Functions Coding natural numbers Any natural numbers can be represented as strings in  {0} U {1, 2, …, 9} {0,1, 2, 3, …9}* or as strings  in {0} U {1} {0, 1}*

35 Definition. Let M = (K, , δ, s, H) be a TM such that 0, 1, ;  , and let f be any function We say that M computes f if  is recursive if there is a TM computing f.

36 Example The successor function is recursive. The following TM computes the function: R L Џ 1 1 S R 0 0 Џ 1

37 Recursively Enumerable Languages Note: A TM can be viewed as one of the three:  Acceptor  Computer  Generator Definition. Let M = (K, , , s, H) be a TM, let  0 =  - { , Ц} be an alphabet, and let L  be a language. We say that M semidecides L if for any string   the following is true:    L if and only if M halts on input .

38 Recursively Enumerable Languages A language L is r.e. if and only if there is a TM which semidecides L. When M does not halt on input , we write  M (  ) = L is r.e. if and only if    , M (  ) =     L.

39 Examples L = {   {a, b}* :  contains at least one a } is r.e. The following TM M semidecides L: R a

40 Recursive vs. R.E. Languages Theorem. If a language is recursive, then it is r.e. Theorem. If a language is recursive, then so is its complement. Theorem: A language L is recursive if L and L are both r.e. Proofs? (Prove in class)

41 Extensions of TM Multiple tapes … … …

42 Definition of Multiple Tape TM Definition. Let be an integer. A k-tape TM M is (K, , , s, H), where  K is the set of states   is the set of input symbols  s  K is the initial state  H  K is the set of final states.   transition function, Explain

43 Configurations of Multiple Tape TM Definition. Let M=(K, , , s, H) be a k-tape TM. A configuration of M is a member of Explain

44 The Yield Relation of k-Tape TM Define the yield relation Define the reflexive transitive closure of the yield relation Accepting configurations? Rejecting? Copmputing? R.e.?

45 Computing with a k-Tape TM A k-tape TM can be used to compute a function or decide or semidecide a language. Convention:  The first tape is the input and output tape  The other tapes are just working tapes. K-tape TM’s are relatively easier to construct in some cases than single-tape TM’s

46 Example Ex. Design a 2-tape TM to make a copy of the input:  Idea of construction  Copy ω to the second tape  Cope the content of the second tape to the first tape

47 Single Tape vs. Multiple Tapes Theorem. Let M=(K, , , s, H) be a k-tape TM for some. Then there is a standard single tape TM M’=(K’,  ’,  ’, s’, H’) with   ’ such that the following holds: 

48 Proof. Use 2k-tracks on a single-tape to simulate k-tape computation:  Each of the k-tapes can be simulated by two tracks:  One track for the content  The other track for the head position Example Δ a _ b a _ _ Δ b b b _ _ _ 0 0 1 0 0 0 0 Δ b b b _ _ _ 0 0 0 1 0 0 0 Δ a _ b a _ _ Δ_

49 Corollary Corollary. Any function that is computed or language that is decided or semidecided by a k-tape TM is also computed, decided, or semidecided, respectively by a standard single-tape TM.

50 Other Extensions of TM’s Two-way infinite tape TM’s Multiple heads TM’s Two-dimensional tape TM’s Random Access TM’s Many other models … All models have the same computational power  That is, for any two models, one model can do something, so does the other; and vice versa.

51 Nondeterministic TM (NTM) Allow more than one choice for next move Definition. An NTM M=(K,∑,Δ,s,H), where  K,∑,s and H are the same as for standard TM’s  Δ is a transition relation: Explain Can you see nondeterministism from Δ?

52 Configurations and Yield Relation of NTM Both can defined in a way similar to these of standard TM’s Can one define configurations? Can one define yield relation? The reflexive transitive closure of yield relation describes computation of the NTM The difference:  Each configuration may yield (or derive) several configurations at each step! Nondeterministic computation

53 Computation of an NTM Definition. Let M=(K,∑,Δ,s,H) be an NTM. M accepts if  Remark.  An NTM accepts an input ω even though it may have nonhalting computation on ω  As long as at least one computation of the NTM halts, then we say it accepts ω.

54 Tree-like Computation of NTM ……………… ………………………………

55 Semidecidability Let M=(K,∑,Δ,s,H) be an NTM. Let be a language. M semidecides L, if  Think about what will happen if

56 Decidability Let M=(K,∑,Δ,s,H) be an NTM. Let be a language. M decides L, if the following two conditions hold for all  There is a natural number N, depending on M and ω, such that all possible computations of M on ω end in no more N steps (either halt or no further computations can be performed).  At least one particular computation halts in no more than N steps (hence, this computation accepts ω).

57 Computing Functions M computes a function  if the following two conditions hold for all  There is a natural number N, depending on M and ω, such that all possible computations of M on ω end in no more N steps (either halt or no further computations can be performed).  At least one particular computation halts with configuration in no more than N steps Hence, this computation computes f(ω)=u.

58 NTM vs. DTM Theorem. If there is an NTM M semidecides, or decides a languages, or computes a function, then there is a standard deterministic TM (DTM) semideciding, deciding the same language, or computing the same function. Proof. Use multiple-tape DTM to simulate the DTM.

59 Grammars: Unrestricted Grammars Definition. A grammar is a quadruple Where  is an alphabet  is the set of terminals  is the set of non-terminals  S is the start symbol  is the set of production rules Note. Examine R to tell the difference between an unrestricted grammar and a CF grammar.

60 Derivations Let be a grammar. Let iff  Let denote the reflexive transitive closure of describes one step of derivation describes zero or a finite number steps of derivation

61 Strings and Languages Let be a grammar. A string is generated by G if The language generated by G is 

62 Examples Design a grammar to generate the language  Here is the grammar: Try a few examples.

63 R.E. Languages vs. Unrestricted Grammar Theorem 4.6.1. A language is generated by an unrestricted grammar iff it is r.e. Proof Ideas.  Suppose L is generated by a grammar Design a TM M to simulate the derivation of G such that M semidecides L. This part is easy to do  Suppose a TM M =(K,∑,δ,s,{h}) semidecides L. Construct a grammar to generate L.

64 The If-Part Proof of Theorem 4.6.1. M semidecides L, that is, for any  Rewrite this we have  Design L to simulate M backwards, that is, 

65 The If-Part Proof of Theorem 4.6.1. How to design L? Have you noticed the backward computation of M simulated by G?

66 Computing Functions by Grammars Definition. Let be a grammar, and let be a function. We say that G computes f if, for all the following is true:   A function is called grammatically computable iff there is a grammar G that computes it.

67 Theorem Theorem 4.6.2. A function is recursive iff it is grammatically computable. Proof. Simulate a TM by grammar, and vice versa.

68 Numerical Functions: Definitions Basic Functions  k-ary zero function  The j-th k-ary identity function  Successor function

69 Composition Let be -ary functions. Define

70 Recursive Definition Let be -ary functions. Let h be a -ary function. Define

71 Primitive Recursive Functions All basic functions Plus All functions obtained from basic functions by any number of successive applications of composition and recursive definition

72 Minimalization Let be -ary function. For some Define

73 μ-Recursive Functions A function is μ-recursive if  it is primitive recursive, or  can be obtained from basic functions by any number of successive applications of composition, recursive definition, and minimalization on minimalizable functions These always with m’s satisfy the minimalization condition

74 Theorem Theorem 4.7.1. A function is μ-recursive iff it is recursive. Proof.  (Only-if part) Show all basic functions are TM- computable, and all functions derived from basic functions using composition, recursive definition, and minimalizable minimalization are all TM- computable.  (If-part) Show μ-recursive functions can simulate computation of TM.


Download ppt "CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American."

Similar presentations


Ads by Google