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).:- 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).β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.β
Example
```prolog
sib(X,Y) :- parent(P,X), parent(P,Y), X \== Y.```
- βFor all
X,Y, andP: ifPis a parent ofXandPis a parent ofYandXis different fromY, thenXis a sibling ofY.β- βFor all
XandY:Xis a sibling ofYif there exists a parentPofXsuch thatPis a parent ofYandXis different fromY.
Previous: 4.5 Generate and Test
Next: 4.7 Lists in Prolog