420 likes | 586 Views
Lecture 1: A Formal Model of Computation. 虞台文. 大同大學資工所 智慧型多媒體研究室. Content. Formalizing the Idea of Programmable Computer. Program Defined Machine Defined Computation Defined A Simple Machine. Lecture 1: A Formal Model of Computation. Formalizing the Idea of Programmable Computer.
E N D
Lecture 1: A Formal Model of Computation 虞台文 大同大學資工所 智慧型多媒體研究室
Content • Formalizing the Idea of Programmable Computer. • Program Defined • Machine Defined • Computation Defined • A Simple Machine
Lecture 1: A Formal Model of Computation Formalizing the Idea of Programmable Computer 大同大學資工所 智慧型多媒體研究室
A Simple Programmable Device PC PC Pocket Calculator What is inside?
Inside PC • Memory Set • Tworegisters with unbounded capacity • Machine Instructions • Operations & tests e.g.,
Inside PC • Memory Set • Tworegisters with unbounded capacity • Machine Instructions • Operations & tests How about if n = 0? Undefined if n = 0. e.g.,
Inside PC • Memory Set • Tworegisters with unbounded capacity • Machine Instructions • Operations & tests Partial Functions Partial Predicates e.g.,
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)fis written as: If, aA,there is no bB such thatf(a) = b, then we say that f(a)is undefined, and denote this condition as:
Partial Functions • is reserved to denote undefined object. • f() = . • Totally undefined • Partially defined • Totally defined There Cases:
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:
Partial Predicates which does not change the information environment. Example:
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.
Exercises • Define “algorithm”. • Show that , where f, g, andh are partial functions.
Lecture 1: A Formal Model of Computation Program Defined 大同大學資工所 智慧型多媒體研究室
Programs vs. Flowcharts Essentially, we take programs to be flowcharts constituting the following components. START Operation HALT Predicate (Test)
START F0 F1 HALT P1 F2 false true Flowchart
START F0 F1 HALT P1 F2 false true Labeled Statements START: GOTO L3 L0: DO F2 GOTO L3 L3 L1: IF P1 THENGOTO L0 ELSE GOTO L3 L2: DO F1 GOTO L1 L2 L3: DO F0 GOTO L2 L4: HALT L1 L0 L4
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 THENGOTO L0 ELSE GOTO L3 L2: DO F1 GOTO L1 L3: DO F0 GOTO L2 L4: HALT
-Loop: L: DO F GOTO L Four Types of Instructions • Start Instruction • Operation Instruction • Test Instruction • Halt Instruction START: GOTO L L: DO F GOTO L’ L: IF P1 THENGOTO L’ ELSEGOTO L’’ L: HALT
Program Schema • Exactly one start instruction; • No repeat on label. A program schema is a set of instructions that contains:
p1 := P1; p2 := false; while p1 or p2 do begin if p2 then W2 else W1; p2 := P2; p1 := P1; end. while P1 do begin W1; while P2 do W2; end. Exercise Translate the above two Pascal Programs into labeled statements and prove their equivalence, using computation sequence in any convenient way.
Lecture 1: A Formal Model of Computation Machine Defined 大同大學資工所 智慧型多媒體研究室
M-Machine • A machine is a function, say, M defined on • the instruction setF P • for which there exists a memory setM • such that • MFis a partial function over M for each FF • MPis a partial predicate over M for each PP.
M-Program An M-program or a program for M is a program in which noinstruction, except perhaps -loops, makes use an operation or test name that is interpreted as the totally undefined function by M. Without Syntax Error
Lecture 1: A Formal Model of Computation Computation Defined 大同大學資工所 智慧型多媒體研究室
Complete Computation A completed computation by a program on a machine M is a finite computation sequence: Label of start instruction Label of a halt instruction
Without ambiguity at each step. Complete Computation A completed computation by a program on a machine M is a finite computation sequence: Case 1: Case 2:
Uncompletable Computation • The reasons for a computation being uncompletable: • Never reach halt instruction; • Instruction Li: DOFGOTOL’ causes • Instruction Li: IFPTHENGOTOL’ELSEGOTOL’’ causes • Reaches a -loop.
The (partial) function Computed by a program on a machine M is such that is a completed computation. Partial Function what a computer does.
Lecture 1: A Formal Model of Computation A Simple Machine 大同大學資工所 智慧型多媒體研究室
Definition of Machine PC N N Memory set: Instruction set: Operations & Predicates F P
Operations of PC other
Predicates of PC other
START L0 L1 true HALT L4 false L2 L3 A PC-Program
START L0 L1 true HALT L4 false L2 L3 Computation Sequence
START L0 L1 true HALT L4 false L2 L3 PC=?
d e k! k Encoding/Decoding Encoding by Decoding by
d e k! k Encoding/Decoding
d e output input Man-Machine Interaction M a machine an M-program an encoding function a decoding function
d e output input What Computed? A partial function