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
That is, “for all , , and : if ( is a parent of , and is a sibling of , and is female), then is an aunt of .”
However, there is a logical equivalence
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 appears only on the premise of the implication) to get the logically equivalent translation:
That is, “for all and : if (there exists such that is a parent of , and is a sibling of , and is female), then is an aunt of .”
We can express this even more simply as, “(for all and ): is an aunt of if there exists a parent of where is a sibling of , and is female.”
aunt(A,N) :- parent(P,N), sib(P,A), female(A).
:- operator) but not the conclusion (to the
left of the :- operator), then we can read the rule as if those
variables are existentially quantified.rel(X,Y) :- anc(A,X), anc(A,Y).“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.”
“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.”
sib(X,Y) :- parent(P,X), parent(P,Y), X \== Y.X, Y, and P: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 .”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.