cd5560 faber formal languages, automata and models of computation lecture 12 mälardalen university...
DESCRIPTION
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 12 Mälardalen University 2007. Content Chomsky Language Hierarchy Turing Machines Determinism Halting TM Examples Standard TM Computing Functions with TM Combining TMs Turing Thesis. The Language Hierarchy. ?. ?. - PowerPoint PPT PresentationTRANSCRIPT
1
CD5560
FABERFormal Languages, Automata
and Models of ComputationLecture 12
Mälardalen University
2007
2
Content
Chomsky Language Hierarchy Turing Machines DeterminismHaltingTM ExamplesStandard TMComputing Functions with TMCombining TMsTuring Thesis
4
Regular Languages**ba
Context-free languages
Unrestricted grammar languages}0:{ ncba nnn
}0:{ nba nn
}},{:{ bawww
}*},{:{ bawwwR
}0:{ ! nan }0:{2
nba nn
8
............
Read-Write head
No boundaries -- infinite length
The head moves Left or Right
The Tape
9
............
Read-Write head
1. Reads a symbol2. Writes a symbol3. Moves Left or Right
The head at each time step:
10
ExampleTime 0
............ a a cb
Time 1
............ a b k c
1. Reads a2. Writes k
3. Moves left
12
Head starts at the leftmost positionof the input string
............
Blank symbol
head
a b ca
Input string
The Input String
#####
18
Determinism
1q
2qRba ,
Allowed Not Allowed
3qLdb ,
1q
2qRba ,
3qLda ,
No lambda transitions allowed in TM!
Turing Machines are deterministic
19
Partial Transition Function
1q
2qRba ,
3qLdb ,
............ a b ca
1q
Example
No transitionfor input symbol c
Allowed
# # # # #
22
Final States
1q 2q Allowed
1q 2q 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
36
Time 2 ba
0q
a
baTime 3
0q
a
baTime 4
0q
a
baTime 5
0q
a
... 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 }{ nnba
0q 1q 2q3q Rxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx 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49
Ryy ,
yx
0q
x yTime 10
0q 1q 2q3q Rxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
4q
L,##
# # #}{ nnba
50
yx
3q
x yTime 11
0q 1q 2q3q Rxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,##
# # #}{ nnba
51
yx
3q
x yTime 12
0q 1q 2q3q Rxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,##
# # #}{ nnba
52
yx
4q
x y
0q 1q 2q3q Rxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
Halt & Accept
Time 13
L,##
# # #}{ nnba
53
If we modify the machine for the language }{ nnba
we can easily construct a machine for the language }{ nnn cba
Observation
57
Turing Machine
),#,,,,,( 0 FqQM
Transitionfunction
Initialstate
blank
Finalstates
States
Inputalphabet
Tapealphabet
60
Time 4 Time 5yx
2q
a b yx
0q
a b
bqxxyybqxxaybqxxaybq 1102
Time 6 Time 7yx
1q
x b yx
1q
x b
# # # # # #
# # # # # #
64
Standard Turing Machine
• Deterministic
• Infinite tape in both directions
• Tape is the input/output file
The machine we described is the standard:
68
Integer Domain
Binary: 101
Decimal: 5
We prefer unary representation:
easier to manipulate
Unary: 11111
69
Definition
A function is computable ifthere is a Turing Machine such that:
fM
Initial configuration Final configuration
Dw Domain
fq
)(wf
final state0q
w
initial state
For all
# # # #
70
)(0 wfqwq f
Initial Configuration
FinalConfiguration
In other words
Dw DomainFor all
A function is computable ifthere is a Turing Machine such that
fM
71
Example (Addition)
The function yxyxf ),( is computable
Turing Machine:
Input string: yx0 unary
Output string: 0xy unary
yx, are integers
88
Another Example (Multiplication)
The function xxf 2)( is computable
Turing Machine
Input string: x unaryOutput string: xx unary
x is integer
90
Turing Machine Pseudocode for xxf 2)(
• Replace every 1 with $
• Repeat:
• Find rightmost $, replace it with 1• Go to right end, insert 1
Until no more $ remain
108
Another Example
The function is computable
),( yxf0
1 yx
yx
if
if
Turing Machine for
Output: 1 0or
Input: yx0
109
Turing Machine Pseudocode
Match a 1 from with a 1 from x y• Repeat
Until all of or are matchedx y
• If a 1 from is not matched erase tape, write 1 else erase tape, write 0
x
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 outby mechanical meanscan be performed by a Turing Machine
(1930)
116
Computer Science Law
A computation is mechanical if and only ifit can be performed by a Turing Machine
There is no known model of computationmore powerful than Turing Machines
118
When we say There exists an algorithm
Algorithms are Turing Machines
It meansThere exists a Turing Machine
119
Language Grammar MachineChomsky Hierarchy
Turing non-computable
Natural computing??
Recursively enumerable (RE) Unrestricted Turing machines 0
RecursiveTuring machines that always halt 0
Context-sensitiveContext-sensitive grammar
Linear-bounded automata 1
Context-freeContext-free grammar
Non-deterministic pushdown automata 2
RegularRegular expressions Finite state
automata 3
properly inclusive
Languages, Grammars, Machines