next up previous contents
Next: Semantics Up: Knowledge Representation Previous: Multiple Clauses

Rules

  The format is:



divisible_by_two:-

even.

This is a non-unit clause.

In general a clause consists of two parts: the head and the bodygif.

The head is divisible_by_two and the body is even --- even is sometimes referred to as a subgoal.

Note that the symbol ``:-'' is read as if. An informal reading of the clause is `` divisible_by_two is true if even is true'' which is equivalent to `` even divisible_by_two''.

Any number of subgoals may be in the body of the rule.

This is another way in which Prolog is a restriction of full first order predicate calculus. For example we cannot translate rich(fred) happy(fred)powerful(fred) directly into the Prolog version happy(fred) powerful(fred) :- rich(fred).

See section 2.10 for an example of a clause with more than one subgoal in the body. A fact is effectively a rule with no subgoals.

You may have noticed that even if it is held that ``even'' is a relation it does not seem to relate anything to anything else.

The rule is not as much use as it might be because it does not reveal the more interesting relationship that

A number is divisible by two if it is even
We can express this with the help of the logical variable. Here is the improved rule:


divisible_by_two(X):-

even(X).

This is also a non-unit clause. The named logical variable is X. This Prolog clause is equivalent to the predicate calculus statement X. (even(X) divisible_by_two(X)).

Paul Brna
Mon May 24 20:14:48 BST 1999