Home » Satisfying Goals in Prolog

Satisfying Goals in Prolog

by Online Tutorials Library

Satisfying Goals in Prolog

In this section, we will look at how the goals are satisfied by the Prolog. If the user has a good understanding of this, he will write a powerful Prolog program in a compact way, and it will frequently use just a few clauses.  

This process starts when at the system prompt the user specifies a sequence of goals.

For example:

The prolog system is used to satisfy each goal sequence by sequence. It will work from left to right. If the goal has variables like owns(A, B), then the Prolog system always involves binding them to value like A to Kevin and B to dane. All sequence of goals succeeds if all goals succeed turn by turn. All the values of variables are output by the Prolog system used in the sequence of goals.

The sequence of goals will fail if it is not possible to satisfy all the goals.

We have an issue, and that is what Prolog will do if the first sequence goal succeeds, and the second sequence of goal fails.

Call Terms

In Prolog, every goal must be a term, but it doesn’t have any kind of term. The term may be a compound term, list, variables, atoms, not a number, or other types of term which is provided by some particular implementation of Prolog. This is a restriction type of term, and that is known as call term. In the bodies of rule, the goals, and heads of the clauses must also be call terms.

Every goal like go, nl, write(‘Welcome to Tutor Aspire’), dog(A) has a corresponding predicate as go/0, n1/0, write/1, and dog/1, respectively. The write and nl predicates are known as a functor. It has a number of arguments which are known as arity.

To satisfy the goal, Prolog matches the goal with the heads of clauses in the database, and the search will be done from top to bottom.

For example:

The above goal will match with the fact as follows:

It will give the output as follow:

To evaluate the user-defined predicate, there is a fundamental principle in Prolog that is if the facts and rules in the database are unable to satisfy the goal, the goal will fail. It has no intermediate position like ‘unknown’ or ‘not proven’. This is equivalent to making a very strong assumption, which is known as closed world assumption about the database: if the facts and rules in the database are unable to prove any conclusion, it will be false. There is no other information.


You may also like