Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logical and Functional Programming

Similar presentations


Presentation on theme: "Logical and Functional Programming"— Presentation transcript:

1 Logical and Functional Programming
Computational Models Evolution of Languages Logical Programming

2 Computational Models Programming language design amounts to a model, or abstract description, of computation Most languages based upon computation model where Arithmetic operations Variable assignments Calling procedures, looping, etc. Three computational models

3 Alan Turing’s Model Read/write characters on a tape under control of a “program” Suggests a physical machine Assignment, control structures Specify how results computed What is computed is implicit Imperative Languages like C++, Fortran, Pascal, Cobol, etc., based on this model.

4 Church’s Model - Equivalent to Turing’s Model
Involves “lambda calculus” and formalizes ideas of mathematical functions Formal rules govern how to apply a function to its arguments Repeated use of rules  reduces mathematical expression to its value Program is one BIG function anyway Functional Programming Languages like Lisp, SASL based on Church’s model

5 Predicate Calculus Model
OLD Solution of systems of logical equations Logical Programming Languages like Prolog based on Predicate Calculus Model Also known as Declarative Languages Specify what is to be computed, without the detail of how

6 Evolution of Languages
Ada PROLOG (70’s France) Pascal LISP (60s) Algol SASL Fortran Mercury (95) Scheme (75) Haskell (87)

7 Evolution of Languages
Software Engineering drove evolution of imperative languages Artificial Intelligence drove evolution of non-imperative languages Aside: 4GLS (non-imperative  imperative)

8 Prolog – Programming in Logic
Prolog is simple Collection of facts (concrete relations) And rules (patterns of relations)

9 Simple program dog (fido). --fact spotted (fido). --fact
dalmation (X) :- dog(X), spotted(X). --rule Semantics of rule: if X is a dog and is spotted, then X is a dalmation

10 Syntax :- (if) , (and) % comment Variables – Uppercase letter to start
Objects – lower case letter to start

11 Prolog is interactive Program does nothing until programmer adds a question or a query ?- dalmation (fido). Prolog system answers Yes. The facts and rules determine substitutions for variables in query (unification)

12 Can add to program Query Response No. leopard (leo). spotted (leo).
?-dalmation (leo). Response No.

13 Want to know all spotted? That is, “For what X is X spotted?” Query
?-spotted(X). Answer X=fido. F8 X=leo. F8 No.

14 Prolog is interpreted Applications Allows flexibility
Can add new facts and rules anytime. Applications Knowledge of representation and reasoning Symbolic manipulation e.g., validating well-formed prefix expressions

15 Homework Due next Wednesday: Type in fido example and run
Come with questions if NOT working Turn in program and output, if it is.


Download ppt "Logical and Functional Programming"

Similar presentations


Ads by Google