6 LogicAndProgramming

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

BITS Pilani

Pilani Campus
BITS Pilani
Pilani Campus
MODULE: INTRODUCTION
Logic and Programming
Sundar B. CS&IS, BITS Pilani 0 20-08-2014
CS/IS F214
Logic in Computer Science
Logic Programming
In the late 60s and early 70s Robert Kowalski and Alan
Colmeraur demonstrated that
first order predicate logic can be used as a basis for
programming.
This style of programming is referred to as Logic
Programming

20-08-2014
1 Sundar B. CS&IS, BITS Pilani
Logic Programming
A key idea was that clauses in first order logic can capture
relations (as rules):
human(X) --> male(X) OR female(X).
parent(X,Y) <-- mother(X,Y) OR father(X,Y).
and these relations can be composed to form more
complex relations (or rules):
grandparent(X,Y) <-- parent(X,Z) AND parent(Z,Y).
Then one has to encode computations as relations (say,
between input values and output values).
20-08-2014
2 Sundar B. CS&IS, BITS Pilani
Logic Programming
Consider the relations given in the previous slide:
Suppose the following facts are also given:
father(vichitra, pandu).
father(vichitra, dritha).
father(pandu, arjun).
father(dritha, duryodhan).
father(shantanu, bhishm).
Then a query of the form:
grandparent(vichitra, X)?
will yield the results of X = arjun; and X = duryodhan
by searching the list of rules and facts.
20-08-2014
3 Sundar B. CS&IS, BITS Pilani
Horn Clause Programming - Prolog
In particular, Horn Clauses
were proposed as a practical basis for programming and
the language Prolog was introduced.
Refer to the previous slide:
Which of the clauses are Horn Clauses?
Prolog uses depth-first-search as a strategy for searching
through rules:
each searched rule must be matched with the given
query to determine whether it will yield a result.


20-08-2014
4 Sundar B. CS&IS, BITS Pilani

You might also like