Prolog to English

DuckDuckGo Query: Prolog to English
Top Result: Prologue

Earlier, we said that in each rule in a Prolog database of facts, the variables in that rule are implicitly universally quantified. This is true, but many rules have an alternative interpretation that is logically equivalent and sometimes sounds more intuitive.

For example, recall our definition of the aunt predicate:

        aunt(A,N) :- parent(P,N), sib(P,A), female(A).

If we universally quantify the variables in this right-to-left implication, we get the corresponding Predicate Logic formula

a n p ((parent(p,n)sib(p,a)female(A))aunt(a,n))\forall a\ \forall n\ \forall p\ \bigl( (\mathrm{parent}(p,n) \land \mathrm{sib}(p,a) \land \mathrm{female}(A)) \to \mathrm{aunt}(a,n)\bigr)

That is, “for all aa, nn, and pp: if (pp is a parent of nn, and pp is a sibling of aa, and aa is female), then aa is an aunt of nn.”

However, there is a logical equivalence

x (x  )(xx)  \forall x\ (\ldots x\ldots\ \to\ \ldots) \quad \equiv \quad (\exists x \ldots x\ldots)\ \to\ \ldots

in the special case where a term variable only appears in the premise of an implication but not the conclusion.

We can apply this equivalence to our translation of the Prolog rule (because the universally quantified variable pp appears only on the premise of the implication) to get the logically equivalent translation:

a n ( p(parent(p,n)sib(p,a)female(A))  aunt(a,n))\forall a\ \forall n\ \bigl(\ \exists p(\mathrm{parent}(p,n) \land \mathrm{sib}(p,a) \land \mathrm{female}(A)) \ \to \ \mathrm{aunt}(a,n)\bigr)

That is, “for all aa and nn: if (there exists pp such that pp is a parent of nn, and pp is a sibling of aa, and aa is female), then aa is an aunt of nn.”

We can express this even more simply as, “(for all aa and nn): aa is an aunt of nn if there exists a parent pp of nn where pp is a sibling of aa, and aa is female.”

          aunt(A,N) :- parent(P,N), sib(P,A), female(A).

Reading Prolog

  1. In all cases, we can just read a Prolog fact as if its variables are universally quantified (at the front of the formula).
  2. If there are variables that appear in the premise of the implication (to the right of the :- operator) but not the conclusion (to the left of the :- operator), then we can read the rule as if those variables are existentially quantified.

Example

rel(X,Y) :- anc(A,X), anc(A,Y).
  1. “For all X, Y, and A : if A is an ancestor of X and A is an ancestor of Y, then X is related to Y.”

  2. “For all X and Y:
    X is related to Y if there exists A such that A is an ancestor of X and A is an ancestor of Y .”

    Or more simply, “For all X and Y :
    X is related to Y if there exists an ancestor A of X such that A is also an ancestor of Y.”

Example

          sib(X,Y) :- parent(P,X), parent(P,Y), X \== Y.
  1. “For all X, Y, and P:
    if P is a parent of X and P is a parent of Y and X is different from Y, then X is a sibling of Y .”
  2. “For all X and Y:
    X is a sibling of Y if there exists a parent P of X such that P is a parent of Y and X is different from Y.