4.6 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 \[ \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 \(a\), \(n\), and \(p\): if (\(p\) is a parent of \(n\), and \(p\) is a sibling of \(a\), and \(a\) is female), then \(a\) is an aunt of \(n\).”

However, there is a logical equivalence \[ \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 \(p\) appears only on the premise of the implication) to get the logically equivalent translation: \[ \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 \(a\) and \(n\): if (there exists \(p\) such that \(p\) is a parent of \(n\), and \(p\) is a sibling of \(a\), and \(a\) is female), then \(a\) is an aunt of \(n\).”

We can express this even more simply as, β€œ(for all \(a\) and \(n\)): \(a\) is an aunt of \(n\) if there exists a parent \(p\) of \(n\) where \(p\) is a sibling of \(a\), and \(a\) 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

```prolog

    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.

Previous: 4.5 Generate and Test

Next: 4.7 Lists in Prolog