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:
If we universally quantify the variables in this right-to-left implication, we get the corresponding Predicate Logic formula
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
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:
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."
Reading Prolog¶
- In all cases, we can just read a Prolog fact as if its variables are universally quantified (at the front of the formula).
- 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
-
"For all
X,Y, andA: ifAis an ancestor ofXandAis an ancestor ofY, thenXis related toY." -
"For all
XandY:Xis related toYif there existsAsuch thatAis an ancestor ofXandAis an ancestor ofY."
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
- "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