A Motivational Introduction to Computational Logic
and (Constraint) Logic Programming
- Conventional models of using computers - not easy to determine
correctness!
- Has become a very important issue, not just in safety-critical
apps.
- Components with assured quality, being able to give a warranty, ...
- Being able to run untrusted code, certificate carrying code, ...
``Compute the squares of the natural numbers which are less or equal than 5.''
- Ideal at first sight, but:
- verbose
- vague
- ambiguous
- needs context (assumed information)
- ...
- Philosophers and Mathematicians already pointed this out a long time
ago...
- A means of clarifying / formalizing the human thought process
- Logic for example tells us that (classical logic)
Aristotle likes cookies, and
Plato is a friend of anyone who likes cookies
imply that
Plato is a friend of Aristotle
- Symbolic logic:
A shorthand for classical logic - plus many
useful results:
- But, can logic be used:
- To represent the problem (specifications)?
- Even perhaps to solve the problem?
- For expressing specifications and reasoning about the
correctness of programs we need:
- Specification languages (assertions), modeling, ...
- Program semantics (models, axiomatic, fixpoint, ...).
- Proofs: program verification (and debugging,
equivalence, ...).
Numbers --we will use ``Peano'' representation for simplicity:
0
0 1
s(0)
2
s(s(0)) 3
s(s(s(0)))
...
- Defining the natural numbers:
- A better solution:
- Order on the naturals:
- Addition of naturals:
We can now write a specification of the (imperative) program,
i.e., conditions that we want the program to meet:
- Precondition:
empty.
- Postcondition:
- Assuming the existence of
a mechanical proof method (deduction procedure)
a new view of problem solving and computing is possible [Greene]:
- program once and for all the deduction procedure in the computer,
- find a suitable representation for the problem (i.e., the
specification),
- then, to obtain solutions, ask questions and let
deduction procedure do rest:
- No correctness proofs needed!
| Query |
Answer |
| |
|
? |
 |
| |
|
? |
 |
| |
|
? |
 |
| |
|
? |
 |
| |
|
? |
 |
| |
|
? |
 |
| |
|
? |
 |
| |
|
? |
 |
| |
|
? |
 |
| |
|
- We have already argued the convenience of representing the
problem in logic, but
- which logic?
- propositional
- predicate calculus (first order)
- higher-order logics
- modal logics
-calculus, ...
- which reasoning procedure?
- natural deduction, classical methods
- resolution
- Prawitz/Bibel, tableaux
- bottom-up fixpoint
- rewriting
- narrowing, ...
- We try to maximize expressive power.
- But one of the main issues is whether we have an
effective reasoning procedure.
- It is important to understand the underlying properties and the
theoretical limits!
- Example: propositions vs. first-order formulas.
- Propositional logic:
SPMgt;``spot is a dog'' p
+ decidability/completeness
- limited expressive power
+ practical deduction mechanism
circuit design, ``answer set'' programming, ...
- Predicate logic: (first order)
SPMgt;``spot is a dog'' dog(spot)
+/- decidability/completeness
+/- good expressive power
+ practical deduction mechanism (e.g., SLD-resolution)
classical logic programming!
- Higher-order predicate logic:
SPMgt;``There is a relationship for spot'' X(spot)
- decidability/completeness
+ good expressive power
- practical deduction mechanism
But interesting subsets
HO logic programming, functional-logic
prog., ...
- Other logics: decidability? Expressive power? Practical
deduction mechanism?
Often (very useful) variants of previous ones:
- Predicate logic + constraints (in place of unification)
constraint programming!
- Propositional temporal logic, etc.
- Interesting case:
-calculus
+ similar to predicate logic in results, allows higher order
- does not support predicates (relations), only functions
functional programming!
- We code the problem as definite (Horn) clauses:
- Query:
?
- In order to refute:
- Resolution:
with
gives
with
gives
- Answer:
- $$
- Query:
?
- $$
- In order to refute:
- $$
- Resolution:
with
gives
solved as before
- $$
- Answer:
- $$
- Alternative:
with
gives
:- module(_,_,['bf/af']).
nat(0) <- .
nat(s(X)) <- nat(X).
le(0,_X) <- .
le(s(X),s(Y)) <- le(X,Y).
add(0,Y,Y) <- nat(Y).
add(s(X),Y,s(Z)) <- add(X,Y,Z).
mult(0,Y,0) <- nat(Y).
mult(s(X),Y,Z) <- add(W,Y,Z), mult(X,Y,W).
nat_square(X,Y) <- nat(X), nat(Y), mult(X,X,Y).
output(X) <- nat(Y), le(Y,s(s(s(s(s(0)))))), nat_square(Y,X).
| Query |
Answer |
| |
|
| ?- nat(s(0)). |
yes |
| |
|
| ?- add(s(0),s(s(0)),X). |
X = s(s(s(0))) |
| |
|
| ?- add(s(0),X,s(s(s(0)))). |
X = s(s(0)) |
| |
|
| ?- nat(X). |
X = 0 ; X = s(0) ; X = s(s(0)) ; ... |
| |
|
| ?- add(X,Y,s(0)). |
(X = 0 , Y=s(0)) ; (X = s(0) , Y = 0) |
| |
|
| ?- nat_square(s(s(0)), X). |
X = s(s(s(s(0)))) |
| |
|
| ?- nat_square(X,s(s(s(s(0))))). |
X = s(s(0)) |
| |
|
| ?- nat_square(X,Y). |
(X = 0 , Y=0) ;
(X = s(0) , Y=s(0)) ;
(X = s(s(0)) , Y=s(s(s(s(0))))) ;
... |
| |
|
| ?- output(X). |
X = 0 ;
X = s(0) ;
X = s(s(s(s(0)))) ;
...
|
| |
|
-
father_of(john, peter).
father_of(john, mary).
father_of(peter, michael).
mother_of(mary, david).
grandfather_of(L,M) :- father_of(L,K),
father_of(K,M).
grandfather_of(X,Y) :- father_of(X,Z),
mother_of(Z,Y).
|
|
|
figure=/home/logalg/public_html/slides/Figs/family_1.eps,width=0.45
|
|
- $$
- How can
grandmother_of/2 be represented?
- $$
- What does
grandfather_of(X,david) mean? And grandfather_of(john,X)?
- Declarative view:
- Suppose there is a functor
such that
represents a list with head
and tail
.
- Membership definition:
- Using logic:
- Using Prolog:
member(X, f(X, T)).
member(X, f(Z, T)) :- member(X,T).
- Procedural view (but for checking membership only!):
- 60's
- Greene: problem solving.
- Robinson: linear resolution.
- 70's
- Late 80's, 90's
- Major research in the basic paradigms
and advanced implementation techniques: Japan (Fifth Generation
Project), US (MCC), Europe (ECRC, ESPRIT projects).
- Numerous commercial Prolog implementations, programming books,
and a de facto standard, the Edinburgh Prolog family.
- First parallel and concurrent logic programming systems.
- CLP - Constraint Logic Programming: Major
extension - many new applications areas.
- 1995: ISO Prolog standard.
- Many commercial CLP systems with fielded applications.
- Extensions to full higher order, inclusion of functional
programming, ...
- Highly optimizing compilers, automatic parallelism, automatic
debugging.
- Concurrent constraint programming systems.
- Distributed systems.
- Object oriented dialects.
- Applications
- Natural language processing
- Scheduling/Optimization problems
- AI related problems
- (Multi) agent systems programming.
- Program analyzers
- ...
Last modification: Wed Mar 21 12:47:35 CET 2007 <webmaster@clip.dia.fi.upm.es>