CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 13
Lecture 1: A Formal Model of Computation
-
Upload
frances-medina -
Category
Documents
-
view
40 -
download
2
description
Transcript of Lecture 1: A Formal Model of Computation
![Page 1: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/1.jpg)
Lecture 1: A Formal Model of Computation
虞台文大同大學資工所智慧型多媒體研究室
![Page 2: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/2.jpg)
Content
Formalizing the Idea of Programmable Computer.
Program Defined Machine Defined Computation Defined A Simple Machine
![Page 3: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/3.jpg)
Lecture 1: A Formal Model of Computation
Formalizing the Idea of Programmable
Computer
大同大學資工所智慧型多媒體研究室
![Page 4: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/4.jpg)
A Simple Programmable Device PC
PC Pocket Calculator
What is inside?
![Page 5: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/5.jpg)
Inside PC Memory Set
– Two registers with unbounded capacity
Machine Instructions– Operations & tests
, , 0m n mM n
, ,m n m n ne.g.,
![Page 6: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/6.jpg)
Inside PC Memory Set
– Two registers with unbounded capacity
Machine Instructions– Operations & tests
, , 0m n mM n
, ,m n m n ne.g.,
How about if n = 0?How about if n = 0?
Undefined if n = 0.Undefined if n = 0.
![Page 7: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/7.jpg)
Inside PC Memory Set
– Two registers with unbounded capacity
Machine Instructions– Operations & tests
, , 0m n mM n
, ,m n m n ne.g.,
Partial FunctionsPartial
FunctionsPartial
PredicatesPartial
Predicates
![Page 8: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/8.jpg)
Partial Functions
Let A and B be two sets, and
( ,, )A B a b a A Bf b is a set of ordered pairs.
We say that f is a partial function if( , )
( , )
a bb b
a b
f
f
Hence, (a, b)f is written as:
If, aA, there is no bB such that f(a) = b, then we say that f(a) is undefined, and denote this condition as: ( )f a
( )f a b
![Page 9: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/9.jpg)
Partial Functions is reserved to denote undefined object. f() = . ( ) ( ) and Domain a a A f af
( ) , ( )st Range b b B a A a bf f
There Cases:
1. Totally undefined
2. Partially defined
3. Totally defined
( )Domain f
( )Domain f
( )Domain f A
![Page 10: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/10.jpg)
Operations for PC
Each operation of PC would be defined by some partial function over M.
Example: define the division operation of PC as a partial function as follows:
if
if
, 0,
0
m n n nm n
n
![Page 11: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/11.jpg)
Partial Predicates
: , ,p M true false which does not change the information environment.
Example: | ?m n
if
if not
i
|
, |
0f
true m n
m n false m n
n
![Page 12: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/12.jpg)
Computable Functions
By a computable function, we mean a function that can be algorithmically specified.
When a algorithm is applied to an element outside its domain, it may– not terminated; or– the result B.
Whenever an algorithm is such that it computation does not always terminate, then the algorithm defines a computable partial function.
![Page 13: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/13.jpg)
Exercises
Define “algorithm”.
Show that ,
where f, g, and h are partial functions.
( ) ( )f g h f g h
![Page 14: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/14.jpg)
Lecture 1: A Formal Model of Computation
Program Defined
大同大學資工所智慧型多媒體研究室
![Page 15: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/15.jpg)
Programs vs. Flowcharts
Essentially, we take programs to be flowcharts constituting the following components.
START
HALT
Operation
Predicate (Test)
![Page 16: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/16.jpg)
Flowchart
START
HALT
F0
P1
F1
F2truefalse
![Page 17: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/17.jpg)
Labeled Statements
START
HALT
F0
P1
F1
F2truefalse
L0L1
L2
L3
L4
START: GOTO L3
L0: DO F2 GOTO L3
L1: IF P1 THEN GOTO L0 ELSE GOTO L3
L2: DO F1 GOTO L1
L3: DO F0 GOTO L2
L4: HALT
![Page 18: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/18.jpg)
Instructions
Instructions are
made up from:
L : a set of labels;
F : a set of operations;
P : a set of predicates.
START: GOTO L3
L0: DO F2 GOTO L3
L1: IF P1 THEN GOTO L0 ELSE GOTO L3
L2: DO F1 GOTO L1
L3: DO F0 GOTO L2
L4: HALT
![Page 19: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/19.jpg)
Four Types of Instructions
1. Start Instruction
2. Operation Instruction
3. Test Instruction
4. Halt Instruction
START: GOTO L
L: DO F GOTO L’
L: IF P1 THEN GOTO L’ ELSE GOTO L’’
L: HALT-Loop:
L: DO F GOTO L
![Page 20: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/20.jpg)
Program Schema
A program schema is a set of instructions that contains:
Exactly one start instruction; No repeat on label.
![Page 21: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/21.jpg)
Exercise
while P1 do begin W1; while P2 do
W2; end.
p1 := P1;p2 := false;while p1 or p2 do begin if p2 then W2 else W1; p2 := P2; p1 := P1; end.
Translate the above two Pascal Programs into labeled statements and prove their equivalence, using computation sequence in any convenient way.
![Page 22: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/22.jpg)
Lecture 1: A Formal Model of Computation
Machine Defined
大同大學資工所智慧型多媒體研究室
![Page 23: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/23.jpg)
Machines
![Page 24: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/24.jpg)
M-Machine
A machine is a function, say, M defined on
• the instruction set F P
• for which there exists a memory set M
such that
• MF is a partial function over M for each FF
• MP is a partial predicate over M for each PP.
![Page 25: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/25.jpg)
M-Program
An M-program or a program for M is a program
in which no instruction, except perhaps -loops,
makes use an operation or test name that is
interpreted as the totally undefined function by
M.
Without Syntax ErrorWithout Syntax Error
![Page 26: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/26.jpg)
Lecture 1: A Formal Model of Computation
Computation Defined
大同大學資工所智慧型多媒體研究室
![Page 27: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/27.jpg)
Complete Computation
A completed computation by a program on a machine M is a finite computation sequence: 0 0 1 1 1 1, , , , , , , , , , ,i i i i n nL m L m L m L m L m
Label ofstart instruction
Label of ahalt instruction
![Page 28: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/28.jpg)
Complete Computation
A completed computation by a program on a machine M is a finite computation sequence: 0 0 1 1 1 1, , , , , , , , , , ,i i i i n nL m L m L m L m L m
Case 1:
Case 2:
: DO GO O TiL F L
: IF THEN GOT O ELSE GOTO iL P L L
1 1, ( )i i F iL L m m M
1 1
( ),
( )P i
i i iP i
L m truem m L
L m false
M
M
Without ambiguity at each step. Without ambiguity at each step.
![Page 29: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/29.jpg)
Uncompletable Computation
The reasons for a computation being uncompletable:– Never reach halt instruction;
– Instruction Li: DO F GOTO L’ causes
– Instruction Li: IF P THEN GOTO L’ ELSE GOTO L’’
causes– Reaches a -loop.
( )F im M
( )P im M
![Page 30: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/30.jpg)
Partial Function
The (partial) function
Computed by a program on a machine M is
such that
is a completed computation.
: M M M
0( ) nm m M
0 0 1 1, , , , , ,n nL m L m L m
0( ) nm completedm
othewise
M what a computer does.
![Page 31: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/31.jpg)
Lecture 1: A Formal Model of Computation
A Simple Machine
大同大學資工所智慧型多媒體研究室
![Page 32: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/32.jpg)
Definition of Machine PC
Memory set:
Instruction set: Operations & Predicates
N N
F P
![Page 33: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/33.jpg)
Operations of PC
1x x
1x x
1y y
1y y
y x y
y x y
, 1,m n m n
, 1, if 0
, 0, if 0
m n m n m
m n n m
, , 1m n m n
, , 1 if 0
, ,0 if 0
m n m n n
m n m n
, ,m n m m n
, ,m n m mn
other
![Page 34: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/34.jpg)
Predicates of PC
0?x if 0
,if 0
true mm n
false m
0?y if 0
,if 0
true nm n
false n
?x yif
,if
true m nm n
false m n
other
![Page 35: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/35.jpg)
A PC-Program
START
HALTtrue
false
1x x
1y y
y x y
0?x
GOTO
DO GOTO
IF THEN GOTO E
START: L0
L0: 1 L1
L1: 0? L4 L2
L2: L3
L3:
LSE GOTO
DO GOTO
DO GOT1 L1
L4: HALT
O
y y
x
y x y
x x
L0
L1
L2
L3
L4
![Page 36: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/36.jpg)
Computation Sequence
START
HALTtrue
false
1x x
1y y
y x y
0?x
GOTO
DO GOTO
IF THEN GOTO E
START: L0
L0: 1 L1
L1: 0? L4 L2
L2: L3
L3:
LSE GOTO
DO GOTO
DO GOT1 L1
L4: HALT
O
y y
x
y x y
x x
L0
L1
L2
L3
L4
0 3,0m
0 0, 3,L 1 ,1, 3L 2 ,1, 3L
3 ,3, 3L 1 ,3, 2L 2 ,3, 2L
3 ,6, 2L 1 ,6, 1L 2 ,6, 1L
3 ,6, 1L 1 ,6, 0L 4 ,6, 0L
![Page 37: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/37.jpg)
PC=?
START
HALTtrue
false
1x x
1y y
y x y
0?x
L0
L1
L2
L3
L4
: , 0, ( 1) !m n n m PC
0 0, 3,L 1 ,1, 3L 2 ,1, 3L
3 ,3, 3L 1 ,3, 2L 2 ,3, 2L
3 ,6, 2L 1 ,6, 1L 2 ,6, 1L
3 ,6, 1L 1 ,6, 0L 4 ,6, 0L
![Page 38: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/38.jpg)
Encoding/Decoding
: , 0, ( 1) !m n n m PC
Encoding
Decoding
:e X M
:d M Y
,0k k
,m n n
by
by
PC
k k!
0, !k,0ke d
![Page 39: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/39.jpg)
Encoding/Decoding
: !d e k kPC
PC
k k!
0, !k,0ke d
![Page 40: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/40.jpg)
Man-Machine Interaction
M a machine an M-program
:e X M:d M Y
an encoding function a decoding function
Me d
input output
![Page 41: Lecture 1: A Formal Model of Computation](https://reader035.fdocuments.net/reader035/viewer/2022062517/568137e2550346895d9f8715/html5/thumbnails/41.jpg)
What Computed?
Me d
input output
d eM A partial function