18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

War Story: What's Past is Prolog<br />

Next: War Story: Text Compression Up: Breaking Problems Down Previous: War Story: Evolution of<br />

War Story: What's Past is Prolog<br />

``But our heuristic works very, very well in practice.'' He was simultaneously boasting and crying for<br />

help.<br />

Unification is the basic computational mechanism in logic programming languages like Prolog. A Prolog<br />

program consists of a set of rules, where each rule has a head and an associated action whenever the rule<br />

head matches or unifies with the current computation.<br />

An execution of a Prolog program starts by specifying a goal, say p(a,X,Y), where a is a constant and X<br />

and Y are variables. <strong>The</strong> system then systematically matches the head of the goal with the head of each of<br />

the rules that can be unified with the goal. Unification means binding the variables with the constants, if<br />

it is possible to match them. For the nonsense program below, p(X,Y,a) unifies with either of the first two<br />

rules, since X and Y can be bound to match the extra characters. <strong>The</strong> goal p(X,X,a) would only match the<br />

first rule, since the variable bound to the first and second positions must be the same.<br />

p(a,a,a) := h(a);<br />

p(b,a,a) := h(a) * h(b);<br />

p(c,b,b) := h(b) + h(c);<br />

p(d,b,b) := h(d) + h(b);<br />

file:///E|/BOOK/BOOK2/NODE51.HTM (1 of 4) [19/1/2003 1:28:54]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!