1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 12 Mälardalen University 2007
2 Content Chomsky Language Hierarchy Turing Machines Determinism Halting TM Examples Standard TM Computing Functions with TM Combining TMs Turing Thesis
3 The Language Hierarchy Regular Languages Context-Free Languages ? ?
4 Regular Languages Context-free languages Unrestricted grammar languages
5 FA Push-down Automata Languages accepted by Turing Machines
6
Tape Read-Write head Control Unit A Turing Machine
Read-Write head No boundaries -- infinite length The head moves Left or Right The Tape
Read-Write head 1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right The head at each time step:
10 Example Time Time Reads a 2. Writes k 3. Moves left
11 Time Time Reads b 2. Writes f 3. Moves Right
12 Head starts at the leftmost position of the input string Blank symbol head Input string The Input String
13 Read Write Move Left Move Right States & Transitions
14 Example Time 1 current state
Time Time 2
Time Time 2 Example
Time Time 2 Example
18 Determinism Allowed Not Allowed No lambda transitions allowed in TM! Turing Machines are deterministic
19 Partial Transition Function Example No transition for input symbol Allowed
20 Halting The machine halts if there are no possible transitions to follow
21 Example No possible transition HALT!
22 Final States Allowed Not Allowed Final states have no outgoing transitions In a final state the machine halts
23 Acceptance Accept input If machine halts in a final state Reject input If machine halts in a non-final state or If machine enters an infinite loop
24 Turing Machine Example A TM that accepts the language
25 Time 0
26 Time 1
27 Time 2
28 Time 3
29 Time 4 Halt & Accept
30 Rejection Example Time 0
31 Time 1 No possible Transition Halt & Reject
32 Infinite Loop Example Another TM for language
33 Time 0
34 Time 1
35 Time 2
36 Time 2 Time 3 Time 4 Time 5... infinite loop…
37 Because of the infinite loop: The final state cannot be reached The machine never halts The input is not accepted
38 Another Turing Machine Example Turing machine for the language
39 Time 0
40 Time 1
41 Time 2
42 Time 3
43 Time 4
44 Time 5
45 Time 6
46 Time 7
47 Time 8
48 Time 9
49 Time 10
50 Time 11
51 Time 12
52 Halt & Accept Time 13
53 If we modify the machine for the language we can easily construct a machine for the language Observation
54 Formal Definitions for Turing Machines
55 Transition Function
56 Transition Function
57 Turing Machine Transition function Initial state blank Final states States Input alphabet Tape alphabet
58 Instantaneous description: Configuration
59 Time 4Time 5 A move:
60 Time 4Time 5 Time 6Time 7
61 Equivalent notation:
62 Initial configuration: Input string
63 For any Turing Machine Initial stateFinal state The Accepted Language
64 Standard Turing Machine Deterministic Infinite tape in both directions Tape is the input/output file The machine we described is the standard:
65 Computing Functions with Turing Machines
66 A function has: Domain (domän): Range (värdemängd):
67 A function may have many parameters: Example: Addition function
68 Integer Domain Binary:101 Decimal:5 We prefer unary representation: easier to manipulate Unary:11111
69 Definition A function is computable if there is a Turing Machine such that: Initial configuration Final configuration Domain final state initial state For all
70 Initial Configuration Final Configuration In other words Domain For all A function is computable if there is a Turing Machine such that
71 Example (Addition) The function is computable Turing Machine: Input string: unary Output string: unary are integers
72 Start Finish final state initial state
73 Turing machine for function
74 Execution Example: Time 0 Final Result (2)
75 Time 0
76 Time 1
77 Time 2
78 Time 3
79 Time 4
80 Time 5
81 Time 6
82 Time 7
83 Time 8
84 Time 9
85 Time 10
86 Time 11
87 HALT & accept Time 12
88 Another Example (Multiplication) The functionis computable Turing Machine Input string: unary Output string:unary is integer
89 Start Finish final state initial state
90 Turing Machine Pseudocode for Replace every 1 with $ Repeat: Find rightmost $, replace it with 1 Go to right end, insert 1 Until no more $ remain
91 Turing Machine for
92 Start Finish
93 Time 0
94 Time 1
95 Time 2
96 Time 3
97 Time 4
98 Time 5
99 Time 6
100 Time 7
101 Time 8
102 Time 9
103 Time 10
104 Time 11
105 Time 12
106 Time 13
107 Time 14
108 Another Example The function is computable if Turing Machine for Output: or Input:
109 Turing Machine Pseudocode Match a 1 from with a 1 from Repeat Until all of or are matched If a 1 from is not matched erase tape, write 1 else erase tape, write 0
110 Combining Turing Machines
111 Block Diagram Turing Machine inputoutput
112 Example if Comparer Adder Eraser
113 Turing’s Thesis
114 Do Turing machines have the same power with a digital computer? Intuitive answer: Yes There is no formal answer! Question:
115 Turing’s thesis Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
116 Computer Science Law A computation is mechanical if and only if it can be performed by a Turing Machine There is no known model of computation more powerful than Turing Machines
117 Definition of Algorithm An algorithm for function f(w) is a Turing Machine which computes f(w)
118 When we say There exists an algorithm Algorithms are Turing Machines It means There exists a Turing Machine
119 LanguageGrammarMachine Chomsky Hierarchy Turing non- computable Natural computing?? Recursively enumerable (RE) UnrestrictedTuring machines 0 Recursive Turing machines that always halt 0 Context-sensitive Context-sensitive grammar Linear-bounded automata 1 Context-free Context-free grammar Non-deterministic pushdown automata 2 Regular Regular expressions Finite state automata 3 properly inclusive Languages, Grammars, Machines
120 Regular Languages FINITE AUTOMATA Context-free languages PUSH-DOWN AUTOMATA Unrestricted grammar languages TURING MACHINES