Previous topic  Top  Next topic  Print this Topic



Based on a given object base (which can be considered as a set of facts), rules offer the possibility to derive new information, i.e. to extend the object base intentionally. Rules encode generic information of the form:

Whenever the precondition of a rule is satisfied, the conclusion of the rule is also true.

The precondition is called rule body and is formed by an arbitrary logical formula consisting of P-Atoms (predicates) or F-molecules, which are combined by OR, NOT, AND, <--, --> and <-->.

A --> B in the body is an abbreviation for NOT A OR B,
A <-- B is an abbreviation for NOT B OR A and
A <--> B is an abbreviation for (A-->B) AND (B<--A).

Variables in the rule body may be quantified either existentially or universally. The conclusion, the rule head, is a conjunction of P-Atoms and F-molecules. Syntactically, the rule head is separated from the rule body by the symbol :- and every rule ends with a dot. Non-ground rules use variables for passing information between sub-goals and to the head. Every variable in the head of the rule must also occur in a positive F- or P-Atom in the body of the rule.

Assume an object base defining the methods friend and owner for some persons. The rules below compute the reflexive closure of friend and define a new method admissibleDriver based on friend- and owner-facts.

?X[friend->?Y] :- ?Y:Person[friend->?X].

?X[admissibleDriver->?Y] :- ?X:Vehicle[owner->?Y].

?X[admissibleDriver->?Z] :- ?X:Vehicle[owner->?Y] AND ?Y:Person[friend->?Z].


Partial logical formulae in the rule body may be negated. E.g. the following rule computes for every car ?X all persons ?Y that are prohibited as drivers for ?X:

?X[prohibitedDriver->?Y] :-

 ?X:Car AND

 ?Y:Person AND

 NOT ?X[admissibleDriver -> ?Y].


The following rule computes all persons ?X that do have (at least one) friend:

personWithFriends(?X) :-

 ?X:Person AND

 (EXIST ?Y ?X[friend -> ?Y]).


Rules can also be identified by rule names, e.g. MutualFriendship in the following rule:

@{MutualFriendship} ?X[friend -> ?Y] :- ?Y:Person[friend -> ?X].


The rule name can be any arbitrary ground term.