15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

GAs = evolution: e.g., real genes encode replication machinery!<br />

4.2 Logic Programming<br />

c○: Michael Kohlhase 502<br />

We will now learn a new programming paradigm: “logic programming” (also called “Declarative<br />

Programming”), which is an application of the search techniques we looked at last, and the logic<br />

techniques. We are going to study ProLog (the oldest and most widely used) as a concrete example<br />

of the ideas behind logic programming.<br />

4.2.1 Introduction to Logic Programming and PROLOG<br />

Logic Programming is a programming style that differs from functional and imperative programming<br />

in the basic procedural intuition. Instead of transforming the state of the memory by issuing<br />

instructions (as in imperative programming), or computing the value of a function on some arguments,<br />

logic programming interprets the program as a body of knowledge about the respective<br />

situation, which can be queried for consequences. This is actually a very natural intuition; after<br />

all we only run (imperative or functional) programs if we want some question answered.<br />

Logic Programming<br />

Idea: Use logic as a programming language!<br />

We state what we know about a problem (the program) and then ask for results (what the<br />

program would compute)<br />

Example 623<br />

Program Leibniz is human x + 0 = x<br />

Sokrates is is human If x + y = z then x + s(y) = s(z)<br />

Sokrates is a greek 3 is prime<br />

Every human is fallible<br />

Query Are there fallible greeks? is there a z with s(s(0)) + s(0) = z<br />

Answer Yes, Sokrates! yes s(s(s(0)))<br />

How to achieve this?: Restrict the logic calculus sufficiently that it can be used as computational<br />

procedure.<br />

Slogan: Computation = Logic + Control ([Kowalski ’73])<br />

We will use the programming language ProLog as an example<br />

c○: Michael Kohlhase 503<br />

Of course, this the whole point of writing down a knowledge base (a program with knowledge<br />

about the situation), if we do not have to write down all the knowledge, but a (small) subset,<br />

from which the rest follows. We have already seen how this can be done: with logic. For logic<br />

programming we will use a logic called “first-order logic” which we will not formally introduce<br />

here. We have already seen that we can formulate propositional logic using terms from an abstract<br />

data type instead of propositional variables – recall Definition 2.6.1. For our purposes, we will<br />

just use terms with variables instead of the ground terms used there.<br />

Representing a Knowledge base in ProLog<br />

Definition 624 Fix an abstract data type 〈{B, . . .}, {, . . .}〉, then we call all constructor<br />

terms of sort B ProLog terms.<br />

264

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!