How Prolog works    Next: The effect of clause ordering
Up: Introduction to Prolog for Mathematicians
Previous: Memo-functions with lists

# How Prolog works

Prolog is not a general-purpose theorem prover, and its powers of inference are limited. For example, it cannot answer these questions:

```X > 1, X =< 2, integer(X).
25 is X^2 + Y^2, integer(X), integer(Y).```

Prolog works by backward-chaining, using Modus Ponens:

```If I am asked to prove Q
and I have the rule (P implies Q)
then if I can prove P, I can prove Q
otherwise I shall assume Q
is false.```
Note that if Prolog can't prove a goal, it assumes it to be false. This is called the closed world assumption.

I shall illustrate execution using the following set of rules.

```/*10*/   suits(Skier, st_sartre) :-
is_a(Skier, beginner),
wants(Skier, fun).

/*20*/   suits(Skier,
schloss_heidegger) :-
is_a(Skier, beginner),
wants(Skier, serious).

/*30*/   suits(Skier, chateau_derrida) :-
wants(Skier, serious).

/*40*/   suits(Skier,
wants(Skier, fun).

/*50*/   is_a(Skier, beginner) :-
L < 30.

/*60*/   is_a(Skier, beginner) :-
L >= 30,
has_fitness(Skier, poor).

/*70*/   is_a(Skier, advanced) :-
L >= 30,
has_fitness(Skier, good).

/*80*/   has_fitness(Skier, poor) :-
max_pressups(Skier, P),
P < 10.

/*90*/   has_fitness(Skier, good) :-
max_pressups(Skier, P),
P >= 10.

wants(eddie,fun).
max_pressups(eddie,170).