1 / 41

Lecture 1: A Formal Model of Computation

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.

Download Presentation

Lecture 1: A Formal Model of Computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 • Tworegisters with unbounded capacity • Machine Instructions • Operations & tests e.g.,

  6. Inside PC • Memory Set • Tworegisters with unbounded capacity • Machine Instructions • Operations & tests How about if n = 0? Undefined if n = 0. e.g.,

  7. Inside PC • Memory Set • Tworegisters with unbounded capacity • Machine Instructions • Operations & tests Partial Functions Partial Predicates e.g.,

  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)fis written as: If, aA,there is no bB such thatf(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() = . • Totally undefined • Partially defined • Totally defined There Cases:

  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, andh 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 Operation HALT Predicate (Test)

  16. START F0 F1 HALT P1 F2 false true Flowchart

  17. 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

  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 THENGOTO L0 ELSE GOTO L3 L2: DO F1 GOTO L1 L3: DO F0 GOTO L2 L4: HALT

  19. -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

  20. Program Schema • Exactly one start instruction; • No repeat on label. A program schema  is a set of instructions that contains:

  21. 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.

  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 setF P • for which there exists a memory setM • such that • MFis a partial function over M for each FF • MPis 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 noinstruction, 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 of start instruction Label of a halt instruction

  28. 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:

  29. 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.

  30. The (partial) function Computed by a program  on a machine M is such that is a completed computation. Partial Function what a computer does.

  31. Lecture 1: A Formal Model of Computation A Simple Machine 大同大學資工所 智慧型多媒體研究室

  32. Definition of Machine PC N N Memory set: Instruction set: Operations & Predicates F P

  33. Operations of PC  other

  34. Predicates of PC  other

  35. START L0 L1 true HALT L4 false L2 L3 A PC-Program 

  36. START L0 L1 true HALT L4 false L2 L3 Computation Sequence 

  37. START L0 L1 true HALT L4 false L2 L3 PC=? 

  38. d e k! k Encoding/Decoding Encoding by Decoding by

  39. d e k! k Encoding/Decoding

  40. d e output input Man-Machine Interaction M  a machine  an M-program  an encoding function  a decoding function

  41. d e output input What Computed? A partial function

More Related