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 – Two registers with unbounded capacity Machine Instructions – Operations & tests e.g.,
Inside PC Memory Set – Two registers with unbounded capacity Machine Instructions – Operations & tests e.g., How about if n = 0 ? Undefined if n = 0.
Inside PC Memory Set – Two registers with unbounded capacity Machine Instructions – Operations & tests e.g., Partial Functions Partial Predicates
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:
Partial Functions is reserved to denote undefined object. f( ) = . There Cases: 1.Totally undefined 2.Partially defined 3.Totally defined
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, and h 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 HALT Operation Predicate (Test)
Flowchart START HALT F0 P1 F1 F2 truefalse
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
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
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
Program Schema A program schema is a set of instructions that contains: Exactly one start instruction; No repeat on label.
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.
Lecture 1: A Formal Model of Computation Machine Defined 大同大學資工所 智慧型多媒體研究室
Machines
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.
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
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 ofstart instruction Label of a halt instruction
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.
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.
Partial Function The (partial) function Computed by a program on a machine M is such that is a completed computation. what a computer does.
Lecture 1: A Formal Model of Computation A Simple Machine 大同大學資工所 智慧型多媒體研究室
Definition of Machine PC Memory set: Instruction set: Operations & Predicates N N FP
Operations of PC other
Predicates of PC other
A PC-Program START HALT true false L0 L1 L2 L3 L4
Computation Sequence START HALT true false L0 L1 L2 L3 L4
PC =? START HALT true false L0 L1 L2 L3 L4
Encoding/Decoding Encoding Decoding by k k!k! e d
Encoding/Decoding k k!k! e d
Man-Machine Interaction M a machine an M -program an encoding function a decoding function e d input output
What Computed? e d input output A partial function