Next: About this document
Up: No Title
Previous: Examples
- When we make the query :
nice.
- nice becomes the goal to be satisfied.
- Next, warm becomes the goal to be satisfied, as warm
is the first clause Prolog finds.
- Prolog again searches the program to find a clause whose head matches
the desired goal, warm
- Two goals are found in the body of the rule to be satisfied :
temperature (T) and T > 20. Prolog attempts to satisfy
them left to right. When fact temperature(15) is encountered,
Prolog tries to satisfy the goal 15 > 20. This is not possible,
so goal fails and Prolog automatically backtracks to the last goal that
was matched, i.e. temperature (T), and tries to perform this match in
another way. While backtracking (T) gets uninstantiated.
- To satisfy the goal temperature (T), Prolog does not start search from
the beginning but continues from the clause where this goal was matched last.
It starts with the fact temperature (15), and searches for another clause with
head of the same name (temperature). = it fails.
- Prolog again automatically backtracks to the last goal that was
successfully matched i.e. to the goal warm. Now it tries to find
an alternative clause whose head would match this goal. Search continues
from the point where the last match occured, and not from the beginning.
Since another clause for warm cannot be found, Prolog backtracks to nice
- A new clause is now found !!
- Execution is now performed as above, with the goal to be satisfied
now being sunny and not_windy. The goal sunny is
satisfied by matching it with the fact sunny.
- Similarly the goal not_windy is matched with the relevant clause
- Now, the two goals to be satisfied are wind_speed(S) and S < 5,
which are compared with the fact wind_speed(3) and the goal
3 < 5, which is the final goal
The execution of a Prolog program is therefore non-deterministic
because of multiple execution paths. Of course, if all procedures in a
program consisted of only one clause, then only one execution path would exist
- The closed world assumption
- Prolog program as a set of axioms (as facts and rules) from which
we can prove theorems (get answer to questions) using logical deductive
reasoning
- We state a theorem and Prolog tries to prove it (derive it)
from the given axioms (program). Hence, the concept of Prolog as
a theorem prover.
Useful to draw search trees to understand the operation of
Prolog in backtracking - Graphical representations always prefered.
Next: About this document
Up: No Title
Previous: Examples
Omer F Rana
Fri Feb 7 11:39:23 GMT 1997