Download presentation
Presentation is loading. Please wait.
Published byDrusilla Casey Modified over 9 years ago
1
Lecture 1: A Formal Model of Computation 虞台文 大同大學資工所 智慧型多媒體研究室
2
Content Formalizing the Idea of Programmable Computer. Program Defined Machine Defined Computation Defined A Simple Machine
3
Lecture 1: A Formal Model of Computation Formalizing the Idea of Programmable Computer 大同大學資工所 智慧型多媒體研究室
4
A Simple Programmable Device PC PC Pocket Calculator What is inside?
5
Inside PC Memory Set – Two registers with unbounded capacity Machine Instructions – Operations & tests e.g.,
6
Inside PC Memory Set – Two registers with unbounded capacity Machine Instructions – Operations & tests e.g., How about if n = 0 ? Undefined if n = 0.
7
Inside PC Memory Set – Two registers with unbounded capacity Machine Instructions – Operations & tests e.g., Partial Functions Partial Predicates
8
Partial Functions Let A and B be two sets, and is a set of ordered pairs. We say that f is a partial function if Hence, (a, b) f is written as : If, a A, there is no b B such that f(a) = b, then we say that f(a) is undefined, and denote this condition as:
9
Partial Functions is reserved to denote undefined object. f( ) = . There Cases: 1.Totally undefined 2.Partially defined 3.Totally defined
10
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:
11
Partial Predicates which does not change the information environment. Example:
12
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.
13
Exercises Define “algorithm”. Show that, where f, g, and h are partial functions.
14
Lecture 1: A Formal Model of Computation Program Defined 大同大學資工所 智慧型多媒體研究室
15
Programs vs. Flowcharts Essentially, we take programs to be flowcharts constituting the following components. START HALT Operation Predicate (Test)
16
Flowchart START HALT F0 P1 F1 F2 truefalse
17
Labeled Statements START HALT F0 P1 F1 F2 truefalse L0 L1 L2 L3 L4 START: GOTO L3 L0: DO F2 GOTO L4 L1: IF P1 THEN GOTO L0 ELSE GOTO L3 L2: DO F1 GOTO L1 L3: DO F0 GOTO L2 L4: HALT
18
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
19
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
20
Program Schema A program schema is a set of instructions that contains: Exactly one start instruction; No repeat on label.
21
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.
22
Lecture 1: A Formal Model of Computation Machine Defined 大同大學資工所 智慧型多媒體研究室
23
Machines
24
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 M F is a partial function over M for each F F M P is a partial predicate over M for each P P.
25
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 Error
26
Lecture 1: A Formal Model of Computation Computation Defined 大同大學資工所 智慧型多媒體研究室
27
Complete Computation A completed computation by a program on a machine M is a finite computation sequence: Label ofstart instruction Label of a halt instruction
28
Complete Computation A completed computation by a program on a machine M is a finite computation sequence: Case 1: Case 2: Without ambiguity at each step.
29
Uncompletable Computation The reasons for a computation being uncompletable: – Never reach halt instruction; – Instruction L i : DO F GOTO L’ causes – Instruction L i : IF P THEN GOTO L’ ELSE GOTO L’’ causes – Reaches a -loop.
30
Partial Function The (partial) function Computed by a program on a machine M is such that is a completed computation. what a computer does.
31
Lecture 1: A Formal Model of Computation A Simple Machine 大同大學資工所 智慧型多媒體研究室
32
Definition of Machine PC Memory set: Instruction set: Operations & Predicates N N FP
33
Operations of PC other
34
Predicates of PC other
35
A PC-Program START HALT true false L0 L1 L2 L3 L4
36
Computation Sequence START HALT true false L0 L1 L2 L3 L4
37
PC =? START HALT true false L0 L1 L2 L3 L4
38
Encoding/Decoding Encoding Decoding by k k!k! e d
39
Encoding/Decoding k k!k! e d
40
Man-Machine Interaction M a machine an M -program an encoding function a decoding function e d input output
41
What Computed? e d input output A partial function
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.