Reputation: 57
I don't understand what the Horn clause is in prolog. • A Horn clause is a clause with exactly one positive literal.
root(X) :- \+ left(X,Y), \+ right(X,Y).
So for this one it is not a horn clause cause it has multiple clauses? Or is there having any way to express it as a horn clause?
Upvotes: 1
Views: 1325
Reputation: 4998
Since \+
stands for negation as failure(*), the clause you give as an example does not have a pure logical meaning but depends on the evaluation strategy of Prolog. In classical logic, a horn clause is a clause which has at most one positive literal. Using logical notation, it can be written as ¬ A1 ∨ ... ∨ ¬ An ∨ B
which is equivalent to A1 ∧ ... ∧ An → B
. In human words, this means: suppose A1 to An can be proved, then we can prove B. In Prolog, we write this backwards as b :- a1, ..., an.
There's a special form called a fact, when we know that something is true without conditions. Logically, you can write this as true → A
, in Prolog this just becomes a.
.
(*) A formula is false because it can't be proven true. Another closely related keyword you can google for is closed world assumption.
Upvotes: 4