|
|
- Prolog (Programming in Logic)
is a programming language based on
Predicate Logic.
It uses the restricted syntax of Horn Clauses:
-
| Predicates, e.g., | floats(), etc. |
| Operators | <=, and, not |
| Logical variables | X, GP, etc. |
| Constants | 7, girl, etc. |
| Function names | f, left(), ... |
| Facts | female(girl). |
| rules | burns(X) <= wooden(X). |
| queries | ? witch(girl). |
- Quantification of logical variables is implicit --
universal for facts and rules,
existential for queries.
-
- The introduction will get you going and
there are more examples.
The interpreter shows how Prolog works.
-
-
- NB. The applet above needs Java on.
-
-
| <= (also :- )
| can be read as if, or as is implied by.
|
| planet(P)<=orbits(P,sun)
| can be read as ∀ P, P is a planet if P orbits the sun.
(That is not to say that the
definition cannot be tightened.)
|
| ?satellite(S)
| can be read as
does there exist an S such that S is a satellite?
|
| And the answer, here, is yes, if
S is earth's moon, or a moon of another planet.
|
|
|