When to use facts instead of rules?



I'm just getting started in Prolog by working my way through "Prolog
Programming for Artificial Intelligence" by Bratko. It's all making sense
on a superficial level, but I'm having trouble determining when to use
facts instead of rules. For instance, in problem 2.8, you're to rewrite
this formula without semicolons:

translate(Number, Word) :-
Number = 1, Word = one;
Number = 2, Word = two;
Number = 3, Word = three.

My answer was:

translate(Number, Word) :- Number = 1, Word = one.
translate(Number, Word) :- Number = 2, Word = two.
translate(Number, Word) :- Number = 3, Word = three.

However, the book suggested the more elegant:

translate(1, one).
translate(2, two).
translate(3, three).

I see why that's also correct, but I wouldn't have thought to express it
that way. Part of the problem, I figure, is that I'm coming from 20 years
of programming nothing but imperative languages. The rule version seems
far more obvious to me, I guess, because it looks like a subroutine. The
fact version doesn't look like it "does" anything.

Are there some rules* of thumb to use in determining whether to use a fact
or a rule? Of course, there's the obvious "try to express everything as a
fact first, and if you can't, express it as a rule," but that feels very
unnatural, like speaking a second language by imagining sentences in your
native langauge, then attempting to translate them to the second language.
It works, but it's slow and tiring. I have a hard time believing anyone
who enjoys Prolog programming endures such a thing!

* no pun intended
.



Relevant Pages

  • Re: When to use facts instead of rules?
    ... Programming for Artificial Intelligence" by Bratko. ... but I'm having trouble determining when to use ... then attempting to translate them to the second language. ... Use facts to express non-contingent relations ...
    (comp.lang.prolog)
  • Re: Is Prolog good for AI? (was: Minsky still posting)
    ... > than a programming language suitable for large scale direct human use. ... but it was Prolog nor AI. ... >> than most other languages. ... PHP because it solves a very specific problem. ...
    (comp.lang.prolog)
  • Re: Sublists question
    ... I do not really get what the predicate means or does. ... >>helps just to write the predicate out clearly in natural language, ... >>then translate into Prolog. ... more as a functional programming language than as a logic ...
    (comp.lang.prolog)
  • Hear Ye, Hear Ye, Hear Ye...
    ... and Imposium on the First Annual N Queens in Prolog ... Programming Conference and Review. ... The Chair will hear proposals on what to call the ... The Chair will be competing under the Initiate title, ...
    (comp.lang.prolog)
  • Re: A few questions about Prolog...
    ... few Prolog implementations, and would appreciate if the community ... SWI-Prolog uses a lot of memory for stacks? ... unexpected is behavior of your program caused by programming error. ...
    (comp.lang.prolog)