3

In Prolog, this is unambiguously a fact:

foo(bar).

And this is unambiguously a rule:

foo(X) :- bar(X).

But what about a clause that has both non-singleton variables and no :- such as

identity(X,X).

or more realistically something like

my_member(X, [X|_]).

I've been calling these rules since I learned Prolog, but now that I've tried to check to be 100% sure, I can't seem to find any source making a stronger distinction than what I have in the first two examples.

So is a rule:

  • a clause that defines a variable logical relationship, i.e. a clause that will not always succeed.
  • a clause that that defines a relationship between predicates (or possibly a predicate and itself).
false
  • 10,264
  • 13
  • 101
  • 209
Elliot Way
  • 243
  • 1
  • 9
  • 1
    I would say these are *facts*. Especially since this source: http://www.cs.trincoll.edu/~ram/cpsc352/notes/prolog/factsrules.html says that rules have form `... :- ...`, your `identity(X, X)` does not follow that pattern. – Willem Van Onsem Feb 15 '20 at 19:09
  • 3
    A fact is syntax sugar for an always true rule, that is `identity(X,X).` is the same as `identity(X,X) :- true`. A predicate (could also be called a procedure), is a collection of clauses with same functor and arity. – CapelliC Feb 15 '20 at 19:11
  • @closer: This is a perfect question – false Feb 15 '20 at 20:57
  • 1
    @GuyCoder, ah. Your answer there may contain the answer here, but it is somewhat deep buried within. The idea of SO is to give clear answers. – false Feb 16 '20 at 12:16

2 Answers2

4

Sometimes terminology itself causes problems the actual Prolog systems do not have at all. In common terminology as well as standard terminology, both identity(X,X). and my_member(X, [X|_]). are facts. However, better use clause when this seems fit.

The unease stems from the set of solutions that are implied by such cases. In fact, there is an infinity of solutions for both examples. Otherwise, ground facts just describe one solution each. Sticking to ground facts only, simplifies bottom-up interpretations.

So what about the clause a :- true. Is it a fact or a rule? It uses a rule-atom. but it's body is true. A Note in 3.72 excludes (:-)/2 as principal functor of facts. Well, all of this is a clear indication that terminology is here a bit too fine grained.

So, stick as much as you can to clause.

false
  • 10,264
  • 13
  • 101
  • 209
1

The truth is that there is an argument over Prolog's terminology, but i' ll try to make a brief review which will hopefully lead to some answers.

Generally speaking, a Prolog program consists of objects and the relations between them.

The relations are called predicates and the objects are called arguments of the predicate. The number of the arguments is the predicate's arity.

Describing the objects and their relations is being done with clauses. There are three types of clauses: facts, rules and queries.

A fact denotes a relation between objects. This relation is unambiguously true. Syntactically, a fact consists of a name describing a relation, followed by one or more comma separated objects in parenthesis and a period. Example:

male(john).
father_of(adam, cain).

Combining facts, we can define new relations between objects. This is done with a rule, which consists of two parts: a condition section (also called body of the rule) and a conclusion (also called head of the rule). While facts denote relations that are unambiguously true, rules denote relations that are true only if certain conditions are true. These conditions are also relations between objects. Syntactically, the head of the rule is separated from the body with the neck operator (:-) which can be read as if. The conditions of the rule, if more than one, are separated by commas which can be read as and. Example:

father_of(X,Y) :-
    parent(X,Y),
    male(X).

In conclusion, rules and facts are clauses. A rule has the form Head :- Body. and a fact has the form Head. Predicates are relations defined by a name and number of arguments and there can be multiple facts or rules for the same predicate. Ultimately:

father_of/2 is a predicate named father_of with arity 2

father_of(adam, cain). is a fact

father_of(adam, abel). is another fact

father_of(A,B) :- parent(A,B), male(A). is a rule

Glauvus
  • 96
  • 4
  • 1
    @GuyCode: See 3.12, 3.88, 3.200 for similar uses of object. – false Feb 16 '20 at 12:46
  • 2
    `:-` is not read as if and only if. At best you can do this when there is a single rule. – false Feb 16 '20 at 12:48
  • 1
    I remember that also Clocksin & Mellish talk about relations between objects. – false Feb 16 '20 at 13:00
  • 2
    @false Clocksin & Mellish's "Programming in Prolog" is indeed the source of my phrase "a Prolog program consists of objects and the relations between them". They actually state that "_Prolog is a computer programming language that is used for solving problems that involve objects and the relationships between objects_". – Glauvus Feb 16 '20 at 13:16
  • 1
    @GuyCoder. If and only if lost its and only if:) – repeat Feb 16 '20 at 21:53
  • 2
    How about using some non-bogus facts in the example? Neither `father(X,Y).` nor the following redundant `father(Z,W)` make much sense. (and btw a better name like `father_of` could also improve your answer). So why not take some ground facts like: `father_of(adam, cain). father_of(adam, abel). father_of(adam, seth). father_of(seth, enosh).` ? – repeat Feb 16 '20 at 22:11