6.5 Rules, Goals and Subgoals

Introduction

A rule expresses something dynamic, i.e., something that can be computed.

This contrasts with facts, which are static.

Rules

Syntax

The syntax of a rule consist of three things: a head, an entails-symbol (":-"), a body, and a period (".").

Simply put:

head :- body.

Head

The head can be any kind of term except variables, lists, and numbers.

In particular, a head can be a structure, which is what you will use most often.

Body

The body consists of a comma-separated list of subgoals. To explain what a subgoal is, we must first explain what a goal is.

Goal

A goal is something that Prolog+CG can seek to satisfy. That is, it tries to prove that the goal is true.

We have already met goals in the form of queries. For example:

?- is_philosopher(Peirce).

Here, "is_philosopher(Peirce)" is a goal which Prolog+CG must prove or satisfy in order for the query to succeed.

Subgoal

A subgoal is a goal in a rule or query. There can be more than one subgoal in a query or the body of a rule.

For example:

CarnivoreEatsAnimal(L) :- gr(L, G), 
                          subsume([Carnivore]<-AGNT-[Eat]-PTNT->[Animal], G).

Here, the body of the rule consists of two subgoals:

  • gr(L, G)
  • subsume([Carnivore]<-AGNT-[Eat]-PTNT->[Animal], G)

Satisfying rules

The head of the rule can be "satisfied" or "proved" if the body of the rule can be "satisfied" or proved.

The body of the rule can be "satisfied" or "proved" if all of its subgoals can be "satisfied" or proved. This is done in the order in which they are listed.

Summary

Thus a rule consists of a head, an "entails" symbol, a body, and a period.

The head can be proved if the body can be proved. The body can be proved if all its subgoals can be proved, in the order in which they are listed.

A subgoal is a goal in a rule or query. A goal is something that Prolog+CG will seek to satisfy or prove.


PrevLite: 6.4 Facts
NextLite: 6.6 Clauses and predicates

Prev: 6.4 Facts
Up: 6 Prolog for CG users
Next: 6.6 Clauses and predicates