Presentation is loading. Please wait.

Presentation is loading. Please wait.

11.1 11. Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.

Similar presentations


Presentation on theme: "11.1 11. Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing."— Presentation transcript:

1 Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing machine equivalence. Referential transparency.

2 11.2 Computational Models Computability : the study of what can be computed by a Totally Obedient Moron (TOM). –TOM = computational model = programming paradigm. –Follows instructions correctly. –Has no initiative. State manipulating TOMs : –Turing machine. –Von Neumann machine. State constant TOMs : – calculus. –Predicate calculus.

3 11.3 Turing Machine Tape is infinitely long. Read / write head can : –Go left or right. –Write 0 or 1. –Change state. c.f. Programmable logic arrays (S1,1)  (0,L,S2) (S1,0)  (0,R,S3) (S2,1)  (1,R,S4) (S2,0)  (0,R,S4) (S3,1)  (0,R,S1) (S3,0)  (1,L,S2) (S4,1)  (1,L,S2) (S4,0)  (1,L,S5) (S5,1)  ()

4 11.4 Von Neumann Machine Program and data held in (infinite) memory. Processor reads instructions from memory and executes them. –Instructions modify memory. Processor MOVE adr1,adr2 ADD adr1,adr2 HALT F1A ABCD 786B

5 11.5 Calculus Computation is reduction of a (possibly infinite) expression to normal form. Only one operation : function application (a.k.a.  reduction). ( x. e) v  e[v / x] Two possible evaluation strategies : –Applicative order : choose leftmost innermost redex. –Normal order : choose leftmost outermost redex. When expression contains no redexs it is in normal form. If an expression can be reduced to normal form then using normal order reduction will always succeed in doing so. NB : We also allow  (renaming) and  (arithmetical etc.) reductions but they are not really required.

6 11.6 Predicate Calculus Computation is an attempt to prove a predicate (a.k.a. a query) from a (possibly infinite) database of predicates (a.k.a. facts and rules). –Proof either succeeds with a set of variable bindings or fails. Only one operation : unification. P(A,fred,B,7)  P(X,Y,23,7) succeeds with bindings A  X, fred  Y, B  23, 7  7. If unification of two predicates fails then backtrack to a “higher level” of the search tree and try something else. –Only if all alternatives fail will the overall query fail.

7 11.7 In Practice Programming languages could be based on each model. –Turing machine : none that I know of. Why? –Von Neumann machine : imperative (C, C++, Pascal etc.). – calculus : functional (ML {nearly}, Miranda, Haskell etc.). –Predicate calculus : relational (PROLOG {nearly}). Programming languages use sugared syntax to make life easier for programmers. –C++ translates directly to Von Neumann machine instructions. –Miranda translates directly to calculus. –PROLOG translates directly to predicate calculus.

8 11.8 In Practice II Almost all computers are Von Neumann machines. –Most languages are imperative. –Functional and relational languages must be translated to Von Neumann machine instructions.  Not easy, especially for relational languages. NB: Computer memory is finite so a computer is not a pure Von Neumann machine but it’s as close as we’ll get. Some computers have been built which take calculus or predicate calculus as their “machine code”. –Mainly research projects. –Imperative languages must be translated to calculus or predicate calculus.  Not easy, but possible.

9 11.9 Turing Machine Equivalence A.K.A Church’s thesis after Alonzo Church. Very informally : anything one model can do any other model can do. –All TOMs have equivalent computational power. Impossible to prove (why?) but intuitively seems to be correct. Major consequence : –Any program than can be written in a general purpose (a.k.a. Turing machine equivalent) programming language can be written in any other general purpose language. –Miranda == PROLOG == C++ == Java == Haskell etc. Which language you use is purely a matter of convenience.

10 11.10 State Manipulating vs. State Constant Models In state manipulating models (Turing and Von Neumann machines) variables are (bound to) store locations. Computation proceeds by state modifications. –Writing 0 or 1 on the tape. Moving left or right. –Changing values in memory. In state constant models ( and predicate calculus) variables are bound to values. Computation proceeds by re-writing expressions. –Reduction to normal form. –Unification. Main consequence : referential transparency of declarative programs.

11 11.11 Referential Transparency Within the same scope an expression always means the same thing (since the value of variables cannot be changed). Expressions obey simple rules : f(x) + g(x)  g(x) + f(x) Can’t guarantee this in an imperative (or Turing machine) language. Declarative language compilers use these rules extensively to optimise code. –Compilation by transformation. Programmers use these rules (sometimes) to prove their programs correct.

12 11.12 Summary Four main models of computation. –State manipulating : Turing machine and Von Neumann machine. –State constant : calculus and predicate calculus. Turing machine equivalence : all models are equally powerful (Church’s thesis). State constant models exhibit referential transparency. Imperative programming languages based on Von Neumann machine model. Functional programming languages based on calculus model. Relational programming languages based on predicate calculus model.


Download ppt "11.1 11. Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing."

Similar presentations


Ads by Google