PART 2. PROLOG, RESOLUTION PRINCIPLE

PART 2. PROLOG, RESOLUTION PRINCIPLE

In the last blog article, we solved the simple task of appending lists. This article will describe how Prolog works in general so we will cover the resolution principle.

Prolog is based on the first order predicate logic and is therefore independent of the classic von Neuman architecture and requires a new programming technique. As you might remember Prolog was created to automatically prove mathematical theorems.

proof strategy

The principal task of Prolog is to proof literals in requests, based on given facts and rules. If a proof exists the resolution principle will find it. For efficiency reason, Prolog applies a limited version of the resolution principle. It does not search for all possible solutions in parallel, it does a deep search first. This implicates that a problem in one of the deep searches causes that a proof in another branch can’t be found even it would exist.

Resolution Principle

The semantics of rules are defined as follows:

If all literals L1, …, Ln can be proven and L0 :- L1,…,Ln is a rule, then L0 is proven.

This rule is known as modus ponens. This and the interpretation of facts as rules with an empty right-hand side gives the Prolog program meaning.

The resolution principle means a proof can be found by searching a suitable rule whose left-hand side matches the given literals and then trying to prove the literals of the right of that rule.

However, there is generally no rule directly related to the given literal. This brings us to the topic of unification.

Unification

The process of variable replacement is called unification. In a resolution step, the variables in a literal and a clause can be replaced by new terms such that the literal and the left side of the clause are matching. Because the meaning of a predicate can be defined both by facts and by rules, they are also named clauses.

As example σ = {N/doe, J/23} is a substitution where all occurrences of the variable N are replaced by the atom doe and all occurrences of the variable J are replaced by number 23.

Therefore: σ(person(jane,N,date(12,7,J))) = person(jane,doe,date(12,7,23))

It is important that the applied unifier is not too especially since otherwise, a proof might end in a dead-end. A most common unifier replaces only the variables by terms that are mandatory to unify the two terms.

Backtracking

By now you know that Prolog proofs a request by utilizing the resolution principle and that the most common unification is used as substitution between the literal to be derived and the left side of a rule. But this doesn’t explain the exact strategy used for each resolution step because there exists more than one possibility.

  1. A request may contain more than one literal. Which one do we use next?
  2. Generally, more than one clause fits a literal. Which one do we use next?

The answer to the second question is, the clauses are used in the order they are fed into the prolog system.

Backtracking means that previous steps have to be undone, this means that previous variable bindings have to be undone because in an alternative step the variables might be bound to other objects.

?-a(X), b(X),c(X)

Let’s say a(X) and b(X) has been proven but c(X) can’t. All variable bindings of b(X) will be undone and Prolog will try to find an alternative proof for b(X). If one exists Prolog will try to find a proof for c(X) with new variable bindings of b(X). If no alternative for b(X) was found Prolog will undo all variable bindings for a(X). I hope you get the idea by now.

So the answer to question one is, Prolog tries all alternatives.

end

By now, you should have some basic understanding of Prolog. For people who would like to to see a debug session of append and a thorough explanation, I recommend having a look at this site.

ePILOG

I hope you value that this actually a wordplay with prolog, and it makes even some sense.

 

zurück zur Übersicht

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.